Skip to content

Commit 5d7d1f4

Browse files
committed
fix: node particle system size creation to support centimeters by default
1 parent f4da94c commit 5d7d1f4

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

editor/src/editor/layout/assets-browser.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,10 +804,11 @@ export class EditorAssetsBrowser extends Component<IEditorAssetsBrowserProps, IE
804804
</ContextMenuSubContent>
805805
</ContextMenuSub>
806806

807+
<ContextMenuSeparator />
808+
<ContextMenuItem onClick={() => this._handleAddNodeParticleSystem()}>Node Particle System</ContextMenuItem>
809+
807810
{this.props.editor.state.enableExperimentalFeatures && (
808811
<>
809-
<ContextMenuSeparator />
810-
<ContextMenuItem onClick={() => this._handleAddNodeParticleSystem()}>Node Particle System</ContextMenuItem>
811812
<ContextMenuSeparator />
812813
<ContextMenuItem onClick={() => this._handleAddCinematic()}>Cinematic</ContextMenuItem>
813814
<ContextMenuSeparator />

editor/src/editor/nodes/node-particle-system.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export class NodeParticleSystemSetMesh extends Mesh {
2121
*/
2222
public constructor(name: string, scene: Scene, parent?: Node | null, source?: Mesh, doNotCloneChildren?: boolean, clonePhysicsImpostor?: boolean) {
2323
super(name, scene, parent, source, doNotCloneChildren, clonePhysicsImpostor);
24+
25+
// Set scale to 100 as default unit size is centimeters and particles are in meters
26+
this.scaling.setAll(100);
2427
}
2528

2629
public async buildNodeParticleSystemSet(data: any): Promise<void> {
@@ -47,6 +50,17 @@ export class NodeParticleSystemSetMesh extends Mesh {
4750
particleSystem.id = Tools.RandomId();
4851
particleSystem.uniqueId = UniqueNumber.Get();
4952

53+
if (isParticleSystem(particleSystem)) {
54+
const sizeCreationProcess = particleSystem._sizeCreation.process;
55+
if (sizeCreationProcess) {
56+
particleSystem._sizeCreation.process = (particle, system) => {
57+
sizeCreationProcess(particle, system);
58+
particle.scale.x *= 100;
59+
particle.scale.y *= 100;
60+
};
61+
}
62+
}
63+
5064
if (isParticleSystem(particleSystem) || isGPUParticleSystem(particleSystem)) {
5165
setParticleSystemVisibleInGraph(particleSystem, false);
5266
}

tools/src/loading/node-particle-system-set.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AssetContainer } from "@babylonjs/core/assetContainer";
33
import { AddParser } from "@babylonjs/core/Loading/Plugins/babylonFileParser.function";
44
import { NodeParticleSystemSet } from "@babylonjs/core/Particles/Node/nodeParticleSystemSet";
55

6+
import { isParticleSystem } from "../tools/guards";
67
import { NodeParticleSystemMesh } from "../tools/particle";
78

89
let registered = false;
@@ -40,6 +41,19 @@ export function registerNodeParticleSystemSetParser() {
4041
scene.removePendingData(mesh.id);
4142
instance.particleSystemSet = particleSystemSet;
4243

44+
particleSystemSet.systems.forEach((particleSystem) => {
45+
if (isParticleSystem(particleSystem)) {
46+
const sizeCreationProcess = particleSystem._sizeCreation.process;
47+
if (sizeCreationProcess) {
48+
particleSystem._sizeCreation.process = (particle, system) => {
49+
sizeCreationProcess(particle, system);
50+
particle.scale.x *= 100;
51+
particle.scale.y *= 100;
52+
};
53+
}
54+
}
55+
});
56+
4357
particleSystemSet.emitterNode = instance;
4458
particleSystemSet.start();
4559
});

0 commit comments

Comments
 (0)