Esempio n. 1
0
        public static Texture2D ImportConnectedTexture <T>(Scene scene,
                                                           Connectable <T> connection,
                                                           bool isNormalMap,
                                                           SceneImportOptions options,
                                                           out string uvPrimvar)
        {
            uvPrimvar = null;

            // TODO: look for the expected texture/primvar reader pair.
            var       textureSample     = new TextureReaderSample();
            var       connectedPrimPath = scene.GetSdfPath(connection.connectedPath).GetPrimPath();
            Texture2D result            = null;

            scene.Read(connectedPrimPath, textureSample);

            if (textureSample.file.defaultValue != null &&
                !string.IsNullOrEmpty(textureSample.file.defaultValue.GetResolvedPath()))
            {
                if (OnResolveTexture != null)
                {
                    result = OnResolveTexture(textureSample.file.defaultValue, isNormalMap, options);
                }
                else
                {
                    result = DefaultTextureResolver(textureSample.file.defaultValue, isNormalMap, options);
                }
            }

            Connectable <Vector2> st = textureSample.st;

            if (st != null && st.IsConnected() && !string.IsNullOrEmpty(st.connectedPath))
            {
                var pvSrc = new PrimvarReaderSample <Vector2>();
                scene.Read(new pxr.SdfPath(textureSample.st.connectedPath).GetPrimPath(), pvSrc);

                if (pvSrc.varname != null &&
                    pvSrc.varname.defaultValue != null)
                {
                    // Ask the mesh importer to load the specified texcoord.
                    // This must be a callback, since materials-to-meshes are one-to-many.
                    uvPrimvar = pvSrc.varname.defaultValue;
                }
            }

            return(result);
        }
Esempio n. 2
0
 protected void ImportValueOrMap <T>(Scene scene,
                                     Connectable <T> usdParam,
                                     bool isNormalMap,
                                     SceneImportOptions options,
                                     ref Texture2D map,
                                     ref T?value,
                                     out string uvPrimvar) where T : struct
 {
     uvPrimvar = null;
     if (usdParam.IsConnected())
     {
         map = MaterialImporter.ImportConnectedTexture(scene, usdParam, isNormalMap, options, out uvPrimvar);
     }
     else
     {
         value = usdParam.defaultValue;
     }
 }
Esempio n. 3
0
 protected void ImportColorOrMap(Scene scene,
                                 Connectable <Vector3> usdParam,
                                 bool isNormalMap,
                                 SceneImportOptions options,
                                 ref Texture2D map,
                                 ref Color?value,
                                 out string uvPrimvar)
 {
     uvPrimvar = null;
     if (usdParam.IsConnected())
     {
         map = MaterialImporter.ImportConnectedTexture(scene, usdParam, isNormalMap, options, out uvPrimvar);
     }
     else
     {
         var rgb = usdParam.defaultValue;
         value = new Color(rgb.x, rgb.y, rgb.z).gamma;
     }
 }
        public static Texture2D ImportConnectedTexture <T>(Scene scene,
                                                           Connectable <T> connection,
                                                           bool isNormalMap,
                                                           SceneImportOptions options,
                                                           out string uvPrimvar)
        {
            uvPrimvar = null;

            // TODO: look for the expected texture/primvar reader pair.
            var       textureSample     = new TextureReaderSample();
            var       connectedPrimPath = scene.GetSdfPath(connection.connectedPath).GetPrimPath();
            Texture2D result            = null;

            scene.Read(connectedPrimPath, textureSample);

            if (textureSample.file.defaultValue != null &&
                !string.IsNullOrEmpty(textureSample.file.defaultValue.GetResolvedPath()))
            {
                if (OnResolveTexture != null)
                {
                    result = OnResolveTexture(textureSample.file.defaultValue, isNormalMap, options);
                }
                else
                {
                    result = DefaultTextureResolver(textureSample.file.defaultValue, isNormalMap, options);
                }
            }

            Connectable <Vector2> st = textureSample.st;

            if (st != null && st.IsConnected() && !string.IsNullOrEmpty(st.connectedPath))
            {
                var pvSrc = new PrimvarReaderSample <Vector2>();
                scene.Read(new pxr.SdfPath(textureSample.st.connectedPath).GetPrimPath(), pvSrc);

                if (pvSrc.varname != null)
                {
                    if (pvSrc.varname.IsConnected())
                    {
                        var connPath = new pxr.SdfPath(pvSrc.varname.GetConnectedPath());
                        var attr     = scene.GetAttributeAtPath(connPath);
                        if (attr != null)
                        {
                            var value = attr.Get(scene.Time);
                            uvPrimvar = pxr.UsdCs.VtValueToTfToken(value).ToString();
                        }
                        else
                        {
                            Debug.LogWarning("No primvar name was provided at the connected path: " + connPath);
                            uvPrimvar = "";
                        }
                    }
                    else if (pvSrc.varname.defaultValue != null)
                    {
                        // Ask the mesh importer to load the specified texcoord.
                        // This must be a callback, since materials-to-meshes are one-to-many.
                        uvPrimvar = pvSrc.varname.defaultValue;
                    }
                }
            }

            return(result);
        }