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

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

问题描述

反正有中心模型的枢轴吗?当前(默认情况下)它设置在左下角.我想设置到中心.我怎样才能做到这一点?

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?

这是图片:

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

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
        }

    }

推荐答案

您可以使用SCNNode的pivot属性(

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

您可以使用SCNMatrix4MakeTranslation进行更改,例如:

You can change this using an SCNMatrix4MakeTranslation e.g:

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)

您还可以在BlenderMaya之类的程序中更改它.

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

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

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

如果您无法解决它的关键问题,那么您可以做的是创建一个Empty Node,然后将Chair添加为该子级,以确保其居中.

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天全站免登陆