-
Notifications
You must be signed in to change notification settings - Fork 2k
Recalculate particle local bounds when the spawn volume changes #9192
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| import { expect } from 'chai'; | ||
|
|
||
| import { Curve } from '../../../src/core/math/curve.js'; | ||
| import { Vec3 } from '../../../src/core/math/vec3.js'; | ||
| import { Entity } from '../../../src/framework/entity.js'; | ||
| import { EMITTERSHAPE_SPHERE } from '../../../src/scene/constants.js'; | ||
| import { createApp } from '../../app.mjs'; | ||
| import { jsdomSetup, jsdomTeardown } from '../../jsdom.mjs'; | ||
|
|
||
| /** | ||
| * @import { Application } from '../../../src/framework/application.js' | ||
| */ | ||
|
|
||
| describe('ParticleEmitter', function () { | ||
| /** @type {Application} */ | ||
| let app; | ||
|
|
||
| beforeEach(function () { | ||
| jsdomSetup(); | ||
| app = createApp(); | ||
|
|
||
| // the null device skips particle systems by default - enable them so the emitter is created | ||
| app.graphicsDevice.disableParticleSystem = false; | ||
| }); | ||
|
|
||
| afterEach(function () { | ||
| app?.destroy(); | ||
| app = null; | ||
| jsdomTeardown(); | ||
| }); | ||
|
|
||
| /** | ||
| * @param {object} [options] - Particle system component options. | ||
| * @param {boolean} [gpu] - Whether the emitter simulates on the GPU. | ||
| * @returns {import('../../../src/scene/particle-system/particle-emitter.js').ParticleEmitter} The emitter. | ||
| */ | ||
| const createEmitter = (options = {}, gpu = true) => { | ||
| app.graphicsDevice.supportsGpuParticles = gpu; | ||
| const entity = new Entity(); | ||
| entity.addComponent('particlesystem', { numParticles: 10, ...options }); | ||
| app.root.addChild(entity); | ||
| return entity.particlesystem.emitter; | ||
| }; | ||
|
|
||
| describe('#localBounds', function () { | ||
|
|
||
| it('grows when emitterExtents is replaced', function () { | ||
| const emitter = createEmitter({ emitterExtents: new Vec3(1, 1, 1) }); | ||
| const before = emitter.localBounds.halfExtents.x; | ||
|
|
||
| emitter.node.particlesystem.emitterExtents = new Vec3(100, 100, 100); | ||
| emitter.addTime(0.1, false); | ||
|
|
||
| expect(emitter.localBounds.halfExtents.x).to.be.above(before + 40); | ||
| }); | ||
|
|
||
| it('grows when emitterExtents is modified in place', function () { | ||
| const emitter = createEmitter({ emitterExtents: new Vec3(1, 1, 1) }); | ||
| const before = emitter.localBounds.halfExtents.x; | ||
|
|
||
| // the extents are handed to the emitter by reference, so an in place change must be | ||
| // detected as well | ||
| emitter.node.particlesystem.emitterExtents.set(100, 100, 100); | ||
| emitter.addTime(0.1, false); | ||
|
|
||
| expect(emitter.localBounds.halfExtents.x).to.be.above(before + 40); | ||
| }); | ||
|
|
||
| it('grows when emitterRadius changes on a sphere emitter', function () { | ||
| const emitter = createEmitter({ emitterShape: EMITTERSHAPE_SPHERE, emitterRadius: 1 }); | ||
| const before = emitter.localBounds.halfExtents.x; | ||
|
|
||
| emitter.node.particlesystem.emitterRadius = 100; | ||
| emitter.addTime(0.1, false); | ||
|
|
||
| expect(emitter.localBounds.halfExtents.x).to.be.above(before + 40); | ||
| }); | ||
|
|
||
| it('grows when emitterExtents changes on a CPU emitter', function () { | ||
| const emitter = createEmitter({ emitterExtents: new Vec3(1, 1, 1) }, false); | ||
| expect(emitter.useCpu).to.be.true; | ||
| const before = emitter.localBounds.halfExtents.x; | ||
|
|
||
| emitter.node.particlesystem.emitterExtents = new Vec3(100, 100, 100); | ||
| emitter.addTime(0.1, false); | ||
|
|
||
| expect(emitter.localBounds.halfExtents.x).to.be.above(before + 40); | ||
| expect(emitter.meshInstance.aabb.halfExtents.x).to.be.above(before + 40); | ||
| }); | ||
|
|
||
| it('is not recalculated while the spawn volume is unchanged', function () { | ||
| const emitter = createEmitter({ emitterExtents: new Vec3(1, 1, 1) }); | ||
|
|
||
| emitter.node.particlesystem.emitterExtents = new Vec3(100, 100, 100); | ||
| emitter.addTime(0.1, false); | ||
|
|
||
| let calls = 0; | ||
| const calculateLocalBounds = emitter.calculateLocalBounds.bind(emitter); | ||
| emitter.calculateLocalBounds = () => { | ||
| calls++; | ||
| calculateLocalBounds(); | ||
| }; | ||
|
|
||
| for (let i = 0; i < 5; i++) { | ||
| emitter.addTime(0.1, false); | ||
| } | ||
|
|
||
| expect(calls).to.equal(0); | ||
| }); | ||
|
|
||
| it('grows when the scale curve changes', function () { | ||
| const emitter = createEmitter(); | ||
| const before = emitter.localBounds.halfExtents.x; | ||
|
|
||
| emitter.node.particlesystem.scaleGraph = new Curve([0, 100, 1, 100]); | ||
|
|
||
| expect(emitter.localBounds.halfExtents.x).to.be.above(before + 40); | ||
| }); | ||
|
|
||
| it('grows when only the secondary scale curve changes', function () { | ||
| const emitter = createEmitter(); | ||
| const before = emitter.localBounds.halfExtents.x; | ||
|
|
||
| // the rendered size is interpolated between both scale curves | ||
| emitter.node.particlesystem.scaleGraph2 = new Curve([0, 100, 1, 100]); | ||
|
|
||
| expect(emitter.localBounds.halfExtents.x).to.be.above(before + 40); | ||
| }); | ||
|
|
||
| it('covers the magnitude of a negative scale curve', function () { | ||
| const emitter = createEmitter(); | ||
|
|
||
| // a negative scale mirrors the particle without shrinking it | ||
| emitter.node.particlesystem.scaleGraph = new Curve([0, -100, 1, -100]); | ||
|
|
||
| expect(emitter.localBounds.halfExtents.x).to.be.above(40); | ||
| }); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.