BOOL MeshExpUtility::BuildObject(CEditableObject*& exp_obj, LPCSTR m_ExportName) { bool bResult = true; if (m_ExportName[0]==0) return false; ELog.Msg(mtInformation,"Building object..." ); char fname[256]; _splitpath( m_ExportName, 0, 0, fname, 0 ); exp_obj = xr_new<CEditableObject>(fname); exp_obj->SetVersionToCurrent(TRUE,TRUE); ExportItemIt it = m_Items.begin(); for(;it!=m_Items.end();it++){ CEditableMesh *submesh = xr_new<CEditableMesh>(exp_obj); ELog.Msg(mtInformation,"Converting node '%s'...", it->pNode->GetName()); if( submesh->Convert(it->pNode) ){ // transform Matrix3 mMatrix; mMatrix = it->pNode->GetNodeTM(0)*Inverse(it->pNode->GetParentNode()->GetNodeTM(0)); Point3 r1 = mMatrix.GetRow(0); Point3 r2 = mMatrix.GetRow(1); Point3 r3 = mMatrix.GetRow(2); Point3 r4 = mMatrix.GetRow(3); Fmatrix m; m.identity(); m.i.set(r1.x, r1.z, r1.y); m.j.set(r2.x, r2.z, r2.y); m.k.set(r3.x, r3.z, r3.y); m.c.set(r4.x, r4.z, r4.y); submesh->Transform( m ); // flip faces Fvector v; v.crossproduct(m.j, m.k); if(v.dotproduct(m.i)<0.f) submesh->FlipFaces(); if(m_ObjectFlipFaces) submesh->FlipFaces(); submesh->RecomputeBBox(); // append mesh submesh->SetName (it->pNode->GetName()); exp_obj->m_Meshes.push_back (submesh); }else{ ELog.Msg(mtError,"! can't convert", it->pNode->GetName()); xr_delete(submesh); bResult = false; break; } } if (bResult){ exp_obj->UpdateBox (); exp_obj->VerifyMeshNames(); ELog.Msg (mtInformation,"Object '%s' contains: %d points, %d faces", exp_obj->GetName(), exp_obj->GetVertexCount(), exp_obj->GetFaceCount()); }else{ xr_delete(exp_obj); } //------------------------------------------------------------------- return bResult; }
//---------------------------------------------------------------------------- // Skeleton functions //---------------------------------------------------------------------------- bool CEditableObject::ImportMAXSkeleton(CExporter* E) { bool bResult = true; CEditableMesh* MESH = xr_new<CEditableMesh>(this); m_Meshes.push_back(MESH); // import mesh if (!MESH->Convert(E)) return FALSE; // BONES m_Bones.reserve(E->m_Bones.size()); for (int B=0; B!=E->m_Bones.size(); B++){ m_Bones.push_back(xr_new<CBone>()); CBone* BONE = m_Bones.back(); CBoneDef* bone = E->m_Bones[B]; CBoneDef* parent_bone = bone->parent; Fvector offset,rotate; float length= 0.1f; Fmatrix m; if (parent_bone) m.mul(parent_bone->matOffset,bone->matInit); else m.set(bone->matInit); m.getXYZi (rotate); offset.set (m.c); BONE->SetWMap (bone->name.c_str()); BONE->SetName (bone->name.c_str()); BONE->SetParentName (Helper::ConvertSpace(string(bone->pBone->GetParentNode()->GetName())).c_str()); BONE->SetRestParams (length,offset,rotate); } // DEFAULT BONE PART m_BoneParts.push_back(SBonePart()); SBonePart& BP = m_BoneParts.back(); BP.alias = "default"; for (int b_i=0; b_i<(int)m_Bones.size(); b_i++) BP.bones.push_back(Bones()[b_i]->Name()); m_objectFlags.set(CEditableObject::eoDynamic,TRUE); if ((0==GetVertexCount())||(0==GetFaceCount())){ bResult = false; }else{ ELog.Msg(mtInformation,"Model '%s' contains: %d points, %d faces, %d bones", E->m_MeshNode->GetName(), GetVertexCount(), GetFaceCount(), Bones().size()); } return bResult; }