arx-tools / arx-level-generator

A node.js library for creating maps for the video game Arx Fatalis
MIT License
6 stars 0 forks source link

Polygons.addThreeJsMesh: repetitive code when adding mesh to a map #30

Open meszaros-lajos-gyorgy opened 1 month ago

meszaros-lajos-gyorgy commented 1 month ago

The following code has to be executed in order to have a mesh positioned to the map's origin:

const mesh = createPlaneMesh({ size: 1000, texture: Texture.missingTexture })

applyTransformations(mesh)
mesh.translateX(map.config.offset.x)
mesh.translateY(map.config.offset.y)
mesh.translateZ(map.config.offset.z)
applyTransformations(mesh)

map.polygons.addThreeJsMesh(mesh)

Another way of adding multiple meshes to the map is the following:

const meshes: Mesh[] = []

// ...

meshes
  .forEach((mesh) => {
    applyTransformations(mesh)
    mesh.translateX(map.config.offset.x)
    mesh.translateY(map.config.offset.y)
    mesh.translateZ(map.config.offset.z)
    applyTransformations(mesh)

    map.polygons.addThreeJsMesh(mesh, { tryToQuadify: DONT_QUADIFY, shading: SHADING_SMOOTH })
  })

These should be handled internally similar to ArxMap.add(..., true)