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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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.