Exemplo n.º 1
0
bool SGMExporter::DoExport(const TCHAR *name, ExpInterface *ei, Interface *max_interface)
{
	scene = GetIGameInterface();
	assert(scene != NULL);

	std::string sceneName = StringUtils::ToNarrow(scene->GetSceneFileName());
	sceneName.replace(sceneName.find(".max"), 4, "");
	fileName = StringUtils::ToNarrow(name) + sceneName + ".skm";

	Log::StartLog(true, false, false);
	Log::LogT("=== exporting skinned mesh to file '%s'", fileName.c_str());

	scene->SetStaticFrame(0);

	IGameConversionManager *cm = GetConversionManager();
	assert(cm != NULL);

	cm->SetCoordSystem(IGameConversionManager::IGAME_OGL);

	if (!scene->InitialiseIGame(false))
	{
		Log::LogT("error: couldnt initialize scene");
		return false;
	}

	meshesCount = 0;

	std::ofstream fileStream(fileName.c_str(), std::ios::binary);
	BinaryWriter bw(&fileStream);

	/*

	1.2
		- vertex channels in mesh part

	*/

	bw.Write("FTSMDL", 6);
	bw.Write((unsigned short)((1 << 8) | 2)); // version 1.2

	bw.Write((int)0);

	std::vector<Scene3DMesh*> meshes;
	if (!GetMeshes(meshes, &bw))
		return false;

	fileStream.seekp(8, std::ios::beg);
	//fileStream.seekp(0, std::ios::beg);
	bw.Write((int)meshesCount);
	fileStream.close();

	return true;
}
Exemplo n.º 2
0
int DoExport( const MCHAR* name, ExpInterface* ei, Interface* i, BOOL suppressPrompts, DWORD options )
{
	UserCoord exporterCoord =
	{
		1,		// right-handed coordinate
		1,		// X axis goes right
		2,		// Y axis goes up
		5,		// Z axis goes out
		1,		// U goes right
		0,		// V goes up
	};

	//// d3d setup
	//UserCoord exporterCoord =
	//{
	//	0,		// left-handed coordinate
	//	0,		// X axis goes left
	//	2,		// Y axis goes up
	//	5,		// Z axis goes out
	//	1,		// U goes right
	//	1,		// V goes down
	//};

	IGameScene*		igScene = GetIGameInterface();

	IGameConversionManager* cm = GetConversionManager();
	cm->SetUserCoordSystem(exporterCoord);

	igScene->InitialiseIGame();

	// export the very first frame
	igScene->SetStaticFrame( 0 );

	RootExporter rootExporter;

	// go through all top nodes
	for ( int i=0; i<igScene->GetTopLevelNodeCount(); i++ )
	{
		IGameNode* gameNode = igScene->GetTopLevelNode( i );
		rootExporter.AddNode( gameNode );
	}

	rootExporter.SaveToFile( name );

	// done
	igScene->ReleaseIGame();

	return TRUE;
}
Exemplo n.º 3
0
int TrianExporter::DoExport( const TCHAR * name, ExpInterface *ei, Interface *i, BOOL suppressPrompts, DWORD options )
{
	//Open the file to export to.
	m_of.open( name );

	//Create an Error procedure.
	MyErrorProc pErrorProc;
	SetErrorCallBack( &pErrorProc );

	//Get the game interface
	m_pIGame = GetIGameInterface();

	//Start the progress bar.
	i->ProgressStart( _T( "Exporting to .trian file..." ), TRUE, fn, NULL );

	//Set up the conversion manager.
	IGameConversionManager * cm = GetConversionManager();
	
	//Set up the whacky coordinate system that 3DS Max uses.
	UserCoord whacky = 
	{
		1, //Right-Handed.
		1, //X Axis goes right.
		4, //Y Axis goes in.
		3, //Z Axis goes down.
		0, //U Tex Axis is left.
		1  //V Tex Axis is down.
	};
	cm->SetUserCoordSystem( whacky );

	//Set the coordinate system.
	cm->SetCoordSystem( IGameConversionManager::IGAME_MAX );
	
	//Initialize the game scene.
	m_pIGame->InitialiseIGame( options & SCENE_EXPORT_SELECTED );

	//Go through all the nodes of the scene and export only the Game Meshes.
	for( int l = 0; l < m_pIGame->GetTopLevelNodeCount(); l++ )
	{
		//Get the current Game node.
		IGameNode * node = m_pIGame->GetTopLevelNode( l );

		//Check for selected state.
		if( node->IsTarget() )
			continue;

		ExportNodeInfo( node );
	}

	//End the progress bar.
	i->ProgressEnd();

	//Release the scene.
	m_pIGame->ReleaseIGame();
	m_pIGame = 0;

	//Close the output stream.
	m_of.close();

	return TRUE;
}
Exemplo n.º 4
0
int	maxProject2::DoExport(const TCHAR *name,ExpInterface *ei,Interface *i, BOOL suppressPrompts, DWORD options)
{
	//TODO: Implement the actual file Export here and 
	//		return TRUE If the file is exported properly

	AllocConsole();
	 _cprintf( "Export Begin\n" );//¼ÇµÃ#include <conio.h>
	IGameConversionManager * cm = GetConversionManager();
	cm->SetCoordSystem( IGameConversionManager::IGAME_D3D );
	
	IGameScene* pSce=GetIGameInterface();

	pSce->InitialiseIGame(false);
	pSce->SetStaticFrame(0);

	int num=pSce->GetTopLevelNodeCount();
//	_cprintf("node count %d \n",num);
//	_cprintf("%s \n",name);

	TSTR outBuf;
	int matCount = pSce->GetRootMaterialCount();
//	_cprintf("MaterialCount count %d \n",matCount);
	FILE* file=freopen(name, "w", stdout);

	if(!file)
	{
		return FALSE;
	}
	/*cout<<"MatreialRootList Num: "<<matCount<<endl;
	
	for(int j =0;j<matCount;j++){	
		IGameMaterial* rootmat=pSce->GetRootMaterial(j);
		int num=rootmat->GetSubMaterialCount();
		TCHAR* name= rootmat->GetMaterialName();
		cout<<"\tMatrial mutiType :"<<rootmat->IsMultiType()<<endl;
		cout<<"\ttMatreialRoot name : "<<name<<endl;
		cout<<"\t\tMatreialRoot #"<<j<<" ----SubMatNum : "<<num<<endl;
		for(int i=0;i<num;i++){
			IGameMaterial* submat=rootmat->GetSubMaterial(i);
			cout<<"\t\tMatrial mutiType"<<submat->IsMultiType()<<endl;
			cout<<"\t\tSubMatName : "<<submat->GetMaterialName()<<endl;
			cout<<"\t\tSubMatSubNum : "<<submat->GetSubMaterialCount()<<endl;
		}
	}*/
	int nodecount=pSce->GetTopLevelNodeCount();
	int frame=pSce->GetSceneStartTime();
/*	cout<<pSce->GetSceneStartTime()<<endl;
	cout<<pSce->GetSceneEndTime()<<endl;
	cout<<GetFrameRate()<<endl;*/
//	cout<<"top level node count:"<<nodecount<<endl;
	for(int i=0;i<nodecount;i++)
	{
		IGameNode* topnode=pSce->GetTopLevelNode(i);
		IGameObject* obj=topnode->GetIGameObject();
//		cout<<"\tnode #:"<<i<<endl;
		if(obj->GetIGameType()==IGameObject::IGAME_BONE)
		{
/*	
			cout<<"\t\t bone"<<endl;
			
			IGameSupportObject * hO = (IGameSupportObject*)obj;
			IGameMesh * hm = hO->GetMeshObject();
			if(hm->InitializeData())
			{
				int num = hm->GetNumberOfVerts();
				cout<<"\t\t number of vertex : "<<num<<endl;
				cout<<"\t\t number of texcoord : "<<hm->GetNumberOfTexVerts()<<endl;
				cout<<"\t\t number of normals : "<<hm->GetNumberOfNormals()<<endl;
			}
			if(obj->GetIGameSkin()){
				cout<<"\t\tHAS SKIN"<<endl;
			}
*/
			IGameControl* con=topnode->GetIGameControl();

			IGameKeyTab keys;
			con->get
			con->GetFullSampledKeys(keys,GetFrameRate(),IGAME_ROT);
			int num=keys.Count();

			_cprintf( "keys count %d \n",keys.Count());//¼ÇµÃ#include <conio.h>
	//		if(num>1)
			//	num=1;
			for(int i=0;i<num;i++){
				Matrix3 t=keys[i].sampleKey.gval.ExtractMatrix3();

				_cprintf("\tkey frame time : %d\n",keys[i].t);
				_cprintf("\tkey frame pos : %d\n",keys[i].t/pSce->GetSceneTicks());
				AffineParts ap;
				
				float rotAngle;
				Point3 rotAxis;
				float scaleAxAngle;	
				Point3 scaleAxis;

				decomp_affine(t, &ap);

				
					// Quaternions are dumped as angle axis.
				AngAxisFromQ(ap.q, &rotAngle, rotAxis);
				AngAxisFromQ(ap.u, &scaleAxAngle, scaleAxis);

				/*_cprintf("\ttrans%f %f %f\n",ap.t.x,ap.t.y,ap.t.z);			
				_cprintf("\trot%f %f %f %f\n",rotAxis.x, rotAxis.y, rotAxis.z, rotAngle);
				_cprintf("%f %f %f %f %f %f %f\n", ap.k.x, ap.k.y, ap.k.z, scaleAxis.x,scaleAxis.y,scaleAxis.z, scaleAxAngle);*/

			}


		}else if(obj->GetIGameType()==IGameObject::IGAME_MESH){
		//	cout<<"\t\t mesh"<<endl;
			
			IGameMesh * hm = (IGameMesh*)obj;


			IGameSkin* skin=obj->GetIGameSkin();
		/*	if(skin){
				cout<<"\t\tHAS SKIN"<<endl;

				if(skin->GetSkinType()== IGameSkin::IGAME_PHYSIQUE)
					cout<<"\t\t\tPhysique"<<endl;
				else
					cout<<"\t\t\tmaxskin"<<endl;
				int bn=skin->GetNumberOfBones(0);
				cout<<"\t\t\t number of bones for 0 :"<<skin->GetNumberOfBones(0)<<endl;
				for(int i=0;i<bn;i++){
					cout<<"\t\t\t"<<skin->GetBone(0,i)->GetName()<<endl;
					cout<<"\t\t\t"<<skin->GetWeight(0,i)<<endl;
				}

				cout<<"\t\t\t total number of bones :"<<skin->GetTotalBoneCount()<<endl;

			}*/
			if(hm->InitializeData())
			{
				cout<<"m"<<endl;
				int num = hm->GetNumberOfVerts();
			/*	cout<<"\t\t number of vertex : "<<num<<endl;
				cout<<"\t\t number of texcoord : "<<hm->GetNumberOfTexVerts()<<endl;
				cout<<"\t\t number of normals : "<<hm->GetNumberOfNormals()<<endl;*/
				for(int iv=0;iv<num;iv++){
					Point3 v=hm->GetVertex(iv);
					cout<<"v "<<v.x<<" "<<v.y<<" "<<v.z<<endl;
					if(skin)
					{
						int bonenum=skin->GetNumberOfBones(iv);
						for(int bi=0;bi<bonenum;bi++)
						{
							INode* bone=skin->GetBone(iv,bi);
							int boneid=skin->GetBoneID(iv,bi);
							bone->GetNodeTM(0);
							cout<<"\t bone ID : "<<boneid<<" bone weight : "<<skin->GetWeight(iv,bi)<<endl;
						}
					}
				}
				cout<<"mi"<<endl;
				int tn=hm->GetNumberOfFaces();
				for(int tv=0;tv<tn;tv++){
					FaceEx* f=hm->GetFace(tv);
					cout<<"i "<<f->vert[0]<<" "<<f->vert[1]<<" "<<f->vert[2]<<endl;
				}
			}
		}else{
//			cout<<"\t\t else"<<endl;
		}

	}


	/*if(!suppressPrompts)
		DialogBoxParam(hInstance, 
				MAKEINTRESOURCE(IDD_PANEL), 
				GetActiveWindow(), 
				maxProject2OptionsDlgProc, (LPARAM)this);*/
	fclose(file);
	return TRUE;
}
Exemplo n.º 5
0
int ExporterF3D::DoExport(const TCHAR* name, ExpInterface* ei, Interface* i, BOOL suppressPrompts, DWORD options)
{
#if USE_CONSOLE
    AllocConsole();
    freopen("CONOUT$", "w", stdout);
#endif

    LOG_INFO("Start Export file [%s]", TCHARToString(name).c_str());

    Interface* ip = GetCOREInterface();
    SetErrorCallBack(&errorCallback);

    m_iGameVersion = GetIGameVersion();
    LOG_INFO("IGameVersion %f", m_iGameVersion);

    INT_PTR err = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), i->GetMAXHWnd(), &ExporterF3D::ExporterF3DOptionsDlgProc, (LPARAM)this);
    if (err != IDOK)
    {
        if (err != FALSE)
        {
            LOG_ERROR("Error Create DialogBox %d", err);
            MessageBox(NULL, _T("Error Create DialogBox"), _T("CLOSE"), MB_OK | MB_ICONERROR);
        }
#if USE_CONSOLE
        fclose(stdout);
        FreeConsole();
#endif

        return 1;
    }

    m_iGameScene = GetIGameInterface();
    m_iGameScene->InitialiseIGame(m_settings->isExportSelected());

    IGameConversionManager* cm = GetConversionManager();
    cm->SetCoordSystem(IGameConversionManager::IGAME_USER); // IGAME_OGL); // IGAME_D3D);

    UserCoord userCoordSystem;
    userCoordSystem.rotation = 1;
    userCoordSystem.xAxis = 1; // 1
    userCoordSystem.yAxis = 2; // 2
    userCoordSystem.zAxis = 5; // 4
    userCoordSystem.uAxis = 1;
    userCoordSystem.vAxis = 0;
    cm->SetUserCoordSystem(userCoordSystem);
    cm->SetCoordSystem(IGameConversionManager::IGAME_USER);

    m_iGameScene->SetStaticFrame(0);

    EExportError success = ExporterF3D::CreateModel();

    m_iGameScene->ReleaseIGame();
    ip->ProgressEnd();

    if (success == eNoError && m_scene)
    {
        if (!m_scene->save(TCHARToString(name), k_exporterVersion))
        {
            success = eSaveError;
        }
    }
    LOG_INFO("Save Completed\n");

    if (success == eNoError)
    {
        LOG_INFO("Export Finished Success");
        MessageBox(NULL, _T("Finished Success"), _T("OK"), MB_OK);
    }
    else
    {
        LOG_ERROR("Error Export code %d", success);

        std::wstring steError(L"", 256);
        wsprintf(&steError[0], L"Error Export Model. Code %d", success);
        MessageBox(NULL, steError.c_str(), _T("CLOSE"), MB_OK | MB_ICONERROR);
    }

#if USE_CONSOLE
    fclose(stdout);
    FreeConsole();
#endif

    return (success == eNoError) ? 1 : 0;
}
	bool MeshXMLExporter::Export(OutputMap& output) 
	{

		try {

			// write XML to a strstream
			std::stringstream of;

			while (!m_submeshNames.empty())
				m_submeshNames.pop();

			if (m_pGame) {
				m_pGame->ReleaseIGame();
				m_pGame = 0;
			}

			m_ei->theScene->EnumTree(this);

			m_pGame = GetIGameInterface();
			IGameConversionManager* cm = GetConversionManager();
			cm->SetCoordSystem(IGameConversionManager::IGAME_OGL);
			m_pGame->InitialiseIGame(m_nodeTab, false);
			m_pGame->SetStaticFrame(0);
			int nodeCount = m_pGame->GetTopLevelNodeCount();

			if (nodeCount == 0) {
				MessageBox(GetActiveWindow(), "No nodes available to export, aborting...", "Nothing To Export", MB_ICONINFORMATION);
				m_pGame->ReleaseIGame();
				return false;
			}

			// if we are writing everything to one file, use the name provided when the user first started the export;
			// otherwise, create filenames on the basis of the node (submesh) names
			std::string fileName;
			IGameNode* node = m_pGame->GetTopLevelNode(0);
			if (!m_config.getExportMultipleFiles())
				fileName = m_config.getExportFilename();
			else {
				fileName = m_config.getExportPath() + "\\";
				fileName += node->GetName();
				fileName += ".mesh.xml";
			}

			// write start of XML data
			streamFileHeader(of);

			int nodeIdx = 0;
			std::map<std::string, std::string> materialScripts;

			while (nodeIdx < nodeCount) {

				std::string mtlName;
				IGameNode* node = m_pGame->GetTopLevelNode(nodeIdx);
				IGameObject* obj = node->GetIGameObject();

				// InitializeData() is important -- it performs all of the WSM/time eval for us; no data without it
				obj->InitializeData();
				
				IGameMaterial* mtl = node->GetNodeMaterial();
				if (mtl == NULL)
					mtlName = m_config.getDefaultMaterialName();
				else
					mtlName = mtl->GetMaterialName();

				// clean out any spaces the user left in their material name
				std::string::size_type pos;
				while ((pos = mtlName.find_first_of(' ')) != std::string::npos)
					mtlName.replace(pos, 1, _T("_"));

				if (materialScripts.find(mtlName) == materialScripts.end()) {

					// export new material script
					MaterialExporter mexp(m_config, m_materialMap);
					std::string script;

					mexp.buildMaterial(mtl, mtlName, script);
					materialScripts[mtlName] = script;
				}

				//if (streamSubmesh(of, node, mtlName))
				if (streamSubmesh(of, obj, mtlName))
					m_submeshNames.push(std::string(node->GetName()));

				node->ReleaseIGameObject();
				nodeIdx++;

				if (m_config.getExportMultipleFiles() || nodeIdx == nodeCount) {

					// write end of this file's XML
					streamFileFooter(of);

					// insert new filename --> stream pair into output map
					output[fileName] = std::string(of.str());
					of.str("");

					if (nodeIdx != nodeCount) {
						fileName = m_config.getExportPath() + "\\";
						node = m_pGame->GetTopLevelNode(nodeIdx);
						fileName += node->GetName();
						fileName += ".mesh.xml";

						// start over again with new data
						streamFileHeader(of);
					}
				}
			}

			m_pGame->ReleaseIGame();

			// export materials if we are writing those
			if (m_config.getExportMaterial()) {

				std::ofstream materialFile;
				materialFile.open((m_config.getExportPath() + "\\" + m_config.getMaterialFilename()).c_str(), std::ios::out);

				if (materialFile.is_open()) {
					for (std::map<std::string, std::string>::iterator it = materialScripts.begin();
						it != materialScripts.end(); ++it)
					{
						materialFile << it->second;
					}

					materialFile.close();
				}
			}

			return true;
		}
		catch (...) {
			MessageBox(GetActiveWindow(), "An unexpected error has occurred while trying to export, aborting", "Error", MB_ICONEXCLAMATION);

			if (m_pGame)
				m_pGame->ReleaseIGame();

			return false;
		}
	}
Exemplo n.º 7
0
	// Load blend shape poses
	bool BlendShape::loadPoses(ParamList &params, std::vector<vertex> &vertices,long numVertices,long offset,long targetIndex)
	{
		if (params.useSharedGeom)
		{
			assert(targetIndex == 0);
			m_target = T_MESH;
		}
		else
		{
			assert(offset == 0);
			poseGroup new_pg;
			m_target = T_SUBMESH;
			new_pg.targetIndex = targetIndex;
			m_poseGroups.insert(std::pair<int,poseGroup>(targetIndex,new_pg));
		}
		poseGroup& pg = m_poseGroups.find(targetIndex)->second;

		if(m_pGameNode && m_pMorphR3)
		{
            // Disable all skin Modifiers.
            std::vector<Modifier*> disabledSkinModifiers;
            IGameObject* pGameObject = m_pGameNode->GetIGameObject();
            if( pGameObject )
            {
                int numModifiers = pGameObject->GetNumModifiers();
                for( int i = 0; i < numModifiers; ++i )
                {
                    IGameModifier* pGameModifier = pGameObject->GetIGameModifier(i);
                    if( pGameModifier )
                    {
                        if( pGameModifier->IsSkin() )
                        {
                            Modifier* pModifier = pGameModifier->GetMaxModifier();
                            if( pModifier )
                            {
                                if( pModifier->IsEnabled() )
                                {
                                    disabledSkinModifiers.push_back(pModifier);
                                    pModifier->DisableMod();
                                }
                            }
                        }
                    }
                }
            }

			// Get the original mesh from the IGameNode.  Not using IGame here
			// since MorphR3 doesn't allow for it.  Also we don't know if our vertices
			// are in object or world space, so we'll just calculate diffs directly from 
			// the Max meshes and modify the coordinate system manually.  
			// Obtained method of getting mesh from 3D Studio Max SDK Training session by
			// David Lanier.
 			bool DeleteObjectWhenDone;
			const ObjectState& objectState = m_pGameNode->GetMaxNode()->EvalWorldState(GetCOREInterface()->GetTime());
			Object *origMeshObj = objectState.obj;
			if (!origMeshObj->CanConvertToType(Class_ID(TRIOBJ_CLASS_ID, 0)))
			{
				FxOgreMaxExporterLog( "Could not access original mesh for morph target comparison.");
				return false;
			}

			// Calculate the DiffTM matrix.  This is the difference between the INode's world transform
			// which is used to calculate the morph verticies, and the IGameNode's world transform, which is used
			// to calculate the Ogre mesh's verticies.
			Matrix3 DiffTM = m_pGameNode->GetObjectTM(GetCOREInterface()->GetTime()).ExtractMatrix3();

			// The below code is not well tested as FaceFX needs content in the native coordinates.
			// I've seen the direction of the morph movement flipped on some content when in Y-up mode 
			// which sets the coordinate system to IGAME_OGL.
			// I can't get this to work on all the morph examples I have however.
			IGameConversionManager* pConversionManager = GetConversionManager();
			if(IGameConversionManager::IGAME_OGL == pConversionManager->GetCoordSystem())
			{			
				Matrix3 conv = Matrix3(Point3(1,0,0), Point3(0,0,1), Point3(0,-1,0), Point3(0,0,0));
				DiffTM = DiffTM * conv;
			}

			TriObject *origMeshTriObj = (TriObject *) origMeshObj->ConvertToType(GetCOREInterface()->GetTime(), Class_ID(TRIOBJ_CLASS_ID, 0));
			if (origMeshObj != origMeshTriObj) DeleteObjectWhenDone = true;
			Mesh& origMesh = origMeshTriObj->GetMesh();
			const int NumVerts = origMesh.getNumVerts();
 

			for( int i = 0; i < m_pMorphR3->chanBank.size() && i < MR3_NUM_CHANNELS; ++i )
			{
				if( m_pMorphR3->chanBank[i].mActive )
				{
					morphChannel* pMorphChannel = &m_pMorphR3->chanBank[i];	
					if( pMorphChannel )
					{
						pMorphChannel->rebuildChannel();

						std::string posename = string_tools::string_cast<ogre_string_type>(pMorphChannel->mName.data());
						int numMorphVertices = pMorphChannel->mNumPoints;
						
						if( numMorphVertices != origMesh.getNumVerts() )
						{
							MessageBox(GetCOREInterface()->GetMAXHWnd(), _T("Morph targets have failed to export becuase the morph vertex count did not match the base mesh.  Collapse the modifier stack prior to export, as smoothing is not supported with morph target export."), _T("Morph Target Export Failed."), MB_OK);
							return false;
						}
						else
						{
							FxOgreMaxExporterLog( "Exporting Morph target: %s with %d vertices.\n", posename.c_str(), numMorphVertices);
							FxOgreMaxExporterLog( "Mesh has %d vertices.\n", numVertices);
							FxOgreMaxExporterLog( "%d total vertices.\n", vertices.size());
							assert(offset+numVertices <= vertices.size());
							// create a new pose
							pose p;
							p.poseTarget = m_target;
							p.index = targetIndex;
							p.blendShapeIndex = i;
							p.name = posename;
							p.pMChannel = pMorphChannel;

							size_t numPoints = pMorphChannel->mPoints.size();
							std::vector<Point3> vmPoints;
							vmPoints.reserve(numPoints);
							for( size_t k = 0; k < numPoints; ++k )
							{
								vmPoints.push_back(pMorphChannel->mPoints[k]);
							}

							Box3 morphBoundingBox;
							// calculate vertex offsets
							for (int k=0; k<numVertices; k++)
							{
								vertexOffset vo;
								assert ((offset+k)<vertices.size());

								vertex v = vertices[offset+k];
								assert(v.index < numMorphVertices);
								assert(v.index < origMesh.getNumVerts());

								Point3 meshVert = origMesh.getVert(v.index);
								Point3 morphVert = vmPoints[v.index];

								Point3 diff = morphVert - meshVert;

								// Transform our morph vertex movements by whatever
								// scaling/rotation is being done by IGame..
								Point3 ogreSpacediff = DiffTM.VectorTransform(diff);


								// Add this point to the bounding box
								morphBoundingBox += morphVert;

								vo.x = ogreSpacediff.x * params.lum;
								vo.y = ogreSpacediff.y * params.lum;
								vo.z = ogreSpacediff.z * params.lum;	

								vo.index = offset+k;
								if (fabs(vo.x) < PRECISION)
									vo.x = 0;
								if (fabs(vo.y) < PRECISION)
									vo.y = 0;
								if (fabs(vo.z) < PRECISION)
									vo.z = 0;
								if ((vo.x!=0) || (vo.y!=0) || (vo.z!=0))
									p.offsets.push_back(vo);
							}
							// add pose to pose list
							if (p.offsets.size() > 0)
							{
								pg.poses.push_back(p);
							}
							if (params.bsBB)
							{
								// update bounding boxes of loaded submeshes
								for (int j=0; j<params.loadedSubmeshes.size(); j++)
								{
									Point3 min = morphBoundingBox.Min() * params.lum;
									Point3 max = morphBoundingBox.Max() * params.lum;
									// Update coordinate system here.
									Point3 newMin, newMax;
									newMin.x = min.x;
									newMin.y = min.z;
									newMin.z = min.y;
									Box3 newBox(newMin, newMax);
									if (params.exportWorldCoords)
										newBox = newBox * m_pGameNode->GetWorldTM(GetCOREInterface()->GetTime()).ExtractMatrix3();
									params.loadedSubmeshes[j]->m_boundingBox += newBox;
								}
							}
						}

					}
				}
			}
            // Re-enable skin modifiers.
            for( int i = 0; i < disabledSkinModifiers.size(); ++i )
            {
                disabledSkinModifiers[i]->EnableMod();
            }
			// According to David Lanier, this should be deleted, but I get crashes when exporting blendShapes
			// without shared geometry when I use the object for the second time.  Perhaps it
			// can only be used/deleted once.  Even without shared geometry, I'll get a strange crash
			// a few seconds after successful export with this here.
//			if (DeleteObjectWhenDone)
//				origMeshTriObj->DeleteMe();
		}
		return true;
	}
Exemplo n.º 8
0
void MeshExporter::Export()
{
	mRoot = new Root;
	mResourceManager = new ResourceManager;
	mRenderSystem = new NullRenderSystem;
	mWorld = new World;

	try 
	{
		IGameConversionManager* cm = GetConversionManager();
		cm->SetCoordSystem(IGameConversionManager::IGAME_D3D);
		mGameScene->InitialiseIGame(ExportConfig::Instance()->IsExportSelected());
		mGameScene->SetStaticFrame(0);

		int nodeCount = mGameScene->GetTopLevelNodeCount();
		if (nodeCount == 0)
		{
			MessageBox(GetActiveWindow(), "No nodes available!", "Error", MB_OK);
			goto __end;
		}

		mMeshSource = MeshManager::Instance()->NewMesh("MaxExporter");

		// extract skeleton
		for (int i = 0; i < nodeCount; ++i)
		{
			IGameNode* node = mGameScene->GetTopLevelNode(i);

			if (node->IsNodeHidden())
				continue ;

			ExtractSkeleton(node);
		}

		// extract mesh
		mMeshData.Clear();

		for (int i = 0; i < nodeCount; ++i)
		{
			IGameNode* node = mGameScene->GetTopLevelNode(i);

			if (node->IsNodeHidden())
				continue ;

			ExtractMesh(node);
		}

		if (mMMPairs.Size() == 0)
		{
			MessageBox(GetActiveWindow(), "No Objects!", "Error", MB_OK);
			goto __end;
		}

		BuildMesh();

		// save mesh
		MeshSerializer::Save(mMeshSource.c_ptr(), ExportConfig::Instance()->GetExportFilename());

		MessageBox(GetActiveWindow(), "Export OK!", "Info", MB_ICONINFORMATION);
	}
	catch (...) 
	{
		MessageBox(GetActiveWindow(), "Error!", "Error", MB_ICONEXCLAMATION);
	}

__end:
	mMeshSource = NULL;

	delete mWorld;
	delete mRenderSystem;
	delete mResourceManager;
	delete mRoot;
}