Author Topic: Script Rotation around Pivot Point  (Read 3570 times)

0 Members and 1 Guest are viewing this topic.

Offline Ryan Fenik

  • Newbie
  • *
  • Posts: 24
Script Rotation around Pivot Point
« on: December 15, 2015, 08:14:28 am »
Hello,

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

Is this possible? 

Thanks. 

Offline Morten Kristensen

  • root
  • Administrator
  • Full Member
  • *****
  • Posts: 128
  • Software Engineer, Luxion
Re: Script Rotation around Pivot Point
« Reply #1 on: December 17, 2015, 01:23:14 am »
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.

Offline Ryan Fenik

  • Newbie
  • *
  • Posts: 24
Re: Script Rotation around Pivot Point
« Reply #2 on: December 17, 2015, 05:43:06 am »
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): 

Code: [Select]
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

Offline Ryan Fenik

  • Newbie
  • *
  • Posts: 24
Re: Script Rotation around Pivot Point
« Reply #3 on: December 17, 2015, 01:48:58 pm »
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. 

Offline Morten Kristensen

  • root
  • Administrator
  • Full Member
  • *****
  • Posts: 128
  • Software Engineer, Luxion
Re: Script Rotation around Pivot Point
« Reply #4 on: December 18, 2015, 01:44:38 am »
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. ;)

Offline Ryan Fenik

  • Newbie
  • *
  • Posts: 24
Re: Script Rotation around Pivot Point
« Reply #5 on: December 28, 2015, 12:02:00 pm »
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. 
« Last Edit: December 28, 2015, 01:24:39 pm by ryanfenik »