melonJS
    Preparing search index...

    Function getOBJ

    • return the specified OBJ model data

      Parameters

      • elt: string

        name of the OBJ file (as specified in the preload list)

      Returns object

      parsed OBJ data with vertices (Float32Array), uvs (Float32Array), indices (Uint16Array), and vertexCount (number), or null if not found

      loader

      // 1. preload the OBJ model and its texture
      me.loader.preload([
      { name: "cube", type: "obj", src: "models/cube.obj" },
      { name: "cube", type: "image", src: "models/cube_texture.png" },
      ], () => {
      // 2. create a Mesh using the preloaded model name
      const mesh = new me.Mesh(400, 300, {
      model: "cube", // references the preloaded OBJ
      texture: "cube", // references the preloaded image
      width: 200,
      height: 200,
      });
      me.game.world.addChild(mesh);

      // 3. or access the raw parsed data directly
      const data = me.loader.getOBJ("cube");
      // data.vertices — Float32Array of x,y,z positions
      // data.uvs — Float32Array of u,v texture coordinates
      // data.indices — Uint16Array of triangle vertex indices
      // data.vertexCount — number of unique vertices
      });