Coder Social home page Coder Social logo

ilia-maslakov / file-format-wavefront Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dwmkerr/file-format-wavefront

0.0 0.0 0.0 5.1 MB

A simple .NET library to load data from Wavefront *.obj and *.mlb files.

License: MIT License

PowerShell 4.31% C# 95.69%

file-format-wavefront's Introduction

file-format-wavefront

A simple .NET library to load data from Wavefront *.obj and *.mlb files.

Installation

You can use Nuget to install the library.

PM> Install-Package FileFormatWavefront

Usage

To load data from a Wavefront Object File, use the FileFormatObj class:

//  Use the File Format object to load the test data.
bool loadTextureImages = true;
var result = FileFormatObj.Load("MyFile.obj", loadTextureImages);

The object that is returned is a FileLoadResult object. The object contains a property Model which is the Scene of data loaded.

Texture map images can optionally be loaded, but you can skip this if you are not going to need the image or will load it yourself (whether or not the image is loaded, a TextureMap object is still created with the image path as part of it).

The object also contains a collection of Message objects describing any warnings or errors encountered loading the file. An example of iterating through the vertices and messages would look like this:

//  Show each vertex.
foreach(Vertex v in result.Model.Vertices)
{
    Console.Write("{0} {1} {2}", v.x, v.y, v.z);
}

//  Show each message.
foreach (var message in result.Messages)
{
    Console.WriteLine("{0}: {1}", message.MessageType, message.Details);
    Console.WriteLine("{0}: {1}", message.FileName, message.LineNumber);
}

The Model property is of type Scene and contains the following members:

  • Vertices all vertex data.
  • Uvs all material coordinate data.
  • Normals all normal data.
  • Materials all material data.
  • Groups all objects (groups of faces).
  • UngroupedFaces all faces not grouped into objects.

Associated *.mlb (material library) files are loaded automatically. If you want to load a material library only, you can use the FileFormatMlb class in the same way as the FileFormatObj class.

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.