1 line
16 KiB
Plaintext
1 line
16 KiB
Plaintext
|
|
{"version":3,"file":"LineSegments2.cjs","sources":["../../src/lines/LineSegments2.js"],"sourcesContent":["import {\n Box3,\n InstancedInterleavedBuffer,\n InterleavedBufferAttribute,\n Line3,\n MathUtils,\n Matrix4,\n Mesh,\n Sphere,\n Vector3,\n Vector4,\n} from 'three'\nimport { LineSegmentsGeometry } from '../lines/LineSegmentsGeometry'\nimport { LineMaterial } from '../lines/LineMaterial'\nimport { UV1 } from '../_polyfill/uv1'\n\nconst _viewport = /* @__PURE__ */ new Vector4()\n\nconst _start = /* @__PURE__ */ new Vector3()\nconst _end = /* @__PURE__ */ new Vector3()\n\nconst _start4 = /* @__PURE__ */ new Vector4()\nconst _end4 = /* @__PURE__ */ new Vector4()\n\nconst _ssOrigin = /* @__PURE__ */ new Vector4()\nconst _ssOrigin3 = /* @__PURE__ */ new Vector3()\nconst _mvMatrix = /* @__PURE__ */ new Matrix4()\nconst _line = /* @__PURE__ */ new Line3()\nconst _closestPoint = /* @__PURE__ */ new Vector3()\n\nconst _box = /* @__PURE__ */ new Box3()\nconst _sphere = /* @__PURE__ */ new Sphere()\nconst _clipToWorldVector = /* @__PURE__ */ new Vector4()\n\nlet _ray, _lineWidth\n\n// Returns the margin required to expand by in world space given the distance from the camera,\n// line width, resolution, and camera projection\nfunction getWorldSpaceHalfWidth(camera, distance, resolution) {\n // transform into clip space, adjust the x and y values by the pixel width offset, then\n // transform back into world space to get world offset. Note clip space is [-1, 1] so full\n // width does not need to be halved.\n _clipToWorldVector.set(0, 0, -distance, 1.0).applyMatrix4(camera.projectionMatrix)\n _clipToWorldVector.multiplyScalar(1.0 / _clipToWorldVector.w)\n _clipToWorldVector.x = _lineWidth / resolution.width\n _clipToWorldVector.y = _lineWidth / resolution.height\n _clipToWorldVector.applyMatrix4(camera.projectionMatrixInverse)\n _clipToWorldVector.multiplyScalar(1.0 / _clipToWorldVector.w)\n\n return Math.abs(Math.max(_clipToWorldVector.x, _clipToWorldVector.y))\n}\n\nfunction raycastWorldUnits(lineSegments, intersects) {\n const matrixWorld = lineSegments.matrixWorld\n const geometry = lineSegments.geometry\n const instanceStart = geometry.attributes.instanceStart\n const instanceEnd = geometry.attributes.instanceEnd\n const segmentCount = Math.min(geometry.instanceCount, instanceStart.count)\n\n for (let i = 0, l = segmentCount; i < l; i++) {\n _line.start.fromBufferAttribute(instanceStart, i)\n _line.end.fromBufferAttribute(instanceEnd, i)\n\n _line.applyMatrix4(matrixWorld)\n\n const pointOnLine = new Vector3()\n const point = new Vector3()\n\n _ray.distanceSqToSegment(_line.start, _line.end, point, pointOnLine)\n const isInside = point.distanceTo(pointOnLine) < _lineWidth * 0.5\n\n if (isInside) {\n intersects.push({\n point,\n pointOnLine,\n distance: _ray.origin.distanceTo(point),\n object: lineSegments,\n face: null,\n faceIndex: i,\n uv: null,\n [UV1]: null,\n })\n }\n }\n}\n\nfunction raycastScreenSpace(lineSegments, camera, intersects) {\n const projectionMatrix = camera.projectionMatrix\n const material = lineSegments.material\n const resolution = material.resolution\n const matrixWorld = lineSegments.matrixWorld\n\n const geometry = lineSegments.geometry\n const instanceStart = geometry.attributes.instanceStart\n const instanceEnd = geometry.attributes.instanceEnd\n const segmentCount = Math.min(geometry.instanceCount, instanceStart.count)\n\n const near = -camera.near\n\n //\n\n // pick a point 1 unit out along the ray to avoid the ray origin\n // sitting at the camera origin which will cause \"w\" to be 0 when\n // applying the projection matrix.\n _ray.at(1, _ssOrigin)\n\n // ndc space [ - 1.0, 1.0 ]\n _ssOrigin.w = 1\n _ssOrigin.applyMatrix4(camera.matrixWorldInverse)\n _ssOrigin.applyMatrix4(projectionMatrix)\n _ssOrigin.multiplyScalar(1 / _ssOrigin.w)\n\n // screen space\n _ssOrigin.x *= resolution.x / 2\n _ssOrigin.y *= resolution.y / 2\n _ssOrigin.z = 0\n\n _ssOrigi
|