Git Product home page Git Product logo

meshellator's Introduction

Meshellator

What is this?

3D asset import library for .NET 4.0. Supported formats are Autodesk 3DS and Lightwave OBJ.

How do I use it?

Meshellator is designed to be extremely simple to use. The following line will import a model into a Scene object:

Scene scene = MeshellatorLoader.ImportFromFile(@"Models\3ds\85-nissan-fairlady.3ds");

You can then iterate over the materials and meshes within the scene.

meshellator's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

meshellator's Issues

Errors on opening my mesh

I have an OBJ mesh (I'd like to attach it to this issue, but I don't know how) that crashes Meshellator when I attempt to load it. First I got an "dictionary key not found" error in the MTL loader; I figured out that was because I had spaces in some of my material names, so I removed the spaces from both the MTL file and the references to the materials in the OBJ file. However even after doing so I get an error that I can't figure out. It's just an "index out of range" error, and it's in the OBJ loader itself, so I'm not sure what's wrong.

edit: Since I can't seem to attach files, I'll link to my mesh here: http://edkolis.exofire.net/hull-segment-1.7z

Add post-process triangulation

This will allow quad primitives to be imported from meshes that support that kind of primitive, and then Meshellator will convert the quads to triangles as a post-process.

A bug in ObjImporter

Hi
First of all, you did a great work.

I found a tiny bug in the obj importer (ObjImporter), when trying to import an obj file that has no textures the code will raise IndexOutOfRangeException in line 77. The solution is very simple, just add an if condition to check if the number of textures in the mtl file.

Old code:

// Copy normals.
foreach (int textureIndex in f.TextureIndices)
{
        TextureCoordinate tc = wavefrontObject.Textures[textureIndex];
        mesh.TextureCoordinates.Add(new Point3D(tc.U, tc.V, tc.W));
}

New code (my code):

// Copy normals.
foreach (int textureIndex in f.TextureIndices) 
{
    if (wavefrontObject.Textures.Count > 0) 
    {
          TextureCoordinate tc = wavefrontObject.Textures[textureIndex];
           mesh.TextureCoordinates.Add(new Point3D(tc.U, tc.V, tc.W));
    }
}

Thanks a lot

Untitled

'face' element (f) in OBJ file can have one of the following formats:

(1) f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3
(2) f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 v4/vt4/vn4

(3) f v1//vn1 v2//vn2 v3//vn3
(4) f v1//vn1 v2//vn2 v3//vn3 v4//vn4

(5) f v1/vn1 v2/vn2 v3/vn3
(6) f v1/vn1 v2/vn2 v3/vn3 v4/vn4

or simply
(7) f v1 v2 v3 ...

FaceParser.ParsLine() method is throwing an IndexOutOfRange exception when formats 3-7 are used.


The following modification of FaceParser.ParsLine() method will fix the issue:

    private void ParseLine( int vertexCount ) {
        // Fix: explicitly set the array length
        string[] rawFaces = new string[3];

        vindices = new int[vertexCount];
        nindices = new int[vertexCount];
        tindices = new int[vertexCount];
        vertices = new Vertex[vertexCount];
        normals = new Vertex[vertexCount];
        textures = new TextureCoordinate[vertexCount];

        for ( int i = 1; i <= vertexCount; i++ ) {
            // Fix: Use additional array for parsed words
            var wordParts = Words[i].Split('/');
            // Fix: setup rawFaces array
            rawFaces[0] = wordParts[0];
            rawFaces[1] = wordParts.Length == 3 ? wordParts[1] : null;
            rawFaces[2] = wordParts.Length == 3 
                ? wordParts[2] 
                : wordParts.Length == 2 
                    ? wordParts[1]
                    : null
            ;

            // v
            int currentValue = int.Parse(rawFaces[0]);
            vindices[i - 1] = currentValue - 1;
            // save vertex
            vertices[i - 1] = _object.Vertices[currentValue - 1];   // -1 because references starts at 1

            if ( wordParts.Length == 1 ) {
                continue;
            }

            // save texcoords. 
            if ( !string.IsNullOrEmpty(rawFaces[1]) ) {
                currentValue = int.Parse(rawFaces[1]);
                // This is to compensate the fact that if no texture is in the obj file, 
                // sometimes '1' is put instead of 'blank' (we find coord1/1/coord3 instead of 
                // coord1//coord3 or coord1/coord3)                 
                if (currentValue <= _object.Textures.Count) {
                    tindices[i - 1] = currentValue - 1;
                    textures[i - 1] = _object.Textures[currentValue - 1]; // -1 because references starts at 1
                }
            }

            // save normal
            currentValue = int.Parse(rawFaces[2]);

            nindices[i - 1] = currentValue - 1;
            normals[i - 1] = _object.Normals[currentValue - 1];     // -1 because references starts at 1
        }
    }

Meshellator use not via importing model but by creating custom mesh

Hi,

Is it possible to get a simple example how to make simple mesh from points and faces.
And then remesh it.

I do not want to import the model each time. I want just to pass mesh model to type that is readable to your library remesh it and return it back.

I see that it is not possible to make a simple mesh as there are no functions for them:
Meshellator.Mesh m = new Meshellator.Mesh();

Also when I try to get coordinates out of a simple solid I get empty list:

Kind Regards,
Petras

NullReferenceException in MaterialParser

According to OBJ spec,

usemtl material-ref 

operator could be found before any group is created. The following test is failing:

# start test file
mtllib ./mylib.mtl
usemtl red
# end test file

To fix this issue I would propose the following change in MaterialParser.IncorporateResults():

    public override void IncorporateResults(WavefrontObject wavefrontObject) {
        if (!wavefrontObject.Materials.ContainsKey(_materialName))
            return;

        Material newMaterial = wavefrontObject.Materials[_materialName];

        // Fix: CurrentGroup could be null...
        if ( wavefrontObject.CurrentGroup == null ) {
            wavefrontObject.CurrentGroup = new Group("default");
        }
        wavefrontObject.CurrentGroup.Material = newMaterial;
    }

Note that OBJ spec is using "default" as a group name in these cases (not "Default created by loader")

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.