コード例 #1
0
        public void VRMLookAtTest()
        {
            var parser = new GltfParser();

            parser.ParsePath(AliciaPath);
            byte[] bytes = default;
            using (var loader = new VRMImporterContext(parser))
            {
                loader.Load();
                loader.ShowMeshes();

                var go = loader.Root;
                var fp = go.GetComponent <VRMFirstPerson>();
                GameObject.DestroyImmediate(go.GetComponent <VRMLookAtBoneApplyer>());
                go.AddComponent <VRMLookAtBlendShapeApplyer>();
                bytes = VRMEditorExporter.Export(go, null, new VRMExportSettings
                {
                    PoseFreeze = true,
                });
            }

            var parser2 = new GltfParser();

            parser2.Parse(AliciaPath, bytes);
            var loader2 = new VRMImporterContext(parser2);

            Assert.AreEqual(LookAtType.BlendShape, loader2.VRM.firstPerson.lookAtType);
        }
コード例 #2
0
        public void Sample()
        {
            var path = "Tests/Models/Alicia_vrm-0.51/AliciaSolid_vrm-0.51.vrm";

            Debug.Log($"load: {path}");

            var migrated = MigrationVrm.Migrate(File.ReadAllBytes(path));

            var parser = new GltfParser();

            parser.Parse(path, migrated);

            var asset = BuildGameObject(parser, true);

            Debug.Log(asset);

            // export
            var dstModel = ToModel(asset);

            Debug.Log(dstModel);

            var vrmBytes = ToVrm10(dstModel);

            Debug.Log($"export {vrmBytes.Length} bytes");
        }
コード例 #3
0
        VrmLib.Model ReadModel(string path)
        {
            var bytes = MigrationVrm.Migrate(File.ReadAllBytes(path));

            var parser = new GltfParser();

            parser.Parse("migrated", bytes);

            var model = UniVRM10.VrmLoader.CreateVrmModel(parser);

            return(model);
        }
コード例 #4
0
        static GameObject Load(byte[] bytes, string path)
        {
            var parser = new GltfParser();

            parser.Parse(path, bytes);

            using (var loader = new VRMImporterContext(parser))
            {
                loader.Load();
                loader.ShowMeshes();
                return(loader.DisposeOnGameObjectDestroyed().gameObject);
            }
        }
コード例 #5
0
    static GameObject Import(byte[] bytes, FileInfo path)
    {
        var parser = new GltfParser();

        parser.Parse(path.FullName, bytes);

        using (var loader = new RuntimeUnityBuilder(parser))
        {
            loader.Load();
            loader.ShowMeshes();
            return(loader.DisposeOnGameObjectDestroyed().gameObject);
        }
    }
コード例 #6
0
        public void MaterialImporterTest()
        {
            var migratedBytes = MigrationVrm.Migrate(File.ReadAllBytes(AliciaPath));
            var parser        = new GltfParser();

            parser.Parse(AliciaPath, migratedBytes);

            var materialParam = Vrm10MaterialImporter.GetMaterialParam(parser, 0);

            Assert.AreEqual("VRM/MToon", materialParam.ShaderName);
            Assert.AreEqual("Alicia_body", materialParam.TextureSlots["_MainTex"].UnityObjectName);

            var(key, value) = materialParam.EnumerateSubAssetKeyValue().First();
            Assert.AreEqual(new SubAssetKey(typeof(Texture2D), "Alicia_body"), key);
        }
コード例 #7
0
ファイル: VRMRuntimeLoader.cs プロジェクト: unitycoder/UniVRM
        async void LoadVRMClicked()
        {
#if UNITY_STANDALONE_WIN
            var path = FileDialogForWindows.FileDialog("open VRM", ".vrm");
#elif UNITY_EDITOR
            var path = UnityEditor.EditorUtility.OpenFilePanel("Open VRM", "", "vrm");
#else
            var path = Application.dataPath + "/default.vrm";
#endif
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            var bytes = File.ReadAllBytes(path);
            // なんらかの方法でByte列を得た

            // GLB形式でJSONを取得しParseします
            var parser = new GltfParser();
            parser.Parse(path, bytes);

            using (var context = new VRMImporterContext(parser))
            {
                // metaを取得(todo: thumbnailテクスチャのロード)
                var meta = await context.ReadMetaAsync();

                Debug.LogFormat("meta: title:{0}", meta.Title);

                // ParseしたJSONをシーンオブジェクトに変換していく
                if (m_loadAsync)
                {
                    await context.LoadAsync();
                }
                else
                {
                    context.Load();
                }

                OnLoaded(context);
            }
        }
コード例 #8
0
        public void Sample()
        {
            var path = "Tests/Models/Alicia_vrm-0.51/AliciaSolid_vrm-0.51.vrm";

            Debug.Log($"load: {path}");

            var migrated = MigrationVrm.Migrate(File.ReadAllBytes(path));

            var parser = new GltfParser();

            parser.Parse(path, migrated);

            var go = BuildGameObject(parser, true);

            Debug.Log(go);

            // export
            var vrmBytes = Vrm10Exporter.Export(go, AssetTextureUtil.GetTextureBytesWithMime);

            Debug.Log($"export {vrmBytes.Length} bytes");
        }
コード例 #9
0
        static GameObject Load(FileInfo gltf, DirectoryInfo root, byte[] bytes = null)
        {
            var parser = new GltfParser();

            try
            {
                if (bytes != null)
                {
                    parser.Parse(gltf.FullName, bytes);
                }
                else
                {
                    parser.ParsePath(gltf.FullName);
                }
            }
            catch (Exception ex)
            {
                Debug.LogError($"ParseError: {gltf}");
                Debug.LogException(ex);
                return(null);
            }

            try
            {
                using (var importer = new VRMImporterContext(parser))
                {
                    importer.Load();
                    return(importer.DisposeOnGameObjectDestroyed().gameObject);
                }
            }
            catch (Exception ex)
            {
                Message(gltf.FullName.Substring(root.FullName.Length), ex);
                return(null);
            }
        }
コード例 #10
0
        public void VRMLookAtCurveMapTest()
        {
            var parser = new GltfParser();

            parser.ParsePath(AliciaPath);
            byte[]      bytes           = default;
            CurveMapper horizontalInner = default;

            using (var loader = new VRMImporterContext(parser))
            {
                loader.Load();
                loader.ShowMeshes();

                var go     = loader.Root;
                var fp     = go.GetComponent <VRMFirstPerson>();
                var lookAt = go.GetComponent <VRMLookAtBoneApplyer>();
                horizontalInner = lookAt.HorizontalInner;
                bytes           = VRMEditorExporter.Export(go, null, new VRMExportSettings
                {
                    PoseFreeze = false,
                });
            }

            var parser2 = new GltfParser();

            parser2.Parse(AliciaPath, bytes);
            using (var loader = new VRMImporterContext(parser2))
            {
                loader.Load();
                loader.ShowMeshes();

                var lookAt = loader.Root.GetComponent <VRMLookAtBoneApplyer>();
                Assert.AreEqual(horizontalInner.CurveXRangeDegree, lookAt.HorizontalInner.CurveXRangeDegree);
                Assert.AreEqual(horizontalInner.CurveYRangeDegree, lookAt.HorizontalInner.CurveYRangeDegree);
            }
        }
コード例 #11
0
        /// <summary>
        /// VRM1 で パースし、失敗したら Migration してから VRM1 でパースする
        /// </summary>
        /// <param name="path"></param>
        /// <param name="migrateToVrm1"></param>
        /// <returns></returns>
        public static GltfParser Parse(string path, bool migrateToVrm1)
        {
            //
            // Parse(parse glb, parser gltf json)
            //
            var parser = new GltfParser();

            parser.ParsePath(path);
            if (UniGLTF.Extensions.VRMC_vrm.GltfDeserializer.TryGet(parser.GLTF.extensions, out UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm))
            {
                return(parser);
            }

            if (migrateToVrm1)
            {
                // try migrateion
                var migrated = MigrationVrm.Migrate(File.ReadAllBytes(path));
                parser = new GltfParser();
                parser.Parse(path, migrated);
                return(parser);
            }

            return(null);
        }