コード例 #1
0
        void LoadModel(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

            Debug.LogFormat("{0}", path);
            var ext = Path.GetExtension(path).ToLower();

            switch (ext)
            {
            case ".vrm":
            {
                var context = new VRMImporterContext();
                var file    = File.ReadAllBytes(path);
                context.ParseGlb(file);
                m_texts.UpdateMeta(context);
                context.Load();
                context.ShowMeshes();
                context.EnableUpdateWhenOffscreen();
                context.ShowMeshes();
                SetModel(context.Root);
                break;
            }

            case ".glb":
            {
                var context = new UniGLTF.ImporterContext();
                var file    = File.ReadAllBytes(path);
                context.ParseGlb(file);
                context.Load();
                context.ShowMeshes();
                context.EnableUpdateWhenOffscreen();
                context.ShowMeshes();
                SetModel(context.Root);
                break;
            }

            case ".gltf":
            case ".zip":
            {
                var context = new UniGLTF.ImporterContext();
                context.Parse(path);
                context.Load();
                context.ShowMeshes();
                context.EnableUpdateWhenOffscreen();
                context.ShowMeshes();
                SetModel(context.Root);
                break;
            }

            default:
                Debug.LogWarningFormat("unknown file type: {0}", path);
                break;
            }
        }
コード例 #2
0
        public static async Task <RuntimeGltfInstance> LoadAsync(string path, IAwaitCaller awaitCaller = null, IMaterialDescriptorGenerator materialGenerator = null)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException(path);
            }

            Debug.LogFormat("{0}", path);
            using (GltfData data = new AutoGltfFileParser(path).Parse())
                using (var loader = new UniGLTF.ImporterContext(data, materialGenerator: materialGenerator))
                {
                    return(await loader.LoadAsync(awaitCaller));
                }
        }
コード例 #3
0
ファイル: ViewerUI.cs プロジェクト: Maple614/Myo_Capture
        void LoadModel(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

            Debug.LogFormat("{0}", path);
            var ext = Path.GetExtension(path).ToLower();

            switch (ext)
            {
            case ".vrm":
            {
                var context = new VRMImporterContext();

                var file = File.ReadAllBytes(path);
                context.ParseGlb(file);

                m_texts.UpdateMeta(context);
                //UniJSON.JsonParser.Parse(context.Json);

                VRMImporter.LoadVrmAsync(context, SetModel);

                break;
            }

            case ".glb":
            {
                var context = new UniGLTF.ImporterContext();

                var file = File.ReadAllBytes(path);
                context.ParseGlb(file);

                UniGLTF.gltfImporter.Load(context);
                context.ShowMeshes();
                SetModel(context.Root);

                break;
            }

            default:
                Debug.LogWarningFormat("unknown file type: {0}", path);
                break;
            }
        }
コード例 #4
0
ファイル: ViewerUI.cs プロジェクト: ichi-23/UniVRM
        void LoadModel(string path)
        {
            if (!File.Exists(path))
            {
                return;
            }

            Debug.LogFormat("{0}", path);
            var ext = Path.GetExtension(path).ToLower();

            switch (ext)
            {
            case ".vrm":
            {
                // var context = new ImporterContext();
                var file = File.ReadAllBytes(path);
                // context.ParseGlb(file);
                // context.Load();
                // context.ShowMeshes();
                // context.EnableUpdateWhenOffscreen();
                // context.ShowMeshes();

                var model = UniVRM10.VrmLoader.CreateVrmModel(file, new FileInfo(path));

                // UniVRM-0.XXのコンポーネントを構築する
                var assets = UniVRM10.RuntimeUnityBuilder.ToUnityAsset(model, showMesh: false);

                // showRenderer = false のときに後で表示する例
                foreach (var renderer in assets.Renderers)
                {
                    renderer.enabled = true;
                }

                UniVRM10.ComponentBuilder.Build10(model, assets);

                SetModel(assets.Root);
                break;
            }

            case ".glb":
            {
                var context = new UniGLTF.ImporterContext();
                var file    = File.ReadAllBytes(path);
                context.ParseGlb(file);
                context.Load();
                context.ShowMeshes();
                context.EnableUpdateWhenOffscreen();
                context.ShowMeshes();
                SetModel(context.Root);
                break;
            }

            case ".gltf":
            case ".zip":
            {
                var context = new UniGLTF.ImporterContext();
                context.Parse(path);
                context.Load();
                context.ShowMeshes();
                context.EnableUpdateWhenOffscreen();
                context.ShowMeshes();
                SetModel(context.Root);
                break;
            }

            default:
                Debug.LogWarningFormat("unknown file type: {0}", path);
                break;
            }
        }