Reputation: 178
I found the old code, it almost works.
var geom = new THREE.Geometry();
geom.vertices = testRect.verts();
for ( var i = 0; i < verts.length; i+=4 ) {
geom.faceVertexUvs[0].push([
new THREE.Vector2(1.0 - ((verts[i].x - testRect.x) / testRect.width), 1.0 - ((verts[i].z - testRect.y) / testRect.height)),
new THREE.Vector2(1.0 - ((verts[i+1].x - testRect.x) / testRect.width), 1.0 - ((verts[i+1].z - testRect.y) / testRect.height)),
new THREE.Vector2(1.0 - ((verts[i+2].x - testRect.x) / testRect.width), 1.0 - ((verts[i+2].z - testRect.y) / testRect.height)),
new THREE.Vector2(1.0 - ((verts[i+3].x - testRect.x) / testRect.width), 1.0 - ((verts[i+3].z - testRect.y) / testRect.height))
]);
}
for ( var i=0, vl=verts.length; i<vl; i+=4) {
geom.faces.push(new THREE.Face4(i, i+1, i+2, i+3));
}
I found how to fix it (Face4
to Face3
)
THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
return new THREE.Face3( a, b, c, normal, color, materialIndex );
};
But it seems that there are not enough polygons http://dt-byte.ru/fea28697.png
Tried to do so
for ( var i=0, vl=verts.length; i<vl; i+=4) {
geom.faces.push(new THREE.Face4(i, i+1, i+2, i+3));
geom.faces.push(new THREE.Face4(i, i+3, i+2, i+1));
}
But something did not help (
Help solve this problem)
Upvotes: 1
Views: 443
Reputation: 211228
If a geometry is defined by the quad (A, B, C, D), then the same geometry can be draw by the 2 triangles (A, B, C) and (A, C, D).
Adapt the code somehow like this:
for ( var i=0, vl=verts.length; i<vl; i+=4) {
geom.faces.push( new THREE.Face3( i, i+1, i+2 ) );
geom.faces.push( new THREE.Face3( i, i+2, i+3 ) );
}
Upvotes: 3