Closed NgVThangBz closed 10 months ago
Currently DrawNode->drawPolygon is using the wrong triangulation method (from cocos2dx), which leads to complex and concave polylines being drawn incorrectly.
Do you have an example, and by that I mean screenshots of incorrect and correct rendering?
cocos2dx v3 now has a new update to draw polygon more accurately (not released yet), i haven't tried it but maybe it will work, or use poly2tri to be able to triangulate correctly than
There are no new versions of Cocos2d-x v3, and unlikely for any others to be released given that the Cocos team haven't worked on it for over 2 years. So, what exactly do you mean by that statement?
You can see the image below: the blue color uses poly2tri for triangulation, and the red color uses the default version.
I'm not talking about released versions, I'm talking about DrawNode code on the contributed v3 branch,
I just tested cocos2dx v3, and they work wrong, don't worry about them, sorry
I just tested cocos2dx v3, and they work wrong, don't worry about them, sorry
Sorry, that's what I actually meant. There were no new PRs or updates listed against cocos2d-x v3 with polygon related code, so I wasn't sure what you were referring to.
Anyhow, I'm pretty sure poly2tri was updated a while back by @aismann, so perhaps he may be able to give his input regarding this.
- You can see the image below: the blue color uses poly2tri for triangulation, and the red color uses the default version.
- I'm not talking about released versions, I'm talking about DrawNode code on the contributed v3 branch,
@NgVThangBz Your vertices list from this example plz. And yes its known (see cpp-tests DrawNode tests) => cocos2dx 4.0 issue (implementation)
[0] = {x=290.250000 y=98.1250000 } [1] = {x=235.000000 y=90.8750000 } [2] = {x=270.500000 y=109.875000 } [3] = {x=235.000000 y=119.125000 } [4] = {x=275.250000 y=145.875000 } [5] = {x=249.500000 y=145.875000 } [6] = {x=249.500000 y=178.125000 } [7] = {x=275.250000 y=187.375015 } [8] = {x=294.750488 y=168.333344 } [9] = {x=311.250000 y=181.125000 } [10] = {x=257.000000 y=213.625015 } [11] = {x=338.500000 y=193.125000 } [12] = {x=300.000000 y=211.125015 } [13] = {x=333.750000 y=211.125015 } [14] = {x=368.250000 y=206.625000 } [15] = {x=377.000000 y=178.125000 } [16] = {x=421.750000 y=170.125000 } [17] = {x=416.250000 y=115.375000 } [18] = {x=391.250000 y=157.875000 } [19] = {x=338.500000 y=131.625000 } [20] = {x=362.750000 y=131.625000 } [21] = {x=362.750000 y=106.875000 } [22] = {x=306.500000 y=119.125000 } [23] = {x=324.250000 y=85.1250000 } [24] = {x=227.500000 y=61.8750000 } im create new polygon, please check
@NgVThangBz Thats issue comes with Cocos2dx 4.0.
yes it happens with both 3.17 and 4.0 and it leads to axmol also crashing, so let's find a solution, currently I'm using poly2tri to solve the problem.
It happens only with filled polygon: see here: DrawNode::drawPoly: SolidPoly/Polygon cannot render concave structure correct. #829 The changed draw order is not a solution for complex concave polygons.
Thats the reason for wrong filled polygons (using GL_TRIANGLE_FAN): (screenshot from here:)
Here a possible solution (pseudo code):
if isConvex
use the Cocos2dx version
else
create triangles and fill each
Another idea is to use the class AutoPolygon/PolygonInfo class to create the triangles
The problem is on each solution is it filled only (no border line) => workaround: drawPoly for the border)
@halx99 you can also add tags like on #829
yes it happens with both 3.17 and 4.0 and it leads to axmol also crashing, so let's find a solution, currently I'm using poly2tri to solve the problem.
@NgVThangBz Do you have a PR?
I simply used poly2tri to create the triangles, and colored them @aismann
do we have an axmol test where this issue can be seen? if not please add
I simply used poly2tri to create the triangles, and colored them
@NgVThangBz You used an app like paint, right? Polztri makes only the triangles like autopolygon or get you a filled Polygon with polyti directly
do we have an axmol test where this issue can be seen? if not please add
we have:
and an info too:
yes, instead of using
@NgVThangBz
What is globalToDrawing(pt)
doing (code snippet)?
@aismann it's just for frame conversion, you can ignore it
Ok I have a solution: Coming PR needs some more tests datas, @NgVThangBz maybe you have some more? Format:
Vec2 vertices[] = {
{290.250000, 98.1250000 },
{235.000000, 90.8750000 },
...
{324.250000, 85.1250000 },
{227.500000, 61.8750000 } };
@halx99 you can remove the "help wanted".
I have created 2 more data (files below), in the file there are 2 Vec2 lists: -data1 is manually generated,
-data2 is taken from a
data here: polyLineData.txt
Looks good (but there are some issues which i have to fix/changes before I can make the PR):
I think I need some more time (not all is working at this moment)! @halx99 please add 'long story', 'enhancement' tag However I will add some more 'new' drawing methodes too: eg: drawPolyline with thickness
Here a preview of the drawPolyline with thickness
I opening an issue on poly2tri https://github.com/jhasse/poly2tri/issues/54
@NgVThangBz Maybe you want check your data also for correctness?
Thats the poly2tri result (axmol has the same of course):
@aismann maye my data wrong, you can check again with data: polyLineData.txt but i think axmol like poly2tri is fine
@NgVThangBz I got an exeption with your new data on p2t.exe (poly2tri testbed) Please check it with poly2tri first.
@halx99 Short info: I will have no time to work on it this year.
Small update (seems it works now correct)
@NgVThangBz can be closed now.
@aismann yes, thank you, it good
@aismann yes, thank you, it good
@NgVThangBz You are the author, you can close it (im not) ;)
Currently DrawNode->drawPolygon is using the wrong triangulation method (from cocos2dx), which leads to complex and concave polylines being drawn incorrectly.
why not replace the more accurate triangulation with triangulation algorithms (poly2tri...??)
cocos2dx v3 now has a new update to draw polygon more accurately (not released yet), i haven't tried it but maybe it will work, or use poly2tri to be able to triangulate correctly than