Пример #1
0
        /// <summary>
        ///
        /// * Texture(.png etc...)をディスクに書き出す
        /// * EditorApplication.delayCall で処理を進めて 書き出した画像が Asset として成立するのを待つ
        /// * 書き出した Asset から TextureImporter を取得して設定する
        ///
        /// </summary>
        /// <param name="importer"></param>
        /// <param name="dirName"></param>
        /// <param name="onCompleted"></param>
        public static void ExtractTextures(GltfParser parser, UnityPath textureDirectory,
                                           TextureEnumerator textureEnumerator, Texture2D[] subAssets, Action <Texture2D> addRemap,
                                           Action <IEnumerable <UnityPath> > onCompleted = null)
        {
            var extractor = new TextureExtractor(parser, textureDirectory, subAssets);

            foreach (var x in textureEnumerator(parser))
            {
                extractor.Extract(x);
            }

            EditorApplication.delayCall += () =>
            {
                // Wait for the texture assets to be imported

                foreach (var kv in extractor.Textures)
                {
                    var targetPath = kv.Key;
                    var param      = kv.Value;

                    // remap
                    var externalObject = targetPath.LoadAsset <Texture2D>();
                    if (externalObject != null)
                    {
                        addRemap(externalObject);
                    }
                }

                if (onCompleted != null)
                {
                    onCompleted(extractor.Textures.Keys);
                }
            };
        }
Пример #2
0
        /// <summary>
        ///
        /// * Texture(.png etc...)をディスクに書き出す
        /// * EditorApplication.delayCall で処理を進めて 書き出した画像が Asset として成立するのを待つ
        /// * 書き出した Asset から TextureImporter を取得して設定する
        ///
        /// </summary>
        /// <param name="importer"></param>
        /// <param name="dirName"></param>
        /// <param name="onCompleted"></param>
        public static void ExtractTextures(string assetPath, TextureEnumerator textureEnumerator, Texture2D[] subAssets, Action <Texture2D> addRemap, Action <IEnumerable <string> > onCompleted = null)
        {
            var extractor  = new TextureExtractor(assetPath, subAssets);
            var normalMaps = new List <string>();

            foreach (var x in textureEnumerator(extractor.GLTF))
            {
                var gltfTexture = extractor.GLTF.textures[x.Index0.Value];
                var gltfImage   = extractor.GLTF.images[gltfTexture.source];
                extractor.Extract(x, !string.IsNullOrEmpty(gltfImage.uri));
            }

            EditorApplication.delayCall += () =>
            {
                // Wait for the texture assets to be imported

                foreach (var kv in extractor.Textures)
                {
                    var targetPath = kv.Key;
                    var param      = kv.Value;

                    // remap
                    var externalObject = AssetDatabase.LoadAssetAtPath <UnityEngine.Texture2D>(targetPath);
                    if (externalObject != null)
                    {
                        addRemap(externalObject);
                    }
                }

                if (onCompleted != null)
                {
                    onCompleted(extractor.Textures.Keys);
                }
            };
        }
Пример #3
0
        /// <summary>
        ///
        /// * Texture(.png etc...)をディスクに書き出す
        /// * EditorApplication.delayCall で処理を進めて 書き出した画像が Asset として成立するのを待つ
        /// * 書き出した Asset から TextureImporter を取得して設定する
        ///
        /// </summary>
        /// <param name="importer"></param>
        /// <param name="dirName"></param>
        /// <param name="onCompleted"></param>
        public static void ExtractTextures(GltfParser parser, UnityPath textureDirectory,
                                           TextureEnumerator textureEnumerator, Texture2D[] subAssets, Action <Texture2D> addRemap,
                                           Action <IEnumerable <UnityPath> > onCompleted = null)
        {
            var extractor = new TextureExtractor(parser, textureDirectory, subAssets);

            foreach (var x in textureEnumerator(extractor.GLTF))
            {
                var gltfTexture = extractor.GLTF.textures[x.Index0.Value];
                var gltfImage   = extractor.GLTF.images[gltfTexture.source];
                extractor.Extract(x, !string.IsNullOrEmpty(gltfImage.uri));
            }

            EditorApplication.delayCall += () =>
            {
                // Wait for the texture assets to be imported

                foreach (var kv in extractor.Textures)
                {
                    var targetPath = kv.Key;
                    var param      = kv.Value;

                    // remap
                    var externalObject = targetPath.LoadAsset <Texture2D>();
                    if (externalObject != null)
                    {
                        addRemap(externalObject);
                    }
                }

                if (onCompleted != null)
                {
                    onCompleted(extractor.Textures.Keys);
                }
            };
        }
Пример #4
0
        /// <summary>
        ///
        /// * Texture(.png etc...)をディスクに書き出す
        /// * EditorApplication.delayCall で処理を進めて 書き出した画像が Asset として成立するのを待つ
        /// * 書き出した Asset から TextureImporter を取得して設定する
        ///
        /// </summary>
        /// <param name="importer"></param>
        /// <param name="dirName"></param>
        /// <param name="onCompleted"></param>
        public static void ExtractTextures(string assetPath, TextureEnumerator textureEnumerator, Texture2D[] subAssets, Action <Texture2D> addRemap, Action <IEnumerable <string> > onCompleted = null)
        {
            var extractor  = new TextureExtractor(assetPath, subAssets);
            var normalMaps = new List <string>();

            foreach (var x in textureEnumerator(extractor.GLTF))
            {
                var gltfTexture = extractor.GLTF.textures[x.Index0.Value];
                var gltfImage   = extractor.GLTF.images[gltfTexture.source];
                extractor.Extract(x, !string.IsNullOrEmpty(gltfImage.uri));
            }

            EditorApplication.delayCall += () =>
            {
                foreach (var kv in extractor.Textures)
                {
                    var targetPath = kv.Key;
                    var param      = kv.Value;

                    // TextureImporter
                    var targetTextureImporter = AssetImporter.GetAtPath(targetPath) as TextureImporter;
                    if (targetTextureImporter != null)
                    {
                        switch (param.TextureType)
                        {
                        case GetTextureParam.OCCLUSION_PROP:
                        case GetTextureParam.METALLIC_GLOSS_PROP:
#if VRM_DEVELOP
                            Debug.Log($"{targetPath} => linear");
#endif
                            targetTextureImporter.sRGBTexture = false;
                            targetTextureImporter.SaveAndReimport();
                            break;

                        case GetTextureParam.NORMAL_PROP:
#if VRM_DEVELOP
                            Debug.Log($"{targetPath} => normalmap");
#endif
                            targetTextureImporter.textureType = TextureImporterType.NormalMap;
                            targetTextureImporter.SaveAndReimport();
                            break;
                        }
                    }
                    else
                    {
                        throw new FileNotFoundException(targetPath);
                    }

                    // remap
                    var externalObject = AssetDatabase.LoadAssetAtPath <UnityEngine.Texture2D>(targetPath);
                    if (externalObject != null)
                    {
                        addRemap(externalObject);
                    }
                }

                if (onCompleted != null)
                {
                    onCompleted(extractor.Textures.Keys);
                }
            };
        }