コード例 #1
0
        public MaterialDescriptor Get(GltfData data, int i)
        {
            // mtoon
            if (Vrm10MToonMaterialImporter.TryCreateParam(data, i, out MaterialDescriptor matDesc))
            {
                return(matDesc);
            }
            // unlit
            if (GltfUnlitMaterialImporter.TryCreateParam(data, i, out matDesc))
            {
                return(matDesc);
            }
            // pbr
            if (GltfPbrMaterialImporter.TryCreateParam(data, i, out matDesc))
            {
                return(matDesc);
            }
            // fallback
#if VRM_DEVELOP
            Debug.LogWarning($"material: {i} out of range. fallback");
#endif
            return(new MaterialDescriptor(
                       GltfMaterialDescriptorGenerator.GetMaterialName(i, null), GltfPbrMaterialImporter.ShaderName,
                       null,
                       new Dictionary <string, TextureDescriptor>(),
                       new Dictionary <string, float>(),
                       new Dictionary <string, Color>(),
                       new Dictionary <string, Vector4>(),
                       new Action <Material>[] {}));
        }
コード例 #2
0
        public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, bool migrateToVrm1)
        {
#if VRM_DEVELOP
            Debug.Log("OnImportAsset to " + scriptedImporter.assetPath);
#endif

            var parser = Parse(scriptedImporter.assetPath, migrateToVrm1);
            if (parser == null)
            {
                // fail to parse vrm1
                return;
            }

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

            using (var loader = new RuntimeUnityBuilder(parser, externalObjectMap))
            {
                // settings TextureImporters
                foreach (var textureInfo in Vrm10MToonMaterialImporter.EnumerateAllTexturesDistinct(parser))
                {
                    TextureImporterConfigurator.Configure(textureInfo, loader.TextureFactory.ExternalMap);
                }

                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);
                });
            }
        }
コード例 #3
0
        public MaterialDescriptor Get(GltfData data, int i)
        {
            // mtoon
            if (!Vrm10MToonMaterialImporter.TryCreateParam(data, i, out MaterialDescriptor matDesc))
            {
                // unlit
                if (!GltfUnlitMaterialImporter.TryCreateParam(data, i, out matDesc))
                {
                    // pbr
                    if (!GltfPbrMaterialImporter.TryCreateParam(data, i, out matDesc))
                    {
                        // fallback
#if VRM_DEVELOP
                        Debug.LogWarning($"material: {i} out of range. fallback");
#endif
                        return(new MaterialDescriptor(GltfMaterialDescriptorGenerator.GetMaterialName(i, null), GltfPbrMaterialImporter.ShaderName));
                    }
                }
            }
            return(matDesc);
        }