Skip to content

Commit e2426d3

Browse files
committed
feat: add support of direct descandants only when retrieving particle system using @particleSystemFromScene in babylonjs-editor-tools
1 parent 918e0b9 commit e2426d3

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

tools/src/decorators/apply.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Scene } from "@babylonjs/core/scene";
33
import { Color3, Color4 } from "@babylonjs/core/Maths/math.color";
44
import { Texture } from "@babylonjs/core/Materials/Textures/texture";
55
import { Vector2, Vector3 } from "@babylonjs/core/Maths/math.vector";
6+
import { ParticleSystem } from "@babylonjs/core/Particles/particleSystem";
7+
import { GPUParticleSystem } from "@babylonjs/core/Particles/gpuParticleSystem";
68

79
import { AdvancedDynamicTexture } from "@babylonjs/gui/2D/advancedDynamicTexture";
810

@@ -48,6 +50,7 @@ export interface ISceneDecoratorData {
4850
// @fromParticleSystems
4951
_ParticleSystemsFromScene: {
5052
particleSystemName: string;
53+
directDescendantsOnly: boolean;
5154
propertyKey: string | Symbol;
5255
}[];
5356

@@ -108,8 +111,12 @@ export function applyDecorators(scene: Scene, object: any, script: any, instance
108111

109112
// @fromParticleSystems
110113
ctor._ParticleSystemsFromScene?.forEach((params) => {
111-
const particleSystem = scene.particleSystems?.find((particleSystem) => {
112-
return particleSystem.name === params.particleSystemName;
114+
const particleSystem = scene.particleSystems?.find((particleSystem: ParticleSystem | GPUParticleSystem) => {
115+
if (particleSystem.name !== params.particleSystemName) {
116+
return false;
117+
}
118+
119+
return params.directDescendantsOnly ? particleSystem.emitter === object : particleSystem;
113120
});
114121

115122
instance[params.propertyKey.toString()] = particleSystem;

tools/src/decorators/particle-systems.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import { ISceneDecoratorData } from "./apply";
66
* from the scene and assigned to the property. Node link cant' be used in constructor.
77
* This can be used only by scripts using Classes.
88
* @param particleSystemName defines the name of the sound to retrieve in scene.
9+
* @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also global particle systems will be considered.
910
*/
10-
export function particleSystemFromScene(particleSystemName: string) {
11+
export function particleSystemFromScene(particleSystemName: string, directDescendantsOnly: boolean = false) {
1112
return function (target: any, propertyKey: string | Symbol) {
1213
const ctor = target.constructor as ISceneDecoratorData;
1314

1415
ctor._ParticleSystemsFromScene ??= [];
15-
ctor._ParticleSystemsFromScene.push({ propertyKey, particleSystemName });
16+
ctor._ParticleSystemsFromScene.push({ propertyKey, particleSystemName, directDescendantsOnly });
1617
};
1718
}

0 commit comments

Comments
 (0)