Esempio n. 1
0
std::list<TPPLPoly> fromClipperFormat2PolyPartitionFormat(const ClipperLib::Polygons& clipperPoly)
{
    std::list<TPPLPoly> polypartitionPoly;
    for(unsigned int i=0; i < clipperPoly.size() ; ++i)
        polypartitionPoly.push_back( TPPLPoly_To_Polygon(clipperPoly[i]) );

    return polypartitionPoly;
}
Esempio n. 2
0
// clip infill pattern polys against polys
void Infill::addInfill(double z, const vector<Poly> polys, 
		       const ClipperLib::Polygons patterncpolys,
		       double offsetDistance)
{
  ClipperLib::Polygons cpolys;
  //   ClipperLib::OffsetPolygons(Clipping::getClipperPolygons(polys), cpolys, 100,
  // 			       ClipperLib::jtMiter,1);
  // else 
    cpolys = Clipping::getClipperPolygons(polys);
  ClipperLib::Clipper clpr;
  clpr.AddPolygons(patterncpolys,ClipperLib::ptSubject);
  clpr.AddPolygons(cpolys,ClipperLib::ptClip);
  ClipperLib::Polygons result;
  clpr.Execute(ClipperLib::ctIntersection, result, 
	       ClipperLib::pftEvenOdd, ClipperLib::pftNonZero);
  if (type==PolyInfill) { // reversal from evenodd clipping
    for (uint i = 0; i<result.size(); i+=2)
      std::reverse(result[i].begin(),result[i].end());
  }
  addInfillPolys(Clipping::getPolys(result, z, extrusionfactor));
}
Esempio n. 3
0
GeneralPolygon::GeneralPolygon(const ClipperLib::Polygons& Polygons): 
	_position(0.0f, 0.0f), _rotation(0.0f), _size(1.0f, 1.0f), _gluTesselator(NULL), _renderMode(RenderMethod::GLU_Tessalation)
{
	_contours.resize(Polygons.size());
	for(unsigned int c=0; c < _contours.size() ; ++c)
	{
		const ClipperLib::Polygon &polygon = Polygons[c];
		Contour &contour = _contours[c];

		contour.resize(polygon.size());

		for(unsigned int v=0; v < polygon.size() ; ++v)
			contour[v] = sf::Vector2f(polygon[v].X / clipperScaleCoeficient, polygon[v].Y / clipperScaleCoeficient);

		PolygonWindingOrder winding = _getWinding(contour);

		if( winding == PolygonWindingOrder::Winding_CW )
			std::reverse(contour.begin(), contour.end());
		
	}

	_updateOptimalConvexTesselation();
}
Esempio n. 4
0
void NavMeshEditorApp::_processEvent(const sf::Event& event)
{
	_polygonUserController.processUserEvent(event);

	switch(event.type)
	{
		case sf::Event::KeyPressed:
		{
			switch(event.key.code)
			{
				case sf::Keyboard::A:
				{
					_changeEditorState(EditorState::EditingWalkableRegion);

					std::cerr<<"State: EditingWalkableRegion"<<std::endl;
				}
					break;

				case sf::Keyboard::S:
				{
					_changeEditorState(EditorState::EditingObstacleRegion);

					std::cerr<<"State: EditingObstacleRegion"<<std::endl;
				}
					break;

				case sf::Keyboard::Q:
				{
					// walkableRegions
					ClipperLib::Polygons walkableRegions;
					for(unsigned int i=0; i < _walkableCuadrilaterals.size() ; ++i)
					{
						ClipperLib::Polygons p = (ClipperLib::Polygons)*_walkableCuadrilaterals[i];
						for(unsigned int j=0; j < p.size() ; ++j)
							walkableRegions.push_back(p[j]);
					}

					std::cerr<<"Process Walkable Polygons"<<std::endl;

					// obstaclesRegions
					ClipperLib::Polygons obstacleRegions;
					for(unsigned int i=0; i < _obstacleCuadrilaterals.size() ; ++i)
					{
						ClipperLib::Polygons p = (ClipperLib::Polygons)*_obstacleCuadrilaterals[i];
						for(unsigned int j=0; j < p.size() ; ++j)
							obstacleRegions.push_back(p[j]);
					}

					std::cerr<<"Process Obstacles Polygons"<<std::endl;

					_pNavMesh->processNavigationMesh( walkableRegions, obstacleRegions );

					walkableRegions.clear();
					obstacleRegions.clear();

					_changeEditorState(EditorState::ViewingNavMeshResult);
				}
					break;

				case sf::Keyboard::Escape:
					_App.close();
					break;
			}
		}
			break;
				
		case sf::Event::Closed://Si se cierra la ventana
			_App.close();
			break;
	}
}