copper3d 3.5.0 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/Scene/copperScene.d.ts +12 -0
  2. package/dist/Scene/copperScene.js +38 -44
  3. package/dist/Scene/copperScene.js.map +1 -1
  4. package/dist/Utils/surfaceAnnotation/MeshGraph.d.ts +40 -0
  5. package/dist/Utils/surfaceAnnotation/MeshGraph.js +198 -0
  6. package/dist/Utils/surfaceAnnotation/MeshGraph.js.map +1 -0
  7. package/dist/Utils/surfaceAnnotation/SurfaceAnnotator.d.ts +103 -0
  8. package/dist/Utils/surfaceAnnotation/SurfaceAnnotator.js +402 -0
  9. package/dist/Utils/surfaceAnnotation/SurfaceAnnotator.js.map +1 -0
  10. package/dist/Utils/surfaceAnnotation/annotationStore.d.ts +37 -0
  11. package/dist/Utils/surfaceAnnotation/annotationStore.js +105 -0
  12. package/dist/Utils/surfaceAnnotation/annotationStore.js.map +1 -0
  13. package/dist/Utils/surfaceAnnotation/contourRender.d.ts +7 -0
  14. package/dist/Utils/surfaceAnnotation/contourRender.js +57 -0
  15. package/dist/Utils/surfaceAnnotation/contourRender.js.map +1 -0
  16. package/dist/Utils/surfaceAnnotation/geodesicContour.d.ts +19 -0
  17. package/dist/Utils/surfaceAnnotation/geodesicContour.js +43 -0
  18. package/dist/Utils/surfaceAnnotation/geodesicContour.js.map +1 -0
  19. package/dist/Utils/surfaceAnnotation/index.d.ts +3 -0
  20. package/dist/Utils/surfaceAnnotation/index.js +2 -0
  21. package/dist/Utils/surfaceAnnotation/index.js.map +1 -0
  22. package/dist/Utils/surfaceAnnotation/pointMarkers.d.ts +7 -0
  23. package/dist/Utils/surfaceAnnotation/pointMarkers.js +16 -0
  24. package/dist/Utils/surfaceAnnotation/pointMarkers.js.map +1 -0
  25. package/dist/Utils/surfaceAnnotation/raycastSurface.d.ts +7 -0
  26. package/dist/Utils/surfaceAnnotation/raycastSurface.js +27 -0
  27. package/dist/Utils/surfaceAnnotation/raycastSurface.js.map +1 -0
  28. package/dist/Utils/surfaceAnnotation/strokeContour.d.ts +19 -0
  29. package/dist/Utils/surfaceAnnotation/strokeContour.js +35 -0
  30. package/dist/Utils/surfaceAnnotation/strokeContour.js.map +1 -0
  31. package/dist/Utils/surfaceAnnotation/types.d.ts +40 -0
  32. package/dist/Utils/surfaceAnnotation/types.js +26 -0
  33. package/dist/Utils/surfaceAnnotation/types.js.map +1 -0
  34. package/dist/bundle.esm.js +2867 -79
  35. package/dist/bundle.umd.js +2867 -78
  36. package/dist/index.d.ts +5 -3
  37. package/dist/index.js +3 -2
  38. package/dist/index.js.map +1 -1
  39. package/dist/types/Scene/copperScene.d.ts +12 -0
  40. package/dist/types/Utils/surfaceAnnotation/MeshGraph.d.ts +40 -0
  41. package/dist/types/Utils/surfaceAnnotation/SurfaceAnnotator.d.ts +103 -0
  42. package/dist/types/Utils/surfaceAnnotation/annotationStore.d.ts +37 -0
  43. package/dist/types/Utils/surfaceAnnotation/contourRender.d.ts +7 -0
  44. package/dist/types/Utils/surfaceAnnotation/geodesicContour.d.ts +19 -0
  45. package/dist/types/Utils/surfaceAnnotation/index.d.ts +3 -0
  46. package/dist/types/Utils/surfaceAnnotation/pointMarkers.d.ts +7 -0
  47. package/dist/types/Utils/surfaceAnnotation/raycastSurface.d.ts +7 -0
  48. package/dist/types/Utils/surfaceAnnotation/strokeContour.d.ts +19 -0
  49. package/dist/types/Utils/surfaceAnnotation/types.d.ts +40 -0
  50. package/dist/types/index.d.ts +5 -3
  51. package/package.json +1 -1
@@ -18015,7 +18015,7 @@ const mat2array = new Float32Array( 4 );
18015
18015
 
18016
18016
  // Flattening for arrays of vectors and matrices
18017
18017
 
18018
- function flatten( array, nBlocks, blockSize ) {
18018
+ function flatten$1( array, nBlocks, blockSize ) {
18019
18019
 
18020
18020
  const firstElem = array[ 0 ];
18021
18021
 
@@ -18643,7 +18643,7 @@ function setValueV1fArray( gl, v ) {
18643
18643
 
18644
18644
  function setValueV2fArray( gl, v ) {
18645
18645
 
18646
- const data = flatten( v, this.size, 2 );
18646
+ const data = flatten$1( v, this.size, 2 );
18647
18647
 
18648
18648
  gl.uniform2fv( this.addr, data );
18649
18649
 
@@ -18651,7 +18651,7 @@ function setValueV2fArray( gl, v ) {
18651
18651
 
18652
18652
  function setValueV3fArray( gl, v ) {
18653
18653
 
18654
- const data = flatten( v, this.size, 3 );
18654
+ const data = flatten$1( v, this.size, 3 );
18655
18655
 
18656
18656
  gl.uniform3fv( this.addr, data );
18657
18657
 
@@ -18659,7 +18659,7 @@ function setValueV3fArray( gl, v ) {
18659
18659
 
18660
18660
  function setValueV4fArray( gl, v ) {
18661
18661
 
18662
- const data = flatten( v, this.size, 4 );
18662
+ const data = flatten$1( v, this.size, 4 );
18663
18663
 
18664
18664
  gl.uniform4fv( this.addr, data );
18665
18665
 
@@ -18669,7 +18669,7 @@ function setValueV4fArray( gl, v ) {
18669
18669
 
18670
18670
  function setValueM2Array( gl, v ) {
18671
18671
 
18672
- const data = flatten( v, this.size, 4 );
18672
+ const data = flatten$1( v, this.size, 4 );
18673
18673
 
18674
18674
  gl.uniformMatrix2fv( this.addr, false, data );
18675
18675
 
@@ -18677,7 +18677,7 @@ function setValueM2Array( gl, v ) {
18677
18677
 
18678
18678
  function setValueM3Array( gl, v ) {
18679
18679
 
18680
- const data = flatten( v, this.size, 9 );
18680
+ const data = flatten$1( v, this.size, 9 );
18681
18681
 
18682
18682
  gl.uniformMatrix3fv( this.addr, false, data );
18683
18683
 
@@ -18685,7 +18685,7 @@ function setValueM3Array( gl, v ) {
18685
18685
 
18686
18686
  function setValueM4Array( gl, v ) {
18687
18687
 
18688
- const data = flatten( v, this.size, 16 );
18688
+ const data = flatten$1( v, this.size, 16 );
18689
18689
 
18690
18690
  gl.uniformMatrix4fv( this.addr, false, data );
18691
18691
 
@@ -33060,7 +33060,7 @@ const _vStart = /*@__PURE__*/ new Vector3();
33060
33060
  const _vEnd = /*@__PURE__*/ new Vector3();
33061
33061
 
33062
33062
  const _inverseMatrix$1 = /*@__PURE__*/ new Matrix4();
33063
- const _ray$1 = /*@__PURE__*/ new Ray();
33063
+ const _ray$1$1 = /*@__PURE__*/ new Ray();
33064
33064
  const _sphere$1 = /*@__PURE__*/ new Sphere();
33065
33065
 
33066
33066
  const _intersectPointOnRay = /*@__PURE__*/ new Vector3();
@@ -33147,7 +33147,7 @@ class Line extends Object3D {
33147
33147
  //
33148
33148
 
33149
33149
  _inverseMatrix$1.copy( matrixWorld ).invert();
33150
- _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
33150
+ _ray$1$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
33151
33151
 
33152
33152
  const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
33153
33153
  const localThresholdSq = localThreshold * localThreshold;
@@ -33168,7 +33168,7 @@ class Line extends Object3D {
33168
33168
  const a = index.getX( i );
33169
33169
  const b = index.getX( i + 1 );
33170
33170
 
33171
- const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, a, b );
33171
+ const intersect = checkIntersection( this, raycaster, _ray$1$1, localThresholdSq, a, b );
33172
33172
 
33173
33173
  if ( intersect ) {
33174
33174
 
@@ -33183,7 +33183,7 @@ class Line extends Object3D {
33183
33183
  const a = index.getX( end - 1 );
33184
33184
  const b = index.getX( start );
33185
33185
 
33186
- const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, a, b );
33186
+ const intersect = checkIntersection( this, raycaster, _ray$1$1, localThresholdSq, a, b );
33187
33187
 
33188
33188
  if ( intersect ) {
33189
33189
 
@@ -33200,7 +33200,7 @@ class Line extends Object3D {
33200
33200
 
33201
33201
  for ( let i = start, l = end - 1; i < l; i += step ) {
33202
33202
 
33203
- const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, i, i + 1 );
33203
+ const intersect = checkIntersection( this, raycaster, _ray$1$1, localThresholdSq, i, i + 1 );
33204
33204
 
33205
33205
  if ( intersect ) {
33206
33206
 
@@ -33212,7 +33212,7 @@ class Line extends Object3D {
33212
33212
 
33213
33213
  if ( this.isLineLoop ) {
33214
33214
 
33215
- const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, end - 1, start );
33215
+ const intersect = checkIntersection( this, raycaster, _ray$1$1, localThresholdSq, end - 1, start );
33216
33216
 
33217
33217
  if ( intersect ) {
33218
33218
 
@@ -33292,8 +33292,8 @@ function checkIntersection( object, raycaster, ray, thresholdSq, a, b ) {
33292
33292
 
33293
33293
  }
33294
33294
 
33295
- const _start = /*@__PURE__*/ new Vector3();
33296
- const _end = /*@__PURE__*/ new Vector3();
33295
+ const _start$1 = /*@__PURE__*/ new Vector3();
33296
+ const _end$1 = /*@__PURE__*/ new Vector3();
33297
33297
 
33298
33298
  class LineSegments extends Line {
33299
33299
 
@@ -33320,11 +33320,11 @@ class LineSegments extends Line {
33320
33320
 
33321
33321
  for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {
33322
33322
 
33323
- _start.fromBufferAttribute( positionAttribute, i );
33324
- _end.fromBufferAttribute( positionAttribute, i + 1 );
33323
+ _start$1.fromBufferAttribute( positionAttribute, i );
33324
+ _end$1.fromBufferAttribute( positionAttribute, i + 1 );
33325
33325
 
33326
33326
  lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
33327
- lineDistances[ i + 1 ] = lineDistances[ i ] + _start.distanceTo( _end );
33327
+ lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 );
33328
33328
 
33329
33329
  }
33330
33330
 
@@ -33408,7 +33408,7 @@ class PointsMaterial extends Material {
33408
33408
 
33409
33409
  const _inverseMatrix = /*@__PURE__*/ new Matrix4();
33410
33410
  const _ray$4 = /*@__PURE__*/ new Ray();
33411
- const _sphere = /*@__PURE__*/ new Sphere();
33411
+ const _sphere$2 = /*@__PURE__*/ new Sphere();
33412
33412
  const _position$2 = /*@__PURE__*/ new Vector3();
33413
33413
 
33414
33414
  class Points extends Object3D {
@@ -33450,11 +33450,11 @@ class Points extends Object3D {
33450
33450
 
33451
33451
  if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
33452
33452
 
33453
- _sphere.copy( geometry.boundingSphere );
33454
- _sphere.applyMatrix4( matrixWorld );
33455
- _sphere.radius += threshold;
33453
+ _sphere$2.copy( geometry.boundingSphere );
33454
+ _sphere$2.applyMatrix4( matrixWorld );
33455
+ _sphere$2.radius += threshold;
33456
33456
 
33457
- if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
33457
+ if ( raycaster.ray.intersectsSphere( _sphere$2 ) === false ) return;
33458
33458
 
33459
33459
  //
33460
33460
 
@@ -33754,6 +33754,279 @@ class RingGeometry extends BufferGeometry {
33754
33754
 
33755
33755
  }
33756
33756
 
33757
+ class SphereGeometry extends BufferGeometry {
33758
+
33759
+ constructor( radius = 1, widthSegments = 32, heightSegments = 16, phiStart = 0, phiLength = Math.PI * 2, thetaStart = 0, thetaLength = Math.PI ) {
33760
+
33761
+ super();
33762
+
33763
+ this.type = 'SphereGeometry';
33764
+
33765
+ this.parameters = {
33766
+ radius: radius,
33767
+ widthSegments: widthSegments,
33768
+ heightSegments: heightSegments,
33769
+ phiStart: phiStart,
33770
+ phiLength: phiLength,
33771
+ thetaStart: thetaStart,
33772
+ thetaLength: thetaLength
33773
+ };
33774
+
33775
+ widthSegments = Math.max( 3, Math.floor( widthSegments ) );
33776
+ heightSegments = Math.max( 2, Math.floor( heightSegments ) );
33777
+
33778
+ const thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
33779
+
33780
+ let index = 0;
33781
+ const grid = [];
33782
+
33783
+ const vertex = new Vector3();
33784
+ const normal = new Vector3();
33785
+
33786
+ // buffers
33787
+
33788
+ const indices = [];
33789
+ const vertices = [];
33790
+ const normals = [];
33791
+ const uvs = [];
33792
+
33793
+ // generate vertices, normals and uvs
33794
+
33795
+ for ( let iy = 0; iy <= heightSegments; iy ++ ) {
33796
+
33797
+ const verticesRow = [];
33798
+
33799
+ const v = iy / heightSegments;
33800
+
33801
+ // special case for the poles
33802
+
33803
+ let uOffset = 0;
33804
+
33805
+ if ( iy === 0 && thetaStart === 0 ) {
33806
+
33807
+ uOffset = 0.5 / widthSegments;
33808
+
33809
+ } else if ( iy === heightSegments && thetaEnd === Math.PI ) {
33810
+
33811
+ uOffset = - 0.5 / widthSegments;
33812
+
33813
+ }
33814
+
33815
+ for ( let ix = 0; ix <= widthSegments; ix ++ ) {
33816
+
33817
+ const u = ix / widthSegments;
33818
+
33819
+ // vertex
33820
+
33821
+ vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
33822
+ vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
33823
+ vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
33824
+
33825
+ vertices.push( vertex.x, vertex.y, vertex.z );
33826
+
33827
+ // normal
33828
+
33829
+ normal.copy( vertex ).normalize();
33830
+ normals.push( normal.x, normal.y, normal.z );
33831
+
33832
+ // uv
33833
+
33834
+ uvs.push( u + uOffset, 1 - v );
33835
+
33836
+ verticesRow.push( index ++ );
33837
+
33838
+ }
33839
+
33840
+ grid.push( verticesRow );
33841
+
33842
+ }
33843
+
33844
+ // indices
33845
+
33846
+ for ( let iy = 0; iy < heightSegments; iy ++ ) {
33847
+
33848
+ for ( let ix = 0; ix < widthSegments; ix ++ ) {
33849
+
33850
+ const a = grid[ iy ][ ix + 1 ];
33851
+ const b = grid[ iy ][ ix ];
33852
+ const c = grid[ iy + 1 ][ ix ];
33853
+ const d = grid[ iy + 1 ][ ix + 1 ];
33854
+
33855
+ if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
33856
+ if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
33857
+
33858
+ }
33859
+
33860
+ }
33861
+
33862
+ // build geometry
33863
+
33864
+ this.setIndex( indices );
33865
+ this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
33866
+ this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
33867
+ this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
33868
+
33869
+ }
33870
+
33871
+ copy( source ) {
33872
+
33873
+ super.copy( source );
33874
+
33875
+ this.parameters = Object.assign( {}, source.parameters );
33876
+
33877
+ return this;
33878
+
33879
+ }
33880
+
33881
+ static fromJSON( data ) {
33882
+
33883
+ return new SphereGeometry( data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength );
33884
+
33885
+ }
33886
+
33887
+ }
33888
+
33889
+ class WireframeGeometry extends BufferGeometry {
33890
+
33891
+ constructor( geometry = null ) {
33892
+
33893
+ super();
33894
+
33895
+ this.type = 'WireframeGeometry';
33896
+
33897
+ this.parameters = {
33898
+ geometry: geometry
33899
+ };
33900
+
33901
+ if ( geometry !== null ) {
33902
+
33903
+ // buffer
33904
+
33905
+ const vertices = [];
33906
+ const edges = new Set();
33907
+
33908
+ // helper variables
33909
+
33910
+ const start = new Vector3();
33911
+ const end = new Vector3();
33912
+
33913
+ if ( geometry.index !== null ) {
33914
+
33915
+ // indexed BufferGeometry
33916
+
33917
+ const position = geometry.attributes.position;
33918
+ const indices = geometry.index;
33919
+ let groups = geometry.groups;
33920
+
33921
+ if ( groups.length === 0 ) {
33922
+
33923
+ groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
33924
+
33925
+ }
33926
+
33927
+ // create a data structure that contains all edges without duplicates
33928
+
33929
+ for ( let o = 0, ol = groups.length; o < ol; ++ o ) {
33930
+
33931
+ const group = groups[ o ];
33932
+
33933
+ const groupStart = group.start;
33934
+ const groupCount = group.count;
33935
+
33936
+ for ( let i = groupStart, l = ( groupStart + groupCount ); i < l; i += 3 ) {
33937
+
33938
+ for ( let j = 0; j < 3; j ++ ) {
33939
+
33940
+ const index1 = indices.getX( i + j );
33941
+ const index2 = indices.getX( i + ( j + 1 ) % 3 );
33942
+
33943
+ start.fromBufferAttribute( position, index1 );
33944
+ end.fromBufferAttribute( position, index2 );
33945
+
33946
+ if ( isUniqueEdge( start, end, edges ) === true ) {
33947
+
33948
+ vertices.push( start.x, start.y, start.z );
33949
+ vertices.push( end.x, end.y, end.z );
33950
+
33951
+ }
33952
+
33953
+ }
33954
+
33955
+ }
33956
+
33957
+ }
33958
+
33959
+ } else {
33960
+
33961
+ // non-indexed BufferGeometry
33962
+
33963
+ const position = geometry.attributes.position;
33964
+
33965
+ for ( let i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
33966
+
33967
+ for ( let j = 0; j < 3; j ++ ) {
33968
+
33969
+ // three edges per triangle, an edge is represented as (index1, index2)
33970
+ // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
33971
+
33972
+ const index1 = 3 * i + j;
33973
+ const index2 = 3 * i + ( ( j + 1 ) % 3 );
33974
+
33975
+ start.fromBufferAttribute( position, index1 );
33976
+ end.fromBufferAttribute( position, index2 );
33977
+
33978
+ if ( isUniqueEdge( start, end, edges ) === true ) {
33979
+
33980
+ vertices.push( start.x, start.y, start.z );
33981
+ vertices.push( end.x, end.y, end.z );
33982
+
33983
+ }
33984
+
33985
+ }
33986
+
33987
+ }
33988
+
33989
+ }
33990
+
33991
+ // build geometry
33992
+
33993
+ this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
33994
+
33995
+ }
33996
+
33997
+ }
33998
+
33999
+ copy( source ) {
34000
+
34001
+ super.copy( source );
34002
+
34003
+ this.parameters = Object.assign( {}, source.parameters );
34004
+
34005
+ return this;
34006
+
34007
+ }
34008
+
34009
+ }
34010
+
34011
+ function isUniqueEdge( start, end, edges ) {
34012
+
34013
+ const hash1 = `${start.x},${start.y},${start.z}-${end.x},${end.y},${end.z}`;
34014
+ const hash2 = `${end.x},${end.y},${end.z}-${start.x},${start.y},${start.z}`; // coincident edge
34015
+
34016
+ if ( edges.has( hash1 ) === true || edges.has( hash2 ) === true ) {
34017
+
34018
+ return false;
34019
+
34020
+ } else {
34021
+
34022
+ edges.add( hash1 );
34023
+ edges.add( hash2 );
34024
+ return true;
34025
+
34026
+ }
34027
+
34028
+ }
34029
+
33757
34030
  class RawShaderMaterial extends ShaderMaterial {
33758
34031
 
33759
34032
  static get type() {
@@ -37262,6 +37535,43 @@ class LoaderUtils {
37262
37535
 
37263
37536
  }
37264
37537
 
37538
+ class InstancedBufferGeometry extends BufferGeometry {
37539
+
37540
+ constructor() {
37541
+
37542
+ super();
37543
+
37544
+ this.isInstancedBufferGeometry = true;
37545
+
37546
+ this.type = 'InstancedBufferGeometry';
37547
+ this.instanceCount = Infinity;
37548
+
37549
+ }
37550
+
37551
+ copy( source ) {
37552
+
37553
+ super.copy( source );
37554
+
37555
+ this.instanceCount = source.instanceCount;
37556
+
37557
+ return this;
37558
+
37559
+ }
37560
+
37561
+ toJSON() {
37562
+
37563
+ const data = super.toJSON();
37564
+
37565
+ data.instanceCount = this.instanceCount;
37566
+
37567
+ data.isInstancedBufferGeometry = true;
37568
+
37569
+ return data;
37570
+
37571
+ }
37572
+
37573
+ }
37574
+
37265
37575
  class ImageBitmapLoader extends Loader {
37266
37576
 
37267
37577
  constructor( manager ) {
@@ -39940,6 +40250,51 @@ class AnimationMixer extends EventDispatcher {
39940
40250
 
39941
40251
  }
39942
40252
 
40253
+ class InstancedInterleavedBuffer extends InterleavedBuffer {
40254
+
40255
+ constructor( array, stride, meshPerAttribute = 1 ) {
40256
+
40257
+ super( array, stride );
40258
+
40259
+ this.isInstancedInterleavedBuffer = true;
40260
+
40261
+ this.meshPerAttribute = meshPerAttribute;
40262
+
40263
+ }
40264
+
40265
+ copy( source ) {
40266
+
40267
+ super.copy( source );
40268
+
40269
+ this.meshPerAttribute = source.meshPerAttribute;
40270
+
40271
+ return this;
40272
+
40273
+ }
40274
+
40275
+ clone( data ) {
40276
+
40277
+ const ib = super.clone( data );
40278
+
40279
+ ib.meshPerAttribute = this.meshPerAttribute;
40280
+
40281
+ return ib;
40282
+
40283
+ }
40284
+
40285
+ toJSON( data ) {
40286
+
40287
+ const json = super.toJSON( data );
40288
+
40289
+ json.isInstancedInterleavedBuffer = true;
40290
+ json.meshPerAttribute = this.meshPerAttribute;
40291
+
40292
+ return json;
40293
+
40294
+ }
40295
+
40296
+ }
40297
+
39943
40298
  const _matrix = /*@__PURE__*/ new Matrix4();
39944
40299
 
39945
40300
  class Raycaster {
@@ -40145,7 +40500,118 @@ class Spherical {
40145
40500
 
40146
40501
  }
40147
40502
 
40148
- const _box = /*@__PURE__*/ new Box3();
40503
+ const _startP = /*@__PURE__*/ new Vector3();
40504
+ const _startEnd = /*@__PURE__*/ new Vector3();
40505
+
40506
+ class Line3 {
40507
+
40508
+ constructor( start = new Vector3(), end = new Vector3() ) {
40509
+
40510
+ this.start = start;
40511
+ this.end = end;
40512
+
40513
+ }
40514
+
40515
+ set( start, end ) {
40516
+
40517
+ this.start.copy( start );
40518
+ this.end.copy( end );
40519
+
40520
+ return this;
40521
+
40522
+ }
40523
+
40524
+ copy( line ) {
40525
+
40526
+ this.start.copy( line.start );
40527
+ this.end.copy( line.end );
40528
+
40529
+ return this;
40530
+
40531
+ }
40532
+
40533
+ getCenter( target ) {
40534
+
40535
+ return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
40536
+
40537
+ }
40538
+
40539
+ delta( target ) {
40540
+
40541
+ return target.subVectors( this.end, this.start );
40542
+
40543
+ }
40544
+
40545
+ distanceSq() {
40546
+
40547
+ return this.start.distanceToSquared( this.end );
40548
+
40549
+ }
40550
+
40551
+ distance() {
40552
+
40553
+ return this.start.distanceTo( this.end );
40554
+
40555
+ }
40556
+
40557
+ at( t, target ) {
40558
+
40559
+ return this.delta( target ).multiplyScalar( t ).add( this.start );
40560
+
40561
+ }
40562
+
40563
+ closestPointToPointParameter( point, clampToLine ) {
40564
+
40565
+ _startP.subVectors( point, this.start );
40566
+ _startEnd.subVectors( this.end, this.start );
40567
+
40568
+ const startEnd2 = _startEnd.dot( _startEnd );
40569
+ const startEnd_startP = _startEnd.dot( _startP );
40570
+
40571
+ let t = startEnd_startP / startEnd2;
40572
+
40573
+ if ( clampToLine ) {
40574
+
40575
+ t = clamp( t, 0, 1 );
40576
+
40577
+ }
40578
+
40579
+ return t;
40580
+
40581
+ }
40582
+
40583
+ closestPointToPoint( point, clampToLine, target ) {
40584
+
40585
+ const t = this.closestPointToPointParameter( point, clampToLine );
40586
+
40587
+ return this.delta( target ).multiplyScalar( t ).add( this.start );
40588
+
40589
+ }
40590
+
40591
+ applyMatrix4( matrix ) {
40592
+
40593
+ this.start.applyMatrix4( matrix );
40594
+ this.end.applyMatrix4( matrix );
40595
+
40596
+ return this;
40597
+
40598
+ }
40599
+
40600
+ equals( line ) {
40601
+
40602
+ return line.start.equals( this.start ) && line.end.equals( this.end );
40603
+
40604
+ }
40605
+
40606
+ clone() {
40607
+
40608
+ return new this.constructor().copy( this );
40609
+
40610
+ }
40611
+
40612
+ }
40613
+
40614
+ const _box$5 = /*@__PURE__*/ new Box3();
40149
40615
 
40150
40616
  class BoxHelper extends LineSegments {
40151
40617
 
@@ -40179,14 +40645,14 @@ class BoxHelper extends LineSegments {
40179
40645
 
40180
40646
  if ( this.object !== undefined ) {
40181
40647
 
40182
- _box.setFromObject( this.object );
40648
+ _box$5.setFromObject( this.object );
40183
40649
 
40184
40650
  }
40185
40651
 
40186
- if ( _box.isEmpty() ) return;
40652
+ if ( _box$5.isEmpty() ) return;
40187
40653
 
40188
- const min = _box.min;
40189
- const max = _box.max;
40654
+ const min = _box$5.min;
40655
+ const max = _box$5.max;
40190
40656
 
40191
40657
  /*
40192
40658
  5____4
@@ -47507,7 +47973,7 @@ class Copper3dTrackballControls extends EventDispatcher {
47507
47973
  const _changeEvent$1 = { type: 'change' };
47508
47974
  const _startEvent$1 = { type: 'start' };
47509
47975
  const _endEvent$1 = { type: 'end' };
47510
- const _ray = new Ray();
47976
+ const _ray$1 = new Ray();
47511
47977
  const _plane = new Plane();
47512
47978
  const _TILT_LIMIT = Math.cos( 70 * MathUtils.DEG2RAD );
47513
47979
 
@@ -47950,19 +48416,19 @@ class OrbitControls extends Controls$1 {
47950
48416
  } else {
47951
48417
 
47952
48418
  // get the ray and translation plane to compute target
47953
- _ray.origin.copy( this.object.position );
47954
- _ray.direction.set( 0, 0, - 1 ).transformDirection( this.object.matrix );
48419
+ _ray$1.origin.copy( this.object.position );
48420
+ _ray$1.direction.set( 0, 0, - 1 ).transformDirection( this.object.matrix );
47955
48421
 
47956
48422
  // if the camera is 20 degrees above the horizon then don't adjust the focus target to avoid
47957
48423
  // extremely large values
47958
- if ( Math.abs( this.object.up.dot( _ray.direction ) ) < _TILT_LIMIT ) {
48424
+ if ( Math.abs( this.object.up.dot( _ray$1.direction ) ) < _TILT_LIMIT ) {
47959
48425
 
47960
48426
  this.object.lookAt( this.target );
47961
48427
 
47962
48428
  } else {
47963
48429
 
47964
48430
  _plane.setFromNormalAndCoplanarPoint( this.object.up, this.target );
47965
- _ray.intersectPlane( _plane, this.target );
48431
+ _ray$1.intersectPlane( _plane, this.target );
47966
48432
 
47967
48433
  }
47968
48434
 
@@ -50323,6 +50789,169 @@ class baseRenderer {
50323
50789
  }
50324
50790
  }
50325
50791
 
50792
+ /**
50793
+ * @param {BufferGeometry} geometry
50794
+ * @param {number} tolerance
50795
+ * @return {BufferGeometry}
50796
+ */
50797
+ function mergeVertices( geometry, tolerance = 1e-4 ) {
50798
+
50799
+ tolerance = Math.max( tolerance, Number.EPSILON );
50800
+
50801
+ // Generate an index buffer if the geometry doesn't have one, or optimize it
50802
+ // if it's already available.
50803
+ const hashToIndex = {};
50804
+ const indices = geometry.getIndex();
50805
+ const positions = geometry.getAttribute( 'position' );
50806
+ const vertexCount = indices ? indices.count : positions.count;
50807
+
50808
+ // next value for triangle indices
50809
+ let nextIndex = 0;
50810
+
50811
+ // attributes and new attribute arrays
50812
+ const attributeNames = Object.keys( geometry.attributes );
50813
+ const tmpAttributes = {};
50814
+ const tmpMorphAttributes = {};
50815
+ const newIndices = [];
50816
+ const getters = [ 'getX', 'getY', 'getZ', 'getW' ];
50817
+ const setters = [ 'setX', 'setY', 'setZ', 'setW' ];
50818
+
50819
+ // Initialize the arrays, allocating space conservatively. Extra
50820
+ // space will be trimmed in the last step.
50821
+ for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {
50822
+
50823
+ const name = attributeNames[ i ];
50824
+ const attr = geometry.attributes[ name ];
50825
+
50826
+ tmpAttributes[ name ] = new attr.constructor(
50827
+ new attr.array.constructor( attr.count * attr.itemSize ),
50828
+ attr.itemSize,
50829
+ attr.normalized
50830
+ );
50831
+
50832
+ const morphAttributes = geometry.morphAttributes[ name ];
50833
+ if ( morphAttributes ) {
50834
+
50835
+ if ( ! tmpMorphAttributes[ name ] ) tmpMorphAttributes[ name ] = [];
50836
+ morphAttributes.forEach( ( morphAttr, i ) => {
50837
+
50838
+ const array = new morphAttr.array.constructor( morphAttr.count * morphAttr.itemSize );
50839
+ tmpMorphAttributes[ name ][ i ] = new morphAttr.constructor( array, morphAttr.itemSize, morphAttr.normalized );
50840
+
50841
+ } );
50842
+
50843
+ }
50844
+
50845
+ }
50846
+
50847
+ // convert the error tolerance to an amount of decimal places to truncate to
50848
+ const halfTolerance = tolerance * 0.5;
50849
+ const exponent = Math.log10( 1 / tolerance );
50850
+ const hashMultiplier = Math.pow( 10, exponent );
50851
+ const hashAdditive = halfTolerance * hashMultiplier;
50852
+ for ( let i = 0; i < vertexCount; i ++ ) {
50853
+
50854
+ const index = indices ? indices.getX( i ) : i;
50855
+
50856
+ // Generate a hash for the vertex attributes at the current index 'i'
50857
+ let hash = '';
50858
+ for ( let j = 0, l = attributeNames.length; j < l; j ++ ) {
50859
+
50860
+ const name = attributeNames[ j ];
50861
+ const attribute = geometry.getAttribute( name );
50862
+ const itemSize = attribute.itemSize;
50863
+
50864
+ for ( let k = 0; k < itemSize; k ++ ) {
50865
+
50866
+ // double tilde truncates the decimal value
50867
+ hash += `${ ~ ~ ( attribute[ getters[ k ] ]( index ) * hashMultiplier + hashAdditive ) },`;
50868
+
50869
+ }
50870
+
50871
+ }
50872
+
50873
+ // Add another reference to the vertex if it's already
50874
+ // used by another index
50875
+ if ( hash in hashToIndex ) {
50876
+
50877
+ newIndices.push( hashToIndex[ hash ] );
50878
+
50879
+ } else {
50880
+
50881
+ // copy data to the new index in the temporary attributes
50882
+ for ( let j = 0, l = attributeNames.length; j < l; j ++ ) {
50883
+
50884
+ const name = attributeNames[ j ];
50885
+ const attribute = geometry.getAttribute( name );
50886
+ const morphAttributes = geometry.morphAttributes[ name ];
50887
+ const itemSize = attribute.itemSize;
50888
+ const newArray = tmpAttributes[ name ];
50889
+ const newMorphArrays = tmpMorphAttributes[ name ];
50890
+
50891
+ for ( let k = 0; k < itemSize; k ++ ) {
50892
+
50893
+ const getterFunc = getters[ k ];
50894
+ const setterFunc = setters[ k ];
50895
+ newArray[ setterFunc ]( nextIndex, attribute[ getterFunc ]( index ) );
50896
+
50897
+ if ( morphAttributes ) {
50898
+
50899
+ for ( let m = 0, ml = morphAttributes.length; m < ml; m ++ ) {
50900
+
50901
+ newMorphArrays[ m ][ setterFunc ]( nextIndex, morphAttributes[ m ][ getterFunc ]( index ) );
50902
+
50903
+ }
50904
+
50905
+ }
50906
+
50907
+ }
50908
+
50909
+ }
50910
+
50911
+ hashToIndex[ hash ] = nextIndex;
50912
+ newIndices.push( nextIndex );
50913
+ nextIndex ++;
50914
+
50915
+ }
50916
+
50917
+ }
50918
+
50919
+ // generate result BufferGeometry
50920
+ const result = geometry.clone();
50921
+ for ( const name in geometry.attributes ) {
50922
+
50923
+ const tmpAttribute = tmpAttributes[ name ];
50924
+
50925
+ result.setAttribute( name, new tmpAttribute.constructor(
50926
+ tmpAttribute.array.slice( 0, nextIndex * tmpAttribute.itemSize ),
50927
+ tmpAttribute.itemSize,
50928
+ tmpAttribute.normalized,
50929
+ ) );
50930
+
50931
+ if ( ! ( name in tmpMorphAttributes ) ) continue;
50932
+
50933
+ for ( let j = 0; j < tmpMorphAttributes[ name ].length; j ++ ) {
50934
+
50935
+ const tmpMorphAttribute = tmpMorphAttributes[ name ][ j ];
50936
+
50937
+ result.morphAttributes[ name ][ j ] = new tmpMorphAttribute.constructor(
50938
+ tmpMorphAttribute.array.slice( 0, nextIndex * tmpMorphAttribute.itemSize ),
50939
+ tmpMorphAttribute.itemSize,
50940
+ tmpMorphAttribute.normalized,
50941
+ );
50942
+
50943
+ }
50944
+
50945
+ }
50946
+
50947
+ // indices
50948
+
50949
+ result.setIndex( newIndices );
50950
+
50951
+ return result;
50952
+
50953
+ }
50954
+
50326
50955
  /**
50327
50956
  * @param {BufferGeometry} geometry
50328
50957
  * @param {number} drawMode
@@ -58881,6 +59510,2172 @@ function onTouchEnd( event ) {
58881
59510
 
58882
59511
  }
58883
59512
 
59513
+ const _inv = new Matrix4();
59514
+ /** 世界系命中点 → local 顶点(位置 worldToLocal,法线用逆变换)。 */
59515
+ function worldHitToLocalVertex(h, mesh) {
59516
+ const lp = mesh.worldToLocal(h.point.clone());
59517
+ _inv.copy(mesh.matrixWorld).invert();
59518
+ const ln = h.normal.clone().transformDirection(_inv).normalize();
59519
+ return {
59520
+ x: lp.x,
59521
+ y: lp.y,
59522
+ z: lp.z,
59523
+ nx: ln.x,
59524
+ ny: ln.y,
59525
+ nz: ln.z,
59526
+ faceIndex: h.faceIndex,
59527
+ };
59528
+ }
59529
+ const _nm = new Matrix3();
59530
+ /** local 顶点 → world 位置 + world 法线(供渲染)。 */
59531
+ function localVertexToWorld(v, mesh) {
59532
+ const p = new Vector3(v.x, v.y, v.z).applyMatrix4(mesh.matrixWorld);
59533
+ _nm.getNormalMatrix(mesh.matrixWorld);
59534
+ const n = new Vector3(v.nx, v.ny, v.nz).applyMatrix3(_nm).normalize();
59535
+ return { p, n };
59536
+ }
59537
+
59538
+ const ray = new Raycaster();
59539
+ const ndc = new Vector2();
59540
+ /**
59541
+ * 把屏幕坐标(clientX/Y)投射到 mesh 表面,返回命中点、world-space 法线与 faceIndex。
59542
+ * 未命中返回 null。本地实现,不依赖 Copper3D 未导出的 raycast 内部函数。
59543
+ */
59544
+ function raycastSurface(camera, container, mesh, clientX, clientY) {
59545
+ var _a;
59546
+ const rect = container.getBoundingClientRect();
59547
+ ndc.x = ((clientX - rect.left) / rect.width) * 2 - 1;
59548
+ ndc.y = -((clientY - rect.top) / rect.height) * 2 + 1;
59549
+ ray.setFromCamera(ndc, camera);
59550
+ const hits = ray.intersectObject(mesh, false);
59551
+ if (hits.length === 0)
59552
+ return null;
59553
+ const h = hits[0];
59554
+ const point = h.point.clone();
59555
+ const normal = new Vector3(0, 0, 1);
59556
+ if (h.face) {
59557
+ normal.copy(h.face.normal);
59558
+ const nm = new Matrix3().getNormalMatrix(mesh.matrixWorld);
59559
+ normal.applyMatrix3(nm).normalize();
59560
+ }
59561
+ return { point, normal, faceIndex: (_a = h.faceIndex) !== null && _a !== void 0 ? _a : -1 };
59562
+ }
59563
+
59564
+ /**
59565
+ * 在 local 顶点处生成一个标记小球(fiducial)。local→world 后沿 world 法线略外移,
59566
+ * 避免一半埋进表面。radius 由调用方按模型 bbox 缩放传入。
59567
+ */
59568
+ function makePointMarker(v, mesh, color, radius) {
59569
+ const geo = new SphereGeometry(radius, 16, 16);
59570
+ const mat = new MeshBasicMaterial({ color });
59571
+ const m = new Mesh(geo, mat);
59572
+ const { p, n } = localVertexToWorld(v, mesh);
59573
+ m.position.copy(p.addScaledVector(n, radius * 0.5));
59574
+ m.renderOrder = 999;
59575
+ return m;
59576
+ }
59577
+
59578
+ /**
59579
+ * 模式 A(自由手绘)一笔的状态机。
59580
+ * pointermove 时不断 addSample;与上一采样点世界距离 < minGap 的样本丢弃,避免过密。
59581
+ * 顶点以 local 存(由 mesh 把世界命中点转 local)。
59582
+ */
59583
+ class StrokeContour {
59584
+ constructor(minGap, mesh) {
59585
+ this.minGap = minGap;
59586
+ this.mesh = mesh;
59587
+ this.verts = [];
59588
+ this.last = new Vector3();
59589
+ this.has = false;
59590
+ }
59591
+ begin() {
59592
+ this.verts = [];
59593
+ this.has = false;
59594
+ }
59595
+ addSample(hit) {
59596
+ // gap 判定用世界距离(屏幕笔触在世界系采样)
59597
+ if (this.has && hit.point.distanceTo(this.last) < this.minGap)
59598
+ return;
59599
+ this.verts.push(worldHitToLocalVertex(hit, this.mesh));
59600
+ this.last.copy(hit.point);
59601
+ this.has = true;
59602
+ }
59603
+ get vertices() {
59604
+ return this.verts;
59605
+ }
59606
+ end() {
59607
+ return this.verts;
59608
+ }
59609
+ }
59610
+
59611
+ const _box$1 = new Box3();
59612
+ const _vector = new Vector3();
59613
+
59614
+ class LineSegmentsGeometry extends InstancedBufferGeometry {
59615
+
59616
+ constructor() {
59617
+
59618
+ super();
59619
+
59620
+ this.isLineSegmentsGeometry = true;
59621
+
59622
+ this.type = 'LineSegmentsGeometry';
59623
+
59624
+ const positions = [ - 1, 2, 0, 1, 2, 0, - 1, 1, 0, 1, 1, 0, - 1, 0, 0, 1, 0, 0, - 1, - 1, 0, 1, - 1, 0 ];
59625
+ const uvs = [ - 1, 2, 1, 2, - 1, 1, 1, 1, - 1, - 1, 1, - 1, - 1, - 2, 1, - 2 ];
59626
+ const index = [ 0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3, 4, 6, 5, 6, 7, 5 ];
59627
+
59628
+ this.setIndex( index );
59629
+ this.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
59630
+ this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
59631
+
59632
+ }
59633
+
59634
+ applyMatrix4( matrix ) {
59635
+
59636
+ const start = this.attributes.instanceStart;
59637
+ const end = this.attributes.instanceEnd;
59638
+
59639
+ if ( start !== undefined ) {
59640
+
59641
+ start.applyMatrix4( matrix );
59642
+
59643
+ end.applyMatrix4( matrix );
59644
+
59645
+ start.needsUpdate = true;
59646
+
59647
+ }
59648
+
59649
+ if ( this.boundingBox !== null ) {
59650
+
59651
+ this.computeBoundingBox();
59652
+
59653
+ }
59654
+
59655
+ if ( this.boundingSphere !== null ) {
59656
+
59657
+ this.computeBoundingSphere();
59658
+
59659
+ }
59660
+
59661
+ return this;
59662
+
59663
+ }
59664
+
59665
+ setPositions( array ) {
59666
+
59667
+ let lineSegments;
59668
+
59669
+ if ( array instanceof Float32Array ) {
59670
+
59671
+ lineSegments = array;
59672
+
59673
+ } else if ( Array.isArray( array ) ) {
59674
+
59675
+ lineSegments = new Float32Array( array );
59676
+
59677
+ }
59678
+
59679
+ const instanceBuffer = new InstancedInterleavedBuffer( lineSegments, 6, 1 ); // xyz, xyz
59680
+
59681
+ this.setAttribute( 'instanceStart', new InterleavedBufferAttribute( instanceBuffer, 3, 0 ) ); // xyz
59682
+ this.setAttribute( 'instanceEnd', new InterleavedBufferAttribute( instanceBuffer, 3, 3 ) ); // xyz
59683
+
59684
+ this.instanceCount = this.attributes.instanceStart.count;
59685
+
59686
+ //
59687
+
59688
+ this.computeBoundingBox();
59689
+ this.computeBoundingSphere();
59690
+
59691
+ return this;
59692
+
59693
+ }
59694
+
59695
+ setColors( array ) {
59696
+
59697
+ let colors;
59698
+
59699
+ if ( array instanceof Float32Array ) {
59700
+
59701
+ colors = array;
59702
+
59703
+ } else if ( Array.isArray( array ) ) {
59704
+
59705
+ colors = new Float32Array( array );
59706
+
59707
+ }
59708
+
59709
+ const instanceColorBuffer = new InstancedInterleavedBuffer( colors, 6, 1 ); // rgb, rgb
59710
+
59711
+ this.setAttribute( 'instanceColorStart', new InterleavedBufferAttribute( instanceColorBuffer, 3, 0 ) ); // rgb
59712
+ this.setAttribute( 'instanceColorEnd', new InterleavedBufferAttribute( instanceColorBuffer, 3, 3 ) ); // rgb
59713
+
59714
+ return this;
59715
+
59716
+ }
59717
+
59718
+ fromWireframeGeometry( geometry ) {
59719
+
59720
+ this.setPositions( geometry.attributes.position.array );
59721
+
59722
+ return this;
59723
+
59724
+ }
59725
+
59726
+ fromEdgesGeometry( geometry ) {
59727
+
59728
+ this.setPositions( geometry.attributes.position.array );
59729
+
59730
+ return this;
59731
+
59732
+ }
59733
+
59734
+ fromMesh( mesh ) {
59735
+
59736
+ this.fromWireframeGeometry( new WireframeGeometry( mesh.geometry ) );
59737
+
59738
+ // set colors, maybe
59739
+
59740
+ return this;
59741
+
59742
+ }
59743
+
59744
+ fromLineSegments( lineSegments ) {
59745
+
59746
+ const geometry = lineSegments.geometry;
59747
+
59748
+ this.setPositions( geometry.attributes.position.array ); // assumes non-indexed
59749
+
59750
+ // set colors, maybe
59751
+
59752
+ return this;
59753
+
59754
+ }
59755
+
59756
+ computeBoundingBox() {
59757
+
59758
+ if ( this.boundingBox === null ) {
59759
+
59760
+ this.boundingBox = new Box3();
59761
+
59762
+ }
59763
+
59764
+ const start = this.attributes.instanceStart;
59765
+ const end = this.attributes.instanceEnd;
59766
+
59767
+ if ( start !== undefined && end !== undefined ) {
59768
+
59769
+ this.boundingBox.setFromBufferAttribute( start );
59770
+
59771
+ _box$1.setFromBufferAttribute( end );
59772
+
59773
+ this.boundingBox.union( _box$1 );
59774
+
59775
+ }
59776
+
59777
+ }
59778
+
59779
+ computeBoundingSphere() {
59780
+
59781
+ if ( this.boundingSphere === null ) {
59782
+
59783
+ this.boundingSphere = new Sphere();
59784
+
59785
+ }
59786
+
59787
+ if ( this.boundingBox === null ) {
59788
+
59789
+ this.computeBoundingBox();
59790
+
59791
+ }
59792
+
59793
+ const start = this.attributes.instanceStart;
59794
+ const end = this.attributes.instanceEnd;
59795
+
59796
+ if ( start !== undefined && end !== undefined ) {
59797
+
59798
+ const center = this.boundingSphere.center;
59799
+
59800
+ this.boundingBox.getCenter( center );
59801
+
59802
+ let maxRadiusSq = 0;
59803
+
59804
+ for ( let i = 0, il = start.count; i < il; i ++ ) {
59805
+
59806
+ _vector.fromBufferAttribute( start, i );
59807
+ maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector ) );
59808
+
59809
+ _vector.fromBufferAttribute( end, i );
59810
+ maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector ) );
59811
+
59812
+ }
59813
+
59814
+ this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
59815
+
59816
+ if ( isNaN( this.boundingSphere.radius ) ) {
59817
+
59818
+ console.error( 'THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.', this );
59819
+
59820
+ }
59821
+
59822
+ }
59823
+
59824
+ }
59825
+
59826
+ toJSON() {
59827
+
59828
+ // todo
59829
+
59830
+ }
59831
+
59832
+ applyMatrix( matrix ) {
59833
+
59834
+ console.warn( 'THREE.LineSegmentsGeometry: applyMatrix() has been renamed to applyMatrix4().' );
59835
+
59836
+ return this.applyMatrix4( matrix );
59837
+
59838
+ }
59839
+
59840
+ }
59841
+
59842
+ UniformsLib.line = {
59843
+
59844
+ worldUnits: { value: 1 },
59845
+ linewidth: { value: 1 },
59846
+ resolution: { value: new Vector2( 1, 1 ) },
59847
+ dashOffset: { value: 0 },
59848
+ dashScale: { value: 1 },
59849
+ dashSize: { value: 1 },
59850
+ gapSize: { value: 1 } // todo FIX - maybe change to totalSize
59851
+
59852
+ };
59853
+
59854
+ ShaderLib[ 'line' ] = {
59855
+
59856
+ uniforms: UniformsUtils.merge( [
59857
+ UniformsLib.common,
59858
+ UniformsLib.fog,
59859
+ UniformsLib.line
59860
+ ] ),
59861
+
59862
+ vertexShader:
59863
+ /* glsl */`
59864
+ #include <common>
59865
+ #include <color_pars_vertex>
59866
+ #include <fog_pars_vertex>
59867
+ #include <logdepthbuf_pars_vertex>
59868
+ #include <clipping_planes_pars_vertex>
59869
+
59870
+ uniform float linewidth;
59871
+ uniform vec2 resolution;
59872
+
59873
+ attribute vec3 instanceStart;
59874
+ attribute vec3 instanceEnd;
59875
+
59876
+ attribute vec3 instanceColorStart;
59877
+ attribute vec3 instanceColorEnd;
59878
+
59879
+ #ifdef WORLD_UNITS
59880
+
59881
+ varying vec4 worldPos;
59882
+ varying vec3 worldStart;
59883
+ varying vec3 worldEnd;
59884
+
59885
+ #ifdef USE_DASH
59886
+
59887
+ varying vec2 vUv;
59888
+
59889
+ #endif
59890
+
59891
+ #else
59892
+
59893
+ varying vec2 vUv;
59894
+
59895
+ #endif
59896
+
59897
+ #ifdef USE_DASH
59898
+
59899
+ uniform float dashScale;
59900
+ attribute float instanceDistanceStart;
59901
+ attribute float instanceDistanceEnd;
59902
+ varying float vLineDistance;
59903
+
59904
+ #endif
59905
+
59906
+ void trimSegment( const in vec4 start, inout vec4 end ) {
59907
+
59908
+ // trim end segment so it terminates between the camera plane and the near plane
59909
+
59910
+ // conservative estimate of the near plane
59911
+ float a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column
59912
+ float b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column
59913
+ float nearEstimate = - 0.5 * b / a;
59914
+
59915
+ float alpha = ( nearEstimate - start.z ) / ( end.z - start.z );
59916
+
59917
+ end.xyz = mix( start.xyz, end.xyz, alpha );
59918
+
59919
+ }
59920
+
59921
+ void main() {
59922
+
59923
+ #ifdef USE_COLOR
59924
+
59925
+ vColor.xyz = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;
59926
+
59927
+ #endif
59928
+
59929
+ #ifdef USE_DASH
59930
+
59931
+ vLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd;
59932
+ vUv = uv;
59933
+
59934
+ #endif
59935
+
59936
+ float aspect = resolution.x / resolution.y;
59937
+
59938
+ // camera space
59939
+ vec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );
59940
+ vec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 );
59941
+
59942
+ #ifdef WORLD_UNITS
59943
+
59944
+ worldStart = start.xyz;
59945
+ worldEnd = end.xyz;
59946
+
59947
+ #else
59948
+
59949
+ vUv = uv;
59950
+
59951
+ #endif
59952
+
59953
+ // special case for perspective projection, and segments that terminate either in, or behind, the camera plane
59954
+ // clearly the gpu firmware has a way of addressing this issue when projecting into ndc space
59955
+ // but we need to perform ndc-space calculations in the shader, so we must address this issue directly
59956
+ // perhaps there is a more elegant solution -- WestLangley
59957
+
59958
+ bool perspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 ); // 4th entry in the 3rd column
59959
+
59960
+ if ( perspective ) {
59961
+
59962
+ if ( start.z < 0.0 && end.z >= 0.0 ) {
59963
+
59964
+ trimSegment( start, end );
59965
+
59966
+ } else if ( end.z < 0.0 && start.z >= 0.0 ) {
59967
+
59968
+ trimSegment( end, start );
59969
+
59970
+ }
59971
+
59972
+ }
59973
+
59974
+ // clip space
59975
+ vec4 clipStart = projectionMatrix * start;
59976
+ vec4 clipEnd = projectionMatrix * end;
59977
+
59978
+ // ndc space
59979
+ vec3 ndcStart = clipStart.xyz / clipStart.w;
59980
+ vec3 ndcEnd = clipEnd.xyz / clipEnd.w;
59981
+
59982
+ // direction
59983
+ vec2 dir = ndcEnd.xy - ndcStart.xy;
59984
+
59985
+ // account for clip-space aspect ratio
59986
+ dir.x *= aspect;
59987
+ dir = normalize( dir );
59988
+
59989
+ #ifdef WORLD_UNITS
59990
+
59991
+ vec3 worldDir = normalize( end.xyz - start.xyz );
59992
+ vec3 tmpFwd = normalize( mix( start.xyz, end.xyz, 0.5 ) );
59993
+ vec3 worldUp = normalize( cross( worldDir, tmpFwd ) );
59994
+ vec3 worldFwd = cross( worldDir, worldUp );
59995
+ worldPos = position.y < 0.5 ? start: end;
59996
+
59997
+ // height offset
59998
+ float hw = linewidth * 0.5;
59999
+ worldPos.xyz += position.x < 0.0 ? hw * worldUp : - hw * worldUp;
60000
+
60001
+ // don't extend the line if we're rendering dashes because we
60002
+ // won't be rendering the endcaps
60003
+ #ifndef USE_DASH
60004
+
60005
+ // cap extension
60006
+ worldPos.xyz += position.y < 0.5 ? - hw * worldDir : hw * worldDir;
60007
+
60008
+ // add width to the box
60009
+ worldPos.xyz += worldFwd * hw;
60010
+
60011
+ // endcaps
60012
+ if ( position.y > 1.0 || position.y < 0.0 ) {
60013
+
60014
+ worldPos.xyz -= worldFwd * 2.0 * hw;
60015
+
60016
+ }
60017
+
60018
+ #endif
60019
+
60020
+ // project the worldpos
60021
+ vec4 clip = projectionMatrix * worldPos;
60022
+
60023
+ // shift the depth of the projected points so the line
60024
+ // segments overlap neatly
60025
+ vec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd;
60026
+ clip.z = clipPose.z * clip.w;
60027
+
60028
+ #else
60029
+
60030
+ vec2 offset = vec2( dir.y, - dir.x );
60031
+ // undo aspect ratio adjustment
60032
+ dir.x /= aspect;
60033
+ offset.x /= aspect;
60034
+
60035
+ // sign flip
60036
+ if ( position.x < 0.0 ) offset *= - 1.0;
60037
+
60038
+ // endcaps
60039
+ if ( position.y < 0.0 ) {
60040
+
60041
+ offset += - dir;
60042
+
60043
+ } else if ( position.y > 1.0 ) {
60044
+
60045
+ offset += dir;
60046
+
60047
+ }
60048
+
60049
+ // adjust for linewidth
60050
+ offset *= linewidth;
60051
+
60052
+ // adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...
60053
+ offset /= resolution.y;
60054
+
60055
+ // select end
60056
+ vec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd;
60057
+
60058
+ // back to clip space
60059
+ offset *= clip.w;
60060
+
60061
+ clip.xy += offset;
60062
+
60063
+ #endif
60064
+
60065
+ gl_Position = clip;
60066
+
60067
+ vec4 mvPosition = ( position.y < 0.5 ) ? start : end; // this is an approximation
60068
+
60069
+ #include <logdepthbuf_vertex>
60070
+ #include <clipping_planes_vertex>
60071
+ #include <fog_vertex>
60072
+
60073
+ }
60074
+ `,
60075
+
60076
+ fragmentShader:
60077
+ /* glsl */`
60078
+ uniform vec3 diffuse;
60079
+ uniform float opacity;
60080
+ uniform float linewidth;
60081
+
60082
+ #ifdef USE_DASH
60083
+
60084
+ uniform float dashOffset;
60085
+ uniform float dashSize;
60086
+ uniform float gapSize;
60087
+
60088
+ #endif
60089
+
60090
+ varying float vLineDistance;
60091
+
60092
+ #ifdef WORLD_UNITS
60093
+
60094
+ varying vec4 worldPos;
60095
+ varying vec3 worldStart;
60096
+ varying vec3 worldEnd;
60097
+
60098
+ #ifdef USE_DASH
60099
+
60100
+ varying vec2 vUv;
60101
+
60102
+ #endif
60103
+
60104
+ #else
60105
+
60106
+ varying vec2 vUv;
60107
+
60108
+ #endif
60109
+
60110
+ #include <common>
60111
+ #include <color_pars_fragment>
60112
+ #include <fog_pars_fragment>
60113
+ #include <logdepthbuf_pars_fragment>
60114
+ #include <clipping_planes_pars_fragment>
60115
+
60116
+ vec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {
60117
+
60118
+ float mua;
60119
+ float mub;
60120
+
60121
+ vec3 p13 = p1 - p3;
60122
+ vec3 p43 = p4 - p3;
60123
+
60124
+ vec3 p21 = p2 - p1;
60125
+
60126
+ float d1343 = dot( p13, p43 );
60127
+ float d4321 = dot( p43, p21 );
60128
+ float d1321 = dot( p13, p21 );
60129
+ float d4343 = dot( p43, p43 );
60130
+ float d2121 = dot( p21, p21 );
60131
+
60132
+ float denom = d2121 * d4343 - d4321 * d4321;
60133
+
60134
+ float numer = d1343 * d4321 - d1321 * d4343;
60135
+
60136
+ mua = numer / denom;
60137
+ mua = clamp( mua, 0.0, 1.0 );
60138
+ mub = ( d1343 + d4321 * ( mua ) ) / d4343;
60139
+ mub = clamp( mub, 0.0, 1.0 );
60140
+
60141
+ return vec2( mua, mub );
60142
+
60143
+ }
60144
+
60145
+ void main() {
60146
+
60147
+ #include <clipping_planes_fragment>
60148
+
60149
+ #ifdef USE_DASH
60150
+
60151
+ if ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps
60152
+
60153
+ if ( mod( vLineDistance + dashOffset, dashSize + gapSize ) > dashSize ) discard; // todo - FIX
60154
+
60155
+ #endif
60156
+
60157
+ float alpha = opacity;
60158
+
60159
+ #ifdef WORLD_UNITS
60160
+
60161
+ // Find the closest points on the view ray and the line segment
60162
+ vec3 rayEnd = normalize( worldPos.xyz ) * 1e5;
60163
+ vec3 lineDir = worldEnd - worldStart;
60164
+ vec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd );
60165
+
60166
+ vec3 p1 = worldStart + lineDir * params.x;
60167
+ vec3 p2 = rayEnd * params.y;
60168
+ vec3 delta = p1 - p2;
60169
+ float len = length( delta );
60170
+ float norm = len / linewidth;
60171
+
60172
+ #ifndef USE_DASH
60173
+
60174
+ #ifdef USE_ALPHA_TO_COVERAGE
60175
+
60176
+ float dnorm = fwidth( norm );
60177
+ alpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm );
60178
+
60179
+ #else
60180
+
60181
+ if ( norm > 0.5 ) {
60182
+
60183
+ discard;
60184
+
60185
+ }
60186
+
60187
+ #endif
60188
+
60189
+ #endif
60190
+
60191
+ #else
60192
+
60193
+ #ifdef USE_ALPHA_TO_COVERAGE
60194
+
60195
+ // artifacts appear on some hardware if a derivative is taken within a conditional
60196
+ float a = vUv.x;
60197
+ float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;
60198
+ float len2 = a * a + b * b;
60199
+ float dlen = fwidth( len2 );
60200
+
60201
+ if ( abs( vUv.y ) > 1.0 ) {
60202
+
60203
+ alpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 );
60204
+
60205
+ }
60206
+
60207
+ #else
60208
+
60209
+ if ( abs( vUv.y ) > 1.0 ) {
60210
+
60211
+ float a = vUv.x;
60212
+ float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;
60213
+ float len2 = a * a + b * b;
60214
+
60215
+ if ( len2 > 1.0 ) discard;
60216
+
60217
+ }
60218
+
60219
+ #endif
60220
+
60221
+ #endif
60222
+
60223
+ vec4 diffuseColor = vec4( diffuse, alpha );
60224
+
60225
+ #include <logdepthbuf_fragment>
60226
+ #include <color_fragment>
60227
+
60228
+ gl_FragColor = vec4( diffuseColor.rgb, alpha );
60229
+
60230
+ #include <tonemapping_fragment>
60231
+ #include <colorspace_fragment>
60232
+ #include <fog_fragment>
60233
+ #include <premultiplied_alpha_fragment>
60234
+
60235
+ }
60236
+ `
60237
+ };
60238
+
60239
+ class LineMaterial extends ShaderMaterial {
60240
+
60241
+
60242
+ static get type() {
60243
+
60244
+ return 'LineMaterial';
60245
+
60246
+ }
60247
+
60248
+ constructor( parameters ) {
60249
+
60250
+ super( {
60251
+
60252
+ uniforms: UniformsUtils.clone( ShaderLib[ 'line' ].uniforms ),
60253
+
60254
+ vertexShader: ShaderLib[ 'line' ].vertexShader,
60255
+ fragmentShader: ShaderLib[ 'line' ].fragmentShader,
60256
+
60257
+ clipping: true // required for clipping support
60258
+
60259
+ } );
60260
+
60261
+ this.isLineMaterial = true;
60262
+
60263
+ this.setValues( parameters );
60264
+
60265
+ }
60266
+
60267
+ get color() {
60268
+
60269
+ return this.uniforms.diffuse.value;
60270
+
60271
+ }
60272
+
60273
+ set color( value ) {
60274
+
60275
+ this.uniforms.diffuse.value = value;
60276
+
60277
+ }
60278
+
60279
+ get worldUnits() {
60280
+
60281
+ return 'WORLD_UNITS' in this.defines;
60282
+
60283
+ }
60284
+
60285
+ set worldUnits( value ) {
60286
+
60287
+ if ( value === true ) {
60288
+
60289
+ this.defines.WORLD_UNITS = '';
60290
+
60291
+ } else {
60292
+
60293
+ delete this.defines.WORLD_UNITS;
60294
+
60295
+ }
60296
+
60297
+ }
60298
+
60299
+ get linewidth() {
60300
+
60301
+ return this.uniforms.linewidth.value;
60302
+
60303
+ }
60304
+
60305
+ set linewidth( value ) {
60306
+
60307
+ if ( ! this.uniforms.linewidth ) return;
60308
+ this.uniforms.linewidth.value = value;
60309
+
60310
+ }
60311
+
60312
+ get dashed() {
60313
+
60314
+ return 'USE_DASH' in this.defines;
60315
+
60316
+ }
60317
+
60318
+ set dashed( value ) {
60319
+
60320
+ if ( ( value === true ) !== this.dashed ) {
60321
+
60322
+ this.needsUpdate = true;
60323
+
60324
+ }
60325
+
60326
+ if ( value === true ) {
60327
+
60328
+ this.defines.USE_DASH = '';
60329
+
60330
+ } else {
60331
+
60332
+ delete this.defines.USE_DASH;
60333
+
60334
+ }
60335
+
60336
+ }
60337
+
60338
+ get dashScale() {
60339
+
60340
+ return this.uniforms.dashScale.value;
60341
+
60342
+ }
60343
+
60344
+ set dashScale( value ) {
60345
+
60346
+ this.uniforms.dashScale.value = value;
60347
+
60348
+ }
60349
+
60350
+ get dashSize() {
60351
+
60352
+ return this.uniforms.dashSize.value;
60353
+
60354
+ }
60355
+
60356
+ set dashSize( value ) {
60357
+
60358
+ this.uniforms.dashSize.value = value;
60359
+
60360
+ }
60361
+
60362
+ get dashOffset() {
60363
+
60364
+ return this.uniforms.dashOffset.value;
60365
+
60366
+ }
60367
+
60368
+ set dashOffset( value ) {
60369
+
60370
+ this.uniforms.dashOffset.value = value;
60371
+
60372
+ }
60373
+
60374
+ get gapSize() {
60375
+
60376
+ return this.uniforms.gapSize.value;
60377
+
60378
+ }
60379
+
60380
+ set gapSize( value ) {
60381
+
60382
+ this.uniforms.gapSize.value = value;
60383
+
60384
+ }
60385
+
60386
+ get opacity() {
60387
+
60388
+ return this.uniforms.opacity.value;
60389
+
60390
+ }
60391
+
60392
+ set opacity( value ) {
60393
+
60394
+ if ( ! this.uniforms ) return;
60395
+ this.uniforms.opacity.value = value;
60396
+
60397
+ }
60398
+
60399
+ get resolution() {
60400
+
60401
+ return this.uniforms.resolution.value;
60402
+
60403
+ }
60404
+
60405
+ set resolution( value ) {
60406
+
60407
+ this.uniforms.resolution.value.copy( value );
60408
+
60409
+ }
60410
+
60411
+ get alphaToCoverage() {
60412
+
60413
+ return 'USE_ALPHA_TO_COVERAGE' in this.defines;
60414
+
60415
+ }
60416
+
60417
+ set alphaToCoverage( value ) {
60418
+
60419
+ if ( ! this.defines ) return;
60420
+
60421
+ if ( ( value === true ) !== this.alphaToCoverage ) {
60422
+
60423
+ this.needsUpdate = true;
60424
+
60425
+ }
60426
+
60427
+ if ( value === true ) {
60428
+
60429
+ this.defines.USE_ALPHA_TO_COVERAGE = '';
60430
+
60431
+ } else {
60432
+
60433
+ delete this.defines.USE_ALPHA_TO_COVERAGE;
60434
+
60435
+ }
60436
+
60437
+ }
60438
+
60439
+ }
60440
+
60441
+ const _viewport = new Vector4();
60442
+
60443
+ const _start = new Vector3();
60444
+ const _end = new Vector3();
60445
+
60446
+ const _start4 = new Vector4();
60447
+ const _end4 = new Vector4();
60448
+
60449
+ const _ssOrigin = new Vector4();
60450
+ const _ssOrigin3 = new Vector3();
60451
+ const _mvMatrix = new Matrix4();
60452
+ const _line = new Line3();
60453
+ const _closestPoint = new Vector3();
60454
+
60455
+ const _box = new Box3();
60456
+ const _sphere = new Sphere();
60457
+ const _clipToWorldVector = new Vector4();
60458
+
60459
+ let _ray, _lineWidth;
60460
+
60461
+ // Returns the margin required to expand by in world space given the distance from the camera,
60462
+ // line width, resolution, and camera projection
60463
+ function getWorldSpaceHalfWidth( camera, distance, resolution ) {
60464
+
60465
+ // transform into clip space, adjust the x and y values by the pixel width offset, then
60466
+ // transform back into world space to get world offset. Note clip space is [-1, 1] so full
60467
+ // width does not need to be halved.
60468
+ _clipToWorldVector.set( 0, 0, - distance, 1.0 ).applyMatrix4( camera.projectionMatrix );
60469
+ _clipToWorldVector.multiplyScalar( 1.0 / _clipToWorldVector.w );
60470
+ _clipToWorldVector.x = _lineWidth / resolution.width;
60471
+ _clipToWorldVector.y = _lineWidth / resolution.height;
60472
+ _clipToWorldVector.applyMatrix4( camera.projectionMatrixInverse );
60473
+ _clipToWorldVector.multiplyScalar( 1.0 / _clipToWorldVector.w );
60474
+
60475
+ return Math.abs( Math.max( _clipToWorldVector.x, _clipToWorldVector.y ) );
60476
+
60477
+ }
60478
+
60479
+ function raycastWorldUnits( lineSegments, intersects ) {
60480
+
60481
+ const matrixWorld = lineSegments.matrixWorld;
60482
+ const geometry = lineSegments.geometry;
60483
+ const instanceStart = geometry.attributes.instanceStart;
60484
+ const instanceEnd = geometry.attributes.instanceEnd;
60485
+ const segmentCount = Math.min( geometry.instanceCount, instanceStart.count );
60486
+
60487
+ for ( let i = 0, l = segmentCount; i < l; i ++ ) {
60488
+
60489
+ _line.start.fromBufferAttribute( instanceStart, i );
60490
+ _line.end.fromBufferAttribute( instanceEnd, i );
60491
+
60492
+ _line.applyMatrix4( matrixWorld );
60493
+
60494
+ const pointOnLine = new Vector3();
60495
+ const point = new Vector3();
60496
+
60497
+ _ray.distanceSqToSegment( _line.start, _line.end, point, pointOnLine );
60498
+ const isInside = point.distanceTo( pointOnLine ) < _lineWidth * 0.5;
60499
+
60500
+ if ( isInside ) {
60501
+
60502
+ intersects.push( {
60503
+ point,
60504
+ pointOnLine,
60505
+ distance: _ray.origin.distanceTo( point ),
60506
+ object: lineSegments,
60507
+ face: null,
60508
+ faceIndex: i,
60509
+ uv: null,
60510
+ uv1: null,
60511
+ } );
60512
+
60513
+ }
60514
+
60515
+ }
60516
+
60517
+ }
60518
+
60519
+ function raycastScreenSpace( lineSegments, camera, intersects ) {
60520
+
60521
+ const projectionMatrix = camera.projectionMatrix;
60522
+ const material = lineSegments.material;
60523
+ const resolution = material.resolution;
60524
+ const matrixWorld = lineSegments.matrixWorld;
60525
+
60526
+ const geometry = lineSegments.geometry;
60527
+ const instanceStart = geometry.attributes.instanceStart;
60528
+ const instanceEnd = geometry.attributes.instanceEnd;
60529
+ const segmentCount = Math.min( geometry.instanceCount, instanceStart.count );
60530
+
60531
+ const near = - camera.near;
60532
+
60533
+ //
60534
+
60535
+ // pick a point 1 unit out along the ray to avoid the ray origin
60536
+ // sitting at the camera origin which will cause "w" to be 0 when
60537
+ // applying the projection matrix.
60538
+ _ray.at( 1, _ssOrigin );
60539
+
60540
+ // ndc space [ - 1.0, 1.0 ]
60541
+ _ssOrigin.w = 1;
60542
+ _ssOrigin.applyMatrix4( camera.matrixWorldInverse );
60543
+ _ssOrigin.applyMatrix4( projectionMatrix );
60544
+ _ssOrigin.multiplyScalar( 1 / _ssOrigin.w );
60545
+
60546
+ // screen space
60547
+ _ssOrigin.x *= resolution.x / 2;
60548
+ _ssOrigin.y *= resolution.y / 2;
60549
+ _ssOrigin.z = 0;
60550
+
60551
+ _ssOrigin3.copy( _ssOrigin );
60552
+
60553
+ _mvMatrix.multiplyMatrices( camera.matrixWorldInverse, matrixWorld );
60554
+
60555
+ for ( let i = 0, l = segmentCount; i < l; i ++ ) {
60556
+
60557
+ _start4.fromBufferAttribute( instanceStart, i );
60558
+ _end4.fromBufferAttribute( instanceEnd, i );
60559
+
60560
+ _start4.w = 1;
60561
+ _end4.w = 1;
60562
+
60563
+ // camera space
60564
+ _start4.applyMatrix4( _mvMatrix );
60565
+ _end4.applyMatrix4( _mvMatrix );
60566
+
60567
+ // skip the segment if it's entirely behind the camera
60568
+ const isBehindCameraNear = _start4.z > near && _end4.z > near;
60569
+ if ( isBehindCameraNear ) {
60570
+
60571
+ continue;
60572
+
60573
+ }
60574
+
60575
+ // trim the segment if it extends behind camera near
60576
+ if ( _start4.z > near ) {
60577
+
60578
+ const deltaDist = _start4.z - _end4.z;
60579
+ const t = ( _start4.z - near ) / deltaDist;
60580
+ _start4.lerp( _end4, t );
60581
+
60582
+ } else if ( _end4.z > near ) {
60583
+
60584
+ const deltaDist = _end4.z - _start4.z;
60585
+ const t = ( _end4.z - near ) / deltaDist;
60586
+ _end4.lerp( _start4, t );
60587
+
60588
+ }
60589
+
60590
+ // clip space
60591
+ _start4.applyMatrix4( projectionMatrix );
60592
+ _end4.applyMatrix4( projectionMatrix );
60593
+
60594
+ // ndc space [ - 1.0, 1.0 ]
60595
+ _start4.multiplyScalar( 1 / _start4.w );
60596
+ _end4.multiplyScalar( 1 / _end4.w );
60597
+
60598
+ // screen space
60599
+ _start4.x *= resolution.x / 2;
60600
+ _start4.y *= resolution.y / 2;
60601
+
60602
+ _end4.x *= resolution.x / 2;
60603
+ _end4.y *= resolution.y / 2;
60604
+
60605
+ // create 2d segment
60606
+ _line.start.copy( _start4 );
60607
+ _line.start.z = 0;
60608
+
60609
+ _line.end.copy( _end4 );
60610
+ _line.end.z = 0;
60611
+
60612
+ // get closest point on ray to segment
60613
+ const param = _line.closestPointToPointParameter( _ssOrigin3, true );
60614
+ _line.at( param, _closestPoint );
60615
+
60616
+ // check if the intersection point is within clip space
60617
+ const zPos = MathUtils.lerp( _start4.z, _end4.z, param );
60618
+ const isInClipSpace = zPos >= - 1 && zPos <= 1;
60619
+
60620
+ const isInside = _ssOrigin3.distanceTo( _closestPoint ) < _lineWidth * 0.5;
60621
+
60622
+ if ( isInClipSpace && isInside ) {
60623
+
60624
+ _line.start.fromBufferAttribute( instanceStart, i );
60625
+ _line.end.fromBufferAttribute( instanceEnd, i );
60626
+
60627
+ _line.start.applyMatrix4( matrixWorld );
60628
+ _line.end.applyMatrix4( matrixWorld );
60629
+
60630
+ const pointOnLine = new Vector3();
60631
+ const point = new Vector3();
60632
+
60633
+ _ray.distanceSqToSegment( _line.start, _line.end, point, pointOnLine );
60634
+
60635
+ intersects.push( {
60636
+ point: point,
60637
+ pointOnLine: pointOnLine,
60638
+ distance: _ray.origin.distanceTo( point ),
60639
+ object: lineSegments,
60640
+ face: null,
60641
+ faceIndex: i,
60642
+ uv: null,
60643
+ uv1: null,
60644
+ } );
60645
+
60646
+ }
60647
+
60648
+ }
60649
+
60650
+ }
60651
+
60652
+ class LineSegments2 extends Mesh {
60653
+
60654
+ constructor( geometry = new LineSegmentsGeometry(), material = new LineMaterial( { color: Math.random() * 0xffffff } ) ) {
60655
+
60656
+ super( geometry, material );
60657
+
60658
+ this.isLineSegments2 = true;
60659
+
60660
+ this.type = 'LineSegments2';
60661
+
60662
+ }
60663
+
60664
+ // for backwards-compatibility, but could be a method of LineSegmentsGeometry...
60665
+
60666
+ computeLineDistances() {
60667
+
60668
+ const geometry = this.geometry;
60669
+
60670
+ const instanceStart = geometry.attributes.instanceStart;
60671
+ const instanceEnd = geometry.attributes.instanceEnd;
60672
+ const lineDistances = new Float32Array( 2 * instanceStart.count );
60673
+
60674
+ for ( let i = 0, j = 0, l = instanceStart.count; i < l; i ++, j += 2 ) {
60675
+
60676
+ _start.fromBufferAttribute( instanceStart, i );
60677
+ _end.fromBufferAttribute( instanceEnd, i );
60678
+
60679
+ lineDistances[ j ] = ( j === 0 ) ? 0 : lineDistances[ j - 1 ];
60680
+ lineDistances[ j + 1 ] = lineDistances[ j ] + _start.distanceTo( _end );
60681
+
60682
+ }
60683
+
60684
+ const instanceDistanceBuffer = new InstancedInterleavedBuffer( lineDistances, 2, 1 ); // d0, d1
60685
+
60686
+ geometry.setAttribute( 'instanceDistanceStart', new InterleavedBufferAttribute( instanceDistanceBuffer, 1, 0 ) ); // d0
60687
+ geometry.setAttribute( 'instanceDistanceEnd', new InterleavedBufferAttribute( instanceDistanceBuffer, 1, 1 ) ); // d1
60688
+
60689
+ return this;
60690
+
60691
+ }
60692
+
60693
+ raycast( raycaster, intersects ) {
60694
+
60695
+ const worldUnits = this.material.worldUnits;
60696
+ const camera = raycaster.camera;
60697
+
60698
+ if ( camera === null && ! worldUnits ) {
60699
+
60700
+ console.error( 'LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.' );
60701
+
60702
+ }
60703
+
60704
+ const threshold = ( raycaster.params.Line2 !== undefined ) ? raycaster.params.Line2.threshold || 0 : 0;
60705
+
60706
+ _ray = raycaster.ray;
60707
+
60708
+ const matrixWorld = this.matrixWorld;
60709
+ const geometry = this.geometry;
60710
+ const material = this.material;
60711
+
60712
+ _lineWidth = material.linewidth + threshold;
60713
+
60714
+ // check if we intersect the sphere bounds
60715
+ if ( geometry.boundingSphere === null ) {
60716
+
60717
+ geometry.computeBoundingSphere();
60718
+
60719
+ }
60720
+
60721
+ _sphere.copy( geometry.boundingSphere ).applyMatrix4( matrixWorld );
60722
+
60723
+ // increase the sphere bounds by the worst case line screen space width
60724
+ let sphereMargin;
60725
+ if ( worldUnits ) {
60726
+
60727
+ sphereMargin = _lineWidth * 0.5;
60728
+
60729
+ } else {
60730
+
60731
+ const distanceToSphere = Math.max( camera.near, _sphere.distanceToPoint( _ray.origin ) );
60732
+ sphereMargin = getWorldSpaceHalfWidth( camera, distanceToSphere, material.resolution );
60733
+
60734
+ }
60735
+
60736
+ _sphere.radius += sphereMargin;
60737
+
60738
+ if ( _ray.intersectsSphere( _sphere ) === false ) {
60739
+
60740
+ return;
60741
+
60742
+ }
60743
+
60744
+ // check if we intersect the box bounds
60745
+ if ( geometry.boundingBox === null ) {
60746
+
60747
+ geometry.computeBoundingBox();
60748
+
60749
+ }
60750
+
60751
+ _box.copy( geometry.boundingBox ).applyMatrix4( matrixWorld );
60752
+
60753
+ // increase the box bounds by the worst case line width
60754
+ let boxMargin;
60755
+ if ( worldUnits ) {
60756
+
60757
+ boxMargin = _lineWidth * 0.5;
60758
+
60759
+ } else {
60760
+
60761
+ const distanceToBox = Math.max( camera.near, _box.distanceToPoint( _ray.origin ) );
60762
+ boxMargin = getWorldSpaceHalfWidth( camera, distanceToBox, material.resolution );
60763
+
60764
+ }
60765
+
60766
+ _box.expandByScalar( boxMargin );
60767
+
60768
+ if ( _ray.intersectsBox( _box ) === false ) {
60769
+
60770
+ return;
60771
+
60772
+ }
60773
+
60774
+ if ( worldUnits ) {
60775
+
60776
+ raycastWorldUnits( this, intersects );
60777
+
60778
+ } else {
60779
+
60780
+ raycastScreenSpace( this, camera, intersects );
60781
+
60782
+ }
60783
+
60784
+ }
60785
+
60786
+ onBeforeRender( renderer ) {
60787
+
60788
+ const uniforms = this.material.uniforms;
60789
+
60790
+ if ( uniforms && uniforms.resolution ) {
60791
+
60792
+ renderer.getViewport( _viewport );
60793
+ this.material.uniforms.resolution.value.set( _viewport.z, _viewport.w );
60794
+
60795
+ }
60796
+
60797
+ }
60798
+
60799
+ }
60800
+
60801
+ class LineGeometry extends LineSegmentsGeometry {
60802
+
60803
+ constructor() {
60804
+
60805
+ super();
60806
+
60807
+ this.isLineGeometry = true;
60808
+
60809
+ this.type = 'LineGeometry';
60810
+
60811
+ }
60812
+
60813
+ setPositions( array ) {
60814
+
60815
+ // converts [ x1, y1, z1, x2, y2, z2, ... ] to pairs format
60816
+
60817
+ const length = array.length - 3;
60818
+ const points = new Float32Array( 2 * length );
60819
+
60820
+ for ( let i = 0; i < length; i += 3 ) {
60821
+
60822
+ points[ 2 * i ] = array[ i ];
60823
+ points[ 2 * i + 1 ] = array[ i + 1 ];
60824
+ points[ 2 * i + 2 ] = array[ i + 2 ];
60825
+
60826
+ points[ 2 * i + 3 ] = array[ i + 3 ];
60827
+ points[ 2 * i + 4 ] = array[ i + 4 ];
60828
+ points[ 2 * i + 5 ] = array[ i + 5 ];
60829
+
60830
+ }
60831
+
60832
+ super.setPositions( points );
60833
+
60834
+ return this;
60835
+
60836
+ }
60837
+
60838
+ setColors( array ) {
60839
+
60840
+ // converts [ r1, g1, b1, r2, g2, b2, ... ] to pairs format
60841
+
60842
+ const length = array.length - 3;
60843
+ const colors = new Float32Array( 2 * length );
60844
+
60845
+ for ( let i = 0; i < length; i += 3 ) {
60846
+
60847
+ colors[ 2 * i ] = array[ i ];
60848
+ colors[ 2 * i + 1 ] = array[ i + 1 ];
60849
+ colors[ 2 * i + 2 ] = array[ i + 2 ];
60850
+
60851
+ colors[ 2 * i + 3 ] = array[ i + 3 ];
60852
+ colors[ 2 * i + 4 ] = array[ i + 4 ];
60853
+ colors[ 2 * i + 5 ] = array[ i + 5 ];
60854
+
60855
+ }
60856
+
60857
+ super.setColors( colors );
60858
+
60859
+ return this;
60860
+
60861
+ }
60862
+
60863
+ fromLine( line ) {
60864
+
60865
+ const geometry = line.geometry;
60866
+
60867
+ this.setPositions( geometry.attributes.position.array ); // assumes non-indexed
60868
+
60869
+ // set colors, maybe
60870
+
60871
+ return this;
60872
+
60873
+ }
60874
+
60875
+ }
60876
+
60877
+ class Line2 extends LineSegments2 {
60878
+
60879
+ constructor( geometry = new LineGeometry(), material = new LineMaterial( { color: Math.random() * 0xffffff } ) ) {
60880
+
60881
+ super( geometry, material );
60882
+
60883
+ this.isLine2 = true;
60884
+
60885
+ this.type = 'Line2';
60886
+
60887
+ }
60888
+
60889
+ }
60890
+
60891
+ /**
60892
+ * 把标注顶点(local)序列展平成 Line2 需要的 world [x,y,z, ...]。
60893
+ * 每个点 local→world,再沿 world 法线外移 epsilon,避免与模型表面 z-fighting。
60894
+ * closed 时把首点追加到末尾形成环。
60895
+ */
60896
+ function flatten(verts, closed, epsilon, mesh) {
60897
+ const pts = [];
60898
+ const push = (v) => {
60899
+ const { p, n } = localVertexToWorld(v, mesh);
60900
+ pts.push(p.x + n.x * epsilon, p.y + n.y * epsilon, p.z + n.z * epsilon);
60901
+ };
60902
+ verts.forEach(push);
60903
+ if (closed && verts.length > 1)
60904
+ push(verts[0]);
60905
+ return pts;
60906
+ }
60907
+ function makeContourLine(verts, color, closed, container, epsilon, mesh) {
60908
+ const geo = new LineGeometry();
60909
+ const pos = flatten(verts, closed, epsilon, mesh);
60910
+ // Line2 至少需要 2 个点;不足时给一个退化占位,后续 update 会补上。
60911
+ geo.setPositions(pos.length >= 6 ? pos : [0, 0, 0, 0, 0, 0]);
60912
+ const mat = new LineMaterial({
60913
+ color: new Color$1(color).getHex(),
60914
+ linewidth: 3, // 像素宽(需 resolution 配合)
60915
+ });
60916
+ mat.resolution.set(container.clientWidth, container.clientHeight);
60917
+ const line = new Line2(geo, mat);
60918
+ line.computeLineDistances();
60919
+ line.renderOrder = 998;
60920
+ // 关键:Line2 的包围球停留在初始点,拖拽生长后真实几何会被错误剔除。
60921
+ // 关闭视锥剔除,保证线始终渲染。
60922
+ line.frustumCulled = false;
60923
+ return line;
60924
+ }
60925
+ function updateContourLine(line, verts, closed, epsilon, mesh) {
60926
+ const pos = flatten(verts, closed, epsilon, mesh);
60927
+ if (pos.length < 6)
60928
+ return; // Line2 需要 >=2 点
60929
+ // 关键:Line2 在原 geometry 上 setPositions 扩容后只渲染首段(已知坑)。
60930
+ // 改为每次重建一个新 LineGeometry 并替换,保证实例数正确、全段渲染。
60931
+ const geo = new LineGeometry();
60932
+ geo.setPositions(pos);
60933
+ const old = line.geometry;
60934
+ line.geometry = geo;
60935
+ old.dispose();
60936
+ line.computeLineDistances();
60937
+ }
60938
+ /** 改变已有 contour 线的颜色。 */
60939
+ function setContourColor(line, color) {
60940
+ line.material.color.set(color);
60941
+ }
60942
+
60943
+ /**
60944
+ * 从 BufferGeometry 的索引构建顶点邻接图,用于模式 B(测地线)的最短路径。
60945
+ * 顶点坐标按 local 存;传入的查询点需先转为 local(mesh.worldToLocal)。
60946
+ *
60947
+ * 说明:几何须为已索引(indexed)。modelLoader 用 mergeVertices 焊接重复顶点,
60948
+ * 保证同一表面位置共享顶点,邻接图才连通。
60949
+ *
60950
+ * 性能:O(V²) Dijkstra + O(V) 最近顶点查找。对几万顶点单次点击可接受;
60951
+ * 若过大可后续换二叉堆 + 空间网格加速(留作升级)。
60952
+ */
60953
+ class MeshGraph {
60954
+ constructor(geometry) {
60955
+ this.adj = [];
60956
+ const pos = geometry.getAttribute("position");
60957
+ this.positions = pos.array;
60958
+ const nrm = geometry.getAttribute("normal");
60959
+ this.normals = nrm ? nrm.array : null;
60960
+ this.vertexCount = pos.count;
60961
+ for (let i = 0; i < this.vertexCount; i++)
60962
+ this.adj.push(new Set());
60963
+ const addEdge = (a, b) => {
60964
+ this.adj[a].add(b);
60965
+ this.adj[b].add(a);
60966
+ };
60967
+ const index = geometry.getIndex();
60968
+ if (index) {
60969
+ for (let i = 0; i < index.count; i += 3) {
60970
+ const a = index.getX(i);
60971
+ const b = index.getX(i + 1);
60972
+ const c = index.getX(i + 2);
60973
+ addEdge(a, b);
60974
+ addEdge(b, c);
60975
+ addEdge(c, a);
60976
+ }
60977
+ }
60978
+ else {
60979
+ // 非索引兜底(连通性差,仅避免崩溃)。
60980
+ for (let i = 0; i + 2 < this.vertexCount; i += 3) {
60981
+ addEdge(i, i + 1);
60982
+ addEdge(i + 1, i + 2);
60983
+ addEdge(i + 2, i);
60984
+ }
60985
+ }
60986
+ }
60987
+ px(i) {
60988
+ return this.positions[i * 3];
60989
+ }
60990
+ py(i) {
60991
+ return this.positions[i * 3 + 1];
60992
+ }
60993
+ pz(i) {
60994
+ return this.positions[i * 3 + 2];
60995
+ }
60996
+ /** 最近顶点(传入 local 坐标)。 */
60997
+ nearestVertex(localPoint) {
60998
+ let best = -1;
60999
+ let bestD = Infinity;
61000
+ for (let i = 0; i < this.vertexCount; i++) {
61001
+ const dx = this.px(i) - localPoint.x;
61002
+ const dy = this.py(i) - localPoint.y;
61003
+ const dz = this.pz(i) - localPoint.z;
61004
+ const d = dx * dx + dy * dy + dz * dz;
61005
+ if (d < bestD) {
61006
+ bestD = d;
61007
+ best = i;
61008
+ }
61009
+ }
61010
+ return best;
61011
+ }
61012
+ /**
61013
+ * 两顶点间最短路径(含端点的顶点索引序列)。二叉堆 Dijkstra,O(E log V)。
61014
+ * 不连通时返回 [start,end] 兜底。
61015
+ */
61016
+ shortestPath(startV, endV) {
61017
+ if (startV === endV)
61018
+ return [startV];
61019
+ const dist = new Float64Array(this.vertexCount).fill(Infinity);
61020
+ const prev = new Int32Array(this.vertexCount).fill(-1);
61021
+ const done = new Uint8Array(this.vertexCount);
61022
+ dist[startV] = 0;
61023
+ const heap = new MinHeap();
61024
+ heap.push(startV, 0);
61025
+ while (heap.size > 0) {
61026
+ const u = heap.pop();
61027
+ if (done[u])
61028
+ continue;
61029
+ done[u] = 1;
61030
+ if (u === endV)
61031
+ break;
61032
+ const ud = dist[u];
61033
+ const ux = this.px(u);
61034
+ const uy = this.py(u);
61035
+ const uz = this.pz(u);
61036
+ for (const w of this.adj[u]) {
61037
+ if (done[w])
61038
+ continue;
61039
+ const dx = this.px(w) - ux;
61040
+ const dy = this.py(w) - uy;
61041
+ const dz = this.pz(w) - uz;
61042
+ const nd = ud + Math.sqrt(dx * dx + dy * dy + dz * dz);
61043
+ if (nd < dist[w]) {
61044
+ dist[w] = nd;
61045
+ prev[w] = u;
61046
+ heap.push(w, nd);
61047
+ }
61048
+ }
61049
+ }
61050
+ if (prev[endV] === -1 && startV !== endV)
61051
+ return [startV, endV];
61052
+ const path = [];
61053
+ for (let c = endV; c !== -1; c = prev[c]) {
61054
+ path.push(c);
61055
+ if (c === startV)
61056
+ break;
61057
+ }
61058
+ return path.reverse();
61059
+ }
61060
+ vertexWorld(i, matrixWorld) {
61061
+ return new Vector3(this.px(i), this.py(i), this.pz(i)).applyMatrix4(matrixWorld);
61062
+ }
61063
+ vertexNormalWorld(i, mesh) {
61064
+ const n = new Vector3(0, 0, 1);
61065
+ if (this.normals) {
61066
+ n.set(this.normals[i * 3], this.normals[i * 3 + 1], this.normals[i * 3 + 2]);
61067
+ }
61068
+ const nm = new Matrix3().getNormalMatrix(mesh.matrixWorld);
61069
+ return n.applyMatrix3(nm).normalize();
61070
+ }
61071
+ /** 顶点的 local 坐标 + local 法线(图几何即 local 空间)。 */
61072
+ vertexLocal(i) {
61073
+ return {
61074
+ x: this.px(i),
61075
+ y: this.py(i),
61076
+ z: this.pz(i),
61077
+ nx: this.normals ? this.normals[i * 3] : 0,
61078
+ ny: this.normals ? this.normals[i * 3 + 1] : 0,
61079
+ nz: this.normals ? this.normals[i * 3 + 2] : 1,
61080
+ faceIndex: -1,
61081
+ };
61082
+ }
61083
+ }
61084
+ /** 极简二叉最小堆(按 priority 排序,存顶点索引)。用于 Dijkstra。 */
61085
+ class MinHeap {
61086
+ constructor() {
61087
+ this.ids = [];
61088
+ this.prio = [];
61089
+ }
61090
+ get size() {
61091
+ return this.ids.length;
61092
+ }
61093
+ push(id, priority) {
61094
+ this.ids.push(id);
61095
+ this.prio.push(priority);
61096
+ let i = this.ids.length - 1;
61097
+ while (i > 0) {
61098
+ const parent = (i - 1) >> 1;
61099
+ if (this.prio[parent] <= this.prio[i])
61100
+ break;
61101
+ this.swap(i, parent);
61102
+ i = parent;
61103
+ }
61104
+ }
61105
+ pop() {
61106
+ const topId = this.ids[0];
61107
+ const lastId = this.ids.pop();
61108
+ const lastPrio = this.prio.pop();
61109
+ if (this.ids.length > 0) {
61110
+ this.ids[0] = lastId;
61111
+ this.prio[0] = lastPrio;
61112
+ let i = 0;
61113
+ const n = this.ids.length;
61114
+ for (;;) {
61115
+ const l = 2 * i + 1;
61116
+ const r = 2 * i + 2;
61117
+ let smallest = i;
61118
+ if (l < n && this.prio[l] < this.prio[smallest])
61119
+ smallest = l;
61120
+ if (r < n && this.prio[r] < this.prio[smallest])
61121
+ smallest = r;
61122
+ if (smallest === i)
61123
+ break;
61124
+ this.swap(i, smallest);
61125
+ i = smallest;
61126
+ }
61127
+ }
61128
+ return topId;
61129
+ }
61130
+ swap(a, b) {
61131
+ const ti = this.ids[a];
61132
+ this.ids[a] = this.ids[b];
61133
+ this.ids[b] = ti;
61134
+ const tp = this.prio[a];
61135
+ this.prio[a] = this.prio[b];
61136
+ this.prio[b] = tp;
61137
+ }
61138
+ }
61139
+
61140
+ /**
61141
+ * 模式 B(测地线)状态机:逐次点击锚点,相邻锚点之间用 MeshGraph 求最短路径,
61142
+ * 拼成一条贴合表面的折线。Enter 结束并可闭合(首尾再求一段)。
61143
+ */
61144
+ class GeodesicContour {
61145
+ constructor(graph, mesh) {
61146
+ this.graph = graph;
61147
+ this.mesh = mesh;
61148
+ this.anchors = []; // 顶点索引
61149
+ this.segments = []; // 相邻锚点间路径(含端点)
61150
+ }
61151
+ /** 传入 local 命中点,snap 到最近顶点并对上一锚点求路径。 */
61152
+ addAnchor(localHitPoint) {
61153
+ const v = this.graph.nearestVertex(localHitPoint);
61154
+ if (this.anchors.length > 0) {
61155
+ const prev = this.anchors[this.anchors.length - 1];
61156
+ this.segments.push(this.graph.shortestPath(prev, v));
61157
+ }
61158
+ this.anchors.push(v);
61159
+ }
61160
+ get anchorCount() {
61161
+ return this.anchors.length;
61162
+ }
61163
+ /** 把所有路径顶点(world)+ 法线 拼成折线;closed 时补一段首尾路径。 */
61164
+ buildVertices(closed) {
61165
+ const segs = this.segments.slice();
61166
+ if (closed && this.anchors.length > 2) {
61167
+ segs.push(this.graph.shortestPath(this.anchors[this.anchors.length - 1], this.anchors[0]));
61168
+ }
61169
+ const idxPath = [];
61170
+ segs.forEach((s, si) => {
61171
+ const start = si === 0 ? 0 : 1; // 去重相邻段共享端点
61172
+ for (let k = start; k < s.length; k++)
61173
+ idxPath.push(s[k]);
61174
+ });
61175
+ if (idxPath.length === 0 && this.anchors.length === 1) {
61176
+ idxPath.push(this.anchors[0]);
61177
+ }
61178
+ // 图几何即 local 空间,直接产出 local 顶点(渲染时再派生 world)。
61179
+ return idxPath.map((i) => this.graph.vertexLocal(i));
61180
+ }
61181
+ }
61182
+
61183
+ /**
61184
+ * 标注数据模型 + 撤销栈 + 导出。纯数据,无 three / DOM 依赖。
61185
+ * 撤销只记录 add / remove 两类原子操作(满足"撤销最近添加 / 恢复删除")。
61186
+ * 通过 subscribe 通知 UI 与渲染层(后者据 list() 做场景对账)。
61187
+ */
61188
+ class AnnotationStore {
61189
+ constructor() {
61190
+ this.items = [];
61191
+ this.undoStack = [];
61192
+ this.subs = new Set();
61193
+ }
61194
+ notify() {
61195
+ this.subs.forEach((f) => f());
61196
+ }
61197
+ subscribe(cb) {
61198
+ this.subs.add(cb);
61199
+ return () => this.subs.delete(cb);
61200
+ }
61201
+ add(a) {
61202
+ this.items.push(a);
61203
+ this.undoStack.push({ kind: "add", ann: a });
61204
+ this.notify();
61205
+ }
61206
+ remove(id) {
61207
+ const i = this.items.findIndex((x) => x.id === id);
61208
+ if (i < 0)
61209
+ return undefined;
61210
+ const [ann] = this.items.splice(i, 1);
61211
+ this.undoStack.push({ kind: "remove", ann });
61212
+ this.notify();
61213
+ return ann;
61214
+ }
61215
+ undo() {
61216
+ const op = this.undoStack.pop();
61217
+ if (!op)
61218
+ return;
61219
+ if (op.kind === "add") {
61220
+ const i = this.items.findIndex((x) => x.id === op.ann.id);
61221
+ if (i >= 0)
61222
+ this.items.splice(i, 1);
61223
+ }
61224
+ else {
61225
+ this.items.push(op.ann);
61226
+ }
61227
+ this.notify();
61228
+ }
61229
+ /** 清空,返回被清掉的项(供渲染层 dispose three 对象)。 */
61230
+ clear() {
61231
+ const old = this.items;
61232
+ this.items = [];
61233
+ this.undoStack = [];
61234
+ this.notify();
61235
+ return old;
61236
+ }
61237
+ list() {
61238
+ return this.items;
61239
+ }
61240
+ get(id) {
61241
+ return this.items.find((x) => x.id === id);
61242
+ }
61243
+ setLabel(id, label) {
61244
+ const a = this.get(id);
61245
+ if (a) {
61246
+ a.label = label;
61247
+ this.notify();
61248
+ }
61249
+ }
61250
+ setColor(id, color) {
61251
+ const a = this.get(id);
61252
+ if (a) {
61253
+ a.color = color;
61254
+ this.notify();
61255
+ }
61256
+ }
61257
+ toJSON(modelName, mesh, opts = {}) {
61258
+ var _a;
61259
+ const space = (_a = opts.space) !== null && _a !== void 0 ? _a : "local";
61260
+ const toPt = (v) => {
61261
+ let x = v.x, y = v.y, z = v.z;
61262
+ if (space === "world") {
61263
+ const p = new Vector3(v.x, v.y, v.z).applyMatrix4(mesh.matrixWorld);
61264
+ x = p.x;
61265
+ y = p.y;
61266
+ z = p.z;
61267
+ }
61268
+ return opts.includeNormals ? [x, y, z, v.nx, v.ny, v.nz] : [x, y, z];
61269
+ };
61270
+ return {
61271
+ model: modelName,
61272
+ exportedAt: new Date().toISOString(),
61273
+ space,
61274
+ annotations: this.items.map((a) => ({
61275
+ id: a.id,
61276
+ type: a.type,
61277
+ mode: a.mode,
61278
+ label: a.label,
61279
+ color: a.color,
61280
+ closed: a.closed,
61281
+ points: a.vertices.map(toPt),
61282
+ })),
61283
+ };
61284
+ }
61285
+ }
61286
+
61287
+ const LINE_W = 3;
61288
+ const LINE_W_SEL = 6;
61289
+ /**
61290
+ * 表面标注主控制器(Phase 4):navigate / freehand / geodesic / point 四模式,
61291
+ * Enter 闭合,数据交给 AnnotationStore 管理(多条带颜色标签、撤销/删除/清空、导出)。
61292
+ * 渲染层据 store.list() 做场景对账(reconcile),撤销/删除自动加/移 three 对象。
61293
+ */
61294
+ class SurfaceAnnotator {
61295
+ constructor(opts) {
61296
+ var _a, _b;
61297
+ this.mode = "navigate";
61298
+ this.spaceHeld = false;
61299
+ this.pointerDown = false;
61300
+ this.store = new AnnotationStore();
61301
+ this.managed = new Set();
61302
+ this.seq = 0;
61303
+ this.selectedId = null;
61304
+ /** 窗口尺寸变化时更新所有 fat line 的像素分辨率,否则线宽会失真。 */
61305
+ this.onResize = () => {
61306
+ const w = this.o.container.clientWidth;
61307
+ const h = this.o.container.clientHeight;
61308
+ for (const a of this.store.list()) {
61309
+ if (a.type === "contour" && a.object3D) {
61310
+ const mat = a.object3D.material;
61311
+ mat.resolution.set(w, h);
61312
+ }
61313
+ }
61314
+ if (this.activeLine)
61315
+ (this.activeLine.material.resolution.set(w, h));
61316
+ if (this.activeGeoLine)
61317
+ (this.activeGeoLine.material.resolution.set(w, h));
61318
+ };
61319
+ this.onPointerDown = (e) => {
61320
+ if (this.spaceHeld)
61321
+ return;
61322
+ if (e.button !== 0)
61323
+ return; // 仅左键
61324
+ if (!this.insideContainer(e))
61325
+ return;
61326
+ this.pointerDown = true;
61327
+ if (this.mode === "point") {
61328
+ const h = this.hit(e);
61329
+ if (!h)
61330
+ return;
61331
+ const v = worldHitToLocalVertex(h, this.o.mesh);
61332
+ const marker = makePointMarker(v, this.o.mesh, this.pointColorVal, this.markerRadius);
61333
+ this.o.scene.add(marker);
61334
+ const ann = {
61335
+ id: this.nextId(),
61336
+ type: "points",
61337
+ mode: null,
61338
+ label: `Point ${this.seq}`,
61339
+ color: this.pointColorVal,
61340
+ closed: false,
61341
+ vertices: [v],
61342
+ object3D: marker,
61343
+ };
61344
+ this.store.add(ann);
61345
+ return;
61346
+ }
61347
+ if (this.mode === "freehand") {
61348
+ this.activeStroke = new StrokeContour(this.minGap, this.o.mesh);
61349
+ this.activeStroke.begin();
61350
+ const h = this.hit(e);
61351
+ if (h)
61352
+ this.activeStroke.addSample(h);
61353
+ this.activeLine = makeContourLine(this.activeStroke.vertices, this.freehandColor, false, this.o.container, this.epsilon, this.o.mesh);
61354
+ this.o.scene.add(this.activeLine);
61355
+ return;
61356
+ }
61357
+ if (this.mode === "geodesic") {
61358
+ const h = this.hit(e);
61359
+ if (!h)
61360
+ return;
61361
+ if (!this.activeGeo) {
61362
+ this.activeGeo = new GeodesicContour(this.graph, this.o.mesh);
61363
+ }
61364
+ const local = this.o.mesh.worldToLocal(h.point.clone());
61365
+ this.activeGeo.addAnchor(local);
61366
+ const verts = this.activeGeo.buildVertices(false);
61367
+ if (!this.activeGeoLine) {
61368
+ this.activeGeoLine = makeContourLine(verts, this.geodesicColor, false, this.o.container, this.epsilon, this.o.mesh);
61369
+ this.o.scene.add(this.activeGeoLine);
61370
+ }
61371
+ else {
61372
+ updateContourLine(this.activeGeoLine, verts, false, this.epsilon, this.o.mesh);
61373
+ }
61374
+ }
61375
+ };
61376
+ this.onPointerMove = (e) => {
61377
+ if (this.spaceHeld)
61378
+ return;
61379
+ if (this.mode === "freehand" &&
61380
+ this.pointerDown &&
61381
+ this.activeStroke &&
61382
+ this.activeLine) {
61383
+ const h = this.hit(e);
61384
+ if (!h)
61385
+ return;
61386
+ this.activeStroke.addSample(h);
61387
+ updateContourLine(this.activeLine, this.activeStroke.vertices, false, this.epsilon, this.o.mesh);
61388
+ }
61389
+ };
61390
+ this.onPointerUp = () => {
61391
+ if (!this.pointerDown)
61392
+ return;
61393
+ this.pointerDown = false;
61394
+ if (this.activeStroke && this.activeLine) {
61395
+ const verts = this.activeStroke.end();
61396
+ if (verts.length >= 2) {
61397
+ const ann = {
61398
+ id: this.nextId(),
61399
+ type: "contour",
61400
+ mode: "freehand",
61401
+ label: `Contour ${this.seq}`,
61402
+ color: this.freehandColor,
61403
+ closed: false,
61404
+ vertices: verts,
61405
+ object3D: this.activeLine,
61406
+ };
61407
+ this.store.add(ann);
61408
+ this.lastFreehand = ann;
61409
+ }
61410
+ else {
61411
+ this.o.scene.remove(this.activeLine);
61412
+ }
61413
+ this.activeStroke = undefined;
61414
+ this.activeLine = undefined;
61415
+ }
61416
+ };
61417
+ this.onKeyDown = (e) => {
61418
+ if (this.isTypingTarget(e))
61419
+ return;
61420
+ if (e.code === "Space") {
61421
+ this.spaceHeld = true;
61422
+ this.applyCameraGating();
61423
+ return;
61424
+ }
61425
+ if (e.key === "Escape") {
61426
+ this.setMode("navigate");
61427
+ return;
61428
+ }
61429
+ if ((e.ctrlKey || e.metaKey) && (e.key === "z" || e.key === "Z")) {
61430
+ e.preventDefault();
61431
+ this.undo();
61432
+ return;
61433
+ }
61434
+ if (e.key === "Delete" || e.key === "Backspace") {
61435
+ if (this.selectedId)
61436
+ this.deleteAnnotation(this.selectedId);
61437
+ return;
61438
+ }
61439
+ if (e.key === "Enter") {
61440
+ // 测地线进行中 → 结束并闭合;否则闭合最近一条自由手绘线。
61441
+ if (this.activeGeo)
61442
+ this.finishGeodesic();
61443
+ else
61444
+ this.closeLastContour();
61445
+ return;
61446
+ }
61447
+ if (e.key === "1")
61448
+ this.setMode("navigate");
61449
+ if (e.key === "2")
61450
+ this.setMode("freehand");
61451
+ if (e.key === "3")
61452
+ this.setMode("geodesic");
61453
+ if (e.key === "4")
61454
+ this.setMode("point");
61455
+ };
61456
+ this.onKeyUp = (e) => {
61457
+ if (e.code === "Space") {
61458
+ this.spaceHeld = false;
61459
+ this.applyCameraGating();
61460
+ }
61461
+ };
61462
+ this.o = opts;
61463
+ const meshGeo = opts.mesh.geometry;
61464
+ if (!meshGeo.getAttribute("normal"))
61465
+ meshGeo.computeVertexNormals(); // 渲染需要法线
61466
+ meshGeo.computeBoundingBox();
61467
+ const diag = (_a = opts.bboxDiagonal) !== null && _a !== void 0 ? _a : meshGeo.boundingBox.getSize(new Vector3()).length();
61468
+ this.markerRadius = (_b = opts.markerRadius) !== null && _b !== void 0 ? _b : diag * 0.006;
61469
+ this.epsilon = diag * 0.002;
61470
+ this.minGap = diag * 0.004;
61471
+ // 测地线连通性:单独焊接一份"仅位置"的几何给 MeshGraph 用——
61472
+ // 不动被渲染的 mesh(保留其法线/UV/纹理)。仅位置可保证同表面位置的顶点
61473
+ // 被 mergeVertices 合并(否则逐面法线/UV 会阻止合并,图断裂 → 闭合穿模)。
61474
+ const posOnly = new BufferGeometry();
61475
+ posOnly.setAttribute("position", meshGeo.getAttribute("position").clone());
61476
+ const graphGeo = mergeVertices(posOnly);
61477
+ graphGeo.computeVertexNormals();
61478
+ this.graph = new MeshGraph(graphGeo);
61479
+ this.store.subscribe(() => this.reconcile());
61480
+ // 监听挂到 window 的捕获阶段(capture=true):在 copper 的 TrackballControls
61481
+ // 之前拿到每一个指针事件,避免它的 setPointerCapture / 事件路由导致拖拽中途丢 move。
61482
+ window.addEventListener("pointerdown", this.onPointerDown, true);
61483
+ window.addEventListener("pointermove", this.onPointerMove, true);
61484
+ window.addEventListener("pointerup", this.onPointerUp, true);
61485
+ window.addEventListener("keydown", this.onKeyDown);
61486
+ window.addEventListener("keyup", this.onKeyUp);
61487
+ window.addEventListener("resize", this.onResize);
61488
+ this.applyCameraGating();
61489
+ }
61490
+ get freehandColor() {
61491
+ var _a;
61492
+ return (_a = this.o.freehandColor) !== null && _a !== void 0 ? _a : "#e5006e";
61493
+ }
61494
+ get geodesicColor() {
61495
+ var _a;
61496
+ return (_a = this.o.geodesicColor) !== null && _a !== void 0 ? _a : "#ffa24e";
61497
+ }
61498
+ get pointColorVal() {
61499
+ var _a;
61500
+ return (_a = this.o.pointColor) !== null && _a !== void 0 ? _a : "#ffd166";
61501
+ }
61502
+ // ---- 对外 API(供 Vue 调用) ----
61503
+ getMode() {
61504
+ return this.mode;
61505
+ }
61506
+ setMode(m) {
61507
+ var _a, _b;
61508
+ this.mode = m;
61509
+ this.applyCameraGating();
61510
+ (_b = (_a = this.o).onModeChange) === null || _b === void 0 ? void 0 : _b.call(_a, m);
61511
+ }
61512
+ getStore() {
61513
+ return this.store;
61514
+ }
61515
+ /** 当前标注列表快照。 */
61516
+ getAnnotations() {
61517
+ return this.store.list();
61518
+ }
61519
+ undo() {
61520
+ this.store.undo();
61521
+ }
61522
+ clearAll() {
61523
+ const removed = this.store.clear();
61524
+ removed.forEach((a) => {
61525
+ if (a.object3D) {
61526
+ this.o.scene.remove(a.object3D);
61527
+ this.disposeObject(a.object3D);
61528
+ }
61529
+ });
61530
+ this.managed.clear();
61531
+ this.selectedId = null;
61532
+ }
61533
+ deleteAnnotation(id) {
61534
+ if (this.selectedId === id)
61535
+ this.selectedId = null;
61536
+ this.store.remove(id);
61537
+ }
61538
+ selectAnnotation(id) {
61539
+ this.selectedId = id;
61540
+ this.applySelection();
61541
+ }
61542
+ /** 颜色变更后重画对应 three 对象。 */
61543
+ refreshAnnotation(id) {
61544
+ const a = this.store.get(id);
61545
+ if (!a || !a.object3D)
61546
+ return;
61547
+ if (a.type === "contour") {
61548
+ setContourColor(a.object3D, a.color);
61549
+ }
61550
+ else {
61551
+ const m = a.object3D;
61552
+ m.material.color.set(a.color);
61553
+ }
61554
+ }
61555
+ exportJSON(modelName, opts) {
61556
+ return this.store.toJSON(modelName, this.o.mesh, opts);
61557
+ }
61558
+ // ---- 内部 ----
61559
+ applyCameraGating() {
61560
+ // 按住 Space 临时旋转优先;否则仅 navigate 模式开相机。
61561
+ this.o.controls.enabled = this.spaceHeld || this.mode === "navigate";
61562
+ }
61563
+ /** 据 store.list() 对账场景:补齐缺失对象、移除已删对象(不 dispose,留给撤销恢复)。 */
61564
+ reconcile() {
61565
+ var _a, _b;
61566
+ const present = new Set();
61567
+ for (const a of this.store.list())
61568
+ if (a.object3D)
61569
+ present.add(a.object3D);
61570
+ for (const o of this.managed) {
61571
+ if (!present.has(o))
61572
+ this.o.scene.remove(o);
61573
+ }
61574
+ for (const o of present) {
61575
+ if (!this.managed.has(o))
61576
+ this.o.scene.add(o);
61577
+ }
61578
+ this.managed = present;
61579
+ this.applySelection();
61580
+ (_b = (_a = this.o).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, this.store.list());
61581
+ }
61582
+ applySelection() {
61583
+ for (const a of this.store.list()) {
61584
+ if (!a.object3D)
61585
+ continue;
61586
+ const sel = a.id === this.selectedId;
61587
+ if (a.type === "contour") {
61588
+ const mat = a.object3D.material;
61589
+ mat.linewidth = sel ? LINE_W_SEL : LINE_W;
61590
+ }
61591
+ else {
61592
+ a.object3D.scale.setScalar(sel ? 1.6 : 1);
61593
+ }
61594
+ }
61595
+ }
61596
+ disposeObject(o) {
61597
+ var _a, _b, _c;
61598
+ const any = o;
61599
+ (_b = (_a = any.geometry) === null || _a === void 0 ? void 0 : _a.dispose) === null || _b === void 0 ? void 0 : _b.call(_a);
61600
+ const mat = any.material;
61601
+ if (Array.isArray(mat))
61602
+ mat.forEach((m) => m.dispose());
61603
+ else
61604
+ (_c = mat === null || mat === void 0 ? void 0 : mat.dispose) === null || _c === void 0 ? void 0 : _c.call(mat);
61605
+ }
61606
+ nextId() {
61607
+ return "a" + ++this.seq;
61608
+ }
61609
+ hit(e) {
61610
+ return raycastSurface(this.o.camera, this.o.container, this.o.mesh, e.clientX, e.clientY);
61611
+ }
61612
+ /** 事件目标是否落在标注容器内(排除面板/页面其它区域的点击)。 */
61613
+ insideContainer(e) {
61614
+ const t = e.target;
61615
+ return !!t && this.o.container.contains(t);
61616
+ }
61617
+ closeLastContour() {
61618
+ const last = this.lastFreehand;
61619
+ if (!last || last.closed || last.vertices.length < 3 || !last.object3D)
61620
+ return;
61621
+ // 用测地线沿表面把末点连回首点,避免直线弦从模型内部"抄近路"被遮挡。
61622
+ const tail = last.vertices[last.vertices.length - 1];
61623
+ const head = last.vertices[0];
61624
+ const closing = this.surfacePathBetween(tail, head);
61625
+ last.vertices = last.vertices.concat(closing);
61626
+ last.closed = true;
61627
+ updateContourLine(last.object3D, last.vertices, true, this.epsilon, this.o.mesh);
61628
+ }
61629
+ /** 沿网格表面求 a→b 的测地路径(local 顶点),去掉与 a 重合的首点。a/b 已是 local。 */
61630
+ surfacePathBetween(a, b) {
61631
+ const va = this.graph.nearestVertex(new Vector3(a.x, a.y, a.z));
61632
+ const vb = this.graph.nearestVertex(new Vector3(b.x, b.y, b.z));
61633
+ const path = this.graph.shortestPath(va, vb);
61634
+ return path.slice(1).map((i) => this.graph.vertexLocal(i));
61635
+ }
61636
+ /** 结束当前测地线:闭合成环并落定为一条 contour。 */
61637
+ finishGeodesic() {
61638
+ if (!this.activeGeo || !this.activeGeoLine)
61639
+ return;
61640
+ const closed = this.activeGeo.anchorCount > 2;
61641
+ const verts = this.activeGeo.buildVertices(closed);
61642
+ if (verts.length >= 2) {
61643
+ updateContourLine(this.activeGeoLine, verts, closed, this.epsilon, this.o.mesh);
61644
+ const ann = {
61645
+ id: this.nextId(),
61646
+ type: "contour",
61647
+ mode: "geodesic",
61648
+ label: `Contour ${this.seq}`,
61649
+ color: this.geodesicColor,
61650
+ closed,
61651
+ vertices: verts,
61652
+ object3D: this.activeGeoLine,
61653
+ };
61654
+ this.store.add(ann);
61655
+ }
61656
+ else {
61657
+ this.o.scene.remove(this.activeGeoLine);
61658
+ }
61659
+ this.activeGeo = undefined;
61660
+ this.activeGeoLine = undefined;
61661
+ }
61662
+ isTypingTarget(e) {
61663
+ const t = e.target;
61664
+ if (!t)
61665
+ return false;
61666
+ const tag = t.tagName;
61667
+ return tag === "INPUT" || tag === "TEXTAREA" || t.isContentEditable;
61668
+ }
61669
+ dispose() {
61670
+ window.removeEventListener("pointerdown", this.onPointerDown, true);
61671
+ window.removeEventListener("pointermove", this.onPointerMove, true);
61672
+ window.removeEventListener("pointerup", this.onPointerUp, true);
61673
+ window.removeEventListener("keydown", this.onKeyDown);
61674
+ window.removeEventListener("keyup", this.onKeyUp);
61675
+ window.removeEventListener("resize", this.onResize);
61676
+ }
61677
+ }
61678
+
58884
61679
  class copperScene extends baseScene {
58885
61680
  // rayster pick
58886
61681
  constructor(container, renderer, opt) {
@@ -58890,6 +61685,7 @@ class copperScene extends baseScene {
58890
61685
  this.mixer = null;
58891
61686
  this.playRate = 1.0;
58892
61687
  this.modelReady = false;
61688
+ this.surfaceAnnotators = [];
58893
61689
  if ((opt === null || opt === void 0 ? void 0 : opt.controls) === "trackball") {
58894
61690
  this.controls = new TrackballControls(this.camera, this.renderer.domElement);
58895
61691
  }
@@ -58965,53 +61761,45 @@ class copperScene extends baseScene {
58965
61761
  console.log("An error happened: ", error);
58966
61762
  });
58967
61763
  }
58968
- // loadOBJ(url: string, callback?: (mesh: THREE.Group) => void) {
58969
- // objLoader.load(
58970
- // url,
58971
- // (obj) => {
58972
- // obj.traverse((child) => {
58973
- // if ((child as THREE.Mesh).isMesh) {
58974
- // // (child as THREE.Mesh).material = new THREE.MeshStandardMaterial({
58975
- // // side: THREE.DoubleSide,
58976
- // // color: 0xffffff,
58977
- // // });
58978
- // // ((child as THREE.Mesh).material as THREE.MeshPhongMaterial).color =
58979
- // // new THREE.Color(0xffffff);
58980
- // }
58981
- // });
58982
- // const box = new THREE.Box3().setFromObject(obj);
58983
- // const size = box.getSize(new THREE.Vector3()).length();
58984
- // const center = box.getCenter(new THREE.Vector3());
58985
- // this.controls.maxDistance = size * 10;
58986
- // obj.position.x += obj.position.x - center.x;
58987
- // obj.position.y += obj.position.y - center.y;
58988
- // obj.position.z += obj.position.z - center.z;
58989
- // if (!this.cameraPositionFlag) {
58990
- // this.camera.position.copy(center);
58991
- // this.camera.position.x += size / 2.0;
58992
- // this.camera.position.y += size / 5.0;
58993
- // this.camera.position.z += size / 2.0;
58994
- // this.camera.lookAt(center);
58995
- // this.viewPoint = this.setViewPoint(
58996
- // this.camera as THREE.PerspectiveCamera,
58997
- // [center.x, center.y, center.z]
58998
- // );
58999
- // }
59000
- // this.scene.add(obj);
59001
- // !!callback && callback(obj);
59002
- // }, // called when loading is in progresses
59003
- // (xhr: any) => {
59004
- // console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
59005
- // },
59006
- // // called when loading has errors
59007
- // (error: any) => {
59008
- // console.log("An error happened");
59009
- // }
59010
- // );
59011
- // }
59012
61764
  loadVtk(url) {
59013
61765
  copperVtkLoader(url, this.scene, this.content);
59014
61766
  }
61767
+ /**
61768
+ * 在给定模型表面创建标注器(画 contour / 放点 / 导出坐标)。
61769
+ * target 可为单个 Mesh,或 Group/Object3D(自动选顶点数最多的 mesh)。
61770
+ * 复用本 scene 的 camera / container / controls;几何非索引时内部自动焊接索引化。
61771
+ */
61772
+ createSurfaceAnnotator(target, opts) {
61773
+ const mesh = this.pickAnnotatableMesh(target);
61774
+ if (!mesh)
61775
+ throw new Error("createSurfaceAnnotator: no mesh found in target");
61776
+ const annotator = new SurfaceAnnotator(Object.assign({ scene: this.scene, camera: this.camera, container: this.container, controls: this.controls, mesh }, (opts !== null && opts !== void 0 ? opts : {})));
61777
+ this.surfaceAnnotators.push(annotator);
61778
+ return annotator;
61779
+ }
61780
+ pickAnnotatableMesh(target) {
61781
+ if (target.isMesh)
61782
+ return target;
61783
+ let best = null;
61784
+ let bestCount = -1;
61785
+ target.traverse((c) => {
61786
+ var _a, _b;
61787
+ const m = c;
61788
+ if (m.isMesh) {
61789
+ const n = (_b = (_a = m.geometry.getAttribute("position")) === null || _a === void 0 ? void 0 : _a.count) !== null && _b !== void 0 ? _b : 0;
61790
+ if (n > bestCount) {
61791
+ bestCount = n;
61792
+ best = m;
61793
+ }
61794
+ }
61795
+ });
61796
+ return best;
61797
+ }
61798
+ /** 释放本 scene 创建的所有标注器(移除事件监听与标注对象)。 */
61799
+ disposeSurfaceAnnotators() {
61800
+ this.surfaceAnnotators.forEach((a) => a.dispose());
61801
+ this.surfaceAnnotators = [];
61802
+ }
59015
61803
  loadVtks(models) {
59016
61804
  let count = 0;
59017
61805
  let { vtkLoader } = copperMultipleVtk();
@@ -79866,7 +82654,7 @@ function evaluateElement(element, weights) {
79866
82654
  }
79867
82655
 
79868
82656
  // import * as kiwrious from "copper3d_plugin_heart_k";
79869
- const REVISION = "v3.5.0-beta";
82657
+ const REVISION = "v3.6.0-beta";
79870
82658
  console.log(`%cCopper3D Visualisation %cBeta:${REVISION}`, "padding: 3px;color:white; background:#023047", "padding: 3px;color:white; background:#f50a25");
79871
82659
 
79872
- export { AI_CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, CHANNEL_COLORS, CHANNEL_HEX_COLORS, CameraViewPoint, Copper3dTrackballControls, GaussianSmoother, MeshNodeTool, NrrdTools, REVISION, addBoxHelper, addLabelToScene, configKiwriousHeart, convert3DPostoScreenPos, convertScreenPosto3DPos, copperMScene, copperMSceneRenderer, copperRenderer, copperRendererOnDemond, copperScene, copperSceneOnDemond, createTexture2D_NRRD, fullScreenListenner, kiwrious, loading, removeGuiFolderChilden, rgbaToCss, rgbaToHex, setHDRFilePath, throttle };
82660
+ export { AI_CHANNEL_HEX_COLORS, AI_MASK_CHANNEL_COLORS, CHANNEL_COLORS, CHANNEL_HEX_COLORS, CameraViewPoint, Copper3dTrackballControls, GaussianSmoother, MeshNodeTool, NrrdTools, REVISION, SurfaceAnnotator, addBoxHelper, addLabelToScene, configKiwriousHeart, convert3DPostoScreenPos, convertScreenPosto3DPos, copperMScene, copperMSceneRenderer, copperRenderer, copperRendererOnDemond, copperScene, copperSceneOnDemond, createTexture2D_NRRD, fullScreenListenner, kiwrious, loading, removeGuiFolderChilden, rgbaToCss, rgbaToHex, setHDRFilePath, throttle };