1
1
import {
2
- BufferGeometry ,
3
2
Line3 ,
4
3
Plane ,
5
4
Triangle ,
6
5
Vector3
7
6
} from 'three' ;
7
+
8
8
/**
9
9
* Ported from: https://github.com/maurizzzio/quickhull3d/ by Mauricio Poppe (https://github.com/maurizzzio)
10
10
*/
@@ -42,6 +42,18 @@ var ConvexHull = ( function () {
42
42
43
43
Object . assign ( ConvexHull . prototype , {
44
44
45
+ collectFaces : function ( ) {
46
+ const faceIndices = [ ]
47
+ for ( let i = 0 ; i < this . faces . length ; i += 1 ) {
48
+ if ( this . faces [ i ] . mark !== Visible ) {
49
+ throw Error ( 'attempt to include a destroyed face in the hull' ) ;
50
+ }
51
+ const indices = this . faces [ i ] . collectIndices ( ) ;
52
+ faceIndices . push ( indices ) ;
53
+ }
54
+ return faceIndices ;
55
+ } ,
56
+
45
57
setFromPoints : function ( points ) {
46
58
47
59
if ( Array . isArray ( points ) !== true ) {
@@ -60,7 +72,7 @@ var ConvexHull = ( function () {
60
72
61
73
for ( var i = 0 , l = points . length ; i < l ; i ++ ) {
62
74
63
- this . vertices . push ( new VertexNode ( points [ i ] ) ) ;
75
+ this . vertices . push ( new VertexNode ( points [ i ] , i ) ) ;
64
76
65
77
}
66
78
@@ -70,54 +82,6 @@ var ConvexHull = ( function () {
70
82
71
83
} ,
72
84
73
- setFromObject : function ( object ) {
74
-
75
- var points = [ ] ;
76
-
77
- object . updateMatrixWorld ( true ) ;
78
-
79
- object . traverse ( function ( node ) {
80
-
81
- var i , l , point ;
82
-
83
- var geometry = node . geometry ;
84
-
85
- if ( geometry === undefined ) return ;
86
-
87
- if ( geometry . isGeometry ) {
88
-
89
- geometry = geometry . toBufferGeometry
90
- ? geometry . toBufferGeometry ( )
91
- : new BufferGeometry ( ) . fromGeometry ( geometry ) ;
92
-
93
- }
94
-
95
- if ( geometry . isBufferGeometry ) {
96
-
97
- var attribute = geometry . attributes . position ;
98
-
99
- if ( attribute !== undefined ) {
100
-
101
- for ( i = 0 , l = attribute . count ; i < l ; i ++ ) {
102
-
103
- point = new Vector3 ( ) ;
104
-
105
- point . fromBufferAttribute ( attribute , i ) . applyMatrix4 ( node . matrixWorld ) ;
106
-
107
- points . push ( point ) ;
108
-
109
- }
110
-
111
- }
112
-
113
- }
114
-
115
- } ) ;
116
-
117
- return this . setFromPoints ( points ) ;
118
-
119
- } ,
120
-
121
85
containsPoint : function ( point ) {
122
86
123
87
var faces = this . faces ;
@@ -980,6 +944,17 @@ var ConvexHull = ( function () {
980
944
981
945
Object . assign ( Face . prototype , {
982
946
947
+ collectIndices : function ( ) {
948
+ const indices = [ ] ;
949
+ let edge = this . edge ;
950
+ console . log ( this . edge )
951
+ do {
952
+ indices . push ( edge . head ( ) . index ) ;
953
+ edge = edge . next || null ;
954
+ } while ( edge !== this . edge ) ;
955
+ return indices ;
956
+ } ,
957
+
983
958
getEdge : function ( i ) {
984
959
985
960
var edge = this . edge ;
@@ -1105,12 +1080,15 @@ var ConvexHull = ( function () {
1105
1080
1106
1081
// A vertex as a double linked list node.
1107
1082
1108
- function VertexNode ( point ) {
1083
+ function VertexNode ( point , index ) {
1109
1084
1110
1085
this . point = point ;
1086
+ // index in the input array
1087
+ this . index = index ;
1111
1088
this . prev = null ;
1112
1089
this . next = null ;
1113
- this . face = null ; // the face that is able to see this vertex
1090
+ // the face that is able to see this vertex
1091
+ this . face = null ;
1114
1092
1115
1093
}
1116
1094
0 commit comments