如何在 SceneKit 编辑器中将模型的枢轴点居中 [英] How to Center the Pivot Point of a Model in SceneKit Editor

查看:36
本文介绍了如何在 SceneKit 编辑器中将模型的枢轴点居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何可以将模型的枢轴居中吗?当前(默认情况下)它设置在左下角.我想设置到中心.我怎样才能做到这一点?

图片如下:

更新:我添加了另一个节点并将椅子添加为孩子.

所以,现在它工作得更好,但它不会一直旋转,如果我继续旋转,它会重置位置.这是平移操作的代码:

 @objc func panned(recognizer :UIPanGestureRecognizer) {var newAngleY :Float = 0.0如果识别器.状态 == .changed {让sceneView =receiver.view as!ARSCN视图让 touchPoint =receiver.location(in:sceneView)让翻译=recognizer.translation(在:sceneView)打印(翻译.x)让 scnHitTestResults = self.sceneView.hitTest(touchPoint, options: nil)如果让 hitTestResult = scnHitTestResults.first {如果让 parentNode = hitTestResult.node.parent {newAngleY = (Float)(translation.x)*(Float)(Double.pi)/180newAngleY += currentAngleYparentNode.eulerAngles.y = newAngleY}}}否则如果识别器.状态 == .end {currentAngleY = newAngleY}}

解决方案

您可以使用 SCNNode (Apple 文档)

您可以使用 SCNMatrix4MakeTranslation 更改此设置,例如:

nodeToAdd.pivot = SCNMatrix4MakeTranslation(0,0,0)

这可能会解决问题:

//1.获取节点的边界框让最小值 = float3(nodeToAdd.boundingBox.min)让最大值 = float3(nodeToAdd.boundingBox.max)//2.将翻译设置为向量之间的一半让翻译 =(最大值 + 最小值)* 0.5//3.设置支点nodeToAdd.pivot = SCNMatrix4MakeTranslation(translation.x,translation.y,translation.z)

您也可以在 BlenderMaya 等程序中更改它.

或者,可能更容易,是在 SceneKit Editor 本身中编辑模型.

如果您无法修复它的枢轴,那么您可以做的是创建一个 Empty Node,然后将 Chair 添加为它的子项,确保它在其中居中.>

通过这种方式,您应该能够更准确地转换它的旋转.

Is there anyway to center the pivot of a model? Currently (by default) it is set to the bottom left. I want to set to the center. How can I do that?

Here is the image:

UPDATE: I added another node and added the chair as a child.

So, now it works better but it does not rotate all the way and it resets the position if I continue to rotate. Here is the code for the panned operation:

  @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
        }

    }

解决方案

You can change a pivot of the Chair using the pivotproperty of the SCNNode (Apple Documentation)

You can change this using an SCNMatrix4MakeTranslation e.g:

nodeToAdd.pivot = SCNMatrix4MakeTranslation(0,0,0)

This may solve the problem:

    //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)

You could also change it within within a program like Blender or Maya.

Alternatively, and probably much easier, is to edit the model in the SceneKit Editor itself.

If you cant fix it's pivot, then what you can do is to create an Empty Node, and then add the Chair as a child of this, ensuring that it is centered within that.

This way you should be able to transform it's rotation for example more accurately.

这篇关于如何在 SceneKit 编辑器中将模型的枢轴点居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆