@needle-tools/three-mesh-effects 0.2.3 → 0.3.2
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.
- package/CHANGELOG.md +34 -8
- package/README.md +86 -3
- package/SKILL.md +14 -4
- package/build/box-impostor-runtime.js +1423 -0
- package/build/box-impostor-runtime.js.map +7 -0
- package/build/deformation-runtime.js +30 -19
- package/build/deformation-runtime.js.map +3 -3
- package/build/hull-effects.js +60 -28
- package/build/hull-effects.js.map +3 -3
- package/build/impostor-runtime.js +264 -133
- package/build/impostor-runtime.js.map +4 -4
- package/build/index.js +8 -0
- package/build/index.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-display-settings.js +50 -0
- package/build/internal/box-impostor/box-impostor-display-settings.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-display.js +1102 -0
- package/build/internal/box-impostor/box-impostor-display.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-face-axes.js +15 -0
- package/build/internal/box-impostor/box-impostor-face-axes.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-faces.js +125 -0
- package/build/internal/box-impostor/box-impostor-faces.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-geometry.js +230 -0
- package/build/internal/box-impostor/box-impostor-geometry.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-material.js +1056 -0
- package/build/internal/box-impostor/box-impostor-material.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-metadata.js +108 -0
- package/build/internal/box-impostor/box-impostor-metadata.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-projection.js +276 -0
- package/build/internal/box-impostor/box-impostor-projection.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-runtime.js +1369 -0
- package/build/internal/box-impostor/box-impostor-runtime.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-surface-search.js +21 -0
- package/build/internal/box-impostor/box-impostor-surface-search.js.map +7 -0
- package/build/internal/deformation/cloth-surface.js +23 -17
- package/build/internal/deformation/cloth-surface.js.map +3 -3
- package/build/internal/deformation/pin-cloth.js +7 -2
- package/build/internal/deformation/pin-cloth.js.map +2 -2
- package/build/internal/deformation/rig-runtime.js +30 -19
- package/build/internal/deformation/rig-runtime.js.map +3 -3
- package/build/internal/impostor/impostor-node-material.js +264 -133
- package/build/internal/impostor/impostor-node-material.js.map +4 -4
- package/build/internal/pixel-impostor/pixel-impostor-display.js +84 -38
- package/build/internal/pixel-impostor/pixel-impostor-display.js.map +4 -4
- package/build/internal/rendering/captured-surface-depth.js +35 -0
- package/build/internal/rendering/captured-surface-depth.js.map +7 -0
- package/build/internal/rendering/captured-surface-material.js +28 -0
- package/build/internal/rendering/captured-surface-material.js.map +7 -0
- package/build/internal/rendering/hull-effect-runtime.js +59 -27
- package/build/internal/rendering/hull-effect-runtime.js.map +3 -3
- package/build/internal/rendering/renderer-support.js +31 -0
- package/build/internal/rendering/renderer-support.js.map +7 -0
- package/build/internal/rendering/wireframe.js +41 -9
- package/build/internal/rendering/wireframe.js.map +2 -2
- package/build/internal/rendering/wrap-preview.js +59 -27
- package/build/internal/rendering/wrap-preview.js.map +3 -3
- package/build/pixel-impostor-runtime.js +84 -38
- package/build/pixel-impostor-runtime.js.map +4 -4
- package/build/types/box-impostor/box-impostor-display-settings.d.ts +30 -0
- package/build/types/box-impostor/box-impostor-display-settings.js +1 -0
- package/build/types/box-impostor/box-impostor-display.d.ts +13 -0
- package/build/types/box-impostor/box-impostor-display.js +1 -0
- package/build/types/box-impostor/box-impostor-face-axes.d.ts +5 -0
- package/build/types/box-impostor/box-impostor-face-axes.js +1 -0
- package/build/types/box-impostor/box-impostor-faces.d.ts +11 -0
- package/build/types/box-impostor/box-impostor-faces.js +1 -0
- package/build/types/box-impostor/box-impostor-geometry.d.ts +5 -0
- package/build/types/box-impostor/box-impostor-geometry.js +1 -0
- package/build/types/box-impostor/box-impostor-material.d.ts +14 -0
- package/build/types/box-impostor/box-impostor-material.js +1 -0
- package/build/types/box-impostor/box-impostor-metadata.d.ts +31 -0
- package/build/types/box-impostor/box-impostor-metadata.js +1 -0
- package/build/types/box-impostor/box-impostor-projection.d.ts +19 -0
- package/build/types/box-impostor/box-impostor-projection.js +1 -0
- package/build/types/box-impostor/box-impostor-runtime.d.ts +19 -0
- package/build/types/box-impostor/box-impostor-runtime.js +1 -0
- package/build/types/box-impostor/box-impostor-surface-search.d.ts +13 -0
- package/build/types/box-impostor/box-impostor-surface-search.js +1 -0
- package/build/types/deformation/cloth-surface.d.ts +1 -0
- package/build/types/deformation/pin-cloth.d.ts +1 -0
- package/build/types/impostor/impostor-node-material.d.ts +2 -15
- package/build/types/public/box-impostor-runtime.d.ts +6 -0
- package/build/types/public/box-impostor-runtime.js +1 -0
- package/build/types/public/hull-effects.d.ts +1 -0
- package/build/types/public/index.d.ts +1 -1
- package/build/types/rendering/captured-surface-depth.d.ts +5 -0
- package/build/types/rendering/captured-surface-depth.js +1 -0
- package/build/types/rendering/captured-surface-material.d.ts +8 -0
- package/build/types/rendering/captured-surface-material.js +1 -0
- package/build/types/rendering/renderer-support.d.ts +27 -0
- package/build/types/rendering/renderer-support.js +1 -0
- package/build/types/rendering/wireframe.d.ts +2 -2
- package/package.json +29 -8
- package/src/box-impostor/box-impostor-display-settings.js +54 -0
- package/src/box-impostor/box-impostor-display.js +50 -0
- package/src/box-impostor/box-impostor-face-axes.js +11 -0
- package/src/box-impostor/box-impostor-faces.js +118 -0
- package/src/box-impostor/box-impostor-geometry.js +140 -0
- package/src/box-impostor/box-impostor-material.js +771 -0
- package/src/box-impostor/box-impostor-metadata.js +122 -0
- package/src/box-impostor/box-impostor-projection.js +276 -0
- package/src/box-impostor/box-impostor-runtime.js +124 -0
- package/src/box-impostor/box-impostor-surface-search.js +11 -0
- package/src/deformation/cloth-surface.ts +28 -17
- package/src/deformation/pin-cloth.ts +9 -3
- package/src/impostor/impostor-node-material.js +188 -157
- package/src/pixel-impostor/pixel-impostor-display.js +5 -13
- package/src/public/box-impostor-runtime.js +14 -0
- package/src/public/hull-effects.js +1 -0
- package/src/public/index.js +10 -1
- package/src/rendering/captured-surface-depth.js +55 -0
- package/src/rendering/captured-surface-material.js +27 -0
- package/src/rendering/renderer-support.js +50 -0
- package/src/rendering/wireframe.js +51 -13
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/deformation/pin-cloth.ts", "../../../src/deformation/wind.ts", "../../../src/deformation/motion-settings.ts"],
|
|
4
|
-
"sourcesContent": ["import { Quaternion, Vector3 } from 'three';\nimport type { PinRecord, Point } from './pin-types.js';\nimport type { PinParents, HierarchyEdge } from './pin-types.js';\nimport { windAcceleration } from './wind.js';\nimport { DEFAULT_MOTION } from './motion-settings.js';\n\nexport type ClothLink = { a: string; b: string; length: number };\nexport type ClothCollider = { position: Point; radius: number; driver?: string };\n\n/** Connect authored cloth controls along the occupied-volume geodesic, not\n * across the shortest line through empty space. The tree is a coarse fabric\n * constraint network; the ordinary skin remains its portable GLB fallback. */\nexport function clothLinks(pins: readonly PinRecord[], parents: PinParents, edges: readonly HierarchyEdge[] = [], components?: ReadonlyMap<string, number>): ClothLink[] {\n const cloth = pins.filter(p => p.cloth && !p.guide), byId = new Map(pins.map(p => [p.id, p]));\n const result: ClothLink[] = [], seen = new Set<string>();\n const add = (a: string, b: string) => {\n if (a === b || !byId.has(a) || !byId.has(b)) return;\n const key = [a, b].sort().join('\\0'); if (seen.has(key)) return;\n seen.add(key); result.push({ a, b, length: new Vector3().fromArray(byId.get(a)!.rest).distanceTo(new Vector3().fromArray(byId.get(b)!.rest)) });\n };\n for (const pin of cloth) {\n let parent = parents.get(pin.id);\n const visited = new Set<string>();\n while (parent && byId.get(parent)?.guide && !visited.has(parent)) { visited.add(parent); parent = parents.get(parent); }\n if (parent) add(pin.id, parent);\n }\n // A topology hierarchy may root a sheet at one of its free corners. Cloth\n // still needs body attachments there; otherwise the entire sheet falls as\n // one unconstrained pair or chain despite nearby non-cloth controls.\n for (const pin of cloth) {\n const parent = byId.get(parents.get(pin.id) ?? '');\n if (parent && !parent.cloth && !parent.guide) continue;\n const anchors = edges.filter(edge => (edge.from === pin.id || edge.to === pin.id) &&\n !byId.get(edge.from === pin.id ? edge.to : edge.from)?.cloth &&\n !byId.get(edge.from === pin.id ? edge.to : edge.from)?.guide &&\n Number.isFinite(edge.geodesic ?? edge.cost));\n const same = anchors.filter(edge => !components || components.get(pin.id) === components.get(edge.from === pin.id ? edge.to : edge.from));\n const best = (same.length ? same : anchors).sort((a, b) => (a.geodesic ?? a.cost) - (b.geodesic ?? b.cost))[0];\n if (best) add(pin.id, best.from === pin.id ? best.to : best.from);\n }\n const candidates = edges.filter(e => cloth.some(p => p.id === e.from) && cloth.some(p => p.id === e.to) && Number.isFinite(e.geodesic ?? e.cost)\n && (!components || components.get(e.from) === components.get(e.to)))\n .sort((a, b) => (a.geodesic ?? a.cost) - (b.geodesic ?? b.cost));\n const root = new Map(cloth.map(p => [p.id, p.id]));\n const find = (id: string): string => { const parent = root.get(id)!; if (parent === id) return id; const top = find(parent); root.set(id, top); return top; };\n for (const edge of candidates) {\n const a = find(edge.from), b = find(edge.to); if (a === b) continue;\n root.set(a, b); add(edge.from, edge.to);\n }\n return result;\n}\n\n/** Small, fixed-step Verlet graph. The editor passes deformed voxel centers;\n * the GLB loader passes the same collider proxy driven by its joint graph. */\nexport class PinCloth {\n private particles = new Map<string, { position: Vector3; previous: Vector3 }>();\n private layout = '';\n private windTime = 0;\n reset() { this.particles.clear(); this.layout = ''; this.windTime = 0; }\n step(pins: readonly PinRecord[], parents: PinParents, seconds: number, links: readonly ClothLink[], colliders: readonly ClothCollider[] = [], windStrength = 0): { pins: readonly PinRecord[]; active: boolean } {\n const cloth = pins.filter(p => p.cloth && !p.guide);\n if (!cloth.length) { this.reset(); return { pins, active: false }; }\n const layout = JSON.stringify([cloth.map(p => [p.id, p.rest]), links]);\n if (layout !== this.layout) { this.reset(); this.layout = layout; }\n const byId = new Map(pins.map(p => [p.id, p]));\n for (const pin of cloth) if (!this.particles.has(pin.id)) {\n const position = new Vector3().fromArray(pin.pose.position);\n this.particles.set(pin.id, { position, previous: position.clone() });\n }\n const dt = Math.min(Math.max(seconds, 0), .05), steps = Math.max(1, Math.ceil(dt / (1 / 60))), h = dt / steps;\n const scale = Math.max(1e-4, ...links.map(link => link.length));\n // A sampled voxel shell can contain thousands of spheres. Bin it once\n // per frame, then refresh each particle's nearby set after integration so\n // a fast-moving cloth point cannot retain last frame's collision region.\n let maxRadius = 0;\n for (const collider of colliders) maxRadius = Math.max(maxRadius, collider.radius);\n const cell = Math.max(1e-4, scale * 2 + maxRadius);\n const spatial = cloth.length > 4 && colliders.length > 128;\n const bins = new Map<string, ClothCollider[]>();\n const key = (x: number, y: number, z: number) => `${x},${y},${z}`;\n if (spatial) for (const collider of colliders) {\n const p = collider.position, id = key(Math.floor(p[0] / cell), Math.floor(p[1] / cell), Math.floor(p[2] / cell));\n const bin = bins.get(id) ?? []; bin.push(collider); bins.set(id, bin);\n }\n const candidates = (position: Vector3) => {\n const found: ClothCollider[] = [];\n const search = (collider: ClothCollider) => {\n const p = collider.position, dx = position.x - p[0], dy = position.y - p[1], dz = position.z - p[2], reach = collider.radius + scale * 2;\n if (dx * dx + dy * dy + dz * dz < reach * reach) found.push(collider);\n };\n if (spatial) {\n const x = Math.floor(position.x / cell), y = Math.floor(position.y / cell), z = Math.floor(position.z / cell);\n for (let dz = -1; dz <= 1; dz++) for (let dy = -1; dy <= 1; dy++) for (let dx = -1; dx <= 1; dx++)\n for (const collider of bins.get(key(x + dx, y + dy, z + dz)) ?? []) search(collider);\n } else for (const collider of colliders) search(collider);\n return found;\n };\n for (let substep = 0; substep < steps && dt > 0; substep++) {\n this.windTime += h;\n for (const pin of cloth) {\n const particle = this.particles.get(pin.id)!;\n const motion = pin.motion ?? DEFAULT_MOTION;\n const velocity = particle.position.clone().sub(particle.previous).multiplyScalar(Math.exp(-motion.damping * 3 * h));\n particle.previous.copy(particle.position);\n particle.position.add(velocity).y -= 2.5 * scale * h * h;\n if (windStrength > 0 && motion.strength > 0) particle.position.addScaledVector(windAcceleration(this.windTime, windStrength, scale, particle.position.toArray()), motion.strength * h * h);\n // Pins are sparse controls, not free particles. A soft return to their\n // authored positions keeps broad sheets from drifting indefinitely.\n particle.position.lerp(new Vector3().fromArray(pin.pose.position), 1 - Math.exp(-2 * Math.PI * motion.frequency * h));\n }\n const nearby = new Map(cloth.map(pin => [pin.id, candidates(this.particles.get(pin.id)!.position)]));\n for (let iteration = 0; iteration < 6; iteration++) {\n for (const link of links) {\n const a = this.particles.get(link.a), b = this.particles.get(link.b);\n const pa = a?.position ?? new Vector3().fromArray(byId.get(link.a)?.pose.position ?? [0, 0, 0]);\n const pb = b?.position ?? new Vector3().fromArray(byId.get(link.b)?.pose.position ?? [0, 0, 0]);\n const delta = pa.clone().sub(pb), distance = delta.length(); if (distance < 1e-8) continue;\n const correction = delta.multiplyScalar((distance - link.length) / distance);\n if (a && b) { a.position.addScaledVector(correction, -.5); b.position.addScaledVector(correction, .5); }\n else if (a) a.position.sub(correction); else if (b) b.position.add(correction);\n }\n for (const [id, particle] of this.particles) for (const collider of nearby.get(id) ?? []) {\n const center = collider.position, dx = particle.position.x - center[0], dy = particle.position.y - center[1], dz = particle.position.z - center[2];\n const squared = dx * dx + dy * dy + dz * dz;\n if (squared >= collider.radius * collider.radius) continue;\n if (squared < 1e-16) particle.position.set(center[0], center[1] + collider.radius, center[2]);\n else {\n const factor = collider.radius / Math.sqrt(squared);\n particle.position.set(center[0] + dx * factor, center[1] + dy * factor, center[2] + dz * factor);\n }\n }\n }\n }\n let active = false;\n const result = pins.map(pin => {\n const particle = this.particles.get(pin.id); if (!particle) return pin;\n const target = new Vector3().fromArray(pin.pose.position), offset = particle.position.clone().sub(target);\n const velocity = particle.position.clone().sub(particle.previous);\n if (offset.lengthSq() > scale * scale * 1e-10 || velocity.lengthSq() > scale * scale * 1e-10) active = true;\n const parent = byId.get(parents.get(pin.id) ?? '');\n const rotation = parent ? new Quaternion().setFromUnitVectors(\n target.clone().sub(new Vector3().fromArray(parent.pose.position)).normalize(),\n particle.position.clone().sub(new Vector3().fromArray(parent.pose.position)).normalize()) : new Quaternion();\n return { ...pin, pose: { ...pin.pose, position: particle.position.toArray() as Point,\n rotation: rotation.multiply(new Quaternion().fromArray(pin.pose.rotation)).normalize().toArray() as [number, number, number, number] } };\n });\n return { pins: active ? result : pins, active };\n }\n}\n", "import { Vector3 } from 'three';\n\nexport const MAX_WIND_STRENGTH = 4;\n\n/** A single weather control drives pin motion and surface pressure. Sparse pin\n * loads stay bounded; fabric pressure has room to grow through a storm. */\nexport function windProfile(strength: number) {\n const level = Math.max(0, Math.min(MAX_WIND_STRENGTH, strength));\n const label = level === 0 ? 'Off' : level < .75 ? 'Breeze' : level < 1.5 ? 'Windy' : level < 2.5 ? 'Strong wind' : level < 3.3 ? 'Gale' : 'Storm';\n return {\n label,\n load: 30 * level * level / (.8 + level * level),\n surfaceLoad: 4 * level * level,\n gust: .14 + .12 * level,\n crosswind: .05 + .07 * level,\n gustRate: .42 + .12 * level,\n };\n}\n\n/** Deterministic scene-local prevailing wind with slow gusts and spatially\n * varying eddies. Force is an acceleration scaled to the model's size, so a\n * tiny prop and a large character respond comparably at the same setting. */\nexport function windAcceleration(seconds: number, strength: number, scale: number, position: readonly number[]) {\n if (strength <= 0) return new Vector3();\n const size = Math.max(1e-4, scale);\n const profile = windProfile(strength);\n // Advect the gust bands along +X. Nearby controls see related wind, while\n // their phase delay keeps a large sheet or branch hierarchy from moving as\n // one perfectly synchronized rigid object.\n const along = position[0] / size, lateral = (position[1] * .67 + position[2] * .33) / size;\n const slow = seconds * profile.gustRate - along * .55;\n const fast = seconds * (profile.gustRate * 2.7) - along * 1.4 + lateral * .4;\n const gust = Math.max(.2, 1 + profile.gust * (.7 * Math.sin(slow) + .3 * Math.sin(fast + 1.3)));\n const cross = profile.crosswind * (.65 * Math.sin(fast + lateral) + .35 * Math.sin(slow * .73 - lateral * .6));\n return new Vector3(1, cross * .35, cross).normalize().multiplyScalar(profile.load * size * gust);\n}\n", "export type MotionSettings = { reach: number; frequency: number; damping: number; massInfluence:number; strength:number };\nexport const DEFAULT_MOTION: Readonly<MotionSettings> = { reach: .5, frequency: 14 / (2*Math.PI), damping: .28, massInfluence:1,strength:1 };\nexport function validateMotionSettings(value: MotionSettings) {\n if (!value || !Number.isFinite(value.reach) || value.reach < 0 || value.reach > 1\n || !Number.isFinite(value.frequency) || value.frequency < .25 || value.frequency > 8\n || !Number.isFinite(value.damping) || value.damping < .05 || value.damping > 1\n || !Number.isFinite(value.massInfluence) || value.massInfluence<0 || value.massInfluence>2\n || !Number.isFinite(value.strength) || value.strength<0 || value.strength>3) throw new Error('Invalid motion settings.');\n}\n"],
|
|
5
|
-
"mappings": ";;;AAAA,SAAS,YAAY,WAAAA,gBAAe;;;ACApC,SAAS,eAAe;AAEjB,IAAM,oBAAoB;AAI1B,SAAS,YAAY,UAAkB;AAC5C,QAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,mBAAmB,QAAQ,CAAC;AAC/D,QAAM,QAAQ,UAAU,IAAI,QAAQ,QAAQ,OAAM,WAAW,QAAQ,MAAM,UAAU,QAAQ,MAAM,gBAAgB,QAAQ,MAAM,SAAS;AAC1I,SAAO;AAAA,IACL;AAAA,IACA,MAAM,KAAK,QAAQ,SAAS,MAAK,QAAQ;AAAA,IACzC,aAAa,IAAI,QAAQ;AAAA,IACzB,MAAM,OAAM,OAAM;AAAA,IAClB,WAAW,OAAM,OAAM;AAAA,IACvB,UAAU,OAAM,OAAM;AAAA,EACxB;AACF;AAKO,SAAS,iBAAiB,SAAiB,UAAkB,OAAe,UAA6B;AAC9G,MAAI,YAAY,EAAG,QAAO,IAAI,QAAQ;AACtC,QAAM,OAAO,KAAK,IAAI,MAAM,KAAK;AACjC,QAAM,UAAU,YAAY,QAAQ;AAIpC,QAAM,QAAQ,SAAS,CAAC,IAAI,MAAM,WAAW,SAAS,CAAC,IAAI,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,EAAE,IAAI,KAAK,MAAM,KAAK,OAAK,EAAE,OAAO,EAAE,EAAE,KAAK,OAAO,SAAS,EAAE,YAAY,EAAE,IAAI,MACzI,CAAC,cAAc,WAAW,IAAI,EAAE,IAAI,MAAM,WAAW,IAAI,EAAE,EAAE,EAAE,EAClE,KAAK,CAAC,GAAG,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK;AACjE,QAAM,OAAO,IAAI,IAAI,MAAM,IAAI,OAAK,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;AACjD,QAAM,OAAO,CAAC,OAAuB;AAAE,UAAM,SAAS,KAAK,IAAI,EAAE;AAAI,QAAI,WAAW,GAAI,QAAO;AAAI,UAAM,MAAM,KAAK,MAAM;AAAG,SAAK,IAAI,IAAI,GAAG;AAAG,WAAO;AAAA,EAAK;AAC5J,aAAW,QAAQ,YAAY;AAC7B,UAAM,IAAI,KAAK,KAAK,IAAI,GAAG,IAAI,KAAK,KAAK,EAAE;AAAG,QAAI,MAAM,EAAG;AAC3D,SAAK,IAAI,GAAG,CAAC;AAAG,QAAI,KAAK,MAAM,KAAK,EAAE;AAAA,EACxC;AACA,SAAO;AACT;AAIO,IAAM,WAAN,MAAe;AAAA,EACZ,YAAY,oBAAI,IAAsD;AAAA,EACtE,SAAS;AAAA,EACT,WAAW;AAAA,
|
|
4
|
+
"sourcesContent": ["import { Quaternion, Vector3 } from 'three';\nimport type { PinRecord, Point } from './pin-types.js';\nimport type { PinParents, HierarchyEdge } from './pin-types.js';\nimport { windAcceleration } from './wind.js';\nimport { DEFAULT_MOTION } from './motion-settings.js';\n\nexport type ClothLink = { a: string; b: string; length: number };\nexport type ClothCollider = { position: Point; radius: number; driver?: string };\n\n/** Connect authored cloth controls along the occupied-volume geodesic, not\n * across the shortest line through empty space. The tree is a coarse fabric\n * constraint network; the ordinary skin remains its portable GLB fallback. */\nexport function clothLinks(pins: readonly PinRecord[], parents: PinParents, edges: readonly HierarchyEdge[] = [], components?: ReadonlyMap<string, number>): ClothLink[] {\n const cloth = pins.filter(p => p.cloth && !p.guide), byId = new Map(pins.map(p => [p.id, p]));\n const result: ClothLink[] = [], seen = new Set<string>();\n const add = (a: string, b: string) => {\n if (a === b || !byId.has(a) || !byId.has(b)) return;\n const key = [a, b].sort().join('\\0'); if (seen.has(key)) return;\n seen.add(key); result.push({ a, b, length: new Vector3().fromArray(byId.get(a)!.rest).distanceTo(new Vector3().fromArray(byId.get(b)!.rest)) });\n };\n for (const pin of cloth) {\n let parent = parents.get(pin.id);\n const visited = new Set<string>();\n while (parent && byId.get(parent)?.guide && !visited.has(parent)) { visited.add(parent); parent = parents.get(parent); }\n if (parent) add(pin.id, parent);\n }\n // A topology hierarchy may root a sheet at one of its free corners. Cloth\n // still needs body attachments there; otherwise the entire sheet falls as\n // one unconstrained pair or chain despite nearby non-cloth controls.\n for (const pin of cloth) {\n const parent = byId.get(parents.get(pin.id) ?? '');\n if (parent && !parent.cloth && !parent.guide) continue;\n const anchors = edges.filter(edge => (edge.from === pin.id || edge.to === pin.id) &&\n !byId.get(edge.from === pin.id ? edge.to : edge.from)?.cloth &&\n !byId.get(edge.from === pin.id ? edge.to : edge.from)?.guide &&\n Number.isFinite(edge.geodesic ?? edge.cost));\n const same = anchors.filter(edge => !components || components.get(pin.id) === components.get(edge.from === pin.id ? edge.to : edge.from));\n const best = (same.length ? same : anchors).sort((a, b) => (a.geodesic ?? a.cost) - (b.geodesic ?? b.cost))[0];\n if (best) add(pin.id, best.from === pin.id ? best.to : best.from);\n }\n const candidates = edges.filter(e => cloth.some(p => p.id === e.from) && cloth.some(p => p.id === e.to) && Number.isFinite(e.geodesic ?? e.cost)\n && (!components || components.get(e.from) === components.get(e.to)))\n .sort((a, b) => (a.geodesic ?? a.cost) - (b.geodesic ?? b.cost));\n const root = new Map(cloth.map(p => [p.id, p.id]));\n const find = (id: string): string => { const parent = root.get(id)!; if (parent === id) return id; const top = find(parent); root.set(id, top); return top; };\n for (const edge of candidates) {\n const a = find(edge.from), b = find(edge.to); if (a === b) continue;\n root.set(a, b); add(edge.from, edge.to);\n }\n return result;\n}\n\n/** Small, fixed-step Verlet graph. The editor passes deformed voxel centers;\n * the GLB loader passes the same collider proxy driven by its joint graph. */\nexport class PinCloth {\n private particles = new Map<string, { position: Vector3; previous: Vector3 }>();\n private layout = '';\n private windTime = 0;\n private accumulator = 0;\n reset() { this.particles.clear(); this.layout = ''; this.windTime = 0; this.accumulator = 0; }\n step(pins: readonly PinRecord[], parents: PinParents, seconds: number, links: readonly ClothLink[], colliders: readonly ClothCollider[] = [], windStrength = 0): { pins: readonly PinRecord[]; active: boolean } {\n const cloth = pins.filter(p => p.cloth && !p.guide);\n if (!cloth.length) { this.reset(); return { pins, active: false }; }\n const layout = JSON.stringify([cloth.map(p => [p.id, p.rest]), links]);\n if (layout !== this.layout) { this.reset(); this.layout = layout; }\n const byId = new Map(pins.map(p => [p.id, p]));\n for (const pin of cloth) if (!this.particles.has(pin.id)) {\n const position = new Vector3().fromArray(pin.pose.position);\n this.particles.set(pin.id, { position, previous: position.clone() });\n }\n // Verlet stores displacement per step. Changing the step with render\n // timing changes its velocity and keeps a calm sheet moving.\n const h = 1 / 60;\n this.accumulator += Math.min(Math.max(seconds, 0), .05);\n const steps = Math.floor((this.accumulator + 1e-12) / h);\n this.accumulator = Math.max(0, this.accumulator - steps * h);\n const scale = Math.max(1e-4, ...links.map(link => link.length));\n // A sampled voxel shell can contain thousands of spheres. Bin it once\n // per frame, then refresh each particle's nearby set after integration so\n // a fast-moving cloth point cannot retain last frame's collision region.\n let maxRadius = 0;\n for (const collider of colliders) maxRadius = Math.max(maxRadius, collider.radius);\n const cell = Math.max(1e-4, scale * 2 + maxRadius);\n const spatial = cloth.length > 4 && colliders.length > 128;\n const bins = new Map<string, ClothCollider[]>();\n const key = (x: number, y: number, z: number) => `${x},${y},${z}`;\n if (spatial) for (const collider of colliders) {\n const p = collider.position, id = key(Math.floor(p[0] / cell), Math.floor(p[1] / cell), Math.floor(p[2] / cell));\n const bin = bins.get(id) ?? []; bin.push(collider); bins.set(id, bin);\n }\n const candidates = (position: Vector3) => {\n const found: ClothCollider[] = [];\n const search = (collider: ClothCollider) => {\n const p = collider.position, dx = position.x - p[0], dy = position.y - p[1], dz = position.z - p[2], reach = collider.radius + scale * 2;\n if (dx * dx + dy * dy + dz * dz < reach * reach) found.push(collider);\n };\n if (spatial) {\n const x = Math.floor(position.x / cell), y = Math.floor(position.y / cell), z = Math.floor(position.z / cell);\n for (let dz = -1; dz <= 1; dz++) for (let dy = -1; dy <= 1; dy++) for (let dx = -1; dx <= 1; dx++)\n for (const collider of bins.get(key(x + dx, y + dy, z + dz)) ?? []) search(collider);\n } else for (const collider of colliders) search(collider);\n return found;\n };\n for (let substep = 0; substep < steps; substep++) {\n this.windTime += h;\n for (const pin of cloth) {\n const particle = this.particles.get(pin.id)!;\n const motion = pin.motion ?? DEFAULT_MOTION;\n const velocity = particle.position.clone().sub(particle.previous).multiplyScalar(Math.exp(-motion.damping * 3 * h));\n particle.previous.copy(particle.position);\n particle.position.add(velocity).y -= 2.5 * scale * h * h;\n if (windStrength > 0 && motion.strength > 0) particle.position.addScaledVector(windAcceleration(this.windTime, windStrength, scale, particle.position.toArray()), motion.strength * h * h);\n // Pins are sparse controls, not free particles. A soft return to their\n // authored positions keeps broad sheets from drifting indefinitely.\n particle.position.lerp(new Vector3().fromArray(pin.pose.position), 1 - Math.exp(-2 * Math.PI * motion.frequency * h));\n }\n const nearby = new Map(cloth.map(pin => [pin.id, candidates(this.particles.get(pin.id)!.position)]));\n for (let iteration = 0; iteration < 6; iteration++) {\n for (const link of links) {\n const a = this.particles.get(link.a), b = this.particles.get(link.b);\n const pa = a?.position ?? new Vector3().fromArray(byId.get(link.a)?.pose.position ?? [0, 0, 0]);\n const pb = b?.position ?? new Vector3().fromArray(byId.get(link.b)?.pose.position ?? [0, 0, 0]);\n const delta = pa.clone().sub(pb), distance = delta.length(); if (distance < 1e-8) continue;\n const correction = delta.multiplyScalar((distance - link.length) / distance);\n if (a && b) { a.position.addScaledVector(correction, -.5); b.position.addScaledVector(correction, .5); }\n else if (a) a.position.sub(correction); else if (b) b.position.add(correction);\n }\n for (const [id, particle] of this.particles) for (const collider of nearby.get(id) ?? []) {\n const center = collider.position, dx = particle.position.x - center[0], dy = particle.position.y - center[1], dz = particle.position.z - center[2];\n const squared = dx * dx + dy * dy + dz * dz;\n if (squared >= collider.radius * collider.radius) continue;\n if (squared < 1e-16) particle.position.set(center[0], center[1] + collider.radius, center[2]);\n else {\n const factor = collider.radius / Math.sqrt(squared);\n particle.position.set(center[0] + dx * factor, center[1] + dy * factor, center[2] + dz * factor);\n }\n }\n }\n }\n let active = false;\n const result = pins.map(pin => {\n const particle = this.particles.get(pin.id); if (!particle) return pin;\n const target = new Vector3().fromArray(pin.pose.position), offset = particle.position.clone().sub(target);\n const velocity = particle.position.clone().sub(particle.previous);\n if (offset.lengthSq() > scale * scale * 1e-10 || velocity.lengthSq() > scale * scale * 1e-10) active = true;\n const parent = byId.get(parents.get(pin.id) ?? '');\n const rotation = parent ? new Quaternion().setFromUnitVectors(\n target.clone().sub(new Vector3().fromArray(parent.pose.position)).normalize(),\n particle.position.clone().sub(new Vector3().fromArray(parent.pose.position)).normalize()) : new Quaternion();\n return { ...pin, pose: { ...pin.pose, position: particle.position.toArray() as Point,\n rotation: rotation.multiply(new Quaternion().fromArray(pin.pose.rotation)).normalize().toArray() as [number, number, number, number] } };\n });\n return { pins: active ? result : pins, active };\n }\n}\n", "import { Vector3 } from 'three';\n\nexport const MAX_WIND_STRENGTH = 4;\n\n/** A single weather control drives pin motion and surface pressure. Sparse pin\n * loads stay bounded; fabric pressure has room to grow through a storm. */\nexport function windProfile(strength: number) {\n const level = Math.max(0, Math.min(MAX_WIND_STRENGTH, strength));\n const label = level === 0 ? 'Off' : level < .75 ? 'Breeze' : level < 1.5 ? 'Windy' : level < 2.5 ? 'Strong wind' : level < 3.3 ? 'Gale' : 'Storm';\n return {\n label,\n load: 30 * level * level / (.8 + level * level),\n surfaceLoad: 4 * level * level,\n gust: .14 + .12 * level,\n crosswind: .05 + .07 * level,\n gustRate: .42 + .12 * level,\n };\n}\n\n/** Deterministic scene-local prevailing wind with slow gusts and spatially\n * varying eddies. Force is an acceleration scaled to the model's size, so a\n * tiny prop and a large character respond comparably at the same setting. */\nexport function windAcceleration(seconds: number, strength: number, scale: number, position: readonly number[]) {\n if (strength <= 0) return new Vector3();\n const size = Math.max(1e-4, scale);\n const profile = windProfile(strength);\n // Advect the gust bands along +X. Nearby controls see related wind, while\n // their phase delay keeps a large sheet or branch hierarchy from moving as\n // one perfectly synchronized rigid object.\n const along = position[0] / size, lateral = (position[1] * .67 + position[2] * .33) / size;\n const slow = seconds * profile.gustRate - along * .55;\n const fast = seconds * (profile.gustRate * 2.7) - along * 1.4 + lateral * .4;\n const gust = Math.max(.2, 1 + profile.gust * (.7 * Math.sin(slow) + .3 * Math.sin(fast + 1.3)));\n const cross = profile.crosswind * (.65 * Math.sin(fast + lateral) + .35 * Math.sin(slow * .73 - lateral * .6));\n return new Vector3(1, cross * .35, cross).normalize().multiplyScalar(profile.load * size * gust);\n}\n", "export type MotionSettings = { reach: number; frequency: number; damping: number; massInfluence:number; strength:number };\nexport const DEFAULT_MOTION: Readonly<MotionSettings> = { reach: .5, frequency: 14 / (2*Math.PI), damping: .28, massInfluence:1,strength:1 };\nexport function validateMotionSettings(value: MotionSettings) {\n if (!value || !Number.isFinite(value.reach) || value.reach < 0 || value.reach > 1\n || !Number.isFinite(value.frequency) || value.frequency < .25 || value.frequency > 8\n || !Number.isFinite(value.damping) || value.damping < .05 || value.damping > 1\n || !Number.isFinite(value.massInfluence) || value.massInfluence<0 || value.massInfluence>2\n || !Number.isFinite(value.strength) || value.strength<0 || value.strength>3) throw new Error('Invalid motion settings.');\n}\n"],
|
|
5
|
+
"mappings": ";;;AAAA,SAAS,YAAY,WAAAA,gBAAe;;;ACApC,SAAS,eAAe;AAEjB,IAAM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,OAAO;AAAA,EAChD;AACF;",
|
|
6
6
|
"names": ["Vector3", "Vector3"]
|
|
7
7
|
}
|
|
@@ -1081,10 +1081,12 @@ var PinCloth = class {
|
|
|
1081
1081
|
particles = /* @__PURE__ */ new Map();
|
|
1082
1082
|
layout = "";
|
|
1083
1083
|
windTime = 0;
|
|
1084
|
+
accumulator = 0;
|
|
1084
1085
|
reset() {
|
|
1085
1086
|
this.particles.clear();
|
|
1086
1087
|
this.layout = "";
|
|
1087
1088
|
this.windTime = 0;
|
|
1089
|
+
this.accumulator = 0;
|
|
1088
1090
|
}
|
|
1089
1091
|
step(pins, parents, seconds, links, colliders = [], windStrength = 0) {
|
|
1090
1092
|
const cloth = pins.filter((p) => p.cloth && !p.guide);
|
|
@@ -1102,7 +1104,10 @@ var PinCloth = class {
|
|
|
1102
1104
|
const position = new Vector35().fromArray(pin.pose.position);
|
|
1103
1105
|
this.particles.set(pin.id, { position, previous: position.clone() });
|
|
1104
1106
|
}
|
|
1105
|
-
const
|
|
1107
|
+
const h = 1 / 60;
|
|
1108
|
+
this.accumulator += Math.min(Math.max(seconds, 0), 0.05);
|
|
1109
|
+
const steps = Math.floor((this.accumulator + 1e-12) / h);
|
|
1110
|
+
this.accumulator = Math.max(0, this.accumulator - steps * h);
|
|
1106
1111
|
const scale = Math.max(1e-4, ...links.map((link) => link.length));
|
|
1107
1112
|
let maxRadius = 0;
|
|
1108
1113
|
for (const collider of colliders) maxRadius = Math.max(maxRadius, collider.radius);
|
|
@@ -1129,7 +1134,7 @@ var PinCloth = class {
|
|
|
1129
1134
|
} else for (const collider of colliders) search(collider);
|
|
1130
1135
|
return found;
|
|
1131
1136
|
};
|
|
1132
|
-
for (let substep = 0; substep < steps
|
|
1137
|
+
for (let substep = 0; substep < steps; substep++) {
|
|
1133
1138
|
this.windTime += h;
|
|
1134
1139
|
for (const pin of cloth) {
|
|
1135
1140
|
const particle = this.particles.get(pin.id);
|
|
@@ -1254,6 +1259,7 @@ var ClothSurface = class {
|
|
|
1254
1259
|
edges;
|
|
1255
1260
|
scale;
|
|
1256
1261
|
time = 0;
|
|
1262
|
+
accumulator = 0;
|
|
1257
1263
|
constructor(restVertices, indices, pins) {
|
|
1258
1264
|
const vertexCount = restVertices.length / 3;
|
|
1259
1265
|
const min = new Vector36(Infinity, Infinity, Infinity), max = new Vector36(-Infinity, -Infinity, -Infinity);
|
|
@@ -1335,6 +1341,7 @@ var ClothSurface = class {
|
|
|
1335
1341
|
}
|
|
1336
1342
|
reset() {
|
|
1337
1343
|
this.time = 0;
|
|
1344
|
+
this.accumulator = 0;
|
|
1338
1345
|
for (const particle of this.particles) particle.position.copy(particle.base), particle.previous.copy(particle.base);
|
|
1339
1346
|
}
|
|
1340
1347
|
step(baseVertices, seconds, windStrength, colliders = [], motion = DEFAULT_MOTION) {
|
|
@@ -1351,7 +1358,10 @@ var ClothSurface = class {
|
|
|
1351
1358
|
particle.previous.add(delta);
|
|
1352
1359
|
particle.base.copy(base[i]);
|
|
1353
1360
|
}
|
|
1354
|
-
const
|
|
1361
|
+
const h = 1 / 60;
|
|
1362
|
+
this.accumulator += Math.min(Math.max(seconds, 0), 0.05);
|
|
1363
|
+
const steps = Math.floor((this.accumulator + 1e-12) / h);
|
|
1364
|
+
this.accumulator = Math.max(0, this.accumulator - steps * h);
|
|
1355
1365
|
const profile = windProfile(windStrength), pressureScale = profile.load ? 0.025 * profile.surfaceLoad / profile.load : 0;
|
|
1356
1366
|
const radius = Math.max(1e-4, ...colliders.map((collider) => collider.radius));
|
|
1357
1367
|
const cell = radius * 2;
|
|
@@ -1363,7 +1373,7 @@ var ClothSurface = class {
|
|
|
1363
1373
|
bin.push(collider);
|
|
1364
1374
|
bins.set(id, bin);
|
|
1365
1375
|
}
|
|
1366
|
-
for (let step = 0; step < steps
|
|
1376
|
+
for (let step = 0; step < steps; step++) {
|
|
1367
1377
|
this.time += h;
|
|
1368
1378
|
const force = Array.from({ length: count }, () => new Vector36());
|
|
1369
1379
|
const area = new Float32Array(count);
|
|
@@ -1410,23 +1420,24 @@ var ClothSurface = class {
|
|
|
1410
1420
|
}
|
|
1411
1421
|
if (colliders.length) for (const particle of this.particles) {
|
|
1412
1422
|
if (particle.share < 0.35) continue;
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
for (
|
|
1419
|
-
const
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
penetration
|
|
1425
|
-
|
|
1423
|
+
for (let contact = 0; contact < 8; contact++) {
|
|
1424
|
+
const p = particle.position, px = p.x / cell, py = p.y / cell, pz = p.z / cell;
|
|
1425
|
+
const x = Math.floor(px), y = Math.floor(py), z = Math.floor(pz);
|
|
1426
|
+
const sx = px - x < 0.5 ? -1 : 1, sy = py - y < 0.5 ? -1 : 1, sz = pz - z < 0.5 ? -1 : 1;
|
|
1427
|
+
let chosen, penetration = 0;
|
|
1428
|
+
for (let iz = 0; iz < 2; iz++) for (let iy = 0; iy < 2; iy++) for (let ix = 0; ix < 2; ix++) {
|
|
1429
|
+
for (const collider of bins.get(key(x + ix * sx, y + iy * sy, z + iz * sz)) ?? []) {
|
|
1430
|
+
const center2 = collider.position, bx = particle.base.x - center2[0], by = particle.base.y - center2[1], bz = particle.base.z - center2[2];
|
|
1431
|
+
if (bx * bx + by * by + bz * bz < collider.radius * collider.radius * 1.04) continue;
|
|
1432
|
+
const vx = p.x - center2[0], vy = p.y - center2[1], vz = p.z - center2[2];
|
|
1433
|
+
const depth = collider.radius - Math.hypot(vx, vy, vz);
|
|
1434
|
+
if (depth > penetration) {
|
|
1435
|
+
penetration = depth;
|
|
1436
|
+
chosen = collider;
|
|
1437
|
+
}
|
|
1426
1438
|
}
|
|
1427
1439
|
}
|
|
1428
|
-
|
|
1429
|
-
if (chosen) {
|
|
1440
|
+
if (!chosen || penetration < this.scale * 1e-7) break;
|
|
1430
1441
|
const center = chosen.position, delta = p.clone().sub(new Vector36().fromArray(center));
|
|
1431
1442
|
if (delta.lengthSq() < 1e-12) delta.copy(particle.base).sub(new Vector36().fromArray(center));
|
|
1432
1443
|
p.copy(new Vector36().fromArray(center).add(delta.setLength(chosen.radius)));
|