using UniGLTF; using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; using Unity.Jobs; using UnityEngine; #if ENABLE_VRM10_BURST using Unity.Burst; #endif namespace UniVRM10 { /// /// 渡されたバッファを一つのバッファにインターリーブするJob /// #if ENABLE_VRM10_BURST [BurstCompile] #endif internal struct InterleaveMeshVerticesJob : IJobParallelFor { [WriteOnly] private NativeSlice _vertices0; [WriteOnly] private NativeSlice _vertices1; [WriteOnly] private NativeSlice _vertices2; [ReadOnly] private readonly NativeSlice _positions; // default値を許容する [ReadOnly, NativeDisableContainerSafetyRestriction] private readonly NativeSlice _normals; [ReadOnly, NativeDisableContainerSafetyRestriction] private readonly NativeSlice _texCoords; [ReadOnly, NativeDisableContainerSafetyRestriction] private readonly NativeSlice _colors; [ReadOnly, NativeDisableContainerSafetyRestriction] private readonly NativeSlice _weights; [ReadOnly, NativeDisableContainerSafetyRestriction] private readonly NativeSlice _joints; public InterleaveMeshVerticesJob( NativeSlice vertices0, NativeSlice vertices1, NativeSlice vertices2, NativeSlice positions, NativeSlice normals = default, NativeSlice texCoords = default, NativeSlice colors = default, NativeSlice weights = default, NativeSlice joints = default) { _vertices0 = vertices0; _vertices1 = vertices1; _vertices2 = vertices2; _positions = positions; _normals = normals; _texCoords = texCoords; _colors = colors; _weights = weights; _joints = joints; } public void Execute(int index) { _vertices0[index] = new MeshVertex0( _positions[index], _normals.Length > 0 ? _normals[index] : Vector3.zero ); _vertices1[index] = new MeshVertex1( _texCoords.Length > 0 ? _texCoords[index] : Vector2.zero, _colors.Length > 0 ? _colors[index] : Color.white ); _vertices2[index] = new MeshVertex2( _joints.Length > 0 ? _joints[index].Joint0 : (ushort)0, _joints.Length > 0 ? _joints[index].Joint1 : (ushort)0, _joints.Length > 0 ? _joints[index].Joint2 : (ushort)0, _joints.Length > 0 ? _joints[index].Joint3 : (ushort)0, _weights.Length > 0 ? _weights[index].x : 0, _weights.Length > 0 ? _weights[index].y : 0, _weights.Length > 0 ? _weights[index].z : 0, _weights.Length > 0 ? _weights[index].w : 0 ); } } }