New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Particle helper #4288
Particle helper #4288
Changes from 6 commits
6c54e1b
dc4e33c
c8e169e
0e15783
0d4fb51
6aa6044
685db1e
51e6428
7160564
db41d50
e414ae8
2107b32
1c68a4d
8c7d6f3
3434632
24bd715
901d414
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "fire" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
- Add webVR support for Oculus Go ([TrevorDev](https://github.com/TrevorDev)) | ||
- Add ability to not generate polynomials harmonics upon prefiltered texture creation ([sebavan](http://www.github.com/sebavan)) | ||
- Add predicate function to customize the list of mesh included in the computation of bounding vectors in the ```getHierarchyBoundingVectors``` method ([sebavan](http://www.github.com/sebavan)) | ||
- Add webVR constructor options: disable laser pointer toggle, teleportation floor meshes ([TrevorDev](https://github.com/TrevorDev)) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a line in the major update to present your great work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I will do that :) |
||
### glTF Loader | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,4 @@ | |
"base64-font-loader": "0.0.4", | ||
"typescript": "^2.8.1" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
module BABYLON { | ||
/** | ||
* ParticleSystemType | ||
*/ | ||
export enum ParticleSystemType { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed anymore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mhhh I was thinking this was a good idea to let this with the parse method but yeah if a user made a typo is not our fault ^^ |
||
/** | ||
* None is to represents an error in parsing the type string in the create method. | ||
*/ | ||
None, | ||
/** | ||
* Fire particle system. | ||
*/ | ||
Fire, | ||
/** | ||
* Smoke particle system. | ||
*/ | ||
Smoke | ||
} | ||
/** | ||
* This class is made for on one-liner static method to help creating particle systems. | ||
*/ | ||
export class ParticleHelper { | ||
/** | ||
* Base Assets URL. | ||
*/ | ||
private static _baseAssetsUrl = "https://assets.babylonjs.com/particles/"; | ||
|
||
private static _scene: Scene; | ||
|
||
private static _emitter: AbstractMesh; | ||
|
||
/** | ||
* This is the main static method (one-liner) of this helper to create different particle systems. | ||
* @param type This string will be parsed to a ParticleSystemType | ||
* @param emitter The object where the particle system will start to emit from. | ||
* @param scene The scene where the particle system should live. | ||
* @param gpu If the system will use gpu. | ||
* @returns the ParticleSystem created. | ||
*/ | ||
public static Create(type: string, emitter: AbstractMesh, scene: Nullable<Scene> = Engine.LastCreatedScene, gpu: boolean = false): ParticleSystem { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would rather prefer having a json file loaded where you can find fire or smoke parameters Does it make sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I understand that, but how can I properly load a JSON file (I already created it in assets/particles)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create will be async and you can just call Tools.LoadFile to get the content of the json file (from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh okay, i haven't see that, thanks you :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But, can I know why you prefer async method + JSON file over a simple synchronous method? |
||
const typeParsed = this._parseType(type); | ||
if (typeParsed === ParticleSystemType.None) { | ||
throw new Error("This particle system type doesn't exist."); | ||
} | ||
|
||
if (scene) { | ||
this._scene = scene; | ||
} else { | ||
throw new Error("A particle system need a scene."); | ||
} | ||
|
||
this._emitter = emitter; | ||
|
||
switch (typeParsed) { | ||
case ParticleSystemType.Fire: | ||
return this._createFire(); | ||
case ParticleSystemType.Smoke: | ||
return this._createSmoke(); | ||
default: | ||
throw new Error("Not yet implemented."); | ||
} | ||
} | ||
|
||
private static _parseType(type: string): ParticleSystemType { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed |
||
switch (type) { | ||
case "fire": | ||
case "Fire": | ||
case "FIRE": | ||
return ParticleSystemType.Fire; | ||
case "smoke": | ||
case "Smoke": | ||
case "SMOKE": | ||
return ParticleSystemType.Smoke; | ||
default: | ||
return ParticleSystemType.None; | ||
} | ||
} | ||
|
||
private static _createFire(): ParticleSystem { | ||
// Create a particle system | ||
const fireSystem = new ParticleSystem("particles", 2000, this._scene); | ||
// Texture of each particle | ||
fireSystem.particleTexture = new Texture(`${this._baseAssetsUrl}textures/flare.png`, this._scene); | ||
// Where the particles come from | ||
fireSystem.emitter = this._emitter; // the starting object, the emitter | ||
fireSystem.minEmitBox = new Vector3(-0.5, 1, -0.5); // Starting all from | ||
fireSystem.maxEmitBox = new Vector3(0.5, 1, 0.5); // To... | ||
|
||
// Colors of all particles | ||
fireSystem.color1 = new Color4(1, 0.5, 0, 1.0); | ||
fireSystem.color2 = new Color4(1, 0.5, 0, 1.0); | ||
fireSystem.colorDead = new Color4(0, 0, 0, 0.0); | ||
|
||
// Size of each particle (random between... | ||
fireSystem.minSize = 0.3; | ||
fireSystem.maxSize = 1; | ||
|
||
// Life time of each particle (random between... | ||
fireSystem.minLifeTime = 0.2; | ||
fireSystem.maxLifeTime = 0.4; | ||
|
||
// Emission rate | ||
fireSystem.emitRate = 600; | ||
|
||
// Blend mode : BLENDMODE_ONEONE, or BLENDMODE_STANDARD | ||
fireSystem.blendMode = ParticleSystem.BLENDMODE_ONEONE; | ||
|
||
// Set the gravity of all particles | ||
fireSystem.gravity = new Vector3(0, 0, 0); | ||
|
||
// Direction of each particle after it has been emitted | ||
fireSystem.direction1 = new Vector3(0, 4, 0); | ||
fireSystem.direction2 = new Vector3(0, 4, 0); | ||
|
||
// Angular speed, in radians | ||
fireSystem.minAngularSpeed = 0; | ||
fireSystem.maxAngularSpeed = Math.PI; | ||
|
||
// Speed | ||
fireSystem.minEmitPower = 1; | ||
fireSystem.maxEmitPower = 3; | ||
fireSystem.updateSpeed = 0.007; | ||
|
||
return fireSystem; | ||
} | ||
|
||
private static _createSmoke(): ParticleSystem { | ||
const smokeSystem = new ParticleSystem("smoke", 1000, this._scene); | ||
smokeSystem.particleTexture = new Texture(`${this._baseAssetsUrl}textures/flare.png`, this._scene); | ||
smokeSystem.emitter = this._emitter; | ||
smokeSystem.minEmitBox = new Vector3(-0.5, 1, -0.5); | ||
smokeSystem.maxEmitBox = new Vector3(0.5, 1, 0.5); | ||
|
||
smokeSystem.color1 = new Color4(0.1, 0.1, 0.1, 1.0); | ||
smokeSystem.color2 = new Color4(0.1, 0.1, 0.1, 1.0); | ||
smokeSystem.colorDead = new Color4(0, 0, 0, 0.0); | ||
|
||
smokeSystem.minSize = 0.3; | ||
smokeSystem.maxSize = 1; | ||
|
||
smokeSystem.minLifeTime = 0.3; | ||
smokeSystem.maxLifeTime = 1.5; | ||
|
||
smokeSystem.emitRate = 350; | ||
|
||
smokeSystem.blendMode = ParticleSystem.BLENDMODE_ONEONE; | ||
|
||
smokeSystem.gravity = new Vector3(0, 0, 0); | ||
|
||
smokeSystem.direction1 = new Vector3(-1.5, 8, -1.5); | ||
smokeSystem.direction2 = new Vector3(1.5, 8, 1.5); | ||
|
||
smokeSystem.minAngularSpeed = 0; | ||
smokeSystem.maxAngularSpeed = Math.PI; | ||
|
||
smokeSystem.minEmitPower = 0.5; | ||
smokeSystem.maxEmitPower = 1.5; | ||
smokeSystem.updateSpeed = 0.005; | ||
|
||
return smokeSystem; | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should just rely on particles actually
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that's what I said I was not sure at all what to do here so just :
is good?