tyra icon indicating copy to clipboard operation
tyra copied to clipboard

Improve obj loader

Open h4570 opened this issue 3 years ago • 8 comments

@Foxar please describe the needs if you could.

https://github.com/h4570/tyra/blob/d58163d75be2d6c848f4456f73cebd8a6c1a63bd/src/engine/include/loaders/obj_loader.hpp#L18

h4570 avatar Dec 04 '20 08:12 h4570

So far I've thought of these:

  • [ ] Basic material loading from .mtl file.

  • [ ] Default texture for .obj models, if no texture specified

  • [ ] Error message improvements (if loading failed, why? where exaclty?)

Foxar avatar Dec 04 '20 14:12 Foxar

  • [ ] Default texture for .obj models, if no texture specified

Good point. I think that will be good idea to perform PRINT_ERR() (future assert()) on vt (texture data), vn (normal vector) and 2x on f (faces), if they are triangulated and all values are present.

h4570 avatar Dec 05 '20 20:12 h4570

How is using PRINT_ERR() on those values going to provide a default texture for a model? I was hoping to allow the engine to load a model and use some default texture (solid white color, or green and black squares tileset like in source games) to signify failure to load the texture for the model, without grinding the entire .elf executable to a halt.

Image for reference: main-qimg-d3c394175ea164074ff37d70b1f62a66

Foxar avatar Dec 06 '20 07:12 Foxar

I've changed my original TO-DO to specify that the ".mtl loading" should be for basic materials only, such as solid colors/gradients. This is because .mtl files themselves only designate a filename for textures, which seems redundant to have considering the current way TextureRepositories and png/bmp loaders work.

I'd like opinion on this and if you have any other suggestions for improvements to obj_loader, please add them. @h4570

Foxar avatar Dec 06 '20 08:12 Foxar

Hmm.

My thought with PRINT_ERR() was, to just check if texture data is present (assert()) and print error if not.

This is pretty good idea, regarding the "no-texture" texture, we can generate this tex in c++ as well. But yesterday I did small investigation there, and I see that we will MUST add non-texture meshes support. For example yesterday I downloaded christmas tree .obj file, which has texture for tree, and only colors for christmas balls. Texture and colors was described in .mtl file.

My point of view is:

  • Render "no-texture" texture if texture is described in .obj, but texture loading failed.
  • Add new feature, which will enable 2D / 3D rendering without textures (new issue -> enhacement?).

What do you think?

h4570 avatar Dec 06 '20 09:12 h4570

The way I understand this:

Render "no-texture" texture if texture is described in .obj, but texture loading failed.

  1. Load the obj file, load the texture name from inside of it.
  2. If it's missing (no usemtl texture), load default texture name ( "missingtex" for instance).
  3. If AddByMesh fails to find texture, (no texture.png found), instead default to loading missingtex.

Add new feature, which will enable 2D / 3D rendering without textures (new issue -> enhacement?).

Agreed, we can add a boolean value in loaders if they should expect or not material data. If we take an example of obj_loader: here https://github.com/h4570/tyra/blob/d58163d75be2d6c848f4456f73cebd8a6c1a63bd/src/engine/loaders/obj_loader.cpp#L73

Foxar avatar Dec 06 '20 09:12 Foxar

I'd like to note here that recently we've commited some changes to objloader, allowing to load without complete set of Vectors Normals and UVmaps, however it is unlikely to render properly. As such this issue is on hold until we resolve #66

Foxar avatar Dec 20 '20 10:12 Foxar

Tomorrow I'd like to look into this issue, testing to see the rendering behavior of models without Normals or UVMaps, as I understand that #66 has been fixed.

Foxar avatar Apr 18 '21 21:04 Foxar

Resolved. Tyra 2.0.0 uses tinyobjloader

h4570 avatar Aug 24 '22 21:08 h4570