Entity - modelEntity

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Entity - modelEntity

    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

    Quellcode

    1. import UIKit
    2. import RealityKit
    3. import ARKit
    4. class ViewController: UIViewController {
    5. @IBOutlet var arView: ARView!
    6. override func viewDidLoad() {
    7. super.viewDidLoad()
    8. // THIS IS THE CODE FOR THE GROUP WITH GESTURES
    9. // Load scene
    10. let sceneAnchor = try! Spiralrc.loadMainScene()
    11. // Create transparent object
    12. let transparentBox = ModelEntity(mesh: .generateBox(size: [0.1,0.1,0.1]),materials: [SimpleMaterial(color: .clear, isMetallic: false)])
    13. // Load group of geometry
    14. let spiralBlueEntity = sceneAnchor.findEntity(named: "spiralBlue")
    15. let spiralGreenEntity = sceneAnchor.findEntity(named: "spiralGreen")
    16. // Add geometry to transparent box as child
    17. transparentBox.addChild(spiralBlueEntity!)
    18. transparentBox.addChild(spiralGreenEntity!)
    19. // Add collision and gestures to transparent box
    20. transparentBox.generateCollisionShapes(recursive: true)
    21. arView.installGestures(.all, for: transparentBox)
    22. // Add plane anchor to scene
    23. let modelAnchor = AnchorEntity(plane: .horizontal)
    24. // Add transparent box to anchor
    25. modelAnchor.addChild(transparentBox)
    26. // Add anchor to scene
    27. arView.scene.anchors.append(modelAnchor)
    28. //END OF CODE FOR THE GROUP WITH GESTURES
    29. }
    30. }
    Alles anzeigen