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_light(app, params, path_for_objects, stage, xsi_light, root_path): # here me add only basic parameters, all other will be defined in the material imp.reload(materials) # basic transform usd_xform, ref_stage, ref_stage_asset = add_xform(app, params, path_for_objects, True, stage, xsi_light, root_path) # get the type of the light xsi_light_type = xsi_light.Parameters("Type").Value usd_light = None xsi_geom_type = -1 if xsi_light_type == 0: # point (also area light) xsi_is_area = xsi_light.Parameters("LightArea").Value xsi_geom_type = xsi_light.Parameters("LightAreaGeom").Value if xsi_is_area: if xsi_geom_type == 1: # rectangular usd_light = UsdLux.RectLight.Define(ref_stage, str(usd_xform.GetPath()) + "/" + xsi_light.Name) elif xsi_geom_type == 2: # disc usd_light = UsdLux.DiskLight.Define(ref_stage, str(usd_xform.GetPath()) + "/" + xsi_light.Name) elif xsi_geom_type == 3: # sphere usd_light = UsdLux.SphereLight.Define(ref_stage, str(usd_xform.GetPath()) + "/" + xsi_light.Name) elif xsi_geom_type == 4: # cylinder usd_light = UsdLux.CylinderLight.Define(ref_stage, str(usd_xform.GetPath()) + "/" + xsi_light.Name) elif xsi_light_type == 1: # infinite usd_light = UsdLux.DistantLight.Define(ref_stage, str(usd_xform.GetPath()) + "/" + xsi_light.Name) elif xsi_light_type == 2: # spot usd_light = UsdLux.DistantLight.Define(ref_stage, str(usd_xform.GetPath()) + "/" + xsi_light.Name) # export light shader to material materials_opt = params.get("materials", None) if materials_opt is not None: is_materials = materials_opt.get("is_materials", True) if is_materials: usd_material = UsdShade.Material.Define(ref_stage, str(usd_xform.GetPath()) + "/Shader") xsi_root_shader = xsi_light.Parameters("LightShader") if xsi_root_shader is not None: materials.set_material_complete(xsi_root_shader, ref_stage, usd_material) # bind shader to the light UsdShade.MaterialBindingAPI(usd_light).Bind(usd_material) if usd_light is not None: # set neutral color usd_light.CreateColorAttr().Set((1.0, 1.0, 1.0)) # diffuse and specular coefficients xsi_is_diffuse = xsi_light.Parameters("DiffuseContribution").Value xsi_is_specular = xsi_light.Parameters("SpecularContribution").Value usd_light.CreateDiffuseAttr().Set(1.0 if xsi_is_diffuse else 0.0) usd_light.CreateSpecularAttr().Set(1.0 if xsi_is_specular else 0.0) # default intensity = 1.0 usd_light.CreateIntensityAttr().Set(1.0) # set animated parameters opt_animation = params["animation"] if opt_animation is None: set_light_at_frame(xsi_light, xsi_light_type, xsi_geom_type, usd_light) if opt_animation is not None: for frame in range(opt_animation[0], opt_animation[1] + 1): set_light_at_frame(xsi_light, xsi_light_type, xsi_geom_type, usd_light, frame) ref_stage.Save() return stage.GetPrimAtPath(root_path + str(usd_xform.GetPath()))
def add_cycles_light(app, params, path_for_objects, stage, cyc_light, materials_opt, root_path): usd_xform, ref_stage, ref_stage_asset = add_xform(app, params, path_for_objects, True, stage, cyc_light, root_path) light_type = cyc_light.Type usd_light = None anim_opt = params.get("animation", None) if light_type == "cyclesPoint": usd_light = UsdLux.SphereLight.Define(ref_stage, str(usd_xform.GetPath()) + "/" + cyc_light.Name) set_color(usd_light, (1.0, 1.0, 1.0), anim_opt) set_diffuse(usd_light, cyc_light.Parameters("use_diffuse"), anim_opt) set_specular(usd_light, cyc_light.Parameters("use_glossy"), anim_opt) set_intensity(usd_light, cyc_light.Parameters("power"), anim_opt) set_radius(usd_light, cyc_light.Parameters("size"), anim_opt) elif light_type == "cyclesSun": usd_light = UsdLux.DistantLight.Define(ref_stage, str(usd_xform.GetPath()) + "/" + cyc_light.Name) set_color(usd_light, (1.0, 1.0, 1.0), anim_opt) set_diffuse(usd_light, cyc_light.Parameters("use_diffuse"), anim_opt) set_specular(usd_light, cyc_light.Parameters("use_glossy"), anim_opt) set_intensity(usd_light, cyc_light.Parameters("power"), anim_opt) set_distance_angle(usd_light, cyc_light.Parameters("angle"), anim_opt) elif light_type == "cyclesSpot": # spot light is not supported by usd pass elif light_type == "cyclesArea": xsi_portal = cyc_light.Parameters("is_portal") if xsi_portal is not None and xsi_portal.Value: usd_light = UsdLux.LightPortal.Define(ref_stage, str(usd_xform.GetPath()) + "/" + cyc_light.Name) else: xsi_shape = cyc_light.Parameters("shape") if xsi_shape is not None: xsi_shape_value = xsi_shape.Value if xsi_shape_value < 0.5: usd_light = UsdLux.RectLight.Define(ref_stage, str(usd_xform.GetPath()) + "/" + cyc_light.Name) set_color(usd_light, (1.0, 1.0, 1.0), anim_opt) set_diffuse(usd_light, cyc_light.Parameters("use_diffuse"), anim_opt) set_specular(usd_light, cyc_light.Parameters("use_glossy"), anim_opt) set_intensity(usd_light, cyc_light.Parameters("power"), anim_opt) set_rect_size(usd_light, cyc_light.Parameters("sizeU"), cyc_light.Parameters("sizeV"), anim_opt) else: usd_light = UsdLux.DiskLight.Define(ref_stage, str(usd_xform.GetPath()) + "/" + cyc_light.Name) set_color(usd_light, (1.0, 1.0, 1.0), anim_opt) set_diffuse(usd_light, cyc_light.Parameters("use_diffuse"), anim_opt) set_specular(usd_light, cyc_light.Parameters("use_glossy"), anim_opt) set_intensity(usd_light, cyc_light.Parameters("power"), anim_opt) set_ellipse_radius(usd_light, cyc_light.Parameters("sizeU"), cyc_light.Parameters("sizeV"), anim_opt) elif light_type == "cyclesBackground": usd_light = UsdLux.DomeLight.Define(ref_stage, str(usd_xform.GetPath()) + "/" + cyc_light.Name) set_color(usd_light, (1.0, 1.0, 1.0), anim_opt) set_diffuse(usd_light, None, anim_opt, value=1.0) set_specular(usd_light, None, anim_opt, value=1.0) if usd_light is not None: usd_light_prim = ref_stage.GetPrimAtPath(usd_light.GetPath()) materials.add_material(materials_opt, cyc_light.Material, ref_stage, ref_stage_asset, usd_xform, usd_light_prim) return stage.GetPrimAtPath(root_path + str(usd_xform.GetPath()))
def add_model(app, params, path_for_objects, stage, model_object, materials_opt, root_path): imp.reload(prim_xform) imp.reload(export_processor) usd_xform, ref_stage, ref_stage_asset = add_xform(app, params, path_for_objects, True, stage, model_object, root_path, is_instance=True) model_objects = [] # create new folder for model subobjects model_path_for_objects = path_for_objects + model_object.Name + "_objects\\" # change path in materials_opt, add new .. for obj in model_object.Children: export_processor.export_step(app, params, model_path_for_objects, ref_stage, obj, model_objects, materials_opt, "/" + model_object.Name)
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_camera(app, params, path_for_objects, stage, xsi_camera, root_path): usd_xform, ref_stage, ref_stage_asset = add_xform(app, params, path_for_objects, True, stage, xsi_camera, root_path) usd_camera = UsdGeom.Camera.Define( ref_stage, str(usd_xform.GetPath()) + "/" + xsi_camera.Name) # set time independent attributes # perspective or ortographic if xsi_camera.Parameters("proj").Value == 0: usd_camera.CreateProjectionAttr().Set(UsdGeom.Tokens.orthographic) else: usd_camera.CreateProjectionAttr().Set(UsdGeom.Tokens.perspective) # clipping planes usd_camera.CreateClippingRangeAttr().Set( (xsi_camera.Parameters("near").Value, xsi_camera.Parameters("far").Value)) # visibility xsi_vis_prop = xsi_camera.Properties("Visibility") usd_camera.CreateVisibilityAttr().Set( UsdGeom.Tokens.invisible if xsi_vis_prop.Parameters("viewvis"). Value is False else UsdGeom.Tokens.inherited) # aperture size, w = 1024 pixels xsi_w = 1024 xsi_aspect = xsi_camera.Parameters("aspect").Value usd_camera.CreateHorizontalApertureAttr().Set(xsi_w) usd_camera.CreateVerticalApertureAttr().Set(xsi_w / xsi_aspect) # offset is zero usd_camera.CreateHorizontalApertureOffsetAttr().Set(0) usd_camera.CreateVerticalApertureOffsetAttr().Set(0) opt_animation = params.get("animation", None) if opt_animation is None: set_camera_at_frame(xsi_camera, usd_camera) else: for frame in range(opt_animation[0], opt_animation[1] + 1): set_camera_at_frame(xsi_camera, usd_camera, 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): 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)