Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created January 29, 2021 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/1d1e543a6982570b15e79f24569d9c48 to your computer and use it in GitHub Desktop.
Save sturdysturge/1d1e543a6982570b15e79f24569d9c48 to your computer and use it in GitHub Desktop.
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