summit/frontend/node_modules/three-stdlib/math/OBB.cjs.map

1 line
19 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"OBB.cjs","sources":["../../src/math/OBB.js"],"sourcesContent":["import { Box3, MathUtils, Matrix4, Matrix3, Ray, Vector3 } from 'three'\n\n// module scope helper variables\n\nconst a = {\n c: null, // center\n u: [/* @__PURE__ */ new Vector3(), /* @__PURE__ */ new Vector3(), /* @__PURE__ */ new Vector3()], // basis vectors\n e: [], // half width\n}\n\nconst b = {\n c: null, // center\n u: [/* @__PURE__ */ new Vector3(), /* @__PURE__ */ new Vector3(), /* @__PURE__ */ new Vector3()], // basis vectors\n e: [], // half width\n}\n\nconst R = [[], [], []]\nconst AbsR = [[], [], []]\nconst t = []\n\nconst xAxis = /* @__PURE__ */ new Vector3()\nconst yAxis = /* @__PURE__ */ new Vector3()\nconst zAxis = /* @__PURE__ */ new Vector3()\nconst v1 = /* @__PURE__ */ new Vector3()\nconst size = /* @__PURE__ */ new Vector3()\nconst closestPoint = /* @__PURE__ */ new Vector3()\nconst rotationMatrix = /* @__PURE__ */ new Matrix3()\nconst aabb = /* @__PURE__ */ new Box3()\nconst matrix = /* @__PURE__ */ new Matrix4()\nconst inverse = /* @__PURE__ */ new Matrix4()\nconst localRay = /* @__PURE__ */ new Ray()\n\n// OBB\n\nclass OBB {\n constructor(center = new Vector3(), halfSize = new Vector3(), rotation = new Matrix3()) {\n this.center = center\n this.halfSize = halfSize\n this.rotation = rotation\n }\n\n set(center, halfSize, rotation) {\n this.center = center\n this.halfSize = halfSize\n this.rotation = rotation\n\n return this\n }\n\n copy(obb) {\n this.center.copy(obb.center)\n this.halfSize.copy(obb.halfSize)\n this.rotation.copy(obb.rotation)\n\n return this\n }\n\n clone() {\n return new this.constructor().copy(this)\n }\n\n getSize(result) {\n return result.copy(this.halfSize).multiplyScalar(2)\n }\n\n /**\n * Reference: Closest Point on OBB to Point in Real-Time Collision Detection\n * by Christer Ericson (chapter 5.1.4)\n */\n clampPoint(point, result) {\n const halfSize = this.halfSize\n\n v1.subVectors(point, this.center)\n this.rotation.extractBasis(xAxis, yAxis, zAxis)\n\n // start at the center position of the OBB\n\n result.copy(this.center)\n\n // project the target onto the OBB axes and walk towards that point\n\n const x = MathUtils.clamp(v1.dot(xAxis), -halfSize.x, halfSize.x)\n result.add(xAxis.multiplyScalar(x))\n\n const y = MathUtils.clamp(v1.dot(yAxis), -halfSize.y, halfSize.y)\n result.add(yAxis.multiplyScalar(y))\n\n const z = MathUtils.clamp(v1.dot(zAxis), -halfSize.z, halfSize.z)\n result.add(zAxis.multiplyScalar(z))\n\n return result\n }\n\n containsPoint(point) {\n v1.subVectors(point, this.center)\n this.rotation.extractBasis(xAxis, yAxis, zAxis)\n\n // project v1 onto each axis and check if these points lie inside the OBB\n\n return (\n Math.abs(v1.dot(xAxis)) <= this.halfSize.x &&\n Math.abs(v1.dot(yAxis)) <= this.halfSize.y &&\n Math.abs(v1.dot(zAxis)) <= this.halfSize.z\n )\n }\n\n intersectsBox3(box3) {\n return this.intersectsOBB(obb.fromBox3(box3))\n }\n\n intersectsSphere(sphere) {\n // find the point on the OBB closest to the sphere center\n\n this.clampPoint(sphere.center, closestPoint)\n\n // if that point is inside the sphere, the OBB and sphere intersect\n\n return closestPoint.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius\n }\n\n /**\n * Reference: OBB-OBB Intersection in Real-Time Collision Detection\n * by Christer Ericson (chapter 4.4.1)\n *\n */\n intersectsOBB(obb, epsilon = Number.EPSILON) {\n // prepare data structures (the code uses the same nomenclature like the reference)\n\n a.c = this.center\n a.e[0] = this.halfSize.x\n a.e[1] = this.halfSize.y\n a.e[2] = this.halfSize.z\n this.rotation.extractBasis(a.u[0], a.u[1], a.u[2])\n\n b.c = obb.center\n b.e[0] = obb.halfSize.x\n b.e[1] = obb.halfSize.y\n b.e[2] = obb.halfSize.z\n obb.rotation.extractBasis(b.u[0], b.u[1], b.u[2])\n\n // compute rotation matrix expressing b in a's coordinate frame\n\n fo