summit/frontend/node_modules/three-stdlib/misc/ConvexObjectBreaker.cjs.map

1 line
23 KiB
Plaintext
Raw Normal View History

2025-12-08 16:31:30 +00:00
{"version":3,"file":"ConvexObjectBreaker.cjs","sources":["../../src/misc/ConvexObjectBreaker.js"],"sourcesContent":["import { Line3, Mesh, Plane, Vector3 } from 'three'\nimport { ConvexGeometry } from '../geometries/ConvexGeometry'\n\n/**\n * @fileoverview This class can be used to subdivide a convex Geometry object into pieces.\n *\n * Usage:\n *\n * Use the function prepareBreakableObject to prepare a Mesh object to be broken.\n *\n * Then, call the various functions to subdivide the object (subdivideByImpact, cutByPlane)\n *\n * Sub-objects that are product of subdivision don't need prepareBreakableObject to be called on them.\n *\n * Requisites for the object:\n *\n * - Mesh object must have a buffer geometry and a material\n *\n * - Vertex normals must be planar (not smoothed)\n *\n * - The geometry must be convex (this is not checked in the library). You can create convex\n * geometries with ConvexGeometry. The BoxGeometry, SphereGeometry and other convex primitives\n * can also be used.\n *\n * Note: This lib adds member variables to object's userData member (see prepareBreakableObject function)\n * Use with caution and read the code when using with other libs.\n *\n * @param {double} minSizeForBreak Min size a debris can have to break.\n * @param {double} smallDelta Max distance to consider that a point belongs to a plane.\n *\n */\n\nconst _v1 = /* @__PURE__ */ new Vector3()\n\nconst ConvexObjectBreaker = /* @__PURE__ */ (() => {\n class ConvexObjectBreaker {\n constructor(minSizeForBreak = 1.4, smallDelta = 0.0001) {\n this.minSizeForBreak = minSizeForBreak\n this.smallDelta = smallDelta\n\n this.tempLine1 = new Line3()\n this.tempPlane1 = new Plane()\n this.tempPlane2 = new Plane()\n this.tempPlane_Cut = new Plane()\n this.tempCM1 = new Vector3()\n this.tempCM2 = new Vector3()\n this.tempVector3 = new Vector3()\n this.tempVector3_2 = new Vector3()\n this.tempVector3_3 = new Vector3()\n this.tempVector3_P0 = new Vector3()\n this.tempVector3_P1 = new Vector3()\n this.tempVector3_P2 = new Vector3()\n this.tempVector3_N0 = new Vector3()\n this.tempVector3_N1 = new Vector3()\n this.tempVector3_AB = new Vector3()\n this.tempVector3_CB = new Vector3()\n this.tempResultObjects = { object1: null, object2: null }\n\n this.segments = []\n const n = 30 * 30\n for (let i = 0; i < n; i++) this.segments[i] = false\n }\n\n prepareBreakableObject(object, mass, velocity, angularVelocity, breakable) {\n // object is a Object3d (normally a Mesh), must have a buffer geometry, and it must be convex.\n // Its material property is propagated to its children (sub-pieces)\n // mass must be > 0\n\n const userData = object.userData\n userData.mass = mass\n userData.velocity = velocity.clone()\n userData.angularVelocity = angularVelocity.clone()\n userData.breakable = breakable\n }\n\n /*\n * @param {int} maxRadialIterations Iterations for radial cuts.\n * @param {int} maxRandomIterations Max random iterations for not-radial cuts\n *\n * Returns the array of pieces\n */\n subdivideByImpact(object, pointOfImpact, normal, maxRadialIterations, maxRandomIterations) {\n const debris = []\n\n const tempPlane1 = this.tempPlane1\n const tempPlane2 = this.tempPlane2\n\n this.tempVector3.addVectors(pointOfImpact, normal)\n tempPlane1.setFromCoplanarPoints(pointOfImpact, object.position, this.tempVector3)\n\n const maxTotalIterations = maxRandomIterations + maxRadialIterations\n\n const scope = this\n\n function subdivideRadial(subObject, startAngle, endAngle, numIterations) {\n if (Math.random() < numIterations * 0.05 || numIterations > maxTotalIterations) {\n debris.push(subObject)\n\n return\n }\n\n let angle = Math.PI\n\n if (numIterations === 0) {\n tempPlane2.normal.copy(tempPlane1.normal)\n tempPlane2.constant = tempPlane1.constant\n } else {