mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-26 21:04:14 -05:00
Update exporter interface. use ExportingGltfData
This commit is contained in:
@@ -100,22 +100,21 @@ namespace UniGLTF
|
||||
default: throw new System.Exception();
|
||||
}
|
||||
|
||||
var gltf = new glTF();
|
||||
ExportingGltfData writer = default;
|
||||
using (var exporter = new gltfExporter(gltf, Settings))
|
||||
var data = new ExportingGltfData();
|
||||
using (var exporter = new gltfExporter(data, Settings))
|
||||
{
|
||||
exporter.Prepare(State.ExportRoot);
|
||||
writer = exporter.Export(new EditorTextureSerializer());
|
||||
exporter.Export(new EditorTextureSerializer());
|
||||
}
|
||||
|
||||
if (isGlb)
|
||||
{
|
||||
var bytes = writer.ToGlbBytes();
|
||||
var bytes = data.ToGlbBytes();
|
||||
File.WriteAllBytes(path, bytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
var (json, buffers) = writer.ToGltf(path);
|
||||
var (json, buffers) = data.ToGltf(path);
|
||||
// without BOM
|
||||
var encoding = new System.Text.UTF8Encoding(false);
|
||||
File.WriteAllText(path, json, encoding);
|
||||
|
||||
@@ -7,17 +7,16 @@ namespace UniGLTF
|
||||
{
|
||||
public class ExportingGltfData
|
||||
{
|
||||
readonly glTF _gltf;
|
||||
readonly glTF _gltf = new glTF();
|
||||
|
||||
public glTF GLTF => _gltf;
|
||||
|
||||
public ExportingGltfData(glTF gltf, int reserved = default)
|
||||
public ExportingGltfData(int reserved = default)
|
||||
{
|
||||
if (reserved == 0)
|
||||
{
|
||||
reserved = 50 * 1024 * 1024;
|
||||
}
|
||||
_gltf = gltf;
|
||||
// glb body と gltf の bin 兼用
|
||||
_gltf.buffers.Add(new glTFBuffer(new ArrayByteBuffer(new byte[reserved])));
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace UniGLTF
|
||||
{
|
||||
public class gltfExporter : IDisposable
|
||||
{
|
||||
protected glTF glTF;
|
||||
protected ExportingGltfData _data;
|
||||
|
||||
protected ExportingGltfData _writer;
|
||||
protected glTF _gltf => _data.GLTF;
|
||||
|
||||
public GameObject Copy
|
||||
{
|
||||
@@ -69,14 +69,13 @@ namespace UniGLTF
|
||||
|
||||
GltfExportSettings m_settings;
|
||||
|
||||
public gltfExporter(glTF gltf, GltfExportSettings settings)
|
||||
public gltfExporter(ExportingGltfData data, GltfExportSettings settings)
|
||||
{
|
||||
glTF = gltf;
|
||||
_writer = new ExportingGltfData (gltf);
|
||||
_data = data;
|
||||
|
||||
glTF.extensionsUsed.AddRange(ExtensionUsed);
|
||||
_gltf.extensionsUsed.AddRange(ExtensionUsed);
|
||||
|
||||
glTF.asset = new glTFAssets
|
||||
_gltf.asset = new glTFAssets
|
||||
{
|
||||
generator = "UniGLTF-" + UniGLTFVersion.VERSION,
|
||||
version = "2.0",
|
||||
@@ -225,7 +224,7 @@ namespace UniGLTF
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public virtual ExportingGltfData Export(ITextureSerializer textureSerializer)
|
||||
public virtual void Export(ITextureSerializer textureSerializer)
|
||||
{
|
||||
Nodes = Copy.transform.Traverse()
|
||||
.Skip(1) // exclude root object for the symmetry with the importer
|
||||
@@ -240,7 +239,7 @@ namespace UniGLTF
|
||||
m_textureExporter = new TextureExporter(textureSerializer);
|
||||
|
||||
var materialExporter = CreateMaterialExporter();
|
||||
glTF.materials = Materials.Select(x => materialExporter.ExportMaterial(x, TextureExporter, m_settings)).ToList();
|
||||
_gltf.materials = Materials.Select(x => materialExporter.ExportMaterial(x, TextureExporter, m_settings)).ToList();
|
||||
#endregion
|
||||
|
||||
#region Meshes
|
||||
@@ -253,10 +252,10 @@ namespace UniGLTF
|
||||
}
|
||||
|
||||
var (gltfMesh, blendShapeIndexMap) = m_settings.DivideVertexBuffer
|
||||
? MeshExporter_DividedVertexBuffer.Export(_writer, unityMesh, Materials, m_settings.InverseAxis.Create(), m_settings)
|
||||
: MeshExporter_SharedVertexBuffer.Export(_writer, unityMesh, Materials, m_settings.InverseAxis.Create(), m_settings)
|
||||
? MeshExporter_DividedVertexBuffer.Export(_data, unityMesh, Materials, m_settings.InverseAxis.Create(), m_settings)
|
||||
: MeshExporter_SharedVertexBuffer.Export(_data, unityMesh, Materials, m_settings.InverseAxis.Create(), m_settings)
|
||||
;
|
||||
glTF.meshes.Add(gltfMesh);
|
||||
_gltf.meshes.Add(gltfMesh);
|
||||
Meshes.Add(unityMesh.Mesh);
|
||||
if (!MeshBlendShapeIndexMap.ContainsKey(unityMesh.Mesh))
|
||||
{
|
||||
@@ -276,9 +275,9 @@ namespace UniGLTF
|
||||
foreach (var node in Nodes)
|
||||
{
|
||||
var gltfNode = ExportNode(node, Nodes, uniqueUnityMeshes, skins);
|
||||
glTF.nodes.Add(gltfNode);
|
||||
_gltf.nodes.Add(gltfNode);
|
||||
}
|
||||
glTF.scenes = new List<gltfScene>
|
||||
_gltf.scenes = new List<gltfScene>
|
||||
{
|
||||
new gltfScene
|
||||
{
|
||||
@@ -293,20 +292,20 @@ namespace UniGLTF
|
||||
if (uniqueBones != null && renderer is SkinnedMeshRenderer smr)
|
||||
{
|
||||
var matrices = x.GetBindPoses().Select(m_settings.InverseAxis.Create().InvertMat4).ToArray();
|
||||
var accessor = _writer.ExtendBufferAndGetAccessorIndex(matrices, glBufferTarget.NONE);
|
||||
var accessor = _data.ExtendBufferAndGetAccessorIndex(matrices, glBufferTarget.NONE);
|
||||
var skin = new glTFSkin
|
||||
{
|
||||
inverseBindMatrices = accessor,
|
||||
joints = uniqueBones.Select(y => Nodes.IndexOf(y)).ToArray(),
|
||||
skeleton = Nodes.IndexOf(smr.rootBone),
|
||||
};
|
||||
var skinIndex = glTF.skins.Count;
|
||||
glTF.skins.Add(skin);
|
||||
var skinIndex = _gltf.skins.Count;
|
||||
_gltf.skins.Add(skin);
|
||||
|
||||
foreach (var z in Nodes.Where(y => y.Has(renderer)))
|
||||
{
|
||||
var nodeIndex = Nodes.IndexOf(z);
|
||||
var node = glTF.nodes[nodeIndex];
|
||||
var node = _gltf.nodes[nodeIndex];
|
||||
node.skin = skinIndex;
|
||||
}
|
||||
}
|
||||
@@ -339,14 +338,14 @@ namespace UniGLTF
|
||||
{
|
||||
var sampler = animationWithCurve.Animation.samplers[kv.Key];
|
||||
|
||||
var inputAccessorIndex = _writer.ExtendBufferAndGetAccessorIndex(kv.Value.Input);
|
||||
var inputAccessorIndex = _data.ExtendBufferAndGetAccessorIndex(kv.Value.Input);
|
||||
sampler.input = inputAccessorIndex;
|
||||
|
||||
var outputAccessorIndex = _writer.ExtendBufferAndGetAccessorIndex(kv.Value.Output);
|
||||
var outputAccessorIndex = _data.ExtendBufferAndGetAccessorIndex(kv.Value.Output);
|
||||
sampler.output = outputAccessorIndex;
|
||||
|
||||
// modify accessors
|
||||
var outputAccessor = glTF.accessors[outputAccessorIndex];
|
||||
var outputAccessor = _gltf.accessors[outputAccessorIndex];
|
||||
var channel = animationWithCurve.Animation.channels.First(x => x.sampler == kv.Key);
|
||||
switch (glTFAnimationTarget.GetElementCount(channel.target.path))
|
||||
{
|
||||
@@ -369,7 +368,7 @@ namespace UniGLTF
|
||||
}
|
||||
}
|
||||
animationWithCurve.Animation.name = clip.name;
|
||||
glTF.animations.Add(animationWithCurve.Animation);
|
||||
_gltf.animations.Add(animationWithCurve.Animation);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -383,12 +382,10 @@ namespace UniGLTF
|
||||
for (var exportedTextureIdx = 0; exportedTextureIdx < exported.Count; ++exportedTextureIdx)
|
||||
{
|
||||
var (unityTexture, colorSpace) = exported[exportedTextureIdx];
|
||||
GltfTextureExporter.PushGltfTexture(_writer, unityTexture, colorSpace, textureSerializer);
|
||||
GltfTextureExporter.PushGltfTexture(_data, unityTexture, colorSpace, textureSerializer);
|
||||
}
|
||||
|
||||
FixName(glTF);
|
||||
|
||||
return _writer;
|
||||
FixName(_gltf);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -122,8 +122,8 @@ namespace UniGLTF
|
||||
root.GetComponent<MeshRenderer>().sharedMaterial = mat;
|
||||
|
||||
// Export glTF
|
||||
var gltf = new glTF();
|
||||
using (var exporter = new gltfExporter(gltf, new GltfExportSettings
|
||||
var data = new ExportingGltfData();
|
||||
using (var exporter = new gltfExporter(data, new GltfExportSettings
|
||||
{
|
||||
InverseAxis = Axes.X,
|
||||
ExportOnlyBlendShapePosition = false,
|
||||
@@ -134,6 +134,7 @@ namespace UniGLTF
|
||||
exporter.Prepare(root);
|
||||
exporter.Export(new EditorTextureSerializer());
|
||||
}
|
||||
var gltf = data.GLTF;
|
||||
Assert.AreEqual(1, gltf.images.Count);
|
||||
var exportedImage = gltf.images[0];
|
||||
Assert.AreEqual("image/png", exportedImage.mimeType);
|
||||
@@ -142,10 +143,10 @@ namespace UniGLTF
|
||||
UnityEngine.Object.DestroyImmediate(mat);
|
||||
UnityEngine.Object.DestroyImmediate(root);
|
||||
|
||||
var data = GltfData.CreateFromGltfDataForTest(gltf);
|
||||
var parsed = GltfData.CreateFromGltfDataForTest(gltf);
|
||||
|
||||
// Extract Image to Texture2D
|
||||
var exportedBytes = data.GetViewBytes(exportedImage.bufferView).ToArray();
|
||||
var exportedBytes = parsed.GetViewBytes(exportedImage.bufferView).ToArray();
|
||||
var exportedTexture = new Texture2D(2, 2, TextureFormat.ARGB32, mipChain: false, linear: false);
|
||||
Assert.IsTrue(exportedTexture.LoadImage(exportedBytes)); // Always true ?
|
||||
Assert.AreEqual(srcTex.width, exportedTexture.width);
|
||||
|
||||
@@ -8,7 +8,8 @@ namespace UniGLTF
|
||||
[Test]
|
||||
public void TextureNameUniqueness()
|
||||
{
|
||||
var gltf = new glTF();
|
||||
var data = new ExportingGltfData();
|
||||
var gltf = data.GLTF;
|
||||
gltf.asset.version = "2.0";
|
||||
gltf.buffers.Add(new glTFBuffer(new ArrayByteBuffer(Array.Empty<byte>())));
|
||||
gltf.textures.Add(new glTFTexture
|
||||
@@ -30,12 +31,12 @@ namespace UniGLTF
|
||||
name = "hogefuga",
|
||||
});
|
||||
|
||||
var parser = new GlbLowLevelParser("Test", new ExportingGltfData (gltf).ToGlbBytes());
|
||||
var data = parser.Parse();
|
||||
var parser = new GlbLowLevelParser("Test", data.ToGlbBytes());
|
||||
var parsed = parser.Parse();
|
||||
|
||||
Assert.AreEqual("FooBar", data.GLTF.textures[0].name);
|
||||
Assert.AreEqual("FooBar", parsed.GLTF.textures[0].name);
|
||||
// NOTE: 大文字小文字が違うだけの名前は、同一としてみなされ、Suffix が付く。
|
||||
Assert.AreEqual("foobar__UNIGLTF__DUPLICATED__2", data.GLTF.textures[1].name);
|
||||
Assert.AreEqual("foobar__UNIGLTF__DUPLICATED__2", parsed.GLTF.textures[1].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,13 +57,13 @@ namespace UniGLTF
|
||||
|
||||
static Byte[] Export(GameObject root)
|
||||
{
|
||||
var gltf = new glTF();
|
||||
using (var exporter = new gltfExporter(gltf, new GltfExportSettings()))
|
||||
var data = new ExportingGltfData();
|
||||
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
|
||||
{
|
||||
exporter.Prepare(root);
|
||||
var w = exporter.Export(new EditorTextureSerializer());
|
||||
return w.ToGlbBytes();
|
||||
exporter.Export(new EditorTextureSerializer());
|
||||
}
|
||||
return data.ToGlbBytes();
|
||||
}
|
||||
|
||||
// Unsolved Animation Export issue
|
||||
|
||||
@@ -117,8 +117,7 @@ namespace UniGLTF
|
||||
[Test]
|
||||
public void SharedVertexBufferTest()
|
||||
{
|
||||
var glTF = new glTF();
|
||||
var w = new ExportingGltfData (glTF, 50 * 1024 * 1024);
|
||||
var data = new ExportingGltfData(50 * 1024 * 1024);
|
||||
|
||||
var Materials = new List<Material>{
|
||||
new Material(Shader.Find("Standard")), // A
|
||||
@@ -134,13 +133,14 @@ namespace UniGLTF
|
||||
|
||||
var unityMesh = MeshExportList.Create(go);
|
||||
var (gltfMesh, blendShapeIndexMap) = meshExportSettings.DivideVertexBuffer
|
||||
? MeshExporter_DividedVertexBuffer.Export(w, unityMesh, Materials, axisInverter, meshExportSettings)
|
||||
: MeshExporter_SharedVertexBuffer.Export(w, unityMesh, Materials, axisInverter, meshExportSettings)
|
||||
? MeshExporter_DividedVertexBuffer.Export(data, unityMesh, Materials, axisInverter, meshExportSettings)
|
||||
: MeshExporter_SharedVertexBuffer.Export(data, unityMesh, Materials, axisInverter, meshExportSettings)
|
||||
;
|
||||
var data = GltfData.CreateFromGltfDataForTest(glTF);
|
||||
|
||||
var parsed = GltfData.CreateFromGltfDataForTest(data.GLTF);
|
||||
|
||||
{
|
||||
var indices = data.GetIndices(gltfMesh.primitives[0].indices);
|
||||
var indices = parsed.GetIndices(gltfMesh.primitives[0].indices);
|
||||
Assert.AreEqual(0, indices[0]);
|
||||
Assert.AreEqual(1, indices[1]);
|
||||
Assert.AreEqual(5, indices[2]);
|
||||
@@ -150,7 +150,7 @@ namespace UniGLTF
|
||||
}
|
||||
|
||||
{
|
||||
var indices = data.GetIndices(gltfMesh.primitives[1].indices);
|
||||
var indices = parsed.GetIndices(gltfMesh.primitives[1].indices);
|
||||
Assert.AreEqual(1, indices[0]);
|
||||
Assert.AreEqual(2, indices[1]);
|
||||
Assert.AreEqual(4, indices[2]);
|
||||
@@ -159,15 +159,14 @@ namespace UniGLTF
|
||||
Assert.AreEqual(3, indices[5]);
|
||||
}
|
||||
|
||||
var positions = data.GetArrayFromAccessor<Vector3>(gltfMesh.primitives[0].attributes.POSITION);
|
||||
var positions = parsed.GetArrayFromAccessor<Vector3>(gltfMesh.primitives[0].attributes.POSITION);
|
||||
Assert.AreEqual(6, positions.Length);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DividedVertexBufferTest()
|
||||
{
|
||||
var glTF = new glTF();
|
||||
var w = new ExportingGltfData (glTF, 50 * 1024 * 1024);
|
||||
var data = new ExportingGltfData(50 * 1024 * 1024);
|
||||
|
||||
var Materials = new List<Material>{
|
||||
new Material(Shader.Find("Standard")), // A
|
||||
@@ -183,13 +182,13 @@ namespace UniGLTF
|
||||
|
||||
var unityMesh = MeshExportList.Create(go);
|
||||
var (gltfMesh, blendShapeIndexMap) = meshExportSettings.DivideVertexBuffer
|
||||
? MeshExporter_DividedVertexBuffer.Export(w, unityMesh, Materials, axisInverter, meshExportSettings)
|
||||
: MeshExporter_SharedVertexBuffer.Export(w, unityMesh, Materials, axisInverter, meshExportSettings)
|
||||
? MeshExporter_DividedVertexBuffer.Export(data, unityMesh, Materials, axisInverter, meshExportSettings)
|
||||
: MeshExporter_SharedVertexBuffer.Export(data, unityMesh, Materials, axisInverter, meshExportSettings)
|
||||
;
|
||||
|
||||
var data = GltfData.CreateFromGltfDataForTest(glTF);
|
||||
var parsed = GltfData.CreateFromGltfDataForTest(data.GLTF);
|
||||
{
|
||||
var indices = data.GetIndices(gltfMesh.primitives[0].indices);
|
||||
var indices = parsed.GetIndices(gltfMesh.primitives[0].indices);
|
||||
Assert.AreEqual(0, indices[0]);
|
||||
Assert.AreEqual(1, indices[1]);
|
||||
Assert.AreEqual(3, indices[2]);
|
||||
@@ -198,12 +197,12 @@ namespace UniGLTF
|
||||
Assert.AreEqual(2, indices[5]);
|
||||
}
|
||||
{
|
||||
var positions = data.GetArrayFromAccessor<Vector3>(gltfMesh.primitives[0].attributes.POSITION);
|
||||
var positions = parsed.GetArrayFromAccessor<Vector3>(gltfMesh.primitives[0].attributes.POSITION);
|
||||
Assert.AreEqual(4, positions.Length);
|
||||
}
|
||||
|
||||
{
|
||||
var indices = data.GetIndices(gltfMesh.primitives[1].indices);
|
||||
var indices = parsed.GetIndices(gltfMesh.primitives[1].indices);
|
||||
Assert.AreEqual(0, indices[0]);
|
||||
Assert.AreEqual(1, indices[1]);
|
||||
Assert.AreEqual(3, indices[2]);
|
||||
@@ -212,7 +211,7 @@ namespace UniGLTF
|
||||
Assert.AreEqual(2, indices[5]);
|
||||
}
|
||||
{
|
||||
var positions = data.GetArrayFromAccessor<Vector3>(gltfMesh.primitives[1].attributes.POSITION);
|
||||
var positions = parsed.GetArrayFromAccessor<Vector3>(gltfMesh.primitives[1].attributes.POSITION);
|
||||
Assert.AreEqual(4, positions.Length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,25 +100,25 @@ namespace UniGLTF
|
||||
var go = CreateSimpleScene();
|
||||
|
||||
// export
|
||||
var gltf = new glTF();
|
||||
var data = new ExportingGltfData();
|
||||
|
||||
string json = null;
|
||||
using (var exporter = new gltfExporter(gltf, new GltfExportSettings()))
|
||||
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
|
||||
{
|
||||
exporter.Prepare(go);
|
||||
exporter.Export(new EditorTextureSerializer());
|
||||
|
||||
// remove empty buffer
|
||||
gltf.buffers.Clear();
|
||||
data.GLTF.buffers.Clear();
|
||||
|
||||
json = gltf.ToJson();
|
||||
json = data.GLTF.ToJson();
|
||||
}
|
||||
|
||||
// parse
|
||||
var data = new JsonWithStorageParser(json).Parse();
|
||||
var parsed = new JsonWithStorageParser(json).Parse();
|
||||
|
||||
// import
|
||||
using (var context = new ImporterContext(data))
|
||||
using (var context = new ImporterContext(parsed))
|
||||
using (var loaded = context.Load())
|
||||
{
|
||||
AssertAreEqual(go.transform, loaded.transform);
|
||||
@@ -293,14 +293,14 @@ namespace UniGLTF
|
||||
[Test]
|
||||
public void GlTFToJsonTest()
|
||||
{
|
||||
var gltf = new glTF();
|
||||
using (var exporter = new gltfExporter(gltf, new GltfExportSettings()))
|
||||
var data = new ExportingGltfData();
|
||||
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
|
||||
{
|
||||
exporter.Prepare(CreateSimpleScene());
|
||||
exporter.Export(new EditorTextureSerializer());
|
||||
}
|
||||
|
||||
var expected = gltf.ToJson().ParseAsJson();
|
||||
var expected = data.GLTF.ToJson().ParseAsJson();
|
||||
expected.AddKey(Utf8String.From("meshes"));
|
||||
expected.AddValue(default(ArraySegment<byte>), ValueNodeType.Array);
|
||||
expected["meshes"].AddValue(default(ArraySegment<byte>), ValueNodeType.Object);
|
||||
@@ -334,7 +334,7 @@ namespace UniGLTF
|
||||
primitive["targets"][1].AddKey(Utf8String.From("TANGENT"));
|
||||
primitive["targets"][1].AddValue(Utf8String.From("0").Bytes, ValueNodeType.Integer);
|
||||
|
||||
gltf.meshes.Add(new glTFMesh("test")
|
||||
data.GLTF.meshes.Add(new glTFMesh("test")
|
||||
{
|
||||
primitives = new List<glTFPrimitives>
|
||||
{
|
||||
@@ -362,7 +362,7 @@ namespace UniGLTF
|
||||
}
|
||||
}
|
||||
});
|
||||
var actual = gltf.ToJson().ParseAsJson();
|
||||
var actual = data.GLTF.ToJson().ParseAsJson();
|
||||
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
@@ -528,9 +528,10 @@ namespace UniGLTF
|
||||
}
|
||||
|
||||
// export
|
||||
var gltf = new glTF();
|
||||
var data = new ExportingGltfData();
|
||||
var gltf = data.GLTF;
|
||||
var json = default(string);
|
||||
using (var exporter = new gltfExporter(gltf, new GltfExportSettings()))
|
||||
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
|
||||
{
|
||||
exporter.Prepare(go);
|
||||
exporter.Export(new EditorTextureSerializer());
|
||||
@@ -553,9 +554,9 @@ namespace UniGLTF
|
||||
// import
|
||||
{
|
||||
var storage = new SimpleStorage(new ArraySegment<byte>(new byte[1024 * 1024]));
|
||||
var data = new JsonWithStorageParser(json, storage).Parse();
|
||||
var parsed = new JsonWithStorageParser(json, storage).Parse();
|
||||
|
||||
using (var context = new ImporterContext(data))
|
||||
using (var context = new ImporterContext(parsed))
|
||||
using (var loaded = context.Load())
|
||||
{
|
||||
var importedRed = loaded.transform.GetChild(0);
|
||||
@@ -573,10 +574,10 @@ namespace UniGLTF
|
||||
// import new version
|
||||
{
|
||||
var storage = new SimpleStorage(new ArraySegment<byte>(new byte[1024 * 1024]));
|
||||
var data = new JsonWithStorageParser(json, storage).Parse();
|
||||
var parsed = new JsonWithStorageParser(json, storage).Parse();
|
||||
|
||||
//Debug.LogFormat("{0}", context.Json);
|
||||
using (var context = new ImporterContext(data))
|
||||
using (var context = new ImporterContext(parsed))
|
||||
using (var loaded = context.Load())
|
||||
{
|
||||
var importedRed = loaded.transform.GetChild(0);
|
||||
@@ -610,9 +611,10 @@ namespace UniGLTF
|
||||
}
|
||||
|
||||
// export
|
||||
var gltf = new glTF();
|
||||
var data = new ExportingGltfData();
|
||||
var gltf = data.GLTF;
|
||||
string json;
|
||||
using (var exporter = new gltfExporter(gltf, new GltfExportSettings()))
|
||||
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
|
||||
{
|
||||
exporter.Prepare(go);
|
||||
exporter.Export(new EditorTextureSerializer());
|
||||
@@ -627,9 +629,9 @@ namespace UniGLTF
|
||||
// import
|
||||
{
|
||||
var storage = new SimpleStorage(new ArraySegment<byte>(new byte[1024 * 1024]));
|
||||
var data = new JsonWithStorageParser(json, storage).Parse();
|
||||
var parsed = new JsonWithStorageParser(json, storage).Parse();
|
||||
|
||||
using (var context = new ImporterContext(data))
|
||||
using (var context = new ImporterContext(parsed))
|
||||
using (var loaded = context.Load())
|
||||
{
|
||||
Assert.AreEqual(1, loaded.transform.GetChildren().Count());
|
||||
@@ -674,9 +676,10 @@ namespace UniGLTF
|
||||
Assert.True(vs.All(x => x.CanExport));
|
||||
|
||||
// export
|
||||
var gltf = new glTF();
|
||||
var data = new ExportingGltfData();
|
||||
var gltf = data.GLTF;
|
||||
string json;
|
||||
using (var exporter = new gltfExporter(gltf, new GltfExportSettings()))
|
||||
using (var exporter = new gltfExporter(data, new GltfExportSettings()))
|
||||
{
|
||||
exporter.Prepare(root);
|
||||
exporter.Export(new EditorTextureSerializer());
|
||||
@@ -692,9 +695,9 @@ namespace UniGLTF
|
||||
// import
|
||||
{
|
||||
var storage = new SimpleStorage(new ArraySegment<byte>(new byte[1024 * 1024]));
|
||||
var data = new JsonWithStorageParser(json, storage).Parse();
|
||||
var parsed = new JsonWithStorageParser(json, storage).Parse();
|
||||
|
||||
using (var context = new ImporterContext(data))
|
||||
using (var context = new ImporterContext(parsed))
|
||||
using (var loaded = context.Load())
|
||||
{
|
||||
Assert.AreEqual(2, loaded.transform.GetChildren().Count());
|
||||
|
||||
@@ -222,14 +222,13 @@ namespace VRM
|
||||
|
||||
// 出力
|
||||
var sw = System.Diagnostics.Stopwatch.StartNew();
|
||||
var gltf = new UniGLTF.glTF();
|
||||
ExportingGltfData writer = default;
|
||||
using (var exporter = new VRMExporter(gltf, settings.MeshExportSettings))
|
||||
var data = new UniGLTF.ExportingGltfData();
|
||||
using (var exporter = new VRMExporter(data, settings.MeshExportSettings))
|
||||
{
|
||||
exporter.Prepare(target);
|
||||
writer = exporter.Export(new EditorTextureSerializer());
|
||||
exporter.Export(new EditorTextureSerializer());
|
||||
}
|
||||
var bytes = writer.ToGlbBytes();
|
||||
var bytes = data.ToGlbBytes();
|
||||
Debug.LogFormat("Export elapsed {0}", sw.Elapsed);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@@ -12,26 +12,27 @@ namespace VRM
|
||||
{
|
||||
public const Axes Vrm0xSpecificationInverseAxis = Axes.Z;
|
||||
|
||||
public static ExportingGltfData Export(GltfExportSettings configuration, GameObject go, ITextureSerializer textureSerializer)
|
||||
public static ExportingGltfData Export(GltfExportSettings configuration, GameObject go, ITextureSerializer textureSerializer)
|
||||
{
|
||||
var gltf = new glTF();
|
||||
using (var exporter = new VRMExporter(gltf, configuration))
|
||||
var data = new ExportingGltfData();
|
||||
using (var exporter = new VRMExporter(data, configuration))
|
||||
{
|
||||
exporter.Prepare(go);
|
||||
return exporter.Export(textureSerializer);
|
||||
exporter.Export(textureSerializer);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public readonly VRM.glTF_VRM_extensions VRM = new glTF_VRM_extensions();
|
||||
|
||||
public VRMExporter(glTF gltf, GltfExportSettings exportSettings) : base(gltf, exportSettings)
|
||||
public VRMExporter(ExportingGltfData data, GltfExportSettings exportSettings) : base(data, exportSettings)
|
||||
{
|
||||
if (exportSettings == null || exportSettings.InverseAxis != Vrm0xSpecificationInverseAxis)
|
||||
{
|
||||
throw new Exception($"VRM specification requires InverseAxis settings as {Vrm0xSpecificationInverseAxis}");
|
||||
}
|
||||
|
||||
gltf.extensionsUsed.Add(glTF_VRM_extensions.ExtensionName);
|
||||
_gltf.extensionsUsed.Add(glTF_VRM_extensions.ExtensionName);
|
||||
}
|
||||
|
||||
protected override IMaterialExporter CreateMaterialExporter()
|
||||
@@ -117,7 +118,7 @@ namespace VRM
|
||||
VRM.meta.title = meta.Title;
|
||||
if (meta.Thumbnail != null)
|
||||
{
|
||||
VRM.meta.texture = GltfTextureExporter.PushGltfTexture(_writer, meta.Thumbnail, ColorSpace.sRGB, textureSerializer);
|
||||
VRM.meta.texture = GltfTextureExporter.PushGltfTexture(_data, meta.Thumbnail, ColorSpace.sRGB, textureSerializer);
|
||||
}
|
||||
|
||||
VRM.meta.licenseType = meta.LicenseType;
|
||||
@@ -212,7 +213,7 @@ namespace VRM
|
||||
var f = new JsonFormatter();
|
||||
VRMSerializer.Serialize(f, VRM);
|
||||
var bytes = f.GetStoreBytes();
|
||||
glTFExtensionExport.GetOrCreate(ref glTF.extensions).Add("VRM", bytes);
|
||||
glTFExtensionExport.GetOrCreate(ref _gltf.extensions).Add("VRM", bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ using VrmLib;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public class Vrm10Storage : ExportingGltfData
|
||||
public class Vrm10Storage : ExportingGltfData
|
||||
{
|
||||
UniGLTF.GltfData m_data;
|
||||
public UniGLTF.glTF Gltf => m_data.GLTF;
|
||||
@@ -24,10 +24,7 @@ namespace UniVRM10
|
||||
/// <summary>
|
||||
/// for export
|
||||
/// </summary>
|
||||
public Vrm10Storage() : base(new glTF
|
||||
{
|
||||
extensionsUsed = new List<string>(),
|
||||
})
|
||||
public Vrm10Storage()
|
||||
{
|
||||
m_data = new GltfData(
|
||||
string.Empty,
|
||||
@@ -48,7 +45,7 @@ namespace UniVRM10
|
||||
/// </summary>
|
||||
/// <param name="json"></param>
|
||||
/// <param name="bin"></param>
|
||||
public Vrm10Storage(UniGLTF.GltfData data) : base(data.GLTF)
|
||||
public Vrm10Storage(UniGLTF.GltfData data)
|
||||
{
|
||||
m_data = data;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user