https://stackoverflow.com/questions/20774648/three-js-generate-uv-coordinate
使用模型表面法线来决定使用(xyz)中的哪两个,对应到UV坐标当中。用起来相当不错。当然如果能在设计模型的时候进行展UV就更好了。
The other answers here were a great help but didn't quite fit my requirements to apply a repeating pattern texture to all sides of a shape with mostly flat surfaces. The problem is that using only the x and y components as u and v results in weird stretched textures on vertical surfaces.
My solution below uses surface normals to pick which two components (x, y and z) to map to u and v. It's still pretty crude but it works quite well.
functionassignUVs(geometry) {
geometry.faceVertexUvs[0] =[];
geometry.faces.forEach(function(face) {var components = ['x', 'y', 'z'].sort(function(a, b) {return Math.abs(face.normal[a]) >Math.abs(face.normal[b]);
});var v1 =geometry.vertices[face.a];var v2 &#