I use a function to assign UVs with three.js and it worked great on revision r.103. Unfortunately I can't manage to make it work on r.133
Here's my function :
assignUVs(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 = geometry.vertices[face.b];
var v3 = geometry.vertices[face.c];
geometry.faceVertexUvs[0].push([
new THREE.Vector2(v1[components[0]], v1[components[1]]),
new THREE.Vector2(v2[components[0]], v2[components[1]]),
new THREE.Vector2(v3[components[0]], v3[components[1]])
]);
});
geometry.uvsNeedUpdate = true;
}
I've the following error Cannot set properties of undefined (setting '0') related to this line of code : geometry.faceVertexUvs[0] = []
I tried to convert my Geometry into a BufferGeometry (using BufferGeometryUtils.mergeVertices) but it didn't change a thing. It's like the faceVertexUvs attribute doesn't exist anymore.
Here's a codepen with my code : https://codepen.io/michaelgrc/pen/ExvbMWP
Does anyone know what I'm missing ? Thanks a lot