Hello everyone.
As the next step in improving Corona’s graphics pipeline, I’m glad to introduce the preview of display.newMesh(). This new API creates a Shape Object with provided vertices. Please, give it a spin. I made demo project with different features of meshes, including a test implementation of the Spine runtime. Please, do not use it in real projects for now. I’ve sent a pull request to actual repo with Spine Runtimes. It still has to be properly tested.
Full documentation is available here: https://docs.coronalabs.com/daily/api/library/display/newMesh.html
Here is quick reference:
[lua]
local mesh = display.newMesh(
{
– parent display group (optional)
– parent = group
– position relative to parent (optional)
x = 100,
y = 100,
– mesh mode. One of “triangles”, “strip”, “fan”, or “indexed”
mode = “triangles”,
– vertices used to build a mesh
vertices = {
0,0, 50,0, 0,100,
0,100, 50,0, 100,100,
100,100, 50,0, 100,0
},
– optional texture coordinates; this must be same size as vertices
uvs = {
0,0, 0.5,0, 0,1,
0,1, 0.5,0, 1,1,
1,1, 0.5,0, 1,0
},
– if mode is “indexed” these triplets would be used to form triangles, ignored otherwise
– indices = { 1,2,3, 2,3,4, 3,4,5 },
– if set to true, indices would be treated ad 0 based array, false by default
– zeroBasedIndices = true
})
– Accessing properties of Mesh path with mesh.path:
– All vertices would be offset so origin is in the center of mesh; to restore position
– use following code:
mesh:translate( mesh.path:getVertexOffset() )
– modifying & accessing mesh (you can not delete or create new vertices, only modify existing)
– positions:
local x, y = mesh.path:getVertex( 3 )
mesh.path:setVertex( 3, x, y )
– texture coordinates:
local u, v = mesh.path:getUV( 3 )
mesh.path:setUV( 3, u, v )
[/lua]
Please, note, that this feature is still in testing. I would suggest not to use in production, but feel free to play with it and tell me if something is wrong.
Download latest daily build to use it (note, there is a know rare crash when using meshes in 2016.2890, it would be fixed in next daily build).