Skip to content

Commit 45b1ab5

Browse files
deltakoshDavid Catuhe
andauthored
Fix color being overwritten by Createparticle (#17027)
Co-authored-by: David Catuhe <[email protected]>
1 parent 9737480 commit 45b1ab5

File tree

11 files changed

+44
-5
lines changed

11 files changed

+44
-5
lines changed

.build/config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"versionDefinition": "minor",
3-
"preid": "rc",
4-
"nonce": 404
5-
}
2+
"versionDefinition": "patch",
3+
"preid": "rc",
4+
"nonce": 405
5+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export class CreateParticleBlock extends NodeParticleBlock {
100100
system._colorCreation.process = (particle: Particle) => {
101101
state.particleContext = particle;
102102
particle.color.copyFrom(this.color.getConnectedValue(state));
103+
particle.colorStep.copyFrom(particle.color);
103104
};
104105

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

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export class MeshShapeBlock extends NodeParticleBlock implements IShapeBlock {
4242
@editableInPropertyPage("Use vertex color for color", PropertyTypeForEdition.Boolean, "ADVANCED", { embedded: true, notifiers: { rebuild: true } })
4343
public useMeshColorForColor = false;
4444

45+
/**
46+
* Gets or sets a boolean indicating if the coordinates should be in world space (local space by default)
47+
*/
48+
@editableInPropertyPage("World space", PropertyTypeForEdition.Boolean, "ADVANCED", { embedded: true, notifiers: { rebuild: true } })
49+
public worldSpace = false;
50+
4551
/**
4652
* Gets or sets the mesh to use to get vertex data
4753
*/
@@ -143,6 +149,10 @@ export class MeshShapeBlock extends NodeParticleBlock implements IShapeBlock {
143149
this._normals = this._cachedVertexData.normals;
144150
this._colors = this._cachedVertexData.colors;
145151

152+
if (this.useMeshColorForColor && this._colors) {
153+
system._colorCreation.process = () => {};
154+
}
155+
146156
system._directionCreation.process = (particle: Particle) => {
147157
state.particleContext = particle;
148158
state.systemContext = system;
@@ -196,6 +206,10 @@ export class MeshShapeBlock extends NodeParticleBlock implements IShapeBlock {
196206
randomVertex.y = bu * vertexA.y + bv * vertexB.y + bw * vertexC.y;
197207
randomVertex.z = bu * vertexA.z + bv * vertexB.z + bw * vertexC.z;
198208

209+
if (this.worldSpace && this.mesh) {
210+
Vector3.TransformCoordinatesFromFloatsToRef(randomVertex.x, randomVertex.y, randomVertex.z, this.mesh.getWorldMatrix(), randomVertex);
211+
}
212+
199213
if (state.isEmitterTransformNode) {
200214
Vector3.TransformCoordinatesFromFloatsToRef(randomVertex.x, randomVertex.y, randomVertex.z, state.emitterWorldMatrix!, particle.position);
201215
} else {
@@ -223,6 +237,8 @@ export class MeshShapeBlock extends NodeParticleBlock implements IShapeBlock {
223237
bu * TmpVectors.Vector4[0].z + bv * TmpVectors.Vector4[1].z + bw * TmpVectors.Vector4[2].z,
224238
bu * TmpVectors.Vector4[0].w + bv * TmpVectors.Vector4[1].w + bw * TmpVectors.Vector4[2].w
225239
);
240+
241+
particle.colorStep.copyFrom(particle.color);
226242
}
227243
};
228244

@@ -247,6 +263,7 @@ export class MeshShapeBlock extends NodeParticleBlock implements IShapeBlock {
247263

248264
serializationObject.useMeshNormalsForDirection = this.useMeshNormalsForDirection;
249265
serializationObject.useMeshColorForColor = this.useMeshColorForColor;
266+
serializationObject.worldSpace = this.worldSpace;
250267

251268
return serializationObject;
252269
}
@@ -261,6 +278,7 @@ export class MeshShapeBlock extends NodeParticleBlock implements IShapeBlock {
261278
this.serializedCachedData = !!serializationObject.serializedCachedData;
262279
this.useMeshNormalsForDirection = !!serializationObject.useMeshNormalsForDirection;
263280
this.useMeshColorForColor = !!serializationObject.useMeshColorForColor;
281+
this.worldSpace = !!serializationObject.worldSpace;
264282
}
265283
}
266284

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

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ export enum NodeParticleContextualSources {
2929
SpriteCellStart = 0x0011,
3030
/** SpriteCellEnd */
3131
SpriteCellEnd = 0x0012,
32+
/** Initial Color */
33+
InitialColor = 0x0013,
3234
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ export class NodeParticleBuildState {
119119
return this.systemContext._scaledDirection;
120120
case NodeParticleContextualSources.Color:
121121
return this.particleContext.color;
122+
case NodeParticleContextualSources.InitialColor:
123+
return this.particleContext.colorStep;
122124
case NodeParticleContextualSources.Age:
123125
return this.particleContext.age;
124126
case NodeParticleContextualSources.Lifetime:

packages/tools/nodeParticleEditor/src/blockTools.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ export class BlockTools {
176176
block.contextualValue = NodeParticleContextualSources.Color;
177177
return block;
178178
}
179+
case "InitialColorBlock": {
180+
const block = new ParticleInputBlock("Initial Color");
181+
block.contextualValue = NodeParticleContextualSources.InitialColor;
182+
return block;
183+
}
179184
case "AgeBlock": {
180185
const block = new ParticleInputBlock("Age");
181186
block.contextualValue = NodeParticleContextualSources.Age;

packages/tools/nodeParticleEditor/src/components/nodeList/nodeListComponent.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class NodeListComponent extends React.Component<INodeListComponentProps,
5151
DirectionBlock: "Contextual block to get the direction of a particle",
5252
ScaledDirectionBlock: "Contextual block to get the scaled direction of a particle",
5353
ColorBlock: "Contextual block to get the color of a particle",
54+
InitialColorBlock: "Contextual block to get the initial color of a particle",
5455
AgeBlock: "Contextual block to get the age of a particle",
5556
AngleBlock: "Contextual block to get the angle of a particle",
5657
LifetimeBlock: "Contextual block to get the lifetime of a particle",
@@ -260,6 +261,7 @@ export class NodeListComponent extends React.Component<INodeListComponentProps,
260261
"ScaleBlock",
261262
"AgeGradientBlock",
262263
"AngleBlock",
264+
"InitialColorBlock",
263265
"SpriteCellEndBlock",
264266
"SpriteCellStartBlock",
265267
"SpriteCellIndexBlock",

packages/tools/nodeParticleEditor/src/graphSystem/display/inputDisplayManager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ export class InputDisplayManager implements IDisplayManager {
9898
case NodeParticleContextualSources.Color:
9999
value = "Color";
100100
break;
101+
case NodeParticleContextualSources.InitialColor:
102+
value = "Initial Color";
103+
break;
101104
case NodeParticleContextualSources.SpriteCellEnd:
102105
value = "Sprite Cell End";
103106
break;

packages/tools/nodeParticleEditor/src/graphSystem/properties/inputNodePropertyComponent.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ export class InputPropertyTabComponent extends React.Component<IPropertyComponen
147147
systemSourcesOptions = [{ label: "Emitter", value: NodeParticleSystemSources.Emitter }];
148148
break;
149149
case NodeParticleBlockConnectionPointTypes.Color4:
150-
contextualSourcesOptions = [{ label: "Color", value: NodeParticleContextualSources.Color }];
150+
contextualSourcesOptions = [
151+
{ label: "Color", value: NodeParticleContextualSources.Color },
152+
{ label: "Initial Color", value: NodeParticleContextualSources.InitialColor },
153+
];
151154
break;
152155
}
153156

0 commit comments

Comments
 (0)