Difference between revisions of "Mesh:setVertexMap"

(Add mesh:setVertexMap() (without arguments))
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{{newin|[[0.9.0]]|090|type=function}}
 
{{newin|[[0.9.0]]|090|type=function}}
Sets the vertex map for a Geometry. The vertex map describes the order in which the vertices are used when the Geometry is drawn.
+
Sets the vertex map for the Mesh. The vertex map describes the order in which the vertices are used when the Mesh is drawn. The vertices, vertex map, and mesh draw mode work together to determine what exactly is displayed on the screen.
  
The vertex map allows you to re-order or reuse vertices when drawing without changing the actual vertex parameters or duplicating vertices. It is especially useful when combined with different [[GeometryDrawMode|Geometry Draw Modes]].
+
The vertex map allows you to re-order or reuse vertices when drawing without changing the actual vertex parameters or duplicating vertices. It is especially useful when combined with different [[MeshDrawMode|Mesh Draw Modes]].
  
 
== Function ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
Geometry:setVertexMap( vertex_map )
+
Mesh:setVertexMap( map )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|table|vertex_map|A table containing a list of vertex indices to use when drawing. Values must be in the range of [1, [[Geometry:getVertexCount|Geometry:getVertexCount()]]].}}
+
{{param|table|map|A table containing a list of vertex indices to use when drawing. Values must be in the range of [1, [[Mesh:getVertexCount|Mesh:getVertexCount()]]].}}
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
Line 17: Line 17:
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
Geometry:setVertexMap( vi1, vi2, vi3, ... )
+
Mesh:setVertexMap( vi1, vi2, vi3, ... )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|number|vi1|The index of the first vertex to use when drawing. Must be in the range of [1, [[Geometry:getVertexCount|Geometry:getVertexCount()]]].}}
+
{{param|number|vi1|The index of the first vertex to use when drawing. Must be in the range of [1, [[Mesh:getVertexCount|Mesh:getVertexCount()]]].}}
 
{{param|number|vi2|The index of the second vertex to use when drawing.}}
 
{{param|number|vi2|The index of the second vertex to use when drawing.}}
 
{{param|number|vi3|The index of the third vertex to use when drawing.}}
 
{{param|number|vi3|The index of the third vertex to use when drawing.}}
 +
=== Returns ===
 +
Nothing.
 +
 +
== Function ==
 +
{{newin|[[11.0]]|110|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
Mesh:setVertexMap( data, datatype )
 +
</source>
 +
=== Arguments ===
 +
{{param|Data|data|Array of vertex indices to use when drawing. Values must be in the range of [0, [[Mesh:getVertexCount|Mesh:getVertexCount()]]-1]}}
 +
{{param|IndexDataType|datatype|Datatype of the vertex indices array above.}}
 +
 +
=== Returns ===
 +
Nothing.
 +
 +
== Function ==
 +
Disables the vertex map for this mesh.
 +
=== Synopsis ===
 +
<source lang="lua">
 +
Mesh:setVertexMap( )
 +
</source>
 +
=== Arguments ===
 +
None.
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
Line 31: Line 55:
 
function love.load()
 
function love.load()
 
     image = love.graphics.newImage("pig.png")
 
     image = love.graphics.newImage("pig.png")
     local w,h = image:getWidth(), image:getHeight()
+
     local w,h = image:getDimensions()
  
     -- We want to make a Geometry with 1 vertex in the middle of the image, and 4 at the corners.
+
     -- We want to make a Mesh with 1 vertex in the middle of the image, and 4 at the corners.
 
     local vertices = {
 
     local vertices = {
         {w/2, h/2, 0.5, 0.5, 255,   0,   0}, -- Center vertex has a red tint, the rest are white.
+
         {w/2, h/2,   0.5, 0.5,   1, 0, 0}, -- Center vertex, with a red tint.
         {0,  0,   0,  0,   255, 255, 255},
+
         {0,  0,     0,  0,     1, 1, 1}, -- Top left.
         {w,  0,   1,  0,   255, 255, 255},
+
         {w,  0,     1,  0,     1, 1, 1}, -- Top right.
         {w,  h,   1,  1,   255, 255, 255},
+
         {w,  h,     1,  1,     1, 1, 1}, -- Bottom right.
         {0,  h,   0,  1,   255, 255, 255},
+
         {0,  h,     0,  1,     1, 1, 1}, -- Bottom left.
 
     }
 
     }
  
     -- But there's a problem! The drawn geometry will have a big triangle missing on its left side.
+
     -- But there's a problem! The drawn mesh will have a big triangle missing on its left side.
     -- This is because, in the default draw mode ("fan"), the vertices don't "loop": the top left vertex (#2) is unconnected to the bottom left one (#5).
+
     -- This is because, in the default mesh draw mode ("fan"), the vertices don't "loop": the top left vertex (#2) is unconnected to the bottom left one (#5).
     geometry = love.graphics.newGeometry(vertices)
+
     mesh = love.graphics.newMesh(vertices)
 +
    mesh:setTexture(image)
  
 
     -- We could copy/paste the second vertex onto the end of the table of vertices.
 
     -- We could copy/paste the second vertex onto the end of the table of vertices.
 
     -- But instead we can just change the vertex map!
 
     -- But instead we can just change the vertex map!
     geometry:setVertexMap(1, 2, 3, 4, 5, 2)
+
     mesh:setVertexMap(1, 2, 3, 4, 5, 2)
 
end
 
end
  
 
function love.draw()
 
function love.draw()
     love.graphics.draw(image, geometry, 0, 0)
+
     love.graphics.draw(mesh, 0, 0)
 
end
 
end
 
</source>
 
</source>
  
 
== See Also ==
 
== See Also ==
* [[parent::Geometry]]
+
* [[parent::Mesh]]
* [[Geometry:getVertexMap]]
+
* [[Mesh:getVertexMap]]
* [[GeometryDrawMode]]
+
* [[MeshDrawMode]]
 
[[Category:Functions]]
 
[[Category:Functions]]
{{#set:Description=Sets the vertex map for a Geometry.}}
+
{{#set:Description=Sets the vertex map for the Mesh.}}
 
== Other Languages ==
 
== Other Languages ==
{{i18n|Geometry:setVertexMap}}
+
{{i18n|Mesh:setVertexMap}}

Latest revision as of 00:51, 13 January 2022

Available since LÖVE 0.9.0
This function is not supported in earlier versions.

Sets the vertex map for the Mesh. The vertex map describes the order in which the vertices are used when the Mesh is drawn. The vertices, vertex map, and mesh draw mode work together to determine what exactly is displayed on the screen.

The vertex map allows you to re-order or reuse vertices when drawing without changing the actual vertex parameters or duplicating vertices. It is especially useful when combined with different Mesh Draw Modes.

Function

Synopsis

Mesh:setVertexMap( map )

Arguments

table map
A table containing a list of vertex indices to use when drawing. Values must be in the range of [1, Mesh:getVertexCount()].

Returns

Nothing.

Function

Synopsis

Mesh:setVertexMap( vi1, vi2, vi3, ... )

Arguments

number vi1
The index of the first vertex to use when drawing. Must be in the range of [1, Mesh:getVertexCount()].
number vi2
The index of the second vertex to use when drawing.
number vi3
The index of the third vertex to use when drawing.

Returns

Nothing.

Function

Available since LÖVE 11.0
This variant is not supported in earlier versions.

Synopsis

Mesh:setVertexMap( data, datatype )

Arguments

Data data
Array of vertex indices to use when drawing. Values must be in the range of [0, Mesh:getVertexCount()-1]
IndexDataType datatype
Datatype of the vertex indices array above.

Returns

Nothing.

Function

Disables the vertex map for this mesh.

Synopsis

Mesh:setVertexMap( )

Arguments

None.

Returns

Nothing.

Examples

Use a vertex map to fix a visual glitch without copy/pasting vertices.

function love.load()
    image = love.graphics.newImage("pig.png")
    local w,h = image:getDimensions()

    -- We want to make a Mesh with 1 vertex in the middle of the image, and 4 at the corners.
    local vertices = {
        {w/2, h/2,   0.5, 0.5,   1, 0, 0}, -- Center vertex, with a red tint.
        {0,   0,     0,   0,     1, 1, 1}, -- Top left.
        {w,   0,     1,   0,     1, 1, 1}, -- Top right.
        {w,   h,     1,   1,     1, 1, 1}, -- Bottom right.
        {0,   h,     0,   1,     1, 1, 1}, -- Bottom left.
    }

    -- But there's a problem! The drawn mesh will have a big triangle missing on its left side.
    -- This is because, in the default mesh draw mode ("fan"), the vertices don't "loop": the top left vertex (#2) is unconnected to the bottom left one (#5).
    mesh = love.graphics.newMesh(vertices)
    mesh:setTexture(image)

    -- We could copy/paste the second vertex onto the end of the table of vertices.
    -- But instead we can just change the vertex map!
    mesh:setVertexMap(1, 2, 3, 4, 5, 2)
end

function love.draw()
    love.graphics.draw(mesh, 0, 0)
end

See Also

Other Languages