Skip to content

Commit

Permalink
gltfpack: Change the defaults to copy textures to output
Browse files Browse the repository at this point in the history
To fix consistency issues with output by default, we now default to
copying (.gltf)/embedding (.glb) textures with or without compression.

There are cases when the previous behavior is desireable. This change
adds a new option, -tr, that keeps the references to original textures
without processing. Notably, this also works for .glb outputs, allowing
to avoid embedding textures into .glb.

When compressing textures, -tr is not currently supported because we do
need to produce new file data. In the future we could consider
supporting -tr by saving the .ktx2 files side by side with the original
images.
  • Loading branch information
zeux committed Oct 5, 2023
1 parent c6d03d7 commit 2d23333
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions gltf/gltfpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1348,9 +1348,9 @@ int main(int argc, char** argv)
{
settings.texture_flipy = true;
}
else if (strcmp(arg, "-tcp") == 0)
else if (strcmp(arg, "-tr") == 0)
{
settings.texture_copy = true;
settings.texture_ref = true;
}
else if (strcmp(arg, "-tj") == 0 && i + 1 < argc && isdigit(argv[i + 1][0]))
{
Expand Down Expand Up @@ -1459,6 +1459,7 @@ int main(int argc, char** argv)
fprintf(stderr, "\t-tp: resize textures to nearest power of 2 to conform to WebGL1 restrictions\n");
fprintf(stderr, "\t-tfy: flip textures along Y axis during BasisU supercompression\n");
fprintf(stderr, "\t-tj N: use N threads when compressing textures\n");
fprintf(stderr, "\t-tr: keep referring to original texture paths instead of copying/embedding images\n");
fprintf(stderr, "\tTexture classes:\n");
fprintf(stderr, "\t-tc C: use ETC1S when encoding textures of class C\n");
fprintf(stderr, "\t-tu C: use UASTC when encoding textures of class C\n");
Expand Down Expand Up @@ -1543,6 +1544,12 @@ int main(int argc, char** argv)
return 1;
}

if (settings.texture_ref && settings.texture_ktx2)
{
fprintf(stderr, "Option -tr currently can not be used together with -tc\n");
return 1;
}

if (settings.fallback && settings.compressmore)
{
fprintf(stderr, "Option -cf can not be used together with -cc\n");
Expand Down
2 changes: 1 addition & 1 deletion gltf/gltfpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct Settings

bool texture_ktx2;
bool texture_embed;
bool texture_copy;
bool texture_ref;

bool texture_pow2;
bool texture_flipy;
Expand Down
2 changes: 1 addition & 1 deletion gltf/write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ void writeImage(std::string& json, std::vector<BufferView>& views, const cgltf_i
{
bool dataUri = image.uri && strncmp(image.uri, "data:", 5) == 0;

if (image.uri && !dataUri && !settings.texture_embed && !settings.texture_copy)
if (image.uri && !dataUri && settings.texture_ref)
{
// fast-path: we don't need to read the image to memory
append(json, "\"uri\":\"");
Expand Down

0 comments on commit 2d23333

Please sign in to comment.