Skip to content

Commit dba9160

Browse files
[NPE] Migrating attractors (#17643)
Adds attractors to the migration tool. Adds some missing docs for the linter. PG to test: #DEZ79M#72 <img width="1578" height="1254" alt="image" src="https://github.com/user-attachments/assets/3deea5a4-55c4-4973-8dd0-7901bfff70c3" />
1 parent 567285e commit dba9160

File tree

5 files changed

+61
-1
lines changed

5 files changed

+61
-1
lines changed

packages/dev/core/src/Particles/Node/nodeParticleSystemSet.helper.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Attractor } from "../attractor";
12
import type { Color3Gradient, ColorGradient } from "core/Misc";
23
import type { Nullable } from "core/types";
34
import type { BaseTexture } from "core/Materials/Textures/baseTexture";
@@ -45,6 +46,7 @@ import { SetupSpriteSheetBlock } from "./Blocks/Emitters/setupSpriteSheetBlock";
4546
import { SphereShapeBlock } from "./Blocks/Emitters/sphereShapeBlock";
4647
import { UpdateAngleBlock } from "./Blocks/Update/updateAngleBlock";
4748
import { BasicSpriteUpdateBlock } from "./Blocks/Update/basicSpriteUpdateBlock";
49+
import { UpdateAttractorBlock } from "./Blocks/Update/updateAttractorBlock";
4850
import { UpdateColorBlock } from "./Blocks/Update/updateColorBlock";
4951
import { UpdateDirectionBlock } from "./Blocks/Update/updateDirectionBlock";
5052
import { UpdateNoiseBlock } from "./Blocks/Update/updateNoiseBlock";
@@ -459,6 +461,10 @@ function _UpdateParticleBlockGroup(inputParticle: NodeParticleConnectionPoint, o
459461

460462
updatedParticle = _UpdateParticlePositionBlockGroup(updatedParticle, oldSystem.isLocal, context);
461463

464+
if (oldSystem.attractors && oldSystem.attractors.length > 0) {
465+
updatedParticle = _UpdateParticleAttractorBlockGroup(updatedParticle, oldSystem.attractors);
466+
}
467+
462468
if (oldSystem._limitVelocityGradients && oldSystem._limitVelocityGradients.length > 0 && oldSystem.limitVelocityDamping !== 0) {
463469
updatedParticle = _UpdateParticleVelocityLimitGradientBlockGroup(updatedParticle, oldSystem._limitVelocityGradients, oldSystem.limitVelocityDamping, context);
464470
}
@@ -725,6 +731,28 @@ function _UpdateParticlePositionBlockGroup(inputParticle: NodeParticleConnection
725731
return updatePosition.output;
726732
}
727733

734+
/**
735+
* Creates the group of blocks that represent the particle attractor update
736+
* @param inputParticle The input particle to update
737+
* @param attractors The attractors (if any)
738+
* @returns The output of the group of blocks that represent the particle attractor update
739+
*/
740+
function _UpdateParticleAttractorBlockGroup(inputParticle: NodeParticleConnectionPoint, attractors: Attractor[]): NodeParticleConnectionPoint {
741+
let outputParticle = inputParticle;
742+
743+
// Chain update attractor blocks for each attractor
744+
for (let i = 0; i < attractors.length; i++) {
745+
const attractor = attractors[i];
746+
const attractorBlock = new UpdateAttractorBlock(`Attractor Block ${i}`);
747+
outputParticle.connectTo(attractorBlock.particle);
748+
_CreateAndConnectInput("Attractor Position", attractor.position.clone(), attractorBlock.attractor);
749+
_CreateAndConnectInput("Attractor Strength", attractor.strength, attractorBlock.strength);
750+
outputParticle = attractorBlock.output;
751+
}
752+
753+
return outputParticle;
754+
}
755+
728756
/**
729757
* Creates the group of blocks that represent the particle size update
730758
* @param inputParticle The input particle to update

packages/dev/core/src/Particles/baseParticleSystem.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,13 @@ export class BaseParticleSystem implements IClipPlanesHolder {
889889
throw new Error("Method not implemented.");
890890
}
891891

892+
/**
893+
* Creates a Cone Emitter for the particle system (emits from the cone to the particle position)
894+
* @param radius The radius of the cone to emit from
895+
* @param angle The base angle of the cone
896+
* @param direction1 Particles are emitted between the direction1 and direction2 from within the cone
897+
* @param direction2 Particles are emitted between the direction1 and direction2 from within the cone
898+
*/
892899
public createDirectedConeEmitter(radius = 1, angle = Math.PI / 4, direction1 = new Vector3(0, 1.0, 0), direction2 = new Vector3(0, 1.0, 0)): ConeDirectedParticleEmitter {
893900
throw new Error("Method not implemented.");
894901
}

packages/dev/core/src/Particles/particleSystem.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ export class ParticleSystem extends ThinParticleSystem {
218218
}
219219
}
220220

221+
/**
222+
* Starts the particle system and begins to emit
223+
* @param delay defines the delay in milliseconds before starting the system (this.startDelay by default)
224+
*/
221225
public override start(delay = this.startDelay): void {
222226
if (!this.canStart()) {
223227
return;
@@ -309,6 +313,14 @@ export class ParticleSystem extends ThinParticleSystem {
309313
return particleEmitter;
310314
}
311315

316+
/**
317+
* Creates a Cone Emitter for the particle system (emits from the cone to the particle position)
318+
* @param radius The radius of the cone to emit from
319+
* @param angle The base angle of the cone
320+
* @param direction1 Particles are emitted between the direction1 and direction2 from within the cone
321+
* @param direction2 Particles are emitted between the direction1 and direction2 from within the cone
322+
* @returns the emitter
323+
*/
312324
public override createDirectedConeEmitter(
313325
radius = 1,
314326
angle = Math.PI / 4,

packages/dev/core/src/Particles/thinParticleSystem.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,9 @@ export class ThinParticleSystem extends BaseParticleSystem implements IDisposabl
495495
return this._indexBuffer;
496496
}
497497

498+
/**
499+
* Gets or sets a texture used to add random noise to particle positions
500+
*/
498501
public override get noiseTexture() {
499502
return this._noiseTexture;
500503
}
@@ -759,6 +762,10 @@ export class ThinParticleSystem extends BaseParticleSystem implements IDisposabl
759762
// Do nothing
760763
};
761764

765+
/**
766+
* Serializes the particle system to a JSON object.
767+
* @param _serializeTexture Whether to serialize the texture information
768+
*/
762769
serialize(_serializeTexture: boolean) {
763770
throw new Error("Method not implemented.");
764771
}
@@ -831,6 +838,9 @@ export class ThinParticleSystem extends BaseParticleSystem implements IDisposabl
831838
}
832839
}
833840

841+
/**
842+
* The amount of time the particle system is running (depends of the overall update speed).
843+
*/
834844
public override get targetStopDuration(): number {
835845
return this._targetStopDuration;
836846
}
@@ -1571,7 +1581,6 @@ export class ThinParticleSystem extends BaseParticleSystem implements IDisposabl
15711581
*/
15721582
public start(delay = this.startDelay): void {
15731583
if (!this.targetStopDuration && this._hasTargetStopDurationDependantGradient()) {
1574-
// eslint-disable-next-line no-throw-literal
15751584
throw "Particle system started with a targetStopDuration dependant gradient (eg. startSizeGradients) but no targetStopDuration set";
15761585
}
15771586
if (delay) {

packages/tools/nodeParticleEditor/src/graphSystem/registerToDisplayLedger.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { TeleportInDisplayManager } from "./display/teleportInDisplayManager";
1111
import { ConditionDisplayManager } from "./display/conditionDisplayManager";
1212
import { TriggerDisplayManager } from "./display/triggerDisplayManager";
1313

14+
/**
15+
* Registers all display managers to the display ledger
16+
*/
1417
export const RegisterToDisplayManagers = () => {
1518
DisplayLedger.RegisteredControls["ParticleInputBlock"] = InputDisplayManager;
1619
DisplayLedger.RegisteredControls["ParticleTextureSourceBlock"] = TextureDisplayManager;
@@ -36,6 +39,7 @@ export const RegisterToDisplayManagers = () => {
3639
DisplayLedger.RegisteredControls["BasicPositionUpdateBlock"] = UpdateDisplayManager;
3740
DisplayLedger.RegisteredControls["BasicSpriteUpdateBlock"] = UpdateDisplayManager;
3841
DisplayLedger.RegisteredControls["BasicColorUpdateBlock"] = UpdateDisplayManager;
42+
DisplayLedger.RegisteredControls["UpdateAttractorBlock"] = UpdateDisplayManager;
3943
DisplayLedger.RegisteredControls["UpdateFlowMapBlock"] = UpdateDisplayManager;
4044
DisplayLedger.RegisteredControls["UpdateNoiseBlock"] = UpdateDisplayManager;
4145
DisplayLedger.RegisteredControls["UpdateRemapBlock"] = UpdateDisplayManager;

0 commit comments

Comments
 (0)