Difference between revisions of "Mesh"
Line 5: | Line 5: | ||
'''<translate>Available since</translate>:''' Gideros 2012.09<br/> | '''<translate>Available since</translate>:''' Gideros 2012.09<br/> | ||
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Sprite|Sprite]]<br/> | '''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Sprite|Sprite]]<br/> | ||
+ | |||
=== <translate>Description</translate> === | === <translate>Description</translate> === | ||
− | + | Mesh class is used to create and display custom constructed set of triangles (triangle meshes). It basically consists of 4 arrays: vertex, index, color (optional), textureCoordinate (optional) and a texture (optional) and it provides more than one way to set/modify these arrays. | |
− | Mesh class is used to create and display custom constructed set of triangles (triangle meshes). It basically consists of | + | |
− | 4 arrays: vertex, index, color (optional), textureCoordinate (optional) and a texture (optional) and it provides more than | + | Mesh can be 2D or 3D, the latter expects an additional Z coordinate in its vertices. Additionally, 3D meshes and their children are rendered with depth testing enabled, which prevents far objects to be drawn above nearest ones, irrespective of actual drawing order. |
− | one way to set/modify these arrays. | + | |
− | + | ''note:'' Mesh class doesn't do bounds check. If an element at index array points to an non-existent vertex, the application may crash. | |
− | Mesh can be 2D or 3D, the latter expects an | + | |
− | |||
− | |||
− | |||
− | |||
− | |||
=== <translate>Examples</translate> === | === <translate>Examples</translate> === | ||
− | '''Mesh usage''' | + | '''Mesh usage:''' |
− | <source lang="lua">local mesh = Mesh.new() | + | <source lang="lua"> |
+ | local mesh = Mesh.new() | ||
stage:addChild(mesh) | stage:addChild(mesh) | ||
-- 1. vertex (0, 0) | -- 1. vertex (0, 0) | ||
Line 35: | Line 32: | ||
-- 3. vertex 0x0000ff color with 1 alpha | -- 3. vertex 0x0000ff color with 1 alpha | ||
-- 4. vertex 0xffff00 color with 0 alpha | -- 4. vertex 0xffff00 color with 0 alpha | ||
− | mesh:setColorArray(0xff0000, 0.5, 0x00ff00, 0.7, 0x0000ff, 1.0, 0xffff00, 0)</source> | + | mesh:setColorArray(0xff0000, 0.5, 0x00ff00, 0.7, 0x0000ff, 1.0, 0xffff00, 0) |
+ | </source> | ||
+ | |||
{|- | {|- | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
Line 71: | Line 70: | ||
[[Special:MyLanguage/Mesh:setVertexArray|Mesh:setVertexArray]] <br/><!-- GIDEROSMTD:Mesh:setVertexArray(vertices) --> | [[Special:MyLanguage/Mesh:setVertexArray|Mesh:setVertexArray]] <br/><!-- GIDEROSMTD:Mesh:setVertexArray(vertices) --> | ||
[[Special:MyLanguage/Mesh:setVertices|Mesh:setVertices]] <br/><!-- GIDEROSMTD:Mesh:setVertices(vertices) --> | [[Special:MyLanguage/Mesh:setVertices|Mesh:setVertices]] <br/><!-- GIDEROSMTD:Mesh:setVertices(vertices) --> | ||
+ | |||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
=== <translate>Events</translate> === | === <translate>Events</translate> === | ||
=== <translate>Constants</translate> === | === <translate>Constants</translate> === | ||
|} | |} | ||
− | |||
− |
Revision as of 23:38, 9 December 2019
Supported platforms:
Available since: Gideros 2012.09
Inherits from: Sprite
Description
Mesh class is used to create and display custom constructed set of triangles (triangle meshes). It basically consists of 4 arrays: vertex, index, color (optional), textureCoordinate (optional) and a texture (optional) and it provides more than one way to set/modify these arrays.
Mesh can be 2D or 3D, the latter expects an additional Z coordinate in its vertices. Additionally, 3D meshes and their children are rendered with depth testing enabled, which prevents far objects to be drawn above nearest ones, irrespective of actual drawing order.
note: Mesh class doesn't do bounds check. If an element at index array points to an non-existent vertex, the application may crash.
Examples
Mesh usage:
local mesh = Mesh.new()
stage:addChild(mesh)
-- 1. vertex (0, 0)
-- 2. vertex (100, 0)
-- 3. vertex (100, 150)
-- 4. vertex (0, 150)
mesh:setVertexArray(0, 0, 100, 0, 100, 150, 0, 150)
-- 1. triangle from 1, 2 and 3 vertex
-- 2. triangle from 1, 3 and 4 vertex
mesh:setIndexArray(1, 2, 3, 1, 3, 4)
-- 1. vertex 0xff0000 color with 0.5 alpha
-- 2. vertex 0x00ff00 color with 0.7 alpha
-- 3. vertex 0x0000ff color with 1 alpha
-- 4. vertex 0xffff00 color with 0 alpha
mesh:setColorArray(0xff0000, 0.5, 0x00ff00, 0.7, 0x0000ff, 1.0, 0xffff00, 0)