@@ -402,45 +402,54 @@ export class SkeletonClipping {
402402 if ( this . inverse ) {
403403 const polygon = this . clippingPolygons [ 0 ] ;
404404 for ( let i = 0 ; i < trianglesLength ; i += 3 ) {
405- const t0 = triangles [ i ] << 1 , t1 = triangles [ i + 1 ] << 1 , t2 = triangles [ i + 2 ] << 1 ;
406- const x1 = vertices [ vertexStart + t0 ] , y1 = vertices [ vertexStart + t0 + 1 ] ;
407- const x2 = vertices [ vertexStart + t1 ] , y2 = vertices [ vertexStart + t1 + 1 ] ;
408- const x3 = vertices [ vertexStart + t2 ] , y3 = vertices [ vertexStart + t2 + 1 ] ;
405+ let v = triangles [ i ] * stride ;
406+ const x1 = vertices [ vertexStart + v ] , y1 = vertices [ vertexStart + v + 1 ] ;
407+ let uv = triangles [ i ] << 1 ;
408+ const u1 = uvs [ uv ] , v1 = uvs [ uv + 1 ] ;
409+ v = triangles [ i + 1 ] * stride ;
410+ const x2 = vertices [ vertexStart + v ] , y2 = vertices [ vertexStart + v + 1 ] ;
411+ uv = triangles [ i + 1 ] << 1 ;
412+ const u2 = uvs [ uv ] , v2 = uvs [ uv + 1 ] ;
413+ v = triangles [ i + 2 ] * stride ;
414+ const x3 = vertices [ vertexStart + v ] , y3 = vertices [ vertexStart + v + 1 ] ;
415+ uv = triangles [ i + 2 ] << 1 ;
416+ const u3 = uvs [ uv ] , v3 = uvs [ uv + 1 ] ;
409417 this . clipInverse ( x1 , y1 , x2 , y2 , x3 , y3 , polygon ) ;
410418 const nn = this . inverseVertices . length ;
411419 if ( nn === 0 ) continue ;
412420
413- const u1 = uvs [ t0 ] , v1 = uvs [ t0 + 1 ] ;
414- const u2 = uvs [ t1 ] , v2 = uvs [ t1 + 1 ] ;
415- const u3 = uvs [ t2 ] , v3 = uvs [ t2 + 1 ] ;
416421 const d0 = y2 - y3 , d1 = x3 - x2 , d2 = x1 - x3 , d4 = y3 - y1 , d = 1 / ( d0 * d2 + d1 * ( y1 - y3 ) ) ;
417422 const iv = this . inverseVertices ;
418423 for ( let offset = 0 ; offset < nn ; ) {
419424 const polygonSize = iv [ offset ++ ] ;
420425 const vertexCount = polygonSize >> 1 ;
421426
422427 let s = this . clippedVerticesLength ;
423- const newLength = s + polygonSize ;
428+ const newLength = s + vertexCount * stride ;
429+ const newUVLength = this . clippedUVsLength + vertexCount * 2 ;
424430 if ( clippedVertices . length < newLength ) {
425431 this . _clippedVerticesTyped = new Float32Array ( newLength * 2 ) ;
426432 this . _clippedVerticesTyped . set ( clippedVertices . subarray ( 0 , s ) ) ;
427- this . _clippedUVsTyped = new Float32Array ( newLength * 2 ) ;
428- this . _clippedUVsTyped . set ( clippedUVs . subarray ( 0 , this . clippedUVsLength ) ) ;
429433 clippedVertices = this . _clippedVerticesTyped ;
434+ }
435+ if ( clippedUVs . length < newUVLength ) {
436+ this . _clippedUVsTyped = new Float32Array ( newUVLength * 2 ) ;
437+ this . _clippedUVsTyped . set ( clippedUVs . subarray ( 0 , this . clippedUVsLength ) ) ;
430438 clippedUVs = this . _clippedUVsTyped ;
431439 }
432440 this . clippedVerticesLength = newLength ;
433- this . clippedUVsLength = newLength ;
441+ this . clippedUVsLength = newUVLength ;
434442
435443 const cv = this . _clippedVerticesTyped ;
436444 const cu = this . _clippedUVsTyped ;
437- for ( let ii = 0 ; ii < polygonSize ; ii += 2 , s += 2 ) {
445+ let uvIndex = newUVLength - vertexCount * 2 ;
446+ for ( let ii = 0 ; ii < polygonSize ; ii += 2 , s += stride , uvIndex += 2 ) {
438447 const x = iv [ offset + ii ] , y = iv [ offset + ii + 1 ] ;
439448 cv [ s ] = x ;
440449 cv [ s + 1 ] = y ;
441450 const c0 = x - x3 , c1 = y - y3 , a = ( d0 * c0 + d1 * c1 ) * d , b = ( d4 * c0 + d2 * c1 ) * d , c = 1 - a - b ;
442- cu [ s ] = u1 * a + u2 * b + u3 * c ;
443- cu [ s + 1 ] = v1 * a + v2 * b + v3 * c ;
451+ cu [ uvIndex ] = u1 * a + u2 * b + u3 * c ;
452+ cu [ uvIndex + 1 ] = v1 * a + v2 * b + v3 * c ;
444453 }
445454
446455 s = this . clippedTrianglesLength ;
@@ -469,15 +478,21 @@ export class SkeletonClipping {
469478 const polygonsCount = this . clippingPolygons . length ;
470479 let clipOutputItems = null ;
471480 for ( let i = 0 ; i < trianglesLength ; i += 3 ) {
472- let t = triangles [ i ] << 1 ;
473- const x1 = vertices [ vertexStart + t ] , y1 = vertices [ vertexStart + t + 1 ] ;
474- const u1 = uvs [ t ] , v1 = uvs [ t + 1 ] ;
475- t = triangles [ i + 1 ] << 1 ;
476- const x2 = vertices [ vertexStart + t ] , y2 = vertices [ vertexStart + t + 1 ] ;
477- const u2 = uvs [ t ] , v2 = uvs [ t + 1 ] ;
478- t = triangles [ i + 2 ] << 1 ;
479- const x3 = vertices [ vertexStart + t ] , y3 = vertices [ vertexStart + t + 1 ] ;
480- const u3 = uvs [ t ] , v3 = uvs [ t + 1 ] ;
481+ let t = triangles [ i ] ;
482+ let v = t * stride ;
483+ const x1 = vertices [ vertexStart + v ] , y1 = vertices [ vertexStart + v + 1 ] ;
484+ let uv = t << 1 ;
485+ const u1 = uvs [ uv ] , v1 = uvs [ uv + 1 ] ;
486+ t = triangles [ i + 1 ] ;
487+ v = t * stride ;
488+ const x2 = vertices [ vertexStart + v ] , y2 = vertices [ vertexStart + v + 1 ] ;
489+ uv = t << 1 ;
490+ const u2 = uvs [ uv ] , v2 = uvs [ uv + 1 ] ;
491+ t = triangles [ i + 2 ] ;
492+ v = t * stride ;
493+ const x3 = vertices [ vertexStart + v ] , y3 = vertices [ vertexStart + v + 1 ] ;
494+ uv = t << 1 ;
495+ const u3 = uvs [ uv ] , v3 = uvs [ uv + 1 ] ;
481496 const d0 = y2 - y3 , d1 = x3 - x2 , d2 = x1 - x3 , d4 = y3 - y1 , d = 1 / ( d0 * d2 + d1 * ( y1 - y3 ) ) ;
482497
483498 for ( let p = 0 ; p < polygonsCount ; p ++ ) {
0 commit comments