Giter Site home page Giter Site logo

Comments (7)

syoyo avatar syoyo commented on May 29, 2024

per face material is vital for most renderers including ours and this is only efficient and working solution so far. But if you think there is better solution you can send PR. I will review it.

from tinyobjloader.

KammutierSpule avatar KammutierSpule commented on May 29, 2024

In function exportFaceGroupToShape, the same material_id is assigned to all the faces (i.e: the same value for all the faces, it dont change). I don't know about the .obj format, is that something supported? Or it was because your render?
I was planning to use your lib (I will let you know latter if I use it!) but in the end I have to convert the structures to some other structure in my render, so I was trying to understand how should I interpret the materials to convert it.
Cheers.

from tinyobjloader.

chrisliebert avatar chrisliebert commented on May 29, 2024

Wavefront format is not an optimized format and requires a certain degree of processing prior to rendering such as converting the texture coordinates (y coordinate must be transformed to 1 - y). Faces only reference indices so if you plan to use a buffer of interleaved vertex structs (VBO) you will need to deference the values and copy them to a new buffer. How the materials are processed is dependent on the shading model of your renderer although additional steps are likely necessary. Here are some examples for processing the tinyobj structures:
https://github.com/chrisliebert/sdlgl3-wavefront/blob/master/src/Renderer.cpp
https://github.com/chrisliebert/sdlgl3c-sqlite/blob/master/obj2sqlite/src/SceneBuilder.cpp

from tinyobjloader.

syoyo avatar syoyo commented on May 29, 2024

Thanks Chris!

from tinyobjloader.

KammutierSpule avatar KammutierSpule commented on May 29, 2024

My question is more related with the OBJ format and the tinyobjload structure format than how to render it.
Looking in the ttinyobjload, function exportFaceGroupToShape, it is assigning the same material for that group of vertex/normals/idx
So I was expect that only a single material was assigned to that group instead of a vector of materials (per face).
Does it mean that OBJ can have multiple materials per group?

I was looking for the @chrisliebert sources and I notice this line:
if(materialId != lastMaterialId )
So it seems that it is possible that in the middle of a list of indices we can have different materials, and @chrisliebert is using the change of material to create a new object based on that.

So I was thinking if tinyobjload could create a new mesh_t (with just one material index assigned to that mesh) or why it is not doing that way..?
I think I should have a look in the OBJ specs as well .

from tinyobjloader.

chrisliebert avatar chrisliebert commented on May 29, 2024

OBJ can have multiple materials per group although this isn't always the case. In function exportFaceGroupToShape, the material id is appended to the list of material id indices because each call to exportFaceGroupToShape(,,,,,) could potentially have a different material id passed to it. There are many variants of .obj: Blender3D for example lets you choose options such as "Objects as OBJ Groups", and "Objects as OBJ Objects". The resulting .obj will have line(s) beginning with "o " or "g " which contain object/group names however o and g are independent from the use of "usemtl " which is responsible for setting the current material when reading the .obj file from top to bottom. The current model for tinyobj provides a flexible framework for working with a variety of .OBJ files and to change it would risk breaking compatibility for current applications and introducing additional complexity for handling ambiguous cases.

from tinyobjloader.

KammutierSpule avatar KammutierSpule commented on May 29, 2024

OKs it is more clear now. I will use your source as reference for handling the tinyobj structures.
Thanks

from tinyobjloader.

Related Issues (20)

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.