Exemple #1
0
def emit_default_light(app, light_name, usd_tfm, visibility, usd_prim, light_type, xsi_parent, up_key, ignore_tfm):
    xsi_light = None
    if light_type == "DistantLight":
        xsi_light = app.GetPrimLight("Infinite.Preset", light_name, xsi_parent)
        usd_light = UsdLux.DistantLight(usd_prim)
        # for distance we set transform
        utils.set_xsi_transform(app, xsi_light, usd_tfm, up_key=up_key, add_tfm=usd_light.GetLocalTransformation())
        utils.set_xsi_visibility(xsi_light, visibility)
        # and diffuse and specular params
        set_import_diffuse_param(app, xsi_light, usd_light)
        set_import_specular_param(app, xsi_light, usd_light)
    else:  # all other lights are point lights
        if light_type in ["SphereLight", "RectLight", "DiskLight", "CylinderLight"]:  # portal and dome lights are not supported by default lights
            xsi_light = app.GetPrimLight("Point.Preset", light_name, xsi_parent)
            # cast ptim to light
            usd_light = UsdLux.SphereLight(usd_prim) if light_type == "SphereLight" else (UsdLux.RectLight(usd_prim) if light_type == "RectLight" else (UsdLux.DiskLight(usd_prim) if light_type == "DiskLight" else UsdLux.CylinderLight(usd_prim)))
            # set transform
            utils.set_xsi_transform(app, xsi_light, usd_tfm, up_key=up_key, add_tfm=usd_light.GetLocalTransformation())
            utils.set_xsi_visibility(xsi_light, visibility)
            # set diffuse and specular
            set_import_diffuse_param(app, xsi_light, usd_light)
            set_import_specular_param(app, xsi_light, usd_light)
            # enable area light
            xsi_light.Parameters("LightArea").Value = True
            set_import_light_geometry(app, xsi_light, usd_light, light_type)
    return xsi_light
Exemple #2
0
def emit_pointcloud(app, options, pointloud_name, usd_tfm, visibility,
                    usd_prim, xsi_parent):
    imp.reload(utils)
    usd_points = UsdGeom.Points(usd_prim)
    xsi_points = app.GetPrim("PointCloud", pointloud_name, xsi_parent)
    utils.set_xsi_transform(app, xsi_points, usd_tfm)
    utils.set_xsi_visibility(xsi_points, visibility)

    tree = create_usd_load_tree(app, xsi_points.ActivePrimitive.Geometry)

    if not utils.is_animated_points(usd_points):
        points_data = {}
        read_points_data(points_data, usd_points=usd_points)
        xsi_geometry = xsi_points.ActivePrimitive.Geometry
        set_pointcloud_from_data(app, xsi_geometry, points_data,
                                 options["XSIMath"])
    else:
        operator = app.AddCustomOp("USDPointsOperator",
                                   xsi_points.ActivePrimitive, "",
                                   "USDPointsOperator")
        operator.Parameters("file_path").Value = options["file_path"]
        operator.Parameters("points_path").Value = str(usd_prim.GetPath())
        operator.AlwaysEvaluate = True

        # swap ICE-tree and operator (ICE-tree should be at the top)
        app.MoveOperatorAfter(xsi_points.ActivePrimitive, tree, operator)

    return xsi_points
Exemple #3
0
def emit_sycles_light(app, light_name, usd_tfm, visibility, usd_prim, light_type, xsi_parent, up_key, ignore_tfm):
    xsi_light = None
    usd_light = None
    # cylinder light is not suported by cycles lighst
    if light_type == "RectLight":
        xsi_light = app.GetPrim("cyclesArea", light_name, xsi_parent)
        usd_light = UsdLux.RectLight(usd_prim)
        # set width and height
        set_import_parameter(app, xsi_light, "sizeU", usd_light.GetWidthAttr())
        set_import_parameter(app, xsi_light, "sizeV", usd_light.GetHeightAttr())
    elif light_type == "DiskLight":
        xsi_light = app.GetPrim("cyclesArea", light_name, xsi_parent)
        usd_light = UsdLux.DiskLight(usd_prim)
        xsi_light.Parameters("shape").Value = 1
        set_import_parameter(app, xsi_light, "sizeU", usd_light.GetRadiusAttr())
        set_import_parameter(app, xsi_light, "sizeV", usd_light.GetRadiusAttr())
    elif light_type == "LightPortal":
        xsi_light = app.GetPrim("cyclesArea", light_name, xsi_parent)
        usd_light = UsdLux.LightPortal(usd_prim)
        xsi_light.Parameters("is_portal").Value = True
    elif light_type == "SphereLight":
        xsi_light = app.GetPrim("cyclesPoint", light_name, xsi_parent)
        usd_light = UsdLux.SphereLight(usd_prim)
        set_import_parameter(app, xsi_light, "size", usd_light.GetRadiusAttr())
    elif light_type == "DistantLight":
        xsi_light = app.GetPrim("cyclesSun", light_name, xsi_parent)
        usd_light = UsdLux.DistantLight(usd_prim)
        set_import_parameter(app, xsi_light, "angle", usd_light.GetAngleAttr())
    elif light_type == "DomeLight":
        xsi_light = app.GetPrim("cyclesBackground", light_name, xsi_parent)
        usd_light = UsdLux.DomeLight(usd_prim)
    if xsi_light is not None:
        # set transform
        utils.set_xsi_transform(app, xsi_light, usd_tfm, up_key=up_key, add_tfm=usd_light.GetLocalTransformation())
        utils.set_xsi_visibility(xsi_light, visibility)

        # for all lights (except dome light and portal) we can set diffuse, specular, intensity
        if usd_light is not None and light_type != "DomeLight" and light_type != "LightPortal":
            set_import_parameter(app, xsi_light, "use_diffuse", usd_light.GetDiffuseAttr())
            set_import_parameter(app, xsi_light, "use_glossy", usd_light.GetSpecularAttr())
            set_import_parameter(app, xsi_light, "power", usd_light.CreateIntensityAttr())

    return xsi_light
Exemple #4
0
def emit_pointcloud(app,
                    options,
                    pointloud_name,
                    usd_tfm,
                    visibility,
                    usd_prim,
                    is_strands,
                    xsi_parent,
                    is_simple=False):
    '''if is_simple is True, then we should ignore in-object ransform
    '''
    if DEBUG_MODE:
        imp.reload(materials)
        imp.reload(utils)

    usd_object = UsdGeom.BasisCurves(
        usd_prim) if is_strands else UsdGeom.Points(usd_prim)
    xsi_points = app.GetPrim("PointCloud", pointloud_name, xsi_parent)

    if options.get("is_materials", False):
        usd_material = UsdShade.MaterialBindingAPI(
            usd_prim).GetDirectBinding().GetMaterial()
        xsi_material = materials.import_material(
            app, usd_material, library_name=options["file_name"])
        if xsi_material is not None:
            app.AssignMaterial(xsi_material.FullName + "," +
                               xsi_points.FullName)

    utils.set_xsi_transform(app,
                            xsi_points,
                            usd_tfm,
                            up_key=options["up_axis"])
    utils.set_xsi_visibility(xsi_points, visibility)
    if "project_path" in options:
        is_constant = write_ice_cache(usd_object, is_strands, xsi_points,
                                      options["project_path"],
                                      options["file_name"], options["up_axis"],
                                      is_simple)
        # build ice-tree with caching node
        build_ice_tree(app, xsi_points, is_constant, options["file_name"])

    return xsi_points
Exemple #5
0
def import_item(app, options, usd_item, usd_stage, xsi_parent, is_root=False):
    '''Use xform-based approach. It means, that each object defined by subcomponent of the xform node
    options contains keys:
            clear_scene (True/False),
            is_materials (True/False),
            attributes (list of string for polymesh attributes)
            object_types (list of strings for imported objects)
    '''
    item_type = usd_item.GetTypeName()
    if item_type == "Xform":  # check only Xform, because each essential component should be child of the Xform
        new_object = None
        xform_name = usd_item.GetName()
        usd_tfm = prim_xform.get_transform(usd_item)  # usd_tfm is a tuple (array of transforms or one transform, array of time samples)
        is_visible = prim_xform.get_visibility(usd_item)
        if usd_item.IsInstance():
            # this is an instance
            usd_master = usd_item.GetMaster()
            if str(usd_master.GetPath()) in options["instances"]:
                # master already created, use it for instancing model
                xsi_model = options["instances"][str(usd_master.GetPath())]
                xsi_instance = app.Instantiate(xsi_model)[0]
                app.DeselectAll()
                if xsi_parent.ObjectID != app.ActiveProject2.ActiveScene.Root.ObjectID:
                    app.CopyPaste(xsi_instance, "", xsi_parent, 1)
                utils.set_xsi_visibility(xsi_instance, is_visible)
                utils.set_xsi_transform(app, xsi_instance, usd_tfm)
            else:
                # create the model
                app.DeselectAll()
                xsi_model = app.CreateModel("", xform_name, xsi_parent)[0]
                utils.set_xsi_visibility(xsi_model, is_visible)
                utils.set_xsi_transform(app, xsi_model, usd_tfm)
                # instert objects inside this model
                for child in usd_master.GetChildren():
                    import_item(app, options, child, usd_stage, xsi_model)
                # save the link to the model onject
                options["instances"][str(usd_master.GetPath())] = xsi_model
        else:
            childrens = geather_childrens(usd_item)  # this is a dict with key - prim type, value - array of prims
            ess_comp_count, ess_comp_names = get_number_of_essential_components(childrens)
            if ess_comp_count == 0 and constants.siNullPrimType in options["object_types"]:
                # all childrens are XForms, so current object should be also null
                # create it and iterate throw children
                new_object = emit_item(app, options, usd_item, xsi_parent, predefined_name=xform_name, predefined_visibility=is_visible, predefined_tfm=usd_tfm)
            elif ess_comp_count == 1 and not utils.is_contains_transform(childrens[ess_comp_names[0]][0]):
                # there is exactly one essential componen and it does not contains transfrom
                # so, current xform is object with this component
                if ess_comp_names[0] == "Mesh" and constants.siPolyMeshType in options["object_types"]:
                    new_object = emit_item(app, options, childrens["Mesh"][0], xsi_parent, predefined_name=xform_name, predefined_visibility=is_visible, predefined_tfm=usd_tfm)
                elif ess_comp_names[0] == "Points" and "pointcloud" in options["object_types"]:
                    new_object = emit_item(app, options, childrens["Points"][0], xsi_parent, predefined_name=xform_name, predefined_visibility=is_visible, predefined_tfm=usd_tfm)
            else:
                # current is Xform, but it contains either several essential components, or one component but with transform
                # in this case we should create the null and all subcomponents emit as separate objects
                import_item_simple(app, options, usd_item, usd_stage, xsi_parent)
            if new_object is not None:
                for child in childrens.get("Xform", []):
                    import_item(app, options, child, usd_stage, new_object)
    else:
        if is_root:
            import_item_simple(app, options, usd_item, usd_stage, xsi_parent)
        else:
            for child in usd_item.GetChildren():
                import_item_simple(app, options, child, usd_stage, xsi_parent)
Exemple #6
0
def emit_null(app, null_name, usd_tfm, visibility, usd_prim, xsi_parent, up_key):
    xsi_null = app.GetPrim("Null", null_name, xsi_parent)
    utils.set_xsi_transform(app, xsi_null, usd_tfm, up_key=up_key)
    utils.set_xsi_visibility(xsi_null, visibility)
    return xsi_null