如何解决更改枢纽点后如何正确移动SCNNode?
我当前正在场景中放置一个多维数据集。该多维数据集当前位于根节点内。当我在SceneKit编辑器中检查多维数据集的枢轴点时,它位于边界体积的中心,但位于底部表面。我的目标是使枢轴点成为边界体积的中心。我正在使用此代码来实现此目标:
func showNode(node: SCNNode,horizontalPosition: CLLocationCoordinate2D,verticalPosition: Float){
//All models downloaded will have locations based on centre,therefore set pivot to centre
//Change pivot point to the centre of the bounding box to match structure of uploaded DT models
//1. Get The Bounding Box Of The Node
let min = simd_float3(node.boundingBox.min)
let max = simd_float3(node.boundingBox.max)
//2. Set The Pivot
//Changing pivot will affect location of childnodes
node.pivot = SCNMatrix4MakeTranslation(min.x + (max.x-min.x)/2,min.y + (max.y-min.y)/2,min.z + (max.z-min.z)/2)
//Affine transformations (Scale,Rotation,Translation) -> in this order
node.scale = SCNVector3(Float(scale_W),Float(scale_W),Float(scale_W))
//Coordinates of object in (X,Y) plane
let latLong = getLocalCoordinates(latLong: horizontalPosition)
print(SCNVector3(latLong.x,verticalPosition,latLong.z))
//Place object at world position (referencing world origin)
node.worldPosition = SCNVector3(latLong.x,latLong.z)
//Store which node is added to AR scene
outdoorNode = node
}
我可以成功地将立方体放置在定义的世界坐标上。当我想将多维数据集从其当前位置沿X方向(无论哪个方向)平移1m时,问题就开始了。我有一个将节点平移1m的按钮,代码如下:
@objc func leftTap() {
print("left tap")
if (isOutdoorNodeInScene) {
self.outdoorNode.worldPosition.x -= 1
print(outdoorNode.worldPosition)
addOrUpdateOutdoorAnchor(anchor: outdoorNodeAnchor!,node: outdoorNode)
}
}
我希望模型仅在此X轴上发生变化,但是在所有3个轴上都发生变化。我注意到,当我不更改枢轴点时,就会观察到所需的功能。但是,如果我不更改枢轴点,则它不再位于立方体的中心。有人可以解释为什么我观察这种行为吗?我附上了一些图片作为证据。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。