Skip to content

Commit

Permalink
Merge pull request #1 from AlexeySmolenchuk/packedPrimitives
Browse files Browse the repository at this point in the history
Packed Primitives Support
  • Loading branch information
AlexeySmolenchuk authored Jan 1, 2024
2 parents 5a92fe6 + e6f9711 commit 911cc42
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 6 deletions.
16 changes: 16 additions & 0 deletions rixplugins/Args/closest.args
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@
houdiniui = "oplist">
</param>

<param name="frame"
label="Frame"
type="float"
connectable="False"
default="0">
<help>Frame to Sample Geometry (For Alembic and USD)</help>
</param>

<param name="fps"
label="FPS"
type="float"
connectable="False"
default="24">
<help>Frames per Second (For Alembic)</help>
</param>

<output name="ClosestData"
type="struct"
struct_name="ClosestData">
Expand Down
23 changes: 23 additions & 0 deletions rixplugins/Args/samplePoints.args
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
<help>Geometry Filename</help>
</param>

<param name="pointgroup"
label="Point Group"
type="string"
connectable="False">
<help>Point Group to search</help>
</param>

<param name="numPoints"
label="Number of Points"
type="int"
Expand All @@ -34,6 +41,22 @@
houdiniui="oplist">
</param>

<param name="frame"
label="Frame"
type="float"
connectable="False"
default="0">
<help>Frame to Sample Geometry (For Alembic and USD)</help>
</param>

<param name="fps"
label="FPS"
type="float"
connectable="False"
default="24">
<help>Frames per Second (For Alembic)</help>
</param>

<output name="IdxA"
type="struct"
struct_name="ArrayData">
Expand Down
34 changes: 32 additions & 2 deletions src/closest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <GU/GU_Detail.h>
#include <GU/GU_RayIntersect.h>
#include <GU/GU_PrimPacked.h>

#include <map>
#include <iostream>
Expand All @@ -24,6 +25,8 @@ class closest: public RixPattern
k_maxdist,
k_normdist,
k_coordsys,
k_frame,
k_fps,

// end of list
k_numParams
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -168,8 +177,29 @@ void closest::CreateInstanceData(RixContext& ctx,
GU_Detail *gdp = new GU_Detail;
if (gdp->load(filename.CStr()).success())
{
GA_PrimitiveGroup* grp = nullptr;

// 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<const GU_PrimPacked*>(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)); // assume it's safe to delete prim while iterating
gdp->mergePrimitives(dest, dest.getPrimitiveRange());
}
}
}

GA_PrimitiveGroup* grp = nullptr;
if (!primgroup.Empty())
{
grp = gdp->findPrimitiveGroup(primgroup.CStr());
Expand Down
55 changes: 51 additions & 4 deletions src/samplePoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "hGeoStructsRIS.h"

#include <GU/GU_Detail.h>
#include <GU/GU_PrimPacked.h>
#include <GEO/GEO_PointTree.h>

#include <map>
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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);

Expand All @@ -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<const GU_PrimPacked*>(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<GU_Detail*,GEO_PointTreeGAOffset*>(gdp, tree);
tree->build(gdp, grp);
m_trees[key] = std::pair<GU_Detail*,GEO_PointTreeGAOffset*>(gdp, tree);
data->gdp = gdp;
data->tree = tree;
// std::cout << "Loaded "<< gdp->getNumPoints() << " points: " << filename.CStr() << " " << tree->getMemoryUsage(true) << std::endl;
Expand Down

0 comments on commit 911cc42

Please sign in to comment.