Graph<T> Graph<T>::Prim( int vertex ) { const int V = GetVertices(); Graph<int> MST( V ); MinPairHeap Heap; int current = vertex; Visited[current] = true; for( int i = 0; i < V; i++ ) { std::cout << "current " << current << std::endl; std::vector< std::pair<int, int> > temp = FindAllNeighbors( current ); for( int j = 0; j < temp.size(); j++ ) { if( !Visited[temp[j].first] ) { Heap.push( temp[j] ); Visited[temp[j].first] = true; } } if( !Heap.empty() ) { current = Heap.pop().first; } else return MST; } return MST; }
//---------------------------------------------------------------------------- void CIsoSurface::ExtractContour (float fLevel, std::vector<TVector3D>& rkVA, std::vector<TriangleKey>& rkTA) { rkVA.clear(); rkTA.clear(); for (int iZ = 0; iZ < m_iZBound-1; iZ++) { for (int iY = 0; iY < m_iYBound-1; iY++) { for (int iX = 0; iX < m_iXBound-1; iX++) { // get vertices on edges of box (if any) VETable kTable; int iType = GetVertices(fLevel,iX,iY,iZ,kTable); if ( iType != 0 ) { // get edges on faces of box GetXMinEdges(iX,iY,iZ,iType,kTable); GetXMaxEdges(iX,iY,iZ,iType,kTable); GetYMinEdges(iX,iY,iZ,iType,kTable); GetYMaxEdges(iX,iY,iZ,iType,kTable); GetZMinEdges(iX,iY,iZ,iType,kTable); GetZMaxEdges(iX,iY,iZ,iType,kTable); // ear-clip the wireframe mesh kTable.RemoveTriangles(rkVA,rkTA); } } } } }
void SelectNodesOP::RectQueryVisitor:: Visit(const ee::ShapePtr& shape, bool& next) { auto polyline = std::dynamic_pointer_cast<EditedPolyShape>(shape); if (!polyline) { next = true; return; } if (sm::is_rect_intersect_rect(polyline->GetBounding(), m_rect)) { ChainSelectedNodes* result = new ChainSelectedNodes; result->polyline = polyline; auto& vertices = polyline->GetVertices(); for (size_t i = 0, n = vertices.size(); i < n; ++i) { if (sm::is_point_in_rect(vertices[i], m_rect)) result->selectedNodes.push_back(vertices[i]); } if (result->selectedNodes.empty()) delete result; else m_result.push_back(result); } next = true; }
bool Rectangle::InsideShape(sf::Vector2f val, Num scale, bool shapeOnly) { bool allOnRightSide = true; VectorList verts; GetVertices(&verts); for(int i = 0; i < 4; i++) { Num slope; if(verts.at((i + 1) % 4).x == verts.at(i).x) { if(verts.at((i + 1) % 4).y >= verts.at(i).y) { slope = 100000000; } else slope = -100000000; } else slope = (verts.at((i + 1) % 4).y - verts.at(i).y) / (verts.at((i + 1) % 4).x - verts.at(i).x); Num val1 = val.y - verts.at(i).y - slope * (val.x - verts.at(i).x); Num val2 = verts.at((i + 2) % 4).y - verts.at(i).y - slope * (verts.at((i + 2) % 4).x - verts.at(i).x); if((val1 < 0 && val2 > 0) || (val1 > 0 && val2 < 0)) allOnRightSide = false; } return allOnRightSide; }
void SelectNodesOP::PosQueryVisitor:: Visit(const ee::ShapePtr& shape, bool& next) { auto polyline = std::dynamic_pointer_cast<EditedPolyShape>(shape); if (!polyline) { next = true; return; } if (sm::is_rect_intersect_rect(polyline->GetBounding(), m_rect)) { auto& vertices = polyline->GetVertices(); for (size_t i = 0, n = vertices.size(); i < n; ++i) { if (sm::dis_pos_to_pos(m_pos, vertices[i]) < SelectNodesOP::GetThreshold()) { ChainSelectedNodes* result = new ChainSelectedNodes; result->polyline = polyline; result->selectedNodes.push_back(vertices[i]); *m_result = result; next = false; return; } } } next = true; }
void MD3Model::GetVertices(uint32_t s, uint32_t f, MeshVertex_t*& vertexData, uint32_t& vertexCount) const { assert(s < header->numSurfaces); assert(f < header->numFrames); MD3::Surface_t* surface = surfaces[s]; MD3::Vertex_t* vertices = GetVertices(s, f); MD3::TexCoord_t* texCoords = GetTexCoords(s); vertexCount = surface->numVerts; vertexData = new MeshVertex_t[vertexCount]; for (uint32_t i=0; i<vertexCount; ++i) { vertexData[i].coord = glm::vec3( vertices[i].x, vertices[i].y, vertices[i].z ) * MD3_SCALE; vertexData[i].normal = DecodeNormal(vertices[i].n); vertexData[i].texCoord = glm::vec2( texCoords[i].u, texCoords[i].v ); } }
void FreeParkingLot(ParkingLot * parkinglot) { FreeDecoder( GetDecoder( parkinglot ), GetVertices( parkinglot ) ); FreeGraph( GetGraph( parkinglot ) ) ; freeLinkedList( GetAccesses( parkinglot) ); freeLinkedList( GetQueueHead(parkinglot) ); FreeParkedCars( GetParkedListHead(parkinglot) ); free(parkinglot); }
void CollisionMesh::DrawDiagnostics() { if(m_draw && m_geometry && m_engine->diagnostic()->AllowDiagnostics(Diagnostic::MESH)) { // Render world vertices const std::string id = StringCast(this); const float vertexRadius = 0.1f; const auto& vertices = GetVertices(); for(unsigned int i = 0; i < vertices.size(); ++i) { m_engine->diagnostic()->UpdateSphere(Diagnostic::MESH, "0" + StringCast(i) + id, Diagnostic::RED, vertices[i], vertexRadius); } // Render face normals m_geometry->UpdateDiagnostics(*m_engine->diagnostic(), m_world.GetMatrix()); // Render OABB for diagnostic mesh auto getPointColor = [=](int index) -> Diagnostic::Colour { return index == MINBOUND || index == MAXBOUND ? Diagnostic::BLUE : Diagnostic::MAGENTA; }; const float radius = 0.2f; std::string corner; for(unsigned int i = 0; i < CORNERS/2; ++i) { corner = StringCast(i); m_engine->diagnostic()->UpdateSphere(Diagnostic::MESH, "CornerA" + corner + id, getPointColor(i), m_oabb[i], radius); m_engine->diagnostic()->UpdateSphere(Diagnostic::MESH, "CornerB" + corner + id, getPointColor(i+4), m_oabb[i+4], radius); m_engine->diagnostic()->UpdateLine(Diagnostic::MESH, "LineA" + corner + id, Diagnostic::MAGENTA, m_oabb[i], m_oabb[i+1 >= 4 ? 0 : i+1]); m_engine->diagnostic()->UpdateLine(Diagnostic::MESH, "LineB" + corner + id, Diagnostic::MAGENTA, m_oabb[i+4], m_oabb[i+5 >= CORNERS ? 4 : i+5]); m_engine->diagnostic()->UpdateLine(Diagnostic::MESH, "LineC" + corner + id, Diagnostic::MAGENTA, m_oabb[i], m_oabb[i+4]); } // Render radius of diagnostic mesh in wireframe m_engine->diagnostic()->UpdateSphere(Diagnostic::MESH, "Radius" + id, Diagnostic::WHITE, GetPosition(), GetRadius()); } }
void Element::SetVertices(const int *ind) { int i, n, *v; n = GetNVertices(); v = GetVertices(); for (i = 0; i < n; i++) v[i] = ind[i]; }
void csSprite2DMeshObject::Rotate (float angle) { iColoredVertices* vertices = GetVertices (); size_t i; for (i = 0 ; i < vertices->GetSize(); i++) vertices->Get (i).pos.Rotate (angle); vertices_dirty = true; ShapeChanged (); }
void csSprite2DMeshObject::ScaleBy (float factor) { iColoredVertices* vertices = GetVertices (); size_t i; for (i = 0 ; i < vertices->GetSize(); i++) vertices->Get (i).pos *= factor; vertices_dirty = true; ShapeChanged (); }
ListNode * HandleRest(ListNode * resthead, ParkingLot * parkinglot, int timeunit, FILE * outputfile) { Rest * rest; ListNode * aux; int i=0; /*Get the head of the restricion list to the aux pointer for the first while comparation*/ aux = resthead; if(aux == NULL) return NULL; /*Get the first restriction*/ rest = (Rest*) getItemLinkedList(aux); while(aux != NULL && GetRestTime(rest) == timeunit) { if(GetRestFlag(rest) == 'p') { i = FindIP(GetVertices(parkinglot), GetRestCoord(rest, 'x'), GetRestCoord(rest, 'y'), GetRestCoord(rest, 'z'), GetDecoder(parkinglot) ); if(GetIP_Flagres(i, GetDecoder(parkinglot) ) == 1) { ReleasePos(i, GetDecoder(parkinglot) ); IncFreeSpots(parkinglot); if( GetFreeSpots(parkinglot) != 0) HandleQueue(parkinglot, outputfile, timeunit); } else { RestrictPos(i, GetDecoder(parkinglot) ); DecFreeSpots(parkinglot); } } else if(GetRestFlag(rest) == 'f') { if( IsFloorRestricted( GetRestCoord(rest, 'z'), parkinglot ) ) { ReleaseWholeFloor(i, parkinglot ); /* la dento temos de fazer bue release spots */ if( GetFreeSpots(parkinglot) != 0) HandleQueue(parkinglot, outputfile, timeunit); } else RestrictWholeFloor( GetRestCoord(rest, 'z'), parkinglot ); } aux = getNextNodeLinkedList(aux); rest = (Rest*) getItemLinkedList(aux); } /*Return the new head of the linked list*/ return aux; }
void Geometry::Face2Polygon(const TopoDS_Face &f, pcl::PlanarPolygon<PointT>& poly) { VertexSet vertices; GetVertices(f,vertices); PointCloud cloud; for (VertexSet::iterator it=vertices.begin();it!=vertices.end();++it ){ PointT p; Vertex2Point(*it,p); cloud.push_back(p); } poly.setContour(cloud); }
void csSprite2DMeshObject::AddColor (const csColor& col) { iColoredVertices* vertices = GetVertices (); size_t i; for (i = 0 ; i < vertices->GetSize(); i++) vertices->Get (i).color_init += col; if (!lighting) for (i = 0 ; i < vertices->GetSize(); i++) vertices->Get (i).color = vertices->Get (i).color_init; colors_dirty = true; }
/*! Uses the stored vectors of vertices and triangles to initialize geometry; if these are not yet in memory, will first ask the manager to load them. */ int GeomGraspitDBModel::loadGeometry() { // if geometry has not been already loaded, ask the manager to load it if (GetVertices().empty()) { if (!mManager) { DBGA("Cannot load geometry from database; missing manager"); return FAILURE; } if (!mManager->LoadModelGeometry(this)) { DBGA("Manager failed to load geometry for model from database"); return FAILURE; } if (GetVertices().empty() || GetTriangles().empty()) { DBGA("Empty geometry loaded from database"); return FAILURE; } } //convert geometry to a format that graspit understands and load it std::vector<position> vertices; if (GetVertices().size() % 3 != 0) { DBGA("Load model geometry from database: size of vertices vector is not a multiple of 3"); return FAILURE; } for (size_t i = 0; i < GetVertices().size() / 3; i++) { vertices.push_back(position(GetVertices().at(3 * i + 0), GetVertices().at(3 * i + 1), GetVertices().at(3 * i + 2))); } return mGraspableBody->loadGeometryMemory(vertices, GetTriangles()); }
std::vector<Triangle2D> ConvexPolygon::Triangulate() const { int numVerts = GetNumVertices(); const Vec2 *vertices = GetVertices(); std::vector<Triangle2D> ret; for(int i = 2;i < numVerts;i++) { Triangle2D tri(vertices[0],vertices[i - 1],vertices[i]); ret.push_back(tri); } return ret; }
bool csSprite2DMeshObject::SetColor (const csColor& col) { iColoredVertices* vertices = GetVertices (); size_t i; for (i = 0 ; i < vertices->GetSize(); i++) vertices->Get (i).color_init = col; if (!lighting) for (i = 0 ; i < vertices->GetSize(); i++) vertices->Get (i).color = col; colors_dirty = true; return true; }
int IsFloorRestricted( int z, ParkingLot * parkinglot) { int i; int vertices = GetVertices(parkinglot); for(i = 0; (i < vertices) && (GetIP_Coord(i, 'z', GetDecoder(parkinglot) ) <= z) ; i++) { if( (GetIP_Coord(i, 'z', GetDecoder(parkinglot)) == z) && (GetIP_Flagres(i, GetDecoder(parkinglot)) == 0) && (GetIP_Type(i, GetDecoder(parkinglot)) == '.') ) return 0; } return 1; }
void RestrictWholeFloor( int z, ParkingLot * parkinglot ) { int i; int vertices = GetVertices(parkinglot); for(i = 0; (i < vertices) && (GetIP_Coord(i, 'z', GetDecoder(parkinglot) ) <= z) ; i++) { if( (GetIP_Coord(i, 'z', GetDecoder(parkinglot)) == z) && (GetIP_Flagres(i, GetDecoder(parkinglot)) == 0) && (GetIP_Type(i, GetDecoder(parkinglot)) == '.' )) { RestrictPos(i, GetDecoder(parkinglot) ); DecFreeSpots(parkinglot); } } }
void SpriteComponent::InitializeComponent() { TextureManager::GetInstance()->LoadTexture(m_FilePath.GetAssetsPath(),m_SpriteName); m_Width = TextureManager::GetInstance()->GetTextureDimensions(m_SpriteName).x / m_WidthSegments; m_Heigth = TextureManager::GetInstance()->GetTextureDimensions(m_SpriteName).y / m_HeightSegments; CreateVertices(); CreateIndices(); m_SpriteInfo.spriteName = m_SpriteName; m_SpriteInfo.vertices = GetVertices(); m_SpriteInfo.uvCoords = GetUVCoords(); m_SpriteInfo.bIsHUD = m_bIsHudElement; }
_Use_decl_annotations_ Geometry AssetLoader::LoadGeometryFromFile(const char* filename) const { char source[MAX_PATH]; sprintf_s(source, "%s%s", GetConfig().ContentRoot, filename); GeometryFileData data; LoadGeometryFileData(source, &data); auto pool = GetGraphics().GetPoolWithSpace(VertexFormat::StaticGeometry, data.NumVertices, data.NumIndices); uint32_t verticesIndex = 0; uint32_t indicesIndex = 0; pool->ReserveRange(data.NumVertices, data.NumIndices, &verticesIndex, &indicesIndex); ComPtr<ID3D11Device> device; pool->GetVertices()->GetDevice(&device); ComPtr<ID3D11DeviceContext> context; device->GetImmediateContext(&context); D3D11_BOX box = {}; box.left = sizeof(StaticGeometryVertex) * verticesIndex; box.right = box.left + data.NumVertices * sizeof(StaticGeometryVertex); box.bottom = 1; box.back = 1; context->UpdateSubresource(pool->GetVertices(), 0, &box, data.Vertices, data.NumVertices * sizeof(StaticGeometryVertex), 0); box.left = sizeof(uint32_t) * indicesIndex; box.right = box.left + (data.NumIndices * sizeof(uint32_t)); context->UpdateSubresource(pool->GetIndices(), 0, &box, data.Indices, data.NumIndices * sizeof(uint32_t), 0); Geometry geometry(pool, verticesIndex, indicesIndex, data.NumIndices); FreeGeometryFileData(&data); return geometry; }
void ObjLoader::LoadOBJ(ID3D11Device* Device, ID3D11DeviceContext* DeviceContext, string ObjFile) { mDeviceContext = DeviceContext; vertexPositions = vector<Position>(); vertexTexturePos = vector<Position>(); vertexNormals = vector<Position>(); objVertices = vector<Vertex>(); ifstream myfile; myfile.open (ObjFile); string sLine; ObjToken Token; while (!myfile.eof()) { getline(myfile, sLine); if(sLine.length() > 0) { Token = GetToken(sLine); switch(Token) { case VERTEX_POSITION: vertexPositions.push_back(ConvertToPosition(sLine, Token)); break; case VERTEX_TEXPOS: vertexTexturePos.push_back(ConvertToPosition(sLine, Token)); break; case VERTEX_NORMAL: vertexNormals.push_back(ConvertToPosition(sLine, Token)); break; case FACE_DATA: GetVertices(sLine, vertexPositions, vertexTexturePos, vertexNormals, objVertices); break; } } } myfile.close(); Vertex* vertices = new Vertex[objVertices.size()]; for(int i = 0; i < objVertices.size(); ++i) vertices[i] = objVertices[i]; }
bool Rectangle::IntersectsBox(Num boxX, Num boxY, Num boxW, Num boxH) { /*if(centerX >= boxX && centerX <= boxX + boxW && centerY >= boxY && centerY <= boxY + boxH) return true;*/ VectorList verts; GetVertices(&verts); /*for(int i = 0; i < 4; i++) { if(utils.SegmentsIntersect(verts.at(i).x, verts.at(i).y, verts.at((i + 1) % 4).x, verts.at((i + 1) % 4).y, boxX, boxY, boxX + boxW, boxY)) return true; if(utils.SegmentsIntersect(verts.at(i).x, verts.at(i).y, verts.at((i + 1) % 4).x, verts.at((i + 1) % 4).y, boxX + boxW, boxY, boxX + boxW, boxY + boxH)) return true; if(utils.SegmentsIntersect(verts.at(i).x, verts.at(i).y, verts.at((i + 1) % 4).x, verts.at((i + 1) % 4).y, boxX + boxW, boxY + boxH, boxX, boxY + boxH)) return true; if(utils.SegmentsIntersect(verts.at(i).x, verts.at(i).y, verts.at((i + 1) % 4).x, verts.at((i + 1) % 4).y, boxX, boxY + boxH, boxX, boxY)) return true; } return false;*/ for(int i = 0; i < 4; i++) { if(verts[i].x < boxX) return false; if(verts[i].y < boxY) return false; if(verts[i].x > boxX + boxW) return false; if(verts[i].y > boxY + boxH) return false; } return true; /*for(int i = 0; i < 4; i++) { if(verts[i].x >= boxX && verts[i].y >= boxY && verts[i].x <= boxX + boxW && verts[i].y <= boxY + boxH) return true; } for(int i = 0; i < 4; i++) { if(verts[i].x <= boxX && verts[i].y <= boxY && verts[i].x >= boxX + boxW && verts[i].y >= boxY + boxH) return true; } return false;*/ }
int main() { int gd=DETECT,gm; initgraph(&gd,&gm,"c://TC/bgi"); setlinestyle(SOLID_LINE,1,3); GetVertices(); GetEdges(); Redraw(adj,0); AllPath(); // Redraw(A,0); // Redraw(A); //gotoxy(2,4); //printf("Minimum Cost of this spaning tree is : %d",mstcost); getch(); closegraph(); return 0; }
std::shared_ptr<Scene> SceneFactory::CreateFromFile(const std::string& filename) { Assimp::Importer importer; const aiScene* scene = importer.ReadFile(filename, aiProcess_Triangulate | aiProcess_GenNormals | aiProcess_ImproveCacheLocality | aiProcess_JoinIdenticalVertices | aiProcess_PreTransformVertices); if (scene == NULL) { std::printf("\nImport failed:\n\t"); auto errorString = importer.GetErrorString(); std::printf(errorString); std::printf("\n"); return nullptr; } Scene::vertexList vertices = GetVertices(scene); Scene::triangleList faces = GetFaces(scene); Scene::materialList materials = GetMaterials(scene); return std::shared_ptr<Scene>(new Scene(vertices, faces, materials)); }
Manipulator* MultiLineView::CreateManipulator ( Viewer* v, Event& e, Transformer* rel, Tool* tool ) { Manipulator* m = nil; if (tool->IsA(GRAPHIC_COMP_TOOL)) { v->Constrain(e.x, e.y); Coord x[1], y[1]; x[0] = e.x; y[0] = e.y; GrowingVertices* rub = new GrowingMultiLine( nil, nil, x, y, 1, -1, HANDLE_SIZE ); m = new VertexManip( v, rub, rel, tool, DragConstraint(HorizOrVert | Gravity) ); } else if (tool->IsA(RESHAPE_TOOL)) { Coord* x, *y; int n; v->Constrain(e.x, e.y); GetVertices(x, y, n); GrowingMultiLine* rub = new GrowingMultiLine( nil, nil, x, y, n, ClosestPoint(x, y, n, e.x, e.y), HANDLE_SIZE ); delete x; delete y; m = new VertexManip( v, rub, rel, tool, DragConstraint(HorizOrVert | Gravity) ); } else { m = VerticesView::CreateManipulator(v, e, rel, tool); } return m; }
Graph<T> Graph<T>::Kruskal( int vertex ) { const int V = GetVertices(); Graph<int> MST( V ); MinPairHeap Heap; std::vector<bool> Visited( Matrix.size(), false ); int current = vertex; Visited[current] = true; std::vector< std::pair<int,int> > neighbors = FindAllNeighbors( vertex ); for( int i = 0; i < neighbors.size(); i++ ) { Heap.push( neighbors[i] ); } while( !Heap.empty() ) { std::pair<int, int> Vert = Heap.pop(); std::cout << Vert.first << std::endl; } }
void SpriteComponent::SetTexture( const tstring& filepath, const tstring& spriteName, bool bIsHUDElement /*= false*/, int32 widthSegments /*= 1*/, int32 heightSegments /*= 1*/ ) { m_Width = 0; m_WidthSegments = widthSegments; m_CurrentWidthSegment = 0; m_Heigth = 0; m_HeightSegments = heightSegments; m_CurrentHeightSegment = 0; m_FilePath = filepath; m_SpriteName = spriteName; m_bIsHudElement = bIsHUDElement; TextureManager::GetInstance()->LoadTexture(m_FilePath.GetAssetsPath(),m_SpriteName); m_Width = TextureManager::GetInstance()->GetTextureDimensions(m_SpriteName).x / m_WidthSegments; m_Heigth = TextureManager::GetInstance()->GetTextureDimensions(m_SpriteName).y / m_HeightSegments; CreateVertices(); CreateIndices(); m_SpriteInfo.spriteName = m_SpriteName; m_SpriteInfo.vertices = GetVertices(); m_SpriteInfo.uvCoords = GetUVCoords(); m_SpriteInfo.bIsHUD = m_bIsHudElement; }
int main() { int gd=DETECT,gm; initgraph(&gd,&gm,"c://TC/bgi"); setbkcolor(BROWN); setlinestyle(SOLID_LINE,1,3); GetVertices(); GetEdges(); // getch(); edgecost(); getch(); Redraw(adj); //PRIMS ALGO Vertex *v; int min_edge=MAX_NUM; int min_x, min_y,k,l,z; for(z=0;z<vcount;z++) //create near near1[z]=-1; for(k=0;k<vcount;k++) //near array fill { for(l=0;l<vcount;l++) { if(adj[k][l]<min_edge) {min_edge=adj[k][l]; min_x=k; min_y=l; } } } mincost=0; mincost+=min_edge; // int m=MAX_VERT; //int t[m][2]; t[0][0]=min_x; t[0][1]=min_y; Edge_fill(&v[min_x],&v[min_y],RED,TRUE); getch(); extra[min_x][min_y]=1; extra[min_y][min_x]=1; for(z=0;z<vcount;z++) //near array update { if(adj[z][min_x]<adj[z][min_y]) near1[z]=min_x; else near1[z]=min_y; } near1[min_x]=near1[min_y]=-1; // int k; int min_j; //prims algorithm for( z =1;z<vcount-1;z++) { min_j=MAX_NUM; for(int j=0;j<vcount;j++) //choose nearest vertex { if(adj[j][near1[j]]<min_j && near1[j]!=-1) min_j=j; } t[z][0]=min_j; t[z][1]=near1[min_j]; mincost+=adj[min_j][near1[min_j]]; extra[min_j][near1[min_j]]=1; extra[near1[min_j]][min_j]=1; near1[min_j]=-1; for(k=0;k<vcount;k++) { if(near1[k]!=-1 && adj[k][near1[k]]>adj[k][min_j]) near1[k]=min_j; } } getch(); Redraw(extra); gotoxy(2,4); printf("Minimum Cost of this spaning tree is : %d",mincost); getch(); closegraph(); return 0; }
bool Map::CompileS3D( std::vector<EQEmu::S3D::WLDFragment> &zone_frags, std::vector<EQEmu::S3D::WLDFragment> &zone_object_frags, std::vector<EQEmu::S3D::WLDFragment> &object_frags ) { collide_verts.clear(); collide_indices.clear(); non_collide_verts.clear(); non_collide_indices.clear(); current_collide_index = 0; current_non_collide_index = 0; collide_vert_to_index.clear(); non_collide_vert_to_index.clear(); map_models.clear(); map_eqg_models.clear(); map_placeables.clear(); eqLogMessage(LogTrace, "Processing s3d zone geometry fragments."); for(uint32_t i = 0; i < zone_frags.size(); ++i) { if(zone_frags[i].type == 0x36) { EQEmu::S3D::WLDFragment36 &frag = reinterpret_cast<EQEmu::S3D::WLDFragment36&>(zone_frags[i]); auto model = frag.GetData(); auto &mod_polys = model->GetPolygons(); auto &mod_verts = model->GetVertices(); for (uint32_t j = 0; j < mod_polys.size(); ++j) { auto ¤t_poly = mod_polys[j]; auto v1 = mod_verts[current_poly.verts[0]]; auto v2 = mod_verts[current_poly.verts[1]]; auto v3 = mod_verts[current_poly.verts[2]]; float t = v1.pos.x; v1.pos.x = v1.pos.y; v1.pos.y = t; t = v2.pos.x; v2.pos.x = v2.pos.y; v2.pos.y = t; t = v3.pos.x; v3.pos.x = v3.pos.y; v3.pos.y = t; if(current_poly.flags == 0x10) AddFace(v1.pos, v2.pos, v3.pos, false); else AddFace(v1.pos, v2.pos, v3.pos, true); } } } eqLogMessage(LogTrace, "Processing zone placeable fragments."); std::vector<std::pair<std::shared_ptr<EQEmu::Placeable>, std::shared_ptr<EQEmu::S3D::Geometry>>> placables; std::vector<std::pair<std::shared_ptr<EQEmu::Placeable>, std::shared_ptr<EQEmu::S3D::SkeletonTrack>>> placables_skeleton; for (uint32_t i = 0; i < zone_object_frags.size(); ++i) { if (zone_object_frags[i].type == 0x15) { EQEmu::S3D::WLDFragment15 &frag = reinterpret_cast<EQEmu::S3D::WLDFragment15&>(zone_object_frags[i]); auto plac = frag.GetData(); if(!plac) { eqLogMessage(LogWarn, "Placeable entry was not found."); continue; } bool found = false; for (uint32_t o = 0; o < object_frags.size(); ++o) { if (object_frags[o].type == 0x14) { EQEmu::S3D::WLDFragment14 &obj_frag = reinterpret_cast<EQEmu::S3D::WLDFragment14&>(object_frags[o]); auto mod_ref = obj_frag.GetData(); if(mod_ref->GetName().compare(plac->GetName()) == 0) { found = true; auto &frag_refs = mod_ref->GetFrags(); for (uint32_t m = 0; m < frag_refs.size(); ++m) { if (object_frags[frag_refs[m] - 1].type == 0x2D) { EQEmu::S3D::WLDFragment2D &r_frag = reinterpret_cast<EQEmu::S3D::WLDFragment2D&>(object_frags[frag_refs[m] - 1]); auto m_ref = r_frag.GetData(); EQEmu::S3D::WLDFragment36 &mod_frag = reinterpret_cast<EQEmu::S3D::WLDFragment36&>(object_frags[m_ref]); auto mod = mod_frag.GetData(); placables.push_back(std::make_pair(plac, mod)); } else if (object_frags[frag_refs[m] - 1].type == 0x11) { EQEmu::S3D::WLDFragment11 &r_frag = reinterpret_cast<EQEmu::S3D::WLDFragment11&>(object_frags[frag_refs[m] - 1]); auto s_ref = r_frag.GetData(); EQEmu::S3D::WLDFragment10 &skeleton_frag = reinterpret_cast<EQEmu::S3D::WLDFragment10&>(object_frags[s_ref]); auto skele = skeleton_frag.GetData(); placables_skeleton.push_back(std::make_pair(plac, skele)); } } break; } } } if(!found) { eqLogMessage(LogWarn, "Could not find model for placeable %s", plac->GetName().c_str()); } } } eqLogMessage(LogTrace, "Processing s3d placeables."); size_t pl_sz = placables.size(); for(size_t i = 0; i < pl_sz; ++i) { auto plac = placables[i].first; auto model = placables[i].second; auto &mod_polys = model->GetPolygons(); auto &mod_verts = model->GetVertices(); float offset_x = plac->GetX(); float offset_y = plac->GetY(); float offset_z = plac->GetZ(); float rot_x = plac->GetRotateX() * 3.14159f / 180.0f; float rot_y = plac->GetRotateY() * 3.14159f / 180.0f; float rot_z = plac->GetRotateZ() * 3.14159f / 180.0f; float scale_x = plac->GetScaleX(); float scale_y = plac->GetScaleY(); float scale_z = plac->GetScaleZ(); if (map_models.count(model->GetName()) == 0) { map_models[model->GetName()] = model; } std::shared_ptr<EQEmu::Placeable> gen_plac(new EQEmu::Placeable()); gen_plac->SetFileName(model->GetName()); gen_plac->SetLocation(offset_x, offset_y, offset_z); //y rotation seems backwards on s3ds, probably cause of the weird coord system they used back then //x rotation might be too but there are literally 0 x rotated placeables in all the s3ds so who knows gen_plac->SetRotation(rot_x, -rot_y, rot_z); gen_plac->SetScale(scale_x, scale_y, scale_z); map_placeables.push_back(gen_plac); eqLogMessage(LogTrace, "Adding placeable %s at (%f, %f, %f)", model->GetName().c_str(), offset_x, offset_y, offset_z); } eqLogMessage(LogTrace, "Processing s3d animated placeables."); pl_sz = placables_skeleton.size(); for (size_t i = 0; i < pl_sz; ++i) { auto &plac = placables_skeleton[i].first; auto &bones = placables_skeleton[i].second->GetBones(); if(bones.size() > 0) { float offset_x = plac->GetX(); float offset_y = plac->GetY(); float offset_z = plac->GetZ(); float rot_x = plac->GetRotateX() * 3.14159f / 180.0f; float rot_y = plac->GetRotateY() * 3.14159f / 180.0f; float rot_z = plac->GetRotateZ() * 3.14159f / 180.0f; float scale_x = plac->GetScaleX(); float scale_y = plac->GetScaleY(); float scale_z = plac->GetScaleZ(); TraverseBone(bones[0], glm::vec3(offset_x, offset_y, offset_z), glm::vec3(rot_x, rot_y, rot_z), glm::vec3(scale_x, scale_y, scale_z)); } } return true; }