-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix particle container issue (#11006)
- Loading branch information
1 parent
c689a4d
commit 8616384
Showing
2 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
92 changes: 92 additions & 0 deletions
92
tests/renderering/particle-container/ParticleContainer.test.ts
This file contains 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,92 @@ | ||
import { Rectangle } from '../../../src/maths/shapes/Rectangle'; | ||
import { Texture } from '../../../src/rendering/renderers/shared/texture/Texture'; | ||
import { Container } from '../../../src/scene/container/Container'; | ||
import { Particle } from '../../../src/scene/particle-container/shared/Particle'; | ||
import { ParticleContainer } from '../../../src/scene/particle-container/shared/ParticleContainer'; | ||
import { getWebGLRenderer } from '../../utils/getRenderer'; | ||
|
||
describe('ParticleContainer', () => | ||
{ | ||
describe('constructor', () => | ||
{ | ||
it('should support no arguments', () => | ||
{ | ||
const container = new ParticleContainer(); | ||
|
||
expect(container).toBeDefined(); | ||
expect(container.texture).toEqual(null); | ||
|
||
container.destroy(); | ||
}); | ||
|
||
it('should support options with no texture', () => | ||
{ | ||
const container = new ParticleContainer({ | ||
texture: Texture.WHITE, | ||
}); | ||
|
||
expect(container).toBeDefined(); | ||
expect(container.texture).toEqual(Texture.WHITE); | ||
|
||
container.destroy(); | ||
}); | ||
}); | ||
|
||
describe('destroy', () => | ||
{ | ||
it('should not throw when destroyed', () => | ||
{ | ||
const container = new ParticleContainer(); | ||
|
||
expect(() => container.destroy()).not.toThrow(); | ||
}); | ||
|
||
it('should clean up correctly on the pipe and system when destroyed', async () => | ||
{ | ||
const renderer = await getWebGLRenderer(); | ||
|
||
const container = new Container(); | ||
|
||
const particleContainer = new ParticleContainer(); | ||
|
||
particleContainer.addParticle(new Particle({ | ||
texture: Texture.WHITE | ||
})); | ||
|
||
container.addChild(particleContainer); | ||
|
||
renderer.render({ container }); | ||
|
||
particleContainer.destroy(); | ||
|
||
expect(renderer.renderPipes.particle['_gpuBufferHash'][particleContainer.uid]).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('width', () => | ||
{ | ||
it('should set width correctly if no bounds is set', () => | ||
{ | ||
const container = new ParticleContainer(); | ||
|
||
container.width = 100; | ||
|
||
// this should be 0 as no bounds have been specified | ||
expect(container.width).toEqual(0); | ||
}); | ||
|
||
it('should set bounds on the constructor', () => | ||
{ | ||
const container = new ParticleContainer({ | ||
texture: Texture.WHITE, | ||
boundsArea: new Rectangle(0, 0, 50, 100), | ||
}); | ||
|
||
expect(container.width).toEqual(50); | ||
expect(container.height).toEqual(100); | ||
|
||
container.width = 100; | ||
expect(container.width).toEqual(100); | ||
}); | ||
}); | ||
}); |