/* ==================== exportAnimation ==================== */ void G3DAExport::exportAnimation(NODE* node) { // get the animation if(node->include) { int first_frame = mStart/GetTicksPerFrame(); int last_frame = mEnd/GetTicksPerFrame(); for(int i = first_frame; i <= last_frame; i++) { // does this node have a max node? TimeValue t = i*GetTicksPerFrame(); Matrix3 m(true); if(node->parent) { m = GetTransform(node, t) * Inverse(GetTransform(node->parent, t)); } else { m = GetTransform(node, t); } // add the transform to the sequence node->sequence.push_back(m); } mNodeCount++; } // process the child node for(int i = 0; i < node->children.size(); i++) { exportAnimation(node->children[i]); } }
TupExportModule::TupExportModule(TupProject *project, TupExportWidget::OutputFormat outputFormat, QString title, const TupExportWidget *widget) : TupExportWizardPage(title), m_currentExporter(0), m_currentFormat(TupExportInterface::NONE), m_project(project) { #ifdef K_DEBUG #ifdef Q_OS_WIN qDebug() << "[TupExportModule::TupExportModule()]"; #else TINIT; #endif #endif output = outputFormat; transparency = false; browserWasOpened = false; if (output == TupExportWidget::Animation) { setTag("ANIMATION"); } else if (output == TupExportWidget::ImagesArray) { setTag("IMAGES_ARRAY"); } else if (output == TupExportWidget::AnimatedImage) { setTag("ANIMATED_IMAGE"); } bgTransparency = new QCheckBox(tr("Enable background transparency")); QWidget *container = new QWidget; QVBoxLayout *layout = new QVBoxLayout(container); TCONFIG->beginGroup("General"); path = TCONFIG->value("DefaultPath", QDir::homePath()).toString(); //////////////// QHBoxLayout *prefixLayout = new QHBoxLayout; prefixLayout->addWidget(new QLabel(tr("Image name prefix: "))); QHBoxLayout *filePathLayout = new QHBoxLayout; if (output == TupExportWidget::ImagesArray) filePathLayout->addWidget(new QLabel(tr("Directory: "))); else // Animation or AnimatedImage filePathLayout->addWidget(new QLabel(tr("File: "))); QString prefix = m_project->projectName() + "_img"; m_prefix = new QLineEdit(prefix); m_filePath = new QLineEdit; connect(m_filePath, SIGNAL(textChanged(const QString &)), this, SLOT(updateState(const QString &))); if (output == TupExportWidget::Animation) { connect(widget, SIGNAL(exportAnimation()), this, SLOT(exportIt())); connect(widget, SIGNAL(setAnimationFileName()), this, SLOT(updateNameField())); } if (output == TupExportWidget::AnimatedImage) { connect(widget, SIGNAL(exportAnimatedImage()), this, SLOT(exportIt())); connect(widget, SIGNAL(setAnimatedImageFileName()), this, SLOT(updateNameField())); } if (output == TupExportWidget::ImagesArray) { connect(m_prefix, SIGNAL(textChanged(const QString &)), this, SLOT(updateState(const QString &))); connect(widget, SIGNAL(exportImagesArray()), this, SLOT(exportIt())); connect(widget, SIGNAL(setImagesArrayFileName()), this, SLOT(updateNameField())); }
/* ==================== DoExport ==================== */ int G3DAExport::DoExport(const TCHAR *name, ExpInterface *ei, Interface *i, BOOL suppressPrompts, DWORD options) { // clear the old data if(mRoot){delete mRoot, mRoot = NULL;} mNodeCount = 0; mSkins.clear(); // normalize the file path Str path = UnifySlashes(name); // get the export dir mPath = UnifySlashes(i->GetDir(APP_EXPORT_DIR)); mPath += '/'; if( !strstr( path.c_str(), mPath.c_str() ) ) { G3DAssert("The export path(%s) is illegal!",name); return 1; } // get the animation range Interval inter = i->GetAnimRange(); mTime = i->GetTime(); mStart = inter.Start(); mEnd = inter.End(); // recursive export all of the node exportNode(i->GetRootNode()); // export all of the skin for(int k = 0; k < mSkins.size(); k++) exportSkin(mSkins[k]); // recursive export all of the animation exportAnimation(mRoot); // check all of the nodes std::set<Str> names, duplicates; check(mRoot, names, duplicates); for(std::set<Str>::iterator it = duplicates.begin(); it != duplicates.end(); ++it) { G3DAssert( "Duplicate node name : %s", (*it).c_str() ); return 1; } #if 0 // write all of the data FILE *output = fopen(path.c_str(), "wb"); if(output==NULL) { G3DAssert("Fail to open the file : %s", path.c_str()); return 1; } // write count of the frame unsigned int frame_count = (mEnd-mStart)/GetTicksPerFrame()+1; fwrite( &frame_count, sizeof(unsigned int), 1, output ); // write number of the node fwrite( &mNodeCount, sizeof(unsigned int), 1, output ); // write count of the action unsigned int action_count = 0; fwrite( &action_count, sizeof(unsigned int), 1, output ); // write all of the node animation wirteAnimation(output,mRoot); // close file fclose(output); #else // write all of the data FILE *output = fopen(path.c_str(), "wb"); if(output==NULL) { G3DAssert("Fail to open the file : %s", path.c_str()); return 1; } // get the count of the frame unsigned int frame_count = (mEnd-mStart)/GetTicksPerFrame()+1; // begin to write the animation fprintf(output, "<animation>\n"); // begin to write the frame fprintf(output, "<frame count=\"%d\">\n", frame_count); // write all of the node frame wirteFrame(output,mRoot); // end to wirte the frame fprintf(output, "</frame>\n"); // end to wirte the animation fprintf(output, "</animation>\n"); // close file fclose(output); #endif // clear all of the data mSkins.clear(); if(mRoot){delete mRoot, mRoot = NULL;} return 1; }