SCRIPT: camera mapping

Forums: SCRIPT: camera mapping
Sub forum for help and tutorials.

Moderator: JimStar

SCRIPT: camera mapping

Postby calus » Tue Oct 04, 2016 5:15 pm

calus Tue Oct 04, 2016 5:15 pm
As some may have noticed, the "camera mapped" feature in ImageTexture nodes is broken since it exists in Octane V2,
it only works with "Global" geometry type and doesn't support render layer ("Global" geometry always use the render layer 1, whatever ID is selected)
EDIT: camera mapped feature is now fixed in V3 and last V2 plugin, but the script is still useful for advanced work.

So, here is a python script to project any Image or procedural texture from the current camera:
OctaneCameraProj_0.1.py.zip
(831 Bytes) Downloaded 343 times

Edit: v 0.2 added more nodes for Octane scale factor and Maya units.
OctaneCameraProj_0.2.py.zip
(945 Bytes) Downloaded 320 times

Edit: v 0.3 updated for recent octane plugin, indice of world space coordinate have changed from 0 to 1.
OctaneCameraProj_0.3.py.zip
(997 Bytes) Downloaded 322 times



As usual to use the script, run it from a script editor python tab or from shelf button.

It create this network between current camera and all selected texture nodes:
maya_2016-10-04_17-38-40.png


The resulting projection is the same as the "camera mapped" feature, but works with any geometry types,
if for some reason you need to "bake" the projection,
just delete the decomposeMatrix and the multiplyDivide nodes.

Code: Select all
# For any selected octane textures, this script creates a node network of the projection from the current camera.
# v 0.2 : added nodes for Octane scale factor and Maya units.
# v 0.3 : updated for recent octane plugin, indice of world space coordinate have changed from 0 to 1.


import maya.cmds as cmd
import maya.OpenMaya as om
import maya.OpenMayaUI as mui

nodes = cmd.ls(sl=True, type=cmd.listNodeTypes(cmd.getClassification("octaneImageTexture")))
if len(nodes)>0:
   cmd.loadPlugin("matrixNodes", quiet=True)
   view = mui.M3dView.active3dView()
   cam = om.MDagPath()
   view.getCamera(cam)
   camShape = cam.fullPathName()
   node_a = cmd.createNode("decomposeMatrix")
   node_b = cmd.createNode("multiplyDivide")
   node_c = cmd.createNode("multiplyDivide")
   node_d = cmd.createNode("multiplyDivide")
   node_g = cmd.createNode("multiplyDivide")
   node_h = cmd.createNode("unitConversion")
   cmd.setAttr(node_b+".operation", 2)
   cmd.setAttr(node_c+".input2X", 12.7)
   cmd.setAttr(node_d+".operation", 2)
   cmd.connectAttr(camShape+".worldMatrix[0]", node_a+".inputMatrix")
   cmd.connectAttr(camShape+".horizontalFilmAperture", node_b+".input1X")
   cmd.connectAttr(camShape+".focalLength", node_b+".input2X")
   cmd.connectAttr(node_b+".outputX", node_c+".input1X")
   cmd.connectAttr(node_c+".outputX", node_d+".input1X")
   cmd.connectAttr("defaultResolution.deviceAspectRatio", node_d+".input2X")
   cmd.connectAttr(node_a+".outputTranslate", node_h+".input")
   cmd.connectAttr(node_h+".output", node_g+".input1")
   cmd.setAttr(node_h+".conversionFactor", 1, lock=True)
   cmd.connectAttr("octaneSettings.ScaleFactor", node_g+".input2X")
   cmd.connectAttr("octaneSettings.ScaleFactor", node_g+".input2Y")
   cmd.connectAttr("octaneSettings.ScaleFactor", node_g+".input2Z")
   for node in nodes:
      node_e = cmd.createNode("octanePerspProjection")
      node_f = cmd.createNode("octaneTransform3D")   
      cmd.connectAttr(node_e+".outProj", node+".Projection", f=True)
      cmd.connectAttr(node_f+".outTransform", node_e+".Transform")
      cmd.connectAttr(node_g+".output", node_f+".Translation")
      cmd.connectAttr(node_a+".outputRotate", node_f+".Rotation")
      cmd.connectAttr(node_c+".outputX", node_f+".ScaleX")
      cmd.connectAttr(node_d+".outputX", node_f+".ScaleY")
      cmd.setAttr(node_e+".PosType", 1)
      cmd.setAttr(node_f+".ScaleZ", -1)
      cmd.setAttr(node_f+".RotationOrder", 5)
   
Last edited by calus on Thu Dec 15, 2016 12:32 pm, edited 2 times in total.
Pascal ANDRE
calus
Licensed Customer
Licensed Customer
 
Posts: 1308
Joined: Sat May 22, 2010 9:31 am
Location: Paris

Re: SCRIPT: camera mapping

Postby Jolbertoquini » Mon Oct 17, 2016 11:57 am

Jolbertoquini Mon Oct 17, 2016 11:57 am
Awesome script Calus,

But is a small problem when you use the scale option 0.01 so maya provide 1 maya unit 1cm really standard on the industry the script doesn't work. I have to add manually a extra multiply node to compensate but the result still weird.

Best
JO
Octane Render for Maya.
https://vimeo.com/jocg/videos
https://www.linkedin.com/in/jocgtd
http://www.hmxmedia.com/
--------------------
Join MAYA OCTANE USERS Skype discussion here :
https://join.skype.com/LXEQaqqfN15w
User avatar
Jolbertoquini
Licensed Customer
Licensed Customer
 
Posts: 1067
Joined: Sun Aug 31, 2014 7:08 am
Location: London

Re: SCRIPT: camera mapping

Postby calus » Tue Oct 18, 2016 8:18 pm

calus Tue Oct 18, 2016 8:18 pm
Jolbertoquini wrote:Awesome script Calus,

But is a small problem when you use the scale option 0.01 so maya provide 1 maya unit 1cm really standard on the industry the script doesn't work. I have to add manually a extra multiply node to compensate but the result still weird.

Best
JO

Right, I only considered default settings previously.

I edited the first post with a new version of the script,
it should work correctly now with any Octane scale factor or Maya Unit, even if they are changed later.

Thanks for testing !
Pascal ANDRE
calus
Licensed Customer
Licensed Customer
 
Posts: 1308
Joined: Sat May 22, 2010 9:31 am
Location: Paris

Re: SCRIPT: camera mapping

Postby Jolbertoquini » Thu Oct 20, 2016 5:24 pm

Jolbertoquini Thu Oct 20, 2016 5:24 pm
calus wrote:
Jolbertoquini wrote:Awesome script Calus,

But is a small problem when you use the scale option 0.01 so maya provide 1 maya unit 1cm really standard on the industry the script doesn't work. I have to add manually a extra multiply node to compensate but the result still weird.

Best
JO

Right, I only considered default settings previously.

I edited the first post with a new version of the script,
it should work correctly now with any Octane scale factor or Maya Unit, even if they are changed later.

Thanks for testing !


Yeah! This is nice work Calus well done and thanks a lot.
JO
Octane Render for Maya.
https://vimeo.com/jocg/videos
https://www.linkedin.com/in/jocgtd
http://www.hmxmedia.com/
--------------------
Join MAYA OCTANE USERS Skype discussion here :
https://join.skype.com/LXEQaqqfN15w
User avatar
Jolbertoquini
Licensed Customer
Licensed Customer
 
Posts: 1067
Joined: Sun Aug 31, 2014 7:08 am
Location: London

Re: SCRIPT: camera mapping

Postby abeoctane » Thu Oct 27, 2016 3:53 pm

abeoctane Thu Oct 27, 2016 3:53 pm
Hi calus, sorry for the dumb question, but Im getting this error when I execute the script, I just need to select the octane texture node and run the script?


// Error: Line 1.0: invalid directive //
abeoctane
Licensed Customer
Licensed Customer
 
Posts: 168
Joined: Thu May 01, 2014 5:44 am

Re: SCRIPT: camera mapping

Postby calus » Thu Oct 27, 2016 4:02 pm

calus Thu Oct 27, 2016 4:02 pm
abeoctane wrote:Hi calus, sorry for the dumb question, but Im getting this error when I execute the script, I just need to select the octane texture node and run the script?


// Error: Line 1.0: invalid directive //

This is a python script, not a mel script,
so you have to run it from a python tab in the script editor, not from a mel tab ;)
Pascal ANDRE
calus
Licensed Customer
Licensed Customer
 
Posts: 1308
Joined: Sat May 22, 2010 9:31 am
Location: Paris

Re: SCRIPT: camera mapping

Postby abeoctane » Thu Oct 27, 2016 4:24 pm

abeoctane Thu Oct 27, 2016 4:24 pm
Hahahaha I just saw that, thanks a lot for the script, It is a life savior. :D
abeoctane
Licensed Customer
Licensed Customer
 
Posts: 168
Joined: Thu May 01, 2014 5:44 am

Re: SCRIPT: camera mapping

Postby Jolbertoquini » Fri Dec 09, 2016 5:42 pm

Jolbertoquini Fri Dec 09, 2016 5:42 pm
Hi Calus,

I was testing the script at maya2017 and doesn't work I get some errors like those:
"# Error: RuntimeError: file <maya console> line 46: setAttr: Cannot set the attribute 'octanePerspProjection4.PosType' below its minimum value of 1. # "

I need try in different ones but anyway, This script is awesome I use a lot and should be on the Octane tab hehehe :)

Best,
JO
Octane Render for Maya.
https://vimeo.com/jocg/videos
https://www.linkedin.com/in/jocgtd
http://www.hmxmedia.com/
--------------------
Join MAYA OCTANE USERS Skype discussion here :
https://join.skype.com/LXEQaqqfN15w
User avatar
Jolbertoquini
Licensed Customer
Licensed Customer
 
Posts: 1067
Joined: Sun Aug 31, 2014 7:08 am
Location: London

Re: SCRIPT: camera mapping

Postby calus » Fri Dec 09, 2016 8:40 pm

calus Fri Dec 09, 2016 8:40 pm
Jolbertoquini wrote:I was testing the script at maya2017 and doesn't work I get some errors like those:
"# Error: RuntimeError: file <maya console> line 46: setAttr: Cannot set the attribute 'octanePerspProjection4.PosType' below its minimum value of 1. # "

I need try in different ones but anyway, This script is awesome I use a lot and should be on the Octane tab hehehe :)

well I don't have Maya 2017 at the moment :oops: ,
just 2014 and 2016, but it looks like it's a problem with V3 plugin,
I will have a look.

Oh by the way, the "camera mapped" feature in image texture node is fixed now, it was one of the first JimStar fix.
(that's not exactly the same, as the "camera mapped" feature change of projection each time the current camera change)
Pascal ANDRE
calus
Licensed Customer
Licensed Customer
 
Posts: 1308
Joined: Sat May 22, 2010 9:31 am
Location: Paris

Re: SCRIPT: camera mapping

Postby Jolbertoquini » Sat Dec 10, 2016 12:13 pm

Jolbertoquini Sat Dec 10, 2016 12:13 pm
calus wrote:
Jolbertoquini wrote:I was testing the script at maya2017 and doesn't work I get some errors like those:
"# Error: RuntimeError: file <maya console> line 46: setAttr: Cannot set the attribute 'octanePerspProjection4.PosType' below its minimum value of 1. # "

I need try in different ones but anyway, This script is awesome I use a lot and should be on the Octane tab hehehe :)

well I don't have Maya 2017 at the moment :oops: ,
just 2014 and 2016, but it looks like it's a problem with V3 plugin,
I will have a look.

Oh by the way, the "camera mapped" feature in image texture node is fixed now, it was one of the first JimStar fix.
(that's not exactly the same, as the "camera mapped" feature change of projection each time the current camera change)


Your script is better, the way they implemented works only with the camera render we can't use other cameras to create nice light gobo effect or projector.

In fact your script we can plug any camera is way better then only a option camera mapping on the main camera.
I mean awesome stuff and I think should be standard on Octane maya.

Best,
Jo
Octane Render for Maya.
https://vimeo.com/jocg/videos
https://www.linkedin.com/in/jocgtd
http://www.hmxmedia.com/
--------------------
Join MAYA OCTANE USERS Skype discussion here :
https://join.skype.com/LXEQaqqfN15w
User avatar
Jolbertoquini
Licensed Customer
Licensed Customer
 
Posts: 1067
Joined: Sun Aug 31, 2014 7:08 am
Location: London
Next

Return to Help / Tutorials


Who is online

Users browsing this forum: No registered users and 2 guests

Sun Apr 28, 2024 9:48 am [ UTC ]