0.1.8 • Published 5 years ago

tolw v0.1.8

Weekly downloads
8
License
MIT
Repository
github
Last release
5 years ago

tolw

WebAssembly port of tinyobjloader

Install:

npm install tolw

Usage:

const tolw = require("tolw");
// initialise tolw
tolw.init().then(() => {
  // have fun
  let objFile = new Uint8Array(fs.readFileSync("./model.obj", null));
  let { attrib, shapes } = tolw.loadObj(objFile);
});

Example:

let vertices = [];
let indices = [];
for (let shape of shapes) {
  for (let index of shape.mesh.indices) {
    let pos = {
      x: attrib.vertices[3 * index.vertex_index + 0],
      y: attrib.vertices[3 * index.vertex_index + 2],
      z: attrib.vertices[3 * index.vertex_index + 1]
    };
    let normal = {
      x: attrib.normals[3 * index.normal_index + 0],
      y: attrib.normals[3 * index.normal_index + 2],
      z: attrib.normals[3 * index.normal_index + 1]
    };
    let texCoord = {
      x: attrib.texcoords[2 * index.texcoord_index + 0],
      y: 1.0 - attrib.texcoords[2 * index.texcoord_index + 1]
    };
    vertices.push(
      pos.x, pos.y, pos.z,
      normal.x, normal.y, normal.z,
      texCoord.x, texCoord.y
    );
    indices.push(indices.length);
  };
};

Build:

em++ --bind -o tolw.js tolw.cc -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s NODEJS_CATCH_EXIT -O3
0.1.8

5 years ago

0.1.7

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago