Skip to content

Commit f3364bc

Browse files
deltakoshDavid Catuhe
andauthored
Adding support for texture in NPE converter (#17042)
Co-authored-by: David Catuhe <[email protected]>
1 parent 9294a45 commit f3364bc

File tree

17 files changed

+251
-95
lines changed

17 files changed

+251
-95
lines changed

packages/dev/buildTools/src/webpackTools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export const commonDevWebpackConfiguration = (
198198
let plugins: WebpackPluginInstance[] | undefined = additionalPlugins;
199199
if (devServerConfig && enableHotReload) {
200200
plugins = plugins ?? [];
201-
plugins.push(new ReactRefreshWebpackPlugin());
201+
plugins.push(new ReactRefreshWebpackPlugin({ overlay: !process.env.DISABLE_DEV_OVERLAY }));
202202
}
203203

204204
return {

packages/dev/core/src/Particles/Node/Blocks/Emitters/createParticleBlock.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class CreateParticleBlock extends NodeParticleBlock {
2828
this.registerInput("emitPower", NodeParticleBlockConnectionPointTypes.Float, true, 1);
2929
this.registerInput("lifeTime", NodeParticleBlockConnectionPointTypes.Float, true, 1);
3030
this.registerInput("color", NodeParticleBlockConnectionPointTypes.Color4, true, new Color4(1, 1, 1, 1));
31+
this.registerInput("colorDead", NodeParticleBlockConnectionPointTypes.Color4, true, new Color4(0, 0, 0, 0));
3132
this.registerInput("scale", NodeParticleBlockConnectionPointTypes.Vector2, true, new Vector2(1, 1));
3233
this.registerInput("angle", NodeParticleBlockConnectionPointTypes.Float, true, 0);
3334
this.registerOutput("particle", NodeParticleBlockConnectionPointTypes.Particle);
@@ -62,18 +63,25 @@ export class CreateParticleBlock extends NodeParticleBlock {
6263
return this._inputs[2];
6364
}
6465

66+
/**
67+
* Gets the color dead input component
68+
*/
69+
public get colorDead(): NodeParticleConnectionPoint {
70+
return this._inputs[3];
71+
}
72+
6573
/**
6674
* Gets the scale input component
6775
*/
6876
public get scale(): NodeParticleConnectionPoint {
69-
return this._inputs[3];
77+
return this._inputs[4];
7078
}
7179

7280
/**
7381
* Gets the angle input component
7482
*/
7583
public get angle(): NodeParticleConnectionPoint {
76-
return this._inputs[4];
84+
return this._inputs[5];
7785
}
7886

7987
/**
@@ -100,7 +108,10 @@ export class CreateParticleBlock extends NodeParticleBlock {
100108
system._colorCreation.process = (particle: Particle) => {
101109
state.particleContext = particle;
102110
particle.color.copyFrom(this.color.getConnectedValue(state));
103-
particle.colorStep.copyFrom(particle.color);
111+
system.colorDead.copyFrom(this.colorDead.getConnectedValue(state));
112+
particle.initialColor.copyFrom(particle.color);
113+
system.colorDead.subtractToRef(particle.initialColor, system._colorDiff);
114+
system._colorDiff.scaleToRef(1.0 / particle.lifeTime, particle.colorStep);
104115
};
105116

106117
system._sizeCreation.process = (particle: Particle) => {

packages/dev/core/src/Particles/Node/Blocks/Emitters/meshShapeBlock.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ export class MeshShapeBlock extends NodeParticleBlock implements IShapeBlock {
238238
bu * TmpVectors.Vector4[0].w + bv * TmpVectors.Vector4[1].w + bw * TmpVectors.Vector4[2].w
239239
);
240240

241-
particle.colorStep.copyFrom(particle.color);
241+
particle.initialColor.copyFrom(particle.color);
242+
system.colorDead.subtractToRef(particle.initialColor, system._colorDiff);
243+
system._colorDiff.scaleToRef(1.0 / particle.lifeTime, particle.colorStep);
242244
}
243245
};
244246

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { RegisterClass } from "../../../../Misc/typeStore";
2+
import { NodeParticleBlockConnectionPointTypes } from "../../Enums/nodeParticleBlockConnectionPointTypes";
3+
import { NodeParticleBlock } from "../../nodeParticleBlock";
4+
import type { NodeParticleConnectionPoint } from "../../nodeParticleBlockConnectionPoint";
5+
import type { NodeParticleBuildState } from "../../nodeParticleBuildState";
6+
import type { ThinParticleSystem } from "core/Particles/thinParticleSystem";
7+
import type { Particle } from "core/Particles/particle";
8+
import { _ConnectAtTheEnd } from "core/Particles/Queue/executionQueue";
9+
10+
/**
11+
* Block used to provide the basic update functionality for particle colors.
12+
*/
13+
export class BasicColorUpdateBlock extends NodeParticleBlock {
14+
/**
15+
* Create a new UpdateScaleBlock
16+
* @param name defines the block name
17+
*/
18+
public constructor(name: string) {
19+
super(name);
20+
21+
this.registerInput("particle", NodeParticleBlockConnectionPointTypes.Particle);
22+
this.registerOutput("output", NodeParticleBlockConnectionPointTypes.Particle);
23+
}
24+
25+
/**
26+
* Gets the particle component
27+
*/
28+
public get particle(): NodeParticleConnectionPoint {
29+
return this._inputs[0];
30+
}
31+
32+
/**
33+
* Gets the output component
34+
*/
35+
public get output(): NodeParticleConnectionPoint {
36+
return this._outputs[0];
37+
}
38+
39+
/**
40+
* Gets the current class name
41+
* @returns the class name
42+
*/
43+
public override getClassName() {
44+
return "BasicColorUpdateBlock";
45+
}
46+
47+
/**
48+
* Builds the block
49+
* @param state defines the current build state
50+
*/
51+
public override _build(state: NodeParticleBuildState) {
52+
const system = this.particle.getConnectedValue(state) as ThinParticleSystem;
53+
54+
const processColor = (particle: Particle) => {
55+
state.particleContext = particle;
56+
state.systemContext = system;
57+
58+
particle.colorStep.scaleToRef(system._scaledUpdateSpeed, system._scaledColorStep);
59+
particle.color.addInPlace(system._scaledColorStep);
60+
61+
if (particle.color.a < 0) {
62+
particle.color.a = 0;
63+
}
64+
};
65+
66+
const colorProcessing = {
67+
process: processColor,
68+
previousItem: null,
69+
nextItem: null,
70+
};
71+
72+
if (system._updateQueueStart) {
73+
_ConnectAtTheEnd(colorProcessing, system._updateQueueStart);
74+
} else {
75+
system._updateQueueStart = colorProcessing;
76+
}
77+
78+
this.output._storedValue = system;
79+
}
80+
}
81+
82+
RegisterClass("BABYLON.BasicColorUpdateBlock", BasicColorUpdateBlock);

packages/dev/core/src/Particles/Node/Blocks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export * from "./Update/updateAngleBlock";
1212
export * from "./Update/updateAgeBlock";
1313
export * from "./Update/basicPositionUpdateBlock";
1414
export * from "./Update/basicSpriteUpdateBlock";
15+
export * from "./Update/basicColorUpdateBlock";
1516
export * from "./Update/updateSpriteCellIndexBlock";
1617
export * from "./Update/updateFlowMapBlock";
1718
export * from "./Update/updateAttractorBlock";

packages/dev/core/src/Particles/Node/Blocks/particleInputBlock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export class ParticleInputBlock extends NodeParticleBlock {
137137
break;
138138
case NodeParticleContextualSources.Color:
139139
case NodeParticleContextualSources.InitialColor:
140+
case NodeParticleContextualSources.ColorDead:
140141
this._type = NodeParticleBlockConnectionPointTypes.Color4;
141142
break;
142143
case NodeParticleContextualSources.Age:

packages/dev/core/src/Particles/Node/Blocks/particleSourceTextureBlock.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import type { NodeParticleConnectionPoint } from "../nodeParticleBlockConnection
66
import type { NodeParticleBuildState } from "../nodeParticleBuildState";
77
import type { Nullable } from "core/types";
88
import { TextureTools } from "core/Misc/textureTools";
9+
import type { BaseTexture } from "../../../Materials/Textures/baseTexture";
910

1011
/**
1112
* Block used to provide a texture for particles in a particle system
1213
*/
1314
export class ParticleTextureSourceBlock extends NodeParticleBlock {
1415
private _url: string = "";
1516
private _textureDataUrl: string = "";
16-
private _sourceTexture: Nullable<Texture> = null;
17+
private _sourceTexture: Nullable<BaseTexture> = null;
1718
private _cachedData: Nullable<{
1819
width: number;
1920
height: number;
@@ -65,13 +66,13 @@ export class ParticleTextureSourceBlock extends NodeParticleBlock {
6566
* Directly sets the texture to be used by this block.
6667
* This value will not be serialized.
6768
*/
68-
public set sourceTexture(value: Nullable<Texture>) {
69+
public set sourceTexture(value: Nullable<BaseTexture>) {
6970
if (this._sourceTexture === value) {
7071
return;
7172
}
7273
this._cachedData = null;
7374
this._sourceTexture = value;
74-
this._url = "";
75+
this._url = (value as Texture).url || "";
7576
this._textureDataUrl = "";
7677
}
7778

@@ -105,15 +106,15 @@ export class ParticleTextureSourceBlock extends NodeParticleBlock {
105106
* @returns a promise that resolves to the texture content, including width, height, and pixel data
106107
*/
107108
async extractTextureContentAsync() {
108-
if (!this.texture._storedValue) {
109+
if (!this.texture._storedValue && !this._sourceTexture) {
109110
return null;
110111
}
111112

112113
if (this._cachedData) {
113114
return this._cachedData;
114115
}
115116

116-
const texture = this.texture._storedValue;
117+
const texture = this.texture._storedValue || this._sourceTexture;
117118
return await new Promise<
118119
Nullable<{
119120
width: number;

packages/dev/core/src/Particles/Node/Enums/nodeParticleContextualSources.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ export enum NodeParticleContextualSources {
3131
SpriteCellEnd = 0x0012,
3232
/** Initial Color */
3333
InitialColor = 0x0013,
34+
/** Color Dead*/
35+
ColorDead = 0x0014,
3436
}

packages/dev/core/src/Particles/Node/nodeParticleBuildState.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ export class NodeParticleBuildState {
120120
case NodeParticleContextualSources.Color:
121121
return this.particleContext.color;
122122
case NodeParticleContextualSources.InitialColor:
123-
return this.particleContext.colorStep;
123+
return this.particleContext.initialColor;
124+
case NodeParticleContextualSources.ColorDead:
125+
return this.systemContext.colorDead;
124126
case NodeParticleContextualSources.Age:
125127
return this.particleContext.age;
126128
case NodeParticleContextualSources.Lifetime:

0 commit comments

Comments
 (0)