void CModelExporter::Export(const char* pszFileName) { m_serializer.Reset(); size_t uTotalRootNodeCnt = m_pIGameScene->GetTopLevelNodeCount(); std::vector<IGameNode*> meshNodeVector; for(size_t x = 0; x < uTotalRootNodeCnt; x++) { IGameNode* pNode = m_pIGameScene->GetTopLevelNode(x); IGameObject* pObject = pNode->GetIGameObject(); IGameObject::ObjectTypes gameType = pObject->GetIGameType(); if(gameType == IGameObject::IGAME_MESH) { meshNodeVector.push_back(pNode); } } int uMeshNodeCount = meshNodeVector.size(); m_serializer << uMeshNodeCount; for(auto pNode : meshNodeVector) { ExportMesh(pNode); } m_serializer.Deserialize(pszFileName); }
void MeshExporter::_dumpJoint(IGameNode * node) { IGameObject * obj = node->GetIGameObject(); IGameObject::MaxType T = obj->GetMaxType(); IGameObject::ObjectTypes type = obj->GetIGameType(); const char * name = node->GetName(); switch(type) { case IGameObject::IGAME_BONE: case IGameObject::IGAME_HELPER: { joint * bone = mMeshSource->NewJoint(node->GetName()); int parent = -1; if (node->GetNodeParent()) { parent = _getJointId(node->GetNodeParent()->GetName()); mMeshSource->SetJointLink(parent, mMeshSource->GetJointCount() - 1); } else { INode* pNode = node->GetMaxNode()->GetParentNode(); if (pNode) parent = _getJointId(pNode->GetName()); } IGameControl * pGameControl = node->GetIGameControl(); // base matrix { GMatrix matWorld = node->GetLocalTM(); bone->position = Utility::ToFloat3(matWorld.Translation()); bone->rotation = Utility::ToQuat(matWorld.Rotation()); bone->scale = Utility::ToFloat3(matWorld.Scaling()); /* if (node->GetNodeParent()) { int parentId = _getBoneId(node->GetNodeParent()->GetName()); if (parentId != -1) { xBone * parentBn = GetBone(parentId); bone->position = bone->position - parentBn->position; bone->orientation = parentBn->orientation.Inverse() * bone->orientation; bone->scale = bone->scale / parentBn->scale; } } */ } _dumpAnimation(pGameControl, mMeshSource->GetJointCount() - 1); } break; } }
void Unreal3DExport::ExportNode( IGameNode * child ) { DebugPrint( _T("ExportNode: %s\n"), child->GetName() ); CheckCancel(); ProgressMsg.printf(GetString(IDS_INFO_ENUM_OBJ),NodeIdx,NodeCount,TSTR(child->GetName())); pInt->ProgressUpdate(Progress+((float)NodeIdx/NodeCount*U3D_PROGRESS_ENUM), FALSE, ProgressMsg.data()); ++NodeIdx; if( child->IsGroupOwner() ) { // do nothing } else { IGameObject * obj = child->GetIGameObject(); switch(obj->GetIGameType()) { case IGameObject::IGAME_MESH: { if( !bIgnoreHidden || !child->IsNodeHidden() ) { Nodes.Append(1,&child); } break; } case IGameObject::IGAME_HELPER: { if( !bIgnoreHidden || !child->IsNodeHidden() ) { TrackedNodes.Append(1,&child); } } break; } child->ReleaseIGameObject(); } for( int i=0; i<child->GetChildCount(); ++i ) { IGameNode * n = child->GetNodeChild(i); ExportNode(n); } }
void TrianExporter::ExportNodeInfo( IGameNode * node ) { //If the node is a group owner, do nothing with it. if( !node->IsGroupOwner() ) { //Get the game object. IGameObject * obj = node->GetIGameObject(); //We will only dump the info if it is a IGAME_MESH. if( obj->GetIGameType() == IGameObject::IGAME_MESH ) { //Get the Mesh. IGameMesh * gm = ( IGameMesh * )obj; //If initialization works, dump the mesh. if( gm->InitializeData() ) DumpMesh( gm ); } } }
void MaxAWDExporter::ProcessGeoBlocks() { AWDTriGeom *geoBlock; AWDBlockIterator *it; int proccessed=0; it = new AWDBlockIterator(awd->get_mesh_data_blocks()); UpdateProgressBar(MAXAWD_PHASE_PROCESS_GEOMETRY, (double)proccessed/(double)awd->get_mesh_data_blocks()->get_num_blocks()); INodeTab lNodes; while ((geoBlock = (AWDTriGeom * ) it->next()) != NULL){ INode * node = (INode *)INodeToGeoBlockCache->Get(geoBlock); if (node==NULL){ AWDMessageBlock * newWarning = new AWDMessageBlock(geoBlock->get_name(), "ERROR: Could not find the INode for this AWDGeometry."); awd->get_message_blocks()->append(newWarning); return; } lNodes.AppendNode( node ); } IGameScene* _pIgame = NULL; _pIgame = GetIGameInterface(); _pIgame->InitialiseIGame( lNodes ); it->reset(); while ((geoBlock = (AWDTriGeom * ) it->next()) != NULL){ INode * node = (INode *)INodeToGeoBlockCache->Get(geoBlock); if (node==NULL){ AWDMessageBlock * newWarning = new AWDMessageBlock(geoBlock->get_name(), "ERROR: Could not find the INode for this AWDGeometry."); awd->get_message_blocks()->append(newWarning); } else{ int exportThis=false; IGameObject * gobj = NULL; IGameMesh * igame_mesh = NULL; gobj = GetIGameInterface()->GetIGameNode(node)->GetIGameObject(); if(gobj->GetIGameType()==IGameObject::IGAME_MESH){ igame_mesh = (IGameMesh*)gobj; if (igame_mesh!=NULL){ igame_mesh->InitializeData(); if(igame_mesh->GetNumberOfFaces()>0){ exportThis=true; } } } if (exportThis){ Object *obj; obj = node->GetObjectRef(); int skinIdx; ObjectState os; IDerivedObject *derivedObject = NULL; skinIdx = IndexOfSkinMod(node->GetObjectRef(), &derivedObject); if (skinIdx >= 0) { // Flatten all modifiers up to but not including // the skin modifier. // to do: get the correct time for the neutral-pose os = derivedObject->Eval(0, skinIdx + 1); } else { // Flatten entire modifier stack // to do: get the correct time for the neutral-pose os = node->EvalWorldState(maxInterface->GetTime()); } obj = os.obj; ISkin *skin = NULL; if (derivedObject != NULL && skinIdx >= 0) { Modifier *mod = derivedObject->GetModifier(skinIdx); skin = (ISkin *)mod->GetInterface(I_SKIN); } ExportTriGeom(geoBlock,obj,node,skin, igame_mesh); RETURN_IF_ERROR; } } proccessed++; UpdateProgressBar(MAXAWD_PHASE_PROCESS_GEOMETRY, (double)proccessed/(double)awd->get_mesh_data_blocks()->get_num_blocks()); } delete it; _pIgame->ReleaseIGame(); }
ExporterF3D::EExportError ExporterF3D::ExportNode(IGameNode* node, u32 index, CNode* parent) { IGameObject* gameObject = node->GetIGameObject(); int numChildren = node->GetChildCount(); LOG_INFO("Child count [%d]", numChildren); INode* maxNode = node->GetMaxNode(); IGameObject::ObjectTypes objectType = gameObject->GetIGameType(); if (!m_settings->isExportLights() && objectType == IGameObject::IGAME_LIGHT) { LOG_WARNING("Skip export Ligth: %s", TCHARToString(node->GetName()).c_str()); return eNoError; } else if (!m_settings->isExportCameras() && objectType == IGameObject::IGAME_CAMERA) { LOG_WARNING("Skip export Camera: %s", TCHARToString(node->GetName()).c_str()); return eNoError; } CNode* object = m_scene->createNode(objectType); if (!object) { switch (objectType) { case IGameObject::IGAME_HELPER: LOG_WARNING("Export not supported type: %d", objectType); return eNoError; default: LOG_ERROR("Export unknown type: %d", objectType); return eUnknownError; } } object->setName(TCHARToString(node->GetName())); object->setID(node->GetNodeID()); switch (objectType) { case IGameObject::IGAME_MESH: { LOG_INFO("Export IGAME_MESH: %s", TCHARToString(node->GetName()).c_str()); CMesh* mesh = static_cast<CMesh*>(object); if (!ExportMesh(node, mesh)) { delete object; object = nullptr; return eNodeMeshError; } } break; case IGameObject::IGAME_LIGHT: { LOG_INFO("Export IGAME_LIGHT: %s", TCHARToString(node->GetName()).c_str()); CLight* light = static_cast<CLight*>(object); if (!ExportLight(node, light)) { delete object; object = nullptr; return eNodeLightError; } } break; case IGameObject::IGAME_CAMERA: { LOG_INFO("Export IGAME_CAMERA: %s", TCHARToString(node->GetName()).c_str()); CCamera* camera = static_cast<CCamera*>(object); if (!ExportCamera(node, camera)) { delete object; object = nullptr; return eNodeCameraError; } } break; default: { delete object; object = nullptr; LOG_WARNING("Export unknown type: %d", objectType); return eUnknownError; } } if (parent) { parent->attachChild(object); } m_scene->addNode(std::make_pair(objectType, object)); for (u32 i = 0; i < numChildren; ++i) { LOG_INFO("Processing child [%d/%d:%s] ", i + 1, numChildren, TCHARToString(node->GetName()).c_str()); IGameNode* childNode = node->GetNodeChild(i); EExportError error = ExportNode(childNode, i, object); if (error != eNoError) { return error; } } LOG_INFO("Export Node %s completed\n", TCHARToString(node->GetName()).c_str()); return eNoError; }
void MeshExporter::ExtractMesh(IGameNode * node) { IGameObject* obj = node->GetIGameObject(); // export option bool expColor = ExportConfig::Instance()->IsExportColor(); bool expNormal = ExportConfig::Instance()->IsExportNormal(); bool expTexcoord = ExportConfig::Instance()->IsExportTexcoord(); bool expLightmapUV = ExportConfig::Instance()->IsExportLightmapUV(); obj->InitializeData(); const char * nodeName = node->GetName(); IGameNode * parent = node->GetNodeParent(); IGameMesh::ObjectTypes type = obj->GetIGameType(); if (type == IGameMesh::IGAME_MESH) { IGameMesh* mesh = (IGameMesh*) obj; Tab<int> texMaps = mesh->GetActiveMapChannelNum(); mMeshData.VertexElems |= MeshSerializer::VE_POSITION; // position for (int i = 0; i < mesh->GetNumberOfVerts(); ++i) mMeshData.P.PushBack(Utility::ToFloat3(mesh->GetVertex(i))); // vertex color for (int i = 0; expColor && i < mesh->GetNumberOfColorVerts(); ++i) { Point3 c = mesh->GetColorVertex(i); float a = mesh->GetAlphaVertex(i); mMeshData.C.PushBack(Float4(c.x, c.y, c.z, a)); mMeshData.VertexElems |= MeshSerializer::VE_COLOR; } // normal for (int i = 0; expNormal && i < mesh->GetNumberOfNormals(); ++i) { mMeshData.N.PushBack(Utility::ToFloat3(mesh->GetNormal(i))); mMeshData.VertexElems |= MeshSerializer::VE_NORMAL; } // uv for (int i = 0; expTexcoord && texMaps.Count() > 1 && i < mesh->GetNumberOfMapVerts(texMaps[1]); ++i) { Point3 tv = mesh->GetMapVertex(texMaps[1], i); mMeshData.UV.PushBack(Float2(tv.x, 1 - tv.y)); mMeshData.VertexElems |= MeshSerializer::VE_TEXCOORD; } // light map uv for (int i = 0; expLightmapUV && texMaps.Count() > 2 && i < mesh->GetNumberOfMapVerts(texMaps[2]); ++i) { Point3 tv = mesh->GetMapVertex(texMaps[2], i); mMeshData.LUV.PushBack(Float2(tv.x, 1 - tv.y)); mMeshData.VertexElems |= MeshSerializer::VE_LIGHTMAPUV; } IGameSkin * skin = obj->GetIGameSkin(); if (skin != NULL) _dumpSkinInfo(skin); else if (parent != NULL && parent->GetIGameObject()->GetIGameType() == IGameMesh::IGAME_BONE) _genSkinInfo(parent); _dumpMeshBuffer(mesh); mMeshData.Clear(); } for(int i=0;i<node->GetChildCount();i++) { IGameNode * child = node->GetNodeChild(i); // we deal with targets in the light/camera section if(child->IsTarget()) continue; ExtractMesh(child); } node->ReleaseIGameObject(); }
void MaxExporter::findFaces( Node* myNode, ofstream& myFile ) { myFile << "NewNode\n"; if( myNode != nullptr && myNode->m_gameNode != nullptr ) { IGameObject* gameObject = myNode->m_gameNode->GetIGameObject(); if( gameObject != nullptr ) { m_boneIDToNodeID[ myNode->m_gameNode->GetNodeID() ] = myNode->m_id; //gameObject->InitializeData(); if( gameObject->GetIGameType() == IGameObject::IGAME_MESH ) { myFile << "Is a game mesh \n"; IGameMesh* gameMesh = (IGameMesh*)gameObject; if( gameMesh != nullptr) { gameMesh->InitializeData(); int numberOfFaces = gameMesh->GetNumberOfFaces(); //std::map< IGameMaterial*, TriangleBatch* > triangleBatches; //std::map<IGameMaterial*, std::vector< NodeFace > > nodeFacePerMat; for( int i = 0; i < numberOfFaces; ++i ) { FaceEx* meshFace = gameMesh->GetFace( i ); NodeFace nodeFace( gameMesh, meshFace ); IGameMaterial* gameMaterial = gameMesh->GetMaterialFromFace( meshFace ); m_materialSet.insert( gameMaterial ); auto found = myNode->m_triangleBatchesPerMaterial.find( gameMaterial ); if( found == myNode->m_triangleBatchesPerMaterial.end() ) { MaxMaterial* material = new MaxMaterial( gameMaterial ); myNode->m_triangleBatchesPerMaterial[ gameMaterial ] = new TriangleBatch( material, new VBO(), new IBO() ); std::vector< NodeFace > faces; faces.push_back(nodeFace); myNode->m_facesPerMaterial[ gameMaterial ] = faces; } else { auto findFace = myNode->m_facesPerMaterial.find( gameMaterial ); findFace->second.push_back( nodeFace ); } } //myNode->addNodeFaces( nodeFacePerMat ); //m_triangleBatchesPerNode[gameNode] = triangleBatches; } } } int childCount = myNode->m_gameNode->GetChildCount(); myFile<< childCount << "\n"; for( int j = 0; j < childCount; ++j ) { IGameNode* childGameNode = myNode->m_gameNode->GetNodeChild( j ); if( childGameNode != nullptr ) { Node* childNode = new Node( childGameNode ); childNode->setParent( myNode ); m_NodeList.push_back( childNode ); findFaces( childNode, myFile ); } } //gameNode->ReleaseIGameObject(); } }
//[-------------------------------------------------------] //[ Private virtual PLSceneNode functions ] //[-------------------------------------------------------] void PLSceneSpline::WriteToFile(XmlElement &cSceneElement, const String &sApplicationDrive, const String &sApplicationDir) { // Do NOT save it as scene node, it's just a 'resource' // Get path filename const String sFilename = sApplicationDrive + sApplicationDir + PLTools::GetResourceFilename(PLTools::ResourcePath, GetName() + ".path"); // Get the IGame spline object of the given IGame node IGameObject *pIGameObject = GetIGameNode()->GetIGameObject(); if (pIGameObject) { // Check the type of the IGame object if (pIGameObject->GetIGameType() == IGameObject::IGAME_SPLINE && pIGameObject->InitializeData()) { IGameSpline &cIGameSpline = *static_cast<IGameSpline*>(pIGameObject); if (cIGameSpline.GetNumberOfSplines () > 0) { // We only support spline 0 IGameSpline3D *pIGameSpline3D = cIGameSpline.GetIGameSpline3D(0); if (pIGameSpline3D) { // Get the local transform matrix GMatrix mTransform = cIGameSpline.GetIGameObjectTM(); // Get the 3ds Max shape object ShapeObject *pMaxShapeObject = static_cast<ShapeObject*>(pIGameObject->GetMaxObject()->ConvertToType(TIME_PosInfinity, Class_ID(GENERIC_SHAPE_CLASS_ID, 0))); if (pMaxShapeObject != nullptr && pMaxShapeObject->NumberOfCurves() == cIGameSpline.GetNumberOfSplines()) { // Create XML document XmlDocument cDocument; // Add declaration XmlDeclaration *pDeclaration = new XmlDeclaration("1.0", "ISO-8859-1", ""); cDocument.LinkEndChild(*pDeclaration); // Add path XmlElement *pPathElement = new XmlElement("Path"); // Setup attributes pPathElement->SetAttribute("Version", "1"); pPathElement->SetAttribute("Closed", String::Format("%d", pMaxShapeObject->CurveClosed(0, 0))); // Add all nodes for (int nKnot=0; nKnot<pIGameSpline3D->GetIGameKnotCount(); nKnot++) { IGameKnot *pIGameKnot = pIGameSpline3D->GetIGameKnot(nKnot); if (pIGameKnot) { // Get knot point in object space (although it is not documented it looks like object space...) Point3 cPoint = pIGameKnot->GetKnotPoint(); // We really need to flip the coordinates to OpenGL style, IGame is not doing this automatically... cPoint = PLTools::Convert3dsMaxVectorToOpenGLVector(cPoint); // Transform to world space cPoint = cPoint*mTransform; // If there's a parent container, make the position of this scene node relative to it PLSceneContainer *pContainer = GetContainer(); if (pContainer) cPoint -= pContainer->GetWorldSpaceCenter(); // Add node XmlElement *pNodeElement = new XmlElement("Node"); pNodeElement->SetAttribute("Name", String::Format("%d", nKnot)); pNodeElement->SetAttribute("Position", String::Format("%f %f %f", cPoint.x, cPoint.y, cPoint.z)); // Link general element pPathElement->LinkEndChild(*pNodeElement); } } // Link material element cDocument.LinkEndChild(*pPathElement); // Save settings if (cDocument.Save(sFilename)) g_pLog->LogFLine(PLLog::Hint, "Created '%s'", sFilename.GetASCII()); else g_pLog->LogFLine(PLLog::Error, "Can't create '%s'!", sFilename.GetASCII()); } } } } else { g_pLog->LogFLine(PLLog::Error, "%s: IGame object is no known spline object!", GetIGameNode()->GetName()); } // Release the IGame object GetIGameNode()->ReleaseIGameObject(); } else { g_pLog->LogFLine(PLLog::Error, "%s: IGame node has no IGame object!", GetIGameNode()->GetName()); } }