def set_rect_size(usd_light, xsi_param_width, xsi_param_height, anim_opt): attr_width = usd_light.CreateWidthAttr() if anim_opt is None or not utils.is_param_animated(xsi_param_width, anim_opt): attr_width.Set(xsi_param_width.Value) else: for frame in range(anim_opt[0], anim_opt[1] + 1): attr_width.Set(xsi_param_width.GetValue(frame), Usd.TimeCode(frame)) attr_heigh = usd_light.CreateHeightAttr() if anim_opt is None or not utils.is_param_animated(xsi_param_height, anim_opt): attr_heigh.Set(xsi_param_height.Value) else: for frame in range(anim_opt[0], anim_opt[1] + 1): attr_heigh.Set(xsi_param_height.GetValue(frame), Usd.TimeCode(frame))
def set_ellipse_radius(usd_light, xsi_param_width, xsi_param_height, anim_opt): attr = usd_light.CreateRadiusAttr() if anim_opt is None or not (utils.is_param_animated(xsi_param_width, anim_opt) or utils.is_param_animated(xsi_param_height, anim_opt)): attr.Set((xsi_param_width.Value + xsi_param_height.Value) / 2) else: for frame in range(anim_opt[0], anim_opt[1] + 1): attr.Set((xsi_param_width.GetValue(frame) + xsi_param_height.GetValue(frame)) / 2, Usd.TimeCode(frame))
def set_radius(usd_light, xsi_param, anim_opt): attr = usd_light.CreateRadiusAttr() if anim_opt is None or not utils.is_param_animated(xsi_param, anim_opt): attr.Set(xsi_param.Value) else: for frame in range(anim_opt[0], anim_opt[1] + 1): attr.Set(xsi_param.GetValue(frame), Usd.TimeCode(frame))
def set_specular(usd_light, parameter, anim_opt, value=None): if value is not None: usd_light.CreateSpecularAttr().Set(value) else: attr = usd_light.CreateSpecularAttr() if anim_opt is None or utils.is_param_animated(parameter, anim_opt): for frame in range(anim_opt[0], anim_opt[1] + 1): attr.Set(1.0 if parameter.GetValue(frame) else 0.0, Usd.TimeCode(frame)) else: attr.Set(1.0 if parameter.Value else 0.0)
def set_diffuse(usd_light, parameter, anim_opt, value=None): # value used for background light if value is not None: usd_light.CreateDiffuseAttr().Set(value) else: attr = usd_light.CreateDiffuseAttr() if anim_opt is None or utils.is_param_animated(parameter, anim_opt): for frame in range(anim_opt[0], anim_opt[1] + 1): attr.Set(1.0 if parameter.GetValue(frame) else 0.0, Usd.TimeCode(frame)) else: attr.Set(1.0 if parameter.Value else 0.0)
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 if DEBUG_MODE: imp.reload(materials) imp.reload(utils) # 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 and usd_light 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)) opt_animation = params["animation"] # diffuse and specular coefficients xsi_is_diffuse = xsi_light.Parameters("DiffuseContribution") xsi_is_specular = xsi_light.Parameters("SpecularContribution") usd_diffuse_attr = usd_light.CreateDiffuseAttr() usd_specular_attr = usd_light.CreateSpecularAttr() if opt_animation is not None and utils.is_param_animated(xsi_is_diffuse, opt_animation): for frame in range(opt_animation[0], opt_animation[1] + 1): usd_diffuse_attr.Set(xsi_is_diffuse.GetValue(frame), Usd.TimeCode(frame)) else: usd_diffuse_attr.Set(1.0 if xsi_is_diffuse.Value else 0.0) if opt_animation is not None and utils.is_param_animated(xsi_is_specular, opt_animation): for frame in range(opt_animation[0], opt_animation[1] + 1): usd_specular_attr.Set(xsi_is_specular.GetValue(frame), Usd.TimeCode(frame)) else: usd_specular_attr.Set(1.0 if xsi_is_specular.Value else 0.0) # default intensity = 1.0 usd_light.CreateIntensityAttr().Set(1.0) changes_size_key = [False, False, False] # for x, y and z. If True, then this dimension is changed by animation if opt_animation is None or not utils.is_area_light_animated(xsi_light, opt_animation, changes_size_key): set_light_at_frame(xsi_light, xsi_light_type, xsi_geom_type, usd_light) else: 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=frame, change_keys=changes_size_key) ref_stage.Save() return stage.GetPrimAtPath(root_path + str(usd_xform.GetPath()))