Difference between revisions of "Mesh"

From GiderosMobile
(mostly for)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
 
 
<!-- GIDEROSOBJ:Mesh -->
 
<!-- GIDEROSOBJ:Mesh -->
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
+
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
'''<translate>Available since</translate>:''' Gideros 2012.09<br/>
+
'''Available since:''' Gideros 2012.09<br/>
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Sprite|Sprite]]<br/>
+
'''Inherits from:''' [[Sprite]]<br/>
  
=== <translate>Description</translate> ===
+
=== 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 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.
  
 
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.
 
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.
+
'''the Mesh class doesn't do bounds check. If an element at index array points to an non-existent vertex, the application may crash'''
  
=== <translate>Examples</translate> ===
+
=== Examples ===
 
'''Mesh usage:'''
 
'''Mesh usage:'''
 
<source lang="lua">
 
<source lang="lua">
Line 37: Line 41:
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Methods</translate> ===
+
=== Methods ===
[[Special:MyLanguage/Mesh.new|Mesh.new]] <br/><!-- GIDEROSMTD:Mesh.new(is3d) -->
+
[[Mesh.new]] ''creates a new Mesh instance''<br/><!--GIDEROSMTD:Mesh.new(is3d) creates a new Mesh instance-->
[[Special:MyLanguage/Mesh:clearColorArray|Mesh:clearColorArray]] <br/><!-- GIDEROSMTD:Mesh:clearColorArray() -->
+
[[Mesh:clearColorArray]] ''clears the color array''<br/><!--GIDEROSMTD:Mesh:clearColorArray() clears the color array-->
[[Special:MyLanguage/Mesh:clearIndexArray|Mesh:clearIndexArray]] <br/><!-- GIDEROSMTD:Mesh:clearIndexArray() -->
+
[[Mesh:clearIndexArray]] ''clears the index array''<br/><!--GIDEROSMTD:Mesh:clearIndexArray() clears the index array-->
[[Special:MyLanguage/Mesh:clearTexture|Mesh:clearTexture]] <br/><!-- GIDEROSMTD:Mesh:clearTexture(slot) -->
+
[[Mesh:clearTexture]] ''clears the Mesh texture''<br/><!--GIDEROSMTD:Mesh:clearTexture(slot) clears the Mesh texture-->
[[Special:MyLanguage/Mesh:clearTextureCoordinateArray|Mesh:clearTextureCoordinateArray]] <br/><!-- GIDEROSMTD:Mesh:clearTextureCoordinateArray() -->
+
[[Mesh:clearTextureCoordinateArray]] ''clears the texture coordinate array''<br/><!--GIDEROSMTD:Mesh:clearTextureCoordinateArray() clears the texture coordinate array-->
[[Special:MyLanguage/Mesh:clearVertexArray|Mesh:clearVertexArray]] <br/><!-- GIDEROSMTD:Mesh:clearVertexArray() -->
+
[[Mesh:clearVertexArray]] ''clears the vertex array''<br/><!--GIDEROSMTD:Mesh:clearVertexArray() clears the vertex array-->
[[Special:MyLanguage/Mesh:getColor|Mesh:getColor]] ''<translate>Returns color and alpha of the i-th element from color array</translate>''<br/><!-- GIDEROSMTD:Mesh:getColor(i) Returns color and alpha of the i-th element from color array -->
+
[[Mesh:getColor]] ''returns color and alpha of the i-th element from color array''<br/><!--GIDEROSMTD:Mesh:getColor(i) returns color and alpha of the i-th element from color array-->
[[Special:MyLanguage/Mesh:getColorArraySize|Mesh:getColorArraySize]] ''<translate>Get size of the Color array</translate>''<br/><!-- GIDEROSMTD:Mesh:getColorArraySize() Get size of the Color array -->
+
[[Mesh:getColorArraySize]] ''gets the size of the Color array''<br/><!--GIDEROSMTD:Mesh:getColorArraySize() gets the size of the Color array-->
[[Special:MyLanguage/Mesh:getIndex|Mesh:getIndex]] ''<translate>Returns the i-th element from index array</translate>''<br/><!-- GIDEROSMTD:Mesh:getIndex(i) Returns the i-th element from index array -->
+
[[Mesh:getIndex]] ''returns the i-th element from index array''<br/><!--GIDEROSMTD:Mesh:getIndex(i) returns the i-th element from index array-->
[[Special:MyLanguage/Mesh:getIndexArraySize|Mesh:getIndexArraySize]] ''<translate>Get size of the Index array</translate>''<br/><!-- GIDEROSMTD:Mesh:getIndexArraySize() Get size of the Index array -->
+
[[Mesh:getIndexArraySize]] ''gets the size of the Index array''<br/><!--GIDEROSMTD:Mesh:getIndexArraySize() gets the size of the Index array-->
[[Special:MyLanguage/Mesh:getTextureCoordinate|Mesh:getTextureCoordinate]] ''<translate>Returns u and v coordinate of the i-th element from texture coordinate array</translate>''<br/><!-- GIDEROSMTD:Mesh:getTextureCoordinate(i) Returns u and v coordinate of the i-th element from texture coordinate array -->
+
[[Mesh:getTextureCoordinate]] ''returns u and v coordinate of the i-th element from texture coordinate array''<br/><!--GIDEROSMTD:Mesh:getTextureCoordinate(i) returns u and v coordinate of the i-th element from texture coordinate array-->
[[Special:MyLanguage/Mesh:getTextureCoordinateArraySize|Mesh:getTextureCoordinateArraySize]] ''<translate>Get size of the Texture Coordinate array</translate>''<br/><!-- GIDEROSMTD:Mesh:getTextureCoordinateArraySize() Get size of the Texture Coordinate array -->
+
[[Mesh:getTextureCoordinateArraySize]] ''gets the size of the Texture Coordinate array''<br/><!--GIDEROSMTD:Mesh:getTextureCoordinateArraySize() gets the size of the Texture Coordinate array-->
[[Special:MyLanguage/Mesh:getVertex|Mesh:getVertex]] ''<translate>Returns x and y coordinate of the i-th element from vertex array</translate>''<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-->
[[Special:MyLanguage/Mesh:getVertexArraySize|Mesh:getVertexArraySize]] ''<translate>Get size of the Vertices array</translate>''<br/><!-- GIDEROSMTD:Mesh:getVertexArraySize() Get 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-->
[[Special:MyLanguage/Mesh:resizeColorArray|Mesh:resizeColorArray]] <br/><!-- GIDEROSMTD:Mesh:resizeColorArray(size) -->
+
[[Mesh:resizeColorArray]] ''resizes the size of the Color array''<br/><!--GIDEROSMTD:Mesh:resizeColorArray(size) resizes the size of the Color array-->
[[Special:MyLanguage/Mesh:resizeIndexArray|Mesh:resizeIndexArray]] <br/><!-- GIDEROSMTD:Mesh:resizeIndexArray(size) -->
+
[[Mesh:resizeIndexArray]] ''resizes the size of the Index array''<br/><!--GIDEROSMTD:Mesh:resizeIndexArray(size) resizes the size of the Index array-->
[[Special:MyLanguage/Mesh:resizeTextureCoordinateArray|Mesh:resizeTextureCoordinateArray]] <br/><!-- GIDEROSMTD:Mesh:resizeTextureCoordinateArray(size) -->
+
[[Mesh:resizeTextureCoordinateArray]] <br/><!--GIDEROSMTD:Mesh:resizeTextureCoordinateArray(size)-->
[[Special:MyLanguage/Mesh:resizeVertexArray|Mesh:resizeVertexArray]] <br/><!-- GIDEROSMTD:Mesh:resizeVertexArray(size) -->
+
[[Mesh:resizeVertexArray]] <br/><!--GIDEROSMTD:Mesh:resizeVertexArray(size)-->
[[Special:MyLanguage/Mesh:setColor|Mesh:setColor]] <br/><!-- GIDEROSMTD:Mesh:setColor(i,color,alpha) -->
+
[[Mesh:setColor]] <br/><!--GIDEROSMTD:Mesh:setColor(i,color,alpha)-->
[[Special:MyLanguage/Mesh:setColorArray|Mesh:setColorArray]] <br/><!-- GIDEROSMTD:Mesh:setColorArray(colors) -->
+
[[Mesh:setColorArray]] <br/><!--GIDEROSMTD:Mesh:setColorArray(colors)-->
[[Special:MyLanguage/Mesh:setColors|Mesh:setColors]] <br/><!-- GIDEROSMTD:Mesh:setColors(colors) -->
+
[[Mesh:setColors]] <br/><!--GIDEROSMTD:Mesh:setColors(colors)-->
[[Special:MyLanguage/Mesh:setGenericArray|Mesh:setGenericArray]] <br/><!-- GIDEROSMTD:Mesh:setGenericArray(index,type,mult,count,data) -->
+
[[Mesh:setGenericArray]] <br/><!--GIDEROSMTD:Mesh:setGenericArray(index,type,mult,count,data)-->
[[Special:MyLanguage/Mesh:setIndex|Mesh:setIndex]] <br/><!-- GIDEROSMTD:Mesh:setIndex(i,index) -->
+
[[Mesh:setIndex]] <br/><!--GIDEROSMTD:Mesh:setIndex(i,index)-->
[[Special:MyLanguage/Mesh:setIndexArray|Mesh:setIndexArray]] <br/><!-- GIDEROSMTD:Mesh:setIndexArray(indices) -->
+
[[Mesh:setIndexArray]] <br/><!--GIDEROSMTD:Mesh:setIndexArray(indices)-->
[[Special:MyLanguage/Mesh:setIndices|Mesh:setIndices]] <br/><!-- GIDEROSMTD:Mesh:setIndices(indices) -->
+
[[Mesh:setIndices]] <br/><!--GIDEROSMTD:Mesh:setIndices(indices)-->
[[Special:MyLanguage/Mesh:setTexture|Mesh:setTexture]] <br/><!-- GIDEROSMTD:Mesh:setTexture(texture,slot) -->
+
[[Mesh:setTexture]] <br/><!--GIDEROSMTD:Mesh:setTexture(texture,slot)-->
[[Special:MyLanguage/Mesh:setTextureCoordinate|Mesh:setTextureCoordinate]] <br/><!-- GIDEROSMTD:Mesh:setTextureCoordinate(i,u,v) -->
+
[[Mesh:setTextureCoordinate]] <br/><!--GIDEROSMTD:Mesh:setTextureCoordinate(i,u,v)-->
[[Special:MyLanguage/Mesh:setTextureCoordinateArray|Mesh:setTextureCoordinateArray]] <br/><!-- GIDEROSMTD:Mesh:setTextureCoordinateArray(textureCoordinates) -->
+
[[Mesh:setTextureCoordinateArray]] <br/><!--GIDEROSMTD:Mesh:setTextureCoordinateArray(textureCoordinates)-->
[[Special:MyLanguage/Mesh:setTextureCoordinates|Mesh:setTextureCoordinates]] <br/><!-- GIDEROSMTD:Mesh:setTextureCoordinates(textureCoordinates) -->
+
[[Mesh:setTextureCoordinates]] <br/><!--GIDEROSMTD:Mesh:setTextureCoordinates(textureCoordinates)-->
[[Special:MyLanguage/Mesh:setVertex|Mesh:setVertex]] <br/><!-- GIDEROSMTD:Mesh:setVertex(i,x,y) -->
+
[[Mesh:setVertex]] <br/><!--GIDEROSMTD:Mesh:setVertex(i,x,y)-->
[[Special:MyLanguage/Mesh:setVertexArray|Mesh:setVertexArray]] <br/><!-- GIDEROSMTD:Mesh:setVertexArray(vertices) -->
+
[[Mesh:setVertexArray]] <br/><!--GIDEROSMTD:Mesh:setVertexArray(vertices)-->
[[Special:MyLanguage/Mesh:setVertices|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;"|
=== <translate>Events</translate> ===
+
=== Events ===
=== <translate>Constants</translate> ===
+
=== Constants ===
 
|}
 
|}
  
 
{{GIDEROS IMPORTANT LINKS}}
 
{{GIDEROS IMPORTANT LINKS}}

Revision as of 04:12, 16 December 2020

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
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). The Mesh class 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.

the 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)

Methods

Mesh.new creates a new Mesh instance
Mesh:clearColorArray clears the color array
Mesh:clearIndexArray clears the index array
Mesh:clearTexture clears the Mesh texture
Mesh:clearTextureCoordinateArray clears the texture coordinate array
Mesh:clearVertexArray clears the vertex array
Mesh:getColor returns color and alpha of the i-th element from color array
Mesh:getColorArraySize gets the size of the Color array
Mesh:getIndex returns the i-th element from index array
Mesh:getIndexArraySize gets the size of the Index array
Mesh:getTextureCoordinate returns u and v coordinate of the i-th element from texture coordinate array
Mesh:getTextureCoordinateArraySize gets the size of the Texture Coordinate array
Mesh:getVertex returns x and y coordinate of the i-th element from vertex array
Mesh:getVertexArraySize gets the size of the Vertices array
Mesh:resizeColorArray resizes the size of the Color array
Mesh:resizeIndexArray resizes the size of the Index array
Mesh:resizeTextureCoordinateArray
Mesh:resizeVertexArray
Mesh:setColor
Mesh:setColorArray
Mesh:setColors
Mesh:setGenericArray
Mesh:setIndex
Mesh:setIndexArray
Mesh:setIndices
Mesh:setTexture
Mesh:setTextureCoordinate
Mesh:setTextureCoordinateArray
Mesh:setTextureCoordinates
Mesh:setVertex
Mesh:setVertexArray
Mesh:setVertices

Events

Constants