Skip to content

Commit

Permalink
Merge pull request #1355 from DarcJC/dev/darc/rpc
Browse files Browse the repository at this point in the history
New node register system
  • Loading branch information
littlemine authored Aug 9, 2023
2 parents 22340e8 + 31c018c commit b72efc2
Show file tree
Hide file tree
Showing 5 changed files with 620 additions and 21 deletions.
72 changes: 52 additions & 20 deletions projects/Roads/nodes/src/cost.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,60 @@

#include "zeno/zeno.h"
#include "zeno/utils/logger.h"
#include "zeno/PrimitiveObject.h"
#include "zeno/types/UserData.h"
#include "zeno/utils/PropertyVisitor.h"
#include "roads/roads.h"

template <typename ...Args>
inline void RoadsAssert(const bool Expr, const std::string& InMsg = "[Roads] Assert Failed", Args... args) {
if (!Expr) {
zeno::log_error(InMsg, args...);
}
}

template <typename GridType = roads::Point>
roads::DynamicGrid<GridType> BuildGridFromPrimitive(const zeno::AttrVector<zeno::vec3f>& DataSource, int32_t Nx, int32_t Ny) {
RoadsAssert(Nx * Ny <= DataSource.size());

roads::DynamicGrid<GridType> Grid(Nx, Ny);
for (size_t i = 0; i < Nx * Ny; ++i) {
Grid[i] = DataSource[i];
}

return Grid;
}

namespace {
using namespace zeno;

struct CalcPathCost_Simple : public INode {
void apply() override;
};
struct CalcPathCost_Simple : public zeno::reflect::IParameterAutoNode<CalcPathCost_Simple> {
ZENO_GENERATE_NODE_BODY(CalcPathCost_Simple);

ZENDEFNODE(
CalcPathCost_Simple,
{
{
{ "prim" },
{ "string", "output_channel", "path_cost" },
},
{},
{},
{
"Unreal"
}
}
)
std::shared_ptr<zeno::PrimitiveObject> Primitive;
ZENO_DECLARE_INPUT_FIELD(Primitive, "Prim");
ZENO_DECLARE_OUTPUT_FIELD(Primitive, "Prim");

void CalcPathCost_Simple::apply() {
}
std::string OutputChannel;
ZENO_DECLARE_INPUT_FIELD(OutputChannel, "OutputChannel", false, "", "path_cost");

std::string SizeXChannel;
ZENO_DECLARE_INPUT_FIELD(SizeXChannel, "UserData_NxChannel", false, "", "nx");

std::string SizeYChannel;
ZENO_DECLARE_INPUT_FIELD(SizeYChannel, "UserData_NyChannel", false, "", "ny");

int Nx = 0;
ZENO_BINDING_PRIMITIVE_USERDATA(Primitive, Nx, SizeXChannel, false);

int Ny = 0;
ZENO_BINDING_PRIMITIVE_USERDATA(Primitive, Ny, SizeYChannel, false);

zeno::AttrVector<vec3f> PositionList {};
ZENO_BINDING_PRIMITIVE_ATTRIBUTE(Primitive, PositionList, "pos", zeno::reflect::EZenoPrimitiveAttr::VERT);

void apply() override {
BuildGridFromPrimitive(PositionList, Nx, Ny);
zeno::log_info("aaa: {} {}", AutoParameter->Nx, AutoParameter->Ny);
}
};
}
18 changes: 17 additions & 1 deletion projects/Roads/utilities/include/roads/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
#include <cassert>
#include <cmath>
#include <vector>
#include <functional>

namespace roads {

enum class TriangleType {
ACUTE = 0,
RIGHT = 1,
OBTUSE = 2,
};

struct Point : public Eigen::Vector3d {};
struct Point : public Eigen::Vector3d {
Point(const std::array<float, 3>& InArray) : Eigen::Vector3d(InArray[0], InArray[1], InArray[2]) {}
Point() = default;
};

struct Triangle : public std::array<Point, 3> {
bool AnyAngleLargerThan(const double Degree) {
Expand All @@ -34,4 +39,15 @@ namespace roads {
template <size_t X, size_t Y, typename GridPointType = Point>
struct Grid : public std::array<GridPointType, X * Y> {};

template <typename GridPointType = Point>
struct DynamicGrid : public std::vector<GridPointType> {
size_t Nx, Ny;

DynamicGrid(const size_t InNx, const size_t InNy) : std::vector<GridPointType>(InNx * InNy), Nx(InNx), Ny(InNy) {}
DynamicGrid(DynamicGrid&& OtherGridToMove) noexcept : std::vector<GridPointType>(std::forward<std::vector<GridPointType>>(OtherGridToMove)) {
Nx = OtherGridToMove.Nx;
Ny = OtherGridToMove.Ny;
}
};

}// namespace roads
2 changes: 2 additions & 0 deletions zeno/include/zeno/core/INode.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ struct INode {
}

ZENO_API TempNodeCaller temp_node(std::string const &id);

friend struct reflect;
};

}
Loading

0 comments on commit b72efc2

Please sign in to comment.