Swift - How to change the Pivot of a SCNNode object

前端 未结 2 628
鱼传尺愫
鱼传尺愫 2021-02-08 21:45

I\'ve been playing with the SCNNode object for a while now and I\'m lost with the Pivot. How can I change the pivot of a SCNNode (SCNBox as a bar) and place the pivot on one of

2条回答
  •  醉梦人生
    2021-02-08 22:21

    On the pivot topic:

    Just in case you do not have dimensions for your geometry/node something like this might help (especially for SCNText).

    var minVec = SCNVector3Zero
    var maxVec = SCNVector3Zero
    
    if node.getBoundingBoxMin(&minVec, max: &maxVec) {
    
        let bound = SCNVector3(x: maxVec.x - minVec.x,
                               y: maxVec.y - minVec.y,
                               z: maxVec.z - minVec.z)
    
        node.pivot = SCNMatrix4MakeTranslation(bound.x / 2, 
                                               bound.y / 2, 
                                               bound.z / 2)
    }
    

提交回复
热议问题