Created
January 6, 2021 14:16
-
-
Save MickaelCruzDB/010ebd85390799a5b43c048e0e6be0fa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
func loadModel(named: String, result: ARRaycastResult) { | |
var usdzToLoad: String = "" | |
switch named { | |
case "DYNO": | |
usdzToLoad = "toy_robot_vintage" | |
default: | |
break; | |
} | |
DispatchQueue.main.async { | |
let modelToLoad = try! Entity.load(named: usdzToLoad) | |
switch named { | |
case "DYNO": | |
modelToLoad.name = "DYNO" | |
default: | |
break; | |
} | |
let anchor = AnchorEntity(plane: .horizontal, classification: .any, minimumBounds: [0.1, 0.1]) | |
anchor.position.y = 0.01 | |
anchor.addChild(modelToLoad) | |
// Create a "Physics" model of the toy in order to add physics mode | |
guard let modelEntity = modelToLoad as? HasPhysics else { return } | |
self.arView.installGestures([.rotation], for: modelEntity) | |
modelEntity.generateCollisionShapes(recursive: true) | |
modelEntity.physicsBody = PhysicsBodyComponent(shapes: [.generateBox(size: .one)], | |
mass: 1.0, | |
material: .default, | |
mode: .kinematic) | |
self.currentEntity = modelEntity | |
self.anchorsEntities.append(anchor) | |
self.arView.scene.addAnchor(anchor) | |
let robotAnimationResource = self.currentEntity?.availableAnimations.first | |
self.currentEntity!.playAnimation(robotAnimationResource!.repeat(duration: .infinity), | |
transitionDuration: 1.25, | |
startsPaused: false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment