Пример #1
0
 public void CopyTo(VRM10ObjectMeta dst)
 {
     dst.Name    = Name;
     dst.Version = Version;
     dst.CopyrightInformation = CopyrightInformation;
     if (Authors != null)
     {
         dst.Authors = Authors.Select(x => x).ToList();
     }
     else
     {
         dst.Authors = new List <string>();
     }
     dst.ContactInformation        = ContactInformation;
     dst.References                = References;
     dst.ThirdPartyLicenses        = ThirdPartyLicenses;
     dst.Thumbnail                 = Thumbnail;
     dst.AvatarPermission          = AvatarPermission;
     dst.ViolentUsage              = ViolentUsage;
     dst.SexualUsage               = SexualUsage;
     dst.CommercialUsage           = CommercialUsage;
     dst.PoliticalOrReligiousUsage = PoliticalOrReligiousUsage;
     dst.CreditNotation            = CreditNotation;
     dst.Redistribution            = Redistribution;
     dst.Modification              = Modification;
     dst.OtherLicenseUrl           = OtherLicenseUrl;
 }
Пример #2
0
        public void Export(GameObject root, Model model, ModelExporter converter, ExportArgs option, VRM10ObjectMeta vrmMeta = 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, m_settings);
                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, vrmMeta);

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

            for (var exportedTextureIdx = 0; exportedTextureIdx < exportedTextures.Count; ++exportedTextureIdx)
            {
                var(unityTexture, texColorSpace) = exportedTextures[exportedTextureIdx];
                Storage.Gltf.PushGltfTexture(0, 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);
        }
Пример #3
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);
        }