mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-26 21:04:14 -05:00
Merge pull request #811 from ousttrue/fix/export_reimport
VRM texture export の修正
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UniGLTF.UniUnlit;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -65,7 +66,9 @@ namespace UniGLTF
|
||||
{
|
||||
Texture metallicSmoothTexture = default;
|
||||
float smoothness = 1.0f;
|
||||
if (m.HasProperty("_MetallicGlossMap"))
|
||||
|
||||
var textuerNames = m.GetTexturePropertyNames();
|
||||
if (textuerNames.Contains("_MetallicGlossMap"))
|
||||
{
|
||||
if (m.HasProperty("_GlossMapScale"))
|
||||
{
|
||||
@@ -76,7 +79,7 @@ namespace UniGLTF
|
||||
|
||||
Texture occlusionTexture = default;
|
||||
var occlusionStrength = 1.0f;
|
||||
if (m.HasProperty("_OcclusionMap"))
|
||||
if (textuerNames.Contains("_OcclusionMap"))
|
||||
{
|
||||
occlusionTexture = m.GetTexture("_OcclusionMap");
|
||||
if (occlusionTexture != null && m.HasProperty("_OcclusionStrength"))
|
||||
|
||||
@@ -168,6 +168,11 @@ namespace UniGLTF
|
||||
return node;
|
||||
}
|
||||
|
||||
public virtual void ExportExtensions()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void Export(MeshExportSettings meshExportSettings)
|
||||
{
|
||||
var bytesBuffer = new ArrayByteBuffer(new byte[50 * 1024 * 1024]);
|
||||
@@ -184,12 +189,6 @@ namespace UniGLTF
|
||||
|
||||
var materialExporter = CreateMaterialExporter();
|
||||
glTF.materials = Materials.Select(x => materialExporter.ExportMaterial(x, TextureManager)).ToList();
|
||||
|
||||
for (int i = 0; i < TextureManager.Exported.Count; ++i)
|
||||
{
|
||||
var unityTexture = TextureManager.Exported[i];
|
||||
glTF.PushGltfTexture(bufferIndex, unityTexture);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Meshes
|
||||
@@ -306,6 +305,15 @@ namespace UniGLTF
|
||||
}
|
||||
#endregion
|
||||
#endif
|
||||
|
||||
ExportExtensions();
|
||||
|
||||
// Extension で Texture が増える場合があるので最後に呼ぶ
|
||||
for (int i = 0; i < TextureManager.Exported.Count; ++i)
|
||||
{
|
||||
var unityTexture = TextureManager.Exported[i];
|
||||
glTF.PushGltfTexture(bufferIndex, unityTexture);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -32,10 +32,8 @@ namespace VRM
|
||||
gltf.extensionsUsed.Add(glTF_VRM_extensions.ExtensionName);
|
||||
}
|
||||
|
||||
public override void Export(MeshExportSettings configuration)
|
||||
public override void ExportExtensions()
|
||||
{
|
||||
base.Export(configuration);
|
||||
|
||||
// avatar
|
||||
var animator = Copy.GetComponent<Animator>();
|
||||
if (animator != null)
|
||||
|
||||
@@ -48,17 +48,25 @@ namespace VRM
|
||||
}
|
||||
}
|
||||
|
||||
static void Load(FileInfo gltf, DirectoryInfo root)
|
||||
static GameObject Load(FileInfo gltf, DirectoryInfo root, byte[] bytes = null)
|
||||
{
|
||||
var parser = new GltfParser();
|
||||
try
|
||||
{
|
||||
parser.ParsePath(gltf.FullName);
|
||||
if (bytes != null)
|
||||
{
|
||||
parser.Parse(gltf.FullName, bytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.ParsePath(gltf.FullName);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"ParseError: {gltf}");
|
||||
Debug.LogException(ex);
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
@@ -66,11 +74,13 @@ namespace VRM
|
||||
using (var importer = new VRMImporterContext(parser))
|
||||
{
|
||||
importer.Load();
|
||||
return importer.DisposeOnGameObjectDestroyed().gameObject;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Message(gltf.FullName.Substring(root.FullName.Length), ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +100,23 @@ namespace VRM
|
||||
|
||||
foreach (var gltf in EnumerateGltfFiles(root))
|
||||
{
|
||||
Load(gltf, root);
|
||||
// import
|
||||
var go = Load(gltf, root);
|
||||
try
|
||||
{
|
||||
// export
|
||||
var vrm = VRMExporter.Export(UniGLTF.MeshExportSettings.Default, go);
|
||||
|
||||
// re import
|
||||
if (vrm != null)
|
||||
{
|
||||
Load(gltf, root, vrm.ToGlbBytes());
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
GameObject.DestroyImmediate(go);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user