Flips the geometry’s texture u-coordinates.
In order for texture() to work, the geometry needs a way to map the points on its surface to the pixels in a rectangular image that's used as a texture. The geometry's vertex at coordinates (x, y, z)
maps to the texture image's pixel at coordinates (u, v)
.
The myGeometry.uvs array stores the (u, v)
coordinates for each vertex in the order it was added to the geometry. Calling myGeometry.flipU()
flips a geometry's u-coordinates so that the texture appears mirrored horizontally.
For example, a plane's four vertices are added clockwise starting from the top-left corner. Here's how calling myGeometry.flipU()
would change a plane's texture coordinates:
// Print the original texture coordinates.
// Output: [0, 0, 1, 0, 0, 1, 1, 1]
console.log(myGeometry.uvs);
// Flip the u-coordinates.
myGeometry.flipU();
// Print the flipped texture coordinates.
// Output: [1, 0, 0, 0, 1, 1, 0, 1]
console.log(myGeometry.uvs);
// Notice the swaps:
// Top vertices: [0, 0, 1, 0] --> [1, 0, 0, 0]
// Bottom vertices: [0, 1, 1, 1] --> [1, 1, 0, 1]
示例
Notice any errors or typos? Please let us know. Please feel free to edit src/webgl/p5.Geometry.js and open a pull request!