The goal is to increase the length of a SCNBox such that it only grows in the positive-z direction.
This answer suggests playing with the pivot
property.
However, the documentation for the pivot
property is sparse on the SCNNode page, and there is nothing on the SCNBox page.
Can someone explain how the pivot
property works?
Say you have a box created like this:
The pivot point will be in the center of that box, you now want to move it to one of the edges. This can be done by translating the pivot node by 0.5. (This is half the width of the box or the distance between the center and the edge.)
The pivot point will now be located at center X, center Y, and zero Z of the object. If you now scale the box it will only grow in the positive Z direction.
Changing a node's
pivot
is conceptually the same as inserting an intermediate node between this node and its parent. This can be useful in different cases. One example is when the center of the node's geometry isn't where you expect it to be.For instance if you have an
SCNBox
, it's bounding box is(-0.5 * width, -0.5 * height, -0.5 * length)
(+0.5 * width, +0.5 * height, +0.5 * length)
(0.0, 0.0, 0.0)
If you want the
length
of theSCNBox
to only increase in the positive Z axis, then what you want is(-0.5 * width, -0.5 * height, 0.0)
(+0.5 * width, +0.5 * height, length)
(0.0, 0.0, +0.5 * length)
A geometry's bounding box will never change, but there are ways to arrange nodes and change their bounding boxes.
Solution 1: Intermediate node
One common solution when dealing with transforms is to use intermediate nodes to get a better understanding of how the transforms are applied.
In your case you will want to change the node hierarchy from
to
With this new hierarchy, the center of the bounding box of
node
is still(0.0, 0.0, 0.0)
, but the center of the bounding box ofintermediateNode
is(0.0, 0.0, +0.5 * length)
.By scaling
intermediateNode
instead ofnode
you'll obtain the wanted result.Solution 2: Pivot
It turns out that's exactly what the
pivot
property does:Once you have mentally figured out the transform of the intermediate node, simply set its inverse to the
pivot
property.You can find more information about the
pivot
property here: https://developer.apple.com/reference/scenekit/scnnode/1408044-pivotThis is very similar to Core Animation's
anchorPoint
property onCALayer
, except that in Core Animation the anchor point is specified as relative to the layer's bounding box (goes from0
to1
as a percentage of the layer's width and height), while in SceneKit it's absolute.Sounds like you want to increase the length of the SCNBox(a geometry). So you can simply increase the length property. The answer you mentioned is about the
pivot
property. As you can see from the doc:For example, by setting the pivot to a translation transform you can position a node containing a sphere geometry relative to where the sphere would rest on a floor instead of relative to its center.