@babylonjs/core
Version:
Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.
90 lines • 4.86 kB
JavaScript
import { NodeParticleSystemSet } from "./nodeParticleSystemSet.js";
import { SystemBlock } from "./Blocks/systemBlock.js";
import { CreateParticleBlock } from "./Blocks/Emitters/createParticleBlock.js";
import { BoxShapeBlock } from "./Blocks/Emitters/boxShapeBlock.js";
import { ParticleInputBlock } from "./Blocks/particleInputBlock.js";
import { PointShapeBlock } from "./Blocks/Emitters/pointShapeBlock.js";
import { SphereShapeBlock } from "./Blocks/Emitters/sphereShapeBlock.js";
import { CylinderShapeBlock } from "./Blocks/Emitters/cylinderShapeBlock.js";
import { MeshShapeBlock } from "./Blocks/Emitters/meshShapeBlock.js";
function _CreateAndConnectInput(connectionPoint, name, defaultValue) {
const input = new ParticleInputBlock(name);
input.value = defaultValue;
input.output.connectTo(connectionPoint);
}
/**
* Converts a ParticleSystem to a NodeParticleSystemSet.
* @param name The name of the node particle system set.
* @param particleSystems The particle systems to convert.
* @returns The converted node particle system set or null if conversion failed.
*/
export function ConvertToNodeParticleSystemSet(name, particleSystems) {
if (!particleSystems || !particleSystems.length) {
return null;
}
const nodeParticleSystemSet = new NodeParticleSystemSet(name);
for (const particleSystem of particleSystems) {
// Main system
const system = new SystemBlock(particleSystem.name);
// Create particle
const createParticleBlock = new CreateParticleBlock("Create particle");
// Shape
let shapeBlock = null;
switch (particleSystem.particleEmitterType.getClassName()) {
case "BoxParticleEmitter": {
const source = particleSystem.particleEmitterType;
shapeBlock = new BoxShapeBlock("Box shape");
const target = shapeBlock;
_CreateAndConnectInput(target.direction1, "Direction 1", source.direction1);
_CreateAndConnectInput(target.direction2, "Direction 2", source.direction2);
_CreateAndConnectInput(target.minEmitBox, "Min Emit Box", source.minEmitBox);
_CreateAndConnectInput(target.maxEmitBox, "Max Emit Box", source.maxEmitBox);
break;
}
case "PointParticleEmitter": {
const source = particleSystem.particleEmitterType;
shapeBlock = new PointShapeBlock("Point shape");
const target = shapeBlock;
_CreateAndConnectInput(target.direction1, "Direction 1", source.direction1);
_CreateAndConnectInput(target.direction2, "Direction 2", source.direction2);
break;
}
case "SphereParticleEmitter": {
const source = particleSystem.particleEmitterType;
shapeBlock = new SphereShapeBlock("Sphere shape");
const target = shapeBlock;
_CreateAndConnectInput(target.radius, "Radius", source.radius);
_CreateAndConnectInput(target.radiusRange, "Radius Range", source.radiusRange);
_CreateAndConnectInput(target.directionRandomizer, "Direction Randomizer", source.directionRandomizer);
break;
}
case "CylinderParticleEmitter": {
const source = particleSystem.particleEmitterType;
shapeBlock = new CylinderShapeBlock("Cylinder shape");
const target = shapeBlock;
_CreateAndConnectInput(target.height, "Height", source.height);
_CreateAndConnectInput(target.radius, "Radius", source.radius);
_CreateAndConnectInput(target.radiusRange, "Radius Range", source.radiusRange);
_CreateAndConnectInput(target.directionRandomizer, "Direction Randomizer", source.directionRandomizer);
break;
}
case "MeshParticleEmitter": {
const source = particleSystem.particleEmitterType;
shapeBlock = new MeshShapeBlock("Mesh shape");
const target = shapeBlock;
_CreateAndConnectInput(target.direction1, "Direction 1", source.direction1);
_CreateAndConnectInput(target.direction2, "Direction 2", source.direction2);
target.mesh = source.mesh;
break;
}
}
if (!shapeBlock) {
throw new Error(`Unsupported particle emitter type: ${particleSystem.particleEmitterType.getClassName()}`);
}
createParticleBlock.particle.connectTo(shapeBlock.particle);
shapeBlock.output.connectTo(system.particle);
nodeParticleSystemSet.systemBlocks.push(system);
}
return nodeParticleSystemSet;
}
//# sourceMappingURL=nodeParticleSystemSet.helper.js.map