Cocos2d-x  v3.10
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups
AutoPolygon Class Reference

AutoPolygon is a helper Object AutoPolygon's purpose is to process an image into 2d polygon mesh in runtime It has functions for each step in the process, from tracing all the points, to triangulation the result can be then passed to Sprite::create() to create a Polygon Sprite. More...

Public Member Functions

 AutoPolygon (const std::string &filename)
 create an AutoPolygon and initialize it with an image file the image must be a 32bit PNG for current version 3.7 a path to image file, e.g., "scene1/monster.png". More...
 
 ~AutoPolygon ()
 Destructor of AutoPolygon.
 
std::vector< Vec2trace (const cocos2d::Rect &rect, const float &threshold=0.0)
 trace all the points along the outline of the image, must create AutoPolygon with filename to use this function a texture rect for specify an area of the image, use Rect::Zero for the size of the image, default to Rect::Zero the value when alpha is greater than this value will be counted as opaque, default to 0.0 a vector of vec2 of all the points found in clockwise order
 
var trace ( var rect, var 0)
 trace all the points along the outline of the image, must create AutoPolygon with filename to use this function a texture rect for specify an area of the image, use Rect::Zero for the size of the image, default to Rect::Zero the value when alpha is greater than this value will be counted as opaque, default to 0.0 a vector of vec2 of all the points found in clockwise order
 
local trace ( local rect, local 0)
 trace all the points along the outline of the image, must create AutoPolygon with filename to use this function a texture rect for specify an area of the image, use Rect::Zero for the size of the image, default to Rect::Zero the value when alpha is greater than this value will be counted as opaque, default to 0.0 a vector of vec2 of all the points found in clockwise order
 
std::vector< Vec2reduce (const std::vector< Vec2 > &points, const Rect &rect, const float &epsilon=2.0)
 reduce the amount of points so its faster for GPU to process and draw based on Ramer-Douglas-Puecker algorithm a vector of Vec2 points as input a texture rect for specify an area of the image to avoid over reduction the perpendicular distance where points smaller than this value will be discarded a vector of Vec2 of the remaining points in clockwise order
 
var reduce ( var points, var rect, var 0)
 reduce the amount of points so its faster for GPU to process and draw based on Ramer-Douglas-Puecker algorithm a vector of Vec2 points as input a texture rect for specify an area of the image to avoid over reduction the perpendicular distance where points smaller than this value will be discarded a vector of Vec2 of the remaining points in clockwise order
 
local reduce ( local points, local rect, local 0)
 reduce the amount of points so its faster for GPU to process and draw based on Ramer-Douglas-Puecker algorithm a vector of Vec2 points as input a texture rect for specify an area of the image to avoid over reduction the perpendicular distance where points smaller than this value will be discarded a vector of Vec2 of the remaining points in clockwise order
 
std::vector< Vec2expand (const std::vector< Vec2 > &points, const Rect &rect, const float &epsilon)
 expand the points along their edge, useful after you reduce the points that cuts into the sprite using ClipperLib a vector of Vec2 points as input a texture rect for specify an area of the image, the expanded points will be clamped in this rect, ultimately resulting in a quad if the expansion is too great the distance which the edges will expand a vector of Vec2 as the result of the expansion
 
local expand ( local points, local rect, local epsilon)
 expand the points along their edge, useful after you reduce the points that cuts into the sprite using ClipperLib a vector of Vec2 points as input a texture rect for specify an area of the image, the expanded points will be clamped in this rect, ultimately resulting in a quad if the expansion is too great the distance which the edges will expand a vector of Vec2 as the result of the expansion
 
TrianglesCommand::Triangles triangulate (const std::vector< Vec2 > &points)
 Triangulate the input points into triangles for rendering using poly2tri points must be closed loop, cannot have 2 points sharing the same position and cannot intersect itself a vector of vec2 points as input a Triangles object with points and indices.
 
void calculateUV (const Rect &rect, V3F_C4B_T2F *verts, const ssize_t &count)
 calculate the UV coordinates for each points based on a texture rect This method requires the AutoPolygon object to know the texture file dimension a texture rect to specify where to map the UV a pointer to the verts array, served both as input and output verts the count for the verts array
 
PolygonInfo generateTriangles (const Rect &rect=Rect::ZERO, const float &epsilon=2.0, const float &threshold=0.05)
 a helper function, packing trace, reduce, expand, triangulate and calculate uv in one function texture rect, use Rect::ZERO for the size of the texture, default is Rect::ZERO the value used to reduce and expand, default to 2.0 the value where bigger than the threshold will be counted as opaque, used in trace a PolygonInfo, to use with sprite
 
local generateTriangles ( local ZERO, local 0, local 05)
 a helper function, packing trace, reduce, expand, triangulate and calculate uv in one function texture rect, use Rect::ZERO for the size of the texture, default is Rect::ZERO the value used to reduce and expand, default to 2.0 the value where bigger than the threshold will be counted as opaque, used in trace a PolygonInfo, to use with sprite
 

Static Public Member Functions

static PolygonInfo generatePolygon (const std::string &filename, const Rect &rect=Rect::ZERO, const float epsilon=2.0, const float threshold=0.05)
 a helper function, packing autoPolygon creation, trace, reduce, expand, triangulate and calculate uv in one function if you want to repetitively generate polygons, consider create an AutoPolygon object, and use generateTriangles function, as it only reads the file once A path to image file, e.g., "scene1/monster.png". More...
 
local generatePolygon ( local filename, local ZERO, local 0, local 05)
 a helper function, packing autoPolygon creation, trace, reduce, expand, triangulate and calculate uv in one function if you want to repetitively generate polygons, consider create an AutoPolygon object, and use generateTriangles function, as it only reads the file once A path to image file, e.g., "scene1/monster.png". More...
 

Detailed Description

AutoPolygon is a helper Object AutoPolygon's purpose is to process an image into 2d polygon mesh in runtime It has functions for each step in the process, from tracing all the points, to triangulation the result can be then passed to Sprite::create() to create a Polygon Sprite.


The documentation for this class was generated from the following file: