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_name("(position|normal|tangent|binormial|color|uv0|uv1|auto)");
app.add_option(
"-d,--draco",
[&](std::vector<std::string> 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<std::string> 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);

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

View File

@ -122,46 +122,46 @@ class GltfModel {
return accessor;
};
template <class T>
std::shared_ptr<AccessorData> AddTimestampsToAnimation(
BufferData& buffer,
AnimationData& animationData,
const std::vector<T>& timestamps,
const GLType& glType,
const draco::DataType dracoComponentType) {
std::shared_ptr<AccessorData> 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 <class T>
std::shared_ptr<AccessorData> AddTimestampsToAnimation(
BufferData& buffer,
AnimationData& animationData,
const std::vector<T>& timestamps,
const GLType& glType,
const draco::DataType dracoComponentType) {
std::shared_ptr<AccessorData> 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 <class T>
std::shared_ptr<AccessorData> AddChannelToAnimation(
BufferData& buffer,
AnimationData& animationData,
const NodeData& nDat,
const ChannelDefinition<T>& channelDef) {
std::shared_ptr<AccessorData> 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 <class T>
std::shared_ptr<AccessorData> AddChannelToAnimation(
BufferData& buffer,
AnimationData& animationData,
const NodeData& nDat,
const ChannelDefinition<T>& channelDef) {
std::shared_ptr<AccessorData> 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 <class T>
void serializeHolder(json& glTFJson, std::string key, const Holder<T> holder) {

View File

@ -101,40 +101,40 @@ struct GLType {
((T*)buf)[3] = quaternion.scalar();
}
template <class T>
const std::vector<T>& toStdVec(const std::vector<T>& scalars) const {
return scalars;
}
template <class T>
const std::vector<T>& toStdVec(const std::vector<T>& scalars) const {
return scalars;
}
template <class T, int d>
std::vector<T> toStdVec(const std::vector<mathfu::Vector<T, d>>& vectors) const {
std::vector<T> vec(vectors.size() * d);
std::vector<uint8_t> 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 <class T, int d>
std::vector<T> toStdVec(const std::vector<mathfu::Vector<T, d>>& vectors) const {
std::vector<T> vec(vectors.size() * d);
std::vector<uint8_t> 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 <class T>
std::vector<T> toStdVec(const std::vector<mathfu::Quaternion<T>>& quaternions) const {
std::vector<T> vec(quaternions.size() * 4);
std::vector<uint8_t> 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 <class T>
std::vector<T> toStdVec(const std::vector<mathfu::Quaternion<T>>& quaternions) const {
std::vector<T> vec(quaternions.size() * 4);
std::vector<uint8_t> 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 <class T>
struct ChannelDefinition {
const std::string path;
const std::vector<T>& channelData;
const GLType glType;
const draco::DataType dracoComponentType;
const std::string path;
const std::vector<T>& channelData;
const GLType glType;
const draco::DataType dracoComponentType;
ChannelDefinition(
const std::string path,
const std::vector<T>& 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<T>& 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<T>& 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<T>& channelData,
const GLType& glType)
: path(std::move(path)),
channelData(channelData),
glType(glType),
dracoComponentType(draco::DataType::DT_INVALID) {}
};
struct AccessorData;

View File

@ -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;
}

View File

@ -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<draco::KeyframeAnimation> 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

View File

@ -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 <class T>
void AddDracoNodeChannel(
const NodeData& node,
const AccessorData& accessor,
const std::string& path,
const ChannelDefinition<T>& 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 <class T>
void AddDracoNodeChannel(
const NodeData& node,
const AccessorData& accessor,
const std::string& path,
const ChannelDefinition<T>& 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;