Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import RealityKit
extension ModelEntity {
func changeMaterial(atIndex index: Int, toColour colour: Color) {
assert(model?.materials.indices.contains(index) ?? false, "Index out of range")
model?.materials[index] = SimpleMaterial(color: UIColor(colour), isMetallic: false)
}
}
extension Entity {
func addIfModelEntity(models: inout [ModelEntity]) {
if let modelEntity = self as? ModelEntity {
models.append(modelEntity)
}
}
func getModelEntitiesInDescendants(models: inout [ModelEntity]) {
self.addIfModelEntity(models: &models)
for child in self.children {
child.addIfModelEntity(models: &models)
child.getModelEntitiesInDescendants(models: &models)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment