# # Weta Digital - export multiple reference cameras to maya (via mel). # 260707 - v2: 3dpoints and cameras now respect scene node SRT (local to world transformation) set path [get3DEInstallPath] source $path/user_data/tcl_archive/veclib.tcl open3DEConsole print3DEConsole "\nWeta Mel Export: This script exports all\n reference cameras in the scene\n\n\n" flush3DEConsole #get the camera point group for {set pointGroup [getFirstPGroup]} {$pointGroup!=0} {set pointGroup [getNextPGroup $pointGroup]}\ { if {[getPGroupType $pointGroup]== "CAMERA"} then\ { set cameraPointGroup $pointGroup } } #for if {$cameraPointGroup==0}\ { bell post3DEInfoRequester " \n Error, no camera point group. \n" return } set tcl_precision 10 #check that there is a frame object to export set fObjectNumber [getNoFobjs] if {$fObjectNumber==0}\ { bell post3DEInfoRequester " \n Error, there is no Sequence/Ref. Frames to export. \n" return } # get scene node SRT set global_pos [getScenePosition3D] set global_rot [getSceneRotation3D] set global_scale [getSceneScale3D] #get output file name set filename [post3DEFileRequester "Export Mel File..." "*"] set filename [format "%s.mel" $filename] #if a file was picked lets continue if {$filename != ""}\ { set file [open $filename w+] # write some comments... puts -nonewline $file "// Weta mel export from 3de\n// All lengths are in centimeter, all angles are in degree.\n\n" #set up scene group puts -nonewline $file "//create scene group\n" puts -nonewline $file "string \$sceneGroupName = `group -em -name \"Scene\"`;\n" for {set fobj [getFirstFobj]} {$fobj!=0} {set fobj [getNextFobj $fobj]}\ { if {[getFobjType $fobj]=="REF_FRAME"}\ { # write camera parameter... set camera [getFobjCamera $fobj] if {$camera!=0}\ { set fObjName [getFobjName $fobj] set fObjName [format "%s_%s_1" $fObjName $fobj] set fback_w [getCameraFBackWidth $camera] set fback_h [getCameraFBackHeight $camera] set focal [getCameraFocalLength $camera] set p_aspect [getCameraPixelAspect $camera] # cm -> inches set fback_w [expr $fback_w/2.53995] set fback_h [expr $fback_h/2.53995] # cm -> mm set focal [expr $focal*10.0] #make camera puts -nonewline $file "\n//Make camera $fObjName\n" puts -nonewline $file "string \$cameraNodes\[\] = `camera -name \"$fObjName\" -hfa $fback_w -vfa $fback_h -fl $focal -ncp 0.1 -fcp 1000000 -shutterAngle 180 -ff \"overscan\"`;\n" puts -nonewline $file "string \$cameraTransform = \$cameraNodes\[0\];\n" puts -nonewline $file "string \$cameraShape = \$cameraNodes\[1\];\n" puts -nonewline $file "xform -zeroTransformPivots -rotateOrder zxy \$cameraTransform;\n" #get positon and rotations set pos3dlocal [getPGroupPosition3D $cameraPointGroup $fobj 1] set rot3dlocal [getPGroupRotation3D $cameraPointGroup $fobj 1] set pos3d [vec3+vec3 [s*vec3 $global_scale [mat3*vec3 $global_rot $pos3dlocal]] $global_pos] set rot3d [mat3*mat3 $global_rot $rot3dlocal] set vec [mat3rotangles $rot3d 1 0 2] set rot_x [expr ([lindex $vec 1]*180)/3.141592654] set rot_y [expr ([lindex $vec 0]*180)/3.141592654] set rot_z [expr ([lindex $vec 2]*180)/3.141592654] puts -nonewline $file "xform -translation $pos3d \$cameraTransform;\n" puts -nonewline $file "xform -rotation $rot_x $rot_y $rot_z \$cameraTransform;\n" puts -nonewline $file "xform -scale 40 40 40 \$cameraTransform;\n" #get image plane puts $file "//image plane for $fObjName" puts -nonewline $file "string \$imagePlane = `createNode imagePlane`;\n" puts -nonewline $file "cameraImagePlaneUpdate (\$cameraShape, \$imagePlane);\n" puts -nonewline $file "setAttr (\$imagePlane + \".offsetX\") -0.000000;\n" puts -nonewline $file "setAttr (\$imagePlane + \".offsetY\") -0.000000;\n" puts -nonewline $file "setAttr (\$imagePlane + \".imageName\") -type \"string\" \"[getFobjPath $fobj]\";\n" puts -nonewline $file "setAttr (\$imagePlane + \".fit\") 4;\n" puts -nonewline $file "setAttr (\$imagePlane + \".displayOnlyIfCurrent\") 1;\n" puts -nonewline $file "setAttr (\$imagePlane + \".depth\") (1000);\n" puts -nonewline $file "setAttr (\$imagePlane + \".displayMode\") 2;\n" puts -nonewline $file "//parent the camera to the scene group\n" puts -nonewline $file "parent \$cameraTransform \$sceneGroupName;\n" puts -nonewline $file "hide \$cameraTransform;\n" puts -nonewline $file "\n//end making camera $fObjName\n\n\n" } #if } #if } #for # write points... #make point group puts -nonewline $file "//create points\n\n" set cameraPointGroupName [getPGroupName $cameraPointGroup] set cameraPointGroupName [format "pGroup_%s_1" $cameraPointGroupName] puts -nonewline $file "//Make point group\n" puts -nonewline $file "string \$pointGroupName = `group -em -name \"$cameraPointGroupName\" -parent \$sceneGroupName`;\n" puts -nonewline $file "\$pointGroupName = (\$sceneGroupName + \"|\" + \$pointGroupName);\n" for {set point [getFirstPoint $cameraPointGroup]} {$point!=0} {set point [getNextPoint $cameraPointGroup $point]}\ { if {[isPointCalculated3D $cameraPointGroup $point]} then\ { puts -nonewline $file "\n//Make a point\n" set pointName [getPointName $cameraPointGroup $point] set pointName [format "p%sShape_1" $pointName] set pos3dlocal [getPointCalcPosition3D $cameraPointGroup $point] set pos3d [vec3+vec3 [s*vec3 $global_scale [mat3*vec3 $global_rot $pos3dlocal]] $global_pos] puts -nonewline $file "string \$locatorShapeName = `createNode \"locator\" -name $pointName`;\n" puts -nonewline $file "string \$parent_node\[\] = `listRelatives -p \$locatorShapeName`;\n" puts -nonewline $file "\$locatorTransformName = (\"|\" + \$parent_node\[0\]);\n" puts -nonewline $file "setAttr (\$locatorTransformName + \".scale\") 10 10 10;\n" puts -nonewline $file "move $pos3d \$locatorTransformName;\n" puts -nonewline $file "parent \$locatorTransformName \$pointGroupName;\n" } #if } close $file }