Compose 2D and 3D elements
developPixi3D integrates with PixiJS. You can add 2D containers on top of 3D containers or vice versa.
Important: 2D and 3D transforms are not compatible; changing a parent's 2D transform will not affect its 3D children.
To bridge the two:
- Use
camera.screenToWorldandcamera.worldToScreenfor coordinate conversion. - Use
CompositeSpriteto render a 3D object as a 2D sprite, allowing the use of standard PixiJS filters on 3D content.
// Adding a 2D vignette on top of the 3D scene
let vignette = app.stage.addChild(
PIXI.Sprite.from(
"https://raw.githubusercontent.com/jnsmalm/pixi3d-sandbox/master/assets/vignette.png"
)
);
app.ticker.add(() => {
Object.assign(vignette, {
width: app.renderer.width,
height: app.renderer.height
});
});