Comments (5)
Thanks for pointing out.
As you noticed,
https://github.com/syoyo/tinyobjloader-c/blob/master/tinyobj_loader_c.h#L1081
Updating material_id
is TODO because I was a bit troublesome to implement string-to-int hash function :-)
The best way is to implement (portable) string hash table like this,
http://stackoverflow.com/questions/20462826/hash-function-for-strings-in-c
But for a while, simple linear search should be enough since the number of materials are usually small(~100)
from tinyobjloader-c.
I haven't very fully tested it yet but I made a pull request at #5 where I implemented a simple hashtable with quadratic probing and added it to parse_obj and parse_mtl (I renamed parse_mtl to parse_and_index_mtl, which fills a hash table with the material names and their indices and their names, and created parse_mtl which calls parse_and_index without providing a hash table (parameter is NULL)).
from tinyobjloader-c.
Also I forgot to mention this before, but shouldn't tinyobj_parse_obj have the material file's data as a parameter? If tinyobj_parse_obj's intention is to allow the user to load their file however they want (hence the buf and len parameters, but no filename parameter), then perhaps it should also allow the user to feed it the data from the material file, rather than designing the function to not use fopen but then requiring it once a material filename is encountered.
I have a couple of ideas:
- The user could provide a callback (a "functor" struct containing a function pointer and a pointer to some data) that allows them to load the mtl file their way if a name is found.
- tinyobj_parse_obj could be split into one function that scans for a mtl filename and another function that actually loads the obj. The user would find the mtl filename by calling the first function, load the file data how they wish, then provide that file's data and the obj file's data to the second function.
- tinyobj_parse_obj would store the material names and the mtllib files, and a separate function would patch in the indices. Or, the library doesn't patch in the indicies at all and lets the user link faces to materials.
Again this is an API decision, would be great to get some feedback!
from tinyobjloader-c.
Thanks for hashing feature!
For API, yes, you can implement callback based API like tinyobj_parse_obj_with_callbacks
Please see example in C++ version: https://github.com/syoyo/tinyobjloader/blob/master/tiny_obj_loader.h#L316
Callback based API also make it possible to read .mtl data from memory.
from tinyobjloader-c.
So, possible API design is
tinyobj_parse_obj_with_mtl_callback
I will consider to rewrite tinyobj_parse_and_index_mtl_file
so that it could read .mtl data from user supplied callback function and memory.
from tinyobjloader-c.
Related Issues (20)
- Last face ignored if it's the last line in the file HOT 2
- Clearify num_face and num_face_num_verts variable HOT 3
- carriage return when read diffuse texture name HOT 5
- [TODO] Support reading line larger than 8192 bytes HOT 3
- Windows version of map file HOT 3
- Negative exponents not handled by tryParseDouble
- Heap buffer overflow in my_strndup HOT 1
- Failed to initialize GLEW. (linux) HOT 1
- Material name corruption in tinyobj_parse_obj HOT 1
- Swapped values in returned attribs ? HOT 3
- Presumably broken hashmap for material listing HOT 6
- `obj` parsing doesn't know the file name, but `mtllib` is relative to that file HOT 4
- tinyobj_parse_obj fails to read .mtl file HOT 4
- Maybe use sscanf? HOT 1
- Issue with hashmap algorithm and probably more when loading certain models. HOT 8
- Is this still active?
- Memory leaked after tinyobj_parse_obj do file_reader HOT 5
- obj to gltf? HOT 1
- Memory leak in tinyobj_parse_and_index_mtl_file HOT 2
- Infinite loop in hash table inserting when reading mtl file HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinyobjloader-c.