From f989144d07e79b31cf9469cb09221c13cd39de1f Mon Sep 17 00:00:00 2001 From: littlemine Date: Thu, 30 May 2024 18:14:47 +0800 Subject: [PATCH] p2p attrib assign --- projects/CUDA/utils/Primitives.cpp | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/projects/CUDA/utils/Primitives.cpp b/projects/CUDA/utils/Primitives.cpp index a795fdb7fb..f5d60cb5e6 100644 --- a/projects/CUDA/utils/Primitives.cpp +++ b/projects/CUDA/utils/Primitives.cpp @@ -4633,6 +4633,54 @@ ZENDEFNODE(AdvanceFrame, { {"zs_geom"}, }); +struct PrimAssignRefAttrib : INode { + virtual void apply() override { + auto points = get_input("prim"); + auto prim = get_input("ref_prim"); + auto idTag = get_input2("pointIdTag"); + auto tag = get_input2("attribTag"); + + auto pointIndex = points->attr(idTag); + + auto assignAttrib = [&pointIndex](auto &dstAttrib, const auto &srcAttrib) { + if constexpr (zs::is_same_v) { + #pragma omp parallel for + for (auto index = 0; index < dstAttrib.size(); ++index) { + dstAttrib[index] = srcAttrib[(int)pointIndex[index]]; + } + } else + throw std::runtime_error( + fmt::format("destination attrib [{}], source attrib [{}]\n", + zs::get_var_type_str(dstAttrib), zs::get_var_type_str(srcAttrib))); + }; + + if (tag == "pos") { + assignAttrib(points->verts.values, prim->verts.values); + } else { + zs::match([&verts = points->verts, &tag](const auto &src) { + verts.add_attr(tag); + })(prim->verts.attr(tag)); + zs::match([&assignAttrib](auto &dst, const auto &src) { + assignAttrib(dst, src); + })(points->verts.attr(tag), prim->verts.attr(tag)); + } + + set_output("prim", get_input("prim")); + } +}; + +ZENDEFNODE(PrimAssignRefAttrib, { + { + "prim", + "ref_prim", + {"string", "pointIdTag", "bvh_id"}, + {"string", "attribTag"}, + }, + {"prim"}, + {}, + {"primitive"}, + }); + struct RemovePrimitiveTopo : INode { void apply() override { auto prim = get_input2("prim");