Little001's picture

Load obj files from blender

Pls i have one project in my school (bachelor´s thesis), I need create our faculty in blender and then load this obj file in c# with openGL.
I try meshomatic from this pages, but it wrote error, bcs obj files from blender is different.
Much please help, i have it just a few days.

Sorry for my english :-)


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Little001's picture

If I do anything in blender, export in OBJ, after this obj file you open in SketchUp then export obj file. And this obj file is for meshomatic good.
Now pls i want load with textures "this information is in .mtl file. How can i display model with this information? Thanks :-)

the Fiddler's picture

It appears that meshomatic doesn't support material files (.mtl) out of the box. A quick google search reveals towards ObjLoader that supports .obj and .mtl files in OpenTK. Give that a try.

topsu's picture

I tried that one but I can get list of verticles, textures, normals etc. But I am not sure what to do with them. =/

the Fiddler's picture

ObjLoader comes with its own C# code to display obj files. Can you use that, or do you need to write your own? If you need to write your own, keep reading:

Vertices are the basic building blocks of 3d graphics.

Start with the basic immediate mode example for OpenTK. The DrawCube() shows how to draw a cube using vertices.

Modify this function to draw the Mesh you loaded from ObjLoader:

void DrawMesh(Mesh mesh)
    GL.Begin(PrimitiveType.Triangles); // you can also use Points, Lines, Quads
    for (int index = 0; index < mesh.Triangles.Count; index++)
        var vertex = mesh.Triangles[index];
        var normal = mesh.Normals[index];

Original code from ObjLoader.

You should now be able to see a part of the model. Modify line 111 to move the camera so you can see more of it. (You can connect this to the keyboard and mouse if you wish.)

This should be enough to get you started.