KeyShot Forum

Technical discussions => Extending KeyShot => Scripting => Topic started by: fsong on February 26, 2016, 09:48:38 AM

Title: renderVR(...) and RenderPanoramicFrames issue
Post by: fsong on February 26, 2016, 09:48:38 AM
Hi guys,

Does anyone know the way to control the output format in renderVR()? Really need png format with alpha channel on.
I noticed that "RenderPanoramicFrames" script is using "path" in the renderImage() to specify the format.

So I tried to add another rotation axis, similar to VR.
But it seems only camera rotates along itself, not orbiting around the object.

   for j in range(vframes):
        dir = lux.getCameraDirection()
        for i in range(hframes):
            dir = ((dir[0] * cos(angle) + dir[2] * sin(angle))*cos(vangle),
                   dir[1]*sin(vangle),
                  (-dir[0] * sin(angle) + dir[2] * cos(angle))*cos(vangle))
                       
            lux.setCameraDirection(dir)
            fmth=fmt.replace("%d", str(j),1)
            fmtv=fmth.replace("%d", str(i),1)
            path = os.path.join(folder, fmtv)
            print("Rendering {} of {} frames: {}".format(j+i, vframes*hframes, path))
            lux.renderImage(path = path, width = width, height = height)

Then I tired the original RenderPanoramicFrames script again. It doesn't work either. Attached are some images of first few frames. Could it be the issue of my camera position?
Do I need to use setCameraPosition(...) to get this work?
Title: Re: renderVR(...) and RenderPanoramicFrames issue
Post by: Morten Kristensen on February 28, 2016, 04:12:11 AM
Hello fsong,

You are rotating the camera but not moving it around, which is why you are getting those results. You could use lux.setCameraPosition(). Right now you can't change the output format when calling lux.renderVR(), unfortunately. The Render Panoramic Frames script works just fine, it rotates around its Y-axis. This is not what you want directly.
Title: Re: renderVR(...) and RenderPanoramicFrames issue
Post by: fsong on February 28, 2016, 01:01:52 PM
Hi Morten,

Thanks for the reply.
In the Render Panoramic Frames script, it only uses lux.setCamerDirection() function, not setCameraPosition(), right?  How does it work to make it rotate around Y axis in this script?

Title: Re: renderVR(...) and RenderPanoramicFrames issue
Post by: Morten Kristensen on February 29, 2016, 02:50:49 AM
It only changes the camera direction because it is rendering images "inside" something, e.g. to have a 360 degree look inside a car, for instance.

The rotation itself takes in the camera direction and applies a Y-axis rotation by a certain angle:

# Rotate around Y-axis by angle in radians.
dir = lux.getCameraDirection()
dir = (dir[0] * cos(angle) + dir[2] * sin(angle),   # X
       dir[1],                                      # Y
       -dir[0] * sin(angle) + dir[2] * cos(angle))  # Z
lux.setCameraDirection(dir)


Title: Re: renderVR(...) and RenderPanoramicFrames issue
Post by: fsong on March 14, 2016, 07:36:28 AM
Hi Morten,

So I tried to rotate the part instead. But the problem is that the rotation center is the CAD model coordinate  not the center when we use the move tool. Can you advise how to fix this please? Thanks!

   axis_x=luxmath.Vector(1, 0, 0)
   axis_y=luxmath.Vector(0, 1, 0)
   V = luxmath.Matrix().makeIdentity().rotateAroundAxis(axis_x,vangle)
  H = luxmath.Matrix().makeIdentity().rotateAroundAxis(axis_y,hangle)
Title: Re: renderVR(...) and RenderPanoramicFrames issue
Post by: Morten Kristensen on March 16, 2016, 03:55:14 AM
Hello fsong,

In order to rotate around another origin you need to translate your matrix accordingly. Translate to (0, 0, 0), rotate it, and translate it back to where it was. This way you rotate it around itself.
Title: Re: renderVR(...) and RenderPanoramicFrames issue
Post by: fsong on March 16, 2016, 02:52:20 PM
Thanks, Morten..
I tried to apply .Translate on the root node. It translated entire object but didn't change the rotating center.
Only if I apply .Translate on the children node, it would change both.

Is this the case here?
Title: Re: renderVR(...) and RenderPanoramicFrames issue
Post by: Morten Kristensen on March 28, 2016, 05:45:31 AM
Hello fsong,

It doesn't necessarily make sense to translate the root, but the actual node you want to translate instead. So as I wrote: "Translate to (0, 0, 0), rotate it, and translate it back to where it was."

Thanks