Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tsd/src/tsd/io/importers/import_NVDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,34 @@ SpatialFieldRef import_NVDB(Scene &scene, const char *filepath)
try {
auto grid = nanovdb::io::readGrid(filepath);
auto metadata = grid.gridMetaData();

bool hasActiveVoxels = false;
switch (metadata->gridType()) {
case nanovdb::GridType::Fp4:
hasActiveVoxels = grid.grid<nanovdb::Fp4>()->activeVoxelCount() > 0;
break;
case nanovdb::GridType::Fp8:
hasActiveVoxels = grid.grid<nanovdb::Fp8>()->activeVoxelCount() > 0;
break;
case nanovdb::GridType::Fp16:
hasActiveVoxels = grid.grid<nanovdb::Fp16>()->activeVoxelCount() > 0;
break;
case nanovdb::GridType::FpN:
hasActiveVoxels = grid.grid<nanovdb::FpN>()->activeVoxelCount() > 0;
break;
case nanovdb::GridType::Float:
hasActiveVoxels = grid.grid<float>()->activeVoxelCount() > 0;
break;
default:
break;
}

if (!hasActiveVoxels) {
logStatus("[import_NVDB] no active voxels, skipping '%s'", filepath);
scene.removeObject(field.data());
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field object is being removed from the scene after it was just created. Consider skipping field creation entirely when there are no active voxels to avoid unnecessary object creation and cleanup overhead. Check for active voxels before creating the field object.

Copilot uses AI. Check for mistakes.
return {};
}

if (!metadata->hasMinMax()) {
switch (metadata->gridType()) {
case nanovdb::GridType::Fp4: {
Expand Down
6 changes: 4 additions & 2 deletions tsd/src/tsd/io/importers/import_USD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,8 @@ static void import_usd_volume(Scene &scene,
VolumeTransferFunction tf = get_volume_transfer_function(prim);

ArrayRef colorArray;
math::float2 valueRange;
// Default to the field's value range to avoid undefined ranges.
math::float2 valueRange = field->computeValueRange();

// Create a volume node and assign the field, color map, and value range
auto [inst, volume] = scene.insertNewChildObjectNode<Volume>(
Expand All @@ -922,7 +923,8 @@ static void import_usd_volume(Scene &scene,
// Use transfer function from USD material
colorArray = scene.createArray(ANARI_FLOAT32_VEC4, tf.colors.size());
colorArray->setData(tf.colors.data(), tf.colors.size());
valueRange = tf.domain;
if (tf.domain.x < tf.domain.y)
valueRange = tf.domain;

// Create opacity control points from USD transfer function
std::vector<math::float2> opacityControlPoints;
Expand Down