mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-10-01 15:22:53 -05:00
Merge Vrm10ExportData to ExportingGltfData
This commit is contained in:
@@ -135,6 +135,20 @@ namespace UniGLTF
|
||||
});
|
||||
return accessorIndex;
|
||||
}
|
||||
|
||||
public void Reserve(int bytesLength)
|
||||
{
|
||||
_buffer.ExtendCapacity(bytesLength);
|
||||
}
|
||||
|
||||
public int AppendToBuffer(ArraySegment<byte> segment)
|
||||
{
|
||||
var gltfBufferView = _buffer.Extend(segment);
|
||||
var viewIndex = GLTF.bufferViews.Count;
|
||||
GLTF.bufferViews.Add(gltfBufferView);
|
||||
return viewIndex;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ToGltf & ToGlb
|
||||
@@ -154,6 +168,18 @@ namespace UniGLTF
|
||||
return Glb.Create(json, BinBytes).ToBytes();
|
||||
}
|
||||
|
||||
// public byte[] ToBytes()
|
||||
// {
|
||||
// GLTF.buffers[0].byteLength = _buffer.Bytes.Count;
|
||||
|
||||
// var f = new JsonFormatter();
|
||||
// UniGLTF.GltfSerializer.Serialize(f, GLTF);
|
||||
// var json = f.GetStoreBytes();
|
||||
|
||||
// var glb = UniGLTF.Glb.Create(json, _buffer.Bytes);
|
||||
// return glb.ToBytes();
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// glTF 形式で出力する?
|
||||
/// </summary>
|
||||
|
||||
@@ -278,7 +278,7 @@ namespace UniVRM10
|
||||
var option = new VrmLib.ExportArgs();
|
||||
exporter.Export(root, model, converter, option, Vrm ? Vrm.Meta : m_tmpObject.Meta);
|
||||
|
||||
var exportedBytes = exporter.Storage.ToBytes();
|
||||
var exportedBytes = exporter.Storage.ToGlbBytes();
|
||||
|
||||
m_logLabel += $"write to {path}...\n";
|
||||
File.WriteAllBytes(path, exportedBytes);
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace UniVRM10
|
||||
}
|
||||
|
||||
public static int AddViewTo(this VrmLib.BufferAccessor self,
|
||||
Vrm10ExportData storage, int bufferIndex,
|
||||
ExportingGltfData data, int bufferIndex,
|
||||
int offset = 0, int count = 0)
|
||||
{
|
||||
var stride = self.Stride;
|
||||
@@ -39,7 +39,7 @@ namespace UniVRM10
|
||||
count = self.Count;
|
||||
}
|
||||
var slice = self.Bytes.Slice(offset * stride, count * stride);
|
||||
return storage.AppendToBuffer(slice);
|
||||
return data.AppendToBuffer(slice);
|
||||
}
|
||||
|
||||
static glTFAccessor CreateGltfAccessor(this VrmLib.BufferAccessor self,
|
||||
@@ -60,11 +60,11 @@ namespace UniVRM10
|
||||
}
|
||||
|
||||
public static int AddAccessorTo(this VrmLib.BufferAccessor self,
|
||||
Vrm10ExportData storage, int viewIndex,
|
||||
ExportingGltfData data, int viewIndex,
|
||||
Action<ArraySegment<byte>, glTFAccessor> minMax = null,
|
||||
int offset = 0, int count = 0)
|
||||
{
|
||||
var gltf = storage.GLTF;
|
||||
var gltf = data.GLTF;
|
||||
var accessorIndex = gltf.accessors.Count;
|
||||
var accessor = self.CreateGltfAccessor(viewIndex, count, offset * self.Stride);
|
||||
if (minMax != null)
|
||||
@@ -76,7 +76,7 @@ namespace UniVRM10
|
||||
}
|
||||
|
||||
public static int AddAccessorTo(this VrmLib.BufferAccessor self,
|
||||
Vrm10ExportData storage, int bufferIndex,
|
||||
ExportingGltfData data, int bufferIndex,
|
||||
// GltfBufferTargetType targetType,
|
||||
bool useSparse,
|
||||
Action<ArraySegment<byte>, glTFAccessor> minMax = null,
|
||||
@@ -116,10 +116,10 @@ namespace UniVRM10
|
||||
sparseValueSpan[i] = value;
|
||||
}
|
||||
|
||||
var sparseIndexView = storage.AppendToBuffer(sparseIndexBin);
|
||||
var sparseValueView = storage.AppendToBuffer(sparseValueBin);
|
||||
var sparseIndexView = data.AppendToBuffer(sparseIndexBin);
|
||||
var sparseValueView = data.AppendToBuffer(sparseValueBin);
|
||||
|
||||
var accessorIndex = storage.GLTF.accessors.Count;
|
||||
var accessorIndex = data.GLTF.accessors.Count;
|
||||
var accessor = new glTFAccessor
|
||||
{
|
||||
componentType = (glComponentType)self.ComponentType,
|
||||
@@ -144,13 +144,13 @@ namespace UniVRM10
|
||||
{
|
||||
minMax(sparseValueBin, accessor);
|
||||
}
|
||||
storage.GLTF.accessors.Add(accessor);
|
||||
data.GLTF.accessors.Add(accessor);
|
||||
return accessorIndex;
|
||||
}
|
||||
}
|
||||
|
||||
var viewIndex = self.AddViewTo(storage, bufferIndex, offset, count);
|
||||
return self.AddAccessorTo(storage, viewIndex, minMax, 0, count);
|
||||
var viewIndex = self.AddViewTo(data, bufferIndex, offset, count);
|
||||
return self.AddAccessorTo(data, viewIndex, minMax, 0, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace UniVRM10
|
||||
accessor.max = max.ToFloat3();
|
||||
}
|
||||
|
||||
static int ExportIndices(Vrm10ExportData storage, BufferAccessor x, int offset, int count, ExportArgs option)
|
||||
static int ExportIndices(ExportingGltfData data, BufferAccessor x, int offset, int count, ExportArgs option)
|
||||
{
|
||||
if (x.Count <= ushort.MaxValue)
|
||||
{
|
||||
@@ -41,16 +41,16 @@ namespace UniVRM10
|
||||
dst[i] = (ushort)src[i];
|
||||
}
|
||||
var accessor = new BufferAccessor(new ArraySegment<byte>(bytes), AccessorValueType.UNSIGNED_SHORT, AccessorVectorType.SCALAR, count);
|
||||
return accessor.AddAccessorTo(storage, 0, option.sparse, null, 0, count);
|
||||
return accessor.AddAccessorTo(data, 0, option.sparse, null, 0, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
return x.AddAccessorTo(storage, 0, option.sparse, null, offset, count);
|
||||
return x.AddAccessorTo(data, 0, option.sparse, null, offset, count);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return x.AddAccessorTo(storage, 0, option.sparse, null, offset, count);
|
||||
return x.AddAccessorTo(data, 0, option.sparse, null, offset, count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace UniVRM10
|
||||
/// </summary>
|
||||
/// <param name="mesh"></param>
|
||||
/// <param name="materials"></param>
|
||||
/// <param name="storage"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="gltfMesh"></param>
|
||||
/// <param name="option"></param>
|
||||
static IEnumerable<glTFPrimitives> ExportMeshDivided(this VrmLib.Mesh mesh, List<object> materials,
|
||||
@@ -157,7 +157,7 @@ namespace UniVRM10
|
||||
/// </summary>
|
||||
/// <param name="src"></param>
|
||||
/// <param name="materials"></param>
|
||||
/// <param name="storage"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="option"></param>
|
||||
/// <returns></returns>
|
||||
public static glTFMesh ExportMeshGroup(this MeshGroup src, List<object> materials, ExportingGltfData writer, ExportArgs option)
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
using System;
|
||||
using UniGLTF;
|
||||
using UniJSON;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public class Vrm10ExportData : ExportingGltfData
|
||||
{
|
||||
public void Reserve(int bytesLength)
|
||||
{
|
||||
_buffer.ExtendCapacity(bytesLength);
|
||||
}
|
||||
|
||||
public int AppendToBuffer(ArraySegment<byte> segment)
|
||||
{
|
||||
var gltfBufferView = _buffer.Extend(segment);
|
||||
var viewIndex = GLTF.bufferViews.Count;
|
||||
GLTF.bufferViews.Add(gltfBufferView);
|
||||
return viewIndex;
|
||||
}
|
||||
|
||||
public byte[] ToBytes()
|
||||
{
|
||||
GLTF.buffers[0].byteLength = _buffer.Bytes.Count;
|
||||
|
||||
var f = new JsonFormatter();
|
||||
UniGLTF.GltfSerializer.Serialize(f, GLTF);
|
||||
var json = f.GetStoreBytes();
|
||||
|
||||
var glb = UniGLTF.Glb.Create(json, _buffer.Bytes);
|
||||
return glb.ToBytes();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53bfc0b12550a494e8da90e632e1c456
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -18,7 +18,7 @@ namespace UniVRM10
|
||||
public const string LICENSE_URL_JA = "https://vrm.dev/licenses/1.0/";
|
||||
public const string LICENSE_URL_EN = "https://vrm.dev/licenses/1.0/en/";
|
||||
|
||||
public readonly Vrm10ExportData Storage = new Vrm10ExportData();
|
||||
public readonly ExportingGltfData Storage = new ExportingGltfData();
|
||||
|
||||
public readonly string VrmExtensionName = "VRMC_vrm";
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace UniVRM10
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<(glTFNode, glTFSkin)> ExportNodes(List<Node> nodes, List<MeshGroup> groups, Vrm10ExportData storage, ExportArgs option)
|
||||
public static IEnumerable<(glTFNode, glTFSkin)> ExportNodes(List<Node> nodes, List<MeshGroup> groups, ExportingGltfData data, ExportArgs option)
|
||||
{
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
@@ -100,7 +100,7 @@ namespace UniVRM10
|
||||
}
|
||||
if (skin.InverseMatrices != null)
|
||||
{
|
||||
gltfSkin.inverseBindMatrices = skin.InverseMatrices.AddAccessorTo(storage, 0, option.sparse);
|
||||
gltfSkin.inverseBindMatrices = skin.InverseMatrices.AddAccessorTo(data, 0, option.sparse);
|
||||
}
|
||||
if (skin.Root != null)
|
||||
{
|
||||
@@ -816,7 +816,7 @@ namespace UniVRM10
|
||||
{
|
||||
};
|
||||
exporter10.Export(go, model, converter, option);
|
||||
return exporter10.Storage.ToBytes();
|
||||
return exporter10.Storage.ToGlbBytes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user