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

EntityModel cannot be generated from a simple Threejs geometry #5

Closed meszaros-lajos-gyorgy closed 7 months ago

meszaros-lajos-gyorgy commented 7 months ago
import { Entity, EntityConstructorPropsWithoutSrc, EntityModel, Texture, Vector3 } from 'arx-level-generator'
import { BoxGeometry, Mesh, MeshBasicMaterial } from 'three'

const geometry = new BoxGeometry(1, 1, 1)
const material = new MeshBasicMaterial({ map: Texture.l2TrollStoneGround04 })
const mesh = new Mesh(geometry, material)

export class Pillar extends Entity {
  constructor({ ...props }: EntityConstructorPropsWithoutSrc = {}) {
    super({
      src: 'fix_inter/pillar',
      model: EntityModel.fromThreeJsObj(mesh, {
        filename: 'pillar.ftl',
      }),
      ...props,
    })
  }
}

This results in the following error message in game and the model not showing:

[E] FTL:179               "game/graph/obj3d/interactive/fix_inter/pillar/pillar.ftl": Invalid face material

Extra infos:

meszaros-lajos-gyorgy commented 7 months ago

The issue comes from getNonIndexedVertices returning something called materialIndex which is in fact a group index of the groups inside the geometry. The number of materials don't match the material indices.

meszaros-lajos-gyorgy commented 7 months ago

Fixed in 13.0.0-alpha.2