{{newin (日本語)|[[0.10.0 (日本語)|0.10.0]]|100|type=関数}}
Attaches a per-vertex attribute from a [[Mesh]] onto this SpriteBatch, for use when drawing. This can be combined with a [[Shader]] to augment a SpriteBatch with per-vertex or additional per-sprite information instead of just having per-sprite colors.

Each sprite in a SpriteBatch has 4 vertices in the following order: top-left, bottom-left, top-right, bottom-right. The index returned by [[SpriteBatch:add]] (and used by [[SpriteBatch:set]]) can used to determine the first vertex of a specific sprite with the formula <code>1 + 4 * ( id - 1 )</code>.
== 関数 ==
=== 概要 ===
<source lang="lua">
SpriteBatch:attachAttribute( name, mesh )
</source>
=== 引数 ===
{{param (日本語)|string|name|The name of the vertex attribute to attach.}}
{{param (日本語)|Mesh|mesh|The Mesh to get the vertex attribute from.}}
=== 返値 ===
ありません。

== 注釈 ==
If a [[Mesh]] wasn't [[love.graphics.newMesh|created]] with a custom vertex format, it will have 3 vertex attributes named <code>VertexPosition</code>, <code>VertexTexCoord</code>, and <code>VertexColor</code>. If vertex attributes with those names are attached to the SpriteBatch, it will override the SpriteBatch's sprite positions, texture coordinates, and sprite colors, respectively.

Custom named attributes can be accessed in a [[Shader|vertex shader]] by declaring them as <code>attribute vec4 MyCustomAttributeName;</code> at the top-level of the vertex shader code. The name must match what was specified in the Mesh's vertex format and in the <code>name</code> argument of [[SpriteBatch:attachAttribute]].

A Mesh must have at least 4 * [[SpriteBatch:getBufferSize]] vertices in order to be attachable to a SpriteBatch.

== 関連 ==
* [[parent::SpriteBatch (日本語)]]
* [[Mesh (日本語)]]
* [[Mesh:getVertexFormat (日本語)]]
* [[love.graphics.draw (日本語)]]
[[Category:Functions (日本語)]]
{{#set:Description=Attaches a per-vertex attribute from a [[Mesh]] onto this SpriteBatch, for use when drawing.}}
== そのほかの言語 ==
{{i18n (日本語)|SpriteBatch:attachAttribute}}