From 3bddcdf84c827ee3ec8e7508c69bc6da00bb8464 Mon Sep 17 00:00:00 2001 From: Alexey Smolenchuk Date: Sat, 23 Dec 2023 02:09:34 +0000 Subject: [PATCH 1/3] add packed, alembic and usd support --- rixplugins/Args/closest.args | 16 ++++++++++++++++ src/closest.cpp | 32 +++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/rixplugins/Args/closest.args b/rixplugins/Args/closest.args index 3e77163..0368e1e 100644 --- a/rixplugins/Args/closest.args +++ b/rixplugins/Args/closest.args @@ -48,6 +48,22 @@ houdiniui = "oplist"> + + Frame to Sample Geometry (For Alembic and USD) + + + + Frames per Second (For Alembic) + + diff --git a/src/closest.cpp b/src/closest.cpp index 37f93cb..bcc4b80 100644 --- a/src/closest.cpp +++ b/src/closest.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -24,6 +25,8 @@ class closest: public RixPattern k_maxdist, k_normdist, k_coordsys, + k_frame, + k_fps, // end of list k_numParams @@ -116,6 +119,8 @@ closest::GetParamTable() RixSCParamInfo(RtUString("maxdist"), k_RixSCFloat), RixSCParamInfo(RtUString("normdist"), k_RixSCInteger), RixSCParamInfo(RtUString("coordsys"), k_RixSCString), + RixSCParamInfo(RtUString("frame"), k_RixSCFloat), + RixSCParamInfo(RtUString("fps"), k_RixSCFloat), // end of table @@ -152,13 +157,17 @@ void closest::CreateInstanceData(RixContext& ctx, if (data->coordsys.Empty()) data->coordsys = Rix::k_object; + float frame = 0; + float fps =0; + params->EvalParam(k_frame, -1, &frame); + params->EvalParam(k_fps, -1, &fps); data->isect = nullptr; if (!filename.Empty()) { char buff[255]; - sprintf(buff, "%s:%s", filename.CStr(), primgroup.CStr()); + sprintf(buff, "%s:%s:%g", filename.CStr(), primgroup.CStr(), frame*fps); RtUString key(buff); auto it = m_isect.find(key); @@ -177,6 +186,27 @@ void closest::CreateInstanceData(RixContext& ctx, return; } + // Attempt to unpack all Packeds, Alembics and USD + while (GU_PrimPacked::hasPackedPrimitives(*gdp)) + { + for (GA_Iterator it(gdp->getPrimitiveRange()); !it.atEnd(); ++it) + { + if(GU_PrimPacked::isPackedPrimitive(gdp->getPrimitive(*it)->getTypeDef())) + { + const GU_PrimPacked* packed = UTverify_cast(gdp->getPrimitive(*it)); + gdp->getPrimitive(*it)->setIntrinsic(packed->findIntrinsic("usdFrame"), frame); + gdp->getPrimitive(*it)->setIntrinsic(packed->findIntrinsic("abcframe"), frame/fps); + // packed->findIntrinsic("usdFrame").; + GU_Detail dest; + packed->unpackUsingPolygons(dest); + + // replace packed with poly version + gdp->destroyPrimitive(*gdp->getPrimitive(*it)); // assume it's safe to delete prim while iterating + gdp->mergePrimitives(dest, dest.getPrimitiveRange()); + } + } + } + // Flag 'picking' should be set to 1. When set to 0, curves and surfaces will be polygonalized. GU_RayIntersect *isect = new GU_RayIntersect(gdp, grp, 1, 0, 1); m_isect[key] = isect; From bcf968c890c8f5b9b2ca5f4a7262f912b0d95689 Mon Sep 17 00:00:00 2001 From: Alexey Smolenchuk Date: Sat, 23 Dec 2023 02:11:29 +0000 Subject: [PATCH 2/3] remove commented line --- src/closest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/closest.cpp b/src/closest.cpp index bcc4b80..99b30a4 100644 --- a/src/closest.cpp +++ b/src/closest.cpp @@ -196,7 +196,7 @@ void closest::CreateInstanceData(RixContext& ctx, const GU_PrimPacked* packed = UTverify_cast(gdp->getPrimitive(*it)); gdp->getPrimitive(*it)->setIntrinsic(packed->findIntrinsic("usdFrame"), frame); gdp->getPrimitive(*it)->setIntrinsic(packed->findIntrinsic("abcframe"), frame/fps); - // packed->findIntrinsic("usdFrame").; + GU_Detail dest; packed->unpackUsingPolygons(dest); From e6f9711b1a7193e978398dfe360576140043e29a Mon Sep 17 00:00:00 2001 From: Alexey Smolenchuk Date: Sun, 24 Dec 2023 00:42:48 +0000 Subject: [PATCH 3/3] add packed support and group search to samplePoints --- rixplugins/Args/samplePoints.args | 23 +++++++++++++ src/closest.cpp | 18 +++++----- src/samplePoints.cpp | 55 ++++++++++++++++++++++++++++--- 3 files changed, 83 insertions(+), 13 deletions(-) diff --git a/rixplugins/Args/samplePoints.args b/rixplugins/Args/samplePoints.args index d82a0f5..bd868e0 100644 --- a/rixplugins/Args/samplePoints.args +++ b/rixplugins/Args/samplePoints.args @@ -13,6 +13,13 @@ Geometry Filename + + Point Group to search + + + + Frame to Sample Geometry (For Alembic and USD) + + + + Frames per Second (For Alembic) + + diff --git a/src/closest.cpp b/src/closest.cpp index 99b30a4..c15c69a 100644 --- a/src/closest.cpp +++ b/src/closest.cpp @@ -177,14 +177,6 @@ void closest::CreateInstanceData(RixContext& ctx, GU_Detail *gdp = new GU_Detail; if (gdp->load(filename.CStr()).success()) { - GA_PrimitiveGroup* grp = nullptr; - - if (!primgroup.Empty()) - { - grp = gdp->findPrimitiveGroup(primgroup.CStr()); - if (!grp) - return; - } // Attempt to unpack all Packeds, Alembics and USD while (GU_PrimPacked::hasPackedPrimitives(*gdp)) @@ -196,7 +188,7 @@ void closest::CreateInstanceData(RixContext& ctx, const GU_PrimPacked* packed = UTverify_cast(gdp->getPrimitive(*it)); gdp->getPrimitive(*it)->setIntrinsic(packed->findIntrinsic("usdFrame"), frame); gdp->getPrimitive(*it)->setIntrinsic(packed->findIntrinsic("abcframe"), frame/fps); - + GU_Detail dest; packed->unpackUsingPolygons(dest); @@ -207,6 +199,14 @@ void closest::CreateInstanceData(RixContext& ctx, } } + GA_PrimitiveGroup* grp = nullptr; + if (!primgroup.Empty()) + { + grp = gdp->findPrimitiveGroup(primgroup.CStr()); + if (!grp) + return; + } + // Flag 'picking' should be set to 1. When set to 0, curves and surfaces will be polygonalized. GU_RayIntersect *isect = new GU_RayIntersect(gdp, grp, 1, 0, 1); m_isect[key] = isect; diff --git a/src/samplePoints.cpp b/src/samplePoints.cpp index 367cb0c..62647f1 100644 --- a/src/samplePoints.cpp +++ b/src/samplePoints.cpp @@ -4,6 +4,7 @@ #include "hGeoStructsRIS.h" #include +#include #include #include @@ -20,8 +21,11 @@ class samplePoints: public RixPattern // inputs k_filename, + k_pointgroup, k_numPoints, k_coordsys, + k_frame, + k_fps, // end of list k_numParams @@ -111,8 +115,11 @@ samplePoints::GetParamTable() // inputs RixSCParamInfo(RtUString("filename"), k_RixSCString), + RixSCParamInfo(RtUString("pointgroup"), k_RixSCString), RixSCParamInfo(RtUString("numPoints"), k_RixSCInteger), RixSCParamInfo(RtUString("coordsys"), k_RixSCString), + RixSCParamInfo(RtUString("frame"), k_RixSCFloat), + RixSCParamInfo(RtUString("fps"), k_RixSCFloat), // end of table RixSCParamInfo() @@ -137,6 +144,9 @@ void samplePoints::CreateInstanceData(RixContext& ctx, RtUString filename = US_NULL; params->EvalParam(k_filename, -1, &filename); + RtUString pointgroup = US_NULL; + params->EvalParam(k_pointgroup, -1, &pointgroup); + data->numPoints = 1; params->EvalParam(k_numPoints, -1, &data->numPoints); @@ -145,23 +155,60 @@ void samplePoints::CreateInstanceData(RixContext& ctx, if (data->coordsys.Empty()) data->coordsys = Rix::k_object; - // std::cout << data->coordsys.CStr() << std::endl; + float frame = 0; + float fps =0; + params->EvalParam(k_frame, -1, &frame); + params->EvalParam(k_fps, -1, &fps); data->gdp = nullptr; data->tree = nullptr; if (!filename.Empty()) { - auto it = m_trees.find(filename); + char buff[255]; + sprintf(buff, "%s:%s:%g", filename.CStr(), pointgroup.CStr(), frame*fps); + RtUString key(buff); + + auto it = m_trees.find(key); if (it == m_trees.end()) { GU_Detail * gdp = new GU_Detail; if (gdp->load(filename.CStr()).success()) { + + // Attempt to unpack all Packeds, Alembics and USD + while (GU_PrimPacked::hasPackedPrimitives(*gdp)) + { + for (GA_Iterator it(gdp->getPrimitiveRange()); !it.atEnd(); ++it) + { + if(GU_PrimPacked::isPackedPrimitive(gdp->getPrimitive(*it)->getTypeDef())) + { + const GU_PrimPacked* packed = UTverify_cast(gdp->getPrimitive(*it)); + gdp->getPrimitive(*it)->setIntrinsic(packed->findIntrinsic("usdFrame"), frame); + gdp->getPrimitive(*it)->setIntrinsic(packed->findIntrinsic("abcframe"), frame/fps); + + GU_Detail dest; + packed->unpackUsingPolygons(dest); + + // replace packed with poly version + gdp->destroyPrimitive(*gdp->getPrimitive(*it), true); // assume it's safe to delete prim while iterating + gdp->mergePrimitives(dest, dest.getPrimitiveRange()); + } + } + } + + GA_PointGroup* grp = nullptr; + if (!pointgroup.Empty()) + { + grp = gdp->findPointGroup(pointgroup.CStr()); + if (!grp) + return; + } + GEO_PointTreeGAOffset *tree = new GEO_PointTreeGAOffset; - tree->build(gdp); - m_trees[filename] = std::pair(gdp, tree); + tree->build(gdp, grp); + m_trees[key] = std::pair(gdp, tree); data->gdp = gdp; data->tree = tree; // std::cout << "Loaded "<< gdp->getNumPoints() << " points: " << filename.CStr() << " " << tree->getMemoryUsage(true) << std::endl;