Exemple #1
0
        public void Export(GameObject root, Model model, ModelExporter converter, ExportArgs option, VRM10ObjectMeta vrmMeta = null)
        {
            Storage.Gltf.asset = ExportAsset(model);

            Storage.Reserve(CalcReserveBytes(model));

            foreach (var material in ExportMaterials(model, m_textureExporter, m_settings))
            {
                Storage.Gltf.materials.Add(material);
            }

            foreach (var mesh in ExportMeshes(model.MeshGroups, model.Materials, Storage, option))
            {
                Storage.Gltf.meshes.Add(mesh);
            }

            using (var arrayManager = new NativeArrayManager())
            {
                foreach (var(node, skin) in ExportNodes(arrayManager, model.Nodes, model.MeshGroups, Storage, option))
                {
                    Storage.Gltf.nodes.Add(node);
                    if (skin != null)
                    {
                        var skinIndex = Storage.Gltf.skins.Count;
                        Storage.Gltf.skins.Add(skin);
                        node.skin = skinIndex;
                    }
                }
            }
            Storage.Gltf.scenes.Add(new gltfScene()
            {
                nodes = model.Root.Children.Select(child => model.Nodes.IndexOfThrow(child)).ToArray()
            });

            var(vrm, vrmSpringBone, thumbnailTextureIndex) = ExportVrm(root, model, converter, vrmMeta, Storage.Gltf.nodes, m_textureExporter);

            // Extension で Texture が増える場合があるので最後に呼ぶ
            var exportedTextures = m_textureExporter.Export();

            for (var exportedTextureIdx = 0; exportedTextureIdx < exportedTextures.Count; ++exportedTextureIdx)
            {
                var(unityTexture, texColorSpace) = exportedTextures[exportedTextureIdx];
                GltfTextureExporter.PushGltfTexture(Storage, unityTexture, texColorSpace, m_textureSerializer);
            }

            if (thumbnailTextureIndex.HasValue)
            {
                vrm.Meta.ThumbnailImage = Storage.Gltf.textures[thumbnailTextureIndex.Value].source;
            }

            UniGLTF.Extensions.VRMC_vrm.GltfSerializer.SerializeTo(ref Storage.Gltf.extensions, vrm);

            if (vrmSpringBone != null)
            {
                UniGLTF.Extensions.VRMC_springBone.GltfSerializer.SerializeTo(ref Storage.Gltf.extensions, vrmSpringBone);
            }

            // Fix Duplicated name
            gltfExporter.FixName(Storage.Gltf);
        }
Exemple #2
0
        private Model ToVrmModel(GameObject root)
        {
            var exporter = new UniVRM10.ModelExporter();
            var model    = exporter.Export(root);

            model.ConvertCoordinate(VrmLib.Coordinates.Vrm1, ignoreVrm: false);
            return(model);
        }
Exemple #3
0
        private Model ToVrmModel(GameObject root)
        {
            using (var arrayManager = new NativeArrayManager())
            {
                var exporter = new UniVRM10.ModelExporter();
                var model    = exporter.Export(arrayManager, root);

                model.ConvertCoordinate(VrmLib.Coordinates.Vrm1, ignoreVrm: false);
                return(model);
            }
        }
Exemple #4
0
 public void Export(GameObject root, Model model, ModelExporter converter, ExportArgs option, Func <Texture2D, (byte[], string)> getTextureBytes, VRM10MetaObject metaObject = null)
Exemple #5
0
        public void Export(GameObject root, Model model, ModelExporter converter, ExportArgs option, gltfExporter.GetBytesWithMimeFromTexture2D getTextureBytes, VRM10MetaObject metaObject = null)
        {
            ExportAsset(model);

            ///
            /// 必要な容量を先に確保
            /// (sparseは考慮してないので大きめ)
            ///
            {
                var reserveBytes = 0;
                // mesh
                foreach (var g in model.MeshGroups)
                {
                    foreach (var mesh in g.Meshes)
                    {
                        // 頂点バッファ
                        reserveBytes += mesh.IndexBuffer.ByteLength;
                        foreach (var kv in mesh.VertexBuffer)
                        {
                            reserveBytes += kv.Value.ByteLength;
                        }
                        // morph
                        foreach (var morph in mesh.MorphTargets)
                        {
                            foreach (var kv in morph.VertexBuffer)
                            {
                                reserveBytes += kv.Value.ByteLength;
                            }
                        }
                    }
                }
                Reserve(reserveBytes);
            }

            // material
            var materialExporter = new Vrm10MaterialExporter();

            foreach (Material material in model.Materials)
            {
                var glTFMaterial = materialExporter.ExportMaterial(material, m_textureExporter);
                Storage.Gltf.materials.Add(glTFMaterial);
            }

            // mesh
            ExportMeshes(model.MeshGroups, model.Materials, option);

            // node
            ExportNodes(model.Root, model.Nodes, model.MeshGroups, option);

            var(vrm, vrmSpringBone, thumbnailTextureIndex) = ExportVrm(root, model, converter, metaObject);

            // Extension で Texture が増える場合があるので最後に呼ぶ
            for (int i = 0; i < m_textureExporter.Exported.Count; ++i)
            {
                var(unityTexture, texColorSpace) = m_textureExporter.Exported[i];
                Storage.Gltf.PushGltfTexture(0, unityTexture, texColorSpace, getTextureBytes);
            }

            if (thumbnailTextureIndex.HasValue)
            {
                vrm.Meta.ThumbnailImage = Storage.Gltf.textures[thumbnailTextureIndex.Value].source;
            }

            UniGLTF.Extensions.VRMC_vrm.GltfSerializer.SerializeTo(ref Storage.Gltf.extensions, vrm);

            if (vrmSpringBone != null)
            {
                UniGLTF.Extensions.VRMC_springBone.GltfSerializer.SerializeTo(ref Storage.Gltf.extensions, vrmSpringBone);
            }
        }