diff --git a/src/FBX2glTF.cpp b/src/FBX2glTF.cpp index 9da9144..0ff11f8 100644 --- a/src/FBX2glTF.cpp +++ b/src/FBX2glTF.cpp @@ -185,24 +185,24 @@ int main(int argc, char* argv[]) { ->type_size(-1) ->type_name("(position|normal|tangent|binormial|color|uv0|uv1|auto)"); - app.add_option( - "-d,--draco", - [&](std::vector choices) -> bool { - for (const std::string choice : choices) { - if (choice == "mesh") { - gltfOptions.draco.enabledMesh = true; - } else if (choice == "animation") { - gltfOptions.draco.enabledAnimation = true; - } else { - fmt::printf("Unknown -d,--draco: %s\n", choice); - throw CLI::RuntimeError(1); - } - } - return true; - }, - "Apply Draco mesh|animation compression to geometries|animation data.") - ->type_size(-1) - ->type_name("(mesh|animation)"); + app.add_option( + "-d,--draco", + [&](std::vector choices) -> bool { + for (const std::string choice : choices) { + if (choice == "mesh") { + gltfOptions.draco.enabledMesh = true; + } else if (choice == "animation") { + gltfOptions.draco.enabledAnimation = true; + } else { + fmt::printf("Unknown -d,--draco: %s\n", choice); + throw CLI::RuntimeError(1); + } + } + return true; + }, + "Apply Draco mesh|animation compression to geometries|animation data.") + ->type_size(-1) + ->type_name("(mesh|animation)"); app.add_option( "--draco-mesh-compression-level", @@ -252,29 +252,29 @@ int main(int argc, char* argv[]) { ->check(CLI::Range(1, 30)) ->group("Draco"); - app.add_option( - "--draco-animation-compression-level", - gltfOptions.draco.animationCompressionLevel, - "The animation compression level to tune Draco to.", - true) - ->check(CLI::Range(0, 10)) - ->group("Draco"); + app.add_option( + "--draco-animation-compression-level", + gltfOptions.draco.animationCompressionLevel, + "The animation compression level to tune Draco to.", + true) + ->check(CLI::Range(0, 10)) + ->group("Draco"); - app.add_option( - "--draco-bits-for-timestamp", - gltfOptions.draco.quantBitsTimestamp, - "How many bits to quantize timestamp to.", - true) - ->check(CLI::Range(1, 30)) - ->group("Draco"); + app.add_option( + "--draco-bits-for-timestamp", + gltfOptions.draco.quantBitsTimestamp, + "How many bits to quantize timestamp to.", + true) + ->check(CLI::Range(1, 30)) + ->group("Draco"); - app.add_option( - "--draco-bits-for-keyframe", - gltfOptions.draco.quantBitsKeyframe, - "How many bits to quantize keyframe to.", - true) - ->check(CLI::Range(1, 30)) - ->group("Draco"); + app.add_option( + "--draco-bits-for-keyframe", + gltfOptions.draco.quantBitsKeyframe, + "How many bits to quantize keyframe to.", + true) + ->check(CLI::Range(1, 30)) + ->group("Draco"); CLI11_PARSE(app, argc, argv); diff --git a/src/FBX2glTF.h b/src/FBX2glTF.h index d072b9c..45c8925 100644 --- a/src/FBX2glTF.h +++ b/src/FBX2glTF.h @@ -93,23 +93,23 @@ struct GltfOptions { /** Whether and how to use KHR_draco_mesh_compression & Draco_animation_compression to minimize static geometry size. */ struct { bool enabledMesh = false; - int compressionLevel = 7; - int quantBitsPosition = 14; - int quantBitsTexCoord = 10; - int quantBitsNormal = 10; - int quantBitsColor = 8; - int quantBitsGeneric = 8; -// int compressionLevel = -1; // 7 -// int quantBitsPosition = -1; // 14 -// int quantBitsTexCoord = -1; // 10 -// int quantBitsNormal = -1; // 10 -// int quantBitsColor = -1; // 8 -// int quantBitsGeneric = -1; // 8 + int compressionLevel = 7; + int quantBitsPosition = 14; + int quantBitsTexCoord = 10; + int quantBitsNormal = 10; + int quantBitsColor = 8; + int quantBitsGeneric = 8; + // int compressionLevel = -1; // 7 + // int quantBitsPosition = -1; // 14 + // int quantBitsTexCoord = -1; // 10 + // int quantBitsNormal = -1; // 10 + // int quantBitsColor = -1; // 8 + // int quantBitsGeneric = -1; // 8 - bool enabledAnimation = false; - int animationCompressionLevel = -1; // 5 - int quantBitsTimestamp = -1; - int quantBitsKeyframe = -1; + bool enabledAnimation = false; + int animationCompressionLevel = -1; // 5 + int quantBitsTimestamp = -1; + int quantBitsKeyframe = -1; } draco; /** Whether to include FBX User Properties as 'extras' metadata in glTF nodes. */ diff --git a/src/gltf/GltfModel.hpp b/src/gltf/GltfModel.hpp index 2c56af7..6f094ad 100644 --- a/src/gltf/GltfModel.hpp +++ b/src/gltf/GltfModel.hpp @@ -122,46 +122,46 @@ class GltfModel { return accessor; }; - template - std::shared_ptr AddTimestampsToAnimation( - BufferData& buffer, - AnimationData& animationData, - const std::vector& timestamps, - const GLType& glType, - const draco::DataType dracoComponentType) { - std::shared_ptr accessor; - if (dracoComponentType != draco::DT_INVALID && animationData.dracoKeyframeAnimation != nullptr) { - accessor = accessors.hold(new AccessorData(glType)); - accessor->count = to_uint32(timestamps.size()); - animationData.AddDracoTimestamps(*accessor, timestamps); - } else { - accessor = AddAccessorAndView(buffer, glType, timestamps); - animationData.AddTimestamps(*accessor); - } - return accessor; - }; + template + std::shared_ptr AddTimestampsToAnimation( + BufferData& buffer, + AnimationData& animationData, + const std::vector& timestamps, + const GLType& glType, + const draco::DataType dracoComponentType) { + std::shared_ptr accessor; + if (dracoComponentType != draco::DT_INVALID && animationData.dracoKeyframeAnimation != nullptr) { + accessor = accessors.hold(new AccessorData(glType)); + accessor->count = to_uint32(timestamps.size()); + animationData.AddDracoTimestamps(*accessor, timestamps); + } else { + accessor = AddAccessorAndView(buffer, glType, timestamps); + animationData.AddTimestamps(*accessor); + } + return accessor; + }; - template - std::shared_ptr AddChannelToAnimation( - BufferData& buffer, - AnimationData& animationData, - const NodeData& nDat, - const ChannelDefinition& channelDef) { - std::shared_ptr accessor; - if (channelDef.dracoComponentType != draco::DT_INVALID && animationData.dracoKeyframeAnimation != nullptr) { - accessor = accessors.hold(new AccessorData(channelDef.glType)); - accessor->count = to_uint32(channelDef.channelData.size()); - animationData.AddDracoNodeChannel( - nDat, - *accessor, - channelDef.path, - channelDef); - } else { - accessor = AddAccessorAndView(buffer, channelDef.glType, channelDef.channelData); - animationData.AddNodeChannel(nDat, *accessor, channelDef.path); - } - return accessor; - }; + template + std::shared_ptr AddChannelToAnimation( + BufferData& buffer, + AnimationData& animationData, + const NodeData& nDat, + const ChannelDefinition& channelDef) { + std::shared_ptr accessor; + if (channelDef.dracoComponentType != draco::DT_INVALID && animationData.dracoKeyframeAnimation != nullptr) { + accessor = accessors.hold(new AccessorData(channelDef.glType)); + accessor->count = to_uint32(channelDef.channelData.size()); + animationData.AddDracoNodeChannel( + nDat, + *accessor, + channelDef.path, + channelDef); + } else { + accessor = AddAccessorAndView(buffer, channelDef.glType, channelDef.channelData); + animationData.AddNodeChannel(nDat, *accessor, channelDef.path); + } + return accessor; + }; template void serializeHolder(json& glTFJson, std::string key, const Holder holder) { diff --git a/src/gltf/Raw2Gltf.hpp b/src/gltf/Raw2Gltf.hpp index 2de050e..cbc05c1 100644 --- a/src/gltf/Raw2Gltf.hpp +++ b/src/gltf/Raw2Gltf.hpp @@ -101,40 +101,40 @@ struct GLType { ((T*)buf)[3] = quaternion.scalar(); } - template - const std::vector& toStdVec(const std::vector& scalars) const { - return scalars; - } + template + const std::vector& toStdVec(const std::vector& scalars) const { + return scalars; + } - template - std::vector toStdVec(const std::vector>& vectors) const { - std::vector vec(vectors.size() * d); - std::vector component(sizeof(T) * d); - for (uint32_t ii = 0; ii < vectors.size(); ii++) { - uint8_t* ptr = &component[0]; - this->write(ptr, vectors[ii]); - const T* typePtr = (const T*)ptr; - for (uint32_t jj = 0; jj < d; ++jj) { - vec[ii * d + jj] = *(typePtr + jj); - } - } - return vec; - } + template + std::vector toStdVec(const std::vector>& vectors) const { + std::vector vec(vectors.size() * d); + std::vector component(sizeof(T) * d); + for (uint32_t ii = 0; ii < vectors.size(); ii++) { + uint8_t* ptr = &component[0]; + this->write(ptr, vectors[ii]); + const T* typePtr = (const T*)ptr; + for (uint32_t jj = 0; jj < d; ++jj) { + vec[ii * d + jj] = *(typePtr + jj); + } + } + return vec; + } - template - std::vector toStdVec(const std::vector>& quaternions) const { - std::vector vec(quaternions.size() * 4); - std::vector component(sizeof(T) * 4); - for (uint32_t ii = 0; ii < quaternions.size(); ii++) { - uint8_t* ptr = &component[0]; - this->write(ptr, quaternions[ii]); - const T* typePtr = (const T*)ptr; - for (uint32_t jj = 0; jj < 4; ++jj) { - vec[ii * 4 + jj] = *(typePtr + jj); - } - } - return vec; - } + template + std::vector toStdVec(const std::vector>& quaternions) const { + std::vector vec(quaternions.size() * 4); + std::vector component(sizeof(T) * 4); + for (uint32_t ii = 0; ii < quaternions.size(); ii++) { + uint8_t* ptr = &component[0]; + this->write(ptr, quaternions[ii]); + const T* typePtr = (const T*)ptr; + for (uint32_t jj = 0; jj < 4; ++jj) { + vec[ii * 4 + jj] = *(typePtr + jj); + } + } + return vec; + } const ComponentType componentType; const uint8_t count; @@ -195,29 +195,29 @@ struct AttributeDefinition { template struct ChannelDefinition { - const std::string path; - const std::vector& channelData; - const GLType glType; - const draco::DataType dracoComponentType; + const std::string path; + const std::vector& channelData; + const GLType glType; + const draco::DataType dracoComponentType; - ChannelDefinition( - const std::string path, - const std::vector& channelData, - const GLType& glType, - const draco::DataType dracoComponentType) - : path(std::move(path)), - channelData(channelData), - glType(glType), - dracoComponentType(dracoComponentType) {} + ChannelDefinition( + const std::string path, + const std::vector& channelData, + const GLType& glType, + const draco::DataType dracoComponentType) + : path(std::move(path)), + channelData(channelData), + glType(glType), + dracoComponentType(dracoComponentType) {} - ChannelDefinition( - const std::string path, - const std::vector& channelData, - const GLType& glType) - : path(std::move(path)), - channelData(channelData), - glType(glType), - dracoComponentType(draco::DataType::DT_INVALID) {} + ChannelDefinition( + const std::string path, + const std::vector& channelData, + const GLType& glType) + : path(std::move(path)), + channelData(channelData), + glType(glType), + dracoComponentType(draco::DataType::DT_INVALID) {} }; struct AccessorData; diff --git a/src/gltf/properties/AccessorData.cpp b/src/gltf/properties/AccessorData.cpp index ee2934b..4ecb39e 100644 --- a/src/gltf/properties/AccessorData.cpp +++ b/src/gltf/properties/AccessorData.cpp @@ -26,9 +26,9 @@ json AccessorData::serialize() const { if (bufferView >= 0) { result["bufferView"] = bufferView; } - if (byteOffset >= 0) { - result["byteOffset"] = byteOffset; - } + if (byteOffset >= 0) { + result["byteOffset"] = byteOffset; + } if (!min.empty()) { result["min"] = min; } diff --git a/src/gltf/properties/AnimationData.cpp b/src/gltf/properties/AnimationData.cpp index 3c3d2e5..1578118 100644 --- a/src/gltf/properties/AnimationData.cpp +++ b/src/gltf/properties/AnimationData.cpp @@ -13,16 +13,16 @@ #include "NodeData.hpp" AnimationData::AnimationData(std::string name) - : Holdable(), - name(std::move(name)) {} + : Holdable(), + name(std::move(name)) {} AnimationData::AnimationData(std::string name, std::shared_ptr dracoKeyframeAnimation) - : Holdable(), - name(std::move(name)), - dracoKeyframeAnimation(dracoKeyframeAnimation){} + : Holdable(), + name(std::move(name)), + dracoKeyframeAnimation(dracoKeyframeAnimation) {} void AnimationData::AddTimestamps(const AccessorData& timeAccessor) { - this->timeAccessor = timeAccessor.ix; + this->timeAccessor = timeAccessor.ix; } // assumption: 1-to-1 relationship between channels and samplers; this is a simplification on what diff --git a/src/gltf/properties/AnimationData.hpp b/src/gltf/properties/AnimationData.hpp index bd1a500..ca6c405 100644 --- a/src/gltf/properties/AnimationData.hpp +++ b/src/gltf/properties/AnimationData.hpp @@ -30,22 +30,22 @@ struct AnimationData : Holdable { // glTF can express, but it means we can rely on samplerIx == channelIx throughout an animation void AddNodeChannel(const NodeData& node, const AccessorData& accessor, std::string path); - template - void AddDracoNodeChannel( - const NodeData& node, - const AccessorData& accessor, - const std::string& path, - const ChannelDefinition& keyframe) { - assert(channels.size() == samplers.size()); - uint32_t ix = to_uint32(channels.size()); - channels.emplace_back(channel_t(ix, node, std::move(path))); - samplers.emplace_back(sampler_t(timeAccessor, accessor.ix)); + template + void AddDracoNodeChannel( + const NodeData& node, + const AccessorData& accessor, + const std::string& path, + const ChannelDefinition& keyframe) { + assert(channels.size() == samplers.size()); + uint32_t ix = to_uint32(channels.size()); + channels.emplace_back(channel_t(ix, node, std::move(path))); + samplers.emplace_back(sampler_t(timeAccessor, accessor.ix)); - dracoKeyframeAnimation->AddKeyframes( - keyframe.dracoComponentType, - keyframe.glType.count, - keyframe.glType.toStdVec(keyframe.channelData)); - } + dracoKeyframeAnimation->AddKeyframes( + keyframe.dracoComponentType, + keyframe.glType.count, + keyframe.glType.toStdVec(keyframe.channelData)); + } json serialize() const override;