I am creating a box in RealityKit and want to apply different texture to each side of the box. I am using the following code but it always applies the first texture called "lola" on each of the side as a material. Am I missing something?
cancellable = TextureResource.loadAsync(named: "lola")
.append(TextureResource.loadAsync(named: "cover"))
.append(TextureResource.loadAsync(named: "purple_flower"))
.append(TextureResource.loadAsync(named: "cover"))
.append(TextureResource.loadAsync(named: "purple_flower"))
.append(TextureResource.loadAsync(named: "cover"))
.collect()
.sink { [weak self] completion in
if case let .failure(error) = completion {
fatalError("Unable to load texture \(error)")
}
self?.cancellable?.cancel()
} receiveValue: { textures in
var materials: [UnlitMaterial] = []
textures.forEach { texture in
print(texture)
var material = UnlitMaterial()
material.color = .init(tint: .white, texture: .init(texture))
materials.append(material)
}
box.model?.materials = materials
anchor.addChild(box)
arView.scene.addAnchor(anchor)
}