[英]How to Center the Pivot Point of a Model in SceneKit Editor
無論如何,有沒有將模型的樞軸居中? 當前(默認情況下)它設置在左下方。 我想設置到中心。 我怎樣才能做到這一點?
這是圖片:
更新 :我添加了另一個節點,並將椅子添加為子級。
因此,現在效果更好,但不會一直旋轉,如果我繼續旋轉,它將重置位置。 這是平移操作的代碼:
@objc func panned(recognizer :UIPanGestureRecognizer) {
var newAngleY :Float = 0.0
if recognizer.state == .changed {
let sceneView = recognizer.view as! ARSCNView
let touchPoint = recognizer.location(in: sceneView)
let translation = recognizer.translation(in: sceneView)
print(translation.x)
let scnHitTestResults = self.sceneView.hitTest(touchPoint, options: nil)
if let hitTestResult = scnHitTestResults.first {
if let parentNode = hitTestResult.node.parent {
newAngleY = (Float)(translation.x)*(Float)(Double.pi)/180
newAngleY += currentAngleY
parentNode.eulerAngles.y = newAngleY
}
}
}
else if recognizer.state == .ended {
currentAngleY = newAngleY
}
}
您可以使用SCNNode的ivot屬性來更改Chair的pivot
( Apple文檔 )
您可以使用SCNMatrix4MakeTranslation
進行更改,例如:
nodeToAdd.pivot = SCNMatrix4MakeTranslation(0,0,0)
這可以解決問題:
//1. Get The Bounding Box Of The Node
let minimum = float3(nodeToAdd.boundingBox.min)
let maximum = float3(nodeToAdd.boundingBox.max)
//2. Set The Translation To Be Half Way Between The Vector
let translation = (maximum - minimum) * 0.5
//3. Set The Pivot
nodeToAdd.pivot = SCNMatrix4MakeTranslation(translation.x, translation.y, translation.z)
您也可以在Blender
或Maya
之類的程序中更改它。
另外, 可能更容易的是,在SceneKit Editor
編輯模型。
如果您無法解決它的關鍵問題,那么您可以做的是創建一個Empty Node
,然后將Chair作為其子項添加,確保其在其中居中。
這樣,您應該能夠更准確地轉換其旋轉度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.