UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

55 lines (54 loc) 2.11 kB
"use strict"; import { CoreParticlesController } from "./CoreParticlesController"; import { CoreParticlesAttribute } from "./CoreParticlesAttribute"; const coreParticlesControllerByNodeId = /* @__PURE__ */ new Map(); const rendererByNodeId = /* @__PURE__ */ new Map(); export async function createOrFindParticlesController(object, scene) { const nodeId = CoreParticlesAttribute.getParticlesNodeId(object); let controller = coreParticlesControllerByNodeId.get(nodeId); if (!controller) { const node = scene.graph.nodeFromId(nodeId); if (node) { controller = new CoreParticlesController(scene, node); coreParticlesControllerByNodeId.set(nodeId, controller); } } if (controller) { const renderer = rendererByNodeId.get(nodeId); if (renderer) { controller.init(object, renderer); } } } export function setParticleRenderer(nodeId, renderer) { rendererByNodeId.set(nodeId, renderer); } export function stepParticles(object, delta, configRef) { var _a; (_a = coreParticlesControllerFromObject(object)) == null ? void 0 : _a.stepSimulation(delta, configRef); } export function resetParticles(object) { var _a; (_a = coreParticlesControllerFromObject(object)) == null ? void 0 : _a.reset(); } export function disposeParticlesFromNode(node) { const nodeId = node.graphNodeId(); const controller = coreParticlesControllerByNodeId.get(nodeId); controller == null ? void 0 : controller.dispose(); coreParticlesControllerByNodeId.delete(nodeId); } function coreParticlesControllerFromObject(object) { const nodeId = CoreParticlesAttribute.getParticlesNodeId(object); return coreParticlesControllerByNodeId.get(nodeId); } export function coreParticlesControllerFromNode(node) { return coreParticlesControllerByNodeId.get(node.graphNodeId()); } export function gpuControllerFromNode(node) { var _a; return (_a = coreParticlesControllerFromNode(node)) == null ? void 0 : _a.gpuController; } export function renderControllerFromNode(node) { var _a; return (_a = coreParticlesControllerFromNode(node)) == null ? void 0 : _a.renderController; }