mirror of https://github.com/axmolengine/axmol.git
fixed poly2tri creation method, added testCase
This commit is contained in:
parent
5620da1adf
commit
c1d10ffa1c
|
@ -78,7 +78,7 @@ SpritePolygon *SpritePolygon::create(const std::string& file, std::vector<cocos2
|
|||
SpritePolygon *SpritePolygon::create(const std::string& file, std::vector<cocos2d::Vec2>& verts, const cocos2d::Rect& rect)
|
||||
{
|
||||
SpritePolygon *ret = new (std::nothrow) SpritePolygon();
|
||||
if (ret)
|
||||
if (ret && ret->initWithPoly2tri(file, verts, rect))
|
||||
{
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
|
@ -252,6 +252,8 @@ bool SpritePolygon::initWithMarching(const std::string &file, const cocos2d::Rec
|
|||
marcher->optimize(optimization);
|
||||
|
||||
auto p = marcher->getPoints();
|
||||
// marcher->printPoints();
|
||||
|
||||
// auto calculatedRect = setContentSizeFromVecs(p);
|
||||
// auto _textureRect = Rect(rect.origin.x,rect.origin.y,calculatedRect.size.width, calculatedRect.size.height);
|
||||
auto _triangles = triangulate(p);
|
||||
|
@ -285,7 +287,8 @@ bool SpritePolygon::initWithPoly2tri(const std::string &filename, std::vector<co
|
|||
throw "some error";
|
||||
}
|
||||
SpritePolygonInfo info = SpritePolygonInfo{Rect, triangulate(verts)};
|
||||
SpritePolygonCache::getInstance()->addSpritePolygonCache(filename, info);
|
||||
_polygonInfo = SpritePolygonCache::getInstance()->addSpritePolygonCache(filename, info);
|
||||
calculateUVandContentSize();
|
||||
#if CC_SPRITE_DEBUG_DRAW
|
||||
debugDraw();
|
||||
#endif
|
||||
|
|
|
@ -98,9 +98,49 @@ SpritePolygonTest1::SpritePolygonTest1()
|
|||
|
||||
SpritePolygonTest2::SpritePolygonTest2()
|
||||
{
|
||||
/*
|
||||
36.5 128.5
|
||||
27.5 133.5
|
||||
24.5 145.5
|
||||
26.5 161.5
|
||||
33.5 168.5
|
||||
27.5 168.5
|
||||
16.5 179.5
|
||||
30.5 197.5
|
||||
28.5 237.5
|
||||
56.5 237.5
|
||||
54.5 197.5
|
||||
68.5 184.5
|
||||
57.5 168.5
|
||||
51.5 168.5
|
||||
60.5 154.5
|
||||
57.5 133.5
|
||||
48.5 127.5
|
||||
36.5 127.5
|
||||
*/
|
||||
std::vector<Vec2> verts;
|
||||
verts.push_back(Vec2(36.5, 242.0-128.5));
|
||||
verts.push_back(Vec2(27.5, 242.0-133.5));
|
||||
verts.push_back(Vec2(24.5, 242.0-145.5));
|
||||
verts.push_back(Vec2(26.5, 242.0-161.5));
|
||||
verts.push_back(Vec2(33.5, 242.0-168.5));
|
||||
verts.push_back(Vec2(27.5, 242.0-168.5));
|
||||
verts.push_back(Vec2(16.5, 242.0-179.5));
|
||||
verts.push_back(Vec2(30.5, 242.0-197.5));
|
||||
verts.push_back(Vec2(28.5, 242.0-237.5));
|
||||
verts.push_back(Vec2(56.5, 242.0-237.5));
|
||||
verts.push_back(Vec2(54.5, 242.0-197.5));
|
||||
verts.push_back(Vec2(68.5, 242.0-184.5));
|
||||
verts.push_back(Vec2(57.5, 242.0-168.5));
|
||||
verts.push_back(Vec2(51.5, 242.0-168.5));
|
||||
verts.push_back(Vec2(60.5, 242.0-154.5));
|
||||
verts.push_back(Vec2(57.5, 242.0-133.5));
|
||||
verts.push_back(Vec2(48.5, 242.0-127.5));
|
||||
verts.push_back(Vec2(36.5, 242.0-127.5));
|
||||
|
||||
SpritePolygonCache::getInstance()->removeAllSpritePolygonCache();
|
||||
_title = "SpritePolygon Creation";
|
||||
_subtitle = "SpritePolygon::create(\"Images/grossini.png\")";
|
||||
auto s = experimental::SpritePolygon::create(s_pathGrossini);
|
||||
_subtitle = "SpritePolygon::create(\"Images/grossini.png\", verts)";
|
||||
auto s = experimental::SpritePolygon::create(s_pathGrossini, verts);
|
||||
initDefaultSprite(s_pathGrossini, s);
|
||||
}
|
Loading…
Reference in New Issue