Example #1
0
        static void ImportVrm(UnityPath path)
        {
            if (!path.IsUnderAssetsFolder)
            {
                throw new Exception();
            }

            var parser = new GltfParser();

            try
            {
                parser.ParseGlb(File.ReadAllBytes(path.FullPath));
            }
            catch (KeyNotFoundException)
            {
                // invalid VRM-0.X.
                // maybe VRM-1.0.do nothing
                return;
            }

            var prefabPath = path.Parent.Child(path.FileNameWithoutExtension + ".prefab");

            // save texture assets !
            LoadTextureAsyncFunc textureLoader = async(caller, textureIndex, used) =>
            {
                var gltfTexture = parser.GLTF.textures[textureIndex];
                var gltfImage   = parser.GLTF.images[gltfTexture.source];
                var assetPath   = prefabPath.Parent.Child(gltfImage.uri);
                var texture     = await UniGLTF.AssetTextureLoader.LoadTaskAsync(assetPath, parser.GLTF, textureIndex);

                return(new TextureLoadInfo(texture, used, false));
            };
            var context = new VRMImporterContext(parser, textureLoader);
            var editor  = new VRMEditorImporterContext(context);

            editor.ExtractImages(prefabPath);

            EditorApplication.delayCall += () =>
            {
                //
                // after textures imported
                //
                context.Load();
                editor.SaveAsAsset(prefabPath);
                editor.Dispose();
            };
        }
 public ImporterContext(GltfParser parser,
                        LoadTextureAsyncFunc loadTextureAsync = null,
                        IEnumerable <(string, UnityEngine.Object)> externalObjectMap = null)
Example #3
0
 public TextureFactory(LoadTextureAsyncFunc loadTextureAsync,
                       IEnumerable <(string, UnityEngine.Object)> externalMap)