Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/dev/core/src/Particles/Node/Blocks/systemBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { _TriggerSubEmitter } from "./Triggers/triggerTools";
* Block used to get a system of particles
*/
export class SystemBlock extends NodeParticleBlock {
private static _IdCounter = 0;

/**
* Gets or sets the blend mode for the particle system
*/
Expand Down Expand Up @@ -58,6 +60,9 @@ export class SystemBlock extends NodeParticleBlock {
@editableInPropertyPage("Do no start", PropertyTypeForEdition.Boolean, "ADVANCED", { embedded: true, notifiers: { rebuild: true } })
public doNoStart = false;

/** @internal */
public _internalId = SystemBlock._IdCounter++;

/**
* Create a new SystemBlock
* @param name defines the block name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function _CreateAndConnectInput(connectionPoint: NodeParticleConnectionPoint, na
async function _ExtractDatafromParticleSystemAsync(particleSystem: ParticleSystem, target: NodeParticleSystemSet) {
// Main system
const system = new SystemBlock(particleSystem.name);
system.capacity = particleSystem.getCapacity();
system.emitRate = particleSystem.emitRate;

// Create particle
const createParticleBlock = new CreateParticleBlock("Create particle");
Expand Down Expand Up @@ -107,11 +109,37 @@ async function _ExtractDatafromParticleSystemAsync(particleSystem: ParticleSyste
const color1Block = new ParticleInputBlock("Color1");
color1Block.value = particleSystem.color2;

const randomBlock = new ParticleRandomBlock("Random");
color0Block.output.connectTo(randomBlock.min);
color1Block.output.connectTo(randomBlock.max);
const randomColorBlock = new ParticleRandomBlock("Random Color");
color0Block.output.connectTo(randomColorBlock.min);
color1Block.output.connectTo(randomColorBlock.max);

randomBlock.output.connectTo(createParticleBlock.color);
randomColorBlock.output.connectTo(createParticleBlock.color);

// Emit power
const minEmitPowerBlock = new ParticleInputBlock("Min Emit Power");
minEmitPowerBlock.value = particleSystem.minEmitPower;

const maxEmitPowerBlock = new ParticleInputBlock("Max Emit Power");
maxEmitPowerBlock.value = particleSystem.maxEmitPower;

const randomEmitPowerBlock = new ParticleRandomBlock("Random Emit Power");
minEmitPowerBlock.output.connectTo(randomEmitPowerBlock.min);
maxEmitPowerBlock.output.connectTo(randomEmitPowerBlock.max);

randomEmitPowerBlock.output.connectTo(createParticleBlock.emitPower);

// Lifetime
const minLifetimeBlock = new ParticleInputBlock("Min Lifetime");
minLifetimeBlock.value = particleSystem.minLifeTime;

const maxLifetimeBlock = new ParticleInputBlock("Max Lifetime");
maxLifetimeBlock.value = particleSystem.maxLifeTime;

const randomLifetimeBlock = new ParticleRandomBlock("Random Lifetime");
minLifetimeBlock.output.connectTo(randomLifetimeBlock.min);
maxLifetimeBlock.output.connectTo(randomLifetimeBlock.max);

randomLifetimeBlock.output.connectTo(createParticleBlock.lifeTime);

// Texture
const textureBlock = new ParticleTextureSourceBlock("Texture");
Expand Down Expand Up @@ -141,7 +169,7 @@ async function _ExtractDatafromParticleSystemAsync(particleSystem: ParticleSyste
* @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.
* #0K3AQ2#3625
* #0K3AQ2#3627
*/
export async function ConvertToNodeParticleSystemSetAsync(name: string, particleSystems: ParticleSystem[]): Promise<Nullable<NodeParticleSystemSet>> {
if (!particleSystems || !particleSystems.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export class NodeParticleSystemSet {

const system = block.createSystem(state);
system._source = this;
system._blockReference = block._internalId;

// Errors
state.emitErrors();
Expand Down
3 changes: 3 additions & 0 deletions packages/dev/core/src/Particles/particleSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ export class ParticleSystem extends ThinParticleSystem {
/** @internal */
public _source: Nullable<NodeParticleSystemSet> = null;

/** @internal */
public _blockReference: number = 0;

/**
* Gets the NodeParticleSystemSet that this particle system belongs to.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import { SceneLoaderFlags } from "core/Loading/sceneLoaderFlags";
import type { NodeParticleSystemSet } from "core/Particles/Node/nodeParticleSystemSet";
import { LogEntry } from "../log/logComponent";
import { GridMaterial } from "materials/grid/gridMaterial";
import { MeshBuilder } from "core/Meshes";
import { MeshBuilder } from "core/Meshes/meshBuilder";
import type { AbstractMesh } from "core/Meshes/abstractMesh";
import { SceneInstrumentation } from "core/Instrumentation/sceneInstrumentation";
import type { ThinParticleSystem } from "core/Particles/thinParticleSystem";
import type { ParticleSystemSet } from "core/Particles/particleSystemSet";
import { EngineStore } from "core/Engines";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { EngineStore } from "core/Engines";
import { EngineStore } from "core/Engines/engineStore";

import type { ParticleSystem } from "core/Particles";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import type { ParticleSystem } from "core/Particles";
import type { ParticleSystem } from "core/Particles/particleSystem";


export class PreviewManager {
private _nodeParticleSystemSet: NodeParticleSystemSet;
Expand Down Expand Up @@ -128,6 +131,45 @@ export class PreviewManager {
// Ignore the error
this._globalState.onIsLoadingChanged.notifyObservers(false);
}

// Synchronize with main
for (const engine of EngineStore.Instances) {
for (const scene of engine.scenes) {
if (scene === this._scene) {
continue;
}

void this._reconnectEmittersAsync(scene);
}
}
}

private async _reconnectEmittersAsync(scene: Scene) {
const map = new Map<number, Nullable<AbstractMesh | Vector3>>();

for (const ps of scene.particleSystems) {
const particleSystem = ps as ParticleSystem;
const source = particleSystem.source;
if (source === this._nodeParticleSystemSet) {
// Keep track of particle system reference and emitter
const reference = particleSystem._blockReference;
const emitter = particleSystem.emitter;

particleSystem.dispose();

map.set(reference, emitter);
}
}

const newSet = await this._nodeParticleSystemSet.buildAsync(scene);
for (const [reference, emitter] of map) {
const particleSystem = (newSet.systems as ParticleSystem[]).find((ps) => ps._blockReference === reference);
if (particleSystem) {
particleSystem.emitter = emitter;
}
}

newSet.start();
}

public dispose() {
Expand Down
Loading