GetAsVector4Array

This commit is contained in:
ousttrue
2022-04-19 14:09:50 +09:00
parent 9a394ea842
commit d1fb39bb3b
2 changed files with 24 additions and 1 deletions

View File

@@ -169,6 +169,29 @@ namespace UniGLTF
}
// BoneWeight用
public NativeArray<Vector4> GetAsVector4Array()
{
if (AccessorType != AccessorVectorType.VEC4)
{
throw new InvalidOperationException("not VEC4");
}
switch (ComponentType)
{
case AccessorValueType.FLOAT:
return Bytes.Reinterpret<Vector4>(1);
case AccessorValueType.UNSIGNED_BYTE:
return ArrayManager.Convert(Bytes.Reinterpret<Byte4>(1), (Byte4 b) => new Vector4(b.x / 255.0f, b.y / 255.0f, b.z / 255.0f, b.w / 255.0f));
case AccessorValueType.UNSIGNED_SHORT:
return ArrayManager.Convert(Bytes.Reinterpret<UShort4>(1), (UShort4 b) => new Vector4(b.x / 65535.0f, b.y / 65535.0f, b.z / 65535.0f, b.w / 65535.0f));
default:
throw new NotImplementedException();
}
}
// BoneJoint用
public NativeArray<SkinJoints> GetAsSkinJointsArray()
{
if (AccessorType != AccessorVectorType.VEC4)

View File

@@ -27,7 +27,7 @@ namespace UniVRM10
var normals = src.VertexBuffer.Normals?.Bytes.Reinterpret<Vector3>(1) ?? default;
var texCoords = src.VertexBuffer.TexCoords?.Bytes.Reinterpret<Vector2>(1) ?? default;
var colors = src.VertexBuffer.Colors?.Bytes.Reinterpret<Color>(1) ?? default;
var weights = src.VertexBuffer.Weights?.Bytes.Reinterpret<Vector4>(1) ?? default;
var weights = src.VertexBuffer.Weights?.GetAsVector4Array() ?? default;
var joints = src.VertexBuffer.Joints?.GetAsSkinJointsArray() ?? default;
using (var vertices = new NativeArray<MeshVertex>(positions.Length, Allocator.TempJob))