Difference between revisions of "Mesh"
(mostly formatting :-) and removed language) |
|||
Line 56: | Line 56: | ||
[[Mesh:getVertex]] ''returns x and y coordinate of the i-th element from vertex array''<br/><!--GIDEROSMTD:Mesh:getVertex(i) returns x and y coordinate of the i-th element from vertex array--> | [[Mesh:getVertex]] ''returns x and y coordinate of the i-th element from vertex array''<br/><!--GIDEROSMTD:Mesh:getVertex(i) returns x and y coordinate of the i-th element from vertex array--> | ||
[[Mesh:getVertexArraySize]] ''gets the size of the Vertices array''<br/><!--GIDEROSMTD:Mesh:getVertexArraySize() gets the size of the Vertices array--> | [[Mesh:getVertexArraySize]] ''gets the size of the Vertices array''<br/><!--GIDEROSMTD:Mesh:getVertexArraySize() gets the size of the Vertices array--> | ||
− | [[Mesh:resizeColorArray]] ''resizes | + | [[Mesh:resizeColorArray]] ''resizes the Color array''<br/><!--GIDEROSMTD:Mesh:resizeColorArray(size) resizes the Color array--> |
− | [[Mesh:resizeIndexArray]] ''resizes | + | [[Mesh:resizeIndexArray]] ''resizes the Index array''<br/><!--GIDEROSMTD:Mesh:resizeIndexArray(size) resizes the Index array--> |
− | [[Mesh:resizeTextureCoordinateArray]] <br/><!--GIDEROSMTD:Mesh:resizeTextureCoordinateArray(size)--> | + | [[Mesh:resizeTextureCoordinateArray]] ''resizes the texture coordinates array'' <br/><!--GIDEROSMTD:Mesh:resizeTextureCoordinateArray(size) resizes the texture coordinates array--> |
− | [[Mesh:resizeVertexArray]] <br/><!--GIDEROSMTD:Mesh:resizeVertexArray(size)--> | + | [[Mesh:resizeVertexArray]] ''resizes the vertex array'' <br/><!--GIDEROSMTD:Mesh:resizeVertexArray(size) resizes the vertex array --> |
− | [[Mesh:setColor]] <br/><!--GIDEROSMTD:Mesh:setColor(i,color,alpha)--> | + | [[Mesh:setColor]] ''set a color in the color array'' <br/><!--GIDEROSMTD:Mesh:setColor(i,color,alpha) set a color in the color array--> |
[[Mesh:setColorArray]] <br/><!--GIDEROSMTD:Mesh:setColorArray(colors)--> | [[Mesh:setColorArray]] <br/><!--GIDEROSMTD:Mesh:setColorArray(colors)--> | ||
[[Mesh:setColors]] <br/><!--GIDEROSMTD:Mesh:setColors(colors)--> | [[Mesh:setColors]] <br/><!--GIDEROSMTD:Mesh:setColors(colors)--> | ||
[[Mesh:setGenericArray]] <br/><!--GIDEROSMTD:Mesh:setGenericArray(index,type,mult,count,data)--> | [[Mesh:setGenericArray]] <br/><!--GIDEROSMTD:Mesh:setGenericArray(index,type,mult,count,data)--> | ||
− | [[Mesh:setIndex]] <br/><!--GIDEROSMTD:Mesh:setIndex(i,index)--> | + | [[Mesh:setIndex]] ''set an index in the index array'' <br/><!--GIDEROSMTD:Mesh:setIndex(i,index) set an index in the index array --> |
[[Mesh:setIndexArray]] <br/><!--GIDEROSMTD:Mesh:setIndexArray(indices)--> | [[Mesh:setIndexArray]] <br/><!--GIDEROSMTD:Mesh:setIndexArray(indices)--> | ||
[[Mesh:setIndices]] <br/><!--GIDEROSMTD:Mesh:setIndices(indices)--> | [[Mesh:setIndices]] <br/><!--GIDEROSMTD:Mesh:setIndices(indices)--> | ||
− | [[Mesh:setTexture]] <br/><!--GIDEROSMTD:Mesh:setTexture(texture,slot)--> | + | [[Mesh:setTexture]] ''attach a texture to the Mesh'' <br/><!--GIDEROSMTD:Mesh:setTexture(texture,slot) attach a texture to the Mesh--> |
− | [[Mesh:setTextureCoordinate]] <br/><!--GIDEROSMTD:Mesh:setTextureCoordinate(i,u,v)--> | + | [[Mesh:setTextureCoordinate]] ''set a texture coordinate in the texture coordinates array'' <br/><!--GIDEROSMTD:Mesh:setTextureCoordinate(i,u,v) set a texture coordinate in the texture coordinates array--> |
[[Mesh:setTextureCoordinateArray]] <br/><!--GIDEROSMTD:Mesh:setTextureCoordinateArray(textureCoordinates)--> | [[Mesh:setTextureCoordinateArray]] <br/><!--GIDEROSMTD:Mesh:setTextureCoordinateArray(textureCoordinates)--> | ||
[[Mesh:setTextureCoordinates]] <br/><!--GIDEROSMTD:Mesh:setTextureCoordinates(textureCoordinates)--> | [[Mesh:setTextureCoordinates]] <br/><!--GIDEROSMTD:Mesh:setTextureCoordinates(textureCoordinates)--> | ||
− | [[Mesh:setVertex]] <br/><!--GIDEROSMTD:Mesh:setVertex(i,x,y)--> | + | [[Mesh:setVertex]] ''set a vertex in the vertex array''<br/><!--GIDEROSMTD:Mesh:setVertex(i,x,y) set a vertex in the vertex array--> |
[[Mesh:setVertexArray]] <br/><!--GIDEROSMTD:Mesh:setVertexArray(vertices)--> | [[Mesh:setVertexArray]] <br/><!--GIDEROSMTD:Mesh:setVertexArray(vertices)--> | ||
[[Mesh:setVertices]] <br/><!--GIDEROSMTD:Mesh:setVertices(vertices)--> | [[Mesh:setVertices]] <br/><!--GIDEROSMTD:Mesh:setVertices(vertices)--> | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
+ | |||
=== Events === | === Events === | ||
=== Constants === | === Constants === |
Revision as of 16:42, 7 January 2021
Supported platforms:
Available since: Gideros 2012.09
Inherits from: Sprite
Description
The 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). The Mesh class provides more than one way to set/modify these arrays.
The 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.
the Mesh class doesn't do bounds check: if an element at index array points to an non-existent vertex, the application may crash
Example
Drawing a colored Mesh rectangle
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)
MethodsMesh.new creates a new Mesh instance |
EventsConstants |