Skip to content

Commit

Permalink
[usdImaging] Fix GprimAdapter::_AddRprim material resolution order to…
Browse files Browse the repository at this point in the history
… be consistent with other functions.

In GetMaterialId (on instancers and gprims) and GprimAdapter::UpdateForTime, we consider the local material binding to take precedence over the instancer material binding.  This is consistent with the basic USD rules, where more local material assignments take precedence.  However, this was flipped in _AddRprim, which would preferentially take the instancer material binding.

For many scene structures, this wasn't causing issues, since only one of the material bindings would be non-empty; or they would point to the same path, which is sketchy but worked in practice.  However, this specifically fixes a bug concerning scenes where a point instancer prototype is marked as instanceable, and the material bound to the prototype is inside the instance; in this case, the old code would have a disagreement about whether the material was named /World/path/to/material or /Prototype_N/path/to/material, and so the relationship in hydra would be broken.

Fixes #1626

(Internal change: 2190000)
  • Loading branch information
tcauchois authored and pixar-oss committed Sep 23, 2021
1 parent 2c060ec commit e0da0a7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pxr/usdImaging/usdImaging/gprimAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ UsdImagingGprimAdapter::_AddRprim(TfToken const& primType,
index->AddDependency(cachePath, usdPrim);
}

// Allow instancer context to override the material binding.
SdfPath resolvedUsdMaterialPath = instancerContext ?
instancerContext->instancerMaterialUsdPath : materialUsdPath;
// If there's no local material path, fall back to the instancer material.
SdfPath resolvedUsdMaterialPath = materialUsdPath;
if (materialUsdPath.IsEmpty() && instancerContext != nullptr) {
resolvedUsdMaterialPath = instancerContext->instancerMaterialUsdPath;
}
UsdPrim materialPrim =
usdPrim.GetStage()->GetPrimAtPath(resolvedUsdMaterialPath);

Expand Down

0 comments on commit e0da0a7

Please sign in to comment.