|
@@ -1,27 +1,14 @@
|
|
|
/**
|
|
|
* @author jonobr1 / http://jonobr1.com
|
|
|
*
|
|
|
- * Creates a one-sided polygonal geometry from a path shape. Similar to
|
|
|
+ * Creates a one-sided polygonal geometry from a path shape. Similar to
|
|
|
* ExtrudeGeometry.
|
|
|
*
|
|
|
* parameters = {
|
|
|
*
|
|
|
- * size: <float>, // size of the text
|
|
|
- * height: <float>, // thickness to extrude text
|
|
|
- * curveSegments: <int>, // number of points on the curves
|
|
|
- * steps: <int>, // number of points for z-side extrusions / used for subdividing segements of extrude spline too
|
|
|
- * amount: <int>, // Amount
|
|
|
- *
|
|
|
- * bevelEnabled: <bool>, // turn on bevel
|
|
|
- * bevelThickness: <float>, // how deep into text bevel goes
|
|
|
- * bevelSize: <float>, // how far from text outline is bevel
|
|
|
- * bevelSegments: <int>, // number of bevel layers
|
|
|
- *
|
|
|
- * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
|
|
|
- * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
|
|
|
+ * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
|
|
|
*
|
|
|
* material: <int> // material index for front and back faces
|
|
|
- * extrudeMaterial: <int> // material index for extrusion and beveled faces
|
|
|
* uvGenerator: <Object> // object that provides UV generator functions
|
|
|
*
|
|
|
* }
|
|
@@ -29,99 +16,152 @@
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
- THREE.ShapeGeometry = function( shapes, options ) {
|
|
|
+ THREE.ShapeGeometry = function( _shapes, options ) {
|
|
|
|
|
|
THREE.Geometry.call( this );
|
|
|
|
|
|
- var shapes = shapes instanceof Array ? shapes : [shapes];
|
|
|
+ var shapes = _shapes instanceof Array ? _shapes : [ _shapes ];
|
|
|
|
|
|
this.shapebb = shapes[ shapes.length - 1 ].getBoundingBox();
|
|
|
|
|
|
- this.addShapeList( shapes, options );
|
|
|
+ this.addShapeList( shapes, options );
|
|
|
|
|
|
- this.computeCentroids();
|
|
|
- this.computeFaceNormals();
|
|
|
+ this.computeCentroids();
|
|
|
+ this.computeFaceNormals();
|
|
|
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* Extends THREE.Geometry
|
|
|
*/
|
|
|
- THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
|
|
|
-
|
|
|
- THREE.ShapeGeometry.prototype = {
|
|
|
+ THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
|
|
|
|
|
|
- addShapeList: function( shapes, options ) {
|
|
|
+ /**
|
|
|
+ * Add an array of shapes to THREE.ShapeGeometry.
|
|
|
+ */
|
|
|
+ THREE.ShapeGeometry.prototype.addShapeList = function( shapes, options ) {
|
|
|
|
|
|
- for ( var i = 0, l = shapes.length; i < l; i++ ) {
|
|
|
+ for ( var i = 0, l = shapes.length; i < l; i++ ) {
|
|
|
|
|
|
- var shape = shape[ i ];
|
|
|
- this.addShape( shape, options );
|
|
|
+ var shape = shapes[ i ];
|
|
|
+ this.addShape( shape, options );
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- return this;
|
|
|
+ return this;
|
|
|
|
|
|
- },
|
|
|
+ };
|
|
|
|
|
|
- addShape: function( shape, options ) {
|
|
|
+ /**
|
|
|
+ * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
|
|
|
+ */
|
|
|
+ THREE.ShapeGeometry.prototype.addShape = function( shape, _options ) {
|
|
|
|
|
|
- var curveSegments = isNumber( options.curveSegments ) ? options.curveSegments : 12;
|
|
|
- var steps = isNumber( options.steps ) ? options.steps : 1;
|
|
|
+ var options = isUndefined( _options ) ? {} : _options;
|
|
|
|
|
|
- var material = options.material;
|
|
|
- var uvgen = isUndefined( options.UVGenerator ) ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
|
|
|
+ // TODO: This exists in THREE.ExtrudeGeometry, but not really used.
|
|
|
+ // var curveSegments = isNumber( options.curveSegments ) ? options.curveSegments : 12;
|
|
|
|
|
|
- var shapebb = this.shapebb;
|
|
|
+ var material = options.material;
|
|
|
+ var uvgen = isUndefined( options.UVGenerator ) ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
|
|
|
|
|
|
- // Variable initialization
|
|
|
+ var shapebb = this.shapebb;
|
|
|
|
|
|
- var scope = this;
|
|
|
+ // Variable initialization
|
|
|
|
|
|
- var shapesOffset = this.vertices.length;
|
|
|
- var shapePoints = shape.extractPoints();
|
|
|
+ var scope = this,
|
|
|
+ i, l, hole, s; // Iterable variables
|
|
|
|
|
|
- var vertices = shapePoints.shape;
|
|
|
- var holes = shapePoints.holes;
|
|
|
+ var shapesOffset = this.vertices.length;
|
|
|
+ var shapePoints = shape.extractPoints();
|
|
|
|
|
|
- var reverse = !THREE.ShapeUtils.isClockWise( vertices );
|
|
|
+ var vertices = shapePoints.shape;
|
|
|
+ var holes = shapePoints.holes;
|
|
|
|
|
|
- if ( reverse ) {
|
|
|
+ var reverse = !THREE.Shape.Utils.isClockWise( vertices );
|
|
|
|
|
|
- vertices = vertices.reverse();
|
|
|
+ if ( reverse ) {
|
|
|
|
|
|
- // Maybe we should also check if holes are in the opposite direction, just to be safe...
|
|
|
+ vertices = vertices.reverse();
|
|
|
|
|
|
- for ( var i = 0, l = holes.length; i < l; i++ ) {
|
|
|
+ // Maybe we should also check if holes are in the opposite direction, just to be safe...
|
|
|
|
|
|
- var hole = holes[ i ];
|
|
|
+ for ( i = 0, l = holes.length; i < l; i++ ) {
|
|
|
|
|
|
- if ( THREE.Shape.Utils.isClockWise( hole ) ) {
|
|
|
+ hole = holes[ i ];
|
|
|
|
|
|
- holes[ i ] = hole.reverse();
|
|
|
+ if ( THREE.Shape.Utils.isClockWise( hole ) ) {
|
|
|
|
|
|
- }
|
|
|
+ holes[ i ] = hole.reverse();
|
|
|
|
|
|
}
|
|
|
|
|
|
- reverse = false;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
|
|
|
+ reverse = false;
|
|
|
|
|
|
- // Vertices
|
|
|
+ }
|
|
|
|
|
|
- var contour = vertices;
|
|
|
+ var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
|
|
|
|
|
|
- for ( var i = 0, l = holes.length; i < l; i++ ) {
|
|
|
+ // Vertices
|
|
|
|
|
|
- var hole = holes[ i ];
|
|
|
- vertices = vertices.concat( hole );
|
|
|
+ var contour = vertices;
|
|
|
|
|
|
- }
|
|
|
+ for ( i = 0, l = holes.length; i < l; i++ ) {
|
|
|
+
|
|
|
+ hole = holes[ i ];
|
|
|
+ vertices = vertices.concat( hole );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // Variable initialization round 2
|
|
|
+
|
|
|
+ var vert, vlen = vertices.length,
|
|
|
+ face, flen = faces.length,
|
|
|
+ cont, clen = contour.length;
|
|
|
+
|
|
|
+ /* Vertices */
|
|
|
+
|
|
|
+ // Make sure there is a z-depth, usually not the case
|
|
|
+ // when converting from THREE.Shape
|
|
|
+
|
|
|
+ for ( i = 0; i < vlen; i++ ) {
|
|
|
+
|
|
|
+ vert = vertices[ i ];
|
|
|
+ v( vert.x, vert.y, 0 );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Faces */
|
|
|
+
|
|
|
+ for ( i = 0; i < flen; i++ ) {
|
|
|
+
|
|
|
+ face = faces[ i ];
|
|
|
+ f3( face[ 2 ], face[ 1 ], face[ 0 ] );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Utility functions for addShape method
|
|
|
+ */
|
|
|
+
|
|
|
+ function v( x, y, z ) {
|
|
|
+
|
|
|
+ scope.vertices.push( new THREE.Vector3( x, y, z ) );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ function f3( a, b, c ) {
|
|
|
+
|
|
|
+ a += shapesOffset;
|
|
|
+ b += shapesOffset;
|
|
|
+ c += shapesOffset;
|
|
|
+
|
|
|
+ scope.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
|
|
|
+ var uvs = uvgen.generateBottomUV( scope, shape, options, a, b, c );
|
|
|
|
|
|
-
|
|
|
+ scope.faceVertexUvs[ 0 ].push( uvs );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -132,11 +172,11 @@
|
|
|
*/
|
|
|
|
|
|
function isNumber(o) {
|
|
|
- return toString.call(o) == '[object Number]'
|
|
|
+ return toString.call(o) == '[object Number]';
|
|
|
}
|
|
|
|
|
|
function isUndefined(o) {
|
|
|
- return obj === void 0;
|
|
|
+ return o === void 0;
|
|
|
}
|
|
|
|
|
|
-})();
|
|
|
+})();
|