bool SceneBuilder::BuildSOMModel() { BOOL bResult = TRUE; CMemoryWriter F; F.open_chunk (0); F.w_u32 (0); F.close_chunk (); F.open_chunk (1); ObjectList& lst = Scene->ListObj(OBJCLASS_SCENEOBJECT); for (ObjectIt it=lst.begin(); it!=lst.end(); it++){ CSceneObject* S = (CSceneObject*)(*it); CEditableObject* E = S->GetReference(); R_ASSERT(E); if (E->m_Flags.is(CEditableObject::eoSoundOccluder)){ Fvector v; const Fmatrix& parent = S->_Transform(); for (EditMeshIt m_it=E->FirstMesh(); m_it!=E->LastMesh(); m_it++){ for (SurfFacesPairIt sf_it=(*m_it)->m_SurfFaces.begin(); sf_it!=(*m_it)->m_SurfFaces.end(); sf_it++){ CSurface* surf = sf_it->first; int gm_id = surf->_GameMtl(); if (gm_id==GAMEMTL_NONE_ID){ ELog.DlgMsg (mtError,"Object '%s', surface '%s' contain invalid game material.",(*m_it)->Parent()->m_LibName.c_str(),surf->_Name()); bResult = FALSE; break; } SGameMtl* mtl = GMLib.GetMaterialByID(gm_id); if (0==mtl){ ELog.DlgMsg (mtError,"Object '%s', surface '%s' contain undefined game material.",(*m_it)->Parent()->m_LibName.c_str(),surf->_Name()); bResult = FALSE; break; } BOOL b2Sided = surf->m_Flags.is(CSurface::sf2Sided); IntVec& i_lst = sf_it->second; for (IntIt i_it=i_lst.begin(); i_it!=i_lst.end(); i_it++){ st_Face& face = (*m_it)->m_Faces[*i_it]; for (int k=0; k<3; k++){ parent.transform_tiny(v,(*m_it)->m_Verts[face.pv[k].pindex]); F.w_fvector3(v); } F.w_u32 (b2Sided); F.w_float (mtl->fSndOcclusionFactor); } } } } } BOOL bValid = !!F.chunk_size()&&bResult; F.close_chunk(); if (bValid){ xr_string som_name = MakeLevelPath("level.som"); bValid = F.save_to(som_name.c_str()); } return bValid; }
BOOL GetStaticCformData( CSceneObject* obj,mesh_build_data &data, bool b_selected_only ) { Fmatrix T = obj->_Transform(); CEditableObject *O = obj->GetReference(); for(EditMeshIt M=O->FirstMesh();M!=O->LastMesh();M++){ // CSector* S = PortalUtils.FindSector(obj,*M); // int sect_num = S?S->m_sector_num:m_iDefaultSectorNum; // if (!BuildMesh(T,O,*M,sect_num,l_verts,l_vert_cnt,l_vert_it,l_faces,l_face_cnt,l_face_it,l_smgroups,obj->_Transform())) if(!::GetStaticCformData(T,*M,O,data.l_verts,data.l_vert_cnt,data.l_vert_it,data.l_faces,data.l_face_cnt,data.l_face_it) ) return FALSE; } return FALSE; }
//---------------------------------------------------- // some types bool SceneBuilder::BuildHOMModel() { CMemoryWriter F; F.open_chunk(0); F.w_u32(0); F.close_chunk(); F.open_chunk(1); ObjectList& lst = Scene->ListObj(OBJCLASS_SCENEOBJECT); for (ObjectIt it=lst.begin(); it!=lst.end(); it++){ CSceneObject* S = (CSceneObject*)(*it); CEditableObject* E = S->GetReference(); R_ASSERT(E); if (E->m_Flags.is(CEditableObject::eoHOM)){ Fvector v; const Fmatrix& parent = S->_Transform(); for (EditMeshIt m_it=E->FirstMesh(); m_it!=E->LastMesh(); m_it++){ for (SurfFacesPairIt sf_it=(*m_it)->m_SurfFaces.begin(); sf_it!=(*m_it)->m_SurfFaces.end(); sf_it++){ BOOL b2Sided = sf_it->first->m_Flags.is(CSurface::sf2Sided); IntVec& i_lst= sf_it->second; for (IntIt i_it=i_lst.begin(); i_it!=i_lst.end(); i_it++){ st_Face& face = (*m_it)->m_Faces[*i_it]; for (int k=0; k<3; k++){ parent.transform_tiny(v,(*m_it)->m_Verts[face.pv[k].pindex]); F.w_fvector3 (v); } F.w_u32(b2Sided); } } } } } BOOL bValid = !!F.chunk_size(); F.close_chunk(); if (bValid){ xr_string hom_name = MakeLevelPath("level.hom"); bValid = F.save_to(hom_name.c_str()); } return bValid; }
bool ESceneObjectTool::ExportBreakableObjects(SExportStreams* F) { bool bResult = true; CGeomPartExtractor* extractor=0; Fbox bb; if (!GetBox(bb)) return false; extractor = xr_new<CGeomPartExtractor>(); extractor->Initialize(bb,EPS_L,2); UI->SetStatus ("Export breakable objects..."); // collect verts&&faces { SPBItem* pb = UI->ProgressStart(m_Objects.size(),"Prepare geometry..."); for (ObjectIt it=m_Objects.begin(); it!=m_Objects.end(); it++){ pb->Inc(); CSceneObject* obj = dynamic_cast<CSceneObject*>(*it); VERIFY(obj); if (obj->IsStatic()){ CEditableObject *O = obj->GetReference(); const Fmatrix& T = obj->_Transform(); for(EditMeshIt M=O->FirstMesh();M!=O->LastMesh();M++) if (!build_mesh (T,*M,extractor,SGameMtl::flBreakable,FALSE)){bResult=false;break;} } } UI->ProgressEnd(pb); } if (!extractor->Process()) bResult = false; // export parts if (bResult){ SBPartVec& parts = extractor->GetParts(); SPBItem* pb = UI->ProgressStart(parts.size(),"Export Parts..."); for (SBPartVecIt p_it=parts.begin(); p_it!=parts.end(); p_it++){ pb->Inc(); SBPart* P = *p_it; if (P->Valid()){ // export visual AnsiString sn = AnsiString().sprintf("meshes\\brkbl#%d.ogf",(p_it-parts.begin())); xr_string fn = Scene->LevelPath()+sn.c_str(); IWriter* W = FS.w_open(fn.c_str()); R_ASSERT(W); if (!P->Export(*W,1)){ ELog.DlgMsg (mtError,"Invalid breakable object."); bResult = false; break; } FS.w_close (W); // export spawn object { AnsiString entity_ref = "breakable_object"; ISE_Abstract* m_Data = create_entity(entity_ref.c_str()); VERIFY(m_Data); CSE_Visual* m_Visual = m_Data->visual(); VERIFY(m_Visual); // set params m_Data->set_name (entity_ref.c_str()); m_Data->set_name_replace (sn.c_str()); m_Data->position().set (P->m_RefOffset); m_Data->angle().set (P->m_RefRotate); m_Visual->set_visual (sn.c_str(),false); if (s_draw_dbg){ Fmatrix MX; MX.setXYZi (P->m_RefRotate); MX.translate_over (P->m_RefOffset); Fvector DR = {0,0,1}; MX.transform_dir (DR); Tools->m_DebugDraw.AppendLine(P->m_RefOffset,Fvector().mad(P->m_RefOffset,MX.k,1.f),0xFF0000FF,false,false); } NET_Packet Packet; m_Data->Spawn_Write (Packet,TRUE); F->spawn.stream.open_chunk (F->spawn.chunk++); F->spawn.stream.w (Packet.B.data,Packet.B.count); F->spawn.stream.close_chunk (); destroy_entity (m_Data); } }else{ ELog.Msg(mtError,"Can't export invalid part #%d",p_it-parts.begin()); } } UI->ProgressEnd(pb); } // clean up xr_delete(extractor); return bResult; }
bool ESceneObjectTool::ExportClimableObjects(SExportStreams* F) { bool bResult = true; CGeomPartExtractor* extractor = 0; Fbox bb; if (!GetBox(bb)) return false; extractor = xr_new<CGeomPartExtractor>(); extractor->Initialize (bb,EPS_L,int_max); UI->SetStatus ("Export climable objects..."); // collect verts&&faces { SPBItem* pb = UI->ProgressStart(m_Objects.size(), "Prepare geometry..."); for (ObjectIt it=m_Objects.begin(); it!=m_Objects.end(); it++) { pb->Inc(); CSceneObject* obj = dynamic_cast<CSceneObject*>(*it); VERIFY (obj); if (obj->IsStatic()) { CEditableObject *O = obj->GetReference(); const Fmatrix& T = obj->_Transform(); for(EditMeshIt M =O->FirstMesh(); M!=O->LastMesh(); M++) if (!build_mesh (T, *M, extractor, SGameMtl::flClimable, TRUE)) { bResult = false; break; } } } UI->ProgressEnd(pb); } if (!extractor->Process()) bResult = false; // export parts if (bResult) { SBPartVec& parts = extractor->GetParts(); SPBItem* pb = UI->ProgressStart(parts.size(),"Export Parts..."); for (SBPartVecIt p_it=parts.begin(); p_it!=parts.end(); p_it++) { pb->Inc (); SBPart* P = *p_it; if (P->Valid()) { // export visual AnsiString sn = AnsiString().sprintf("clmbl#%d",(p_it-parts.begin())); Fvector local_normal = {0,0,0}; LPCSTR mat_name = NULL; for (SBFaceVecIt it=P->m_Faces.begin(); it!=P->m_Faces.end(); it++) { for (u32 k=0; k<3; k++) local_normal.add ((*it)->n[k]); mat_name = (*it)->surf->_GameMtlName(); } local_normal.normalize_safe (); // export spawn object { AnsiString entity_ref = "climable_object"; ISE_Abstract* m_Data = create_entity(entity_ref.c_str()); VERIFY(m_Data); ISE_Shape* m_Shape = m_Data->shape(); VERIFY(m_Shape); // CSE_Visual* m_Visual = m_Data->visual(); VERIFY(m_Visual); // set params m_Data->set_name (entity_ref.c_str()); m_Data->set_name_replace (sn.c_str()); // set shape CShapeData::shape_def shape; shape.type = CShapeData::cfBox; shape.data.box.scale ((P->m_BBox.max.x-P->m_BBox.min.x)*0.5f, (P->m_BBox.max.y-P->m_BBox.min.y)*0.5f, (P->m_BBox.max.z-P->m_BBox.min.z)*0.5f); m_Shape->assign_shapes (&shape,1); // orientate object if (!OrientToNorm(local_normal,P->m_OBB.m_rotate,P->m_OBB.m_halfsize)) { ELog.Msg(mtError,"Invalid climable object found. [%3.2f, %3.2f, %3.2f]",VPUSH(P->m_RefOffset)); } else { Fmatrix M; M.set (P->m_OBB.m_rotate.i,P->m_OBB.m_rotate.j,P->m_OBB.m_rotate.k,P->m_OBB.m_translate); M.getXYZ (P->m_RefRotate); // не i потому что в движке так m_Data->position().set (P->m_RefOffset); m_Data->angle().set (P->m_RefRotate); m_Data->set_additional_info((void*)mat_name); NET_Packet Packet; m_Data->Spawn_Write (Packet,TRUE); F->spawn.stream.open_chunk (F->spawn.chunk++); F->spawn.stream.w (Packet.B.data,Packet.B.count); F->spawn.stream.close_chunk (); if (s_draw_dbg) { Tools->m_DebugDraw.AppendOBB(P->m_OBB); M.transform_dir (local_normal); Tools->m_DebugDraw.AppendLine(P->m_RefOffset,Fvector().mad(P->m_RefOffset,local_normal,1.f)); } } destroy_entity (m_Data); } }else { ELog.Msg(mtError,"Can't export invalid part #%d",p_it-parts.begin()); } } UI->ProgressEnd (pb); } // clean up xr_delete (extractor); return bResult; }