Difference between revisions of "Mesh:setVertexAttribute"
m (→Synopsis) |
m |
||
(2 intermediate revisions by one other user not shown) | |||
Line 10: | Line 10: | ||
=== Arguments === | === Arguments === | ||
− | {{param|number|vertexindex|The index of the the vertex to be modified.}} | + | {{param|number|vertexindex|The index of the the vertex to be modified (one-based).}} |
− | {{param|number|attributeindex|The index of the attribute within the vertex to be modified.}} | + | {{param|number|attributeindex|The index of the attribute within the vertex to be modified (one-based).}} |
{{param|number|value1|The new value for the first component of the attribute.}} | {{param|number|value1|The new value for the first component of the attribute.}} | ||
{{param|number|value2|The new value for the second component of the attribute.}} | {{param|number|value2|The new value for the second component of the attribute.}} | ||
Line 18: | Line 18: | ||
Nothing. | Nothing. | ||
=== Notes === | === Notes === | ||
− | Attribute components which exist within the attribute but are not specified as arguments default to 0 for attributes with the <code>float</code> data type, and | + | Attribute components which exist within the attribute but are not specified as arguments default to 0 for attributes with the <code>float</code> data type, and 1 for the <code>byte</code> data type. |
== Examples == | == Examples == | ||
Line 25: | Line 25: | ||
-- Standard mesh with position, texture coordinates, and color attributes. | -- Standard mesh with position, texture coordinates, and color attributes. | ||
mesh = love.graphics.newMesh { | mesh = love.graphics.newMesh { | ||
− | {0, 0, 0, 0, | + | {0, 0, 0, 0, 1, 1, 1, 1}, -- first vertex positioned at (0, 0) |
− | {400, 0, 0, 0, | + | {400, 0, 0, 0, 1, 1, 1, 1}, -- second vertex positioned at (400, 0) |
− | {200, 400, 0, 0, | + | {200, 400, 0, 0, 1, 1, 1, 1}, -- third vertex positioned at (200, 400) |
} | } | ||
Line 37: | Line 37: | ||
for i = 1, mesh:getVertexCount() do | for i = 1, mesh:getVertexCount() do | ||
-- The 3rd vertex attribute for a standard mesh is its color. | -- The 3rd vertex attribute for a standard mesh is its color. | ||
− | mesh:setVertexAttribute(i, 3, (time * 10) % | + | mesh:setVertexAttribute(i, 3, (time * 10) % 1, 1, 1) |
end | end | ||
end | end |
Latest revision as of 00:29, 5 May 2020
Available since LÖVE 0.10.0 |
This function is not supported in earlier versions. |
Sets the properties of a specific attribute within a vertex in the Mesh.
Meshes without a custom vertex format specified in love.graphics.newMesh have position as their first attribute, texture coordinates as their second attribute, and color as their third attribute.
Contents
Function
Synopsis
Mesh:setVertexAttribute( vertexindex, attributeindex, value1, value2, ... )
Arguments
number vertexindex
- The index of the the vertex to be modified (one-based).
number attributeindex
- The index of the attribute within the vertex to be modified (one-based).
number value1
- The new value for the first component of the attribute.
number value2
- The new value for the second component of the attribute.
number ...
- Any additional vertex attribute components.
Returns
Nothing.
Notes
Attribute components which exist within the attribute but are not specified as arguments default to 0 for attributes with the float
data type, and 1 for the byte
data type.
Examples
Modify the colors of a standard mesh after it's created.
-- Standard mesh with position, texture coordinates, and color attributes.
mesh = love.graphics.newMesh {
{0, 0, 0, 0, 1, 1, 1, 1}, -- first vertex positioned at (0, 0)
{400, 0, 0, 0, 1, 1, 1, 1}, -- second vertex positioned at (400, 0)
{200, 400, 0, 0, 1, 1, 1, 1}, -- third vertex positioned at (200, 400)
}
local time = 0
function love.update(dt)
time = time + dt
for i = 1, mesh:getVertexCount() do
-- The 3rd vertex attribute for a standard mesh is its color.
mesh:setVertexAttribute(i, 3, (time * 10) % 1, 1, 1)
end
end
function love.draw()
love.graphics.draw(mesh)
end
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info