So I've created a 3D model in blender,exported it as an obj and have imported it onto C++/OpenGL. The model loads perfectly although it's lost all of it's colouring and texture. It's just a basic white model.. Is there any way of fixing this or can you not have the model imported with the textures you have to redo them in OpenGl?
an .obj file does not contain the texture itself: only the texture coordinates per vertex.
you will need to load and bind the texture yourself separately from loading from the obj file.
Other file formats can have a texture embedded but loading models from files is not within the scope of the openGL API.
It's true that obj files don't contain textures or material data, but they're commonly paired with mtl files. The obj references the mtl file to use with the mtllib directive and chooses materials for subsequent faces with usemtl.
See: http://en.wikipedia.org/wiki/Wavefront_.obj_file#Material_template_library
However, the mtl file only contains colours and texture file names, not the actual texture data. You'll have to look into loading textures separately and use it to load the texture referenced in the mtl file. Then create the OpenGL texture and draw you object with it bound, together with the texture coordinates in the obj file.
In blender, make sure Write Materials is checked when exporting the obj. Also check the relative paths to the textures are appropriate (just open the mtl file in a text editor). As a side note, Include Normals is annoyingly is unchecked by default.
So, your obj file contains:
Vertex positions and possibly normals and texture coordinates too.
Vertex connectivity, or faces, which may actually be n-gons and you need to triangulate.
References to the material file, if there is one.
The mtl file contains:
Many material definitions
Each identified by a name
Containing colour for ambient, diffuse, specular etc.
Also containing texture map references (file names) and could be png, jpg, whatever.
Related
I have learned how to import a .obj with assimp by shaders
However, is it possible to import a .obj with assimp by fixed-function-pipeline.
so that I can program by OpenGL API easily.
It shouldn't change significantly between the two, through assumption you should get your vertex positions, normals and UV coordinates which is independent from opengl.
What will change is that you won't use a VAO/VBO but you will have to send each vertex attribute "by hand"
With
glTexCoord2dv(your uv) glNormal3dv( your normal) glVertex3dv( your vertex)
For each of your face and vertex.
Edit:
The wavefront object format uses only one set of UV coordinates per vertex, so all your textures will use the same UV map. If you have textures that use multiple UV maps you should look into another format like .fbx . But these stuffs have nothing to do with the fixed/ programmable pipeline. Once the files are imported by assimp you are done. All that changes are the functions used to send the data. Also the material data of an obj file is very limited so all you'll have are the name of the texture used and it's channel. Since materials are heavily linked to your rendering pipeline information will always be lost.
I am using a new 3D scanner which uses stereophotogrammetry to extract images at different orientations and then stitch them together to create a 3D model. The model looks great. However, the texture in the models (as referred to in the .mtl file) points to several images(.jpg) corresponding to the orientation. (Every capture has its own texture and they are referenced in the .mtl file). However, my application can only read 3D scans (.obj's) with only one texture referenced in them. Can you advise a way to combine the textures to a single triangle map or UV map?
The textures and the final models are added for your reference.
Please advise if you need any more information.
I'm writing a parser for .obj files with multiple materials and groups (so I'm also parsing usemtl and material files). I can load and render the vertices. How do I deal with different textures and materials?
Do I render each material one by one or having a giant shader to choose ID? And how do I store different textures on the GPU buffer? (Currently I am using GL_TEXTURE_2D_ARRAY but they must have the same size.
So, to handle different materials, each object has the material specifications like ambient_color, diffuse_color, and specular_color. You simply, pass these values as uniform to fragment shader and render the object with different material specs.
Also, you can use 128 textures simultaneously in one fragment shader, so you can render an object with more than texture. But most of the time an object is made of groups and each group has just one texture, so you just need a sampler2D object in fragment shader, just the uniform values which you are passing for the texture will change.
Best way to handle this efficiently is to render the groups with the same texture together, so prevent lots of texture changes.
The link below is a 7zip package containing the blender scene, exported obj file, material and textures. When I load the obj in MeshLab it looks great although the normal bump map does not appear to work in meshlab, the diffuse texture is perfect. When I load the obj in the helix3d toolkit the results I get are less than perfect the UV mapping appears to be almost correct but then is completely wrong in other places.
I checked all the UV coords are in 0-1 range.
obj export 7zip package
Also does normal/bump mapping work correctly in Helix3D viewport?
I solved this, actually its an issue with blender, for some odd reason creating a new scene in blender re-importing just the geometry and then re UV and set-up a new material with new textures then export and the mesh appears fine.
Not sure what was so wrong with it if meshlab could load it but its resolved.
Every time I try to export a obj from some 3d model making program it exports without indices for the texture coordinates. I don't want x//xn y//yn z//zn I want x/xn/u y/yn/v z/zn/w. I've tried blender and maya. Maya doesn't have a option for exporting these. But blender will let you choose whether you want to write normals and texture points. How can I get the texture point indices in there?
Blendr's site mentions that it can export UVs, did you check that? Blender's Wavefront OBJ options