Commit graph

80 commits

Author SHA1 Message Date
Arseny Kapoulkine
33e0ee7162 Trim trailing whitespace for names
Some .obj files have extra whitespace after usemtl and other statements;
this may interfere with parsing, for example by adding a space to the
material name which can result in inability to find it in .mtl file.

For consistency, we replace all uses of is_end_of_name with skip_name
that handles this by leaving trailing whitespace alone. It will be
skipped in the parsing flow when we skip the newline, which is similar
to the behavior of trailing whitespace after numeric data (which
parse_float/int leave alone).
2023-08-13 10:08:29 -07:00
Richard Knight
2bb0b1f650
Merge pull request #41 from maxrigout/master
added support for colored vertices (issue #28)
2023-08-08 10:52:23 +01:00
Max Rigout
491efbbb59 removed extra white spaces 2023-08-03 10:17:31 -04:00
Max Rigout
cd5be148c3 re-added mesh normal initialization that was accidently removed) 2023-08-03 08:40:58 -04:00
Max Rigout
27803406d7 reverted color parsing to original approach 2023-08-03 08:31:16 -04:00
Max Rigout
20a9db53a0
Merge pull request #1 from maxrigout/colors
Colors
2023-08-02 22:34:25 -04:00
Max Rigout
2c91cb2993 added lazy fill for vertex_color_index 2023-08-02 22:18:31 -04:00
Max Rigout
9037820f30 improved color parsing 2023-08-02 22:17:37 -04:00
Max Rigout
a511f60249 added support for colored vertices (issue #28) 2023-07-31 21:23:40 -04:00
Richard Knight
1a8060257a
Merge pull request #40 from zeux/master
Fix 32-bit integer overflow issues
2023-06-10 12:57:54 +01:00
Arseny Kapoulkine
66f467de8f Fix 32-bit integer overflow issues
When an array reached a size that would require >4GB allocation, the
argument to realloc would overflow during multiplication, resulting in a
very small allocation and a subsequent out of bounds access.

This change fixes that and also adjusts capacity calculation so that it
doesn't overflow 32-bit range until it's basically impossible not to.

This is not perfect - in particular, on 32-bit systems there's a risk of
size_t overflow that remains, however because we grow in 1.5x
increments, realistically an attempt to grow a 2GB allocation to the
next increment would fail before that. We can also technically overflow
capacity even after the adjustment, but that requires 3+B elements which
effectively means an .obj file on the scale of hundreds of gigabytes, at
which point maybe a streaming parser would be more practical.
2023-06-08 20:35:25 -07:00
Richard Knight
85778da5fc
Merge pull request #31 from cadenji/add-index_count
Add index_count member to fastObjMesh struct
2022-01-29 16:42:41 +00:00
cadenji
3a1efbcc79 Add index_count member to fastObjMesh struct
In some cases we need to know the length of `indices`.
Currently need to calculate the sum of the `face_vertices`
elements to get this value.

It would be convenient if we could get the value directly.
2022-01-29 23:15:20 +08:00
Richard Knight
d2c273248a Use the same struct definition for Object and Group. 2021-10-19 08:54:00 +01:00
Richard Knight
ed03b86e7f Fix stupid face counting bug in objects 2021-10-19 08:44:07 +01:00
Richard Knight
9f4b38eb1b Add support for object names 2021-10-18 15:56:38 +01:00
Richard Knight
49c810ae1c Bump version number 2021-08-01 14:07:18 +01:00
Richard Knight
86d7dc6e43 Update CMake file so it can be used with FetchContent in other projects 2021-08-01 14:06:21 +01:00
Richard Knight
92551724cf Avoid signed overflow with crazy exponents. Fixes #27. 2021-06-01 18:23:53 +01:00
Richard Knight
d97389aa2d
Merge pull request #26 from zeux/patch-1
Fix version number in the comment
2021-04-01 18:09:38 +01:00
Arseny Kapoulkine
fed0e5760f
Fix version number in the comment
Also fix copyright year while I'm at this.
2021-03-31 22:55:39 -07:00
Richard Knight
5d1a8529cf Tidy formatting, bump version number. 2021-03-13 08:23:38 +00:00
Richard Knight
eba6f59206 Fix #25. Check for 'map_Bump' as well as 'map_bump'. 2021-03-13 08:21:43 +00:00
Richard Knight
e7a99e63a0
Merge pull request #23 from BeastLe9enD/master
Virtual filesystem support
2021-03-06 08:49:26 +00:00
BeastLe9enD
723e0e4775 Fixes 2021-03-05 23:07:01 +01:00
BeastLe9enD
597b5a8420 Some fixes 2021-03-05 00:56:31 +01:00
BeastLe9enD
cf2d64dea3 Virtual filesystem support 2021-03-04 20:25:38 +01:00
Richard Knight
ac312c9c6d
Merge pull request #21 from zeux/master
Fix base path handling for mixed slashes
2021-01-17 19:50:29 +00:00
Arseny Kapoulkine
a40b84252a Fix base path handling for mixed slashes
On Windows, paths with mixed slashes weren't processed correctly as `\`
would be picked if it was anywhere in the path for the purpose of
determining base.

This also removes the #ifdef _WIN32 from the logic; this helps on
platforms like Emscripten where running the resulting binary that
wasn't compiled with WIN32 still needs backslash processing; paths with
backslashes on Linux should be exceedingly rare, plus we *already*
correct backslashes with forward slashes on Linux anyway...
2021-01-17 10:27:44 -08:00
Richard Knight
0f90b6fa0f Allow both direction of slash as a path separator for initial path on Windows 2020-10-28 22:07:20 +00:00
Richard Knight
2c9e41aed3
Merge pull request #19 from AurL/bare-obj-materials
Create materials even if not definition provided
2020-10-20 18:33:17 +01:00
Aurélien Chatelain
76143f7ef2 Create materials for 'usemtl' declaration
Problem: I read a bare OBJ so no MTL is provided. I still want
to keep the materials setup across the scene for further edit.

Fix: Instead of using a fallback material (idx 0), create a material
for each not-defined material while keeping the name
so that the structure of the model is conserved.
2020-10-20 07:52:02 +00:00
Richard Knight
4bc640697f Add a version number 2020-08-21 20:31:47 +01:00
Richard Knight
48127431ad Fix compiler warning 2020-05-23 16:27:22 +01:00
Richard Knight
c9885c36d4 Add fast_obj.c to allow compilation as standalone library if required 2020-05-23 16:25:05 +01:00
Richard Knight
f12fb80c54
Merge pull request #17 from Kuranes/patch-2
Add support for name with spaces
2020-04-17 16:43:29 +01:00
Tuan Kuranes
a33d94e41f
Add support for name with spaces
- allows filepath with spaces for textures
- allows names with space for internal names in obj (group, material)
- It fixes incorrect matching (material name matching on first part of a name like "my material" merges all material with same start)
2020-04-17 17:10:10 +02:00
Richard Knight
e16fb04bab
Merge pull request #16 from sergof/patch-1
Add extern "C" directive
2020-03-24 08:51:12 +00:00
Sergej Reich
fad51e216c
Add extern "C" directive 2020-03-24 06:14:14 +01:00
Richard Knight
13284900ee Attempt to clarify use of dummy entry in position/normal/texture coordinate arrays 2020-02-29 15:01:22 +00:00
Richard Knight
ca31ba8df4
Merge pull request #14 from zeux/master
Fix MSVC /W4 warning
2020-02-08 09:10:22 +00:00
Arseny Kapoulkine
30348b561a Fix MSVC /W4 warning
Conversion from size_t to unsigned int is lossy.
2020-02-07 20:45:58 -08:00
Richard Knight
74e8dc9e07 Convert tabs to spaces 2020-01-01 11:21:50 +00:00
Richard Knight
a22740ad84
Merge pull request #11 from Kuranes/Adds-big-file-support
Adds big obj files support
2019-11-26 08:40:53 +00:00
Kuranes
33ddb7ad33 Adds big obj files support
Problem: on a 22gb file, it fails on "out of bound write"

Fix: using size_t on 64bits for arithmetic ptr alloc/index system fixes it

Usage: user can define FAST_OBJ_UINT_TYPE as size_t on x64
2019-11-26 09:26:46 +01:00
Richard Knight
256f09e8d5
Merge pull request #9 from zeux/memmove
Fix memcpy with overlapping regions
2019-07-27 08:43:54 +01:00
Richard Knight
a92b6f4ad1
Merge pull request #8 from zeux/fix-overflow
Fix buffer overflow in string_equal
2019-07-27 08:43:33 +01:00
Arseny Kapoulkine
1670fe1c00 Fix memcpy with overlapping regions
When moving the unprocessed line to the beginning of the buffer, in rare
edge cases where the unprocessed chunk is larger than the processed
chunks (which means the lines are very long), the source & target range
will overlap. This is undefined as per C standard and triggers ubsan
errors.

Fix this by using memmove.
2019-07-26 22:27:31 -07:00
Arseny Kapoulkine
4053ffa30f Fix buffer overflow in string_equal
When string_equal's first argument is a prefix of the second argument
but the second argument is longer, the loop goes through all characters
of the first string, compares terminating NUL with a different character
in the right hand side string, discovers that it's different and leaves
the loop - with 'a' having already been incremented.

After this the condition proceeds to read from *a which causes a buffer
overrun.

Fix this by changing the function to something that's obviously correct,
even if somewhat less efficient.
2019-07-26 22:20:26 -07:00
Richard Knight
38b9f04613
Merge pull request #7 from aspurdy/fix-bump-map
Fix bump map parsing
2019-07-20 08:42:46 +01:00