From 5965061ca1c6918bd0e12b5adcd3fb8eb91be531 Mon Sep 17 00:00:00 2001 From: Dean Jackson Date: Wed, 30 Nov 2011 08:31:51 +1100 Subject: [PATCH] Extruded geometry was treating materials as objects rather than indices and UV mapping of extruded geometry was miscalculated. - ExtrudeGeometry was documented to take a Three.Material for the "material" and "extrudeMaterial" parameters, but the examples and usage in TextGeometry showed that these were in fact indices into the materials array. This meant that the tests such as "if (material)" would evaluate to false if the index passed in was 0 (a very typical index to choose :). Simply have the tests check against undefined and update the documentation. - Also, the code that converted a shape into a set of triangles was miscalculating the UV offsets. It was correctly dividing the UV by the bounding box of the old shape, but was forgetting to offset the value from the minimum (which potentially led to negative UVs). --- examples/webgl_extrude_material.html | 217 +++++++++++++++++++++++ src/extras/geometries/ExtrudeGeometry.js | 20 +-- 2 files changed, 227 insertions(+), 10 deletions(-) create mode 100644 examples/webgl_extrude_material.html diff --git a/examples/webgl_extrude_material.html b/examples/webgl_extrude_material.html new file mode 100644 index 00000000..5ba3799c --- /dev/null +++ b/examples/webgl_extrude_material.html @@ -0,0 +1,217 @@ + + + + three.js webgl - geometry - extrusion materials + + + + + + + + + + + + + + + + diff --git a/src/extras/geometries/ExtrudeGeometry.js b/src/extras/geometries/ExtrudeGeometry.js index 419cf667..1fb37c5d 100644 --- a/src/extras/geometries/ExtrudeGeometry.js +++ b/src/extras/geometries/ExtrudeGeometry.js @@ -22,8 +22,8 @@ * extrudePath: // path to extrude shape along * bendPath: // path to bend the geometry around * - * material: // material for front and back faces - * extrudeMaterial: // material for extrusion and beveled faces + * material: // material index for front and back faces + * extrudeMaterial: // material index for extrusion and beveled faces * * } **/ @@ -621,7 +621,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) { f4( a, b, c, d ); - if ( extrudeMaterial ) { + if ( extrudeMaterial !== undefined ) { var v1 = s / sl; var v2 = ( s + 1 ) / sl; @@ -664,21 +664,21 @@ THREE.ExtrudeGeometry.prototype.addShape = function( shape, options ) { scope.faces.push( new THREE.Face3( a, b, c, null, null, material ) ); //normal, color, materials - if ( material ) { + if ( material !== undefined ) { var mx = shapebb.minX, my = shapebb.minY; var uy = shapebb.maxY; // - shapebb.minY; var ux = shapebb.maxX; // - shapebb.minX; - var ax = scope.vertices[ a ].position.x, - ay = scope.vertices[ a ].position.y, + var ax = scope.vertices[ a ].position.x - mx, + ay = scope.vertices[ a ].position.y - my, - bx = scope.vertices[ b ].position.x, - by = scope.vertices[ b ].position.y, + bx = scope.vertices[ b ].position.x - mx, + by = scope.vertices[ b ].position.y - my, - cx = scope.vertices[ c ].position.x, - cy = scope.vertices[ c ].position.y; + cx = scope.vertices[ c ].position.x - mx, + cy = scope.vertices[ c ].position.y - my; scope.faceVertexUvs[ 0 ].push( [