Merge pull request #1644 from ousttrue/fix/gltf_without_indices

[1.0] gltf のバリエーション実装
This commit is contained in:
ousttrue
2022-05-12 18:08:30 +09:00
committed by GitHub
5 changed files with 39 additions and 14 deletions

View File

@@ -157,6 +157,9 @@ namespace UniGLTF
}
switch (ComponentType)
{
case AccessorValueType.UNSIGNED_BYTE:
return ArrayManager.Convert(Bytes, (byte x) => (int)x);
case AccessorValueType.UNSIGNED_SHORT:
return ArrayManager.Convert(Bytes.Reinterpret<ushort>(1), (ushort x) => (int)x);

View File

@@ -65,16 +65,27 @@ namespace UniVRM10
// Indexを更新
switch (src.IndexBuffer.ComponentType)
{
case AccessorValueType.UNSIGNED_BYTE:
{
var intIndices = src.IndexBuffer.GetAsIntArray();
mesh.SetIndexBufferParams(intIndices.Length, IndexFormat.UInt32);
mesh.SetIndexBufferData(intIndices, 0, 0, intIndices.Length);
break;
}
case AccessorValueType.UNSIGNED_SHORT:
var shortIndices = src.IndexBuffer.Bytes.Reinterpret<ushort>(1);
mesh.SetIndexBufferParams(shortIndices.Length, IndexFormat.UInt16);
mesh.SetIndexBufferData(shortIndices, 0, 0, shortIndices.Length);
break;
{
var shortIndices = src.IndexBuffer.Bytes.Reinterpret<ushort>(1);
mesh.SetIndexBufferParams(shortIndices.Length, IndexFormat.UInt16);
mesh.SetIndexBufferData(shortIndices, 0, 0, shortIndices.Length);
break;
}
case AccessorValueType.UNSIGNED_INT:
var intIndices = src.IndexBuffer.Bytes.Reinterpret<uint>(1);
mesh.SetIndexBufferParams(intIndices.Length, IndexFormat.UInt32);
mesh.SetIndexBufferData(intIndices, 0, 0, intIndices.Length);
break;
{
var intIndices = src.IndexBuffer.Bytes.Reinterpret<uint>(1);
mesh.SetIndexBufferParams(intIndices.Length, IndexFormat.UInt32);
mesh.SetIndexBufferData(intIndices, 0, 0, intIndices.Length);
break;
}
default:
throw new NotImplementedException();
}
@@ -101,6 +112,10 @@ namespace UniVRM10
// 各種パラメーターを再計算
mesh.RecalculateBounds();
mesh.RecalculateTangents();
if (src.VertexBuffer.Normals == null)
{
mesh.RecalculateNormals();
}
Profiler.EndSample();

View File

@@ -42,6 +42,10 @@ namespace UniVRM10
// 各種データを再構築
resultMesh.RecalculateBounds();
resultMesh.RecalculateTangents();
if (meshGroup.Meshes.Any(mesh => mesh.VertexBuffer.Normals == null))
{
resultMesh.RecalculateNormals();
}
// BlendShapeを更新
var blendShapeCount = meshGroup.Meshes[0].MorphTargets.Count;

View File

@@ -67,6 +67,13 @@ namespace UniVRM10
mesh.IndexBuffer = storage.CreateAccessor(primitive.indices);
}
if (mesh.IndexBuffer == null)
{
var indices = Enumerable.Range(0, mesh.VertexBuffer.Count).ToArray();
var na = storage.Data.NativeArrayManager.CreateNativeArray(indices);
mesh.IndexBuffer = new BufferAccessor(storage.Data.NativeArrayManager, na.Reinterpret<byte>(4), AccessorValueType.UNSIGNED_INT, AccessorVectorType.SCALAR, na.Length);
}
{
gltf_mesh_extras_targetNames.TryGet(x, out List<string> targetNames);

View File

@@ -12,6 +12,7 @@ namespace UniVRM10
public class Vrm10ImportData
{
UniGLTF.GltfData m_data;
public UniGLTF.GltfData Data => m_data;
public UniGLTF.glTF Gltf => m_data.GLTF;
public string AssetVersion => Gltf.asset.version;
@@ -363,12 +364,7 @@ namespace UniVRM10
if (x.translation != null && x.translation.Length > 0) throw new Exception("matrix with translation");
if (x.rotation != null && x.rotation.Length > 0) throw new Exception("matrix with rotation");
if (x.scale != null && x.scale.Length > 0) throw new Exception("matrix with scale");
var m = new Matrix4x4(
new Vector4(x.matrix[0], x.matrix[4], x.matrix[8], x.matrix[12]),
new Vector4(x.matrix[1], x.matrix[5], x.matrix[9], x.matrix[13]),
new Vector4(x.matrix[2], x.matrix[6], x.matrix[10], x.matrix[14]),
new Vector4(x.matrix[3], x.matrix[7], x.matrix[11], x.matrix[15])
);
var m = UnityExtensions.MatrixFromArray(x.matrix);
node.SetLocalMatrix(m, true);
}