def CoreMessage(self, msg, result): #if msg==c4d.EVMSG_BROWSERCHANGE: #print "JA" mainHelpers.updateCanvas(self, exportData) #update the status-canvas doc = c4d.documents.GetActiveDocument() if doc: isDirty = False if self.GetLong(ids.COMBO_RANGE) == 0: if self.firstFrame != doc.GetMinTime().GetFrame(doc.GetFps()): isDirty = True if self.lastFrame != doc.GetMaxTime().GetFrame(doc.GetFps()): isDirty = True if self.GetLong(ids.COMBO_RANGE) == 1: if self.firstFrame != doc.GetLoopMinTime().GetFrame( doc.GetFps()): isDirty = True if self.lastFrame != doc.GetLoopMaxTime().GetFrame( doc.GetFps()): isDirty = True if self.docName != doc.GetDocumentPath(): self.docName = doc.GetDocumentPath() isDirty = True if isDirty == True: maindialogHelpers.setUI(self) 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 CreateLayout(self): #icon2 = c4d.bitmaps.BaseBitmap() #icon2.InitWith(os.path.join(os.path.dirname(__file__), "res", "pic.jpg")) #bc = c4d.BaseContainer() #bc.SetLong(c4d.BITMAPBUTTON_ICONID1, 1390382) #bc.SetBool(c4d.BITMAPBUTTON_BUTTON, True) #self.myBitButton = self.AddCustomGui(1390382, c4d.CUSTOMGUI_BITMAPBUTTON, "Bend", c4d.BFH_CENTER | c4d.BFV_CENTER, 32, 32, bc) #self.myBitButton = c4d.gui.BitmapButtonCustomGui maindialogCreator.createLayout(self) #dialogLoadet=self.LoadDialogResource(ids.MAINDIALOG, None, flags= c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT ) mainHelpers.updateCanvas(self,exportData) maindialogHelpers.InitValues(self) return True
def CreateLayout(self): #icon2 = c4d.bitmaps.BaseBitmap() #icon2.InitWith(os.path.join(os.path.dirname(__file__), "res", "pic.jpg")) #bc = c4d.BaseContainer() #bc.SetLong(c4d.BITMAPBUTTON_ICONID1, 1390382) #bc.SetBool(c4d.BITMAPBUTTON_BUTTON, True) #self.myBitButton = self.AddCustomGui(1390382, c4d.CUSTOMGUI_BITMAPBUTTON, "Bend", c4d.BFH_CENTER | c4d.BFV_CENTER, 32, 32, bc) #self.myBitButton = c4d.gui.BitmapButtonCustomGui maindialogCreator.createLayout(self) #dialogLoadet=self.LoadDialogResource(ids.MAINDIALOG, None, flags= c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT ) mainHelpers.updateCanvas(self, exportData) maindialogHelpers.InitValues(self) return True
def Timer(self, msg): global exportData # we need this to be global, so we can destroy it if needed if self.workerAction is None: self.SetTimer(0) if self.workerAction == "exporting": if workerThread is None: #this should never happen, but if it happens, exportData = None # we destroy the exportData-Object. mainHelpers.updateCanvas( self, exportData) # update the status-canvas print "unexpected Error: Workerthread not found by mainDialog.Timer function" # and print out a error if workerThread is not None: if workerThread.IsRunning( ): # while the background-thread is working, mainHelpers.updateCanvas( self, exportData) # we update the status-canvas if not workerThread.IsRunning( ): # if the background-thread is not working mainExporter.endExport( self, exportData ) # we call the function to end the export-processing exportData = None # destroy the exportData-object mainHelpers.updateCanvas( self, exportData) # and update the status-canvas if self.workerAction == "meshChecking": pass #print "worker2"
def CoreMessage(self, msg, result): #if msg==c4d.EVMSG_BROWSERCHANGE: #print "JA" mainHelpers.updateCanvas(self,exportData)#update the status-canvas doc=c4d.documents.GetActiveDocument() if doc: isDirty=False if self.GetLong(ids.COMBO_RANGE)==0: if self.firstFrame != doc.GetMinTime().GetFrame(doc.GetFps()): isDirty=True if self.lastFrame != doc.GetMaxTime().GetFrame(doc.GetFps()): isDirty=True if self.GetLong(ids.COMBO_RANGE)==1: if self.firstFrame != doc.GetLoopMinTime().GetFrame(doc.GetFps()): isDirty=True if self.lastFrame != doc.GetLoopMaxTime().GetFrame(doc.GetFps()): isDirty=True if self.docName!=doc.GetDocumentPath(): self.docName=doc.GetDocumentPath() isDirty=True if isDirty==True: maindialogHelpers.setUI(self) return True
def Timer(self, msg): global exportData # we need this to be global, so we can destroy it if needed if self.workerAction is None: self.SetTimer(0) if self.workerAction == "exporting": if workerThread is None: #this should never happen, but if it happens, exportData=None # we destroy the exportData-Object. mainHelpers.updateCanvas(self,exportData) # update the status-canvas print "unexpected Error: Workerthread not found by mainDialog.Timer function" # and print out a error if workerThread is not None: if workerThread.IsRunning(): # while the background-thread is working, mainHelpers.updateCanvas(self,exportData) # we update the status-canvas if not workerThread.IsRunning(): # if the background-thread is not working mainExporter.endExport(self,exportData) # we call the function to end the export-processing exportData=None # destroy the exportData-object mainHelpers.updateCanvas(self,exportData) # and update the status-canvas if self.workerAction == "meshChecking": pass#print "worker2"
def startExport(mainDialog,doc): exportData=classMainScene.mainScene(doc,mainDialog) # create a new "mainScene". this class will store all the data collected for export #exportData.doc.SetMode(11)#set EditMode to 11 (Model-Mode) - otherwise the triangulate method will only affect the selected polygons! objectsToExport=exportData.doc.GetObjects() # get a list of all objects in the scene if len(objectsToExport)==0: # if no object is in the scene: if exportData.unusedMats==False: # if no unsued materials should be exported: newError=classesHelper.AWDerrorObject(ids.ERRORMESSAGE2,None) # create a new errorObject exportData.AWDerrorObjects.append(newError) # append the new errorObject to the errorlist, so it will be displayed at the end of export process return exportData # return from function if exportData.unusedMats==True: # if unused materials should be exported: exportData.allc4dMaterials=doc.GetMaterials() # get a list of all materials if len(exportData.allc4dMaterials)==0: # if no material was found: newError=classesHelper.AWDerrorObject(ids.ERRORMESSAGE2,None) # create a new errorObject exportData.AWDerrorObjects.append(newError) # append the new errorObject to the errorlist, so it will be displayed at the end of export process return exportData # return from function exportData.objList=objectsToExport exportData.allStatusLength=2 # used to calculate the progress-bar exportData.allStatus=1 # used to calculate the progress-bar exportData.status=1 datei=c4d.storage.SaveDialog(c4d.FILESELECTTYPE_ANYTHING, "save as *.AWD", "awd") if datei is None: newError=classesHelper.AWDerrorObject(ids.ERRORMESSAGE2,None) # create a new errorObject exportData.AWDerrorObjects.append(newError) # append the new errorObject to the errorlist, so it will be displayed at the end of export process return None maindialogHelpers.enableAll(mainDialog,False) # disable the all GUI-elements, so the user can not change anything while exporting exportData.datei=datei # if this is executed, we know there is something to export! # create the MetaDataBlock newAWDWrapperBlock=classesAWDBlocks.WrapperBlock(None,"",255) exportData.idCounter+=1 newMetaDataBlock=classesAWDBlocks.MetaDataBlock(0,0) newMetaDataBlock.timestamp=0# to do newMetaDataBlock.encoder="AWDToolsC4D" newMetaDataBlock.encoderVersion="0.9" newMetaDataBlock.app="Cinema4D" newMetaDataBlock.appVersion="R13 / R14" # to do newAWDWrapperBlock.data=newMetaDataBlock newAWDWrapperBlock.tagForExport=True exportData.allAWDBlocks.append(newAWDWrapperBlock) # create a AWD-Material-Block for the C4D-Default-Color, in case some Objects have no Materials/ObjectColors Applied newAWDWrapperBlock=classesAWDBlocks.WrapperBlock(None,"C4D-DefaultMaterial",81) defaultColor=exportData.doc[c4d.DOCUMENT_DEFAULTMATERIAL_COLOR] newAWDBlock=classesAWDBlocks.StandartMaterialBlock(exportData.idCounter,0,True) newAWDBlock.saveLookUpName="C4D-DefaultMat" exportData.allMatBlocks.append(newAWDBlock) defaultColorString="#"+str(defaultColor) exportData.colorMaterials[defaultColorString]=newAWDBlock newAWDBlock.matColor=[defaultColor.z*255,defaultColor.y*255,defaultColor.x*255,0] newAWDBlock.saveMatProps.append(1) newAWDBlock.isCreated=True newAWDWrapperBlock.data=newAWDBlock newAWDWrapperBlock.tagForExport=False exportData.allAWDBlocks.append(newAWDWrapperBlock) exportData.idCounter+=1 # create a AWD-Material-Block for all the C4D-Materials in the scene, regardless if they will be exported or not. for mat in exportData.allc4dMaterials: newAWDWrapperBlock=classesAWDBlocks.WrapperBlock(mat,mat.GetName(),81) newAWDBlock=classesAWDBlocks.StandartMaterialBlock(exportData.idCounter,0,False) newAWDBlock.saveLookUpName=mat.GetName() newAWDBlock.name=mat.GetName() newAWDBlock.mat=mat mat.SetName(str(exportData.idCounter)) exportData.idCounter+=1 newAWDWrapperBlock.data=newAWDBlock newAWDWrapperBlock.tagForExport=False exportData.allAWDBlocks.append(newAWDWrapperBlock) exportData.allMatBlocks.append(newAWDBlock) # create a AWD-Block for all Objects in the Scene (and their tags) regardless if they will be exported or not mainParseObjectToAWDBlock.createAllAWDBlocks(exportData,objectsToExport) # create a SceneBlock for all Objects that should be exported mainParseObjectToAWDBlock.createAllSceneBlocks(exportData,objectsToExport,exportData.defaultObjectSettings) exportData.allStatusLength=2+(10*int(exportData.animationCounter))+(10*len(exportData.allMeshObjects))# used to calculate the progress-bar exportData.allStatus=1 # used to calculate the progress-bar exportData.status=1 # used to calculate the progress-bar mainHelpers.updateCanvas(mainDialog,exportData) # update the progress-bar mainSkeletonReader.createSkeletonBlocks(exportData.objList,exportData,mainDialog) if mainDialog.GetBool(ids.CBOX_VANIMATION)==True: mainVertexAnimationReader.getVertexAnimationData(exportData.objList,exportData,mainDialog) exportData.status=2 mainHelpers.updateCanvas(mainDialog,exportData) return exportData
def startExport(mainDialog, doc): exportData = classMainScene.mainScene( doc, mainDialog ) # create a new "mainScene". this class will store all the data collected for export # not needed anymor ? #exportData.doc.SetMode(11)#set EditMode to 11 (Model-Mode) - otherwise the triangulate method will only affect the selected polygons! objectsToExport = exportData.doc.GetObjects( ) # get a list of all objects in the scene # check if there is anything to export if len(objectsToExport) == 0: # if no object is in the scene: if exportData.unusedMats == False: # if no unsued materials should be exported: newError = classesHelper.AWDerrorObject( ids.ERRORMESSAGE2, None) # create a new errorObject exportData.AWDerrorObjects.append( newError ) # append the new errorObject to the errorlist, so it will be displayed at the end of export process return exportData # return from function if exportData.unusedMats == True: # if unused materials should be exported: exportData.allc4dMaterials = doc.GetMaterials( ) # get a list of all materials if len(exportData.allc4dMaterials ) == 0: # if no material was found: newError = classesHelper.AWDerrorObject( ids.ERRORMESSAGE2, None) # create a new errorObject exportData.AWDerrorObjects.append( newError ) # append the new errorObject to the errorlist, so it will be displayed at the end of export process return exportData # return from function exportData.objList = objectsToExport # calculate progressbar exportData.allStatusLength = 2 # used to calculate the progress-bar exportData.allStatus = 1 # used to calculate the progress-bar exportData.status = 1 # open save as dialog datei = c4d.storage.SaveDialog(c4d.FILESELECTTYPE_ANYTHING, "save as *.AWD", "awd") if datei is None: newError = classesHelper.AWDerrorObject( ids.ERRORMESSAGE2, None) # create a new errorObject exportData.AWDerrorObjects.append( newError ) # append the new errorObject to the errorlist, so it will be displayed at the end of export process return None # disable the all GUI-elements, so the user can not change anything while exporting maindialogHelpers.enableAll(mainDialog, False) exportData.datei = datei # if this is executed, we know there is something to export! # create the MetaDataBlock newAWDWrapperBlock = classesAWDBlocks.WrapperBlock(None, "", 255) exportData.idCounter += 1 newMetaDataBlock = classesAWDBlocks.MetaDataBlock(0, 0) newMetaDataBlock.timestamp = 0 # to do newMetaDataBlock.encoder = "AWDToolsC4D" newMetaDataBlock.encoderVersion = "0.9" newMetaDataBlock.app = "Cinema4D" newMetaDataBlock.appVersion = "R13 / R14" # to do newAWDWrapperBlock.data = newMetaDataBlock newAWDWrapperBlock.tagForExport = True exportData.allAWDBlocks.append(newAWDWrapperBlock) # create a AWD-Material-Block for the C4D-Default-Color, in case some Objects have no Materials/ObjectColors Applied newAWDWrapperBlock = classesAWDBlocks.WrapperBlock(None, "C4D-DefaultMaterial", 81) defaultColor = exportData.doc[c4d.DOCUMENT_DEFAULTMATERIAL_COLOR] newAWDBlock = classesAWDBlocks.StandartMaterialBlock( exportData.idCounter, 0, True) newAWDBlock.saveLookUpName = "C4D-DefaultMat" exportData.allMatBlocks.append(newAWDBlock) defaultColorString = "#" + str(defaultColor) exportData.colorMaterials[defaultColorString] = newAWDBlock newAWDBlock.matColor = [ defaultColor.z * 255, defaultColor.y * 255, defaultColor.x * 255, 0 ] newAWDBlock.saveMatProps.append(1) newAWDBlock.isCreated = True newAWDWrapperBlock.data = newAWDBlock newAWDWrapperBlock.tagForExport = False exportData.allAWDBlocks.append(newAWDWrapperBlock) exportData.idCounter += 1 # create a AWD-Material-Block for all the C4D-Materials in the scene, regardless if they will be exported or not. for mat in exportData.allc4dMaterials: newAWDWrapperBlock = classesAWDBlocks.WrapperBlock( mat, mat.GetName(), 81) newAWDBlock = classesAWDBlocks.StandartMaterialBlock( exportData.idCounter, 0, False) newAWDBlock.saveLookUpName = mat.GetName() newAWDBlock.name = mat.GetName() newAWDBlock.mat = mat mat.SetName(str(exportData.idCounter)) exportData.idCounter += 1 newAWDWrapperBlock.data = newAWDBlock newAWDWrapperBlock.tagForExport = False exportData.allAWDBlocks.append(newAWDWrapperBlock) exportData.allMatBlocks.append(newAWDBlock) # create a AWD-Block for all Objects in the Scene (and their tags) regardless if they will be exported or not mainParseObjectToAWDBlock.createAllAWDBlocks(exportData, objectsToExport) # create a SceneBlock for all Objects that should be exported mainParseObjectToAWDBlock.createAllSceneBlocks( exportData, objectsToExport, exportData.defaultObjectSettings) exportData.allStatusLength = 2 + (10 * int(exportData.animationCounter)) + ( 10 * len(exportData.allMeshObjects) ) # used to calculate the progress-bar exportData.allStatus = 1 # used to calculate the progress-bar exportData.status = 1 # used to calculate the progress-bar mainHelpers.updateCanvas(mainDialog, exportData) # update the progress-bar mainSkeletonReader.createSkeletonBlocks(exportData.objList, exportData, mainDialog) if mainDialog.GetBool(ids.CBOX_VANIMATION) == True: mainVertexAnimationReader.getVertexAnimationData( exportData.objList, exportData, mainDialog) exportData.status = 2 mainHelpers.updateCanvas(mainDialog, exportData) return exportData
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 Command(self, id, msg): global workerThread,exportData mainHelpers.updateCanvas(self,exportData) if id == ids.BTN_RECORDVERTEXANIMATION: # Save with assets was hit: doc=c4d.documents.GetActiveDocument() mainHelpers.bakeVertexAnimation(doc) if id == ids.BTN_CHECKSKELETON: # check Skeleton was hit: op=mainHelpers.checkforValidSelectedSkeleton() if op is not None: doc=c4d.documents.GetActiveDocument() doc.StartUndo() # Start undo support doc.AddUndo(c4d.UNDOTYPE_CHANGE, op) # Support redo the insert operation checkSkeleton=mainSkeletonHelper.SkeletonHelper(op) # we create a SkeletonHelper-Object to check if the selected object is a valid skeleton doc.EndUndo() # Do not forget to close the undo support return True c4d.gui.MessageDialog("To use this function, you need to select one Object that has Child-Objects\n,or one SkeletonTag,or one SkeletonAnimationTag") if id == ids.BTN_CREATESKELETONANIMATION: # check Skeleton was hit: op=mainHelpers.checkforValidSelectedSkeleton() if op is not None: mainHelpers.copySkeletonAndApplySkeletonAnimation(op) # we create a SkeletonHelper-Object to check if the selected object is a valid skeleton return True c4d.gui.MessageDialog("To use this function, you need to select one SkeletonTag, or one Object that has a SkeletonTag applied!") if id == ids.BTN_SAVEWITHASSETS: # Save with assets was hit: c4d.CallCommand(12255) # we just call the command "Save C4D-Scene with Assets" if id == ids.BTN_CANCEL: # cancel Button was hit: cancel export process: print "User cancelled the export-process" self.SetTimer(0) self.workerAction=None if workerThread is not None: if workerThread.IsRunning()==True: workerThread.End() exportData=None mainHelpers.updateCanvas(self,exportData) maindialogHelpers.enableAll(self,True) return True if id == ids.BTN_EXPORT: # export button was hit: start export process: #check if a valid C4D scene is active, if not we return with error-message doc=c4d.documents.GetActiveDocument() self.workerAction="exporting" if doc==None: newMessage=c4d.plugins.GeLoadString(ids.STATUSMESSAGE1) c4d.gui.MessageDialog(newMessage) return True if doc.GetDocumentPath()==None or doc.GetDocumentPath()=="": newMessage=c4d.plugins.GeLoadString(ids.STATUSMESSAGE1) c4d.gui.MessageDialog(newMessage) return True exportData=mainExporter.startExport(self,doc) # start the export-process thats done in the c4d-main-Thread if exportData is not None: # if the exportData object is still alive, no error has occured mainHelpers.printErrors(self,exportData) # if any errors occured, print them out and delete the "exportData"-object workerThread = WorkerThread() # recreated the workerThread (open a new c4d-thread for the heavy mesh-processing) workerThread.Start() # start the workerThread self.SetTimer(20) # start the timer-function to monitor the workerThread if exportData is None: # if the export data is not alive, a error has occured self.SetTimer(0) # stop the timer-function if id == ids.CBOX_ANIMATION: self.animationBool=self.GetBool(ids.CBOX_ANIMATION) maindialogHelpers.setUI(self) if id == ids.CBOX_VANIMATION: self.vanimationBool=self.GetBool(ids.CBOX_VANIMATION) maindialogHelpers.setUI(self) if id == ids.CBOX_CLOSEAFTEREXPORT: self.closeAfter=self.GetBool(ids.CBOX_CLOSEAFTEREXPORT) if id == ids.CBOX_UNUSEDMATS: self.unusedMats=self.GetBool(ids.CBOX_UNUSEDMATS) if id == ids.CBOX_STREAMING: self.streaming=self.GetBool(ids.CBOX_STREAMING) if self.streaming==True: self.SetBool(ids.CBOX_COMPRESSED,False) self.compressData=False maindialogHelpers.setUI(self) if id == ids.CBOX_COMPRESSED: self.compressData=self.GetBool(ids.CBOX_COMPRESSED) if self.compressData==True: self.SetBool(ids.CBOX_STREAMING,False) self.streaming=False maindialogHelpers.setUI(self) if id == ids.CBOX_DEBUG: self.debug=self.GetBool(ids.CBOX_DEBUG) if id == ids.CBOX_OPENPREFAB: self.openInPreFab=self.GetBool(ids.CBOX_OPENPREFAB) if id == ids.COMBO_RANGE: self.animationRange=self.GetLong(ids.COMBO_RANGE) maindialogHelpers.setUI(self) if id == ids.COMBO_TEXTURESMODE: maindialogHelpers.setValues(self) maindialogHelpers.setUI(self) if id == ids.MENU_ABOUT_ABOUT: pass#dlg = AboutDialog() #DLG_TYPE_MODAL = > synchronous dialog #DLG_TYPE_ASYNC = > asynchronous dialogs #dlg.Open(dlgtype=c4d.DLG_TYPE_MODAL, defaultw=300, defaulth=300) if id == ids.MENU_ABOUT_HELP: realPath= os.path.abspath(os.path.join(os.path.dirname(__file__),"..")) helpPath=os.path.join(realPath, "res", "Help","index.html") c4d.storage.GeExecuteFile(helpPath) print helpPath #pass#dlg = HelpDialog() #DLG_TYPE_MODAL = > synchronous dialog #DLG_TYPE_ASYNC = > asynchronous dialogs #dlg.Open(dlgtype=c4d.DLG_TYPE_ASYNC, defaultw=400, defaulth=400) if id == ids.MENU_CHECKFORUPDATE: realPath= os.path.abspath(os.path.join(os.path.dirname(__file__),"..")) helpPath=os.path.join(realPath, "res", "awayextensionsc4dversion.xml") versionThis=maindialogHelpers.loadVersionFile(helpPath) versionWeb=maindialogHelpers.loadVersionFilefromNet() if versionThis=="" or versionWeb=="": return if versionThis!=versionWeb: message="Your Version is not up to date\n" message+="Go to \nhttps://github.com/awaytools/AwayExtensions-C4D\n and get the new version\n\n" message+="Your version = "+str(versionThis)+"\n" message+="Latest version = "+str(versionWeb)+"\n" if versionThis==versionWeb: message="Your Version is up to date\n" c4d.gui.MessageDialog(message) maindialogHelpers.setValues(self) return True
def buildVertexAnimation(exportData,curObj,mainDialog,vertexAnimationTag): globalMinFrame=mainDialog.GetReal(ids.REAL_FIRSTFRAME) # get the first frame for the global animation range globalMaxFrame=mainDialog.GetReal(ids.REAL_LASTFRAME) # get the last frame for the global animation range minFrame=globalMinFrame # set the minFrame to the global minFrame maxFrame=globalMaxFrame # set the maxFrame to the global maxFrame animationRange=vertexAnimationTag[1015] # get the range mode of the current Animation if animationRange!=1021: # if it is not set to "Global" we update the minframe/maxFrame using the skeletonAnmiationTags input values minFrame=vertexAnimationTag[1018] maxFrame=vertexAnimationTag[1020] #print "Start Exporting Animation Range = "+str(minFrame)+" - "+str(maxFrame) keyFrameStyle=vertexAnimationTag[1054] curFrame=minFrame # set the first frame to be the current frame frameDurations=[] # list to store all frame-durations framePositions=[] lastFramesDuration=0 keyTime=minFrame*(float(1000/exportData.doc.GetFps())/1000) if keyFrameStyle==1055 or keyFrameStyle==1058: if keyFrameStyle==1055: # all Frames keyLength=maxFrame-minFrame durationTime=(float(1000/exportData.doc.GetFps())/1000) if keyFrameStyle==1058: # keyframe Number allKeysLength=maxFrame-minFrame keyLength=vertexAnimationTag[1061] difKey=allKeysLength-keyLength keyLength2=float(difKey/(keyLength-1)) durationTime=(float(1000/exportData.doc.GetFps())/1000) durationTime+=float((float(1000/exportData.doc.GetFps())/1000)*(keyLength2)) keyCounter=0 while keyCounter<keyLength: if keyCounter==(keyLength-1): durationTime=lastFramesDuration frameDurations.append(durationTime) keyTime+=durationTime newTime=c4d.BaseTime(keyTime) #if keyFrameStyle==1055: # all Frames # newTime.Quantize(exportData.doc.GetFps()) framePositions.append(getMeshPosePosition(exportData,curObj,newTime,vertexAnimationTag[1051])) keyCounter+=1 if keyFrameStyle==1056 or keyFrameStyle==1057: if keyFrameStyle==1056: cloneObj= curObj.GetClone() firstTrack=cloneObj.GetFirstCTrack() firstCurve=firstTrack.GetCurve() tracks=curObj.GetCTracks() keysDic={} keysList=[] keysList2=[] for track in tracks: curve=track.GetCurve() keyCounter=0 while keyCounter<curve.GetKeyCount(): key=curve.GetKey(keyCounter) keyTime=key.GetTime() isKey=firstCurve.FindKey(keyTime) if isKey is None: firstCurve.AddKey(keyTime) keyCounter+=1 if keyFrameStyle==1057: tracks=curObj.GetTag(1030484).GetCTracks() if tracks is not None: for track in tracks: testerString="(1052, 130, 1030484)" if testerString==str(track.GetDescriptionID()): firstCurve=track.GetCurve() if firstCurve is None: pass if firstCurve is not None: keyCounter=0 frametimes=[] startOffset=0 firstKeyTime=None while keyCounter<firstCurve.GetKeyCount(): key=firstCurve.GetKey(keyCounter) keyTimeInFrame=key.GetTime().GetFrame(exportData.doc.GetFps()) if float(keyTimeInFrame)>=float(minFrame) and float(keyTimeInFrame)<=float(maxFrame): if firstKeyTime is None: firstKeyTime=key.GetTime().Get() if firstKeyTime!=startOffset: startOffset=firstKeyTime frametimes.append(c4d.BaseTime(key.GetTime().Get()-firstKeyTime)) keyCounter+=1 if len(frametimes)==0: frametimes.append(c4d.BaseTime(0)) endOffset=float((float(1000/exportData.doc.GetFps())/1000)*(maxFrame))-(frametimes[len(frametimes)-1].Get()+startOffset) keyCounter=0 #print keyCount firstKeyTime=None keyCount=len(frametimes) for keyBaseTime in frametimes: keyTime=keyBaseTime.Get() exportData.allStatus+=float(10/float(keyCount)) mainHelpers.updateCanvas(mainDialog,exportData) if (keyCounter+1)<keyCount: frameDurations.append(float(frametimes[keyCounter+1].Get())-float(keyTime)) if (keyCounter+1)>=keyCount: endDuration=startOffset+endOffset if endDuration<=0: endDuration=0 frameDurations.append(endDuration) framePositions.append(getMeshPosePosition(exportData,curObj,c4d.BaseTime(keyTime+startOffset),vertexAnimationTag[1051])) keyCounter+=1 if len(frameDurations)==1: newAnimBlock=buildMeshPoseBlock(exportData,curObj,frameDurations,framePositions,vertexAnimationTag) if len(frameDurations)>1: newAnimBlock=buildMeshPoseAnimationBlock(exportData,curObj,frameDurations,framePositions,vertexAnimationTag) return newAnimBlock
def Command(self, id, msg): global workerThread, exportData mainHelpers.updateCanvas(self, exportData) if id == ids.BTN_RECORDVERTEXANIMATION: # Save with assets was hit: doc = c4d.documents.GetActiveDocument() mainHelpers.bakeVertexAnimation(doc) if id == ids.BTN_CHECKSKELETON: # check Skeleton was hit: op = mainHelpers.checkforValidSelectedSkeleton() if op is not None: doc = c4d.documents.GetActiveDocument() doc.StartUndo() # Start undo support doc.AddUndo(c4d.UNDOTYPE_CHANGE, op) # Support redo the insert operation checkSkeleton = mainSkeletonHelper.SkeletonHelper( op ) # we create a SkeletonHelper-Object to check if the selected object is a valid skeleton doc.EndUndo() # Do not forget to close the undo support return True c4d.gui.MessageDialog( "To use this function, you need to select one Object that has Child-Objects\n,or one SkeletonTag,or one SkeletonAnimationTag" ) if id == ids.BTN_CREATESKELETONANIMATION: # check Skeleton was hit: op = mainHelpers.checkforValidSelectedSkeleton() if op is not None: mainHelpers.copySkeletonAndApplySkeletonAnimation( op ) # we create a SkeletonHelper-Object to check if the selected object is a valid skeleton return True c4d.gui.MessageDialog( "To use this function, you need to select one SkeletonTag, or one Object that has a SkeletonTag applied!" ) if id == ids.BTN_SAVEWITHASSETS: # Save with assets was hit: c4d.CallCommand( 12255) # we just call the command "Save C4D-Scene with Assets" if id == ids.BTN_CANCEL: # cancel Button was hit: cancel export process: print "User cancelled the export-process" self.SetTimer(0) self.workerAction = None if workerThread is not None: if workerThread.IsRunning() == True: workerThread.End() exportData = None mainHelpers.updateCanvas(self, exportData) maindialogHelpers.enableAll(self, True) return True if id == ids.BTN_EXPORT: # export button was hit: start export process: #check if a valid C4D scene is active, if not we return with error-message doc = c4d.documents.GetActiveDocument() self.workerAction = "exporting" if doc == None: newMessage = c4d.plugins.GeLoadString(ids.STATUSMESSAGE1) c4d.gui.MessageDialog(newMessage) return True if doc.GetDocumentPath() == None or doc.GetDocumentPath() == "": newMessage = c4d.plugins.GeLoadString(ids.STATUSMESSAGE1) c4d.gui.MessageDialog(newMessage) return True exportData = mainExporter.startExport( self, doc ) # start the export-process thats done in the c4d-main-Thread if exportData is not None: # if the exportData object is still alive, no error has occured mainHelpers.printErrors( self, exportData ) # if any errors occured, print them out and delete the "exportData"-object workerThread = WorkerThread( ) # recreated the workerThread (open a new c4d-thread for the heavy mesh-processing) workerThread.Start() # start the workerThread self.SetTimer( 20) # start the timer-function to monitor the workerThread if exportData is None: # if the export data is not alive, a error has occured self.SetTimer(0) # stop the timer-function if id == ids.CBOX_ANIMATION: self.animationBool = self.GetBool(ids.CBOX_ANIMATION) maindialogHelpers.setUI(self) if id == ids.CBOX_VANIMATION: self.vanimationBool = self.GetBool(ids.CBOX_VANIMATION) maindialogHelpers.setUI(self) if id == ids.CBOX_CLOSEAFTEREXPORT: self.closeAfter = self.GetBool(ids.CBOX_CLOSEAFTEREXPORT) if id == ids.CBOX_UNUSEDMATS: self.unusedMats = self.GetBool(ids.CBOX_UNUSEDMATS) if id == ids.CBOX_STREAMING: self.streaming = self.GetBool(ids.CBOX_STREAMING) if self.streaming == True: self.SetBool(ids.CBOX_COMPRESSED, False) self.compressData = False maindialogHelpers.setUI(self) if id == ids.CBOX_COMPRESSED: self.compressData = self.GetBool(ids.CBOX_COMPRESSED) if self.compressData == True: self.SetBool(ids.CBOX_STREAMING, False) self.streaming = False maindialogHelpers.setUI(self) if id == ids.CBOX_DEBUG: self.debug = self.GetBool(ids.CBOX_DEBUG) if id == ids.CBOX_OPENPREFAB: self.openInPreFab = self.GetBool(ids.CBOX_OPENPREFAB) if id == ids.COMBO_RANGE: self.animationRange = self.GetLong(ids.COMBO_RANGE) maindialogHelpers.setUI(self) if id == ids.COMBO_TEXTURESMODE: maindialogHelpers.setValues(self) maindialogHelpers.setUI(self) if id == ids.MENU_ABOUT_ABOUT: pass #dlg = AboutDialog() #DLG_TYPE_MODAL = > synchronous dialog #DLG_TYPE_ASYNC = > asynchronous dialogs #dlg.Open(dlgtype=c4d.DLG_TYPE_MODAL, defaultw=300, defaulth=300) if id == ids.MENU_ABOUT_HELP: realPath = os.path.abspath( os.path.join(os.path.dirname(__file__), "..")) helpPath = os.path.join(realPath, "res", "Help", "index.html") c4d.storage.GeExecuteFile(helpPath) print helpPath #pass#dlg = HelpDialog() #DLG_TYPE_MODAL = > synchronous dialog #DLG_TYPE_ASYNC = > asynchronous dialogs #dlg.Open(dlgtype=c4d.DLG_TYPE_ASYNC, defaultw=400, defaulth=400) if id == ids.MENU_CHECKFORUPDATE: realPath = os.path.abspath( os.path.join(os.path.dirname(__file__), "..")) helpPath = os.path.join(realPath, "res", "awayextensionsc4dversion.xml") versionThis = maindialogHelpers.loadVersionFile(helpPath) versionWeb = maindialogHelpers.loadVersionFilefromNet() if versionThis == "" or versionWeb == "": return if versionThis != versionWeb: message = "Your Version is not up to date\n" message += "Go to \nhttps://github.com/awaytools/AwayExtensions-C4D\n and get the new version\n\n" message += "Your version = " + str(versionThis) + "\n" message += "Latest version = " + str(versionWeb) + "\n" if versionThis == versionWeb: message = "Your Version is up to date\n" c4d.gui.MessageDialog(message) maindialogHelpers.setValues(self) return True
def buildSkeletonAnimation(exportData,curObj,mainDialog,skeletonAnimationTag): globalMinFrame=mainDialog.GetReal(ids.REAL_FIRSTFRAME) # get the first frame for the global animation range globalMaxFrame=mainDialog.GetReal(ids.REAL_LASTFRAME) # get the last frame for the global animation range minFrame=globalMinFrame # set the minFrame to the global minFrame maxFrame=globalMaxFrame # set the maxFrame to the global maxFrame animationRange=skeletonAnimationTag[1015] # get the range mode of the current Animation if animationRange!=1021: # if it is not set to "Global" we update the minframe/maxFrame using the skeletonAnmiationTags input values minFrame=skeletonAnimationTag[1018] maxFrame=skeletonAnimationTag[1020] #print "Start Exporting Animation Range = "+str(minFrame)+" - "+str(maxFrame) curFrame=minFrame # set the first frame to be the current frame durationList=[] # list to store all frame-durations idList=[] if skeletonAnimationTag[1021]==True: keyLength=maxFrame-minFrame # get the curve for this track keyCounter=0 keyTime=minFrame*(float(1000/exportData.doc.GetFps())/1000) durationTime=(float(1000/exportData.doc.GetFps())/1000) while keyCounter<keyLength: durationList.append(durationTime) keyTime+=durationTime newTime=c4d.BaseTime(keyTime) newTime.Quantize(exportData.doc.GetFps()) idList.append(buildSkeletonPose(exportData,curObj,newTime)) keyCounter+=1 buildSkeletonAnimationBlock(exportData,curObj,durationList,idList) return # list to store all frame-IDs track=curObj.GetFirstCTrack() # get the first track of the curObj if track==None: # if no track is found durationList.append(1*exportData.doc.GetFps()) # set only one duration idList.append(buildSkeletonPose(exportData,curObj,c4d.BaseTime((curFrame*exportData.doc.GetFps())/1000))) # add one skeletonPoseBlock to the idLis buildSkeletonAnimationBlock(exportData,curObj,durationList,idList) # create a SkeletonAnimationBlock containing only one Frame return # exit this function curve=track.GetCurve() # get the curve for this track keyCounter=0 keyCount=curve.GetKeyCount() #print keyCount firstKeyTime=None while keyCounter<keyCount: # iterate over the keyCount key=curve.GetKey(keyCounter) # get a key keyTime=key.GetTime() if firstKeyTime < keyTime: firstKeyTime=keyTime #exportData.doc.SetTime(curTime) # get a key keyTimeInFrame=keyTime.GetFrame(exportData.doc.GetFps()) exportData.allStatus+=float(10/float(curve.GetKeyCount())) # used to calculate processbar mainHelpers.updateCanvas(mainDialog,exportData) # update processbar # if the keys time is within the range to export: if float(keyTimeInFrame)>=float(minFrame) and float(keyTimeInFrame)<=float(maxFrame): if (keyCounter+1)<keyCount:# if this is not the last key, we calculate the duration-time like this: durationTime = nextKeyTime - thisKeyTime durationList.append(float(curve.GetKey(keyCounter+1).GetTime().Get())-float(keyTime.Get())) if (keyCounter+1)>=keyCount:# if this is the last keyframe within the range, we set its duration endDuration=float(maxFrame*float(1000/exportData.doc.GetFps())/float(1000))-float(keyTime.Get()) if endDuration<=0: endDuration=0 durationList.append(endDuration)#100*(1000/exportData.doc.GetFps())) idList.append(buildSkeletonPose(exportData,curObj,keyTime)) keyCounter+=1 if firstKeyTime is not None: #durationList.append((1000/exportData.doc.GetFps())/1000) pass#print durationList #idList.append(buildSkeletonPose(exportData,curObj,firstKeyTime)) return buildSkeletonAnimationBlock(exportData,curObj,durationList,idList) # create the SkeletonAnimationBlock
def buildVertexAnimation(exportData, curObj, mainDialog, vertexAnimationTag): globalMinFrame = mainDialog.GetReal( ids.REAL_FIRSTFRAME ) # get the first frame for the global animation range globalMaxFrame = mainDialog.GetReal( ids.REAL_LASTFRAME ) # get the last frame for the global animation range minFrame = globalMinFrame # set the minFrame to the global minFrame maxFrame = globalMaxFrame # set the maxFrame to the global maxFrame animationRange = vertexAnimationTag[ 1015] # get the range mode of the current Animation if animationRange != 1021: # if it is not set to "Global" we update the minframe/maxFrame using the skeletonAnmiationTags input values minFrame = vertexAnimationTag[1018] maxFrame = vertexAnimationTag[1020] #print "Start Exporting Animation Range = "+str(minFrame)+" - "+str(maxFrame) keyFrameStyle = vertexAnimationTag[1054] curFrame = minFrame # set the first frame to be the current frame frameDurations = [] # list to store all frame-durations framePositions = [] lastFramesDuration = 0 keyTime = minFrame * (float(1000 / exportData.doc.GetFps()) / 1000) if keyFrameStyle == 1055 or keyFrameStyle == 1058: if keyFrameStyle == 1055: # all Frames keyLength = maxFrame - minFrame durationTime = (float(1000 / exportData.doc.GetFps()) / 1000) if keyFrameStyle == 1058: # keyframe Number allKeysLength = maxFrame - minFrame keyLength = vertexAnimationTag[1061] difKey = allKeysLength - keyLength keyLength2 = float(difKey / (keyLength - 1)) durationTime = (float(1000 / exportData.doc.GetFps()) / 1000) durationTime += float( (float(1000 / exportData.doc.GetFps()) / 1000) * (keyLength2)) keyCounter = 0 while keyCounter < keyLength: if keyCounter == (keyLength - 1): durationTime = lastFramesDuration frameDurations.append(durationTime) keyTime += durationTime newTime = c4d.BaseTime(keyTime) #if keyFrameStyle==1055: # all Frames # newTime.Quantize(exportData.doc.GetFps()) framePositions.append( getMeshPosePosition(exportData, curObj, newTime, vertexAnimationTag[1051])) keyCounter += 1 if keyFrameStyle == 1056 or keyFrameStyle == 1057: if keyFrameStyle == 1056: cloneObj = curObj.GetClone() firstTrack = cloneObj.GetFirstCTrack() firstCurve = firstTrack.GetCurve() tracks = curObj.GetCTracks() keysDic = {} keysList = [] keysList2 = [] for track in tracks: curve = track.GetCurve() keyCounter = 0 while keyCounter < curve.GetKeyCount(): key = curve.GetKey(keyCounter) keyTime = key.GetTime() isKey = firstCurve.FindKey(keyTime) if isKey is None: firstCurve.AddKey(keyTime) keyCounter += 1 if keyFrameStyle == 1057: tracks = curObj.GetTag(1030484).GetCTracks() if tracks is not None: for track in tracks: testerString = "(1052, 130, 1030484)" if testerString == str(track.GetDescriptionID()): firstCurve = track.GetCurve() if firstCurve is None: pass if firstCurve is not None: keyCounter = 0 frametimes = [] startOffset = 0 firstKeyTime = None while keyCounter < firstCurve.GetKeyCount(): key = firstCurve.GetKey(keyCounter) keyTimeInFrame = key.GetTime().GetFrame( exportData.doc.GetFps()) if float(keyTimeInFrame) >= float(minFrame) and float( keyTimeInFrame) <= float(maxFrame): if firstKeyTime is None: firstKeyTime = key.GetTime().Get() if firstKeyTime != startOffset: startOffset = firstKeyTime frametimes.append( c4d.BaseTime(key.GetTime().Get() - firstKeyTime)) keyCounter += 1 if len(frametimes) == 0: frametimes.append(c4d.BaseTime(0)) endOffset = float( (float(1000 / exportData.doc.GetFps()) / 1000) * (maxFrame)) - (frametimes[len(frametimes) - 1].Get() + startOffset) keyCounter = 0 #print keyCount firstKeyTime = None keyCount = len(frametimes) for keyBaseTime in frametimes: keyTime = keyBaseTime.Get() exportData.allStatus += float(10 / float(keyCount)) mainHelpers.updateCanvas(mainDialog, exportData) if (keyCounter + 1) < keyCount: frameDurations.append( float(frametimes[keyCounter + 1].Get()) - float(keyTime)) if (keyCounter + 1) >= keyCount: endDuration = startOffset + endOffset if endDuration <= 0: endDuration = 0 frameDurations.append(endDuration) framePositions.append( getMeshPosePosition(exportData, curObj, c4d.BaseTime(keyTime + startOffset), vertexAnimationTag[1051])) keyCounter += 1 if len(frameDurations) == 1: newAnimBlock = buildMeshPoseBlock(exportData, curObj, frameDurations, framePositions, vertexAnimationTag) if len(frameDurations) > 1: newAnimBlock = buildMeshPoseAnimationBlock(exportData, curObj, frameDurations, framePositions, vertexAnimationTag) return newAnimBlock