# # Export Single Matchmoving Points - export single points as locators (MEL -> Maya) set path [get3DEInstallPath] source $path/user_data/tcl_archive/veclib.tcl open3DEConsole print3DEConsole "\nExport Single Matchmoving Points: This script exports all\n selected points as 3D locators in Maya (MEL)\n\n\n" flush3DEConsole #get the camera point group set pg [getSelectedPGroup] if {$pg==0}\ { bell post3DEInfoRequester " \n Error, there is no Pointgroup selected. \n" return } set fobj [getSelectedFobj] if {$fobj==0}\ { bell post3DEInfoRequester " \n Error, there is no Sequence selected. \n" return } set tcl_precision 10 #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 "// Single matchmoving points exporter\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" # 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.01 -fcp 10000 -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" #set positon and rotations # set pos3d [getPGroupPosition3D $cameraPointGroup $fobj 1] # set rot3d [getPGroupRotation3D $cameraPointGroup $fobj 1] # 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 0 0 0 \$cameraTransform;\n" puts -nonewline $file "xform -rotation 0 0 0 \$cameraTransform;\n" puts -nonewline $file "xform -scale 20 20 20 \$cameraTransform;\n" #set 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\") (9000/20);\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" } # write points... #make point group puts -nonewline $file "//create points\n\n" set cameraPointGroupName [getPGroupName $pg] set cameraPointGroupName [format "pGroup_%s_1" $pg] 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" set no_frames [getFobjNoFrames $fobj] set fback_w [getCameraFBackWidth $camera] set fback_h [getCameraFBackHeight $camera] set focal [getCameraFocalLength $camera] set factor 100 for {set point [getFirstPoint $pg]} {$point!=0} {set point [getNextPoint $pg $point]}\ { if {[getPointSelectionFlag $pg $point]} then\ { puts -nonewline $file "\n//Make a point\n" set pointName [getPointName $pg $point] set pointName [format "p%sShape_1" $pointName] 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" for {set frame 1} {$frame<=$no_frames} {set frame [expr $frame+1]}\ { if {[isPointPos2DValid $pg $point $fobj $frame]}\ { # calculate 2.5 D point position... set pos_2d [getPointPosition2D $pg $point $fobj $frame] set pos_x [lindex $pos_2d 0] set pos_y [lindex $pos_2d 1] set pos_x [expr (($pos_x-0.5)*$fback_w)*$factor] set pos_y [expr (($pos_y-0.5)*$fback_h)*$factor] set pos_z [expr $focal*$factor*-1.0] puts -nonewline $file "setKeyframe -at translateX -t $frame -v $pos_x \$locatorTransformName; " puts -nonewline $file "setKeyframe -at translateY -t $frame -v $pos_y \$locatorTransformName; " puts -nonewline $file "setKeyframe -at translateZ -t $frame -v $pos_z \$locatorTransformName;\n" } } puts -nonewline $file "parent \$locatorTransformName \$pointGroupName;\n" } } close $file }