From c1d10ffa1c9ced2a08a829c17bb57136ea21afc4 Mon Sep 17 00:00:00 2001 From: WuHao Date: Fri, 24 Apr 2015 18:28:28 +0800 Subject: [PATCH] fixed poly2tri creation method, added testCase --- cocos/2d/SpritePolygon.cpp | 7 ++- .../SpritePolygonTest/SpritePolygonTest.cpp | 44 ++++++++++++++++++- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/cocos/2d/SpritePolygon.cpp b/cocos/2d/SpritePolygon.cpp index 4d39fbf3bd..4f93992c77 100644 --- a/cocos/2d/SpritePolygon.cpp +++ b/cocos/2d/SpritePolygon.cpp @@ -78,7 +78,7 @@ SpritePolygon *SpritePolygon::create(const std::string& file, std::vector& 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::vectoraddSpritePolygonCache(filename, info); + _polygonInfo = SpritePolygonCache::getInstance()->addSpritePolygonCache(filename, info); + calculateUVandContentSize(); #if CC_SPRITE_DEBUG_DRAW debugDraw(); #endif diff --git a/tests/cpp-tests/Classes/SpritePolygonTest/SpritePolygonTest.cpp b/tests/cpp-tests/Classes/SpritePolygonTest/SpritePolygonTest.cpp index 581a7b94bf..b9880d0ac3 100644 --- a/tests/cpp-tests/Classes/SpritePolygonTest/SpritePolygonTest.cpp +++ b/tests/cpp-tests/Classes/SpritePolygonTest/SpritePolygonTest.cpp @@ -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 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); } \ No newline at end of file