11import { BufferGeometry , Color , Float32BufferAttribute , Vector2 , Vector3 } from 'three'
2+ import { UV1 } from '../_polyfill/uv1'
23
34/**
45 * Break faces with edges longer than maxEdgeLength
@@ -57,19 +58,19 @@ class TessellateModifier {
5758 const hasNormals = attributes . normal !== undefined
5859 const hasColors = attributes . color !== undefined
5960 const hasUVs = attributes . uv !== undefined
60- const hasUV2s = attributes . uv2 !== undefined
61+ const hasUV1s = attributes [ UV1 ] !== undefined
6162
6263 let positions = attributes . position . array
6364 let normals = hasNormals ? attributes . normal . array : null
6465 let colors = hasColors ? attributes . color . array : null
6566 let uvs = hasUVs ? attributes . uv . array : null
66- let uv2s = hasUV2s ? attributes . uv2 . array : null
67+ let uv1s = hasUV1s ? attributes . uv1 . array : null
6768
6869 let positions2 = ( positions as unknown ) as number [ ]
6970 let normals2 = ( normals as unknown ) as number [ ]
7071 let colors2 = ( colors as unknown ) as number [ ]
7172 let uvs2 = ( uvs as unknown ) as number [ ]
72- let uv2s2 = ( uv2s as unknown ) as number [ ]
73+ let uv1s2 = ( uv1s as unknown ) as number [ ]
7374
7475 let iteration = 0
7576 let tessellating = true
@@ -113,14 +114,14 @@ class TessellateModifier {
113114 uvs2 . push ( u3 . x , u3 . y )
114115 }
115116
116- if ( hasUV2s ) {
117+ if ( hasUV1s ) {
117118 const u21 = u2s [ a ]
118119 const u22 = u2s [ b ]
119120 const u23 = u2s [ c ]
120121
121- uv2s2 . push ( u21 . x , u21 . y )
122- uv2s2 . push ( u22 . x , u22 . y )
123- uv2s2 . push ( u23 . x , u23 . y )
122+ uv1s2 . push ( u21 . x , u21 . y )
123+ uv1s2 . push ( u22 . x , u22 . y )
124+ uv1s2 . push ( u23 . x , u23 . y )
124125 }
125126 }
126127
@@ -146,9 +147,9 @@ class TessellateModifier {
146147 uvs2 = [ ]
147148 }
148149
149- if ( hasUV2s ) {
150- uv2s = uv2s2 as any
151- uv2s2 = [ ]
150+ if ( hasUV1s ) {
151+ uv1s = uv1s2 as any
152+ uv1s2 = [ ]
152153 }
153154
154155 for ( let i = 0 , i2 = 0 , il = positions . length ; i < il ; i += 9 , i2 += 6 ) {
@@ -174,10 +175,10 @@ class TessellateModifier {
174175 uc . fromArray ( uvs , i2 + 4 )
175176 }
176177
177- if ( hasUV2s && uv2s ) {
178- u2a . fromArray ( uv2s , i2 + 0 )
179- u2b . fromArray ( uv2s , i2 + 2 )
180- u2c . fromArray ( uv2s , i2 + 4 )
178+ if ( hasUV1s && uv1s ) {
179+ u2a . fromArray ( uv1s , i2 + 0 )
180+ u2b . fromArray ( uv1s , i2 + 2 )
181+ u2c . fromArray ( uv1s , i2 + 4 )
181182 }
182183
183184 const dab = va . distanceToSquared ( vb )
@@ -192,7 +193,7 @@ class TessellateModifier {
192193 if ( hasNormals ) nm . lerpVectors ( na , nb , 0.5 )
193194 if ( hasColors ) cm . lerpColors ( ca , cb , 0.5 )
194195 if ( hasUVs ) um . lerpVectors ( ua , ub , 0.5 )
195- if ( hasUV2s ) u2m . lerpVectors ( u2a , u2b , 0.5 )
196+ if ( hasUV1s ) u2m . lerpVectors ( u2a , u2b , 0.5 )
196197
197198 addTriangle ( 0 , 3 , 2 )
198199 addTriangle ( 3 , 1 , 2 )
@@ -201,7 +202,7 @@ class TessellateModifier {
201202 if ( hasNormals ) nm . lerpVectors ( nb , nc , 0.5 )
202203 if ( hasColors ) cm . lerpColors ( cb , cc , 0.5 )
203204 if ( hasUVs ) um . lerpVectors ( ub , uc , 0.5 )
204- if ( hasUV2s ) u2m . lerpVectors ( u2b , u2c , 0.5 )
205+ if ( hasUV1s ) u2m . lerpVectors ( u2b , u2c , 0.5 )
205206
206207 addTriangle ( 0 , 1 , 3 )
207208 addTriangle ( 3 , 2 , 0 )
@@ -210,7 +211,7 @@ class TessellateModifier {
210211 if ( hasNormals ) nm . lerpVectors ( na , nc , 0.5 )
211212 if ( hasColors ) cm . lerpColors ( ca , cc , 0.5 )
212213 if ( hasUVs ) um . lerpVectors ( ua , uc , 0.5 )
213- if ( hasUV2s ) u2m . lerpVectors ( u2a , u2c , 0.5 )
214+ if ( hasUV1s ) u2m . lerpVectors ( u2a , u2c , 0.5 )
214215
215216 addTriangle ( 0 , 1 , 3 )
216217 addTriangle ( 3 , 1 , 2 )
@@ -237,8 +238,8 @@ class TessellateModifier {
237238 geometry2 . setAttribute ( 'uv' , new Float32BufferAttribute ( uvs2 as any , 2 ) )
238239 }
239240
240- if ( hasUV2s ) {
241- geometry2 . setAttribute ( 'uv2' , new Float32BufferAttribute ( uv2s2 as any , 2 ) )
241+ if ( hasUV1s ) {
242+ geometry2 . setAttribute ( UV1 , new Float32BufferAttribute ( uv1s2 as any , 2 ) )
242243 }
243244
244245 return geometry2
0 commit comments