Commit Graph

22 Commits

Author SHA1 Message Date
Arseny Kapoulkine d6db9fd3b3 gltfpack: Simplify texture matching code for .obj
We still can't quite use .obj texture indices directly because we might
end up with a set of unused textures that later parts of pipeline don't
filter out, but we can remove all string operations and just compare
indices instead.
2024-06-05 00:11:25 -07:00
Arseny Kapoulkine 987c4e7cfc extern: Update to fast_obj 1.3
fast_obj 1.3 makes a change to internal data structures to use indexed
texture objects; in this change we blindly rework the code to index the
new textures[] array; this will be reworked in a subsequent change to
directly use the underlying indexing to do obj->gltf mapping.
2024-06-04 16:26:48 -07:00
Arseny Kapoulkine 1497c1ae87 gltfpack: Warn when some materials could not be loaded from the .obj/.mtl
This can happen in multiple different ways:

- No mtllib reference in the .obj file
- mtllib reference in the .obj file that can not be loaded
- usemtl references to materials that don't exist in the mtllib
2023-12-15 11:26:25 -08:00
Arseny Kapoulkine f6e4258ffd clang-format
Note: this change ignores formatting of ternaries where clang-format
makes a very wrong decision, as well as a few small bits that might need
code adjustment in the future to avoid misformats.
2023-11-16 18:38:52 -08:00
Arseny Kapoulkine 050db0b740 gltfpack: Use NULL for null pointer constants instead of 0/nullptr
This fixes instances of Wzero-as-null-pointer-constant warning with the
exception of occurrences inside third-party code (extern).

Note that we previous used 0/nullptr/NULL in gltfpack in different
places. gltfpack is C++11 but since it's developed alongside
meshoptimizer which doesn't currently require C++11, for now we use NULL
for consistency instead of nullptr.
2023-10-13 11:18:25 -07:00
Arseny Kapoulkine f107e960a5 gltfpack: Only use Kd/d from .mtl when associated maps are absent
It's not fully clear what the expected behavior is when both Kd and
map_Kd are specified; some online documentation claims that they are
multiplied, but some .obj files in the wild have map_Kd and Kd=0, so to
stay safe we now only apply Kd/d when there's no map with the same name.
2023-08-22 07:16:43 -07:00
Arseny Kapoulkine 218b6d8005 gltfpack: Fixup texture URIs parsed out of .obj/.mtl
Some .mtl files contain backslash-delimited paths; backslash is not
valid as a delimiter in URIs and paths like this can't be opened on
non-Windows platforms when textures are embedded or compressed.
2023-08-22 07:12:21 -07:00
Arseny Kapoulkine 90d1e54677 gltfpack: Fix default scene for glTF files converted from .obj 2023-08-21 18:18:07 -07:00
Arseny Kapoulkine 7ec9f315e6 gltfpack: Refactor .obj parsing a little bit
This change splits nodes and materials parsing and keeps mesh group
parsing loop so that the code looks more similar to what we used to have
when we just had one group. That will also make it easier to ensure the
relationships between objects and nodes stay 1-1.
2023-08-21 18:17:59 -07:00
Arseny Kapoulkine 273f785675 gltfpack: Parse individual objects in .obj separately
We now assign a node to each individual object in .obj file; this allows
us to preserve object names. When -kn is not specified, gltfpack will
merge the meshes with the same materials anyway so the result should not
change, but with -kn the nodes will be preserved in the output file.
2023-08-21 18:12:15 -07:00
Arseny Kapoulkine 649797adde gltfpack: Preserve material names when parsing .obj files
These will be preserved in the output glTF file, and using -km option
will disable merging named materials.

Also define _CRT_NONSTDC_NO_WARNINGS to avoid MSVC warnings for strdup.
2023-08-21 18:11:55 -07:00
Arseny Kapoulkine 3c4fdbf0cd gltfpack: Properly apply Kd and d for .obj materials
Also when the material is using different texture paths for diffuse and
alpha, warn about the mismatch - we can't represent a separate alpha
mask via standard glTF materials.
2023-08-20 20:59:11 -07:00
Arseny Kapoulkine 3afa362e78 gltfpack: Implement support for extracting colors from .obj files
Note, the colors are indexed with .p as they come with each vertex
instead of using a separate index stream.
2023-08-06 09:44:55 -07:00
Arseny Kapoulkine 4874401dc2 gltfpack: Optimize .obj parsing for memory consumption
With this change we now deduplicate face vertices before creating the
vertex data, and don't create streams that we know don't exist.

This results in memory savings for loading large .obj files, although
this also regresses some:

Before:
./gltfpack -i /home/zeux/Downloads/rungholt.obj -o rh.glb 3.84 sec 924576 KB
./gltfpack -i /home/zeux/Downloads/hairball.obj -o hb.glb 1.36 sec 600440 KB
./gltfpack -i /home/zeux/Downloads/splash.obj -o sp.glb 15.12 sec 4249600 KB

After:
./gltfpack -i /home/zeux/Downloads/rungholt.obj -o rh.glb 3.91 sec 1100132 KB
./gltfpack -i /home/zeux/Downloads/hairball.obj -o hb.glb 1.26 sec 275084 KB
./gltfpack -i /home/zeux/Downloads/splash.obj -o sp.glb 12.06 sec 2766064 KB

It's not clear where the regression on rungholt comes from, although the
peak memory consumption there seems to be driven by mesh merging
instead.
2022-07-24 14:07:41 -07:00
Arseny Kapoulkine bd8b9de1bc extern: Update to latest 2022-07-23 21:05:41 -07:00
Arseny Kapoulkine ffc314f862 gltfpack: Preserve scenes during processing
Before this change gltfack wasn't scene aware, and would process all
nodes regardless of which scene they come from.

With this change, we now output the same number of scenes that the input
file contained. When merging meshes and converting nodes to mesh instances,
the process is limited to cases where the mesh is not used in multiple
scenes.

Fixes #184
2020-10-10 15:33:58 -07:00
Arseny Kapoulkine 718899ab11 gltfpack: Use zero-copy animation parsing
We now reserve the space for animation data before parsing it similarly
to mesh data.

Also clean up mesh data parsing a bit to follow a similar push_back +
back structure for streams.
2020-05-18 23:08:15 -07:00
Arseny Kapoulkine 8f342a07ae gltf: Remove _CRT_NONSTDC_WARNINGS
We can use ::remove instead of ::unlink and ::malloc instead of ::strdup
to work around the warnings.
2020-02-07 22:47:59 -08:00
Arseny Kapoulkine b895be83a6 extern: Update dependencies
Bump cgltf to 1.5 (+ warning fixes)
Bump fast_obj to latest (+ warning fixes)
2020-02-07 20:43:49 -08:00
Arseny Kapoulkine ee026dd2e7 extern: Move most third-party dependencies to extern
With the exception of miniz, third-party source is now in extern/
folder.
2020-02-07 20:27:57 -08:00
Arseny Kapoulkine a796ac8735 gltf: Fix one more MSVC error
Algorithm strikes again
2020-02-07 19:49:30 -08:00
Arseny Kapoulkine 756052d151 gltf: Move .obj parsing out of gltfpack.cpp
Also add a stub for glTF parsing, but not moving the code yet.
2020-02-07 17:56:07 -08:00