static IEnumerable <glTFMaterial> ExportMaterials(Model model, ITextureExporter textureExporter, GltfExportSettings settings) { var materialExporter = new Vrm10MaterialExporter(); foreach (Material material in model.Materials) { yield return(materialExporter.ExportMaterial(material, textureExporter, settings)); } }
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); } }