@@ -204,35 +204,37 @@ def convert_mesh_to_usd(input_file, output_file):
204204 # Create a unique path for each mesh
205205 node_path = f"/World/{ node_name } "
206206 xform = UsdGeom .Xform .Define (stage , node_path )
207+ # Define the Mesh under the Xform
208+ mesh_path = f"{ node_path } /Mesh"
209+ usd_mesh = UsdGeom .Mesh .Define (stage , mesh_path )
207210 # get the geometry of the node
208211 geometry = mesh .geometry [geom_name ]
209- usd_mesh = UsdGeom .Mesh .Define (stage , node_path )
210212
211213 # Create a random color for this mesh
212214 # Using HSV for better color distribution
213215 h = random .random () # Random hue
214216 s = 0.7 + 0.3 * random .random () # Saturation between 0.7-1.0
215217 v = 0.7 + 0.3 * random .random () # Value between 0.7-1.0
216218 r , g , b = colorsys .hsv_to_rgb (h , s , v )
217-
219+
218220 # Create a material with the random color
219221 mat_name = f"{ node_name } _material"
220222 mat_path = f"{ materials_path } /{ mat_name } "
221223 material = UsdShade .Material .Define (stage , mat_path )
222-
224+
223225 # Create shader
224226 shader = UsdShade .Shader .Define (stage , f"{ mat_path } /PreviewSurface" )
225227 shader .CreateIdAttr ("UsdPreviewSurface" )
226-
228+
227229 # Set the random color
228230 shader .CreateInput ("diffuseColor" , Sdf .ValueTypeNames .Color3f ).Set (Gf .Vec3f (r , g , b ))
229231 shader .CreateInput ("roughness" , Sdf .ValueTypeNames .Float ).Set (0.4 )
230-
232+
231233 # Connect shader to material
232234 material_output = material .CreateOutput ("surface" , Sdf .ValueTypeNames .Token )
233235 shader_output = shader .CreateOutput ("surface" , Sdf .ValueTypeNames .Token )
234236 material_output .ConnectToSource (shader_output )
235-
237+
236238 # Bind material to mesh
237239 UsdShade .MaterialBindingAPI (usd_mesh ).Bind (material )
238240
0 commit comments