mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-28 05:44:48 -05:00
BufferAccessor のカプセル化を推進。カプセル化を破るが使っていないメソッドを削除。近隣の未使用も削除。
This commit is contained in:
@@ -80,13 +80,13 @@ namespace UniGLTF
|
||||
|
||||
public NativeArray<byte> Bytes { get; private set; }
|
||||
|
||||
public AccessorValueType ComponentType;
|
||||
public AccessorValueType ComponentType { get; private set; }
|
||||
|
||||
public AccessorVectorType AccessorType;
|
||||
public AccessorVectorType AccessorType { get; private set; }
|
||||
|
||||
public int Stride => ComponentType.ByteSize() * AccessorType.TypeCount();
|
||||
|
||||
public int Count;
|
||||
public int Count { get; private set; }
|
||||
|
||||
public int ByteLength => Stride * Count;
|
||||
|
||||
|
||||
@@ -62,139 +62,10 @@ namespace VrmLib
|
||||
|
||||
public BufferAccessor IndexBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// indicesの最大値が65535未満(-1を避ける)ならばushort 型で、
|
||||
/// そうでなければ int型で IndexBufferを代入する
|
||||
/// </summary>
|
||||
public void AssignIndexBuffer(NativeArray<int> indices)
|
||||
{
|
||||
bool isInt = false;
|
||||
foreach (var i in indices)
|
||||
{
|
||||
if (i >= short.MaxValue)
|
||||
{
|
||||
isInt = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isInt)
|
||||
{
|
||||
if (IndexBuffer.Stride != 4)
|
||||
{
|
||||
IndexBuffer.ComponentType = AccessorValueType.UNSIGNED_INT;
|
||||
if (IndexBuffer.AccessorType != AccessorVectorType.SCALAR)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
// 変換なし
|
||||
IndexBuffer.Assign(indices);
|
||||
}
|
||||
else
|
||||
{
|
||||
// int to ushort
|
||||
IndexBuffer.AssignAsShort(indices);
|
||||
}
|
||||
}
|
||||
|
||||
public TopologyType Topology = TopologyType.Triangles;
|
||||
|
||||
public List<Submesh> Submeshes { private set; get; } = new List<Submesh>();
|
||||
|
||||
public int SubmeshTotalDrawCount => Submeshes.Sum(x => x.DrawCount);
|
||||
|
||||
public IEnumerable<Triangle> GetTriangles(int i)
|
||||
{
|
||||
var indices = IndexBuffer.GetAsIntArray();
|
||||
|
||||
var submesh = Submeshes[i];
|
||||
var submeshEnd = submesh.Offset + submesh.DrawCount;
|
||||
for (int j = submesh.Offset; j < submeshEnd; j += 3)
|
||||
{
|
||||
var triangle = new Triangle(
|
||||
indices[j],
|
||||
indices[j + 1],
|
||||
indices[j + 2]
|
||||
);
|
||||
yield return triangle;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ValueTuple<int, Triangle>> Triangles
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Topology != TopologyType.Triangles)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
var indices = IndexBuffer.GetAsIntArray();
|
||||
|
||||
for (int i = 0; i < Submeshes.Count; ++i)
|
||||
{
|
||||
var submesh = Submeshes[i];
|
||||
var submeshEnd = submesh.Offset + submesh.DrawCount;
|
||||
for (int j = submesh.Offset; j < submeshEnd; j += 3)
|
||||
{
|
||||
var triangle = new Triangle(
|
||||
indices[j],
|
||||
indices[j + 1],
|
||||
indices[j + 2]
|
||||
);
|
||||
yield return (i, triangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GetSubmeshOverlapped<T>() where T : struct
|
||||
{
|
||||
var indices = IndexBuffer.GetSpan<ushort>();
|
||||
var offset = 0;
|
||||
var max = 0;
|
||||
foreach (var x in Submeshes)
|
||||
{
|
||||
var submeshIndices = indices.Slice(offset, x.DrawCount);
|
||||
var currentMax = 0;
|
||||
foreach (var y in submeshIndices)
|
||||
{
|
||||
if (y < max)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
currentMax = Math.Max(y, currentMax);
|
||||
}
|
||||
offset += x.DrawCount;
|
||||
max = currentMax;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsSubmeshOverlapped
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Submeshes.Count <= 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (IndexBuffer.ComponentType)
|
||||
{
|
||||
case AccessorValueType.UNSIGNED_SHORT:
|
||||
return GetSubmeshOverlapped<ushort>();
|
||||
|
||||
case AccessorValueType.UNSIGNED_INT:
|
||||
return GetSubmeshOverlapped<uint>();
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<MorphTarget> MorphTargets = new List<MorphTarget>();
|
||||
|
||||
public override string ToString()
|
||||
@@ -238,11 +109,6 @@ namespace VrmLib
|
||||
Topology = topology;
|
||||
}
|
||||
|
||||
public void RemoveUnusedSubmesh()
|
||||
{
|
||||
Submeshes = Submeshes.Where(x => x.DrawCount != 0).ToList();
|
||||
}
|
||||
|
||||
// Skin.Normalize
|
||||
public void ApplyRotationAndScaling(Matrix4x4 m)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user