Exemplo n.º 1
0
        static void Process(Vrm10Data result, ScriptedImporter scriptedImporter, AssetImportContext context, RenderPipelineTypes renderPipeline, bool doNormalize)
        {
            //
            // Import(create unity objects)
            //
            var extractedObjects = scriptedImporter.GetExternalObjectMap()
                                   .Where(kv => kv.Value != null)
                                   .ToDictionary(kv => new SubAssetKey(kv.Value.GetType(), kv.Key.name), kv => kv.Value);

            var materialGenerator = GetMaterialDescriptorGenerator(renderPipeline);

            using (var loader = new Vrm10Importer(result, extractedObjects,
                                                  materialGenerator: materialGenerator,
                                                  doNormalize: doNormalize))
            {
                // settings TextureImporters
                foreach (var textureInfo in loader.TextureDescriptorGenerator.Get().GetEnumerable())
                {
                    VRMShaders.TextureImporterConfigurator.Configure(textureInfo, loader.TextureFactory.ExternalTextures);
                }

                var loaded = loader.Load();
                loaded.ShowMeshes();

                loaded.TransferOwnership((key, o) =>
                {
                    context.AddObjectToAsset(key.Name, o);
                });
                var root = loaded.Root;
                GameObject.DestroyImmediate(loaded);

                context.AddObjectToAsset(root.name, root);
                context.SetMainObject(root);
            }
        }
Exemplo n.º 2
0
        private static async Task <Vrm10Instance> LoadVrm10DataAsync(
            Vrm10Data vrm10Data,
            MigrationData migrationData,
            bool normalizeTransform,
            bool showMeshes,
            IAwaitCaller awaitCaller,
            IMaterialDescriptorGenerator materialGenerator,
            VrmMetaInformationCallback vrmMetaInformationCallback,
            CancellationToken ct)
        {
            ct.ThrowIfCancellationRequested();
            if (awaitCaller == null)
            {
                throw new ArgumentNullException();
            }

            if (vrm10Data == null)
            {
                throw new ArgumentNullException(nameof(vrm10Data));
            }

            using (var loader = new Vrm10Importer(vrm10Data, materialGenerator: materialGenerator, doNormalize: normalizeTransform))
            {
                // 1. Load meta information if callback was available.
                if (vrmMetaInformationCallback != null)
                {
                    var thumbnail = await loader.LoadVrmThumbnailAsync();

                    if (migrationData != null)
                    {
                        vrmMetaInformationCallback(thumbnail, default, migrationData.OriginalMetaBeforeMigration);
Exemplo n.º 3
0
        public static Vrm10Instance LoadAlicia()
        {
            using (var data = Vrm10Data.ParseOrMigrate(AliciaPath, true, out Vrm10Data vrm, out MigrationData migration))
                using (var loader = new Vrm10Importer(vrm))
                {
                    var task = loader.LoadAsync(new VRMShaders.ImmediateCaller());
                    task.Wait();

                    var instance = task.Result;

                    return(instance.GetComponent <Vrm10Instance>());
                }
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="scriptedImporter"></param>
        /// <param name="context"></param>
        /// <param name="migrateToVrm1">vrm0 だった場合に vrm1 化する</param>
        /// <param name="renderPipeline"></param>
        /// <param name="doNormalize">normalize する</param>
        public static void Import(ScriptedImporter scriptedImporter, AssetImportContext context, bool migrateToVrm1, RenderPipelineTypes renderPipeline, bool doNormalize)
        {
#if VRM_DEVELOP
            Debug.Log("OnImportAsset to " + scriptedImporter.assetPath);
#endif

            using (var data = Vrm10Data.ParseOrMigrate(scriptedImporter.assetPath, migrateToVrm1, out Vrm10Data result, out MigrationData migration))
            {
                if (result == null)
                {
                    // fail to parse vrm1
                    return;
                }

                //
                // Import(create unity objects)
                //
                var extractedObjects = scriptedImporter.GetExternalObjectMap()
                                       .Where(kv => kv.Value != null)
                                       .ToDictionary(kv => new SubAssetKey(kv.Value.GetType(), kv.Key.name), kv => kv.Value);

                var materialGenerator = GetMaterialDescriptorGenerator(renderPipeline);

                using (var loader = new Vrm10Importer(result, extractedObjects,
                                                      materialGenerator: materialGenerator,
                                                      doNormalize: doNormalize))
                {
                    // settings TextureImporters
                    foreach (var textureInfo in loader.TextureDescriptorGenerator.Get().GetEnumerable())
                    {
                        VRMShaders.TextureImporterConfigurator.Configure(textureInfo, loader.TextureFactory.ExternalTextures);
                    }

                    var loaded = loader.Load();
                    loaded.ShowMeshes();

                    loaded.TransferOwnership((key, o) =>
                    {
                        context.AddObjectToAsset(key.Name, o);
                    });
                    var root = loaded.Root;
                    GameObject.DestroyImmediate(loaded);

                    context.AddObjectToAsset(root.name, root);
                    context.SetMainObject(root);
                }
            }
        }