Format code.

This commit is contained in:
owilliamailliwo 2019-06-17 08:16:44 +08:00
parent df71c8ff0a
commit 3e83b4e9d3
7 changed files with 171 additions and 171 deletions

View File

@ -185,24 +185,24 @@ int main(int argc, char* argv[]) {
->type_size(-1) ->type_size(-1)
->type_name("(position|normal|tangent|binormial|color|uv0|uv1|auto)"); ->type_name("(position|normal|tangent|binormial|color|uv0|uv1|auto)");
app.add_option( app.add_option(
"-d,--draco", "-d,--draco",
[&](std::vector<std::string> choices) -> bool { [&](std::vector<std::string> choices) -> bool {
for (const std::string choice : choices) { for (const std::string choice : choices) {
if (choice == "mesh") { if (choice == "mesh") {
gltfOptions.draco.enabledMesh = true; gltfOptions.draco.enabledMesh = true;
} else if (choice == "animation") { } else if (choice == "animation") {
gltfOptions.draco.enabledAnimation = true; gltfOptions.draco.enabledAnimation = true;
} else { } else {
fmt::printf("Unknown -d,--draco: %s\n", choice); fmt::printf("Unknown -d,--draco: %s\n", choice);
throw CLI::RuntimeError(1); throw CLI::RuntimeError(1);
} }
} }
return true; return true;
}, },
"Apply Draco mesh|animation compression to geometries|animation data.") "Apply Draco mesh|animation compression to geometries|animation data.")
->type_size(-1) ->type_size(-1)
->type_name("(mesh|animation)"); ->type_name("(mesh|animation)");
app.add_option( app.add_option(
"--draco-mesh-compression-level", "--draco-mesh-compression-level",
@ -252,29 +252,29 @@ int main(int argc, char* argv[]) {
->check(CLI::Range(1, 30)) ->check(CLI::Range(1, 30))
->group("Draco"); ->group("Draco");
app.add_option( app.add_option(
"--draco-animation-compression-level", "--draco-animation-compression-level",
gltfOptions.draco.animationCompressionLevel, gltfOptions.draco.animationCompressionLevel,
"The animation compression level to tune Draco to.", "The animation compression level to tune Draco to.",
true) true)
->check(CLI::Range(0, 10)) ->check(CLI::Range(0, 10))
->group("Draco"); ->group("Draco");
app.add_option( app.add_option(
"--draco-bits-for-timestamp", "--draco-bits-for-timestamp",
gltfOptions.draco.quantBitsTimestamp, gltfOptions.draco.quantBitsTimestamp,
"How many bits to quantize timestamp to.", "How many bits to quantize timestamp to.",
true) true)
->check(CLI::Range(1, 30)) ->check(CLI::Range(1, 30))
->group("Draco"); ->group("Draco");
app.add_option( app.add_option(
"--draco-bits-for-keyframe", "--draco-bits-for-keyframe",
gltfOptions.draco.quantBitsKeyframe, gltfOptions.draco.quantBitsKeyframe,
"How many bits to quantize keyframe to.", "How many bits to quantize keyframe to.",
true) true)
->check(CLI::Range(1, 30)) ->check(CLI::Range(1, 30))
->group("Draco"); ->group("Draco");
CLI11_PARSE(app, argc, argv); CLI11_PARSE(app, argc, argv);

View File

@ -93,23 +93,23 @@ struct GltfOptions {
/** Whether and how to use KHR_draco_mesh_compression & Draco_animation_compression to minimize static geometry size. */ /** Whether and how to use KHR_draco_mesh_compression & Draco_animation_compression to minimize static geometry size. */
struct { struct {
bool enabledMesh = false; bool enabledMesh = false;
int compressionLevel = 7; int compressionLevel = 7;
int quantBitsPosition = 14; int quantBitsPosition = 14;
int quantBitsTexCoord = 10; int quantBitsTexCoord = 10;
int quantBitsNormal = 10; int quantBitsNormal = 10;
int quantBitsColor = 8; int quantBitsColor = 8;
int quantBitsGeneric = 8; int quantBitsGeneric = 8;
// int compressionLevel = -1; // 7 // int compressionLevel = -1; // 7
// int quantBitsPosition = -1; // 14 // int quantBitsPosition = -1; // 14
// int quantBitsTexCoord = -1; // 10 // int quantBitsTexCoord = -1; // 10
// int quantBitsNormal = -1; // 10 // int quantBitsNormal = -1; // 10
// int quantBitsColor = -1; // 8 // int quantBitsColor = -1; // 8
// int quantBitsGeneric = -1; // 8 // int quantBitsGeneric = -1; // 8
bool enabledAnimation = false; bool enabledAnimation = false;
int animationCompressionLevel = -1; // 5 int animationCompressionLevel = -1; // 5
int quantBitsTimestamp = -1; int quantBitsTimestamp = -1;
int quantBitsKeyframe = -1; int quantBitsKeyframe = -1;
} draco; } draco;
/** Whether to include FBX User Properties as 'extras' metadata in glTF nodes. */ /** Whether to include FBX User Properties as 'extras' metadata in glTF nodes. */

View File

@ -122,46 +122,46 @@ class GltfModel {
return accessor; return accessor;
}; };
template <class T> template <class T>
std::shared_ptr<AccessorData> AddTimestampsToAnimation( std::shared_ptr<AccessorData> AddTimestampsToAnimation(
BufferData& buffer, BufferData& buffer,
AnimationData& animationData, AnimationData& animationData,
const std::vector<T>& timestamps, const std::vector<T>& timestamps,
const GLType& glType, const GLType& glType,
const draco::DataType dracoComponentType) { const draco::DataType dracoComponentType) {
std::shared_ptr<AccessorData> accessor; std::shared_ptr<AccessorData> accessor;
if (dracoComponentType != draco::DT_INVALID && animationData.dracoKeyframeAnimation != nullptr) { if (dracoComponentType != draco::DT_INVALID && animationData.dracoKeyframeAnimation != nullptr) {
accessor = accessors.hold(new AccessorData(glType)); accessor = accessors.hold(new AccessorData(glType));
accessor->count = to_uint32(timestamps.size()); accessor->count = to_uint32(timestamps.size());
animationData.AddDracoTimestamps(*accessor, timestamps); animationData.AddDracoTimestamps(*accessor, timestamps);
} else { } else {
accessor = AddAccessorAndView(buffer, glType, timestamps); accessor = AddAccessorAndView(buffer, glType, timestamps);
animationData.AddTimestamps(*accessor); animationData.AddTimestamps(*accessor);
} }
return accessor; return accessor;
}; };
template <class T> template <class T>
std::shared_ptr<AccessorData> AddChannelToAnimation( std::shared_ptr<AccessorData> AddChannelToAnimation(
BufferData& buffer, BufferData& buffer,
AnimationData& animationData, AnimationData& animationData,
const NodeData& nDat, const NodeData& nDat,
const ChannelDefinition<T>& channelDef) { const ChannelDefinition<T>& channelDef) {
std::shared_ptr<AccessorData> accessor; std::shared_ptr<AccessorData> accessor;
if (channelDef.dracoComponentType != draco::DT_INVALID && animationData.dracoKeyframeAnimation != nullptr) { if (channelDef.dracoComponentType != draco::DT_INVALID && animationData.dracoKeyframeAnimation != nullptr) {
accessor = accessors.hold(new AccessorData(channelDef.glType)); accessor = accessors.hold(new AccessorData(channelDef.glType));
accessor->count = to_uint32(channelDef.channelData.size()); accessor->count = to_uint32(channelDef.channelData.size());
animationData.AddDracoNodeChannel( animationData.AddDracoNodeChannel(
nDat, nDat,
*accessor, *accessor,
channelDef.path, channelDef.path,
channelDef); channelDef);
} else { } else {
accessor = AddAccessorAndView(buffer, channelDef.glType, channelDef.channelData); accessor = AddAccessorAndView(buffer, channelDef.glType, channelDef.channelData);
animationData.AddNodeChannel(nDat, *accessor, channelDef.path); animationData.AddNodeChannel(nDat, *accessor, channelDef.path);
} }
return accessor; return accessor;
}; };
template <class T> template <class T>
void serializeHolder(json& glTFJson, std::string key, const Holder<T> holder) { void serializeHolder(json& glTFJson, std::string key, const Holder<T> holder) {

View File

@ -101,40 +101,40 @@ struct GLType {
((T*)buf)[3] = quaternion.scalar(); ((T*)buf)[3] = quaternion.scalar();
} }
template <class T> template <class T>
const std::vector<T>& toStdVec(const std::vector<T>& scalars) const { const std::vector<T>& toStdVec(const std::vector<T>& scalars) const {
return scalars; return scalars;
} }
template <class T, int d> template <class T, int d>
std::vector<T> toStdVec(const std::vector<mathfu::Vector<T, d>>& vectors) const { std::vector<T> toStdVec(const std::vector<mathfu::Vector<T, d>>& vectors) const {
std::vector<T> vec(vectors.size() * d); std::vector<T> vec(vectors.size() * d);
std::vector<uint8_t> component(sizeof(T) * d); std::vector<uint8_t> component(sizeof(T) * d);
for (uint32_t ii = 0; ii < vectors.size(); ii++) { for (uint32_t ii = 0; ii < vectors.size(); ii++) {
uint8_t* ptr = &component[0]; uint8_t* ptr = &component[0];
this->write(ptr, vectors[ii]); this->write(ptr, vectors[ii]);
const T* typePtr = (const T*)ptr; const T* typePtr = (const T*)ptr;
for (uint32_t jj = 0; jj < d; ++jj) { for (uint32_t jj = 0; jj < d; ++jj) {
vec[ii * d + jj] = *(typePtr + jj); vec[ii * d + jj] = *(typePtr + jj);
} }
} }
return vec; return vec;
} }
template <class T> template <class T>
std::vector<T> toStdVec(const std::vector<mathfu::Quaternion<T>>& quaternions) const { std::vector<T> toStdVec(const std::vector<mathfu::Quaternion<T>>& quaternions) const {
std::vector<T> vec(quaternions.size() * 4); std::vector<T> vec(quaternions.size() * 4);
std::vector<uint8_t> component(sizeof(T) * 4); std::vector<uint8_t> component(sizeof(T) * 4);
for (uint32_t ii = 0; ii < quaternions.size(); ii++) { for (uint32_t ii = 0; ii < quaternions.size(); ii++) {
uint8_t* ptr = &component[0]; uint8_t* ptr = &component[0];
this->write(ptr, quaternions[ii]); this->write(ptr, quaternions[ii]);
const T* typePtr = (const T*)ptr; const T* typePtr = (const T*)ptr;
for (uint32_t jj = 0; jj < 4; ++jj) { for (uint32_t jj = 0; jj < 4; ++jj) {
vec[ii * 4 + jj] = *(typePtr + jj); vec[ii * 4 + jj] = *(typePtr + jj);
} }
} }
return vec; return vec;
} }
const ComponentType componentType; const ComponentType componentType;
const uint8_t count; const uint8_t count;
@ -195,29 +195,29 @@ struct AttributeDefinition {
template <class T> template <class T>
struct ChannelDefinition { struct ChannelDefinition {
const std::string path; const std::string path;
const std::vector<T>& channelData; const std::vector<T>& channelData;
const GLType glType; const GLType glType;
const draco::DataType dracoComponentType; const draco::DataType dracoComponentType;
ChannelDefinition( ChannelDefinition(
const std::string path, const std::string path,
const std::vector<T>& channelData, const std::vector<T>& channelData,
const GLType& glType, const GLType& glType,
const draco::DataType dracoComponentType) const draco::DataType dracoComponentType)
: path(std::move(path)), : path(std::move(path)),
channelData(channelData), channelData(channelData),
glType(glType), glType(glType),
dracoComponentType(dracoComponentType) {} dracoComponentType(dracoComponentType) {}
ChannelDefinition( ChannelDefinition(
const std::string path, const std::string path,
const std::vector<T>& channelData, const std::vector<T>& channelData,
const GLType& glType) const GLType& glType)
: path(std::move(path)), : path(std::move(path)),
channelData(channelData), channelData(channelData),
glType(glType), glType(glType),
dracoComponentType(draco::DataType::DT_INVALID) {} dracoComponentType(draco::DataType::DT_INVALID) {}
}; };
struct AccessorData; struct AccessorData;

View File

@ -26,9 +26,9 @@ json AccessorData::serialize() const {
if (bufferView >= 0) { if (bufferView >= 0) {
result["bufferView"] = bufferView; result["bufferView"] = bufferView;
} }
if (byteOffset >= 0) { if (byteOffset >= 0) {
result["byteOffset"] = byteOffset; result["byteOffset"] = byteOffset;
} }
if (!min.empty()) { if (!min.empty()) {
result["min"] = min; result["min"] = min;
} }

View File

@ -13,16 +13,16 @@
#include "NodeData.hpp" #include "NodeData.hpp"
AnimationData::AnimationData(std::string name) AnimationData::AnimationData(std::string name)
: Holdable(), : Holdable(),
name(std::move(name)) {} name(std::move(name)) {}
AnimationData::AnimationData(std::string name, std::shared_ptr<draco::KeyframeAnimation> dracoKeyframeAnimation) AnimationData::AnimationData(std::string name, std::shared_ptr<draco::KeyframeAnimation> dracoKeyframeAnimation)
: Holdable(), : Holdable(),
name(std::move(name)), name(std::move(name)),
dracoKeyframeAnimation(dracoKeyframeAnimation){} dracoKeyframeAnimation(dracoKeyframeAnimation) {}
void AnimationData::AddTimestamps(const AccessorData& timeAccessor) { 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 // assumption: 1-to-1 relationship between channels and samplers; this is a simplification on what

View File

@ -30,22 +30,22 @@ struct AnimationData : Holdable {
// glTF can express, but it means we can rely on samplerIx == channelIx throughout an animation // 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); void AddNodeChannel(const NodeData& node, const AccessorData& accessor, std::string path);
template <class T> template <class T>
void AddDracoNodeChannel( void AddDracoNodeChannel(
const NodeData& node, const NodeData& node,
const AccessorData& accessor, const AccessorData& accessor,
const std::string& path, const std::string& path,
const ChannelDefinition<T>& keyframe) { const ChannelDefinition<T>& keyframe) {
assert(channels.size() == samplers.size()); assert(channels.size() == samplers.size());
uint32_t ix = to_uint32(channels.size()); uint32_t ix = to_uint32(channels.size());
channels.emplace_back(channel_t(ix, node, std::move(path))); channels.emplace_back(channel_t(ix, node, std::move(path)));
samplers.emplace_back(sampler_t(timeAccessor, accessor.ix)); samplers.emplace_back(sampler_t(timeAccessor, accessor.ix));
dracoKeyframeAnimation->AddKeyframes( dracoKeyframeAnimation->AddKeyframes(
keyframe.dracoComponentType, keyframe.dracoComponentType,
keyframe.glType.count, keyframe.glType.count,
keyframe.glType.toStdVec(keyframe.channelData)); keyframe.glType.toStdVec(keyframe.channelData));
} }
json serialize() const override; json serialize() const override;