Appearance
ExplosionPlugin
Hierarchical mesh explosion. Computes per-mesh explosion vectors from a configurable origin and applies them as a per-axis or radial offset. Integrates with MeshService via a pipeline stage so new meshes get prepared automatically.
Usage
ts
const viewer = new ViewerCore(container, {
plugins: [{ name: "explosion", enabled: true }],
});
await viewer.ready();
const explosion = viewer.pluginManager.getPlugin("explosion") as ExplosionPlugin;
await explosion.explodeRadial(0.5);Or:
ts
await viewer.loadPlugin(new ExplosionPlugin());Service dependencies: mesh (required), commands (optional, enables command registration).
Public API
| Method | Description |
|---|---|
configure(config: Partial<ExplosionConfig>) | Update plugin config. Recomputes mesh data if origin changes. |
explodeHierarchical(x, y, z, radial, scopeObject?, mode?, immediateOnly?) | Full-control explosion. scopeObject limits to its descendants. immediateOnly restricts to direct children of the scope. |
explodeX(factor) / explodeY(factor) / explodeZ(factor) | Axis-only convenience wrappers. |
explodeRadial(factor) | Radial-only explosion. |
explodeDepth(depth, x, y?, z?, radial?, mode?) | Explode all subtrees at a given hierarchy depth. Two-arg form treats the second arg as radial. |
resetExplosion() | Restore meshes to original positions. |
getExplosionState() | Current hierarchical values and isExploded flag. |
getExplosionStats() | Mesh counts, scene bounds, scene scale, current values. |
setExplosionOrigin(origin: THREE.Vector3) | Move the explosion origin; reprocesses meshes. |
setScaleMultiplier(multiplier) | Tune log-scaled magnitude (clamped to [0.1, 20]). |
getScaleMultiplier() | Read current multiplier. |
ExplosionMode
ts
enum ExplosionMode {
RESET_BASED = "reset_based", // Always explode relative to original positions
CURRENT_BASED = "current_based", // Explode relative to current positions
}ExplosionConfig
| Field | Type | Default | Description |
|---|---|---|---|
strength | number | 0.05 | Base scaling factor per unit distance. |
origin | THREE.Vector3 | (0,0,0) | World-space explosion center. |
autoResetOnLoad | boolean | true | Reset explosion on model:loaded. |
scaleMultiplier | number | 5 | Final magnitude multiplier; the plugin log-scales by scene size. |
Events
| Event | Payload |
|---|---|
explosion:applied | { x, y, z, radial, meshCount, scopeObject, mode, immediateOnly? } |
explosion:reset | {} |
explosion:reprocessed | { meshCount } |
explosion:depth-applied | { depth, x, y, z, radial, mode, parents, children } |
Registered Commands
When the commands service is present, the plugin declares these via getCommands() and BasePlugin registers them: explode, explode-x, explode-y, explode-z, explode-radial, reset-explosion, set-explosion-origin, set-explosion-scale, get-explosion-state, get-explosion-stats, explode-scoped, explode-immediate, explode-by-uuid.
Command handlers are thin and call the plugin's public methods (explodeScoped, explodeImmediate, explodeByUuid, etc.). The bodies live in src/plugins/explosion/commands.ts.
Example
ts
const explosion = viewer.pluginManager.getPlugin("explosion") as ExplosionPlugin;
explosion.configure({ strength: 0.1, scaleMultiplier: 3 });
await explosion.explodeHierarchical(0, 0, 0, 0.7);
console.log(explosion.getExplosionState());
await explosion.resetExplosion();