- Use material name for file name
- Create in subfolder with name being the input MaterialX name
diff --git a/documents/html/mtlx2usd_8py_source.html b/documents/html/mtlx2usd_8py_source.html
index 344967d..908e90f 100644
--- a/documents/html/mtlx2usd_8py_source.html
+++ b/documents/html/mtlx2usd_8py_source.html
@@ -187,226 +187,230 @@
77 parser.add_argument(
"-sf",
"--subfolder", action=
"store_true", help=
"Save output to subfolder named <input materialx file> w/o extension.")
78 parser.add_argument(
"-pp",
"--preprocess", action=
"store_true", help=
"Attempt to pre-process the MaterialX file.")
79 parser.add_argument(
"-ip",
"--imagepaths", default=
"", help=
"Comma separated list of search paths for image path resolving. ")
-
-
- 82 args = parser.parse_args()
-
-
- 85 input_paths = get_mtlx_files(args.input_file)
- 86 if len(input_paths) == 0:
- 87 logger.info(f
"Error: No MaterialX files found in {args.input_file}")
-
-
- 90 validate_output = args.validate
-
-
-
-
- 95 for input_path
in input_paths:
-
- 97 logger.info(separator)
-
-
-
- 101 subfolder_path = input_path
-
- 103 logger.info(f
"> Pre-processing MaterialX file: {input_path}")
- 104 utils = mxusd_utils.MaterialXUsdUtilities()
- 105 doc = utils.create_document(input_path)
-
- 107 shader_materials_added = utils.add_materials_for_shaders(doc)
- 108 if shader_materials_added:
- 109 logger.info(f
"> Added {shader_materials_added} shader materials to the document")
-
- 111 doc.setDataLibrary(utils.get_standard_libraries())
- 112 implicit_nodes_added = utils.add_explicit_geometry_stream(doc)
- 113 if implicit_nodes_added:
- 114 logger.info(f
"> Added {implicit_nodes_added} explicit geometry nodes to the document")
- 115 num_top_level_nodes = utils.encapsulate_top_level_nodes(doc,
'root_graph')
- 116 if num_top_level_nodes:
- 117 logger.info(f
"> Encapsulated {num_top_level_nodes} top level nodes.")
-
- 119 materials_added = utils.add_downstream_materials(doc)
- 120 materials_added += utils.add_materials_for_shaders(doc)
-
- 122 logger.info(f
'> Added {materials_added} downstream materials.')
-
-
- 125 explicit_outputs_added = utils.add_nodegraph_output_qualifier_on_shaders(doc)
- 126 if explicit_outputs_added:
- 127 logger.info(f
"> Added {explicit_outputs_added} explicit outputs to nodegraph outputs for shader connections")
-
-
-
- 131 resolved_image_paths =
False
- 132 image_paths = args.imagepaths.split(
',')
if args.imagepaths
else []
- 133 image_paths.append(os.path.dirname(os.path.abspath(input_path)))
-
- 135 beforeDoc = mx.prettyPrint(doc)
- 136 mx_image_search_path = utils.create_FileSearchPath(image_paths)
- 137 utils.resolve_image_file_paths(doc, mx_image_search_path)
- 138 afterDoc = mx.prettyPrint(doc)
- 139 if beforeDoc != afterDoc:
- 140 resolved_image_paths =
True
- 141 logger.info(f
"> Resolved image file paths using search paths: {mx_image_search_path}")
- 142 resolved_image_paths =
True
-
- 144 if explicit_outputs_added
or resolved_image_paths
or materials_added > 0
or num_top_level_nodes > 0
or implicit_nodes_added > 0:
- 145 valid, errors = doc.validate()
- 146 doc.setDataLibrary(
None)
-
- 148 logger.warning(f
"> Validation errors: {errors}")
-
- 150 new_input_path = input_path.replace(
'.mtlx',
'_converted.mtlx')
- 151 utils.write_document(doc, new_input_path)
- 152 logger.info(f
"> Saved converted MaterialX document to: {new_input_path}")
- 153 input_path = new_input_path
-
- 155 material_file_path =
''
-
- 157 material_file_path = input_path.replace(
'.mtlx',
'_material.usda')
-
-
-
-
-
-
-
- 165 logger.info(f
"> Build tests scene from material scene: {input_path}")
- 166 abs_geometry_path = os.path.abspath(args.geometry)
- 167 if not os.path.exists(abs_geometry_path):
- 168 logger.info(f
"> Error: Geometry file not found at {abs_geometry_path}")
-
- 170 abs_environment_path = os.path.abspath(args.environment)
- 171 if not os.path.exists(abs_environment_path):
- 172 logger.info(f
"> Error: Environment file not found at {abs_environment_path}")
-
-
- 175 abs_camera_path =
None
- 176 if args.camera ==
"":
- 177 logger.info(f
"> Using computer camera from geometry.")
-
- 179 abs_camera_path = os.path.abspath(args.camera)
- 180 if not os.path.exists(abs_camera_path):
- 181 logger.info(f
"> Camera file not found at {abs_camera_path}")
-
- 183 converter = mxusd.MaterialxUSDConverter()
- 184 stage, found_materials, test_geom_prim, dome_light, camera_prim = converter.mtlx_to_usd(input_path,
-
- 186 abs_environment_path,
-
-
-
-
- 191 output_folder, input_file = os.path.split(input_path)
- 192 output_file = input_file
- 193 unused, subfolder_file = os.path.split(subfolder_path)
-
- 195 if not found_materials:
-
- 197 material_count = len(found_materials)
- 198 multiple_materials = material_count > 1
- 199 if material_count == 0:
-
-
- 202 found_materials.append(
None)
-
-
-
-
-
-
- 209 for found_material
in found_materials:
-
-
- 212 if test_geom_prim
and found_material:
- 213 logger.info(f
"> Bind material to geometry: {found_material.GetName()} to {test_geom_prim.GetPath()}")
- 214 material_binding_api = UsdShade.MaterialBindingAPI(test_geom_prim)
- 215 material_binding_api.Bind(UsdShade.Material(found_material))
-
-
-
- 219 use_material_name = args.useMaterialName
- 220 if multiple_materials:
- 221 use_material_name =
True
- 222 if use_material_name:
-
- 224 found_material_name = found_material.GetName()
-
- 226 output_file = found_material_name +
".usda"
-
-
- 229 sub_folder = output_folder
- 230 if args.render
and args.subfolder:
- 231 subfolder_name = os.path.join(output_folder, subfolder_file.replace(
'.mtlx',
''))
- 232 if not os.path.exists(subfolder_name):
- 233 os.makedirs(subfolder_name)
- 234 sub_folder = subfolder_name
- 235 logger.info(f
"> Override output folder: {subfolder_name}")
-
- 237 output_file = output_file.replace(
'.mtlx',
'.usda')
- 238 output_path = os.path.join(output_folder, output_file)
-
-
- 241 stage.GetRootLayer().documentation = f
"Combined content from: {input_path}, {abs_geometry_path}, {abs_environment_path}."
- 242 stage.GetRootLayer().Export(output_path)
- 243 logger.info(f
"> Save USD file to: {output_path}.")
-
-
-
- 247 errors, warnings, failed_checks = converter.validate_stage(output_path)
- 248 print_validation_results(output_path, errors, warnings, failed_checks)
-
-
-
-
-
- 254 if args.render
and found_material:
-
-
-
- 258 sub_folder_path = os.path.join(sub_folder, output_file)
- 259 render_path = sub_folder_path.replace(
'.usda', f
'_{args.shadingLanguage}.png')
-
- 261 render_path = output_path.replace(
'.usda', f
'_{args.shadingLanguage}.png')
- 262 render_command = f
'usdrecord "{output_path}" "{render_path}" --disableCameraLight --imageWidth 512'
-
- 264 render_command += f
' --camera "{camera_prim.GetName()}"'
- 265 logger.info(f
"> Rendering using command: {render_command}")
-
- 267 os.system(f
"{render_command} > nul 2>&1" if os.name ==
"nt" else f
"{render_command} > /dev/null 2>&1")
-
- 269 logger.info(
"> Rendering complete.")
-
-
-
-
-
-
- 276 flattened_layer =
None
- 277 need_flattening = args.zip
or args.flatten
-
- 279 logger.info(
"> Flattening the stage.")
- 280 flattened_layer = converter.get_flattend_layer(stage)
-
-
-
-
- 285 usdz_file_path = input_path.replace(
'.mtlx',
'.usdz')
- 286 usdz_created, error = converter.create_usdz_package(usdz_file_path, flattened_layer)
-
- 288 logger.info(f
"> Error: {error}")
-
-
-
- 292 flattend_path = converter.save_flattened_layer(flattened_layer, output_path)
- 293 logger.info(f
"> Flattened USD file saved to: {flattend_path}.")
-
- 295 done_message =
"-" * 80 +
"\n> Done."
- 296 logger.info(done_message)
-
- 298if __name__ ==
"__main__":
-
+ 80 parser.add_argument(
"-ra",
"--renderargs", default=
"", help=
"Additional render arguments.")
+
+
+ 83 args = parser.parse_args()
+
+
+ 86 input_paths = get_mtlx_files(args.input_file)
+ 87 if len(input_paths) == 0:
+ 88 logger.info(f
"Error: No MaterialX files found in {args.input_file}")
+
+
+ 91 validate_output = args.validate
+
+
+
+
+ 96 for input_path
in input_paths:
+
+ 98 logger.info(separator)
+
+
+
+ 102 subfolder_path = input_path
+
+ 104 logger.info(f
"> Pre-processing MaterialX file: {input_path}")
+ 105 utils = mxusd_utils.MaterialXUsdUtilities()
+ 106 doc = utils.create_document(input_path)
+
+ 108 shader_materials_added = utils.add_materials_for_shaders(doc)
+ 109 if shader_materials_added:
+ 110 logger.info(f
"> Added {shader_materials_added} shader materials to the document")
+
+ 112 doc.setDataLibrary(utils.get_standard_libraries())
+ 113 implicit_nodes_added = utils.add_explicit_geometry_stream(doc)
+ 114 if implicit_nodes_added:
+ 115 logger.info(f
"> Added {implicit_nodes_added} explicit geometry nodes to the document")
+ 116 num_top_level_nodes = utils.encapsulate_top_level_nodes(doc,
'root_graph')
+ 117 if num_top_level_nodes:
+ 118 logger.info(f
"> Encapsulated {num_top_level_nodes} top level nodes.")
+
+ 120 materials_added = utils.add_downstream_materials(doc)
+ 121 materials_added += utils.add_materials_for_shaders(doc)
+
+ 123 logger.info(f
'> Added {materials_added} downstream materials.')
+
+
+ 126 explicit_outputs_added = utils.add_nodegraph_output_qualifier_on_shaders(doc)
+ 127 if explicit_outputs_added:
+ 128 logger.info(f
"> Added {explicit_outputs_added} explicit outputs to nodegraph outputs for shader connections")
+
+
+
+ 132 resolved_image_paths =
False
+ 133 image_paths = args.imagepaths.split(
',')
if args.imagepaths
else []
+ 134 image_paths.append(os.path.dirname(os.path.abspath(input_path)))
+
+ 136 beforeDoc = mx.prettyPrint(doc)
+ 137 mx_image_search_path = utils.create_FileSearchPath(image_paths)
+ 138 utils.resolve_image_file_paths(doc, mx_image_search_path)
+ 139 afterDoc = mx.prettyPrint(doc)
+ 140 if beforeDoc != afterDoc:
+ 141 resolved_image_paths =
True
+ 142 logger.info(f
"> Resolved image file paths using search paths: {mx_image_search_path}")
+ 143 resolved_image_paths =
True
+
+ 145 if explicit_outputs_added
or resolved_image_paths
or materials_added > 0
or num_top_level_nodes > 0
or implicit_nodes_added > 0:
+ 146 valid, errors = doc.validate()
+ 147 doc.setDataLibrary(
None)
+
+ 149 logger.warning(f
"> Validation errors: {errors}")
+
+ 151 new_input_path = input_path.replace(
'.mtlx',
'_converted.mtlx')
+ 152 utils.write_document(doc, new_input_path)
+ 153 logger.info(f
"> Saved converted MaterialX document to: {new_input_path}")
+ 154 input_path = new_input_path
+
+ 156 material_file_path =
''
+
+ 158 material_file_path = input_path.replace(
'.mtlx',
'_material.usda')
+
+
+
+
+
+
+
+ 166 logger.info(f
"> Build tests scene from material scene: {input_path}")
+ 167 abs_geometry_path = os.path.abspath(args.geometry)
+ 168 if not os.path.exists(abs_geometry_path):
+ 169 logger.info(f
"> Error: Geometry file not found at {abs_geometry_path}")
+
+ 171 abs_environment_path = os.path.abspath(args.environment)
+ 172 if not os.path.exists(abs_environment_path):
+ 173 logger.info(f
"> Error: Environment file not found at {abs_environment_path}")
+
+
+ 176 abs_camera_path =
None
+ 177 if args.camera ==
"":
+ 178 logger.info(f
"> Using computer camera from geometry.")
+
+ 180 abs_camera_path = os.path.abspath(args.camera)
+ 181 if not os.path.exists(abs_camera_path):
+ 182 logger.info(f
"> Camera file not found at {abs_camera_path}")
+
+ 184 converter = mxusd.MaterialxUSDConverter()
+ 185 stage, found_materials, test_geom_prim, dome_light, camera_prim = converter.mtlx_to_usd(input_path,
+
+ 187 abs_environment_path,
+
+
+
+
+ 192 output_folder, input_file = os.path.split(input_path)
+ 193 output_file = input_file
+ 194 unused, subfolder_file = os.path.split(subfolder_path)
+
+ 196 if not found_materials:
+
+ 198 material_count = len(found_materials)
+ 199 multiple_materials = material_count > 1
+ 200 if material_count == 0:
+
+
+ 203 found_materials.append(
None)
+
+
+
+
+
+
+ 210 for found_material
in found_materials:
+
+
+ 213 if test_geom_prim
and found_material:
+ 214 logger.info(f
"> Bind material to geometry: {found_material.GetName()} to {test_geom_prim.GetPath()}")
+ 215 material_binding_api = UsdShade.MaterialBindingAPI(test_geom_prim)
+ 216 material_binding_api.Bind(UsdShade.Material(found_material))
+
+
+
+ 220 use_material_name = args.useMaterialName
+ 221 if multiple_materials:
+ 222 use_material_name =
True
+ 223 if use_material_name:
+
+ 225 found_material_name = found_material.GetName()
+
+ 227 output_file = found_material_name +
".usda"
+
+
+ 230 sub_folder = output_folder
+ 231 if args.render
and args.subfolder:
+ 232 subfolder_name = os.path.join(output_folder, subfolder_file.replace(
'.mtlx',
''))
+ 233 if not os.path.exists(subfolder_name):
+ 234 os.makedirs(subfolder_name)
+ 235 sub_folder = subfolder_name
+ 236 logger.info(f
"> Override output folder: {subfolder_name}")
+
+ 238 output_file = output_file.replace(
'.mtlx',
'.usda')
+ 239 output_path = os.path.join(output_folder, output_file)
+
+
+ 242 stage.GetRootLayer().documentation = f
"Combined content from: {input_path}, {abs_geometry_path}, {abs_environment_path}."
+ 243 stage.GetRootLayer().Export(output_path)
+ 244 logger.info(f
"> Save USD file to: {output_path}.")
+
+
+
+ 248 errors, warnings, failed_checks = converter.validate_stage(output_path)
+ 249 print_validation_results(output_path, errors, warnings, failed_checks)
+
+
+
+
+
+ 255 if args.render
and found_material:
+
+
+
+ 259 sub_folder_path = os.path.join(sub_folder, output_file)
+ 260 render_path = sub_folder_path.replace(
'.usda', f
'_{args.shadingLanguage}.png')
+
+ 262 render_path = output_path.replace(
'.usda', f
'_{args.shadingLanguage}.png')
+ 263 render_command = f
'usdrecord "{output_path}" "{render_path}" --disableCameraLight --imageWidth 512'
+
+ 265 render_command += f
' --camera "{camera_prim.GetName()}"'
+ 266 logger.info(f
"> Rendering using command: {render_command}")
+
+ 268 render_command += f
' {args.renderargs}'
+ 269 print(
'>'*20, render_command)
+
+ 271 os.system(f
"{render_command} > nul 2>&1" if os.name ==
"nt" else f
"{render_command} > /dev/null 2>&1")
+
+ 273 logger.info(
"> Rendering complete.")
+
+
+
+
+
+
+ 280 flattened_layer =
None
+ 281 need_flattening = args.zip
or args.flatten
+
+ 283 logger.info(
"> Flattening the stage.")
+ 284 flattened_layer = converter.get_flattend_layer(stage)
+
+
+
+
+ 289 usdz_file_path = input_path.replace(
'.mtlx',
'.usdz')
+ 290 usdz_created, error = converter.create_usdz_package(usdz_file_path, flattened_layer)
+
+ 292 logger.info(f
"> Error: {error}")
+
+
+
+ 296 flattend_path = converter.save_flattened_layer(flattened_layer, output_path)
+ 297 logger.info(f
"> Flattened USD file saved to: {flattend_path}.")
+
+ 299 done_message =
"-" * 80 +
"\n> Done."
+ 300 logger.info(done_message)
+
+ 302if __name__ ==
"__main__":
+
diff --git a/index.html b/index.html
index 7cadd87..4bf61f3 100644
--- a/index.html
+++ b/index.html
@@ -125,10 +125,10 @@ Available Components
attempt to produce valid USD shading network (See Support Utilities)