Giter Club home page Giter Club logo

objloader's Introduction

obj-mtl-loader

An obj file loader for WebGL, including .mtl loder

Install


Using npm

npm install obj-mtl-loader

Example


To run example, npm install, then run npm start, you should see the obj loader working on your http://localhost:3001/.

If you want to edit the example, make sure you run webpack after you make any changes or you can run webpack --progress --colors --watch as the watch mode for webpack.

  • only obj file

    var ObjMtlLoader = require("obj-mtl-loader");
    var objMtlLoader = new ObjMtlLoader();
    objMtlLoader.load("./test/objfiles/bunny.obj", function(err, result) {
      if(err){
        /*Handle error here*/
      }
      var vertices = result.vertices;
      var faces = result.faces;
      var normals = result.normals;
    });
  • with materials(.mtl)

    var ObjMtlLoader = require("obj-mtl-loader");
    var objMtlLoader = new ObjMtlLoader();
    objMtlLoader.load("./test/objfiles/sponza/sponza.obj", "./test/objfiles/sponza/sponza.mtl", function(err, result) {
      if(err){
        /*Handle error here*/
      }
      var vertices = result.vertices;
      var faces = result.faces;
      var normals = result.normals;
      var textureCoords = result.textureCoords;
      var facesMaterialsIndex = result.facesMaterialsIndex;
      var materials = result.materials;
    });

    See more examples on examples folder

Attributes


  • vertices: Double Array, each item is an array with 3 or 4 numbers

  • normals: Double Array, each item is an array with 3 numbers

  • textureCoords: Double Array, each item is an array with 2 or 3 numbers

  • faces: Objects inside Array, each Object is

    • indices: the index of the vertices for this face
    • texture: the texture index for this face
    • normal: the normal index of this face
  • facesMaterialsIndex(Optional): Objects inside Array, each object is

    • materialName: The name of the material in mtl file
    • materialStartIndex: The start index of this material
  • materials: Objects inside Array, each object is

    • name: Name of the material
    • ambient: Ambient color, Ka
    • diffuse: Diffuse color, Kd
    • specular: Specular color, Ks
    • specularExponent: Specular Exponent, Ns
    • transparent: transparent, d || Tr
    • illumMode: Illum mode, illum
    • ambientMap: Ambient map, map_Ka
    • diffuseMap: Diffuse map, map_Kd
    • specularMap: Specular map, map_Ks
    • alphaMat: Alpha map, map_d
    • bumpMap: Bump map, map_bump
    • displacementMap: Displacement map, disp

License


MIT

objloader's People

Contributors

oparisy avatar tiansijie avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.