mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-10-02 07:42:25 -05:00
fix BUFFER_VIEW_TARGET_MISSING
This commit is contained in:
@@ -41,9 +41,9 @@ namespace UniVRM10
|
||||
return new MeshUpdater(data).Update(model);
|
||||
}
|
||||
|
||||
int AddBuffer(NativeArray<byte> bytes)
|
||||
int AddBuffer(NativeArray<byte> bytes, glBufferTarget target)
|
||||
{
|
||||
var bufferView = _buffer.Extend(bytes);
|
||||
var bufferView = _buffer.Extend(bytes, target);
|
||||
var index = _bufferViews.Count;
|
||||
_bufferViews.Add(bufferView);
|
||||
var mod = bytes.Length % 4;
|
||||
@@ -55,9 +55,9 @@ namespace UniVRM10
|
||||
return index;
|
||||
}
|
||||
|
||||
int AddAccessor<T>(NativeArray<T> span) where T : struct
|
||||
int AddAccessor<T>(NativeArray<T> span, glBufferTarget target) where T : struct
|
||||
{
|
||||
var bufferViewIndex = AddBuffer(span.Reinterpret<byte>(Marshal.SizeOf<T>()));
|
||||
var bufferViewIndex = AddBuffer(span.Reinterpret<byte>(Marshal.SizeOf<T>()), target);
|
||||
var accessor = new glTFAccessor
|
||||
{
|
||||
bufferView = bufferViewIndex,
|
||||
@@ -71,13 +71,13 @@ namespace UniVRM10
|
||||
return index;
|
||||
}
|
||||
|
||||
int? AddAccessor<T>(BufferAccessor buffer) where T : struct
|
||||
int? AddAccessor<T>(BufferAccessor buffer, glBufferTarget target) where T : struct
|
||||
{
|
||||
if (buffer == null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
return AddAccessor(buffer.GetSpan<T>());
|
||||
return AddAccessor(buffer.GetSpan<T>(), target);
|
||||
}
|
||||
|
||||
struct MorphAccessor
|
||||
@@ -99,7 +99,7 @@ namespace UniVRM10
|
||||
foreach (var image in gltf.images)
|
||||
{
|
||||
var bytes = _data.GetBytesFromBufferView(image.bufferView);
|
||||
image.bufferView = AddBuffer(bytes);
|
||||
image.bufferView = AddBuffer(bytes, default);
|
||||
}
|
||||
|
||||
// copy mesh
|
||||
@@ -136,7 +136,7 @@ namespace UniVRM10
|
||||
if (skinIndex == -1)
|
||||
{
|
||||
skinIndex = gltf.skins.Count;
|
||||
gltfSkin.inverseBindMatrices = AddAccessor(node.MeshGroup.Skin.InverseMatrices.GetSpan<Matrix4x4>());
|
||||
gltfSkin.inverseBindMatrices = AddAccessor(node.MeshGroup.Skin.InverseMatrices.GetSpan<Matrix4x4>(), default);
|
||||
gltf.skins.Add(gltfSkin);
|
||||
}
|
||||
else
|
||||
@@ -222,20 +222,20 @@ namespace UniVRM10
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
var position = AddAccessor<Vector3>(mesh.VertexBuffer.Positions);
|
||||
var normal = AddAccessor<Vector3>(mesh.VertexBuffer.Normals);
|
||||
var uv = AddAccessor<Vector2>(mesh.VertexBuffer.TexCoords);
|
||||
var weights = AddAccessor<Vector4>(mesh.VertexBuffer.Weights);
|
||||
var joints = AddAccessor<UShort4>(mesh.VertexBuffer.Joints);
|
||||
var color = AddAccessor<Vector4>(mesh.VertexBuffer.Colors);
|
||||
var position = AddAccessor<Vector3>(mesh.VertexBuffer.Positions, glBufferTarget.ARRAY_BUFFER);
|
||||
var normal = AddAccessor<Vector3>(mesh.VertexBuffer.Normals, glBufferTarget.ARRAY_BUFFER);
|
||||
var uv = AddAccessor<Vector2>(mesh.VertexBuffer.TexCoords, glBufferTarget.ARRAY_BUFFER);
|
||||
var weights = AddAccessor<Vector4>(mesh.VertexBuffer.Weights, glBufferTarget.ARRAY_BUFFER);
|
||||
var joints = AddAccessor<UShort4>(mesh.VertexBuffer.Joints, glBufferTarget.ARRAY_BUFFER);
|
||||
var color = AddAccessor<Vector4>(mesh.VertexBuffer.Colors, glBufferTarget.ARRAY_BUFFER);
|
||||
|
||||
var morphTargets = new MorphAccessor[] { };
|
||||
if (mesh.MorphTargets != null)
|
||||
{
|
||||
morphTargets = mesh.MorphTargets.Select(x => new MorphAccessor
|
||||
{
|
||||
Position = AddAccessor<Vector3>(x.VertexBuffer.Positions),
|
||||
Normal = AddAccessor<Vector3>(x.VertexBuffer.Normals),
|
||||
Position = AddAccessor<Vector3>(x.VertexBuffer.Positions, glBufferTarget.ARRAY_BUFFER),
|
||||
Normal = AddAccessor<Vector3>(x.VertexBuffer.Normals, glBufferTarget.ARRAY_BUFFER),
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ namespace UniVRM10
|
||||
foreach (var (gltfPrim, submesh) in Enumerable.Zip(gltfMesh.primitives, mesh.Submeshes, (l, r) => (l, r)))
|
||||
{
|
||||
var subIndices = indices.GetSubArray(submesh.Offset, submesh.DrawCount);
|
||||
gltfPrim.indices = AddAccessor(subIndices);
|
||||
gltfPrim.indices = AddAccessor(subIndices, glBufferTarget.ELEMENT_ARRAY_BUFFER);
|
||||
gltfPrim.attributes.POSITION = position.Value;
|
||||
gltfPrim.attributes.NORMAL = normal.GetValueOrDefault(-1); // たぶん、ありえる
|
||||
gltfPrim.attributes.TANGENT = -1;
|
||||
@@ -306,24 +306,24 @@ namespace UniVRM10
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
var position = AddAccessor<Vector3>(mesh.VertexBuffer.Positions);
|
||||
var normal = AddAccessor<Vector3>(mesh.VertexBuffer.Normals);
|
||||
var uv = AddAccessor<Vector2>(mesh.VertexBuffer.TexCoords);
|
||||
var weights = AddAccessor<Vector4>(mesh.VertexBuffer.Weights);
|
||||
var joints = AddAccessor<UShort4>(mesh.VertexBuffer.Joints);
|
||||
var color = AddAccessor<Vector4>(mesh.VertexBuffer.Colors);
|
||||
var position = AddAccessor<Vector3>(mesh.VertexBuffer.Positions, glBufferTarget.ARRAY_BUFFER);
|
||||
var normal = AddAccessor<Vector3>(mesh.VertexBuffer.Normals, glBufferTarget.ARRAY_BUFFER);
|
||||
var uv = AddAccessor<Vector2>(mesh.VertexBuffer.TexCoords, glBufferTarget.ARRAY_BUFFER);
|
||||
var weights = AddAccessor<Vector4>(mesh.VertexBuffer.Weights, glBufferTarget.ARRAY_BUFFER);
|
||||
var joints = AddAccessor<UShort4>(mesh.VertexBuffer.Joints, glBufferTarget.ARRAY_BUFFER);
|
||||
var color = AddAccessor<Vector4>(mesh.VertexBuffer.Colors, glBufferTarget.ARRAY_BUFFER);
|
||||
|
||||
var morphTargets = new MorphAccessor[] { };
|
||||
if (mesh.MorphTargets != null)
|
||||
{
|
||||
morphTargets = mesh.MorphTargets.Select(x => new MorphAccessor
|
||||
{
|
||||
Position = AddAccessor<Vector3>(x.VertexBuffer.Positions),
|
||||
Normal = AddAccessor<Vector3>(x.VertexBuffer.Normals),
|
||||
Position = AddAccessor<Vector3>(x.VertexBuffer.Positions, glBufferTarget.ARRAY_BUFFER),
|
||||
Normal = AddAccessor<Vector3>(x.VertexBuffer.Normals, glBufferTarget.ARRAY_BUFFER),
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
gltfPrim.indices = AddAccessor(indices);
|
||||
gltfPrim.indices = AddAccessor(indices, glBufferTarget.ELEMENT_ARRAY_BUFFER);
|
||||
gltfPrim.attributes.POSITION = position.Value;
|
||||
gltfPrim.attributes.NORMAL = normal.GetValueOrDefault(-1); // たぶん、ありえる
|
||||
gltfPrim.attributes.TANGENT = -1;
|
||||
|
||||
Reference in New Issue
Block a user