예제 #1
0
        /// <summary>
        /// glb をパースして、UnityObject化、さらにAsset化する
        /// </summary>
        /// <param name="scriptedImporter"></param>
        /// <param name="context"></param>
        /// <param name="reverseAxis"></param>
        public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, Axises reverseAxis)
        {
#if VRM_DEVELOP
            Debug.Log("OnImportAsset to " + scriptedImporter.assetPath);
#endif

            //
            // Parse(parse glb, parser gltf json)
            //
            var parser = new GltfParser();
            parser.ParsePath(scriptedImporter.assetPath);

            //
            // Import(create unity objects)
            //
            var externalObjectMap = scriptedImporter.GetExternalObjectMap().Select(kv => (kv.Value.name, kv.Value)).ToArray();

            var externalTextures = EnumerateTexturesFromUri(externalObjectMap, parser, UnityPath.FromUnityPath(scriptedImporter.assetPath).Parent).ToArray();

            using (var loader = new ImporterContext(parser, externalObjectMap.Concat(externalTextures)))
            {
                // settings TextureImporters
                foreach (var(key, textureInfo) in GltfTextureEnumerator.EnumerateAllTexturesDistinct(parser))
                {
                    TextureImporterConfigurator.Configure(textureInfo, loader.TextureFactory.ExternalMap);
                }

                loader.InvertAxis = reverseAxis;
                loader.Load();
                loader.ShowMeshes();

                loader.TransferOwnership(o =>
                {
                    context.AddObjectToAsset(o.name, o);
                    if (o is GameObject)
                    {
                        // Root GameObject is main object
                        context.SetMainObject(loader.Root);
                    }

                    return(true);
                });
            }
        }
예제 #2
0
        /// <summary>
        /// Extract をテスト
        /// </summary>
        /// <param name="gltf"></param>
        /// <param name="root"></param>
        static void EditorLoad(FileInfo gltf, int subStrStart)
        {
            var parser = new GltfParser();

            try
            {
                parser.ParsePath(gltf.FullName);
            }
            catch (Exception ex)
            {
                Debug.LogError($"ParseError: {gltf}");
                Debug.LogException(ex);
            }

            // should unique
            var gltfTextures = GltfTextureEnumerator.EnumerateAllTexturesDistinct(parser).ToArray();
            var distinct     = gltfTextures.Distinct().ToArray();

            Assert.True(gltfTextures.SequenceEqual(distinct));
        }
예제 #3
0
        public void TextureEnumerationTest()
        {
            {
                var parser = new GltfParser
                {
                    GLTF = TwoTexture(),
                };
                var items = GltfTextureEnumerator.EnumerateAllTexturesDistinct(parser).ToArray();
                Assert.AreEqual(2, items.Length);
            }

            {
                var parser = new GltfParser
                {
                    GLTF = TwoTextureOneUri(),
                };
                var items = GltfTextureEnumerator.EnumerateAllTexturesDistinct(parser).ToArray();
                Assert.AreEqual(1, items.Length);
            }

            {
                var parser = new GltfParser
                {
                    GLTF = TwoTextureOneImage(),
                };
                var items = GltfTextureEnumerator.EnumerateAllTexturesDistinct(parser).ToArray();
                Assert.AreEqual(1, items.Length);
            }

            {
                var parser = new GltfParser
                {
                    GLTF = CombineMetallicSmoothOcclusion(),
                };
                var items = GltfTextureEnumerator.EnumerateAllTexturesDistinct(parser).ToArray();
                Assert.AreEqual(1, items.Length);
            }
        }