Transforming scene nodes (GUI and Headless)
Nodes can be translated, scaled, rotated etc. via scripting. It is possible by using 4×4 transformation matrices of type luxmath.Matrix. There are two ways to transform: relative or absolute. A relative transform means to apply the transform locally, i.e. it is multiplied last in the chain of existing transforms. That means that if you relatively translate by (1,0,0) then it will simply move the node one by the x-axis according to its position. In contrast, absolute transforms are not chained in the same fashion and absolutely translating by (1,0,0) will always position the node at (1,0,0).
When doing transforms it is important that an identity matrix (1s on the diagonal) is used as the base matrix. It is obtained in the following way:
>>> M = luxmath.Matrix().makeIdentity()
>>> print(M.dump())
| 1.00 0.00 0.00 0.00 |
| 0.00 1.00 0.00 0.00 |
| 0.00 0.00 1.00 0.00 |
| 0.00 0.00 0.00 1.00 |
To translate a node by (5,0,1):
>>> M = luxmath.Matrix().makeIdentity().translate(luxmath.Vector((5, 0, 3)))
>>> node.applyTransform(M)
>>> print(M.dump()) # Let's have a look at the matrix.
| 1.00 0.00 0.00 0.00 |
| 0.00 1.00 0.00 0.00 |
| 0.00 0.00 1.00 0.00 |
| 5.00 0.00 3.00 1.00 |
If instead an absolute position adjustment is intended, then do the following:
>>> M = luxmath.Matrix().makeIdentity().translate(luxmath.Vector((5, 0, 3)))
>>> node.applyTransform(M, absolute = True)
Note
Only object nodes can have absolute transforms applied!
For further information about what transforms are possible have a look at the documentation for luxmath.Matrix.