Esempio n. 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
Esempio n. 2
0
    def _ValidateDistantLight(self):
        lightPrimPath = '/directionalLight1'
        lightPrim = self._stage.GetPrimAtPath(lightPrimPath)
        self.assertTrue(lightPrim)
        distantLight = UsdLux.DistantLight(lightPrim)
        self.assertTrue(distantLight)

        self.assertTrue(Gf.IsClose(distantLight.GetIntensityAttr().Get(1),
            2, 1e-6))
        self.assertTrue(Gf.IsClose(distantLight.GetColorAttr().Get(1), Gf.Vec3f(1, 0.9, 0.8), 1e-6))

        self.assertTrue(Gf.IsClose(distantLight.GetAngleAttr().Get(1),
            1.5, 1e-6))
        self.assertTrue(Gf.IsClose(distantLight.GetAngleAttr().Get(5),
            2, 1e-6))

        rotateOp = distantLight.GetOrderedXformOps()
        self.assertEqual(rotateOp[0].GetOpType(), UsdGeom.XformOp.TypeRotateXYZ)
        self.assertTrue(UsdGeom.XformCommonAPI(distantLight))
        self.assertTrue(Gf.IsClose(rotateOp[0].Get(1), Gf.Vec3f(-20, -40, 0.0), 1e-6))
       

        self.assertTrue(lightPrim.HasAPI(UsdLux.ShadowAPI))
        shadowAPI = UsdLux.ShadowAPI(lightPrim)
        self.assertTrue(shadowAPI)

        self.assertTrue(shadowAPI.GetShadowEnableAttr().Get(1))
        self.assertTrue(Gf.IsClose(shadowAPI.GetShadowColorAttr().Get(1), Gf.Vec3f(0.1, 0.2, 0.3), 1e-6))
        return
Esempio n. 3
0
    def _ValidateUsdLuxDistantLightAngle(self):
        lightPrimPath = '/RfMLightsTest/Lights/DistantLight'
        lightPrim = self._stage.GetPrimAtPath(lightPrimPath)
        self.assertTrue(lightPrim)

        distantLight = UsdLux.DistantLight(lightPrim)
        self.assertTrue(distantLight)

        expectedAngle = 0.73
        self.assertTrue(Gf.IsClose(distantLight.GetAngleAttr().Get(),
            expectedAngle, 1e-6))
Esempio n. 4
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