UNPKG

1.87 kBJavaScriptView Raw
1console.warn( "THREE.ConvexGeometry: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/#manual/en/introduction/Installation." );
2
3// ConvexGeometry
4
5THREE.ConvexGeometry = function ( points ) {
6
7 THREE.Geometry.call( this );
8
9 this.fromBufferGeometry( new THREE.ConvexBufferGeometry( points ) );
10 this.mergeVertices();
11
12};
13
14THREE.ConvexGeometry.prototype = Object.create( THREE.Geometry.prototype );
15THREE.ConvexGeometry.prototype.constructor = THREE.ConvexGeometry;
16
17// ConvexBufferGeometry
18
19THREE.ConvexBufferGeometry = function ( points ) {
20
21 THREE.BufferGeometry.call( this );
22
23 // buffers
24
25 var vertices = [];
26 var normals = [];
27
28 if ( THREE.ConvexHull === undefined ) {
29
30 console.error( 'THREE.ConvexBufferGeometry: ConvexBufferGeometry relies on THREE.ConvexHull' );
31
32 }
33
34 var convexHull = new THREE.ConvexHull().setFromPoints( points );
35
36 // generate vertices and normals
37
38 var faces = convexHull.faces;
39
40 for ( var i = 0; i < faces.length; i ++ ) {
41
42 var face = faces[ i ];
43 var edge = face.edge;
44
45 // we move along a doubly-connected edge list to access all face points (see HalfEdge docs)
46
47 do {
48
49 var point = edge.head().point;
50
51 vertices.push( point.x, point.y, point.z );
52 normals.push( face.normal.x, face.normal.y, face.normal.z );
53
54 edge = edge.next;
55
56 } while ( edge !== face.edge );
57
58 }
59
60 // build geometry
61
62 this.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
63 this.setAttribute( 'normal', new THREE.Float32BufferAttribute( normals, 3 ) );
64
65};
66
67THREE.ConvexBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
68THREE.ConvexBufferGeometry.prototype.constructor = THREE.ConvexBufferGeometry;