Add separate textures flag.
Don't convert tga to png/jpg if the texture is already converted
This commit is contained in:
parent
762a183b6b
commit
a3dfcda66e
|
@ -51,6 +51,10 @@ int main(int argc, char* argv[]) {
|
||||||
"-e,--embed",
|
"-e,--embed",
|
||||||
gltfOptions.embedResources,
|
gltfOptions.embedResources,
|
||||||
"Inline buffers as data:// URIs within generated non-binary glTF.");
|
"Inline buffers as data:// URIs within generated non-binary glTF.");
|
||||||
|
|
||||||
|
app.add_flag(
|
||||||
|
"-t,--separate-textures", gltfOptions.separateTextures, "Write texture files out separately");
|
||||||
|
|
||||||
app.add_flag("-b,--binary", gltfOptions.outputBinary, "Output a single binary format .glb file.");
|
app.add_flag("-b,--binary", gltfOptions.outputBinary, "Output a single binary format .glb file.");
|
||||||
|
|
||||||
app.add_option(
|
app.add_option(
|
||||||
|
@ -321,6 +325,7 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
if (gltfOptions.outputBinary) {
|
if (gltfOptions.outputBinary) {
|
||||||
// add .glb to output path, unless it already ends in exactly that
|
// add .glb to output path, unless it already ends in exactly that
|
||||||
|
outputFolder = FileUtils::getFolder(outputPath) + "/";
|
||||||
if (suffix.has_value() && suffix.value() == "glb") {
|
if (suffix.has_value() && suffix.value() == "glb") {
|
||||||
modelPath = outputPath;
|
modelPath = outputPath;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -90,6 +90,8 @@ struct GltfOptions {
|
||||||
/** If non-binary, whether to inline all resources, for a single (large) .glTF file. */
|
/** If non-binary, whether to inline all resources, for a single (large) .glTF file. */
|
||||||
bool embedResources{false};
|
bool embedResources{false};
|
||||||
|
|
||||||
|
bool separateTextures{true};
|
||||||
|
|
||||||
/** Whether and how to use KHR_draco_mesh_compression to minimize static geometry size. */
|
/** Whether and how to use KHR_draco_mesh_compression to minimize static geometry size. */
|
||||||
struct {
|
struct {
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
|
|
|
@ -18,6 +18,10 @@
|
||||||
#include <gltf/properties/ImageData.hpp>
|
#include <gltf/properties/ImageData.hpp>
|
||||||
#include <gltf/properties/TextureData.hpp>
|
#include <gltf/properties/TextureData.hpp>
|
||||||
|
|
||||||
|
#ifdef CopyFile
|
||||||
|
#undef CopyFile
|
||||||
|
#endif
|
||||||
|
|
||||||
// keep track of some texture data as we load them
|
// keep track of some texture data as we load them
|
||||||
struct TexInfo {
|
struct TexInfo {
|
||||||
explicit TexInfo(int rawTexIx) : rawTexIx(rawTexIx) {}
|
explicit TexInfo(int rawTexIx) : rawTexIx(rawTexIx) {}
|
||||||
|
@ -138,7 +142,7 @@ std::shared_ptr<TextureData> TextureBuilder::combine(
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageData* image;
|
ImageData* image;
|
||||||
if (options.outputBinary) {
|
if (options.outputBinary && !options.separateTextures) {
|
||||||
const auto bufferView =
|
const auto bufferView =
|
||||||
gltf.AddRawBufferView(*gltf.defaultBuffer, imgBuffer.data(), to_uint32(imgBuffer.size()));
|
gltf.AddRawBufferView(*gltf.defaultBuffer, imgBuffer.data(), to_uint32(imgBuffer.size()));
|
||||||
image = new ImageData(mergedName, *bufferView, png ? "image/png" : "image/jpeg");
|
image = new ImageData(mergedName, *bufferView, png ? "image/png" : "image/jpeg");
|
||||||
|
@ -200,18 +204,17 @@ std::shared_ptr<TextureData> TextureBuilder::simple(int rawTexIndex, const std::
|
||||||
|
|
||||||
} else if (!relativeFilename.empty()) {
|
} else if (!relativeFilename.empty()) {
|
||||||
image = new ImageData(relativeFilename, relativeFilename);
|
image = new ImageData(relativeFilename, relativeFilename);
|
||||||
std::string outputPath = outputFolder + "/" + relativeFilename;
|
|
||||||
auto srcAbs = FileUtils::GetAbsolutePath(rawTexture.fileLocation);
|
auto srcAbs = FileUtils::GetAbsolutePath(rawTexture.fileLocation);
|
||||||
auto dstAbs = FileUtils::GetAbsolutePath(outputPath);
|
if (!FileUtils::FileExists(outputPath) && srcAbs != dstAbs) {
|
||||||
if (srcAbs != dstAbs)
|
if (FileUtils::CopyFile(rawTexture.fileLocation, outputPath, true)) {
|
||||||
if (FileUtils::CopyFile(rawTexture.fileLocation, outputPath, true)) {
|
if (verboseOutput) {
|
||||||
if (verboseOutput) {
|
fmt::printf("Copied texture '%s' to output folder: %s\n", textureName, outputPath);
|
||||||
fmt::printf("Copied texture '%s' to output folder: %s\n", textureName, outputPath);
|
}
|
||||||
|
} else {
|
||||||
|
// no point commenting further on read/write error; CopyFile() does enough of that, and we
|
||||||
|
// certainly want to to add an image struct to the glTF JSON, with the correct relative
|
||||||
|
// path reference, even if the copy failed.
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// no point commenting further on read/write error; CopyFile() does enough of that, and we
|
|
||||||
// certainly want to to add an image struct to the glTF JSON, with the correct relative path
|
|
||||||
// reference, even if the copy failed.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!image) {
|
if (!image) {
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
#include "FBX2glTF.h"
|
#include "FBX2glTF.h"
|
||||||
#include "String_Utils.hpp"
|
#include "String_Utils.hpp"
|
||||||
|
|
||||||
|
#ifdef CopyFile
|
||||||
|
#undef CopyFile
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace FileUtils {
|
namespace FileUtils {
|
||||||
|
|
||||||
std::vector<std::string> ListFolderFiles(
|
std::vector<std::string> ListFolderFiles(
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
|
#ifdef CopyFile
|
||||||
|
#undef CopyFile
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace FileUtils {
|
namespace FileUtils {
|
||||||
|
|
||||||
std::string GetCurrentFolder();
|
std::string GetCurrentFolder();
|
||||||
|
@ -34,7 +38,7 @@ bool CopyFile(
|
||||||
bool createPath = false);
|
bool createPath = false);
|
||||||
|
|
||||||
inline std::string GetAbsolutePath(const std::string& filePath) {
|
inline std::string GetAbsolutePath(const std::string& filePath) {
|
||||||
return boost::filesystem::canonical(boost::filesystem::absolute(filePath)).string();
|
return boost::filesystem::absolute(filePath).string();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string GetCurrentFolder() {
|
inline std::string GetCurrentFolder() {
|
||||||
|
|
Loading…
Reference in New Issue