The <attr:> token enables you to apply different texture maps based on the name of the attribute that is assigned to the mesh. It is supported in the form <attr:name index:name default:value>. The tag will look for the named user data (as a string). The index and default tokens are optional; if the index is used, the UINT user data is found first, and the main attribute then must be an array of strings it indexes into. Among other techniques, this allows e.g. facesets, where you can list the faceset names once each in a constant array, and then have a uniform UINT assigned to each face specifying which faceset the face is a member of. Finally, the default, if present, is substituted if the user data cannot be found for any reason.
The <attr:> token works with both the Ai Image shader and Mayas File shader.
For example, in the situation below we have two spheres, and we want to apply separate textures to each one using the same shader.
- Assign a Standard Surface shader to both spheres and connect a file texture to the Base Color attribute.
- In the Image Name of the file node, type the following:
Where 'moon.jpg' is the name of the default texture.
<attr:> texture token
You should see that currently, both spheres receive the same texture map:
- To change the texture of one of the spheres, select the sphere and add an attribute to it - Attributes>Add Attribute. Remember to select its shape node first by pressing Select at the bottom of the attribute editor).
- In the Add Attribute window, type the following in Long name:
mtoa constant planet
- Select String under Data Type. This will allow us to type the name of the texture in the newly created attribute.
- Under extra attributes, you should see the new attribute Mtoa Constant Planet. Enter mars in the text field next to it.
- Rendering the scene reveals the default texture (
moon.jpg) and (
mars.jpg) is assigned to the sphere with the attribute Mtoa Constant Planet (mars).