hmans/miniplex

[Idea] Allow `World.add` to take a setup function as an optional second argument

hmans opened this issue · 0 comments

hmans commented

This is just some convenience glue to make initializing newly created entities a little easier without requiring the user to store them in a variable first.

As is:

const entity = world.add({
  transform: new Mesh(
    new DodecahedronGeometry(),
    new MeshStandardMaterial({ color: "orange" })
  )
})

entity.transform.position.set(-3, 0, 0)

To be:

world.add({
  transform: new Mesh(
    new DodecahedronGeometry(),
    new MeshStandardMaterial({ color: "orange" })
  )
}, (entity) => { 
  entity.transform.position.set(-3, 0, 0)
})