頂点データを Set した際に Bounds を計算するようにする.

This commit is contained in:
Masataka SUMI 2021-11-30 18:54:43 +09:00
parent d7a85bea85
commit ff7a090c2e
3 changed files with 12 additions and 7 deletions

View File

@ -30,6 +30,9 @@ namespace UniGLTF
{
mesh.SetVertexBufferParams(_vertices.Count, MeshVertex.GetVertexAttributeDescriptor());
mesh.SetVertexBufferData(_vertices, 0, 0, _vertices.Count);
// NOTE: mesh.vertices では自動的に行われていたが、SetVertexBuffer では行われないため、明示的に呼び出す.
mesh.RecalculateBounds();
}
/// <summary>
/// インデックス情報をMeshに対して送る
@ -45,7 +48,7 @@ namespace UniGLTF
mesh.SetSubMesh(i, _subMeshes[i]);
}
}
private BlendShape GetOrCreateBlendShape(int i)
{
if (i < _blendShapes.Count && _blendShapes[i] != null)
@ -93,7 +96,7 @@ namespace UniGLTF
/// <summary>
/// 各 primitive の attribute の要素が同じでない。=> uv が有るものと無いものが混在するなど
/// glTF 的にはありうる。
///
///
/// primitive を独立した(Independent) Mesh として扱いこれを連結する。
/// </summary>
/// <param name="ctx"></param>
@ -232,7 +235,7 @@ namespace UniGLTF
}
/// <summary>
///
///
/// 各primitiveが同じ attribute を共有している場合専用のローダー。
///
/// </summary>

View File

@ -31,13 +31,13 @@ namespace UniVRM10
var joints = src.VertexBuffer.Joints?.AsNativeArray<SkinJoints>(Allocator.TempJob) ?? default;
var vertices = new NativeArray<MeshVertex>(positions.Length, Allocator.TempJob);
// JobとBindPoseの更新を並行して行う
var jobHandle =
new InterleaveMeshVerticesJob(vertices, positions, normals, texCoords, colors, weights, joints)
.Schedule(vertices.Length, 1);
JobHandle.ScheduleBatchedJobs();
// BindPoseを更新
if (weights.IsCreated && joints.IsCreated)
{
@ -53,7 +53,7 @@ namespace UniVRM10
// Jobを完了
jobHandle.Complete();
// 入力のNativeArrayを開放
positions.Dispose();
if (normals.IsCreated) normals.Dispose();
@ -65,6 +65,7 @@ namespace UniVRM10
// 頂点を更新
MeshVertex.SetVertexBufferParamsToMesh(mesh, vertices.Length);
mesh.SetVertexBufferData(vertices, 0, 0, vertices.Length);
mesh.RecalculateBounds();
// 出力のNativeArrayを開放
vertices.Dispose();
@ -110,7 +111,7 @@ namespace UniVRM10
// 各種パラメーターを再計算
mesh.RecalculateBounds();
mesh.RecalculateTangents();
Profiler.EndSample();
return mesh;

View File

@ -276,6 +276,7 @@ namespace UniVRM10
// VertexBufferを設定
MeshVertex.SetVertexBufferParamsToMesh(resultMesh, vertices.Length);
resultMesh.SetVertexBufferData(vertices, 0, 0, vertices.Length);
resultMesh.RecalculateBounds();
// 各種バッファを破棄
foreach (var disposable in disposables)