Skip to content

Commit 108691d

Browse files
committed
Minor fixes
1 parent 53436c5 commit 108691d

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

Source/RunActivity/Viewer3D/GltfShape.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -530,19 +530,15 @@ void GetBinaryData(GltfShape shape, Gltf gltfFile, string gltfFileName)
530530
// Shovel all binary index & vertex attribute data over to the GPU. Such bufferViews are VertexBuffers/IndexBuffers in fact.
531531
// The byteStride is constant throughout a vertex attribute bufferView, but may vary in index bufferViews.
532532
// An accessor is the vertex attribute, is has a byteOffset within the bufferView. If byteOffset < byteStride, then the accessors are interleaved.
533-
var bufferViews = gltfFile.Meshes
534-
.SelectMany(m => m.Primitives)
533+
var primitives = gltfFile.Meshes.SelectMany(m => m.Primitives);
534+
var bufferViews = primitives
535535
.SelectMany(p => p.Attributes)
536+
.Concat(primitives // Upload all the morph targets too in this sole pass.
537+
.SelectMany(p => p.Targets ?? new Dictionary<string, int>[0])
538+
.SelectMany(t => t.Select(d => new KeyValuePair<string, int>("POSITION", d.Value)))) // Create all morph target vertex buffers with POSITION semantic, so they bind to the right slots.
536539
.OrderBy(a => gltfFile.Accessors[a.Value].ByteOffset)
537540
.Distinct()
538-
.GroupBy(a => gltfFile.Accessors[a.Value].BufferView ?? -1)
539-
.Concat(gltfFile.Meshes // Upload all the morph targets too in this sole pass.
540-
.SelectMany(m => m.Primitives)
541-
.SelectMany(p => p.Targets ?? new Dictionary<string, int>[0])
542-
.SelectMany(t => t.Select(d => new KeyValuePair<string, int>("POSITION", d.Value))) // Create all morph target vertex buffers with POSITION semantic, so they bind to the right slots.
543-
.OrderBy(a => gltfFile.Accessors[a.Value].ByteOffset)
544-
.Distinct()
545-
.GroupBy(a => gltfFile.Accessors[a.Value].BufferView ?? -1));
541+
.GroupBy(a => gltfFile.Accessors[a.Value].BufferView ?? -1);
546542

547543
foreach (var bufferView in bufferViews)
548544
{
@@ -641,8 +637,7 @@ void GetBinaryData(GltfShape shape, Gltf gltfFile, string gltfFileName)
641637
while (loop);
642638
}
643639

644-
var indexBufferViews = gltfFile.Meshes
645-
.SelectMany(m => m.Primitives)
640+
var indexBufferViews = primitives
646641
.OrderBy(p => gltfFile.Accessors?.ElementAtOrDefault(p.Indices ?? -1)?.ByteOffset ?? -1)
647642
.GroupBy(p => gltfFile.Accessors?.ElementAtOrDefault(p.Indices ?? -1)?.BufferView ?? -1)
648643
.Where(i => i.Key != -1);
@@ -1289,7 +1284,7 @@ public GltfSubObject(MeshPrimitive meshPrimitive, string name, int hierarchyInde
12891284
if ((options & (SceneryMaterialOptions.PbrHasTangents | SceneryMaterialOptions.PbrHasSkin | SceneryMaterialOptions.PbrHasMorphTargets)) != 0
12901285
|| meshPrimitive.Attributes.ContainsKey("COLOR_0") || meshPrimitive.Attributes.ContainsKey("TEXCOORD_1"))
12911286
{
1292-
if (!vertexAttributes.Any(a => a.VertexBuffer.VertexDeclaration.GetVertexElements().Any(e => e.VertexElementUsage == VertexElementUsage.TextureCoordinate && e.UsageIndex == 1)))
1287+
if (vertexAttributes.Sum(a => a.VertexBuffer.VertexDeclaration.GetVertexElements().Count(e => e.VertexElementUsage == VertexElementUsage.TextureCoordinate)) < 2)
12931288
{
12941289
vertexAttributes.Add(new VertexBufferBinding(new VertexBuffer(shape.Viewer.GraphicsDevice,
12951290
new VertexDeclaration(new VertexElement(0, VertexElementFormat.NormalizedShort2, VertexElementUsage.TextureCoordinate, 1)), vertexCount, BufferUsage.None) { Name = "TEXCOORD_1_DUMMY" }));

0 commit comments

Comments
 (0)