Created
August 7, 2019 20:24
-
-
Save maxxfrazer/b27485a549d4108f25b844e69b0dac0b to your computer and use it in GitHub Desktop.
Example of a custom Entity for RealityKit
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
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