Skip to content

Instantly share code, notes, and snippets.

@maxxfrazer
Created August 7, 2019 20:24
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 maxxfrazer/b27485a549d4108f25b844e69b0dac0b to your computer and use it in GitHub Desktop.
Save maxxfrazer/b27485a549d4108f25b844e69b0dac0b to your computer and use it in GitHub Desktop.
Example of a custom Entity for RealityKit
class CustomBox: Entity, HasModel, HasCollision, HasAnchoring {
/// Used to keeping a reference of any subscriptions involving this entity
var entitySubs: [Cancellable] = []
required init(color: UIColor) {
super.init()
// Shape of this entity for any collisions including gestures
self.components[CollisionComponent] = CollisionComponent(
shapes: [.generateBox(size: [1,0.2,1])],
mode: .trigger,
filter: .sensor
)
// Model of this entity, the physical appearance is a 1x0.2x1 cuboid
self.components[ModelComponent] = ModelComponent(
mesh: .generateBox(size: [1, 0.2, 1]),
materials: [SimpleMaterial(
color: color,
isMetallic: false)
]
)
}
convenience init(color: UIColor, position: SIMD3<Float>) {
self.init(color: color)
self.position = position
}
required convenience init() {
self.init(color: .orange)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment