@@ -9,146 +9,103 @@ class WireframeGeometry extends BufferGeometry {
99 super ( ) ;
1010 this . type = 'WireframeGeometry' ;
1111
12+ if ( geometry . isGeometry === true ) {
13+
14+ console . error ( 'THREE.WireframeGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' ) ;
15+ return ;
16+
17+ }
18+
1219 // buffer
1320
1421 const vertices = [ ] ;
1522
1623 // helper variables
1724
1825 const edge = [ 0 , 0 ] , edges = { } ;
19- const keys = [ 'a' , 'b' , 'c' ] ;
20-
21- // different logic for Geometry and BufferGeometry
22-
23- if ( geometry && geometry . isGeometry ) {
24-
25- // create a data structure that contains all edges without duplicates
26-
27- const faces = geometry . faces ;
28-
29- for ( let i = 0 , l = faces . length ; i < l ; i ++ ) {
30-
31- const face = faces [ i ] ;
32-
33- for ( let j = 0 ; j < 3 ; j ++ ) {
34-
35- const edge1 = face [ keys [ j ] ] ;
36- const edge2 = face [ keys [ ( j + 1 ) % 3 ] ] ;
37- edge [ 0 ] = Math . min ( edge1 , edge2 ) ; // sorting prevents duplicates
38- edge [ 1 ] = Math . max ( edge1 , edge2 ) ;
3926
40- const key = edge [ 0 ] + ',' + edge [ 1 ] ;
27+ const vertex = new Vector3 ( ) ;
4128
42- if ( edges [ key ] === undefined ) {
29+ if ( geometry . index !== null ) {
4330
44- edges [ key ] = { index1 : edge [ 0 ] , index2 : edge [ 1 ] } ;
31+ // indexed BufferGeometry
4532
46- }
47-
48- }
33+ const position = geometry . attributes . position ;
34+ const indices = geometry . index ;
35+ let groups = geometry . groups ;
4936
50- }
37+ if ( groups . length === 0 ) {
5138
52- // generate vertices
53-
54- for ( const key in edges ) {
55-
56- const e = edges [ key ] ;
57-
58- let vertex = geometry . vertices [ e . index1 ] ;
59- vertices . push ( vertex . x , vertex . y , vertex . z ) ;
60-
61- vertex = geometry . vertices [ e . index2 ] ;
62- vertices . push ( vertex . x , vertex . y , vertex . z ) ;
39+ groups = [ { start : 0 , count : indices . count , materialIndex : 0 } ] ;
6340
6441 }
6542
66- } else if ( geometry && geometry . isBufferGeometry ) {
43+ // create a data structure that contains all eges without duplicates
6744
68- const vertex = new Vector3 ( ) ;
45+ for ( let o = 0 , ol = groups . length ; o < ol ; ++ o ) {
6946
70- if ( geometry . index !== null ) {
47+ const group = groups [ o ] ;
7148
72- // indexed BufferGeometry
49+ const start = group . start ;
50+ const count = group . count ;
7351
74- const position = geometry . attributes . position ;
75- const indices = geometry . index ;
76- let groups = geometry . groups ;
52+ for ( let i = start , l = ( start + count ) ; i < l ; i += 3 ) {
7753
78- if ( groups . length === 0 ) {
79-
80- groups = [ { start : 0 , count : indices . count , materialIndex : 0 } ] ;
81-
82- }
83-
84- // create a data structure that contains all eges without duplicates
85-
86- for ( let o = 0 , ol = groups . length ; o < ol ; ++ o ) {
87-
88- const group = groups [ o ] ;
89-
90- const start = group . start ;
91- const count = group . count ;
92-
93- for ( let i = start , l = ( start + count ) ; i < l ; i += 3 ) {
94-
95- for ( let j = 0 ; j < 3 ; j ++ ) {
96-
97- const edge1 = indices . getX ( i + j ) ;
98- const edge2 = indices . getX ( i + ( j + 1 ) % 3 ) ;
99- edge [ 0 ] = Math . min ( edge1 , edge2 ) ; // sorting prevents duplicates
100- edge [ 1 ] = Math . max ( edge1 , edge2 ) ;
54+ for ( let j = 0 ; j < 3 ; j ++ ) {
10155
102- const key = edge [ 0 ] + ',' + edge [ 1 ] ;
56+ const edge1 = indices . getX ( i + j ) ;
57+ const edge2 = indices . getX ( i + ( j + 1 ) % 3 ) ;
58+ edge [ 0 ] = Math . min ( edge1 , edge2 ) ; // sorting prevents duplicates
59+ edge [ 1 ] = Math . max ( edge1 , edge2 ) ;
10360
104- if ( edges [ key ] === undefined ) {
61+ const key = edge [ 0 ] + ',' + edge [ 1 ] ;
10562
106- edges [ key ] = { index1 : edge [ 0 ] , index2 : edge [ 1 ] } ;
63+ if ( edges [ key ] === undefined ) {
10764
108- }
65+ edges [ key ] = { index1 : edge [ 0 ] , index2 : edge [ 1 ] } ;
10966
11067 }
11168
11269 }
11370
11471 }
11572
116- // generate vertices
73+ }
11774
118- for ( const key in edges ) {
75+ // generate vertices
11976
120- const e = edges [ key ] ;
77+ for ( const key in edges ) {
12178
122- vertex . fromBufferAttribute ( position , e . index1 ) ;
123- vertices . push ( vertex . x , vertex . y , vertex . z ) ;
79+ const e = edges [ key ] ;
12480
125- vertex . fromBufferAttribute ( position , e . index2 ) ;
126- vertices . push ( vertex . x , vertex . y , vertex . z ) ;
81+ vertex . fromBufferAttribute ( position , e . index1 ) ;
82+ vertices . push ( vertex . x , vertex . y , vertex . z ) ;
12783
128- }
84+ vertex . fromBufferAttribute ( position , e . index2 ) ;
85+ vertices . push ( vertex . x , vertex . y , vertex . z ) ;
12986
130- } else {
87+ }
13188
132- // non-indexed BufferGeometry
89+ } else {
13390
134- const position = geometry . attributes . position ;
91+ // non-indexed BufferGeometry
13592
136- for ( let i = 0 , l = ( position . count / 3 ) ; i < l ; i ++ ) {
93+ const position = geometry . attributes . position ;
13794
138- for ( let j = 0 ; j < 3 ; j ++ ) {
95+ for ( let i = 0 , l = ( position . count / 3 ) ; i < l ; i ++ ) {
13996
140- // three edges per triangle, an edge is represented as (index1, index2)
141- // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
97+ for ( let j = 0 ; j < 3 ; j ++ ) {
14298
143- const index1 = 3 * i + j ;
144- vertex . fromBufferAttribute ( position , index1 ) ;
145- vertices . push ( vertex . x , vertex . y , vertex . z ) ;
99+ // three edges per triangle, an edge is represented as (index1, index2)
100+ // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
146101
147- const index2 = 3 * i + ( ( j + 1 ) % 3 ) ;
148- vertex . fromBufferAttribute ( position , index2 ) ;
149- vertices . push ( vertex . x , vertex . y , vertex . z ) ;
102+ const index1 = 3 * i + j ;
103+ vertex . fromBufferAttribute ( position , index1 ) ;
104+ vertices . push ( vertex . x , vertex . y , vertex . z ) ;
150105
151- }
106+ const index2 = 3 * i + ( ( j + 1 ) % 3 ) ;
107+ vertex . fromBufferAttribute ( position , index2 ) ;
108+ vertices . push ( vertex . x , vertex . y , vertex . z ) ;
152109
153110 }
154111
0 commit comments