source: other-projects/playing-in-the-street/summer-2013/trunk/Playing-in-the-Street-WPF/Content/Web/mrdoob-three.js-4862f5f/src/extras/geometries/ShapeGeometry.js@ 28897

Last change on this file since 28897 was 28897, checked in by davidb, 10 years ago

GUI front-end to server base plus web page content

File size: 2.8 KB
Line 
1/**
2 * @author jonobr1 / http://jonobr1.com
3 *
4 * Creates a one-sided polygonal geometry from a path shape. Similar to
5 * ExtrudeGeometry.
6 *
7 * parameters = {
8 *
9 * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
10 *
11 * material: <int> // material index for front and back faces
12 * uvGenerator: <Object> // object that provides UV generator functions
13 *
14 * }
15 **/
16
17THREE.ShapeGeometry = function ( shapes, options ) {
18
19 THREE.Geometry.call( this );
20
21 if ( shapes instanceof Array === false ) shapes = [ shapes ];
22
23 this.shapebb = shapes[ shapes.length - 1 ].getBoundingBox();
24
25 this.addShapeList( shapes, options );
26
27 this.computeCentroids();
28 this.computeFaceNormals();
29
30};
31
32THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
33
34/**
35 * Add an array of shapes to THREE.ShapeGeometry.
36 */
37THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
38
39 for ( var i = 0, l = shapes.length; i < l; i++ ) {
40
41 this.addShape( shapes[ i ], options );
42
43 }
44
45 return this;
46
47};
48
49/**
50 * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
51 */
52THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
53
54 if ( options === undefined ) options = {};
55 var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
56
57 var material = options.material;
58 var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
59
60 var shapebb = this.shapebb;
61
62 //
63
64 var i, l, hole, s;
65
66 var shapesOffset = this.vertices.length;
67 var shapePoints = shape.extractPoints( curveSegments );
68
69 var vertices = shapePoints.shape;
70 var holes = shapePoints.holes;
71
72 var reverse = !THREE.Shape.Utils.isClockWise( vertices );
73
74 if ( reverse ) {
75
76 vertices = vertices.reverse();
77
78 // Maybe we should also check if holes are in the opposite direction, just to be safe...
79
80 for ( i = 0, l = holes.length; i < l; i++ ) {
81
82 hole = holes[ i ];
83
84 if ( THREE.Shape.Utils.isClockWise( hole ) ) {
85
86 holes[ i ] = hole.reverse();
87
88 }
89
90 }
91
92 reverse = false;
93
94 }
95
96 var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
97
98 // Vertices
99
100 var contour = vertices;
101
102 for ( i = 0, l = holes.length; i < l; i++ ) {
103
104 hole = holes[ i ];
105 vertices = vertices.concat( hole );
106
107 }
108
109 //
110
111 var vert, vlen = vertices.length;
112 var face, flen = faces.length;
113 var cont, clen = contour.length;
114
115 for ( i = 0; i < vlen; i++ ) {
116
117 vert = vertices[ i ];
118
119 this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
120
121 }
122
123 for ( i = 0; i < flen; i++ ) {
124
125 face = faces[ i ];
126
127 var a = face[ 0 ] + shapesOffset;
128 var b = face[ 1 ] + shapesOffset;
129 var c = face[ 2 ] + shapesOffset;
130
131 this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
132 this.faceVertexUvs[ 0 ].push( uvgen.generateBottomUV( this, shape, options, a, b, c ) );
133
134 }
135
136};
Note: See TracBrowser for help on using the repository browser.