Skip to content

Commit

Permalink
Hair & Curves (#1992)
Browse files Browse the repository at this point in the history
* remove unused

* Refactor & curves support

* remove unused

* CurveGroupAux

* hair transform

* minor update

* transform

* fix crash

* fix windows build

* flex order

* minor updates

* Curves.h
  • Loading branch information
iaomw authored Aug 29, 2024
1 parent 7eb2383 commit 50a0914
Show file tree
Hide file tree
Showing 30 changed files with 2,422 additions and 51,228 deletions.
53 changes: 53 additions & 0 deletions zeno/include/zeno/types/CurveType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#pragma once

#include <string>
#include <magic_enum.hpp>

namespace zeno {

enum struct CurveType {

QUADRATIC_BSPLINE,
RIBBON_BSPLINE,
CUBIC_BSPLINE,

LINEAR,
BEZIER,
CATROM
};

static unsigned int CurveDegree(zeno::CurveType type) {

switch( type ) {
case CurveType::LINEAR:
return 1;

case CurveType::QUADRATIC_BSPLINE:
case CurveType::RIBBON_BSPLINE:
return 2;

case CurveType::CUBIC_BSPLINE:
case CurveType::BEZIER:
case CurveType::CATROM:
return 3;
}
return 0;
}

static std::string CurveTypeDefaultString() {
auto name = magic_enum::enum_name(CurveType::LINEAR);
return std::string(name);
}

static std::string CurveTypeListString() {
auto list = magic_enum::enum_names<CurveType>();

std::string result;
for (auto& ele : list) {
result += " ";
result += ele;
}
return result;
}

} //zeno
35 changes: 35 additions & 0 deletions zeno/src/nodes/prim/AsCurves.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <zeno/types/PrimitiveObject.h>
#include <zeno/types/CurveType.h>
#include <zeno/types/UserData.h>
#include <zeno/zeno.h>

#include "magic_enum.hpp"

namespace zeno {

struct AsCurves : zeno::INode {
virtual void apply() override {

auto prim = get_input2<zeno::PrimitiveObject>("prim");

auto typeString = get_input2<std::string>("type:");
auto typeEnum = magic_enum::enum_cast<CurveType>(typeString).value_or(CurveType::LINEAR);
auto typeIndex = (int)magic_enum::enum_index<CurveType>(typeEnum).value_or(0);

prim->userData().set2("curve", typeIndex);
set_output("prim", std::move(prim));
}
};

ZENDEFNODE(AsCurves,
{ {
{"prim"},
},
{"prim"}, //output
{
{"enum " + zeno::CurveTypeListString(), "type", zeno::CurveTypeDefaultString() }
}, //prim
{"prim"}
});

} // namespace
43 changes: 43 additions & 0 deletions zeno/src/nodes/prim/CyHair.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <zeno/types/PrimitiveObject.h>
#include <zeno/types/CurveType.h>
#include <zeno/types/UserData.h>
#include <zeno/zeno.h>

#include "magic_enum.hpp"

#include <filesystem>
#include <vector>

namespace zeno {

struct CyHair : zeno::INode {
virtual void apply() override {

auto path = get_input2<std::string>("path");
bool exist = std::filesystem::exists(path);
bool yup = get_input2<bool>("yup");

if (!exist) {
throw std::string("CyHair file doesn't exist");
}

auto out = std::make_shared<zeno::PrimitiveObject>();
out->userData().set2("yup", yup);
out->userData().set2("path", path);
out->userData().set2("cyhair", true);

set_output("out", std::move(out));
}
};

ZENDEFNODE(CyHair,
{ {
{"readpath", "path"},
{"bool", "yup", "1"},
},
{"out"}, //output
{},
{"read"}
});

} // namespace
8 changes: 4 additions & 4 deletions zeno/src/nodes/prim/SimpleGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,10 +1283,10 @@ struct CreateSphere : zeno::INode {
memcpy(row2.data(), transform_ptr+8, sizeof(float)*4);
memcpy(row3.data(), transform_ptr+12, sizeof(float)*4);

prim->userData().set2("sphere_transform_row0", row0);
prim->userData().set2("sphere_transform_row1", row1);
prim->userData().set2("sphere_transform_row2", row2);
prim->userData().set2("sphere_transform_row3", row3);
prim->userData().set2("_transform_row0", row0);
prim->userData().set2("_transform_row1", row1);
prim->userData().set2("_transform_row2", row2);
prim->userData().set2("_transform_row3", row3);
}

set_output("prim",std::move(prim));
Expand Down
13 changes: 13 additions & 0 deletions zeno/src/nodes/prim/TransformPrimitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,19 @@ struct PrimitiveTransform : zeno::INode {
}
}

auto transform_ptr = glm::value_ptr(matrix);

zeno::vec4f row0, row1, row2, row3;
memcpy(row0.data(), transform_ptr, sizeof(float)*4);
memcpy(row1.data(), transform_ptr+4, sizeof(float)*4);
memcpy(row2.data(), transform_ptr+8, sizeof(float)*4);
memcpy(row3.data(), transform_ptr+12, sizeof(float)*4);

iObject->userData().set2("_transform_row0", row0);
iObject->userData().set2("_transform_row1", row1);
iObject->userData().set2("_transform_row2", row2);
iObject->userData().set2("_transform_row3", row3);

set_output("outPrim", std::move(iObject));
}
};
Expand Down
Loading

0 comments on commit 50a0914

Please sign in to comment.