Script Rotation around Pivot Point

Started by Ryan Fenik, December 15, 2015, 08:14:28 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ryan Fenik

Hello,

Looking for a way to script rotation around a pivot point. 

Is this possible? 

Thanks. 

Morten Kristensen

Hello Ryan,

You could use an orbit animation for this purpose or similar.

Scripting can set the camera's position (lux.setCameraPosition), direction (lux.setCameraDirection), up vector (lux.setCameraUp), and look-at point (lux.setCameraLookAt), so you can control all these things. You could look at "Render Panoramic Frames.py" if you want an example of rotation, but it's around the Y-axis. You can also use luxmath.Matrix.rotate.

Ryan Fenik

Morton,

Thanks for your reply. 

I looked at the panoramic frames example, and while that looks useful - I don't think that's going to accomplish what I am looking to do.  I just need individual parts rotated, not the camera for the entire scene. 

Here is an example (click on the doors to open them): 

http://www.layerzero.com/Products/Static-Transfer-Switches/150-A-1200-A-eSTS/index.html

These frames were generated with the doors rotated around a pivot point (the hinge) .  Generating the images is a somewhat manual process, and it would be time-saving for me to be able to generate the animation for the frames via scripting. 

I couldn't find any reference to scripting animation in the docs... Is it possible? 

I am looking to: 
• Select animation type (Rotation, Translate, Fade)
• Set vars for the animation (such as degrees, axis, axisOrientation, pivotPoint)
• Set animation to a specific node

Ryan Fenik

I've found a workaround where you can animate parts via scripting: 

• Create bip file with the animation
• Import it

lux.importFile("Z:/parts_location/ani.bip")
frames = lux.getAnimationInfo()["frames"]
for frame in range(start, end+1):
    lux.setAnimationFrame(frame)
    lux.renderImage(path = path, width = 850, height = 500, frames)

Not fully "scripted", but it works. 

Morten Kristensen

Hi Ryan,

That is indeed one of the solutions I mentioned. And by the way, importing a BIP actually means to open a BIP so you can just substitute lux.importFile() for lux.openFile(). If you don't want to use the animation then you can still use vertices and matrices to do the rotation and placement calculations by hand. This is easier, though. ;)

Ryan Fenik

#5
Morten,

Importing a bip file does work, however, it would be preferred to script it for repeatability. 

How would you go about setting a pivot point with the following example? 

for node in root.find("Part_I_Want_To_Rotate"):
    i = 0;
    for i in range(0,90,6): #Rotate to 90 degrees in six degree increments
        R = luxmath.Matrix().makeIdentity().rotateAroundAxis(luxmath.Vector((0, 0, 1)), i)
        print(R) #Output the degrees that each loop iteration will rotate (You would normally call a "render" function)
        node.applyTransform(R)
        i += i

This will transform around the "origin" as defined in the part. 

Any ideas on how I can script a new origin, so that rotation pivot point can center around another part? 

Thanks.