Texture To Face Color
The following example samples the UV coordinates at the center of each face and assigns the pixel color found at that point to all three Vertex Color vertices associated with that face. The result is a "stained glass" effect which depends on the mesh topology. In this particular case, a Rectangle with Garment Maker was used to produce interesting triangulation, but the approach applies to any mesh.
- Create a Rectangle shape with Length 120.0 and Width 160.0 units.
- Add a Garment Maker modifier and set to Density 0.1
- Add a UVW Map modifier to generate Planar Texture Coordinates in Channel 1.
- Add a Genome modifier to the stack, set to "Face Corners" iteration mode.
- Open the Editor and press Ctrl+[O] to create an Output node, set to Color channel.
- Press [O] and [T] to create a TexmapEval operator.
- Click the <Add Texture Map> button and select a Bitmap texture map, then pick an image file from disk.
- Drag a wire from TextureCoord input socket and select Object>FaceQuery operator from the menu.
- With the FaceQuery selected, press [I] and [M] to connect a CurrentMesh input node to the Geometry slot.
- Drag a wire from the FaceIndex socket and select Input>InputChannel>FaceIndex from the menus.
RESULT: Depending on the mesh resolution, the image will be more or less pixelated.
The left image shows the original bitmap displayed in the viewport. The right image shows the Face Colors at meshing density of 0.2:
As you can see, the new image takes the texel color at a few sampling points exactly at the center of each triangle and paints the whole triangle in that color.
To make this looks smoother, we can sample the 3 vertices of each face and use the average color instead:
RESULT: At the same mesh density of 0.2, the left image (vertex sampling average) looks much smoother than the right image (face center, same as above):
Here are the results of meshing with density of 0.3 and 0.4:
And this is the mesh with Density of 0.1, cloned a second time with a 3ds Max Lattice modifier to convert the edges to struts. Left image uses average vertex sampling, right image uses face center sampling:
The following simple animation was created by keyframing a Subdivide operator from 10.0 to 0.5 units over 100 frame. It played back in real time in the viewports. It was rendered in Default Scanline by adding a Vertex Color map to the Diffuse and Self-Illumination map slots of a Standard material. Total render time was 67 seconds:
Vertex Color Sampling
We can interpolate between the colors at the three vertices of the face instead of using a single constant colot, but the result will be much less pleasant.
- Delete the second and third TexmapEval operators.
- Press [L] and [M] to create a Logic > Mux operator, change the number of inputs to 4.
- Connect the 3 FaceQuery operators to the first 3 sockets of the Mux.
- Select the Mux and press [I], [C] and [V] to connect a VertexIndex channel to the Selector socket. This channel will change from 0 to 2 for each FaceIndex iteration.
- Connect the output of the Mux to the TextureCoord input of the TexmapEval operator.
RESULT: Each vertex of each face will get the corresponding texel color and the color will then be interpolated over the face (left image).
This is equivalent to baking the texture into the Vertex Color channel as performed by the 3ds Max Vertex Paint modifier (right image):