jnsmalm / pixi3d

The 3D renderer for PixiJS. Seamless integration with 2D applications.
https://pixi3d.org
MIT License
759 stars 44 forks source link

Combining meshes and rotating them? #83

Closed synthXR closed 2 years ago

synthXR commented 2 years ago

First of all, great work! Let's say there are three cubes stacked on top of each other or some more complex geometry. How is it possible to group them into one single mesh (to later rotate the mesh)? There is not much to be found about combining 3d meshes in the examples. Thanks

const c1 = app.stage.addChild(Mesh3D.createCube());
const c2 = app.stage.addChild(Mesh3D.createCube());
const c3 = app.stage.addChild(Mesh3D.createCube());

// ..? Combine & rotate c1,c2,c3 as one mesh?
jnsmalm commented 2 years ago

Hello!

Just like PixiJS you just add your objects to a container, and then rotate that container.

const container = app.stage.addChild(new PIXI3D.Container3D())

const c1 = container.addChild(PIXI3D.Mesh3D.createCube());
c1.x = -2.5
const c2 = container.addChild(PIXI3D.Mesh3D.createCube());
c2.x = 0
const c3 = container.addChild(PIXI3D.Mesh3D.createCube());
c3.x = +2.5

let rotation = 1
app.ticker.add(() => {
  container.rotationQuaternion.setEulerAngles(rotation++, 0, 0)
})