def add_hair(app, params, path_for_objects, stage, xsi_hair, materials_opt, root_path, progress_bar=None): imp.reload(utils) imp.reload(prim_xform) imp.reload(materials) usd_xform, ref_stage, ref_stage_asset = prim_xform.add_xform( app, params, path_for_objects, True, stage, xsi_hair, root_path) usd_curves = UsdGeom.BasisCurves.Define( ref_stage, str(usd_xform.GetPath()) + "/" + xsi_hair.Name) usd_curves_prim = ref_stage.GetPrimAtPath(usd_curves.GetPath()) materials.add_material(materials_opt, xsi_hair.Material, ref_stage, ref_stage_asset, usd_xform, usd_curves_prim) opt_animation = params.get("animation", None) if opt_animation is None: set_hair_at_frame(app, xsi_hair, usd_curves, usd_curves_prim) else: for frame in range(opt_animation[0], opt_animation[1] + 1): if progress_bar is not None: progress_bar.Caption = utils.build_export_object_caption( xsi_hair, frame) set_hair_at_frame(app, xsi_hair, usd_curves, usd_curves_prim, frame) ref_stage.Save() return stage.GetPrimAtPath(root_path + str(usd_xform.GetPath()))
def add_pointcloud(app, params, path_for_objects, stage, pointcloud_object, materials_opt, root_path, progress_bar=None): if DEBUG_MODE: imp.reload(prim_xform) imp.reload(materials) imp.reload(utils) opt_animation = params.get("animation", None) usd_xform, ref_stage, ref_stage_asset = prim_xform.add_xform( app, params, path_for_objects, True, stage, pointcloud_object, root_path) usd_points = UsdGeom.Points.Define( ref_stage, str(usd_xform.GetPath()) + "/" + "Pointcloud") usd_points_prim = ref_stage.GetPrimAtPath(usd_points.GetPath()) materials.add_material(materials_opt, pointcloud_object.Material, ref_stage, ref_stage_asset, usd_xform, usd_points_prim) opt = params.get("options", {}) if opt_animation is None or not utils.is_poincloud_animated( pointcloud_object, opt_animation): set_pointcloud_at_frame( pointcloud_object.GetActivePrimitive3().Geometry, usd_points, usd_points_prim) else: for frame in range(opt_animation[0], opt_animation[1] + 1): if progress_bar is not None: progress_bar.Caption = utils.build_export_object_caption( pointcloud_object, frame) if opt.get("force_change_frame", False): app.SetValue("PlayControl.Current", frame, "") app.SetValue("PlayControl.Key", frame, "") set_pointcloud_at_frame(pointcloud_object.GetActivePrimitive3( frame).GetGeometry3(frame), usd_points, usd_points_prim, frame=frame) return stage.GetPrimAtPath(root_path + str(usd_xform.GetPath()))
def add_pointcloud(app, params, path_for_objects, stage, pointcloud_object, materials_opt, root_path, progress_bar=None): imp.reload(prim_xform) imp.reload(materials) imp.reload(utils) opt_animation = params.get("animation", None) usd_xform, ref_stage, ref_stage_asset = prim_xform.add_xform( app, params, path_for_objects, True, stage, pointcloud_object, root_path) usd_points = UsdGeom.Points.Define( ref_stage, str(usd_xform.GetPath()) + "/" + "Pointcloud") usd_points_prim = ref_stage.GetPrimAtPath(usd_points.GetPath()) materials.add_material(materials_opt, pointcloud_object.Material, ref_stage, ref_stage_asset, usd_xform, usd_points_prim) if opt_animation is None: set_pointcloud_at_frame( pointcloud_object.GetActivePrimitive3().Geometry, usd_points, usd_points_prim) else: for frame in range(opt_animation[0], opt_animation[1] + 1): if progress_bar is not None: progress_bar.Caption = utils.build_export_object_caption( pointcloud_object, frame) set_pointcloud_at_frame(pointcloud_object.GetActivePrimitive3( frame).GetGeometry3(frame), usd_points, usd_points_prim, frame=frame) return stage.GetPrimAtPath(root_path + str(usd_xform.GetPath()))
def export_step(app, params, path_for_objects, stage, obj, exported_objects, materials_opt, root_path, progress_bar=None): opt_object_types = params.get("object_types", ()) opt = params.get("options", {}) obj_type = obj.Type if progress_bar is not None: progress_bar.Caption = utils.build_export_object_caption(obj) if obj.ObjectID not in exported_objects: usd_pointer = None if obj_type == constants.siPolyMeshType and obj_type in opt_object_types: # mesh usd_pointer = prim_mesh.add_mesh(app, params, path_for_objects, stage, obj, materials_opt, root_path, progress_bar) elif obj_type == constants.siCameraPrimType and obj_type in opt_object_types: # camera usd_pointer = prim_camera.add_camera(app, params, path_for_objects, stage, obj, root_path) elif obj_type == constants.siLightPrimType and obj_type in opt_object_types: # light usd_pointer = prim_light.add_light(app, params, path_for_objects, stage, obj, root_path) elif obj_type == "hair" and obj_type in opt_object_types: # xsi hair usd_pointer = prim_hair.add_hair(app, params, path_for_objects, stage, obj, materials_opt, root_path, progress_bar) elif obj_type == "pointcloud" and obj_type in opt_object_types and utils.is_stands( obj) and "strands" in opt_object_types: # strands hair usd_pointer = prim_hair.add_strands(app, params, path_for_objects, stage, obj, materials_opt, root_path, progress_bar) elif obj_type == "pointcloud" and obj_type in opt_object_types and not utils.is_stands( obj): # pointcloud usd_pointer = prim_pointcloud.add_pointcloud( app, params, path_for_objects, stage, obj, materials_opt, root_path, progress_bar) elif obj_type == constants.siModelType: # model master = obj.InstanceMaster if master is None: # this is model # for models does not go to it childrens, because all models export as separate usd-files prim_model.add_model(app, params, path_for_objects, stage, obj, materials_opt, root_path) exported_objects.append(obj.ObjectID) else: # this is an instance of the model master_id = master.ObjectID if master_id not in exported_objects: # master is not exported, do this prim_model.add_model(app, params, path_for_objects, stage, master, materials_opt, root_path) exported_objects.append(master.ObjectID) # next export the link of the instance usd_model = stage.DefinePrim(root_path + "/" + obj.Name) usd_model.GetReferences().AddReference( "./" + utils.get_last_folder(path_for_objects) + "/" + master.FullName + ".usda", "/" + master.Name) usd_model.SetInstanceable(True) usd_pointer = UsdGeom.Xformable(usd_model) prim_xform.add_transform_to_xfo(usd_pointer, obj, params.get("animation", None)) prim_xform.add_visibility_to_xfo(usd_pointer, obj) elif (obj_type == constants.siNullPrimType and constants.siNullPrimType in opt_object_types) or ( obj_type == "CameraRoot" and constants.siCameraPrimType in opt_object_types): # null usd_pointer, ref_stage, ref_stage_asset = prim_xform.add_xform( app, params, path_for_objects, False, stage, obj, root_path) elif obj_type in [ "cyclesPoint", "cyclesSun", "cyclesSpot", "cyclesArea", "cyclesBackground" ]: # cycles light usd_pointer = prim_light.add_cycles_light(app, params, path_for_objects, stage, obj, materials_opt, root_path) else: if obj_type != "CameraInterest": # camera interest can be recteated from cameta transform and focus distance if not opt.get("ignore_unknown", True): # all unsupported object are nulls, so they are Xforms print("Unknown object " + obj_type + ". Degrade to xform") usd_pointer, ref_stage, ref_stage_asset = prim_xform.add_xform( app, params, path_for_objects, False, stage, obj, root_path) # continue recirsive process if usd_pointer is not None: exported_objects.append(obj.ObjectID) for child in obj.Children: export_step(app, params, path_for_objects, stage, child, exported_objects, materials_opt, str(usd_pointer.GetPath()), progress_bar)