def calculateTimeClicked(self): # Show from FRONT mayaUtils = MayaFunctionUtils() mayaUtils.changeToPerspCam() mayaUtils.viewFromCamPosition('FRONT', self.simulationSettings.fluidBoxName) # Delete / create output folder filePathMain = os.path.dirname(os.path.abspath(__file__)) fxPathRel = os.path.dirname(os.path.abspath(filePathMain)) outputFolder = fxPathRel + '/Output/' outputFolderAbs = os.path.abspath(outputFolder) if os.path.exists(outputFolderAbs): # Delete content filelist = [f for f in os.listdir(outputFolderAbs) if f.endswith((".mc", ".xml", "png", "jpg", "jpeg", "gif"))] for f in filelist: tmpPath = outputFolder + '/' + f tmpPathAbs = os.path.abspath(tmpPath) os.remove(tmpPathAbs) else: os.mkdir(outputFolderAbs) # Caching start_time_cahching = time.time() cacheCmd = MayaCacheCmdString() cacheCmd.setRenderSettingsFromMaya(int(self.simulationSettings.animationStartTime), int(self.simulationSettings.animationEndTime), outputFolderAbs, "Untitled") execCommand = MayaFunctionUtils() execCommand.createFluid(cacheCmd.getCacheCommandString(), None) res_time_caching = time.time() - start_time_cahching # Rendering start_time_rendering = time.time() renderer = MayaFunctionUtils() renderer.renderImages(outputFolder, "None", int(self.simulationSettings.animationStartTime), int(self.simulationSettings.animationEndTime), 640, 480) res_time_rendering = time.time() - start_time_rendering # Create GIF start_time_gif = time.time() directoryImagesDir = outputFolderAbs outputGifFileDir = outputFolderAbs outputGifFileName = 'animation.gif' gifImageCreator = GifCreator() start_time = self.simulationSettings.animationStartTime gifImageCreator.createGifFromImages(self.ffmpegpath, directoryImagesDir, outputGifFileDir, outputGifFileName, start_time, fps=25, gifOptimization=25) res_time_gif = time.time() - start_time_gif # Back to persp cam mayaUtils.changeToPerspCam() mayaUtils.viewFromCamPosition('PERSPECTIVE', self.simulationSettings.fluidBoxName) # Store results self.time_Caching = res_time_caching self.time_Renering = res_time_rendering self.time_GIF = res_time_gif # SetTime self.isTimeCalculated = True self.setTime()
def buttonCreateSimulation_Event(self): # If the fluid container is incorrect, the application closes if not FluidExplorerUtils.FluidExplorerUtils.containerIsCorrect(self.fluidName): self.showMessageBox('Error - Create Sumulation','Cannot select fluid attributes of of the selected container. Simulation stopped!\nFor more information please see the editor log.', 'warning') self.close() return # First of all check of ffmpeg and fluidExplorer executable files are ok ffmpegIsOk = FluidExplorerUtils.FluidExplorerUtils.checkIfFFmpgeIsExectuable(self.ffmpegpath) fluidExplorerIsOk = FluidExplorerUtils.FluidExplorerUtils.checkIfFluidExplorerIsExectuable(self.fluidExplorerPath) if not ffmpegIsOk: self.showMessageBox('Warning - Create Sumulation','Cannot execute FFmpeg. Simulation stopped!\nFor more information please see the editor log.', 'warning') self.close() return if not fluidExplorerIsOk: self.showMessageBox('Warning - Create Sumulation','Cannot execute FluidExplorer application. Simulation stopped!\nFor more information please see the editor log.', 'warning') self.close() return # # Create project and all contents # self.currentMayaSceneName = "" pathName = self.ui.lineEdit_ProjPath.text() projName = self.ui.lineEdit_SimulationName.text() [pathOk, simulationNameAbsolut] = self.checkProjectPathOk(pathName, projName) if not pathOk: return else: # Save a copy of the current scene in the project folder # Student version -> Save dialog has to be confirmed self.currentMayaSceneName = cmds.file(q=True, sn=True) saveFileSuccessfully = True try: tmpMayaFilePath = self.simulationSettings.outputPath + "/fluid_simulation_scene.mb" cmds.file(rename=tmpMayaFilePath) dialogRes = cmds.file(save=True) self.simulationSettings.simulationNameMB = tmpMayaFilePath except: saveFileSuccessfully = False if len(self.currentMayaSceneName) == 0: self.currentMayaSceneName = self.currentMayaSceneName + "untitled" cmds.file(rename=self.currentMayaSceneName) # Old name os.rmdir(self.simulationSettings.outputPath) if not saveFileSuccessfully: self.lgr.warning("Maya file not saved. Simulation stoped") self.close() return # Store information about the current scene self.simulationSettings.fluidBoxName = self.fluidName self.simulationSettings.numberSamples = self.ui.horizontalSlider_numberSeq.value() self.setCameraButtonSelection() # Show setting parameters in console and create xml file MayaCacheCmdSettings.printValues(self.simulationSettings) fileCreated = self.createProjectSettingsFile(simulationNameAbsolut) if not fileCreated: self.lgr.error('Could not create settings file. Simulation stoped') self.showMessageBox('Error - Create Sumulation','An error occurred while the project file was created!\nFor more information please see the editor log.', 'critical') self.close() return # No return until here: Project folder and settings file were created ... # -------------------------------------------------------------------------------------------------------------- # Generate a set of N cache commands and a set of N random samples # -------------------------------------------------------------------------------------------------------------- # Current spans stores the min and max slider vqalues. e.g.: currentSpans.velocitySwirl_Span currentSpans = self.tabParamtersObj.getSelectedValuesFromSlider() randomSamplesList = list() cacheCmdList = list() for iIndex in range(0, self.simulationSettings.numberSamples): # Create random samples fluidValueSampler = FluidValueSampler(currentSpans) fluidValueSampler.setSldierRangeValues() randomSamples = fluidValueSampler.getSampleSet() randomSamplesList.append(randomSamples) del fluidValueSampler del randomSamples # Create commands cacheName = self.simulationSettings.fluidBoxName + "_" + str(iIndex) cacheCmd = MayaCacheCmdString() pathOut = self.simulationSettings.outputPath + "/" + str(iIndex) cacheCmd.setRenderSettingsFromMaya(self.simulationSettings.animationStartTime, self.simulationSettings.animationEndTime, pathOut, cacheName) cmdStr = cacheCmd.getCacheCommandString() cacheCmdList.append(cmdStr) del cacheCmd self.simulationSettings.createCacheCommandString = cacheCmdList self.simulationSettings.randomSliderSamples = randomSamplesList """ # Print cache command and random values print "\nCache Commands:\n" for iIndex in range(0, self.simulationSettings.numberSamples): print("[ Index: ", iIndex, " ]") print(" Command: ", self.simulationSettings.createCacheCommandString[iIndex]) print(" velociySwirl: ", self.simulationSettings.randomSliderSamples[iIndex].velocitySwirl) print "\n" print "\n" """ # Lock the node FluidExplorerUtils.FluidExplorerUtils.lockNodes(self.fluidName, self.transformNode) # -------------------------------------------------------------------------------------------------------------- # Create the cache and render the images # -------------------------------------------------------------------------------------------------------------- self.mayaCallObject = MayaFunctionUtils() self.progressSteps = (self.getNumberOfActiveCameras() + 1) * self.simulationSettings.numberSamples progress = QtGui.QProgressDialog("", None, 0, self.progressSteps, self) progressWasCanceled = False progress.setWindowTitle("Please wait ...") progress.setMinimumDuration(0) progress.setMaximum(int(self.progressSteps)) progress.show() renderedImage = list() index = 0 fluidIndex = 0 progressIndex = 0 for lCmd, lSamples in itertools.izip(self.simulationSettings.createCacheCommandString, self.simulationSettings.randomSliderSamples): """ :type lSamples : MayaCacheCmd """ progressBarText = "<b>Simulation " + str(fluidIndex) + " / " + str(self.simulationSettings.numberSamples) + " created.<b>" progress.setLabelText(progressBarText) # 1. Set the values self.mayaCallObject.setSampledValue(self.simulationSettings.fluidBoxName, lSamples) # 2. Call maya cache function try: self.mayaCallObject.createFluid(lCmd, None) except Exception as e: self.showMessageBox('Error - Create Cache','An error occurred while the cache files were created!\nFor more information please see the editor log.', 'critical') progress.close() self.close() return progressIndex += 1 progress.setValue(progressIndex) # 3. Create the images if self.simulationSettings.imageView: self.mayaCallObject.changeToPerspCam() self.mayaCallObject.viewFromCamPosition('PERSPECTIVE', self.simulationSettings.fluidBoxName) if self.simulationSettings.imageView: try: [progressIndexUpdated, renderedImageSubList] = self.mayaCallObject.renderImagesFromCameras( self.simulationSettings, fluidIndex, progress, progressIndex) except Exception as e: self.showMessageBox('Error - Render Images','An error occurred while the images were rendered!\nFor more information please see the editor log.', 'critical') progress.close() self.close() return progressIndex = progressIndexUpdated renderedImage.append(renderedImageSubList) progressBarText = "<b>Simulation " + str(fluidIndex+1) + " / " + str(self.simulationSettings.numberSamples) + " created.<b>" progress.setLabelText(progressBarText) fluidIndex += 1 if progress.wasCanceled(): progressWasCanceled = True break if self.simulationSettings.imageView: self.mayaCallObject.changeToPerspCam() self.mayaCallObject.viewFromCamPosition('PERSPECTIVE', self.simulationSettings.fluidBoxName) self.mayaCallObject = None progress.close() # -------------------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- # Create GIF images # -------------------------------------------------------------------------------------------------------------- if self.simulationSettings.imageView: self.lgr.info("Creating GIF animations:") progress = QtGui.QProgressDialog("", None, 0, self.progressSteps, self) progress.setWindowTitle("Please wait ...") progress.setMinimumDuration(0) progress.setMaximum(len(renderedImage)) progress.setLabelText("<b>Creating GIF animations ...</b>") progress.show() progressIndex = 0 gifIndex = 0 for idx, val in enumerate(renderedImage): tmpList = val for val in tmpList: progressIndex += 1 progress.setValue(progressIndex) # Store the path to the rendered images directoryImagesDir = val outputGifFileDir = val outputGifFileName = 'animation.gif' self.gifImageCreator = GifCreator() start_time = self.simulationSettings.animationStartTime isFFmpegExecutable = self.gifImageCreator.createGifFromImages(self.ffmpegpath, directoryImagesDir, outputGifFileDir, outputGifFileName, start_time, fps=25, gifOptimization=25) if isFFmpegExecutable==False: self.showMessageBox('Error - Create Animations','An error occurred while the animations were created!\nFor more information please see the editor log.', 'critical') progress.close() self.close() return gifIndex += 1 self.lgr.info('GIF Animation "%s" created', str(gifIndex)) progress.close() # -------------------------------------------------------------------------------------------------------------- # Copy settings file to project folder pathToSettingsFile = os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + '/Resources/settings_file/fluidExplorer.settings') copySettingsFileTo = os.path.abspath(self.simulationSettings.outputPath + '/fluidExplorer.settings') FluidExplorerUtils.FluidExplorerUtils.copySettingsFile(pathToSettingsFile, copySettingsFileTo) text = "Simulations successfully created!" + "\n\nProject Path: " + self.simulationSettings.outputPath + "" + "\nProject File: " + self.simulationSettings.simulationNameMB + "" self.showMessageBox("Information", text, 'information') # Select the transform node cmds.select(self.transformNode, r=True) self.lgr.info('#') self.lgr.info("# Simulation successfully created: %s -", self.simulationSettings.outputPath) self.lgr.info('#') # Close window self.close()