-
Notifications
You must be signed in to change notification settings - Fork 14
/
ExtrudePathGeometry.js
126 lines (97 loc) · 3.2 KB
/
ExtrudePathGeometry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* @author Ikaros Kappler
* @date 2013-08-12
* @version 1.0.0
**/
THREE.ExtrudePathGeometry = function( shape,
path,
options
) {
// Call super 'constructor'
THREE.Geometry.call( this );
// Fetch the points from the shape
var shapePoints = shape.extractAllPoints();
shape = shapePoints.shape;
// Iterate through path elements in n steps
var vertexCount = 0;
for( var i = 0; i <= options.curveSegments; i++ ) {
var t = i / options.curveSegments;
// This is a Vector2 (x,y)
var pathPoint = path.getPointAt( t );
// ...
//if( !pathPoint )
// window.alert( "pathPoint#" + i + " (t=" + t+ "): " + JSON.stringify(pathPoint) );
//for( var s = 0; s < shape.length; s++ ) {
var firstShapePointIndex = vertexCount;
for( var s in shape ) {
var shapePoint2 = shapePoints.shape[s];
var shapePoint3 = new THREE.Vector3( shapePoint2.x,
shapePoint2.y,
0 // t*options.size
);
// Translate the point along the path
shapePoint3.add( new THREE.Vector3( pathPoint.x,
pathPoint.y,
t * options.size // pathPoint.z
)
); // addSelf instead of add?!
// Add path point?
// this.vertices.push( new THREE.Vertex(shapePoint3) );
// ... Vertex was replaced by Vector3 (Vertex is DEPRECATED!)
this.vertices.push( new THREE.Vector3( shapePoint3.x,
shapePoint3.y,
shapePoint3.z
)
);
// Connect previous shape/level with current?
if( i > 0 ) {
var soffset = (s==0) ? shape.length-1 : -1;
// Triangulate?
if( !options.triangulate ) {
this.faces.push( new THREE.Face4( vertexCount + soffset,
vertexCount,
vertexCount-shape.length,
vertexCount-shape.length + soffset
) );
} else {
// Triangulation=on
// -> add two Face3 facets instead of Face4!
// (Otherwise the STL export will fail as it only recognizes Face3)
this.faces.push( new THREE.Face3( vertexCount + soffset,
vertexCount,
vertexCount-shape.length
) );
this.faces.push( new THREE.Face3( vertexCount-shape.length,
vertexCount-shape.length + soffset,
vertexCount + soffset
) );
} // END else [triangulate]
}
// Close first and last shape/level (if at least 3 vertices are present: s > 1)
if( s > 1 ) {
if( i == options.curveSegments ) {
// Last segment
this.faces.push( new THREE.Face3( vertexCount,
vertexCount-1,
firstShapePointIndex
)
);
} else if( i == 0 ) {
// First segment
this.faces.push( new THREE.Face3( firstShapePointIndex,
vertexCount-1,
vertexCount
)
);
}
}
vertexCount++;
} // END for [shape points]
}
this.computeCentroids();
this.computeFaceNormals();
// return new THREE.ExtrudeGeometry( shape, options );
};
THREE.ExtrudePathGeometry.prototype = new THREE.Geometry();
THREE.ExtrudePathGeometry.prototype.constructor = THREE.ExtrudePathGeometry;
// window.alert( "THREE.ExtrudePathGeometry=" + THREE.ExtrudePathGeometry );