def updateViewer(self): """ update the 3d windows if any """ c4d.EventAdd() c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_NO_ANIMATION) c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED)
def update_viewport(): ''' Shortcut for using :func:`c4d.DrawViews` to update the Cinema 4D viewport. Check the source code for the flags that are passed to the function. ''' return c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_NO_REDUCTION | c4d.DRAWFLAGS_STATICBREAK)
def main(): selection = doc.GetActiveObjects() i = 0 for item in selection: l = c4d.BaseObject(c4d.Olight) l.InsertUnder(item) c4d.EventAdd() c4d.DrawViews()
def main(): selection = doc.GetSelection() selection_len = len(selection) i = 0 for item in selection: create_display_tag(selection[i]) i = i + 1 c4d.EventAdd() c4d.DrawViews()
def extend3Dline(self, nameA, nameB, actObjName, offset=1): doc = documents.GetActiveDocument() dazName = self.getDazMesh().GetName() meshName = dazName + "_" meshName = meshName.replace(".Shape", "") actObj = doc.SearchObject(meshName + actObjName) Aobj = doc.SearchObject(meshName + nameA) # Direction line Start Bobj = doc.SearchObject(meshName + nameB) # Direction line End targetObj = c4d.BaseObject(c4d.Onull) targetObj.SetName("TARGET") doc.InsertObject(targetObj) targetObjExtend = c4d.BaseObject(c4d.Onull) targetObjExtend.SetName("TARGET_Extend") doc.InsertObject(targetObjExtend) targetObj.SetMg(Aobj.GetMg()) targetObjExtend.InsertUnder(targetObj) constraintTAG = c4d.BaseTag(1019364) constraintTAG[c4d.ID_CA_CONSTRAINT_TAG_AIM] = True constraintTAG[c4d.ID_CA_CONSTRAINT_TAG_AIM_MAINTAIN] = False constraintTAG[20004] = 2 constraintTAG[20001] = Bobj targetObj.InsertTag(constraintTAG) caca = targetObj.GetFirstTag() c4d.DrawViews( c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK ) caca.Remove() targetMg = None try: targetObjExtend.SetMg(Bobj.GetMg()) objDistance = targetObjExtend[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Z] targetObj.SetAbsPos(Bobj.GetAbsPos()) targetObjExtend[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Z] = ( objDistance * offset ) targetObjExtend[c4d.NULLOBJECT_DISPLAY] = 9 targetMg = targetObjExtend.GetMg() actObj.SetMg(targetObjExtend.GetMg()) except: print("skip extend") targetObj.Remove() c4d.EventAdd() return targetMg
def ikZeroRot(jointObj): tag = jointObj.GetFirstTag() goalObj = tag[10001] ry = jointObj[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Y] tag[10001] = None jointObj[c4d.ID_BASEOBJECT_FROZEN_ROTATION, c4d.VECTOR_Y] = ry jointObj[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Y] = 0 c4d.EventAdd() c4d.DrawViews( c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK ) c4d.EventAdd() goalObj[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_X] = 0 goalObj[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Y] = 0 goalObj[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Z] = 0 goalObj[c4d.ID_BASEOBJECT_FROZEN_ROTATION, c4d.VECTOR_X] = 0 goalObj[c4d.ID_BASEOBJECT_FROZEN_ROTATION, c4d.VECTOR_Y] = 0 goalObj[c4d.ID_BASEOBJECT_FROZEN_ROTATION, c4d.VECTOR_Z] = 0 tag[c4d.ID_CA_CONSTRAINT_TAG_PSR_MAINTAIN] = True c4d.EventAdd() tag[10001] = goalObj c4d.EventAdd() c4d.DrawViews( c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK ) c4d.EventAdd()
def printErrors(mainDialog,exportData): if len(exportData.AWDerrorObjects)>0: maindialogHelpers.enableAll(mainDialog,True) newMessage=c4d.plugins.GeLoadString(ids.ERRORMESSAGE)+"\n" for errorMessage in exportData.AWDerrorObjects: newMessage+=c4d.plugins.GeLoadString(errorMessage.errorID) if errorMessage.errorData!=None: newMessage+="\n\n"+str(c4d.plugins.GeLoadString(ids.ERRORMESSAGEOBJ))+" = "+str(errorMessage.errorData) c4d.gui.MessageDialog(newMessage) exportData=None if mainDialog.GetBool(ids.CBOX_CLOSEAFTEREXPORT) == True: exportData=None c4d.DrawViews( c4d.DA_ONLY_ACTIVE_VIEW|c4d.DA_NO_THREAD|c4d.DA_NO_REDUCTION|c4d.DA_STATICBREAK ) c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED) c4d.EventAdd(c4d.EVENT_ANIMATE) mainDialog.Close() c4d.DrawViews( c4d.DA_ONLY_ACTIVE_VIEW|c4d.DA_NO_THREAD|c4d.DA_NO_REDUCTION|c4d.DA_STATICBREAK ) c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED) c4d.EventAdd(c4d.EVENT_ANIMATE) exportData=None return False return True
def buildSkeletonPose(exportData,curObj,curTime): newAWDWrapperBlock=classesAWDBlocks.WrapperBlock(None,"",0) exportData.allAWDBlocks.append(newAWDWrapperBlock) newAWDBlock=classesAWDBlocks.SkeletonPoseBlock(exportData.idCounter,0,curObj.GetTag(1028938)[1011]) exportData.idCounter+=1 newAWDBlock.name=curObj.GetTag(1028938)[1011] c4d.documents.SetDocumentTime(exportData.doc, curTime)# set original Time c4d.DrawViews( c4d.DRAWFLAGS_FORCEFULLREDRAW|c4d.DRAWFLAGS_NO_THREAD|c4d.DRAWFLAGS_NO_REDUCTION|c4d.DRAWFLAGS_STATICBREAK ) c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED) c4d.EventAdd(c4d.EVENT_ANIMATE) c4d.EventAdd(c4d.EVENT_FORCEREDRAW) c4d.DrawViews( c4d.DRAWFLAGS_FORCEFULLREDRAW) c4d.GeSyncMessage(c4d.EVMSG_ASYNCEDITORMOVE) newAWDBlock.transformations=[] buildJointTransform([curObj],newAWDBlock.transformations,exportData,True) # recursive function to get all Joints as JointBlocks newAWDWrapperBlock.data=newAWDBlock newAWDWrapperBlock.blockType=102 newAWDWrapperBlock.tagForExport=True return newAWDWrapperBlock
def constraintObj(self, obj, target): doc = c4d.documents.GetActiveDocument() constraintTAG = c4d.BaseTag(1019364) constraintTAG[c4d.ID_CA_CONSTRAINT_TAG_AIM] = True constraintTAG[c4d.ID_CA_CONSTRAINT_TAG_AIM_MAINTAIN] = True constraintTAG[20001] = target obj.InsertTag(constraintTAG) c4d.EventAdd() c4d.DrawViews( c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK ) return constraintTAG
def main(): doc = c4d.documents.GetActiveDocument() fps = doc[ c4d.DOCUMENT_FPS ] minTime = doc[ c4d.DOCUMENT_MINTIME ].GetFrame( fps ) maxTime = doc[ c4d.DOCUMENT_MAXTIME ].GetFrame( fps ) f = 0 for f in range( minTime, maxTime ): doc.SetTime( c4d.BaseTime( f, fps ) ) c4d.DrawViews( c4d.DA_ONLY_ACTIVE_VIEW|c4d.DA_NO_THREAD|c4d.DA_NO_REDUCTION|c4d.DA_STATICBREAK ) c4d.GeSyncMessage( c4d.EVMSG_TIMECHANGED ) c4d.EventAdd( c4d.EVENT_ANIMATE ) frame( f ) if escPressed(): break gui.MessageDialog( "%i - %i frames processed." % (minTime, f) )
def preAutoIK(self): doc = documents.GetActiveDocument() obj = doc.SearchObject("hip") if obj: doc = documents.GetActiveDocument() if not doc.SearchObject("lThighTwist"): if self.checkIfPosedResetPose(False) == False: forceTpose().dazFix_All_To_T_Pose() if doc.SearchObject("lThighTwist"): if self.checkIfPosedResetPose(False) == False: self.dazManualRotationFixTpose() c4d.DrawViews( c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK ) c4d.EventAdd()
def resetBindPose(self, curObj, oldSelecObj): tagCnt = 0 doc = c4d.documents.GetActiveDocument() while tagCnt < len(self.allWeightTags): if tagCnt == 0: doc.SetActiveObject(self.allWeightTags[tagCnt].GetObject(), c4d.SELECTION_NEW) if tagCnt > 0: doc.SetActiveObject(self.allWeightTags[tagCnt].GetObject(), c4d.SELECTION_ADD) tagCnt += 1 c4d.EventAdd() self.doc.AddUndo(c4d.UNDOTYPE_CHANGE, curObj) # Support redo the insert operation c4d.CallCommand(1019937) c4d.DrawViews(c4d.DRAWFLAGS_FORCEFULLREDRAW) doc.SetActiveObject(oldSelecObj, c4d.SELECTION_NEW) c4d.EventAdd()
def __init__(self, curObj, wasSelected=None, printErrors=True): self.doc = c4d.documents.GetActiveDocument() if wasSelected is None: wasSelected = curObj self.allWeightTags = [] self.curObj = curObj doc = c4d.documents.GetActiveDocument() allobjects = doc.GetObjects() messageStr = "OK" self.getAllWeightTags(allobjects) self.expressionTagsToRestore = [] self.disableExpressionsOnJoints([curObj], self.expressionTagsToRestore) c4d.DrawViews(c4d.DRAWFLAGS_FORCEFULLREDRAW) c4d.EventAdd() self.resetBindPose(curObj, wasSelected) if self.isRightScale([curObj]) == False: rvalue = gui.QuestionDialog( "Skeleton contains Joints with other Scale than '1,1,1'.\n\n Fix automatically?" ) if rvalue == True: self.setRightScale([self.curObj]) self.setNewBindPose(curObj, wasSelected) if rvalue == False: messageStr = "ERROR: Some Joints have Scale-Values other than '1,1,1' !!!\n\n" skinnedMatrices = self.checkBind() rvalue1 = False if len(skinnedMatrices) >= 1: rvalue1 = gui.QuestionDialog( "Joints are bound to a 'Skinning-Matrix' thats not the Global Matrix of the C4D-Scene.\nTo prevent errors all meshes should be skinned to the GLobal-C4D-Matrix.\nFix automaticcaly ?" ) if rvalue1 == True: self.setSkinMgToGlobal() self.setNewBindPose(curObj, wasSelected) if rvalue1 == False: if messageStr == "OK": messageStr = "" messageStr += "ERROR: Joints are bound to a 'Skinning-Matrix', thats not the Global Matrix of the C4D-Scene.\nTo prevent Errors all Objects should be skinned to the GLobal-C4D-Matrix.\n\n" #print ("Skeleton Status\n"+str(messageStr)) if printErrors == True: gui.MessageDialog("Skeleton Status\n" + str(messageStr)) for tag in self.expressionTagsToRestore: tag[c4d.EXPRESSION_ENABLE] = True
def main(): # for each frame render the associated 3DS file. # The view and animation must already be defined # through the GUI. doc = c4d.documents.GetActiveDocument() fps = doc.GetFps() start = doc.GetMinTime().GetFrame(fps) until = doc.GetMaxTime().GetFrame(fps) # For each frame we save the associated 3DS file. for i in xrange(start, until): # Construct new name tmp_name = [] tmp_name.append('/Users/Robin/Desktop/Scene_3ds/') tmp_name.append('scene.{0:04d}'.format(i)) tmp_name.append('.3ds') name = ''.join(tmp_name) print 'Export : %r' % name # Move to frame doc.SetTime(c4d.BaseTime(i, fps)) # Update GUI c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_NO_REDUCTION | c4d.DRAWFLAGS_STATICBREAK) # Update timeline c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED) # Save document e = c4d.documents.SaveDocument(doc=doc, name=name, saveflags=c4d.SAVEDOCUMENTFLAGS_0, format=c4d.FORMAT_3DSEXPORT) if not e: gui.MessageDialog("Unable to export frame %r" % i) return else: print "Frame %r saved" % i
def main(): c4d.StopAllThreads() doc = c4d.documents.GetActiveDocument() fps = doc.GetFps() fromTime = doc.GetMinTime().GetFrame(fps) toTime = doc.GetMaxTime().GetFrame(fps) animLength = toTime - fromTime + 1 filePath = c4d.storage.SaveDialog() filePath, objName = os.path.split(filePath) objName = objName + "_" filePath = filePath + "\\" for f in range(0,animLength): c4d.EventAdd(c4d.EVENT_FORCEREDRAW) c4d.DrawViews(c4d.DRAWFLAGS_FORCEFULLREDRAW) c4d.StatusSetText("Exporting " + str(f) + " of " + str(animLength)) c4d.StatusSetBar(100.0*f/animLength) objs = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN) # Get a fresh, temporary document with only the selected objects docTemp = c4d.documents.IsolateObjects(doc, objs) docTemp.SetTime(c4d.BaseTime(fromTime,fps) + c4d.BaseTime(f,fps)) if docTemp == None: return # Set project scale unitScale = c4d.UnitScaleData() unitScale.SetUnitScale(1.0, c4d.DOCUMENT_UNIT_M) bc = c4d.BaseContainer() bc[c4d.DOCUMENT_DOCUNIT] = unitScale docTemp.SetDocumentData(c4d. DOCUMENTSETTINGS_DOCUMENT, bc) fileName = filePath+objName+str(f)+".obj" savingresult = c4d.documents.SaveDocument(docTemp,fileName,c4d.SAVEDOCUMENTFLAGS_0,c4d.FORMAT_OBJ2EXPORT) c4d.documents.KillDocument(docTemp) c4d.StatusClear() gui.MessageDialog( 'Exporting to'+filePath+' done' )
def update_editor(): r""" A shortcut for .. code-block:: python c4d.DrawViews( c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_NO_REDUCTION | c4d.DRAWFLAGS_STATICBREAK) Can be used to update the editor, useful for going through the frames of a document and doing backing or similar stuff. :Returns: The return-value of :func:`c4d.DrawViews`. """ return c4d.DrawViews( c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_NO_REDUCTION | c4d.DRAWFLAGS_STATICBREAK)
def autoIK(self, var): doc = c4d.documents.GetActiveDocument() obj = doc.SearchObject("hip") if obj: AllSceneToZero().sceneToZero() applyDazIK(var) dazToC4Dutils().changeSkinType() self.unhideProps() c4d.EventAdd() c4d.DrawViews( c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK ) self.protectIKMControls() self.limitFloorContact() self.freezeTwistBones() self.figureFixBrute() self.protectTwist()
def dazManualRotationFixTpose(self): # return False #Quit TEMPORAL doc = documents.GetActiveDocument() def setRotAndMirror(jointName, x, y, z): joint = doc.SearchObject(jointName) if x != 0.0: joint[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_X] = x if y != 0.0: joint[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Y] = y if z != 0.0: joint[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Z] = z dazType = self.find_genesis() if dazType == "Genesis8": autoAlignArms() if dazType == "Genesis3": autoAlignArms() if dazType == "Genesis2": # Genesis 2 LEFT Side: setRotAndMirror("lShldr", 0.089, 0.0, -0.019) setRotAndMirror("lForeArm", 0.334, 0.0, 0.0) setRotAndMirror("lHand", 0.083, 0.222, -0.121) setRotAndMirror("lThigh", 0.0, 0.0, 0.0) # Genesis 2 RIGHT Side: setRotAndMirror("rShldr", -0.089, 0.0, 0.019) setRotAndMirror("rForeArm", -0.334, 0.0, 0.0) setRotAndMirror("rHand", -0.083, 0.222, 0.121) setRotAndMirror("rThigh", 0.0, 0.0, 0.0) c4d.EventAdd() c4d.DrawViews( c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK ) c4d.EventAdd()
def main(): selection = doc.GetSelection() i = 0 minTime = doc.GetMinTime() maxTime = doc.GetMaxTime() print minTime.GetFrame(doc.GetFps()) print maxTime.GetFrame(doc.GetFps()) for t in range(minTime.GetFrame(doc.GetFps()), maxTime.GetFrame(doc.GetFps())): frame = c4d.BaseTime(t / float(doc.GetFps())) for item in selection: trackPos = c4d.DescID( c4d.DescLevel(c4d.ID_BASEOBJECT_REL_POSITION, c4d.DTYPE_VECTOR, item.GetType())) trackRot = c4d.DescID( c4d.DescLevel(c4d.ID_BASEOBJECT_REL_ROTATION, c4d.DTYPE_VECTOR, item.GetType())) xPos = item.GetVectorTracks(trackPos)[1].GetValue(doc, frame) yPos = item.GetVectorTracks(trackPos)[2].GetValue(doc, frame) zPos = item.GetVectorTracks(trackPos)[3].GetValue(doc, frame) xRot = item.GetVectorTracks(trackRot)[1].GetValue(doc, frame) yRot = item.GetVectorTracks(trackRot)[2].GetValue(doc, frame) zRot = item.GetVectorTracks(trackRot)[3].GetValue(doc, frame) print xPos, yPos, zPos print xRot, yRot, zRot #print item.GetVectorTracks(trackRot) c4d.EventAdd() c4d.DrawViews()
def alignJoint(self, side, jointName, jointTarget): doc = documents.GetActiveDocument() jointSource = doc.SearchObject(side + jointName) objSource = self.newNullfromJoint(side + jointName, "ROTATOR") objTarget = self.newNullfromJoint(side + jointTarget, "TARGET") if jointSource != None: xtag = self.constraintObj(jointSource, objTarget) objTarget.SetMg(objSource.GetMg()) if side == "l": xValue = 100 if side == "r": xValue = -100 objTarget[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_X] += xValue c4d.DrawViews( c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK ) c4d.EventAdd() xtag.Remove() objSource.Remove() objTarget.Remove()
def main(): global path, rangeStart, rangeEnd doc = documents.GetActiveDocument() docFPS = doc[c4d.DOCUMENT_FPS] d_print("Document FPS: " + str(docFPS)) try: cam = doc.GetSelection()[0] if not cam.GetType() == 5103: gui.MessageDialog("Please select a Camera to export") return except IndexError: gui.MessageDialog("Please select a Camera to export") return camTracks = [] for i in range(903, 905): for j in range(1000, 1003): track = cam.FindCTrack( c4d.DescID(c4d.DescLevel(i), c4d.DescLevel(j))) camTracks.append(track) rangeStart = camTracks[0].GetCurve().GetKey(0).GetTime().GetFrame(docFPS) rangeEnd = camTracks[0].GetCurve().GetKey( camTracks[0].GetCurve().GetKeyCount() - 1).GetTime().GetFrame(docFPS) dlg = Dialog() dlg.startFrame = rangeStart dlg.endFrame = rangeEnd dlg.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE, defaultw=500) if not dlg.didPressOK: return keyFrameInterval = dlg.keyFrameInterval timeOffsetInFrames = dlg.timeOffsetInFrames sceneScale = dlg.sceneScale frameSpaceInS = dlg.frameSpaceInS startFrame = dlg.startFrame endFrame = dlg.endFrame targetFPS = dlg.targetFPS d_print("Keyframe Interval: " + str(keyFrameInterval)) d_print("Time Offset: " + str(timeOffsetInFrames)) d_print("Scene Scale: " + str(sceneScale)) d_print("Frame Space: " + str(frameSpaceInS)) d_print("Range Start: " + str(rangeStart)) d_print("Range End: " + str(rangeEnd)) d_print("Target FPS: " + str(targetFPS)) path = storage.LoadDialog(flags=2) if not path: print "No path found" return if not os.path.exists(path + '/fullsequence_empty.xml'): os.rename(path + '/fullsequence.xml', path + '/fullsequence_empty.xml') f = open(path + '/fullsequence_empty.xml', 'r') xmlText = f.read() f.close() split1 = string.rfind(xmlText, "</Syncronorm_ShowSequence_V1.0>") split2 = string.rfind(xmlText, "</blocks>") string1 = xmlText[:split2 - 1] string2 = xmlText[split2:split1 - 1] string3 = xmlText[split1:] insertString1 = "" insertString2 = "<SceneList>" for frame in range(startFrame, endFrame + keyFrameInterval, keyFrameInterval): d_print("\n\n---------- Frame: " + str(frame) + ' ----------') ID = str(uuid.uuid4()) startTime = (frame / targetFPS) + (timeOffsetInFrames / targetFPS) - ( keyFrameInterval / targetFPS) + (1 / docFPS) startTime = string.replace(str(startTime), ".", ",") d_print("Start Time: " + str(startTime)) length = (keyFrameInterval / targetFPS) - frameSpaceInS length = string.replace(str(length), ".", ",") d_print("Length: " + str(length)) doc.SetTime(c4d.BaseTime(frame, docFPS)) c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW | c4d.DA_NO_THREAD | c4d.DA_NO_REDUCTION | c4d.DA_STATICBREAK) c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED) posX = cam.GetMg().off.x * sceneScale posY = cam.GetMg().off.y * sceneScale posZ = -cam.GetMg().off.z * sceneScale rotX = -MatrixToHPB(cam.GetMg()).x * 180 / math.pi rotY = -MatrixToHPB(cam.GetMg()).y * 180 / math.pi rotZ = MatrixToHPB(cam.GetMg()).z * 180 / math.pi if (rotX <= -180): rotX = rotX + 360 if (rotX >= 180): rotX = rotX - 360 if (rotY <= -180): rotY = rotY + 360 if (rotY >= 180): rotY = rotY - 360 if (rotZ <= -180): rotZ = rotZ + 360 if (rotZ >= 180): rotZ = rotZ - 360 # posX = round(posX, 6) # posY = round(posY, 6) # posZ = round(posZ, 6) rotX = round(rotX, 3) rotY = round(rotY, 3) rotZ = round(rotZ, 3) posX = string.replace(str(posX), ".", ",") posY = string.replace(str(posY), ".", ",") posZ = string.replace(str(posZ), ".", ",") rotX = string.replace(str(rotX), ".", ",") rotY = string.replace(str(rotY), ".", ",") rotZ = string.replace(str(rotZ), ".", ",") d_print(posX) d_print(posY) d_print(posZ) d_print(rotX) d_print(rotY) d_print(rotZ) insertString1 = ( insertString1 + '\n<block Name="CamPos" StartTime="' + startTime + '" Lenght="' + length + '" FadeInTime="' + length + '" FadeOutTime="0" DelayInTime="0" DelayOutTime="0" BeatsPerMinute="120" UseACD="False" ACD_InDelay="0" ACD_InFade="0" ACD_OutDelay="0" ACD_OutFade="0" Mute="False" Freeze="False" Tracking="True" EffectSpeedOffset="0" MultiSceneGUID="' + ID + '" CueListGUID="" FadeCenter="True" FadeAmplitude="True" FadePhase="True" FadeRpM="False" UsedCenter="True" UsedAmplitude="True" UsedPhase="True" UsedRpM="True" InFadeRate="100" OutFadeRate="100" FadeType="0" DelayType="0" LightColor="-1">\n' + ' <LightColorX red="255" green="255" blue="255" amber="0" white="0" intensity="255" CellX="0" CellY="0"></LightColorX>\n' + '</block>') insertString2 = ( insertString2 + '<scene GroupGUID="" GUID="' + ID + '" AggTypeGUID="" InDelayTime="0" InFadeTime="0" Name="CamPos" OutDelayTime="0" OutFadeTime="0" IsUniqueBlockScene="False" UsedSplines="True">\n' + ' <Items>\n' + ' <Item UID="65500" PatternGUID="" Amplitude="0" Center="0" EffectGUID="" InDelayPoint="0" InFadePoint="100" Offset="0" OutDelayPoint="0" OutFadePoint="100" MaxPhase="0" Phase="' + posX + '" RpM="0" NumWaves="1" GoOut="0" CutAfter="1" SelectionIndex="0" Direction="0" TogleWinkelLeft="0" TogleWinkelRight="360" VisibleWaves="1" BNC_StartReverse="False" ValueOffset="0" FadeCenter="True" FadeAmplitude="True" FadePhase="True" FadeRpM="False" UsedCenter="True" UsedAmplitude="True" UsedPhase="True" UsedRpM="True" InFadeRate="100" OutFadeRate="100" FadeType="0" DelayType="0"></Item>\n' + ' <Item UID="65504" PatternGUID="" Amplitude="0" Center="0" EffectGUID="" InDelayPoint="0" InFadePoint="100" Offset="0" OutDelayPoint="0" OutFadePoint="100" MaxPhase="0" Phase="' + posY + '" RpM="0" NumWaves="1" GoOut="0" CutAfter="1" SelectionIndex="0" Direction="0" TogleWinkelLeft="0" TogleWinkelRight="360" VisibleWaves="1" BNC_StartReverse="False" ValueOffset="0" FadeCenter="True" FadeAmplitude="True" FadePhase="True" FadeRpM="False" UsedCenter="True" UsedAmplitude="True" UsedPhase="True" UsedRpM="True" InFadeRate="100" OutFadeRate="100" FadeType="0" DelayType="0"></Item>\n' + ' <Item UID="65508" PatternGUID="" Amplitude="0" Center="0" EffectGUID="" InDelayPoint="0" InFadePoint="100" Offset="0" OutDelayPoint="0" OutFadePoint="100" MaxPhase="0" Phase="' + posZ + '" RpM="0" NumWaves="1" GoOut="0" CutAfter="1" SelectionIndex="0" Direction="0" TogleWinkelLeft="0" TogleWinkelRight="360" VisibleWaves="1" BNC_StartReverse="False" ValueOffset="0" FadeCenter="True" FadeAmplitude="True" FadePhase="True" FadeRpM="False" UsedCenter="True" UsedAmplitude="True" UsedPhase="True" UsedRpM="True" InFadeRate="100" OutFadeRate="100" FadeType="0" DelayType="0"></Item>\n' + ' <Item UID="65512" PatternGUID="" Amplitude="0" Center="0" EffectGUID="" InDelayPoint="0" InFadePoint="100" Offset="0" OutDelayPoint="0" OutFadePoint="100" MaxPhase="0" Phase="' + rotX + '" RpM="0" NumWaves="1" GoOut="0" CutAfter="1" SelectionIndex="0" Direction="0" TogleWinkelLeft="0" TogleWinkelRight="360" VisibleWaves="1" BNC_StartReverse="False" ValueOffset="0" FadeCenter="True" FadeAmplitude="True" FadePhase="True" FadeRpM="False" UsedCenter="True" UsedAmplitude="True" UsedPhase="True" UsedRpM="True" InFadeRate="100" OutFadeRate="100" FadeType="0" DelayType="0"></Item>\n' + ' <Item UID="65516" PatternGUID="" Amplitude="0" Center="0" EffectGUID="" InDelayPoint="0" InFadePoint="100" Offset="0" OutDelayPoint="0" OutFadePoint="100" MaxPhase="0" Phase="' + rotY + '" RpM="0" NumWaves="1" GoOut="0" CutAfter="1" SelectionIndex="0" Direction="0" TogleWinkelLeft="0" TogleWinkelRight="360" VisibleWaves="1" BNC_StartReverse="False" ValueOffset="0" FadeCenter="True" FadeAmplitude="True" FadePhase="True" FadeRpM="False" UsedCenter="True" UsedAmplitude="True" UsedPhase="True" UsedRpM="True" InFadeRate="100" OutFadeRate="100" FadeType="0" DelayType="0"></Item>\n' + ' <Item UID="65520" PatternGUID="" Amplitude="0" Center="0" EffectGUID="" InDelayPoint="0" InFadePoint="100" Offset="0" OutDelayPoint="0" OutFadePoint="100" MaxPhase="0" Phase="' + rotZ + '" RpM="0" NumWaves="1" GoOut="0" CutAfter="1" SelectionIndex="0" Direction="0" TogleWinkelLeft="0" TogleWinkelRight="360" VisibleWaves="1" BNC_StartReverse="False" ValueOffset="0" FadeCenter="True" FadeAmplitude="True" FadePhase="True" FadeRpM="False" UsedCenter="True" UsedAmplitude="True" UsedPhase="True" UsedRpM="True" InFadeRate="100" OutFadeRate="100" FadeType="0" DelayType="0"></Item>\n' + ' </Items>\n' + ' <WayPoints PointData=""></WayPoints>\n' + '</scene>\n') insertString1 = insertString1 + "" insertString2 = insertString2 + "</SceneList>" f = open(path + '/fullsequence.xml', 'w') f.write(string1 + insertString1 + string2 + insertString2 + string3) f.close() gui.MessageDialog("Camera Export Successful")
def convertShader(self, sourceMat, mat): def makeVrayShader(slotName, bmpPath): # With Bitmap found: bmpShader = c4d.BaseShader(1026701) bmpShader[c4d.VRAY_SHADERS_LIST] = 10 # Set as Bitmap Shader bc = bmpShader.GetData() # bc[89981968] = 2 # Sets to sRGB but no - leave as default. bc.SetFilename(4999, bmpPath) bmpShader.SetData(bc) mat.InsertShader(bmpShader) if slotName == "diffuse": mat[c4d.VRAYSTDMATERIAL_DIFFUSECOLOR_TEX] = bmpShader if slotName == "mapRough": mat[c4d.VRAYSTDMATERIAL_REFLECTGLOSSINESS_TEX] = bmpShader if slotName == "bump": mat[c4d.VRAYSTDMATERIAL_BUMP_BUMPMAP] = bmpShader try: mat[c4d.VRAYSTDMATERIAL_BUMP_BUMPMAP_MULT] = 0.2 except: pass if slotName == "mapAlpha": mat[c4d.VRAYSTDMATERIAL_OPACITY_TEX] = bmpShader if slotName == "mapSpec": mat[c4d.VRAYSTDMATERIAL_REFLECTCOLOR] = c4d.Vector( 0.0, 0.0, 0.0) mat[c4d.VRAYSTDMATERIAL_REFLECTGLOSSINESS] = 0.7 mat[c4d.VRAYSTDMATERIAL_REFLECTFRESNELIOR_LOCK] = False mat[c4d.VRAYSTDMATERIAL_REFLECTCOLOR_TEX] = bmpShader try: mat[c4d.VRAYSTDMATERIAL_REFLECTCOLOR_TEX][ 107820085] = True # ALPHA_FROM_INTENSITY except: pass bmpPath = r"" # To all Octane mats... With or without Bitmap: if self.matType == "Octane": mat[c4d.OCT_MATERIAL_TYPE] = 2511 # Glossy mat[c4d.OCT_MATERIAL_DIFFUSE_COLOR] = sourceMat[ c4d.MATERIAL_COLOR_COLOR] mat[c4d.OCT_MATERIAL_ROUGHNESS_FLOAT] = 0.3 if "LENS" in mat.GetName(): mat[c4d.OCT_MATERIAL_OPACITY_FLOAT] = 0.0 if "Moisture" in mat.GetName(): mat[c4d.OCT_MATERIAL_TYPE] = 2513 # Specular mat[c4d.OCT_MATERIAL_ROUGHNESS_FLOAT] = 0.0 if "Cornea" in mat.GetName(): mat[c4d.OCT_MATERIAL_TYPE] = 2513 # Specular mat[c4d.OCT_MATERIAL_INDEX] = 2.8 mat[c4d.OCT_MATERIAL_OPACITY_FLOAT] = 0.2 mat[c4d.OCT_MATERIAL_ROUGHNESS_FLOAT] = 0.0 if "Mouth" in mat.GetName(): mat[c4d.OCT_MATERIAL_INDEX] = 4.8 mat[c4d.OCT_MATERIAL_SPECULAR_COLOR] = c4d.Vector( 0.4, 0.2, 0.1) mat[c4d.OCT_MATERIAL_ROUGHNESS_COLOR] = c4d.Vector( 0.08, 0.06, 0.0) # Check if maps found... diffuseMap = None mapBump = None mapSpec = None mapAlpha = None # DIFFUSE --------------------------- try: diffuseMap = sourceMat[c4d.MATERIAL_COLOR_SHADER][ c4d.BITMAPSHADER_FILENAME] except: diffuseMap = None # BUMP --------------------------- try: mapBump = sourceMat[c4d.MATERIAL_BUMP_SHADER][ c4d.BITMAPSHADER_FILENAME] except: mapBump = None # ALPHA --------------------------- try: mapAlpha = sourceMat[c4d.MATERIAL_ALPHA_SHADER][ c4d.BITMAPSHADER_FILENAME] except: mapAlpha = None # SPEC --------------------------- try: layer = sourceMat.GetReflectionLayerIndex(0) caca = sourceMat[layer.GetDataID() + c4d.REFLECTION_LAYER_TRANS_TEXTURE] if caca: if caca.GetType() == 5833: mapSpec = caca[c4d.BITMAPSHADER_FILENAME] except: mapSpec = None # ---------------------- bmpShader = None if self.matType == "Std": bmpShader = c4d.BaseList2D( c4d.Xbitmap) # create a bitmap shader for the material bmpShader[c4d.BITMAPSHADER_FILENAME] = bmpPath mat.InsertShader(bmpShader) mat[dstSlotID] = bmpShader elif self.matType == "Vray": mat[c4d.VRAYSTDMATERIAL_DIFFUSECOLOR] = sourceMat[ c4d.MATERIAL_COLOR_COLOR] mat[c4d.VRAYSTDMATERIAL_REFRACTCOLOR] = sourceMat[ c4d.MATERIAL_TRANSPARENCY_COLOR] mat[c4d.VRAYSTDMATERIAL_REFRACTIOR] = sourceMat[ c4d.MATERIAL_TRANSPARENCY_REFRACTION] extraMapGlossyRough = dazToC4Dutils().findTextInFile( sourceMat.GetName(), "Glossy_Roughness_Map") # If Bitmap found: if diffuseMap != None: makeVrayShader("diffuse", diffuseMap) if mapBump != None: makeVrayShader("bump", mapBump) if mapSpec != None: makeVrayShader("mapSpec", mapSpec) if mapAlpha != None: makeVrayShader("mapAlpha", mapAlpha) if extraMapGlossyRough != None: makeVrayShader("mapRough", extraMapGlossyRough) # Extra adjust.. specular and stuff.. matName = mat.GetName() if "Cornea" in matName or "Sclera" in matName or "Pupil" in matName: mat[c4d.VRAYSTDMATERIAL_REFLECTCOLOR] = c4d.Vector(1, 1, 1) mat[c4d.VRAYSTDMATERIAL_REFLECTFRESNELIOR_LOCK] = False mat[c4d.VRAYSTDMATERIAL_REFLECTFRESNELIOR] = 1.6 if "Mouth" in matName or "Teeth" in matName: mat[c4d.VRAYSTDMATERIAL_REFLECTCOLOR] = c4d.Vector( 0.8, 0.8, 0.8) mat[c4d.VRAYSTDMATERIAL_REFLECTFRESNELIOR_LOCK] = False mat[c4d.VRAYSTDMATERIAL_REFLECTFRESNELIOR] = 1.6 elif self.matType == "Redshift": bmpShader = mat.CreateShader(dstSlotID, "TextureSampler") bmpShader[c4d.REDSHIFT_SHADER_TEXTURESAMPLER_TEX0, c4d.REDSHIFT_FILE_PATH] = bmpPath.encode("utf-8") elif self.matType == "Octane": bmpShader = c4d.BaseList2D(1029508) if isinstance(bmpPath, str): bmpShader[c4d.IMAGETEXTURE_FILE] = bmpPath bmpShader[c4d.IMAGETEXTURE_MODE] = 0 bmpShader[c4d.IMAGETEXTURE_GAMMA] = 2.2 bmpShader[c4d.IMAGETEX_BORDER_MODE] = 0 if slotName == "diffuse": mat[c4d.OCT_MATERIAL_DIFFUSE_LINK] = bmpShader mat[c4d.OCT_MATERIAL_DIFFUSE_COLOR] = sourceMat[ c4d.MATERIAL_COLOR_COLOR] if slotName == "alpha": mat[c4d.OCT_MATERIAL_OPACITY_LINK] = bmpShader mat[c4d.OCT_MATERIAL_OPACITY_LINK][ c4d.IMAGETEXTURE_GAMMA] = 0.5 if slotName == "glossy": mat[c4d.OCT_MATERIAL_ROUGHNESS_LINK] = bmpShader mat[c4d.OCT_MATERIAL_TYPE] = 2511 # Glossy mat.InsertShader(bmpShader) mat.Message(c4d.MSG_UPDATE) c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK) mat.Message(c4d.MSG_UPDATE) mat.Update(True, True) c4d.EventAdd() elif self.matType == "Corona": bmpShader = c4d.BaseList2D( c4d.Xbitmap) # create a bitmap shader for the material bmpShader[1036473] = bmpPath mat.InsertShader(bmpShader) mat[dstSlotID] = bmpShader return True
def run(self, filepath, uid=None): self.model_dir = os.path.split(filepath)[0] self.is_done = False gltf = glTFImporter(filepath) success, txt = gltf.read() # Images self.import_gltf_textures(gltf) # Materials imported_materials = self.import_gltf_materials(gltf) for index in imported_materials: c4d.documents.GetActiveDocument().InsertMaterial( imported_materials[index]) # c4d.documents.GetActiveDocument().AddUndo(c4d.UNDOTYPE_NEW, imported_materials[index]) # Nodes nodes = {} for nodeidx in range(len(gltf.data.nodes)): nodes[nodeidx] = self.convert_node(gltf, nodeidx, imported_materials) self.progress_callback("Importing nodes", nodeidx + 1, len(gltf.data.nodes)) # Add objects to document and do parenting for node in nodes.keys(): if gltf.data.nodes[int(node)].children: for child in gltf.data.nodes[int(node)].children: c4d.documents.GetActiveDocument().InsertObject( nodes[child], parent=nodes[node]) # c4d.documents.GetActiveDocument().AddUndo(c4d.UNDOTYPE_NEW, nodes[child]) # Add root objects to document for node in gltf.data.scenes[0].nodes: c4d.documents.GetActiveDocument().InsertObject(nodes[node]) # c4d.documents.GetActiveDocument().AddUndo(c4d.UNDOTYPE_NEW, nodes[node]) c4d.documents.GetActiveDocument().SetChanged() c4d.DrawViews() # c4d.documents.GetActiveDocument().EndUndo() self.is_done = True gltf_meta = gltf.data.asset if gltf_meta.extras: title = gltf_meta.extras.get('title', 'Imported') author = gltf_meta.extras.get('author') license = gltf_meta.extras.get('license') note = '' # Rename root node with model title roots = gltf.data.scenes[0].nodes if len(roots) == 1: nodes[roots[0]].SetName(title) if gltf.data.animations is not None and len(gltf.data.animations): note = note + ' - Animation: model has animation but they are not yet supported yet (you may encounter some issues)\n' if self.has_vertex_colors: note = note + " - Vertex colors: some vertex colors have been imported but disabled to avoid unexpected results" note = note + "\nYou can enable them manually in their material Color and Reflection layer named 'Vertex Colors'" if note: note = '\n\nWarnings: \n' + note message = 'Successfuly imported model' if author and license: message = message + ' by {} under license {}'.format( Utils.remove_url(author), Utils.remove_url(license)) message = message + note gui.MessageDialog(text=message, type=c4d.GEMB_OK) self.progress_callback('Done', 1, 1)
def checkIfPosedResetPose(self, checkAndReset=True): def checkIfPosed(): obj = doc.GetFirstObject() scene = ObjectIterator(obj) jointsList = [ "Collar", "head", "ShldrTwist", "Forearm", "pelvis", "abdomen", "Shldr", ] caca = False def checkJoint(jointName): joint = doc.SearchObject(jointName) if joint: rotRX = abs(joint[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_X]) rotRY = abs(joint[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Y]) rotRZ = abs(joint[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Z]) if rotRX == rotRY == rotRZ == 0.0: return False else: return True def compareJoints(jointName): jointR = doc.SearchObject("r" + jointName) jointL = doc.SearchObject("l" + jointName) if jointR: rotRX = abs(jointR[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_X]) rotRY = abs(jointR[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Y]) rotRZ = abs(jointR[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Z]) rotLX = abs(jointL[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_X]) rotLY = abs(jointL[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Y]) rotLZ = abs(jointL[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Z]) rotRX = round(rotRX, 2) rotRY = round(rotRY, 2) rotRZ = round(rotRZ, 2) rotLX = round(rotLX, 2) rotLY = round(rotLY, 2) rotLZ = round(rotLZ, 2) if rotRX == rotLX and rotRY == rotLY and rotRZ == rotLZ: return False else: return True isPosed = False if compareJoints("ForeArm"): isPosed = True if compareJoints("Shldr"): isPosed = True if compareJoints("ShldrBend"): isPosed = True if compareJoints("ForearmBend"): isPosed = True if compareJoints("Hand"): isPosed = True if compareJoints("ThighBend"): isPosed = True if checkJoint("chestUpper"): isPosed = True if checkJoint("chestLower"): isPosed = True if checkJoint("abdomenLower"): isPosed = True if checkJoint("abdomenUpper"): isPosed = True if checkJoint("neckLower"): isPosed = True return isPosed doc = documents.GetActiveDocument() if checkAndReset == False: return checkIfPosed() jointHip = doc.SearchObject("hip") jointRig = ObjectIterator(jointHip) if checkIfPosed(): answer = gui.QuestionDialog( "Reset Pose first before Auto-Ik.\nReset Pose now?\n\nWarning: No Undo" ) if answer: for x in jointRig: x[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_X] = 0.0 x[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Y] = 0.0 x[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Z] = 0.0 jointHip[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_X] = 0.0 jointHip[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Y] = 0.0 jointHip[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Z] = 0.0 try: mainJoint = jointHip.GetUp() mainJoint[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_X] = 0.0 mainJoint[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Y] = 0.0 mainJoint[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Z] = 0.0 mainJoint[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_X] = 0.0 mainJoint[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Z] = 0.0 except: pass self.dazManualRotationFixTpose() c4d.EventAdd() c4d.DrawViews( c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK ) c4d.EventAdd() AllSceneToZero().sceneToZero() answer = gui.QuestionDialog("Would You Like to Run\nAUTO-IK") if answer: return True else: return False else: return True
def endExport(mainDialog, exportData): #mainHelpers.deleteCopiedMeshes(exportData.allMeshObjects) if exportData is not None: if len(exportData.AWDerrorObjects) > 0: newMessage = c4d.plugins.GeLoadString(ids.ERRORMESSAGE) + "\n" for errorMessage in exportData.AWDerrorObjects: newMessage += c4d.plugins.GeLoadString(errorMessage.errorID) if errorMessage.errorData != None: newMessage += "\n\n" + str( c4d.plugins.GeLoadString( ids.ERRORMESSAGEOBJ)) + " = " + str( errorMessage.errorData) c4d.gui.MessageDialog(newMessage) if mainDialog.GetBool(ids.CBOX_CLOSEAFTEREXPORT) == True: exportData = None c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW | c4d.DA_NO_THREAD | c4d.DA_NO_REDUCTION | c4d.DA_STATICBREAK) c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED) c4d.EventAdd(c4d.EVENT_ANIMATE) mainDialog.Close() return True exportData = None c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW | c4d.DA_NO_THREAD | c4d.DA_NO_REDUCTION | c4d.DA_STATICBREAK) c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED) c4d.EventAdd(c4d.EVENT_ANIMATE) return True if len(exportData.AWDwarningObjects) > 0: newMessage = c4d.plugins.GeLoadString(ids.WARNINGMESSAGE) + "\n" for errorMessage in exportData.AWDwarningObjects: newMessage += c4d.plugins.GeLoadString(errorMessage.errorID) if errorMessage.errorData != None: newMessage += "AWDWarningObject: " + str( errorMessage.errorData) print "Warning " + str(newMessage) if mainDialog.GetBool(ids.CBOX_CLOSEAFTEREXPORT) == True: exportData = None c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW | c4d.DA_NO_THREAD | c4d.DA_NO_REDUCTION | c4d.DA_STATICBREAK) c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED) c4d.EventAdd(c4d.EVENT_ANIMATE) mainDialog.Close() return True if mainDialog.GetBool(ids.CBOX_CLOSEAFTEREXPORT ) == True and exportData.cancel != True: exportData = None c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW | c4d.DA_NO_THREAD | c4d.DA_NO_REDUCTION | c4d.DA_STATICBREAK) c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED) c4d.EventAdd(c4d.EVENT_ANIMATE) mainDialog.Close() return True exportData = None c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW | c4d.DA_NO_THREAD | c4d.DA_NO_REDUCTION | c4d.DA_STATICBREAK) c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED) c4d.EventAdd(c4d.EVENT_ANIMATE) maindialogHelpers.enableAll(mainDialog, True) #print c4d.plugins.GeLoadString(ids.SUCCESSMESSAGE) mainHelpers.updateCanvas(mainDialog, exportData) c4d.EventAdd(c4d.EVENT_ANIMATE) mainDialog.SetTimer(0)
def main(): # get active document doc = c4d.documents.GetActiveDocument() # retrieve an instance of render data renderSettings = doc.GetActiveRenderData() # retrieve fps docFps = doc.GetFps() # Get Animation Length fromTime = renderSettings[c4d.RDATA_FRAMEFROM].GetFrame(docFps) toTime = renderSettings[c4d.RDATA_FRAMETO].GetFrame(docFps) animLength = toTime - fromTime + 1 # prompt user for directory filePath = c4d.storage.SaveDialog() filePath, objName = os.path.split(filePath) objName = objName + "_" filePath = filePath + "\\" # Check for confirmation questionDialogText = "Obj Sequence will be saved as:\n\n"\ "" + filePath + objName + "####.obj\n\n"\ "From frame " + str(fromTime) + " to " + str(toTime) + " for " + str(animLength) + " frames.\n" proceedBool = c4d.gui.QuestionDialog(questionDialogText) if proceedBool == True: # Loop through animation and export frames for x in range(0,animLength): # change frame, redraw view moveTime = c4d.BaseTime(fromTime,docFps) + c4d.BaseTime(x,docFps) doc.SetTime(moveTime) c4d.EventAdd(c4d.EVENT_FORCEREDRAW) c4d.DrawViews(c4d.DRAWFLAGS_FORCEFULLREDRAW) # progress bar c4d.StatusSetText("Exporting " + str(x) + " of " + str(animLength)) c4d.StatusSetBar(100.0*x/animLength) # add buffer 0001 bufferedNumber = str(doc.GetTime().GetFrame(docFps)) if len(bufferedNumber)<4: for x in range(len(bufferedNumber),4): bufferedNumber = "0" + bufferedNumber #save file fileName = filePath+objName+bufferedNumber+".obj" print fileName c4d.documents.SaveDocument(doc,fileName,c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST,c4d.FORMAT_OBJEXPORT) else: print "User directed cancel" c4d.StatusClear() # ask to open containing folder viewFilesBool = c4d.gui.QuestionDialog("Do you want to open containing folder?") if viewFilesBool == True: ('explorer "C:\path\of\folder"') subprocess.Popen('explorer ' + '"' + filePath + '"' ) else: return None
def Commit(self): self.op[self.target_id] = self.GetString(self.EDT_SOURCE) c4d.DrawViews()
def dazRotFix(self, master, mode="", jointToFix="", rotValue=0): doc = documents.GetActiveDocument() nullObj = c4d.BaseObject(c4d.Onull) nullObj.SetName("TempNull") doc.InsertObject(nullObj) armJoint = doc.SearchObject("lShldrBend") handJoint = doc.SearchObject("lForearmBend") mg = jointToFix.GetMg() nullObj.SetMg(mg) nullObj[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_X] = 0 nullObj[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Y] = 0 nullObj[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_Z] = 0 c4d.EventAdd() slaveObj = nullObj masterObj = master def addConstraint(slaveObj, masterObj, mode="Parent"): if mode == "Parent": constraintTAG = c4d.BaseTag(1019364) constraintTAG[c4d.EXPRESSION_ENABLE] = True constraintTAG[c4d.ID_CA_CONSTRAINT_TAG_PSR_MAINTAIN] = True constraintTAG[c4d.ID_CA_CONSTRAINT_TAG_PSR] = True constraintTAG[10005] = True constraintTAG[10007] = True constraintTAG[10001] = masterObj PriorityDataInitial = c4d.PriorityData() PriorityDataInitial.SetPriorityValue( c4d.PRIORITYVALUE_MODE, c4d.CYCLE_EXPRESSION ) PriorityDataInitial.SetPriorityValue(c4d.PRIORITYVALUE_PRIORITY, 0) PriorityDataInitial.SetPriorityValue( c4d.PRIORITYVALUE_CAMERADEPENDENT, 0 ) constraintTAG[c4d.EXPRESSION_PRIORITY] = PriorityDataInitial slaveObj.InsertTag(constraintTAG) mg = slaveObj.GetMg() constraintTAG = c4d.BaseTag(1019364) if mode == "ROTATION": constraintTAG[c4d.ID_CA_CONSTRAINT_TAG_PSR] = True constraintTAG[10005] = False constraintTAG[10006] = False constraintTAG[10001] = masterObj if mode == "AIM": constraintTAG[c4d.ID_CA_CONSTRAINT_TAG_AIM] = True constraintTAG[c4d.ID_CA_CONSTRAINT_TAG_AIM_MAINTAIN] = False constraintTAG[c4d.ID_CA_CONSTRAINT_TAG_AIM_CONSTRAIN_X] = True constraintTAG[c4d.ID_CA_CONSTRAINT_TAG_AIM_CONSTRAIN_Y] = False constraintTAG[c4d.ID_CA_CONSTRAINT_TAG_AIM_CONSTRAIN_Z] = False constraintTAG[20004] = 5 # Axis X- constraintTAG[20001] = masterObj slaveObj.InsertTag(constraintTAG) c4d.DrawViews( c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK ) c4d.EventAdd() c4d.DrawViews( c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK ) constraintTAG.Remove() addConstraint(jointToFix, slaveObj) c4d.DrawViews( c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK ) slaveObj[c4d.ID_BASEOBJECT_REL_ROTATION, c4d.VECTOR_X] = rotValue
def genesis_import(self, file_path, dtu, sss_value, normal_value, bump_value): mat = StandardMaterials.StdMaterials() morph = Morphs.Morphs() var = Utilities.Variables() jnt_fixes = DazRig.JointFixes() wgt = Weights() anim = Animations.Animations() pose = Poses() if os.path.exists(file_path) == False: gui.MessageDialog( "Nothing to import.\nYou have to export from DAZ Studio first", c4d.GEMB_OK, ) return 0 print("Import FBX from : {0}".format(os.path.dirname(file_path))) c4d.EventAdd() self.import_daz_fbx(file_path) c4d.EventAdd() c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK) dzc4d.deselect_all() # Deselect All screen = c4d.gui.GeGetScreenDimensions(0, 0, True) c4d.EventAdd() dzc4d.update_viewport() c4d.CallCommand(300001026, 300001026) # Deselect All dzc4d.del_unused_mats() c4d.EventAdd() var.store_dtu(dtu) if var.prepare_variables(): gui.MessageDialog( "Import Failed.\nYou can check the console for more info (Shift + F10)", c4d.GEMB_OK, ) print("Import Failed") return print("Import Done") print("Starting Material Updates") c4d.EventAdd() c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK) c4d.EventAdd() c4d.CallCommand(300001026, 300001026) # Deselect All dzc4d.del_unused_mats() mat.store_materials(dtu) mat.store_sliders(sss_value, normal_value, bump_value) mat.update_materials() print("Material Conversion Done") c4d.EventAdd() wgt.store_subdivision(dtu) if wgt.check_level(): auto_weight = c4d.gui.QuestionDialog( "Subdivisions have been detected\nthis is currently not fully supported.\nWould you like to autoweight the mesh?" ) if auto_weight: wgt.auto_calculate_weights(var.body) pose.store_pose(dtu) pose.store_offset(dtu) is_posed = pose.checkIfPosed() is_anim = anim.check_animation_exists(var.c_joints) clear_pose = False if is_posed: clear_pose = gui.QuestionDialog( "Importing Posed Figure is currently not fully supported\nWould you like to try to fix bone orientation?", ) if clear_pose: pose.clear_pose(var.c_joints) pose.fix_offset(var.c_joints, var.c_skin_data) if is_anim == False or clear_pose: jnt_fixes.store_joint_orientations(dtu) jnt_fixes.fix_joints(var.c_skin_data, var.c_joints, var.c_meshes) c4d.EventAdd() dzc4d.deselect_all() if is_posed: pose.restore_pose(var.c_joints) make_tpose = gui.QuestionDialog( "Would you like to Convert\nthe Base Pose to a T-Pose?", ) if make_tpose: pose.preAutoIK() c4d.EventAdd() else: gui.MessageDialog( "Animation or a Pose was Detected\nJoint Orientation has not been fixed", type=c4d.GEMB_ICONEXCLAMATION, ) c4d.EventAdd() if var.body.GetTag(c4d.Tposemorph): print("Starting Morph Updates") morph.store_morph_links(dtu) morph.store_variables(var.body, var.c_meshes, var.c_joints, var.skeleton, var.c_poses) morph.morphs_to_delta() morph.delete_morphs(var.c_meshes) morph.connect_morphs_to_parents(var.body, var.c_meshes) morph.add_drivers() morph.rename_morphs(var.c_meshes) print("Morph Corrections Done") c4d.EventAdd() c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD | c4d.DRAWFLAGS_STATICBREAK) c4d.EventAdd() self.dialog = guiASKtoSave() self.dialog.Open( dlgtype=c4d.DLG_TYPE_MODAL, xpos=screen["sx2"] // 2 - 210, ypos=screen["sy2"] // 2 - 100, defaultw=200, defaulth=150, )
def Timer(self, msg): #print "Execute Timer" global exchangeData, workerThread if self.curTabGroup == ids.TABGRP_LIVESTREAM: if exchangeData.isRecording == True: self.SetString(ids.TXT_FRAMES2, len(exchangeData.recordetFrames)) self.SetString(ids.TXT_SEC, str(exchangeData.doneRecTime / 1000) + " s") if self.playbackC4d == True: timea = float( float(exchangeData.startRecTimeC4D) + float(exchangeData.doneRecTime)) / 1000 #print "hier = "+str(timea) c4d.documents.GetActiveDocument().SetTime( c4d.BaseTime(timea)) c4d.EventAdd(c4d.EVENT_ANIMATE) #c4d.bitmaps.ShowBitmap(self.renderer.bmp) if workerThread.IsRunning(): if exchangeData.connected == 1: exchangeData.connected = 2 self.Enable(ids.GRP_FACESHIFT, True) self.Enable(ids.GRP_RECORDING, True) self.Enable(ids.BTN_STARTREC, True) self.Enable(ids.CBOX_PLAYBACK, True) #c4d.bitmaps.ShowBitmap(self.renderer.bmp) #print "worker runs = "+str(exchangeData.frameSuccess)+ " / "+str(exchangeData.frameTime) if self.enabledUserData == True: if exchangeData.isNew == True: exchangeData.isNew = False if exchangeData.frameSuccess == 1: if self.targetLink is not None: self.targetLink.SetRelRot( exchangeData.rotationVector) self.targetLink.SetRelPos( exchangeData.positionVector) shapeCnt = 0 while shapeCnt < len(self.blendShapeTargets): if len(exchangeData.blendShapes ) > shapeCnt: self.targetLink[self.blendShapeTargets[ shapeCnt]] = exchangeData.blendShapes[ shapeCnt] shapeCnt += 1 eyeCnt = 0 while eyeCnt < len(self.eyeGazeTargets): if len(exchangeData.eyeGazeValues ) > eyeCnt: self.targetLink[self.eyeGazeTargets[ eyeCnt]] = exchangeData.eyeGazeValues[ eyeCnt] eyeCnt += 1 #print self.targetLink.GetFirstTag().GetNodeMaster() #c4d.GeSyncMessage(c4d.EVMSG_ASYNCEDITORMOVE) #c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED) #c4d.documents.GetActiveDocument().SetTime(c4d.BaseTime(0)) c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW | c4d.DA_NO_THREAD | c4d.DA_NO_REDUCTION | c4d.DA_STATICBREAK) #c4d.EventAdd(c4d.EVENT_FORCEREDRAW) if not workerThread.IsRunning(): print "not RUnning" exchangeData.connected = False self.Enable(ids.GRP_FACESHIFT, False) if len(exchangeData.recordetFrames) == 0: self.Enable(ids.GRP_RECORDING, False) if len(exchangeData.recordetFrames) > 0: self.Enable(ids.BTN_STARTREC, False) self.Enable(ids.CBOX_PLAYBACK, False) self.SetString(ids.BTN_CONNECT, "Connect") #self.userarea.draw([]) self.SetTimer(0) if self.curTabGroup == ids.TABGRP_EXPRESSIONMAPPING: pass