Skip to content

Commit c4598d6

Browse files
authored
Merge pull request #1084 from danrbailey/mergesopprimitive
Copy primitive attributes and grid names in VDB Merge SOP for 2nd inputs
2 parents 46df436 + 15da821 commit c4598d6

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

openvdb_houdini/openvdb_houdini/SOP_OpenVDB_Merge.cc

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,15 @@ struct MergeOp
277277

278278
struct OutputGrid
279279
{
280-
explicit OutputGrid(GridBase::Ptr _grid, GEO_PrimVDB* _primitive = nullptr)
281-
: grid(_grid), primitive(_primitive) { }
280+
explicit OutputGrid(GridBase::Ptr _grid, GEO_PrimVDB* _primitive = nullptr,
281+
const GEO_PrimVDB* _referencePrimitive = nullptr)
282+
: grid(_grid)
283+
, primitive(_primitive)
284+
, referencePrimitive(_referencePrimitive) { }
282285

283286
GridBase::Ptr grid;
284287
GEO_PrimVDB* primitive = nullptr;
288+
const GEO_PrimVDB* referencePrimitive = nullptr;
285289
};
286290

287291
using OutputGrids = std::deque<OutputGrid>;
@@ -399,11 +403,12 @@ struct MergeOp
399403
result.emplace_back(gridBase, vdbPrim);
400404
};
401405

402-
auto copyTree = [&](auto& gridBase, GU_PrimVDB* vdbPrim = nullptr)
406+
auto copyTree = [&](auto& gridBase, GU_PrimVDB* vdbPrim = nullptr,
407+
const GU_PrimVDB* constVdbPrim = nullptr)
403408
{
404409
auto grid = GridBase::grid<GridT>(gridBase);
405410
// insert an empty shared pointer and asynchronously replace with a deep copy
406-
result.emplace_back(GridBase::Ptr(), vdbPrim);
411+
result.emplace_back(GridBase::Ptr(), vdbPrim, constVdbPrim);
407412
OutputGrid& output = result.back();
408413
tasks.run(
409414
[&, grid] {
@@ -430,7 +435,7 @@ struct MergeOp
430435
if (key != mergeKey) continue;
431436

432437
GridBase::ConstPtr gridBase = constVdbPrim->getConstGridPtr();
433-
copyTree(gridBase);
438+
copyTree(gridBase, nullptr, constVdbPrim);
434439
}
435440

436441
if (interrupt.wasInterrupted())
@@ -488,12 +493,12 @@ struct MergeOp
488493
if (!reference) reference = gridBase;
489494
};
490495

491-
auto copyTree = [&](auto& gridBase, GU_PrimVDB* vdbPrim = nullptr)
496+
auto copyTree = [&](auto& gridBase, GU_PrimVDB* vdbPrim = nullptr, const GU_PrimVDB* constVdbPrim = nullptr)
492497
{
493498
auto grid = GridBase::grid<GridT>(gridBase);
494499
if (!reference) reference = grid->copyWithNewTree();
495500
// insert a reference and asynchronously replace with a deep copy
496-
result.emplace_back(reference, vdbPrim);
501+
result.emplace_back(reference, vdbPrim, constVdbPrim);
497502
OutputGrid& output = result.back();
498503
tasks.run(
499504
[&, grid] {
@@ -542,7 +547,7 @@ struct MergeOp
542547
if (key != mergeKey) continue;
543548

544549
GridBase::ConstPtr gridBase = constVdbPrim->getConstGridPtr();
545-
if ((!reference) || op.empty()) copyTree(gridBase);
550+
if ((!reference) || op.empty()) copyTree(gridBase, nullptr, constVdbPrim);
546551
else addConstTree(gridBase);
547552
}
548553

@@ -691,7 +696,12 @@ SOP_OpenVDB_Merge::Cache::cookVDBSop(OP_Context& context)
691696
if (!grid) continue;
692697
GEO_PrimVDB* primitive = outputGrid.primitive;
693698
if (primitive) hvdb::replaceVdbPrimitive(*gdp, grid, *primitive);
694-
else hvdb::createVdbPrimitive(*gdp, grid);
699+
else {
700+
const GEO_PrimVDB* referencePrimitive = outputGrid.referencePrimitive;
701+
GU_PrimVDB::buildFromGrid(*gdp, grid,
702+
/*copyAttrsFrom=*/bool(referencePrimitive) ? referencePrimitive : nullptr,
703+
/*gridName=*/bool(referencePrimitive) ? referencePrimitive->getGridName() : nullptr);
704+
}
695705
}
696706
}
697707

0 commit comments

Comments
 (0)