import{Y as V,m as w,bn as q,aa as I,ai as N,ah as R,bo as B,bk as k,l as F,a3 as G}from"./three.module-LeyNtSoi.js";import{LineSegmentsGeometry as H}from"./LineSegmentsGeometry-COlkVDC4.js";import{LineMaterial as Y}from"./LineMaterial-DxUXYPiz.js";const L=new B,j=new w,C=new w,i=new B,r=new B,x=new B,T=new w,W=new F,s=new k,D=new w,z=new R,_=new N,y=new B;let h,b;function E(u,e,n){return y.set(0,0,-e,1).applyMatrix4(u.projectionMatrix),y.multiplyScalar(1/y.w),y.x=b/n.width,y.y=b/n.height,y.applyMatrix4(u.projectionMatrixInverse),y.multiplyScalar(1/y.w),Math.abs(Math.max(y.x,y.y))}function J(u,e){const n=u.matrixWorld,a=u.geometry,o=a.attributes.instanceStart,c=a.attributes.instanceEnd,l=Math.min(a.instanceCount,o.count);for(let t=0,p=l;t<p;t++){s.start.fromBufferAttribute(o,t),s.end.fromBufferAttribute(c,t),s.applyMatrix4(n);const f=new w,m=new w;h.distanceSqToSegment(s.start,s.end,m,f),m.distanceTo(f)<b*.5&&e.push({point:m,pointOnLine:f,distance:h.origin.distanceTo(m),object:u,face:null,faceIndex:t,uv:null,uv1:null})}}function K(u,e,n){const a=e.projectionMatrix,c=u.material.resolution,l=u.matrixWorld,t=u.geometry,p=t.attributes.instanceStart,f=t.attributes.instanceEnd,m=Math.min(t.instanceCount,p.count),d=-e.near;h.at(1,x),x.w=1,x.applyMatrix4(e.matrixWorldInverse),x.applyMatrix4(a),x.multiplyScalar(1/x.w),x.x*=c.x/2,x.y*=c.y/2,x.z=0,T.copy(x),W.multiplyMatrices(e.matrixWorldInverse,l);for(let M=0,P=m;M<P;M++){if(i.fromBufferAttribute(p,M),r.fromBufferAttribute(f,M),i.w=1,r.w=1,i.applyMatrix4(W),r.applyMatrix4(W),i.z>d&&r.z>d)continue;if(i.z>d){const S=i.z-r.z,g=(i.z-d)/S;i.lerp(r,g)}else if(r.z>d){const S=r.z-i.z,g=(r.z-d)/S;r.lerp(i,g)}i.applyMatrix4(a),r.applyMatrix4(a),i.multiplyScalar(1/i.w),r.multiplyScalar(1/r.w),i.x*=c.x/2,i.y*=c.y/2,r.x*=c.x/2,r.y*=c.y/2,s.start.copy(i),s.start.z=0,s.end.copy(r),s.end.z=0;const v=s.closestPointToPointParameter(T,!0);s.at(v,D);const A=G.lerp(i.z,r.z,v),O=A>=-1&&A<=1,U=T.distanceTo(D)<b*.5;if(O&&U){s.start.fromBufferAttribute(p,M),s.end.fromBufferAttribute(f,M),s.start.applyMatrix4(l),s.end.applyMatrix4(l);const S=new w,g=new w;h.distanceSqToSegment(s.start,s.end,g,S),n.push({point:g,pointOnLine:S,distance:h.origin.distanceTo(g),object:u,face:null,faceIndex:M,uv:null,uv1:null})}}}class tt extends V{constructor(e=new H,n=new Y({color:Math.random()*16777215})){super(e,n),this.isLineSegments2=!0,this.type="LineSegments2"}computeLineDistances(){const e=this.geometry,n=e.attributes.instanceStart,a=e.attributes.instanceEnd,o=new Float32Array(2*n.count);for(let l=0,t=0,p=n.count;l<p;l++,t+=2)j.fromBufferAttribute(n,l),C.fromBufferAttribute(a,l),o[t]=t===0?0:o[t-1],o[t+1]=o[t]+j.distanceTo(C);const c=new q(o,2,1);return e.setAttribute("instanceDistanceStart",new I(c,1,0)),e.setAttribute("instanceDistanceEnd",new I(c,1,1)),this}raycast(e,n){const a=this.material.worldUnits,o=e.camera;o===null&&!a&&console.error('LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.');const c=e.params.Line2!==void 0&&e.params.Line2.threshold||0;h=e.ray;const l=this.matrixWorld,t=this.geometry,p=this.material;b=p.linewidth+c,t.boundingSphere===null&&t.computeBoundingSphere(),_.copy(t.boundingSphere).applyMatrix4(l);let f;if(a)f=b*.5;else{const d=Math.max(o.near,_.distanceToPoint(h.origin));f=E(o,d,p.resolution)}if(_.radius+=f,h.intersectsSphere(_)===!1)return;t.boundingBox===null&&t.computeBoundingBox(),z.copy(t.boundingBox).applyMatrix4(l);let m;if(a)m=b*.5;else{const d=Math.max(o.near,z.distanceToPoint(h.origin));m=E(o,d,p.resolution)}z.expandByScalar(m),h.intersectsBox(z)!==!1&&(a?J(this,n):K(this,o,n))}onBeforeRender(e){const n=this.material.uniforms;n&&n.resolution&&(e.getViewport(L),this.material.uniforms.resolution.value.set(L.z,L.w))}}export{tt as LineSegments2};
//# sourceMappingURL=LineSegments2-BcNLTCmD.js.map
