Meshes cocos2d-x v4.0

Does anybody know how to work with meshes in coco2d-x? I found docs only for cocos creator(Mesh Resource · Cocos Creator). The documentation of cpp version doesn’t have docs about meshes.

Okay, I have found a solution for my issue. If you want to dynamically manipulate vertices of a sprite, you have to use the PolygonInfo.

E.g.

auto sprite = Sprite::create();
PolygonInfo polygonInfo;
polygonInfo.setFilename("textures/pixel.png");

// setting the number of vertices in the desired polygon
polygonInfo.triangles.vertCount = 4;
polygonInfo.triangles.verts = new V3F_C4B_T2F[polygonInfo.triangles.vertCount];

// triangles are drawn based on the indices of vertices, hence the count is always divisible by 3
polygonInfo.triangles.indexCount = 6;
polygonInfo.triangles.indices = new unsigned short[polygonInfo.triangles.indexCount];

float width = 2500.0f;
float height = 2500.0f;

//Now setting up triangle vertices
//low left point
polygonInfo.triangles.verts[0].vertices = Vec3(0, 0, -0);
polygonInfo.triangles.verts[0].texCoords = Tex2F(0, 0);
polygonInfo.triangles.verts[0].colors = Color4B(255, 255, 255, 255);

//top left point
polygonInfo.triangles.verts[1].vertices = Vec3(0, height, 0);
polygonInfo.triangles.verts[1].texCoords = Tex2F(0, 1);
polygonInfo.triangles.verts[1].colors = Color4B(255, 255, 255, 255);

//low right point
polygonInfo.triangles.verts[2].vertices = Vec3(width, 0, -0);
polygonInfo.triangles.verts[2].texCoords = Tex2F(1, 0);
polygonInfo.triangles.verts[2].colors = Color4B(255, 255, 255, 255);

//top right point
polygonInfo.triangles.verts[3].vertices = Vec3(width, height, 0);
polygonInfo.triangles.verts[3].texCoords = Tex2F(1, 1);
polygonInfo.triangles.verts[3].colors = Color4B(255, 255, 255, 255);

// setting the vertex indices to draw polygon
polygonInfo.triangles.indices[0] = 0;
polygonInfo.triangles.indices[1] = 1;
polygonInfo.triangles.indices[2] = 2;

polygonInfo.triangles.indices[3] = 1;
polygonInfo.triangles.indices[4] = 2;
polygonInfo.triangles.indices[5] = 3;

polygonInfo.setRect(Rect(Vec2(0, 0), Size(width, height)));

sprite->initWithPolygon(polygonInfo);
addChild(sprite);

In update method you can change positions of vertices of a sprite

sprite->getPolygonInfo().triangles.verts[0].vertices.x = 0.0f;

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.