コード例 #1
0
ファイル: nel_export_swt.cpp プロジェクト: CCChaos/RyzomCore
bool CNelExport::exportSWT(const char *sPath, std::vector<INode*>& vectNode)
{
	float rPosValue;
	float rRotValue;
	float rScaleValue;
	CSkeletonWeight::TNodeArray aSWNodes; // Array of Skeleton Weight Node
	int nNumNode = 0;

	aSWNodes.empty();

	// Build the array of node
	std::vector<INode*>::iterator it = vectNode.begin();

	for(int i=0; i<(int)vectNode.size(); ++i,++it)
	{
		// Get the SWT Modifier
		INode *pNode = *it;

		// SWT active ?
		if (CExportNel::getScriptAppData (pNode, NEL3D_APPDATA_EXPORT_SWT, BST_UNCHECKED) != BST_UNCHECKED)
		{
			// Get the value
			rPosValue = CExportNel::getScriptAppData (pNode, NEL3D_APPDATA_EXPORT_SWT_WEIGHT, 0.f);
			rRotValue = rPosValue;
			rScaleValue = rPosValue;

			// Store them in the temporary list
			aSWNodes.resize(nNumNode+3);
			aSWNodes[nNumNode].Name = pNode->GetName();
			aSWNodes[nNumNode].Name += std::string (".")+ITransformable::getRotQuatValueName();
			aSWNodes[nNumNode].Weight = rRotValue;
			++nNumNode;
			aSWNodes[nNumNode].Name = pNode->GetName();
			aSWNodes[nNumNode].Name += std::string (".")+ITransformable::getPosValueName ();
			aSWNodes[nNumNode].Weight = rPosValue;
			++nNumNode;
			aSWNodes[nNumNode].Name = pNode->GetName();
			aSWNodes[nNumNode].Name += std::string (".")+ITransformable::getScaleValueName();
			aSWNodes[nNumNode].Weight = rScaleValue;
			++nNumNode;
		}
	}

	if (aSWNodes.size())
	{
		CSkeletonWeight sw;
		COFile file;
		
		sw.build( aSWNodes );

		if (file.open (sPath))
		{
			try
			{							
				// Serial the skeleton
				sw.serial (file);
				// All is good
				return true;
			}
			catch (Exception &e)
			{
				nlwarning (e.what());
			}
		}
	}
	else
	{
		// No node found with a SWT Modifier
		nlwarning ("No node found with a SWT Modifier");
	}
	return false;
}
//TODO titegus: replace that by 4 buttons Export128Diffuse, Export128Additive, Export256Diffuse, Export256Diffuse ?
void CTile_browser_dlg::on_exportBorderPushButton_clicked()
{
	// Select a file
	QFileDialog::Options options;
	QString selectedFilter;
	QString fileName = QFileDialog::getSaveFileName(this, tr("Choose Bitmap"), QString(tileBankBrowser.getAbsPath().c_str()) , "Targa Bitmap(*.tga);;All Files (*.*);;", &selectedFilter, options);
	
	if (!fileName.isEmpty())
	{
		fileName = QDir::toNativeSeparators(fileName);
		// Get the border of the bank
		std::vector<NLMISC::CBGRA> array;

		// 256 or 128 ?
		int width, height;
		//TODO titegus: And So what if Alpha ??? and what about border256 ???
		tileBankBrowser.getTileSet (tileSetIndex)->getBorder128 ((CTile::TBitmap)tileTextureButtonGroup->checkedId())->get (width, height, array);

		// Make a bitmap
		if (width&&height)
		{
			NLMISC::CBitmap bitmap;
			bitmap.resize (width, height, NLMISC::CBitmap::RGBA);

			// Get pixel
			CRGBA *pPixel=(CRGBA*)&bitmap.getPixels()[0];

			// Make a copy
			for (int i=0; i<width*height; i++)
			{
				// Copy the pixel
				pPixel->R=array[i].R;
				pPixel->G=array[i].G;
				pPixel->B=array[i].B;
				pPixel->A=array[i].A;
				pPixel++;
			}

			// Write the bitmap
			bool error=false;
			try
			{
				COFile file;
				if (file.open (fileName.toStdString().c_str()))
				{
					// Export
					bitmap.writeTGA (file, 32);
				}
				else
					error=true;
			}
			catch (Exception& e)
			{
				const char *toto=e.what ();
				error=true;
			}

			// Error during export ?
			if (error)
			{
				// Error message
				QString s = tr("Can't write bitmap %1").arg(fileName);
				QMessageBox::information (this, tr("Export border"), s);
			}
		}
	}

}