-
-
Save sturdysturge/1d1e543a6982570b15e79f24569d9c48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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