def callBackExportAll(req, widgetName, widgetStatus): for cameraIndex in range(tde4.getNoCameras()): try: # cameraTmp = tde4.getIndexCamera(cameraIndex) nametmp = "exportCamera" + str(cameraIndex) tde4.setWidgetValue(req, nametmp, str(tde4.getWidgetValue(req, widgetName))) except: pass
def callBackExportCamera(req, widgetName, widgetStatus): exportAll = True for cameraIndex in range(tde4.getNoCameras()): # cameraTmp = tde4.getIndexCamera(cameraIndex) nametmp = "exportCamera" + str(cameraIndex) try: if not tde4.getWidgetValue(req, nametmp): exportAll = False break except: pass tde4.setWidgetValue(req, "exportAllCameras", str(exportAll))
def set_initial_frame_widget(wdg,a,b): val = tde4.getWidgetValue(nuke_node_req,"option_menu_default_initial_frame") try: initial_frame_3de4 = tde4.getCameraFrameOffset(id_cam) except: initial_frame_3de4 = 1 # 3 means user-defined. In this case the GUI allows to enter a frame value. if val == 3: tde4.setWidgetSensitiveFlag(nuke_node_req,"text_initial_frame_nuke",True) elif val == 2: tde4.setWidgetSensitiveFlag(nuke_node_req,"text_initial_frame_nuke",False) tde4.setWidgetValue(nuke_node_req,"text_initial_frame_nuke",str(initial_frame_3de4)) elif val == 1: tde4.setWidgetSensitiveFlag(nuke_node_req,"text_initial_frame_nuke",False) tde4.setWidgetValue(nuke_node_req,"text_initial_frame_nuke",str(tde4.getCameraSequenceAttr(id_cam)[0]))
# Mimicking Nuke's Read Node default behaviour. value_option_menu_default_initial_frame = 1 else: # Using 3DE4 initial frame value_option_menu_default_initial_frame = 2 try: tde4.setWidgetCallbackFunction we_have_set_widget_callback_function = True except: we_have_set_widget_callback_function = False # For older releases we cannot do the smart guessing... if we_have_set_widget_callback_function: widget_default_initial_frame = tde4.addOptionMenuWidget(nuke_node_req,"option_menu_default_initial_frame","Startframe is based on","Nuke Read Node Default","3DE4 Initial Frame","User-defined") tde4.setWidgetValue(nuke_node_req,"option_menu_default_initial_frame",str(value_option_menu_default_initial_frame)) tde4.setWidgetCallbackFunction(nuke_node_req,"option_menu_default_initial_frame","set_initial_frame_widget") # Without / before smart-guessing we mimick Nuke's Read Node default behaviour. tde4.addTextFieldWidget(nuke_node_req,"text_initial_frame_nuke","Startframe in Nuke",str(tde4.getCameraSequenceAttr(id_cam)[0])) # After creating all widgets we invoke the Callback once explicitly in order to initialize the text widget. if we_have_set_widget_callback_function: set_initial_frame_widget(widget_default_initial_frame,None,None) # post requester ret = tde4.postCustomRequester(nuke_node_req,'Export nuke distortion node for camera ' + tde4.getCameraName(id_cam)+' ',700,0,'Ok','Cancel ') if ret != 1: raise CancelException('Cancelled') # At this point we know that user has pressed "Ok". Check path and suffix nuke_path = tde4.getWidgetValue(nuke_node_req,'file_nuke_path') if not nuke_path:
# # open requester... try: req = _export_requester_maya except (ValueError, NameError, TypeError): _export_requester_maya = tde4.createCustomRequester() req = _export_requester_maya tde4.addFileWidget(req, "file_browser", "Exportfile...", "*.mel") tde4.addTextFieldWidget(req, "startframe_field", "Startframe", "1") # tde4.addOptionMenuWidget(req,"mode_menu","Orientation","Y-Up", "Z-Up") tde4.addToggleWidget(req, "hide_ref_frames", "Hide Reference Frames", 0) cam = tde4.getCurrentCamera() offset = tde4.getCameraFrameOffset(cam) tde4.setWidgetValue(req, "startframe_field", str(offset)) FootageWidth = tde4.getCameraImageWidth(cam) FootageHeight = tde4.getCameraImageHeight(cam) lens = tde4.getFirstLens() CameraApertureWidth = tde4.getLensFBackWidth(lens) / 2.54 CameraApertureHeight = tde4.getLensFBackHeight(lens) / 2.54 #about lens distortion. LensDistortionValid = False camList = tde4.getCameraList() for cam in camList: lens = tde4.getCameraLens(cam) for id in tde4.getLensList(): focus = tde4.getLensFocalLength(id)
def main(): campg = None pgl = tde4.getPGroupList() for pg in pgl: if tde4.getPGroupType(pg) == "CAMERA": campg = pg if campg == None: tde4.postQuestionRequester("Export Maya...", "Error, there is no camera point group.", "Ok") # # open requester... try: req = _export_requester_maya except (ValueError, NameError, TypeError): _export_requester_maya = tde4.createCustomRequester() req = _export_requester_maya tde4.addFileWidget(req, "file_browser", "Exportfile...", "*.mel") tde4.addTextFieldWidget(req, "startframe_field", "Startframe", "1") # tde4.addOptionMenuWidget(req,"mode_menu","Orientation","Y-Up", "Z-Up") tde4.addToggleWidget(req, "hide_ref_frames", "Hide Reference Frames", 0) cam = tde4.getCurrentCamera() offset = tde4.getCameraFrameOffset(cam) tde4.setWidgetValue(req, "startframe_field", str(offset)) # ret = tde4.postCustomRequester(req,"Export Maya (MEL-Script)...",600,0,"Ok","Cancel") ret = 1 if ret == 1: # yup = tde4.getWidgetValue(req,"mode_menu") # if yup==2: yup = 0 yup = 1 # path = tde4.getWidgetValue(req,"file_browser") path = get_mel_filename()['path'] # frame0 = float(tde4.getWidgetValue(req,"startframe_field")) # frame0 -= 1 framerange = get_frame_range() playbackoptions = 'playbackOptions -min {0} -max {1};' playbackoptions = playbackoptions.format(framerange['first'], framerange['last']) frame0 = framerange['first'] - 1 hide_ref = tde4.getWidgetValue(req, "hide_ref_frames") if path != None: if not path.endswith('.mel'): path = path + '.mel' f = open(path, "w") if not f.closed: # # write some comments... f.write("//\n") f.write("// Maya/MEL export data written by %s\n" % tde4.get3DEVersion()) f.write("//\n") f.write( "// All lengths are in centimeter, all angles are in degree.\n" ) f.write("//\n\n") # # write scene group... groupname = """// create scene group... string $sceneGroupName = `group -em -name "mm_{name}"`; """ # f.write("// create scene group...\n") # f.write("string $sceneGroupName = `group -em -name \"Scene\"`;\n") groupname = groupname.format( name=get_mel_filename()['filename'][:-4]) f.write(groupname) # # write cameras... cl = tde4.getCameraList() index = 1 for cam in cl: camType = tde4.getCameraType(cam) noframes = tde4.getCameraNoFrames(cam) lens = tde4.getCameraLens(cam) if lens != None: name = validName(tde4.getCameraName(cam)) cam_name = 'cam_mm_' + name # name = "%s_%s_1"%(name,index) # name = "%s_%s"%(name,index) name = cam_name index += 1 fback_w = tde4.getLensFBackWidth(lens) fback_h = tde4.getLensFBackHeight(lens) p_aspect = tde4.getLensPixelAspect(lens) focal = tde4.getCameraFocalLength(cam, 1) lco_x = tde4.getLensLensCenterX(lens) lco_y = tde4.getLensLensCenterY(lens) # convert filmback to inch... fback_w = fback_w / 2.54 fback_h = fback_h / 2.54 lco_x = -lco_x / 2.54 lco_y = -lco_y / 2.54 # convert focal length to mm... focal = focal * 10.0 # create camera... f.write("\n") f.write("// create camera %s...\n" % name) f.write( "string $cameraNodes[] = `camera -name \"%s\" -hfa %.15f -vfa %.15f -fl %.15f -ncp 0.01 -fcp 10000 -shutterAngle 180 -ff \"overscan\"`;\n" % (name, fback_w, fback_h, focal)) f.write("string $cameraTransform = $cameraNodes[0];\n") f.write("string $cameraShape = $cameraNodes[1];\n") f.write( "xform -zeroTransformPivots -rotateOrder zxy $cameraTransform;\n" ) f.write( "setAttr ($cameraShape+\".horizontalFilmOffset\") %.15f;\n" % lco_x) f.write( "setAttr ($cameraShape+\".verticalFilmOffset\") %.15f;\n" % lco_y) f.write("setAttr ($cameraShape+\".renderable\") 1;\n") p3d = tde4.getPGroupPosition3D(campg, cam, 1) p3d = convertZup(p3d, yup) f.write( "xform -translation %.15f %.15f %.15f $cameraTransform;\n" % (p3d[0], p3d[1], p3d[2])) r3d = tde4.getPGroupRotation3D(campg, cam, 1) rot = convertToAngles(r3d) f.write( "xform -rotation %.15f %.15f %.15f $cameraTransform;\n" % rot) f.write("xform -scale 1 1 1 $cameraTransform;\n") """add pipeline attributes to camerashape""" # attribs = add_pipeline_attribs() ### OBSOLETE WAY attribs = add_pipeline_parms() f.write(attribs) # image plane... f.write("\n\n\n\n// create image plane...\n") f.write( "string $imagePlane = `createNode imagePlane`;\n") f.write( "cameraImagePlaneUpdate ($cameraShape, $imagePlane);\n" ) f.write( "setAttr ($imagePlane + \".offsetX\") %.15f;\n" % lco_x) f.write( "setAttr ($imagePlane + \".offsetY\") %.15f;\n" % lco_y) if camType == "SEQUENCE": f.write( "setAttr ($imagePlane+\".useFrameExtension\") 1;\n" ) else: f.write( "setAttr ($imagePlane+\".useFrameExtension\") 0;\n" ) f.write( "expression -n \"frame_ext_expression\" -s ($imagePlane+\".frameExtension=frame\");\n" ) path = tde4.getCameraPath(cam) sattr = tde4.getCameraSequenceAttr(cam) path = prepareImagePath(path, sattr[0]) f.write( "setAttr ($imagePlane + \".imageName\") -type \"string\" \"%s\";\n" % (path)) f.write("setAttr ($imagePlane + \".fit\") 4;\n") f.write( "setAttr ($imagePlane + \".displayOnlyIfCurrent\") 1;\n" ) f.write( "setAttr ($imagePlane + \".depth\") (9000/2);\n") # parent camera to scene group... f.write("\n") f.write("// parent camera to scene group...\n") f.write("parent $cameraTransform $sceneGroupName;\n") if camType == "REF_FRAME" and hide_ref: f.write( "setAttr ($cameraTransform +\".visibility\") 0;\n" ) # animate camera... if camType != "REF_FRAME": f.write("\n") f.write("// animating camera %s...\n" % name) f.write(playbackoptions) # f.write("playbackOptions -min %d -max %d;\n"%(1+frame0,noframes+frame0)) f.write("\n\n") frame = 1 while frame <= noframes: # rot/pos... p3d = tde4.getPGroupPosition3D(campg, cam, frame) p3d = convertZup(p3d, yup) r3d = tde4.getPGroupRotation3D(campg, cam, frame) rot = convertToAngles(r3d) if frame > 1: rot = [ angleMod360(rot0[0], rot[0]), angleMod360(rot0[1], rot[1]), angleMod360(rot0[2], rot[2]) ] rot0 = rot f.write( "setKeyframe -at translateX -t %d -v %.15f $cameraTransform; " % (frame + frame0, p3d[0])) f.write( "setKeyframe -at translateY -t %d -v %.15f $cameraTransform; " % (frame + frame0, p3d[1])) f.write( "setKeyframe -at translateZ -t %d -v %.15f $cameraTransform; " % (frame + frame0, p3d[2])) f.write( "setKeyframe -at rotateX -t %d -v %.15f $cameraTransform; " % (frame + frame0, rot[0])) f.write( "setKeyframe -at rotateY -t %d -v %.15f $cameraTransform; " % (frame + frame0, rot[1])) f.write( "setKeyframe -at rotateZ -t %d -v %.15f $cameraTransform; " % (frame + frame0, rot[2])) # focal length... focal = tde4.getCameraFocalLength(cam, frame) focal = focal * 10.0 f.write( "setKeyframe -at focalLength -t %d -v %.15f $cameraShape;\n" % (frame + frame0, focal)) frame += 1 # # write camera point group... f.write("\n") f.write("// create camera point group...\n") name = "cameraPGroup_%s_1" % validName( tde4.getPGroupName(campg)) f.write( "string $pointGroupName = `group -em -name \"%s\" -parent $sceneGroupName`;\n" % name) # f.write("$pointGroupName = ($sceneGroupName + \"|\" + $pointGroupName);\n") f.write("\n") # write points... l = tde4.getPointList(campg) for p in l: if tde4.isPointCalculated3D(campg, p): name = tde4.getPointName(campg, p) name = "p%s" % validName(name) p3d = tde4.getPointCalcPosition3D(campg, p) p3d = convertZup(p3d, yup) f.write("\n") f.write("// create point %s...\n" % name) f.write( "string $locator = stringArrayToString(`spaceLocator -name %s`, \"\");\n" % name) f.write("$locator = (\"|\" + $locator);\n") f.write("xform -t %.15f %.15f %.15f $locator;\n" % (p3d[0], p3d[1], p3d[2])) f.write("parent $locator $pointGroupName;\n") f.write("\n") f.write( "xform -zeroTransformPivots -rotateOrder zxy -scale 1.000000 1.000000 1.000000 $pointGroupName;\n" ) f.write("\n") # # write object/mocap point groups... camera = tde4.getCurrentCamera() noframes = tde4.getCameraNoFrames(camera) pgl = tde4.getPGroupList() index = 1 for pg in pgl: if tde4.getPGroupType(pg) == "OBJECT" and camera != None: f.write("\n") f.write("// create object point group...\n") pgname = "objectPGroup_%s_%d_1" % (validName( tde4.getPGroupName(pg)), index) index += 1 f.write( "string $pointGroupName = `group -em -name \"%s\" -parent $sceneGroupName`;\n" % pgname) f.write( "$pointGroupName = ($sceneGroupName + \"|\" + $pointGroupName);\n" ) # write points... l = tde4.getPointList(pg) for p in l: if tde4.isPointCalculated3D(pg, p): name = tde4.getPointName(pg, p) name = "p%s" % validName(name) p3d = tde4.getPointCalcPosition3D(pg, p) p3d = convertZup(p3d, yup) f.write("\n") f.write("// create point %s...\n" % name) f.write( "string $locator = stringArrayToString(`spaceLocator -name %s`, \"\");\n" % name) f.write("$locator = (\"|\" + $locator);\n") f.write( "xform -t %.15f %.15f %.15f $locator;\n" % (p3d[0], p3d[1], p3d[2])) f.write("parent $locator $pointGroupName;\n") f.write("\n") scale = tde4.getPGroupScale3D(pg) f.write( "xform -zeroTransformPivots -rotateOrder zxy -scale %.15f %.15f %.15f $pointGroupName;\n" % (scale, scale, scale)) # animate object point group... f.write("\n") f.write("// animating point group %s...\n" % pgname) frame = 1 while frame <= noframes: # rot/pos... p3d = tde4.getPGroupPosition3D(pg, camera, frame) p3d = convertZup(p3d, yup) r3d = tde4.getPGroupRotation3D(pg, camera, frame) rot = convertToAngles(r3d) if frame > 1: rot = [ angleMod360(rot0[0], rot[0]), angleMod360(rot0[1], rot[1]), angleMod360(rot0[2], rot[2]) ] rot0 = rot f.write( "setKeyframe -at translateX -t %d -v %.15f $pointGroupName; " % (frame + frame0, p3d[0])) f.write( "setKeyframe -at translateY -t %d -v %.15f $pointGroupName; " % (frame + frame0, p3d[1])) f.write( "setKeyframe -at translateZ -t %d -v %.15f $pointGroupName; " % (frame + frame0, p3d[2])) f.write( "setKeyframe -at rotateX -t %d -v %.15f $pointGroupName; " % (frame + frame0, rot[0])) f.write( "setKeyframe -at rotateY -t %d -v %.15f $pointGroupName; " % (frame + frame0, rot[1])) f.write( "setKeyframe -at rotateZ -t %d -v %.15f $pointGroupName;\n" % (frame + frame0, rot[2])) frame += 1 # mocap point groups... if tde4.getPGroupType(pg) == "MOCAP" and camera != None: f.write("\n") f.write("// create mocap point group...\n") pgname = "objectPGroup_%s_%d_1" % (validName( tde4.getPGroupName(pg)), index) index += 1 f.write( "string $pointGroupName = `group -em -name \"%s\" -parent $sceneGroupName`;\n" % pgname) f.write( "$pointGroupName = ($sceneGroupName + \"|\" + $pointGroupName);\n" ) # write points... l = tde4.getPointList(pg) for p in l: if tde4.isPointCalculated3D(pg, p): name = tde4.getPointName(pg, p) name = "p%s" % validName(name) p3d = tde4.getPointMoCapCalcPosition3D( pg, p, camera, 1) p3d = convertZup(p3d, yup) f.write("\n") f.write("// create point %s...\n" % name) f.write( "string $locator = stringArrayToString(`spaceLocator -name %s`, \"\");\n" % name) f.write("$locator = (\"|\" + $locator);\n") f.write( "xform -t %.15f %.15f %.15f $locator;\n" % (p3d[0], p3d[1], p3d[2])) for frame in range(1, noframes + 1): p3d = tde4.getPointMoCapCalcPosition3D( pg, p, camera, frame) p3d = convertZup(p3d, yup) f.write( "setKeyframe -at translateX -t %d -v %.15f $locator; " % (frame + frame0, p3d[0])) f.write( "setKeyframe -at translateY -t %d -v %.15f $locator; " % (frame + frame0, p3d[1])) f.write( "setKeyframe -at translateZ -t %d -v %.15f $locator; " % (frame + frame0, p3d[2])) f.write("parent $locator $pointGroupName;\n") f.write("\n") scale = tde4.getPGroupScale3D(pg) f.write( "xform -zeroTransformPivots -rotateOrder zxy -scale %.15f %.15f %.15f $pointGroupName;\n" % (scale, scale, scale)) # animate mocap point group... f.write("\n") f.write("// animating point group %s...\n" % pgname) frame = 1 while frame <= noframes: # rot/pos... p3d = tde4.getPGroupPosition3D(pg, camera, frame) p3d = convertZup(p3d, yup) r3d = tde4.getPGroupRotation3D(pg, camera, frame) rot = convertToAngles(r3d) if frame > 1: rot = [ angleMod360(rot0[0], rot[0]), angleMod360(rot0[1], rot[1]), angleMod360(rot0[2], rot[2]) ] rot0 = rot f.write( "setKeyframe -at translateX -t %d -v %.15f $pointGroupName; " % (frame + frame0, p3d[0])) f.write( "setKeyframe -at translateY -t %d -v %.15f $pointGroupName; " % (frame + frame0, p3d[1])) f.write( "setKeyframe -at translateZ -t %d -v %.15f $pointGroupName; " % (frame + frame0, p3d[2])) f.write( "setKeyframe -at rotateX -t %d -v %.15f $pointGroupName; " % (frame + frame0, rot[0])) f.write( "setKeyframe -at rotateY -t %d -v %.15f $pointGroupName; " % (frame + frame0, rot[1])) f.write( "setKeyframe -at rotateZ -t %d -v %.15f $pointGroupName;\n" % (frame + frame0, rot[2])) frame += 1 # # global (scene node) transformation... p3d = tde4.getScenePosition3D() p3d = convertZup(p3d, yup) r3d = tde4.getSceneRotation3D() rot = convertToAngles(r3d) s = tde4.getSceneScale3D() f.write( "xform -zeroTransformPivots -rotateOrder zxy -translation %.15f %.15f %.15f -scale %.15f %.15f %.15f -rotation %.15f %.15f %.15f $sceneGroupName;\n\n" % (p3d[0], p3d[1], p3d[2], s, s, s, rot[0], rot[1], rot[2])) f.write("\n") f.close() # tde4.postQuestionRequester("Export Maya...","Project successfully exported.","Ok") print '--> successfully exported Maya Mel' else: tde4.postQuestionRequester("Export Maya...", "Error, couldn't open file.", "Ok") return get_mel_filename()['path']