Posts

Post not yet marked as solved
6 Replies
2.2k Views
I am trying to write to get all joint XYZ coordinates in ARKit 3 motion capture to get the XYZ to find all angles of body. but I can't find the XYZ coordinates so I can't do the next step.I am trying to use character!.jointTransforms to get the joint data translation maybe is the XYZ coordinates but I tried to track a few motion but the numbers didn't change.This is my code :import UIKit import RealityKit import ARKit import Combine class ViewController: UIViewController, ARSessionDelegate { @IBOutlet var arView: ARView! var character: BodyTrackedEntity? let characterOffset: SIMD3 = [0.0, 0, 0] let characterAnchor = AnchorEntity() override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) arView.session.delegate = self guard ARBodyTrackingConfiguration.isSupported else { fatalError("This feature is only supported on devices with an A12 chip") } let configuration = ARBodyTrackingConfiguration() arView.session.run(configuration) arView.scene.addAnchor(characterAnchor) // Asynchronously load the 3D character. var cancellable: AnyCancellable? = nil cancellable = Entity.loadBodyTrackedAsync(named: "character/robot").sink( receiveCompletion: { completion in if case let .failure(error) = completion { print("Error: Unable to load model: \(error.localizedDescription)") } cancellable?.cancel() }, receiveValue: { (character: Entity) in if let character = character as? BodyTrackedEntity { // Scale the character to human size character.scale = [1.0, 1.0, 1.0] self.character = character cancellable?.cancel() } else { print("Error: Unable to load model as BodyTrackedEntity") } }) } func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) { for anchor in anchors { guard let bodyAnchor = anchor as? ARBodyAnchor else { continue } let bodyPosition = simd_make_float3(bodyAnchor.transform.columns.3) characterAnchor.position = bodyPosition + characterOffset characterAnchor.orientation = Transform(matrix: bodyAnchor.transform).rotation if let character = character, character.parent == nil { characterAnchor.addChild(character) } let XYZArray = character!.jointTransforms.map({ (transform: RealityKit.Transform) -> SIMD3 in transform.translation }) print(XYZArray) } } }The code is reference by :https://developer.apple.com/documentation/arkit/capturing_body_motion_in_3d
Posted
by royli16go.
Last updated
.