For completeness, I have attached the creation/update code for the instancers.
After further debuging I also have a lot of error messages but I’m not quite sure why… (The prims have colliders)
Both are available below, I’m sure I forgot something when instantiating the instancer.
Best,
Antoine
Instancer code:
class Instancer:
"""
Point instancer.
"""
def __init__(self, instancer_path: str, assets_path: str, seed: int):
"""
Args:
instancer_path (str): The path to the instancer.
assets_path (str): The path to the assets folder.
seed (int): The seed for the random number generator.
"""
self.instancer_path = instancer_path
self.stage = omni.usd.get_context().get_stage()
self.assets_path = assets_path
self.prototypes = []
self.get_asset_list()
self.createInstancer()
self.rng = np.random.default_rng(seed=seed)
def get_asset_list(self):
"""
Get the list of assets in the assets folder.
"""
self.file_paths = [
os.path.join(self.assets_path, file)
for file in os.listdir(self.assets_path)
if file.endswith(".usd")
]
print(self.file_paths)
print(len(self.file_paths))
def createInstancer(self):
"""
Create the instancer.
"""
self.instancer_path = omni.usd.get_stage_next_free_path(
self.stage, self.instancer_path, False
)
self.instancer_prim = self.stage.DefinePrim(self.instancer_path, "Xform")
self.instancer = UsdGeom.PointInstancer.Define(self.stage, self.instancer_path)
for i, file_path in enumerate(self.file_paths):
prim = self.stage.DefinePrim(
os.path.join(self.instancer_path, "asset_" + str(i)), "Xform"
)
prim.GetReferences().AddReference(file_path)
self.instancer.GetPrototypesRel().AddTarget(prim.GetPath())
self.setInstancerParameters(
np.array([[0, 0, 0]]),
np.array([[0, 0, 0, 1]]),
np.array([[1, 1, 1]]),
np.array([0]),
)
def setInstancerParameters(self, positions, orientations, scales, ids):
"""
Set the instancer parameters.
"""
print("positions shape", positions.shape)
print("orientations shape", orientations.shape)
print("scales shape", scales.shape)
print("ids shape", ids.shape)
print("num prototypes rel", len(self.instancer.GetPrototypesRel().GetTargets()))
start = time.time()
self.instancer.GetPositionsAttr().Set(positions)
self.instancer.GetOrientationsAttr().Set(orientations)
self.instancer.GetScalesAttr().Set(scales)
self.instancer.GetProtoIndicesAttr().Set(ids)
end = time.time()
print("Set instancer parameters took", end - start, "seconds")
Print outputs from code:
positions shape (80002, 3)
orientations shape (80002, 4)
scales shape (80002, 3)
ids shape (80002,)
num prototypes rel 23
Set instancer parameters took 66.27125883102417 seconds
Some of the warnings being raised all the time:
2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning: in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 5 out of bounds (prototypes size = 1) for (/World/rock_instancers/very_small_rock_instancer, /World/rock_instancers/very_small_rock_instancer.proto5_rock_37_id0)
2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 11 out of bounds (prototypes size = 1) for (/World/rock_instancers/large_rock_instancer, /World/rock_instancers/large_rock_instancer.proto11_rock_3_id0)
2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 3 out of bounds (prototypes size = 1) for (/World/rock_instancers/large_rock_instancer, /World/rock_instancers/large_rock_instancer.proto3_rock_45_id0)
2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning: in GetInstanceIndices at line 3256 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/delegate.cpp -- Empty InstanceIndices (/World/rock_instancers/very_small_rock_instancer, /World/rock_instancers/very_small_rock_instancer.proto5_rock_37_id0)
2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 3256 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/delegate.cpp -- Empty InstanceIndices (/World/rock_instancers/large_rock_instancer, /World/rock_instancers/large_rock_instancer.proto3_rock_45_id0)
2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 5 out of bounds (prototypes size = 1) for (/World/rock_instancers/large_rock_instancer, /World/rock_instancers/large_rock_instancer.proto5_rock_37_id0)
2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 3256 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/delegate.cpp -- Empty InstanceIndices (/World/rock_instancers/large_rock_instancer, /World/rock_instancers/large_rock_instancer.proto11_rock_3_id0)
2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 20 out of bounds (prototypes size = 1) for (/World/rock_instancers/large_rock_instancer, /World/rock_instancers/large_rock_instancer.proto20_rock_21_id0)
2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 1 out of bounds (prototypes size = 1) for (/World/rock_instancers/very_small_rock_instancer, /World/rock_instancers/very_small_rock_instancer.proto1_rock_17_id0)
2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 4 out of bounds (prototypes size = 1) for (/World/rock_instancers/very_small_rock_instancer, /World/rock_instancers/very_small_rock_instancer.proto4_rock_48_id0)
2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 17 out of bounds (prototypes size = 1) for (/World/rock_instancers/very_small_rock_instancer, /World/rock_instancers/very_small_rock_instancer.proto17_rock_31_id0)
2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 1 out of bounds (prototypes size = 1) for (/World/rock_instancers/large_rock_instancer, /World/rock_instancers/large_rock_instancer.proto1_rock_17_id0)
2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 14 out of bounds (prototypes size = 1) for (/World/rock_instancers/very_small_rock_instancer, /World/rock_instancers/very_small_rock_instancer.proto14_rock_13_id0)
2024-08-25 13:46:31 [13,424ms] [Warning] [omni.hydra.scene_delegate.plugin] Calling getBypassRenderSkelMeshProcessing for prim /World/rock_instancers/large_rock_instancer.proto3_rock_45_id0 that has not been populated
2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 3256 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/delegate.cpp -- Empty InstanceIndices (/World/rock_instancers/very_small_rock_instancer, /World/rock_instancers/very_small_rock_instancer.proto4_rock_48_id0)