RealityKit – AnchorEntity 只移动到 Origin
RealityKit – AnchorEntity moves only to Origin
问题是它上升到原点...不只是自转。
anchorEntity.anchoring = AnchoringComponent(anchor)
anchorEntity.addChild(modelEntityClone)
anchorEntity.addChild(downEntity)
anchorEntity.addChild(sideEntity)
anchorEntity.addChild(rightEntity)
anchorEntity.name = name
arView.scene.addAnchor(anchorEntity)
arView.scene.addAnchor(planeEntity)
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
print("after 3 sec")
let radians = 90.0 * Float.pi / 180.0
let currentMatrix = anchorEntity.transform.matrix
let rotation = simd_float4x4(SCNMatrix4MakeRotation(90.0 * .pi/180, 0,1,0))
let transform = simd_mul(currentMatrix, rotation)
anchorEntity.move(to: transform, relativeTo: nil, duration: 3.0)
}
应用锚点相对于模型实体的旋转:
let model = ModelEntity(mesh: .generateBox(size: 0.2))
let anchor = AnchorEntity(world: [0, 0.5, 0])
anchor.addChild(model)
let currentMatrix = anchor.transform.matrix
let rotation = simd_float4x4(SCNMatrix4MakeRotation(.pi/2, 0, 1, 0))
let transform = simd_mul(currentMatrix, rotation)
anchor.move(to: transform, relativeTo: model, duration: 3.0)
This post 也很有用。
问题是它上升到原点...不只是自转。
anchorEntity.anchoring = AnchoringComponent(anchor)
anchorEntity.addChild(modelEntityClone)
anchorEntity.addChild(downEntity)
anchorEntity.addChild(sideEntity)
anchorEntity.addChild(rightEntity)
anchorEntity.name = name
arView.scene.addAnchor(anchorEntity)
arView.scene.addAnchor(planeEntity)
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
print("after 3 sec")
let radians = 90.0 * Float.pi / 180.0
let currentMatrix = anchorEntity.transform.matrix
let rotation = simd_float4x4(SCNMatrix4MakeRotation(90.0 * .pi/180, 0,1,0))
let transform = simd_mul(currentMatrix, rotation)
anchorEntity.move(to: transform, relativeTo: nil, duration: 3.0)
}
应用锚点相对于模型实体的旋转:
let model = ModelEntity(mesh: .generateBox(size: 0.2))
let anchor = AnchorEntity(world: [0, 0.5, 0])
anchor.addChild(model)
let currentMatrix = anchor.transform.matrix
let rotation = simd_float4x4(SCNMatrix4MakeRotation(.pi/2, 0, 1, 0))
let transform = simd_mul(currentMatrix, rotation)
anchor.move(to: transform, relativeTo: model, duration: 3.0)
This post 也很有用。