Skip to content

Commit

Permalink
Merge d6aa969 into a145f4d
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-deshpande committed Nov 3, 2020
2 parents a145f4d + d6aa969 commit 9222a44
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
4 changes: 1 addition & 3 deletions sandbox/experiments/gpu-renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ window.init = async ({ scene, camera, renderer }) => {
const spriteRenderer = new SpriteRenderer(scene, THREE);
const pointsRenderer = new GPURenderer(scene, THREE);
const systemRenderer = pointsRenderer;
const system = await System.fromJSONAsync(particleSystemState, THREE, {
shouldAutoEmit: true,
});
const system = await System.fromJSONAsync(particleSystemState, THREE);

return system.addRenderer(systemRenderer);
};
7 changes: 3 additions & 4 deletions src/core/System.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,11 @@ export default class System {
*
* @param {object} json - The JSON to create the System instance from
* @param {object} THREE - The Web GL Api to use eg., THREE
* @param {object} [options={}] - Optional config options
* @param {boolean} [options.shouldAutoEmit=true] - Determines if the system should automatically emit particles
* @param {?object} options - Optional config options
* @return {Promise<System>}
*/
static fromJSONAsync(json, THREE, { shouldAutoEmit = false } = {}) {
return fromJSONAsync(json, THREE, System, Emitter, { shouldAutoEmit });
static fromJSONAsync(json, THREE, options) {
return fromJSONAsync(json, THREE, System, Emitter, options);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/core/fromJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ const makeBehaviours = items => {
/**
* Creates a System instance from a JSON object.
*
* @deprecated Use fromJSONAsync instead.
*
* @param {object} json - The JSON to create the System instance from
* @param {object} THREE - The Web GL Api to use
* @param {function} System - The system class
Expand Down
8 changes: 5 additions & 3 deletions src/core/fromJSONAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
import Rate from '../initializer/Rate';
import TextureInitializer from '../initializer/Texture';

const DEFAULT_OPTIONS = { shouldAutoEmit: true };

/**
* Makes a rate instance.
*
Expand Down Expand Up @@ -202,18 +204,18 @@ const makeEmitters = (emitters, Emitter, THREE, shouldAutoEmit) =>
* @param {object} THREE - The Web GL Api to use
* @param {function} System - The system class
* @param {function} Emitter - The emitter class
* @param {object} options - Optional config options
* @param {boolean} [options.shouldAutoEmit=true] - Determines if the system should automatically emit particles
* @param {object} [options={}] - Optional config options
* @return {Promise<System>}
*/
export default (json, THREE, System, Emitter, { shouldAutoEmit = true } = {}) =>
export default (json, THREE, System, Emitter, options = {}) =>
new Promise((resolve, reject) => {
const {
preParticles = POOL_MAX,
integrationType = EULER,
emitters = [],
} = json;
const system = new System(preParticles, integrationType);
const { shouldAutoEmit } = { ...DEFAULT_OPTIONS, ...options };

makeEmitters(emitters, Emitter, THREE, shouldAutoEmit)
.then(madeEmitters => {
Expand Down
10 changes: 10 additions & 0 deletions test/core/fromJSONAsync.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ describe('fromJSONAsync', () => {
emitSpy.restore();
});

it('should default to shouldAutoEmit is true', async () => {
const emitSpy = spy(Emitter.prototype, 'emit');

await Particles.fromJSONAsync(eightdiagrams, THREE);

assert(emitSpy.called);

emitSpy.restore();
});

it("should not ever call an emitter's emit method if shouldAutoEmit option is false", async () => {
const emitSpy = spy(Emitter.prototype, 'emit');

Expand Down

0 comments on commit 9222a44

Please sign in to comment.