Here are some code snippets on how i place my object in the AR View. I place it by tapping on the screen and handle the tap with an ARView Coorinator. I use the focus entity package to define the anchor point for the model entity. Here, i want to access the information about the child elements, that should be places with the usdz file. As you can see I tried to print out the information, and tried some things. I can't figure out where the children are attached to.
`@objc func handleTap() {
guard let view = self.view, let focusEntity = self.focusEntity else {return}
if (!object.inScene) {
object.anchorEntity = AnchorEntity()
view.scene.anchors.append(object.anchorEntity!)
object.modelEntity = try! ModelEntity.loadModel(named: object.fileName)
object.modelEntity!.name = object.name
object.anchorEntity!.position = focusEntity.position
object.anchorEntity!.addChild(object.modelEntity!)
print(object.modelEntity!.children)
print(object.modelEntity!.components)
object.inScene = true
object.anchorPosition = object.anchorEntity!.transform.translation
object.anchorRotation = object.anchorEntity!.transform.rotation
}
else {return}
}`
The "object" class contains the data i need to use in my whole app, it also tells the coordinator the file name and stores some other info:
`
@MainActor class Object: ObservableObject {
let name: String = "Vase"
//let fileName: String = "flower_tulip.usdz"
let fileName: String = "Vase_FP.usdz"
let scale: SIMD3<Float> = SIMD3<Float>(0.1, 0.1, 0.1)
@Published var session: ARSession?
@Published var modelEntity: ModelEntity?
@Published var anchorEntity: AnchorEntity?
@Published var anchorPosition: SIMD3<Float>?
@Published var anchorRotation: simd_quatf?
@Published var deletionRequest: Bool = false
@Published var inScene: Bool = false
func changeObjectPosition(_ sender: Any, newPosition: SIMD3<Float>){
self.anchorPosition = newPosition
self.anchorEntity?.transform.translation = newPosition
}
func changeObjectRotation(_ sender: Any, newRotation: simd_quatf){
self.anchorRotation = newRotation
self.anchorEntity?.transform.rotation = newRotation
}
func enumerateChildren(_ sender: Any){
let children = self.modelEntity!.children
for (n, c) in children.enumerated() {
print("\(n): '\(c)'")
}
}
var deletion: Cancellable?
}`
I use scene reconstruction and depth in my ARView, since i work with an iPad Pro.
But that does not have to do anything with the question.
I hope things got a bit clearer now