ARKit 4,RealityKit - 将局部变换转换为世界变换

ARKit 4, RealityKit - Converting local transform to world transform

在带有 RealityKit 的 ARKit 4 中,可以找到例如左手相对于骨架基础(臀部)的变换。有了lefthand transform(相对于hip)和hip transform(相对于world),如何计算lefthand transform relative to world? API 在哪里?看来,当我想出数学公式时,我可以使用 SIMD api。但我想应该有一个简单的 API 做这种数学?谢谢

编辑:添加一些代码以使其清晰..

guard let bodyAnchor = anchor as? ARBodyAnchor else { continue }
let skeleton = bodyArchor.skeleton
let leftHandModelTransform = skeleton.modelTransform(for: .leftHand)

// at this point. I have access to:
// hip transform (bodyArchor.tranform) which is in the world coordinate system;
// lefthand transform which is relative to hip of the skeleton model. 
// what to do next? any api? or do I have to figureout math and then use simd apis ? 
//

编辑:另外,有人可以推荐一本书/网页来描述如何在不同的 3D 计算中使用 SIMD 吗?我发现这个 post(Augmented Reality 911 — Transform Matrix 4x4) 非常有用。但它没有涉及两个向量空间之间的转换。

好的。在复习了所有关于矩阵、3D 变换和四元数的数学知识之后,我终于找到了解决方案!它实际上被埋在RealityKit API:

func convert(normal: SIMD3<Float>, from referenceEntity: Entity?) -> SIMD3<Float>

我必须创建两个实体才能使用此 API。但至少它有效...

此代码是评论中对 Jan 的回答。希望它有所帮助。 bodyAnchor 是骨骼跟踪的根锚点。

    let skeleton = bodyAnchor.skeleton
    let handTransform = skeleton.modelTransform(for: (ARSkeleton.JointName(rawValue: "left_handIndexStart_joint"))

    let hipEntity = Entity()
    hipEntity.transform = Transform(matrix: bodyAnchor.transform)
    let worldEntity = Entity()
    let handGlobalTransform = worldEntity.convert(transform: Transform(matrix:handTransform!), from: hipEntity)

我不得不承认这不是一个理想的解决方案,因为它创建了两个仅用于数学计算的实体。我相信(不会错),Apple 创建了两种不同的位置操纵机制 - 一种是实体有位置,另一种是锚点。因此,如果您直接操纵实体位置,则会在那里给出数学。但是,我试图操纵锚点位置(并为其分配实体)。这给带来了一些麻烦。