forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShape.js
63 lines (36 loc) · 1.1 KB
/
Shape.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
import { PathPrototype } from './PathPrototype';
import { Path } from './Path';
/**
* @author zz85 / http://www.lab4games.net/zz85/blog
* Defines a 2d shape plane using paths.
**/
// STEP 1 Create a path.
// STEP 2 Turn path into shape.
// STEP 3 ExtrudeGeometry takes in Shape/Shapes
// STEP 3a - Extract points from each shape, turn to vertices
// STEP 3b - Triangulate each shape, add faces.
function Shape() {
Path.apply( this, arguments );
this.holes = [];
}
Shape.prototype = Object.assign( Object.create( PathPrototype ), {
constructor: Shape,
getPointsHoles: function ( divisions ) {
var holesPts = [];
for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
holesPts[ i ] = this.holes[ i ].getPoints( divisions );
}
return holesPts;
},
// Get points of shape and holes (keypoints based on segments parameter)
extractAllPoints: function ( divisions ) {
return {
shape: this.getPoints( divisions ),
holes: this.getPointsHoles( divisions )
};
},
extractPoints: function ( divisions ) {
return this.extractAllPoints( divisions );
}
} );
export { Shape };