Hi,
wenn ich das richtig verstanden habe, muss ein Objekt ein ModelEntity sein, damit man es mit Gesten steuern kann.
Wenn ich nun im RealityComposer mehrere Objekte in einer Szene habe, die ich alle zusammen gleichzeitig mit Gesten steuern möchte, so kann ich sie als Child an ein Objekt binden, dass ein ModelEntity ist. z.B. einen Würfel, den ich in Xcode erstellt habe.
Wenn ich das mache, bekomme ich eine Fehlermeldung: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
Jetzt habe ich zwei Fragen:
1. Was muss ich am Code verändern, damit er funktioniert?
2. Gibt es die Möglichkeit in swift aus einem Entity (also z.B. aus einer in RealityComposer erstellten Gruppe von Objekten) ein ModelEntity zu machen?
Vielen Dank
Tom
Alles anzeigen
wenn ich das richtig verstanden habe, muss ein Objekt ein ModelEntity sein, damit man es mit Gesten steuern kann.
Wenn ich nun im RealityComposer mehrere Objekte in einer Szene habe, die ich alle zusammen gleichzeitig mit Gesten steuern möchte, so kann ich sie als Child an ein Objekt binden, dass ein ModelEntity ist. z.B. einen Würfel, den ich in Xcode erstellt habe.
Wenn ich das mache, bekomme ich eine Fehlermeldung: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
Jetzt habe ich zwei Fragen:
1. Was muss ich am Code verändern, damit er funktioniert?
2. Gibt es die Möglichkeit in swift aus einem Entity (also z.B. aus einer in RealityComposer erstellten Gruppe von Objekten) ein ModelEntity zu machen?
Vielen Dank
Tom
Quellcode
- import UIKit
- import RealityKit
- import ARKit
- class ViewController: UIViewController {
- @IBOutlet var arView: ARView!
- override func viewDidLoad() {
- super.viewDidLoad()
- // THIS IS THE CODE FOR THE GROUP WITH GESTURES
- // Load scene
- let sceneAnchor = try! Spiralrc.loadMainScene()
- // Create transparent object
- let transparentBox = ModelEntity(mesh: .generateBox(size: [0.1,0.1,0.1]),materials: [SimpleMaterial(color: .clear, isMetallic: false)])
- // Load group of geometry
- let spiralBlueEntity = sceneAnchor.findEntity(named: "spiralBlue")
- let spiralGreenEntity = sceneAnchor.findEntity(named: "spiralGreen")
- // Add geometry to transparent box as child
- transparentBox.addChild(spiralBlueEntity!)
- transparentBox.addChild(spiralGreenEntity!)
- // Add collision and gestures to transparent box
- transparentBox.generateCollisionShapes(recursive: true)
- arView.installGestures(.all, for: transparentBox)
- // Add plane anchor to scene
- let modelAnchor = AnchorEntity(plane: .horizontal)
- // Add transparent box to anchor
- modelAnchor.addChild(transparentBox)
- // Add anchor to scene
- arView.scene.anchors.append(modelAnchor)
- //END OF CODE FOR THE GROUP WITH GESTURES
- }
- }