void RenderCommand::rasterRender(bool isPreview) { ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); if (isPreview) { //Let the PreviewFxManager own the rest. Just pass him the current output node. PreviewFxManager::instance()->showNewPreview((TFx *)scene->getXsheet()->getFxDag()->getCurrentOutputFx()); return; } string ext = m_fp.getType(); #ifdef WIN32 if (ext == "avi" && !isPreview) { TPropertyGroup *props = scene->getProperties()->getOutputProperties()->getFileFormatProperties(ext); string codecName = props->getProperty(0)->getValueAsString(); TDimension res = scene->getCurrentCamera()->getRes(); if (!AviCodecRestrictions::canWriteMovie(toWideString(codecName), res)) { QString msg(QObject::tr("The resolution of the output camera does not fit with the options chosen for the output file format.")); MsgBox(WARNING, msg); return; } } #endif; //Extract output properties TOutputProperties *prop = isPreview ? scene->getProperties()->getPreviewProperties() : scene->getProperties()->getOutputProperties(); //Build thread count /*-- Dedicated CPUs のコンボボックス (Single, Half, All) --*/ int index = prop->getThreadIndex(); const int procCount = TSystem::getProcessorCount(); const int threadCounts[3] = {1, procCount / 2, procCount}; int threadCount = threadCounts[index]; /*-- MovieRendererを作る。Previewの場合はファイルパスは空 --*/ MovieRenderer movieRenderer(scene, isPreview ? TFilePath() : m_fp, threadCount, isPreview); TRenderSettings rs = prop->getRenderSettings(); //Build raster granularity size index = prop->getMaxTileSizeIndex(); const int maxTileSizes[4] = { (std::numeric_limits<int>::max)(), TOutputProperties::LargeVal, TOutputProperties::MediumVal, TOutputProperties::SmallVal}; rs.m_maxTileSize = maxTileSizes[index]; //Build #ifdef BRAVODEMO rs.m_mark = loadBravo(scene->getCurrentCamera()->getRes()); #endif /*-- RenderSettingsをセット --*/ movieRenderer.setRenderSettings(rs); /*-- カメラDPIの取得、セット --*/ TPointD cameraDpi = isPreview ? scene->getCurrentPreviewCamera()->getDpi() : scene->getCurrentCamera()->getDpi(); movieRenderer.setDpi(cameraDpi.x, cameraDpi.y); movieRenderer.enablePrecomputing(true); /*-- プログレス ダイアログの作成 --*/ RenderListener *listener = new RenderListener(movieRenderer.getTRenderer(), m_fp, ((m_numFrames - 1) / m_step) + 1, isPreview); QObject::connect(listener, SIGNAL(canceled()), &movieRenderer, SLOT(onCanceled())); movieRenderer.addListener(listener); bool fieldRendering = rs.m_fieldPrevalence != TRenderSettings::NoField; /*-- buildSceneFxの進行状況を表示するプログレスバー --*/ QProgressBar *buildSceneProgressBar = new QProgressBar(TApp::instance()->getMainWindow()); buildSceneProgressBar->setAttribute(Qt::WA_DeleteOnClose); buildSceneProgressBar->setWindowFlags(Qt::SubWindow | Qt::Dialog | Qt::WindowStaysOnTopHint); buildSceneProgressBar->setMinimum(0); buildSceneProgressBar->setMaximum(m_numFrames - 1); buildSceneProgressBar->setValue(0); buildSceneProgressBar->move(600, 500); buildSceneProgressBar->setWindowTitle("Building Schematic..."); buildSceneProgressBar->show(); for (int i = 0; i < m_numFrames; ++i, m_r += m_stepd) { buildSceneProgressBar->setValue(i); if (rs.m_stereoscopic) scene->shiftCameraX(-rs.m_stereoscopicShift / 2); TFxPair fx; fx.m_frameA = buildSceneFx(scene, m_r, rs.m_shrinkX, isPreview); if (fieldRendering && !isPreview) fx.m_frameB = buildSceneFx(scene, m_r + 0.5 / m_timeStretchFactor, rs.m_shrinkX, isPreview); else if (rs.m_stereoscopic) { scene->shiftCameraX(rs.m_stereoscopicShift); fx.m_frameB = buildSceneFx(scene, m_r + 0.5 / m_timeStretchFactor, rs.m_shrinkX, isPreview); scene->shiftCameraX(-rs.m_stereoscopicShift / 2); } else fx.m_frameB = TRasterFxP(); /*-- movieRendererにフレーム毎のFxを登録 --*/ movieRenderer.addFrame(m_r, fx); } /*-- プログレスバーを閉じる --*/ buildSceneProgressBar->close(); //resetViewer(); //TODO cancella le immagini dell'eventuale render precedente //FileViewerPopupPool::instance()->getCurrent()->onClose(); movieRenderer.start(); }
bool RenderCommand::init(bool isPreview) { ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); TSceneProperties *sprop = scene->getProperties(); /*-- Preview/Renderに応じてそれぞれのSettingを取得 --*/ TOutputProperties &outputSettings = isPreview ? *sprop->getPreviewProperties() : *sprop->getOutputProperties(); outputSettings.getRange(m_r0, m_r1, m_step); /*-- シーン全体のレンダリングの場合、m_r1をScene長に設定 --*/ if (m_r0 == 0 && m_r1 == -1) { m_r0 = 0; m_r1 = scene->getFrameCount() - 1; } if (m_r0 < 0) m_r0 = 0; if (m_r1 >= scene->getFrameCount()) m_r1 = scene->getFrameCount() - 1; if (m_r1 < m_r0) { MsgBox(WARNING, QObject::tr("The command cannot be executed because the scene is empty.")); return false; // throw TException("empty scene"); // non so perche', ma termina il programma // nonostante il try all'inizio } // Initialize the preview case /*TRenderSettings rs = sprop->getPreviewProperties()->getRenderSettings(); TRenderSettings rso = sprop->getOutputProperties()->getRenderSettings(); rs.m_stereoscopic=true; rs.m_stereoscopicShift=0.05; rso.m_stereoscopic=true; rso.m_stereoscopicShift=0.05; sprop->getPreviewProperties()->setRenderSettings(rs); sprop->getOutputProperties()->setRenderSettings(rso);*/ if (isPreview) { /*-- PreviewではTimeStretchを考慮しないので、そのままフレーム値を格納してゆく --*/ m_numFrames = (int)(m_r1 - m_r0 + 1); m_r = m_r0; m_stepd = m_step; m_multimediaRender = 0; return true; } // Full render case // Read the output filepath TFilePath fp = outputSettings.getPath(); /*-- ファイル名が指定されていない場合は、シーン名を出力ファイル名にする --*/ if (fp.getWideName() == L"") fp = fp.withName(scene->getScenePath().getName()); /*-- ラスタ画像の場合、ファイル名にフレーム番号を追加 --*/ if (TFileType::getInfo(fp) == TFileType::RASTER_IMAGE || fp.getType() == "pct" || fp.getType() == "pic" || fp.getType() == "pict") //pct e' un formato"livello" (ha i settings di quicktime) ma fatto di diversi frames fp = fp.withFrame(TFrameId::EMPTY_FRAME); fp = scene->decodeFilePath(fp); if (!TFileStatus(fp.getParentDir()).doesExist()) { try { TFilePath parent = fp.getParentDir(); TSystem::mkDir(parent); DvDirModel::instance()->refreshFolder(parent.getParentDir()); } catch (TException &e) { MsgBox(WARNING, QObject::tr("It is not possible to create folder : %1").arg(QString::fromStdString(toString(e.getMessage())))); return false; } catch (...) { MsgBox(WARNING, QObject::tr("It is not possible to create a folder.")); return false; } } m_fp = fp; // Retrieve camera infos const TCamera *camera = isPreview ? scene->getCurrentPreviewCamera() : scene->getCurrentCamera(); TDimension cameraSize = camera->getRes(); TPointD cameraDpi = camera->getDpi(); // Retrieve render interval/step/times double stretchTo = (double)outputSettings.getRenderSettings().m_timeStretchTo; double stretchFrom = (double)outputSettings.getRenderSettings().m_timeStretchFrom; m_timeStretchFactor = stretchTo / stretchFrom; m_stepd = m_step / m_timeStretchFactor; int stretchedR0 = tfloor(m_r0 * m_timeStretchFactor); int stretchedR1 = tceil((m_r1 + 1) * m_timeStretchFactor) - 1; m_r = stretchedR0 / m_timeStretchFactor; m_numFrames = (stretchedR1 - stretchedR0) / m_step + 1; // Update the multimedia render switch m_multimediaRender = outputSettings.getMultimediaRendering(); return true; }