Difference between revisions of "Mesh"

From GiderosMobile
 
(27 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
'''Supported platforms:''' android, ios, mac, pc<br/>
+
<!-- GIDEROSOBJ:Mesh -->
 +
'''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/>
 
'''Available since:''' Gideros 2012.09<br/>
 
'''Available since:''' Gideros 2012.09<br/>
 +
'''Inherits from:''' [[Sprite]]<br/>
 +
 
=== Description ===
 
=== Description ===
<br />
+
The '''Mesh''' class is used to create and display custom constructed set of triangles (triangle meshes). It basically consists of 4 arrays:
Mesh class is used to create and display custom constructed set of triangles (triangle meshes). It basically consists of<br />
+
*vertex
4 arrays: vertex, index, color (optional), textureCoordinate (optional) and a texture (optional) and it provides more than<br />
+
*index
one way to set/modify these arrays.<br />
+
*color (optional)
<br />
+
*textureCoordinate (optional)
Mesh can be 2D or 3D, the latter expects an additionnal Z coordinate in its vertices. Additionnally, 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.
+
and a texture (optional). The Mesh class provides more than one way to set/modify these arrays.
<br />
+
 
<ul><br />
+
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.
<li>`Note 1:` Mesh class doesn't do bounds check. If an element at index array points to an non-existent vertex, the application may crash.</li><br />
+
 
</ul><br />
+
'''the Mesh class doesn't do bounds check: if an element at index array points to an non-existent vertex, the application may crash'''
<br />
+
 
=== Examples ===
+
=== Example ===
'''Mesh usage'''<br/>
+
'''Drawing a colored Mesh rectangle'''
<source lang="lua">local mesh = Mesh.new()
+
<syntaxhighlight lang="lua">
 +
application:configureFrustum(45, -2*128)
 +
--application:configureFrustum(0, 2*128)
 +
 
 +
local mesh = Mesh.new()
 
stage:addChild(mesh)
 
stage:addChild(mesh)
 
-- 1. vertex (0, 0)
 
-- 1. vertex (0, 0)
Line 32: Line 39:
 
-- 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)
 +
</syntaxhighlight>
 +
 
 
{|-
 
{|-
| style="width: 50%;"|
+
| style="width: 50%; vertical-align:top;"|
 +
 
 
=== Methods ===
 
=== Methods ===
[[Mesh.new]] - <br/>
+
[[Mesh.new]] ''creates a new Mesh instance''<br/><!--GIDEROSMTD:Mesh.new(is3d) creates a new Mesh instance-->
[[Mesh:clearColorArray]] - <br/>
+
[[Mesh:clearColorArray]] ''clears the color array''<br/><!--GIDEROSMTD:Mesh:clearColorArray() clears the color array-->
[[Mesh:clearIndexArray]] - <br/>
+
[[Mesh:clearIndexArray]] ''clears the index array''<br/><!--GIDEROSMTD:Mesh:clearIndexArray() clears the index array-->
[[Mesh:clearTexture]] - <br/>
+
[[Mesh:clearTexture]] ''clears the Mesh texture''<br/><!--GIDEROSMTD:Mesh:clearTexture(slot) clears the Mesh texture-->
[[Mesh:clearTextureCoordinateArray]] - <br/>
+
[[Mesh:clearTextureCoordinateArray]] ''clears the texture coordinate array''<br/><!--GIDEROSMTD:Mesh:clearTextureCoordinateArray() clears the texture coordinate array-->
[[Mesh:clearVertexArray]] - <br/>
+
[[Mesh:clearVertexArray]] ''clears the vertex array''<br/><!--GIDEROSMTD:Mesh:clearVertexArray() clears the vertex array-->
[[Mesh:getColor]] - Returns color and alpha of the i-th element from color array<br/>
+
[[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-->
[[Mesh:getColorArraySize]] - Get size of the Color array<br/>
+
[[Mesh:getColorArraySize]] ''gets the size of the Color array''<br/><!--GIDEROSMTD:Mesh:getColorArraySize() gets the size of the Color array-->
[[Mesh:getIndex]] - Returns the i-th element from index array<br/>
+
[[Mesh:getIndex]] ''returns the i-th element from index array''<br/><!--GIDEROSMTD:Mesh:getIndex(i) returns the i-th element from index array-->
[[Mesh:getIndexArraySize]] - Get size of the Index array<br/>
+
[[Mesh:getIndexArraySize]] ''gets the size of the Index array''<br/><!--GIDEROSMTD: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<br/>
+
[[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-->
[[Mesh:getTextureCoordinateArraySize]] - Get size of the Texture Coordinate array<br/>
+
[[Mesh:getTextureCoordinateArraySize]] ''gets the size of the Texture Coordinate array''<br/><!--GIDEROSMTD: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<br/>
+
[[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]] - Get size of the Vertices array<br/>
+
[[Mesh:getVertexArraySize]] ''gets the size of the Vertices array''<br/><!--GIDEROSMTD:Mesh:getVertexArraySize() gets the size of the Vertices array-->
[[Mesh:resizeColorArray]] - <br/>
+
[[Mesh:resizeColorArray]] ''resizes the Color array''<br/><!--GIDEROSMTD:Mesh:resizeColorArray(size) resizes the Color array-->
[[Mesh:resizeIndexArray]] - <br/>
+
[[Mesh:resizeIndexArray]] ''resizes the Index array''<br/><!--GIDEROSMTD:Mesh:resizeIndexArray(size) resizes the Index array-->
[[Mesh:resizeTextureCoordinateArray]] - <br/>
+
[[Mesh:resizeTextureCoordinateArray]] ''resizes the texture coordinates array''<br/><!--GIDEROSMTD:Mesh:resizeTextureCoordinateArray(size) resizes the texture coordinates array-->
[[Mesh:resizeVertexArray]] - <br/>
+
[[Mesh:resizeVertexArray]] ''resizes the vertex array''<br/><!--GIDEROSMTD:Mesh:resizeVertexArray(size) resizes the vertex array-->
[[Mesh:setColor]] - <br/>
+
[[Mesh:setAutoSort]] ''enables depth sorting for translucency''<br/><!--GIDEROSMTD:Mesh:setAutoSort(bool) enables depth sorting for translucency-->
[[Mesh:setColorArray]] - <br/>
+
[[Mesh:setColor]] ''sets a color in the color array''<br/><!--GIDEROSMTD:Mesh:setColor(i,color,alpha) sets a color in the color array-->
[[Mesh:setColors]] - <br/>
+
[[Mesh:setColorArray]] ''sets or replace the whole color array''<br/><!--GIDEROSMTD:Mesh:setColorArray(colors) sets or replace the whole color array-->
[[Mesh:setGenericArray]] - <br/>
+
[[Mesh:setColors]] ''sets several colors at once''<br/><!--GIDEROSMTD:Mesh:setColors(colors) sets several colors at once-->
[[Mesh:setIndex]] - <br/>
+
[[Mesh:setCullMode]] ''sets the face culling mode''<br/><!--GIDEROSMTD:Mesh:setCullMode(mode) sets the face culling mode-->
[[Mesh:setIndexArray]] - <br/>
+
[[Mesh:setGenericArray]] ''sets or replace a generic array''<br/><!--GIDEROSMTD:Mesh:setGenericArray(index,type,mult,count,data) sets or replace a generic array-->
[[Mesh:setIndices]] - <br/>
+
[[Mesh:setIndex]] ''sets an index in the index array''<br/><!--GIDEROSMTD:Mesh:setIndex(i,index) sets an index in the index array-->
[[Mesh:setTexture]] - <br/>
+
[[Mesh:setIndexArray]] ''sets or replace the whole index array''<br/><!--GIDEROSMTD:Mesh:setIndexArray(indices) sets or replace the whole index array-->
[[Mesh:setTextureCoordinate]] - <br/>
+
[[Mesh:setIndices]] ''sets several indices at once''<br/><!--GIDEROSMTD:Mesh:setIndices(indices) sets several indices at once-->
[[Mesh:setTextureCoordinateArray]] - <br/>
+
[[Mesh:setInstanceCount]] ''enables instanced rendering and sets the number of instances to draw''<br/><!--GIDEROSMTD:Mesh:setInstanceCount(count) enables instanced rendering and sets the number of instances to draw-->
[[Mesh:setTextureCoordinates]] - <br/>
+
[[Mesh:setPrimitiveType]] ''sets the type of primitives to render''<br/><!--GIDEROSMTD:Mesh:setPrimitiveType(primitiveType) sets the type of primitives to render-->
[[Mesh:setVertex]] - <br/>
+
[[Mesh:setTexture]] ''attaches a texture to the Mesh'' <br/><!--GIDEROSMTD:Mesh:setTexture(texture,slot) attaches a texture to the Mesh-->
[[Mesh:setVertexArray]] - <br/>
+
[[Mesh:setTextureCoordinate]] ''sets a texture coordinate in the texture coordinates array''<br/><!--GIDEROSMTD:Mesh:setTextureCoordinate(i,u,v) sets a texture coordinate in the texture coordinates array-->
[[Mesh:setVertices]] - <br/>
+
[[Mesh:setTextureCoordinateArray]] ''sets or replace the whole texture coordinates array''<br/><!--GIDEROSMTD:Mesh:setTextureCoordinateArray(textureCoordinates) sets or replace the whole texture coordinates array-->
| style="width: 50%;"|
+
[[Mesh:setTextureCoordinates]] ''sets several texture coordinates at once''<br/><!--GIDEROSMTD:Mesh:setTextureCoordinates(textureCoordinates) sets several texture coordinates at once-->
 +
[[Mesh:setVertex]] ''sets a vertex in the vertex array''<br/><!--GIDEROSMTD:Mesh:setVertex(i,x,y) sets a vertex in the vertex array-->
 +
[[Mesh:setVertexArray]] ''sets or replace the whole vertex array''<br/><!--GIDEROSMTD:Mesh:setVertexArray(vertices) sets or replace the whole vertex array-->
 +
[[Mesh:setVertices]] ''sets several vertices at once''<br/><!--GIDEROSMTD:Mesh:setVertices(vertices) sets several vertices at once-->
 +
 
 +
| style="width: 50%; vertical-align:top;"|
 +
 
 
=== Events ===
 
=== Events ===
 
=== Constants ===
 
=== Constants ===
 
|}
 
|}
 +
 +
{{GIDEROS IMPORTANT LINKS}}

Latest revision as of 23:37, 20 February 2024

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

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

application:configureFrustum(45, -2*128)
--application:configureFrustum(0, 2*128)

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 Color array
Mesh:resizeIndexArray resizes the Index array
Mesh:resizeTextureCoordinateArray resizes the texture coordinates array
Mesh:resizeVertexArray resizes the vertex array
Mesh:setAutoSort enables depth sorting for translucency
Mesh:setColor sets a color in the color array
Mesh:setColorArray sets or replace the whole color array
Mesh:setColors sets several colors at once
Mesh:setCullMode sets the face culling mode
Mesh:setGenericArray sets or replace a generic array
Mesh:setIndex sets an index in the index array
Mesh:setIndexArray sets or replace the whole index array
Mesh:setIndices sets several indices at once
Mesh:setInstanceCount enables instanced rendering and sets the number of instances to draw
Mesh:setPrimitiveType sets the type of primitives to render
Mesh:setTexture attaches a texture to the Mesh
Mesh:setTextureCoordinate sets a texture coordinate in the texture coordinates array
Mesh:setTextureCoordinateArray sets or replace the whole texture coordinates array
Mesh:setTextureCoordinates sets several texture coordinates at once
Mesh:setVertex sets a vertex in the vertex array
Mesh:setVertexArray sets or replace the whole vertex array
Mesh:setVertices sets several vertices at once

Events

Constants