Closed Allfu closed 3 years ago
Hi @Allfu , glad you like it!
As you can see here
if color
is False
, which it is by default, I am using a single color to render the model, ignoring whatever colors have been defined in the model file.
The default color used to render the model is defined here: https://github.com/juangallostra/augmented-reality/blob/970b0cfd569aededa24f68fbc07fe8442212b853/src/ar_main.py#L21
If you only want to render the model with colors - assuming they have been defined in the .obj file - and not textures, you should call the render
function with the last parameter set to True
:
The call to the render
function is done here:
an example of a model with colors is the Pirate Ship (https://github.com/juangallostra/augmented-reality/blob/master/models/pirate-ship-fat.obj). Colors are defined in hex format:
To load colors you should also uncomment the lines: https://github.com/juangallostra/augmented-reality/blob/970b0cfd569aededa24f68fbc07fe8442212b853/src/objloader_simple.py#L25-L26
See below an example result of the Pirate Ship and Fox colored models:
The second one is taken from piotrekk94's fork: https://github.com/piotrekk94/tx2-ar, which has some other improvements.
If what you want is to display a texture for the model, then yes, you should combine the OBJ model with the MTL file.
The code I am using to load OBJ models is based on this one: https://www.pygame.org/wiki/OBJFileLoader As you can see in the link, there is a second class I removed which loads MTL files. In addition to that, lines
should be uncommented. The problem with textures is that you will then need OpenGL (or something similar) to render the model, which was work I didn't want to do at the time. It is possible, however, to do so.
This is a useful resource if you are wishing to dig deeper on how to do it: https://rdmilligan.wordpress.com/2015/10/15/augmented-reality-using-opencv-opengl-and-blender/
got it! thanks for your help! thanks!
thanks for your work! Now i get a question: Is a single color space covering the texture of the model? Or should we combine the MTL file to display the texture of the model? thanks !