Skip to content

Commit

Permalink
Fixed primitive material assignments in RealityKit loader (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
warrenm committed Jan 17, 2024
1 parent d8da16b commit 95d6aaf
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions GLTFKit2/GLTFKit2/GLTFRealityKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,12 @@ public class GLTFRealityKitLoader {
}

func convert(mesh gltfMesh: GLTFMesh, context: GLTFRealityKitResourceContext) throws -> RealityKit.ModelComponent? {
var primitiveMaterialIndex: UInt32 = 0
let meshDescriptorAndMaterials = try gltfMesh.primitives.compactMap { primitive -> (RealityKit.MeshDescriptor, RealityKit.Material)? in
if let meshDescriptor = try self.convert(primitive: primitive, context:context) {
if var meshDescriptor = try self.convert(primitive: primitive, context:context) {
let material = try self.convert(material: primitive.material, context: context)
meshDescriptor.materials = .allFaces(primitiveMaterialIndex)
primitiveMaterialIndex += 1
return (meshDescriptor, material)
}
// If we fail to create a mesh descriptor for a primitive, omit it from the list.
Expand All @@ -369,7 +372,7 @@ public class GLTFRealityKitLoader {

let meshResource = try MeshResource.generate(from: meshDescriptorAndMaterials.map { $0.0 })

let model = ModelComponent(mesh: meshResource, materials: meshDescriptorAndMaterials.map { $0.1} )
let model = ModelComponent(mesh: meshResource, materials: meshDescriptorAndMaterials.map { $0.1 } )

return model
}
Expand Down

0 comments on commit 95d6aaf

Please sign in to comment.