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); }
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); } }
protected override void ExportPath(string path) { m_logLabel = ""; m_logLabel += $"export...\n"; var root = State.ExportRoot; try { using (var arrayManager = new NativeArrayManager()) { var converter = new UniVRM10.ModelExporter(); var model = converter.Export(arrayManager, root); // 右手系に変換 m_logLabel += $"convert to right handed coordinate...\n"; model.ConvertCoordinate(VrmLib.Coordinates.Vrm1, ignoreVrm: false); // export vrm-1.0 var exporter = new UniVRM10.Vrm10Exporter(new EditorTextureSerializer(), new GltfExportSettings()); var option = new VrmLib.ExportArgs(); exporter.Export(root, model, converter, option, Vrm ? Vrm.Meta : m_tmpObject.Meta); var exportedBytes = exporter.Storage.ToGlbBytes(); m_logLabel += $"write to {path}...\n"; File.WriteAllBytes(path, exportedBytes); Debug.Log("exportedBytes: " + exportedBytes.Length); var assetPath = UniGLTF.UnityPath.FromFullpath(path); if (assetPath.IsUnderAssetsFolder) { // asset folder 内。import を発動 assetPath.ImportAsset(); } } } catch (Exception ex) { m_logLabel += ex.ToString(); // rethrow throw; } }