Skip to content

Updated PixiRenderer to v8 #110

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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .github/workflows/node.js.yml

This file was deleted.

64 changes: 51 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,15 @@ Check out examples at [http://drawcall.github.io/Proton/](http://drawcall.github

## Features

- **Easy to use** It takes only a dozen lines of code to create a particle animation effect.
- **Multiple effects** Use Proton to create flames, fireworks, bullets, explosions, and more.
- **Any scene** You can use it in frameworks such as `react`, `vue`, `angular`, and `pixi.js`, `Phaser`, etc.
- **Efficient rendering** Its rendering efficiency is very high, you can render tens of thousands of particles in the page.
- **Simulated physics** Proton can simulate various physical properties including gravity and Brownian motion.
- **Several renderers** Proton provides a variety of renderers, of course you can also customize your own renderer
- `CanvasRenderer` - Proton's canvas renderer
- `DomRenderer` - Proton's dom renderer, supporting hardware acceleration.
- `WebGLRenderer` - Proton's webgl renderer.
- `PixelRenderer` - Proton's pixel renderer, It can implement pixel animation.
- `EaselRenderer` - Easeljs proton renderer.
- `EaselRenderer` - Pixi.js proton renderer.
- `CustomRenderer` - Use a custom renderer that can be applied to any scene.
- **Easy to use** - Particles can be emitted from a point, line, rectangle, circle, etc.
- **Powerful** - 16 different kinds of renderers, also you can easily customize your own renderer.
- **Three.js support** - Check out [three.proton](https://github.com/drawcall/three.proton/)
- **Perfect performance** - Push your particles to the max.
- **Reactive** - Watch and run emitters based on changes to properties.
- **Customizable** - Use your own update function, initialize function, particle factory, and renderer.
- **Compatibility** - Support for both Canvas, DOM, WebGL, Pixi.js (up to v8), EaselJS, and custom renderers.

> **Note:** If you need 3D particle effects, please use [three.proton](https://github.com/drawcall/three.proton/).

## Documentation

Expand Down Expand Up @@ -113,6 +109,48 @@ const renderer = new CanvasRenderer(canvas);
proton.addRenderer(renderer);
```

### Rendering with Pixi.js v8

Pixi.js v8 introduced several breaking changes to its API, particularly in the Graphics API. Proton Engine 7.2.0+ fully supports Pixi.js v8 with a new, compatible PixiRenderer.

```javascript
// Create a Pixi.js v8 application (using async initialization)
const app = new PIXI.Application();
(async function() {
// Initialize the Pixi app
await app.init({
resizeTo: window,
background: '#000',
antialias: true
});

document.body.appendChild(app.canvas);

// Create a Proton instance
// When using in browser with script tags, make sure to include proton.web.js
const proton = new Proton();

// Create an emitter
const emitter = new Proton.Emitter();
// Configure your emitter...

// Add the Pixi.js renderer to Proton
const renderer = new Proton.PixiRenderer(app.stage);
proton.addRenderer(renderer);

// Start the emitter
emitter.emit();
proton.addEmitter(emitter);

// Update Proton in the Pixi.js animation loop
app.ticker.add(() => {
proton.update();
});
})();
```

Check out a complete example in `example/pixiv8.html`.

## Remarks

- `Proton.Span` (or `Proton.getSpan`) is a very important concept of the Proton engine, it's everywhere. If you understand its usage, you can create almost any desired effect!
Expand Down
64 changes: 52 additions & 12 deletions build/proton.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1849,22 +1849,43 @@ declare class Emitter$1 extends Particle$1 {
dispatch(event: any, target: any): void;
emitting(time: any): void;
/**
* Creates a single particle.
*
* @param {Object|Array} [initialize] - Initialization parameters or array of initialization objects.
* @param {Object|Array} [behaviour] - Behavior object or array of behavior objects.
* @returns {Particle} The created particle.
*
* Ultra-fast particle creation - no optional parameters, minimal overhead
* @param {Number} count - Number of particles to create
* @private
*/
createParticle(initialize?: Object | any[], behaviour?: Object | any[]): Particle$1;
private _fastCreateParticles;
/**
* High-speed loop for creating many particles
* @private
*/
private _createParticlesLoop;
/**
* Bulk initialization for particles - more efficient for large batches
* @private
*/
private _initializeParticlesBulk;
/**
* High-performance batch particle creation for large quantities
* @param {Number} length - Number of particles to create
* @param {Object|Array} [initialize] - Initialization parameters
* @param {Object|Array} [behaviour] - Behavior parameters
*/
createParticlesBatch(length: number, initialize?: Object | any[], behaviour?: Object | any[]): void;
/**
* Internal method to create a chunk of particles
* @private
*/
private _createParticleChunk;
/**
* Creates a single particle - now optimized for performance
* but batch methods should be preferred for multiple particles
*/
createParticle(initialize: any, behaviour: any): any;
/**
* Sets up a particle with initialization and behavior.
*
* @param {Particle} particle - The particle to set up.
* @param {Object|Array} [initialize] - Initialization parameters or array of initialization objects.
* @param {Object|Array} [behaviour] - Behavior object or array of behavior objects.
* @deprecated Use direct methods instead for better performance
*/
setupParticle(particle: Particle$1, initialize?: Object | any[], behaviour?: Object | any[]): void;
setupParticle(particle: any, initialize: any, behaviour: any): void;
/**
* Removes all particles and stops the emitter.
*/
Expand Down Expand Up @@ -2089,6 +2110,9 @@ declare class PixiRenderer extends BaseRenderer {
color: boolean;
setColor: boolean;
blendMode: any;
rendererId: number;
pixiPool: EmitterAwarePool;
emitterMap: Map<any, any>;
setPIXI(PIXI: any): void;
createFromImage: any;
/**
Expand All @@ -2114,6 +2138,22 @@ declare class PixiRenderer extends BaseRenderer {
destroy(particles: Array<Particle>): void;
}

/**
* A specialized pool that ensures particles are never shared between different emitters
*/
declare class EmitterAwarePool extends Pool {
constructor();
emitterPools: Map<any, any>;
/**
* Get an item from the pool, ensuring it's specific to the emitter
*/
get(target: any, params: any, emitterId: any): any;
/**
* Return an item to its emitter-specific pool
*/
expire(target: any, emitterId: any): any;
}

declare class MStack {
mats: Float32Array<ArrayBuffer>[];
size: number;
Expand Down
Loading