Format code.
This commit is contained in:
parent
3e83b4e9d3
commit
3030e3aedd
|
@ -149,7 +149,7 @@ ModelData* Raw2Gltf(
|
||||||
nodesById.insert(std::make_pair(node.id, nodeData));
|
nodesById.insert(std::make_pair(node.id, nodeData));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<AccessorData>> accessors;
|
std::vector<std::shared_ptr<AccessorData>> accessors;
|
||||||
|
|
||||||
//
|
//
|
||||||
// animations
|
// animations
|
||||||
|
@ -164,21 +164,21 @@ ModelData* Raw2Gltf(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationData* animationData = nullptr;
|
AnimationData* animationData = nullptr;
|
||||||
if (options.draco.enabledAnimation) {
|
if (options.draco.enabledAnimation) {
|
||||||
// create Draco KeyframeAnimation
|
// create Draco KeyframeAnimation
|
||||||
auto dracoKeyframeAnimation(std::make_shared<draco::KeyframeAnimation>());
|
auto dracoKeyframeAnimation(std::make_shared<draco::KeyframeAnimation>());
|
||||||
animationData = new AnimationData(animation.name, dracoKeyframeAnimation);
|
animationData = new AnimationData(animation.name, dracoKeyframeAnimation);
|
||||||
} else {
|
} else {
|
||||||
animationData = new AnimationData(animation.name);
|
animationData = new AnimationData(animation.name);
|
||||||
}
|
}
|
||||||
AnimationData& aDat = *gltf->animations.hold(animationData);
|
AnimationData& aDat = *gltf->animations.hold(animationData);
|
||||||
|
|
||||||
const auto timestampsAccessor =
|
const auto timestampsAccessor =
|
||||||
gltf->AddTimestampsToAnimation<float>(buffer, aDat, animation.times, GLT_FLOAT, draco::DT_FLOAT32);
|
gltf->AddTimestampsToAnimation<float>(buffer, aDat, animation.times, GLT_FLOAT, draco::DT_FLOAT32);
|
||||||
timestampsAccessor->min = { *std::min_element(std::begin(animation.times), std::end(animation.times)) };
|
timestampsAccessor->min = { *std::min_element(std::begin(animation.times), std::end(animation.times)) };
|
||||||
timestampsAccessor->max = { *std::max_element(std::begin(animation.times), std::end(animation.times)) };
|
timestampsAccessor->max = { *std::max_element(std::begin(animation.times), std::end(animation.times)) };
|
||||||
accessors.emplace_back(timestampsAccessor);
|
accessors.emplace_back(timestampsAccessor);
|
||||||
|
|
||||||
if (verboseOutput) {
|
if (verboseOutput) {
|
||||||
fmt::printf(
|
fmt::printf(
|
||||||
|
@ -203,83 +203,83 @@ ModelData* Raw2Gltf(
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeData& nDat = require(nodesById, node.id);
|
NodeData& nDat = require(nodesById, node.id);
|
||||||
if (!channel.translations.empty()) {
|
if (!channel.translations.empty()) {
|
||||||
const ChannelDefinition<Vec3f> CHANNEL_TRANSLATIONS(
|
const ChannelDefinition<Vec3f> CHANNEL_TRANSLATIONS(
|
||||||
"translation",
|
"translation",
|
||||||
channel.translations,
|
channel.translations,
|
||||||
GLT_VEC3F,
|
GLT_VEC3F,
|
||||||
draco::DT_FLOAT32);
|
draco::DT_FLOAT32);
|
||||||
const auto _ =
|
const auto _ =
|
||||||
gltf->AddChannelToAnimation<Vec3f>(buffer, aDat, nDat, CHANNEL_TRANSLATIONS);
|
gltf->AddChannelToAnimation<Vec3f>(buffer, aDat, nDat, CHANNEL_TRANSLATIONS);
|
||||||
accessors.emplace_back(_);
|
accessors.emplace_back(_);
|
||||||
}
|
}
|
||||||
if (!channel.rotations.empty()) {
|
if (!channel.rotations.empty()) {
|
||||||
const ChannelDefinition<Quatf> CHANNEL_ROTATIONS(
|
const ChannelDefinition<Quatf> CHANNEL_ROTATIONS(
|
||||||
"rotation",
|
"rotation",
|
||||||
channel.rotations,
|
channel.rotations,
|
||||||
GLT_QUATF,
|
GLT_QUATF,
|
||||||
draco::DT_FLOAT32);
|
draco::DT_FLOAT32);
|
||||||
const auto _ =
|
const auto _ =
|
||||||
gltf->AddChannelToAnimation<Quatf>(buffer, aDat, nDat, CHANNEL_ROTATIONS);
|
gltf->AddChannelToAnimation<Quatf>(buffer, aDat, nDat, CHANNEL_ROTATIONS);
|
||||||
accessors.emplace_back(_);
|
accessors.emplace_back(_);
|
||||||
}
|
}
|
||||||
if (!channel.scales.empty()) {
|
if (!channel.scales.empty()) {
|
||||||
const ChannelDefinition<Vec3f> CHANNEL_SCALES(
|
const ChannelDefinition<Vec3f> CHANNEL_SCALES(
|
||||||
"scale",
|
"scale",
|
||||||
channel.scales,
|
channel.scales,
|
||||||
GLT_VEC3F,
|
GLT_VEC3F,
|
||||||
draco::DT_FLOAT32);
|
draco::DT_FLOAT32);
|
||||||
const auto _ =
|
const auto _ =
|
||||||
gltf->AddChannelToAnimation<Vec3f>(buffer, aDat, nDat, CHANNEL_SCALES);
|
gltf->AddChannelToAnimation<Vec3f>(buffer, aDat, nDat, CHANNEL_SCALES);
|
||||||
accessors.emplace_back(_);
|
accessors.emplace_back(_);
|
||||||
}
|
}
|
||||||
if (!channel.weights.empty()) {
|
if (!channel.weights.empty()) {
|
||||||
const ChannelDefinition<float> CHANNEL_WEIGHTS(
|
const ChannelDefinition<float> CHANNEL_WEIGHTS(
|
||||||
"weights",
|
"weights",
|
||||||
channel.weights,
|
channel.weights,
|
||||||
{ CT_FLOAT, 1, "SCALAR" },
|
{ CT_FLOAT, 1, "SCALAR" },
|
||||||
draco::DT_FLOAT32);
|
draco::DT_FLOAT32);
|
||||||
const auto _ =
|
const auto _ =
|
||||||
gltf->AddChannelToAnimation<float>(buffer, aDat, nDat, CHANNEL_WEIGHTS);
|
gltf->AddChannelToAnimation<float>(buffer, aDat, nDat, CHANNEL_WEIGHTS);
|
||||||
accessors.emplace_back(_);
|
accessors.emplace_back(_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.draco.enabledAnimation) {
|
if (options.draco.enabledAnimation) {
|
||||||
draco::EncoderOptions encodeOptions = draco::EncoderOptions::CreateDefaultOptions();
|
draco::EncoderOptions encodeOptions = draco::EncoderOptions::CreateDefaultOptions();
|
||||||
if (options.draco.animationCompressionLevel != -1) {
|
if (options.draco.animationCompressionLevel != -1) {
|
||||||
int dracoSpeed = 10 - options.draco.animationCompressionLevel;
|
int dracoSpeed = 10 - options.draco.animationCompressionLevel;
|
||||||
int en = dracoSpeed;
|
int en = dracoSpeed;
|
||||||
int de = dracoSpeed;
|
int de = dracoSpeed;
|
||||||
encodeOptions.SetSpeed(en, de);
|
encodeOptions.SetSpeed(en, de);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-1 != options.draco.quantBitsTimestamp) {
|
if (-1 != options.draco.quantBitsTimestamp) {
|
||||||
// set quantization for timestamps.
|
// set quantization for timestamps.
|
||||||
encodeOptions.SetAttributeInt(0, "quantization_bits", options.draco.quantBitsTimestamp);
|
encodeOptions.SetAttributeInt(0, "quantization_bits", options.draco.quantBitsTimestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-1 != options.draco.quantBitsKeyframe) {
|
if (-1 != options.draco.quantBitsKeyframe) {
|
||||||
// set quantization for keyframes.
|
// set quantization for keyframes.
|
||||||
for (int i = 1; i <= aDat.dracoKeyframeAnimation->num_animations(); ++i) {
|
for (int i = 1; i <= aDat.dracoKeyframeAnimation->num_animations(); ++i) {
|
||||||
encodeOptions.SetAttributeInt(i, "quantization_bits", options.draco.quantBitsKeyframe);
|
encodeOptions.SetAttributeInt(i, "quantization_bits", options.draco.quantBitsKeyframe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
draco::EncoderBuffer dracoBuffer;
|
draco::EncoderBuffer dracoBuffer;
|
||||||
draco::KeyframeAnimationEncoder encoder;
|
draco::KeyframeAnimationEncoder encoder;
|
||||||
draco::Status status = encoder.EncodeKeyframeAnimation(*(aDat.dracoKeyframeAnimation), encodeOptions, &dracoBuffer);
|
draco::Status status = encoder.EncodeKeyframeAnimation(*(aDat.dracoKeyframeAnimation), encodeOptions, &dracoBuffer);
|
||||||
assert(status.code() == draco::Status::OK);
|
assert(status.code() == draco::Status::OK);
|
||||||
auto view = gltf->AddRawBufferView(buffer, dracoBuffer.data(), to_uint32(dracoBuffer.size()));
|
auto view = gltf->AddRawBufferView(buffer, dracoBuffer.data(), to_uint32(dracoBuffer.size()));
|
||||||
dracoBuffer.Clear();
|
dracoBuffer.Clear();
|
||||||
|
|
||||||
for (auto accessor : accessors)
|
for (auto accessor : accessors)
|
||||||
{
|
{
|
||||||
accessor->bufferView = view->ix;
|
accessor->bufferView = view->ix;
|
||||||
accessor->byteOffset = -1;
|
accessor->byteOffset = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
accessors.clear();
|
accessors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -523,11 +523,11 @@ ModelData* Raw2Gltf(
|
||||||
dracoMesh->SetFace(draco::FaceIndex(ii), face);
|
dracoMesh->SetFace(draco::FaceIndex(ii), face);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<AccessorData> indexes =
|
std::shared_ptr<AccessorData> indexes =
|
||||||
gltf->accessors.hold(new AccessorData(useLongIndices ? GLT_UINT : GLT_USHORT));
|
gltf->accessors.hold(new AccessorData(useLongIndices ? GLT_UINT : GLT_USHORT));
|
||||||
indexes->count = to_uint32(3 * triangleCount);
|
indexes->count = to_uint32(3 * triangleCount);
|
||||||
primitive.reset(new PrimitiveData(*indexes, mData, dracoMesh));
|
primitive.reset(new PrimitiveData(*indexes, mData, dracoMesh));
|
||||||
accessors.emplace_back(indexes);
|
accessors.emplace_back(indexes);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
const AccessorData& indexes = *gltf->AddAccessorWithView(
|
const AccessorData& indexes = *gltf->AddAccessorWithView(
|
||||||
|
@ -554,7 +554,7 @@ ModelData* Raw2Gltf(
|
||||||
|
|
||||||
accessor->min = toStdVec(rawSurface.bounds.min);
|
accessor->min = toStdVec(rawSurface.bounds.min);
|
||||||
accessor->max = toStdVec(rawSurface.bounds.max);
|
accessor->max = toStdVec(rawSurface.bounds.max);
|
||||||
accessors.emplace_back(accessor);
|
accessors.emplace_back(accessor);
|
||||||
}
|
}
|
||||||
if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_NORMAL) != 0) {
|
if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_NORMAL) != 0) {
|
||||||
const AttributeDefinition<Vec3f> ATTR_NORMAL(
|
const AttributeDefinition<Vec3f> ATTR_NORMAL(
|
||||||
|
@ -564,13 +564,13 @@ ModelData* Raw2Gltf(
|
||||||
draco::GeometryAttribute::NORMAL,
|
draco::GeometryAttribute::NORMAL,
|
||||||
draco::DT_FLOAT32);
|
draco::DT_FLOAT32);
|
||||||
const auto _ =
|
const auto _ =
|
||||||
gltf->AddAttributeToPrimitive<Vec3f>(buffer, surfaceModel, *primitive, ATTR_NORMAL);
|
gltf->AddAttributeToPrimitive<Vec3f>(buffer, surfaceModel, *primitive, ATTR_NORMAL);
|
||||||
accessors.emplace_back(_);
|
accessors.emplace_back(_);
|
||||||
}
|
}
|
||||||
if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_TANGENT) != 0) {
|
if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_TANGENT) != 0) {
|
||||||
const AttributeDefinition<Vec4f> ATTR_TANGENT("TANGENT", &RawVertex::tangent, GLT_VEC4F);
|
const AttributeDefinition<Vec4f> ATTR_TANGENT("TANGENT", &RawVertex::tangent, GLT_VEC4F);
|
||||||
const auto _ = gltf->AddAttributeToPrimitive<Vec4f>(buffer, surfaceModel, *primitive, ATTR_TANGENT);
|
const auto _ = gltf->AddAttributeToPrimitive<Vec4f>(buffer, surfaceModel, *primitive, ATTR_TANGENT);
|
||||||
accessors.emplace_back(_);
|
accessors.emplace_back(_);
|
||||||
}
|
}
|
||||||
if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_COLOR) != 0) {
|
if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_COLOR) != 0) {
|
||||||
const AttributeDefinition<Vec4f> ATTR_COLOR(
|
const AttributeDefinition<Vec4f> ATTR_COLOR(
|
||||||
|
@ -581,8 +581,8 @@ ModelData* Raw2Gltf(
|
||||||
draco::DT_FLOAT32);
|
draco::DT_FLOAT32);
|
||||||
const auto _ =
|
const auto _ =
|
||||||
gltf->AddAttributeToPrimitive<Vec4f>(buffer, surfaceModel, *primitive, ATTR_COLOR);
|
gltf->AddAttributeToPrimitive<Vec4f>(buffer, surfaceModel, *primitive, ATTR_COLOR);
|
||||||
accessors.emplace_back(_);
|
accessors.emplace_back(_);
|
||||||
}
|
}
|
||||||
if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_UV0) != 0) {
|
if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_UV0) != 0) {
|
||||||
const AttributeDefinition<Vec2f> ATTR_TEXCOORD_0(
|
const AttributeDefinition<Vec2f> ATTR_TEXCOORD_0(
|
||||||
"TEXCOORD_0",
|
"TEXCOORD_0",
|
||||||
|
@ -592,7 +592,7 @@ ModelData* Raw2Gltf(
|
||||||
draco::DT_FLOAT32);
|
draco::DT_FLOAT32);
|
||||||
const auto _ = gltf->AddAttributeToPrimitive<Vec2f>(
|
const auto _ = gltf->AddAttributeToPrimitive<Vec2f>(
|
||||||
buffer, surfaceModel, *primitive, ATTR_TEXCOORD_0);
|
buffer, surfaceModel, *primitive, ATTR_TEXCOORD_0);
|
||||||
accessors.emplace_back(_);
|
accessors.emplace_back(_);
|
||||||
}
|
}
|
||||||
if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_UV1) != 0) {
|
if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_UV1) != 0) {
|
||||||
const AttributeDefinition<Vec2f> ATTR_TEXCOORD_1(
|
const AttributeDefinition<Vec2f> ATTR_TEXCOORD_1(
|
||||||
|
@ -603,7 +603,7 @@ ModelData* Raw2Gltf(
|
||||||
draco::DT_FLOAT32);
|
draco::DT_FLOAT32);
|
||||||
const auto _ = gltf->AddAttributeToPrimitive<Vec2f>(
|
const auto _ = gltf->AddAttributeToPrimitive<Vec2f>(
|
||||||
buffer, surfaceModel, *primitive, ATTR_TEXCOORD_1);
|
buffer, surfaceModel, *primitive, ATTR_TEXCOORD_1);
|
||||||
accessors.emplace_back(_);
|
accessors.emplace_back(_);
|
||||||
}
|
}
|
||||||
if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_JOINT_INDICES) != 0) {
|
if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_JOINT_INDICES) != 0) {
|
||||||
const AttributeDefinition<Vec4i> ATTR_JOINTS(
|
const AttributeDefinition<Vec4i> ATTR_JOINTS(
|
||||||
|
@ -614,8 +614,8 @@ ModelData* Raw2Gltf(
|
||||||
draco::DT_UINT16);
|
draco::DT_UINT16);
|
||||||
const auto _ =
|
const auto _ =
|
||||||
gltf->AddAttributeToPrimitive<Vec4i>(buffer, surfaceModel, *primitive, ATTR_JOINTS);
|
gltf->AddAttributeToPrimitive<Vec4i>(buffer, surfaceModel, *primitive, ATTR_JOINTS);
|
||||||
accessors.emplace_back(_);
|
accessors.emplace_back(_);
|
||||||
}
|
}
|
||||||
if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_JOINT_WEIGHTS) != 0) {
|
if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_JOINT_WEIGHTS) != 0) {
|
||||||
const AttributeDefinition<Vec4f> ATTR_WEIGHTS(
|
const AttributeDefinition<Vec4f> ATTR_WEIGHTS(
|
||||||
"WEIGHTS_0",
|
"WEIGHTS_0",
|
||||||
|
@ -625,8 +625,8 @@ ModelData* Raw2Gltf(
|
||||||
draco::DT_FLOAT32);
|
draco::DT_FLOAT32);
|
||||||
const auto _ =
|
const auto _ =
|
||||||
gltf->AddAttributeToPrimitive<Vec4f>(buffer, surfaceModel, *primitive, ATTR_WEIGHTS);
|
gltf->AddAttributeToPrimitive<Vec4f>(buffer, surfaceModel, *primitive, ATTR_WEIGHTS);
|
||||||
accessors.emplace_back(_);
|
accessors.emplace_back(_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// each channel present in the mesh always ends up a target in the primitive
|
// each channel present in the mesh always ends up a target in the primitive
|
||||||
for (int channelIx = 0; channelIx < rawSurface.blendChannels.size(); channelIx++) {
|
for (int channelIx = 0; channelIx < rawSurface.blendChannels.size(); channelIx++) {
|
||||||
|
@ -712,15 +712,15 @@ ModelData* Raw2Gltf(
|
||||||
|
|
||||||
auto view = gltf->AddRawBufferView(buffer, dracoBuffer.data(), to_uint32(dracoBuffer.size()));
|
auto view = gltf->AddRawBufferView(buffer, dracoBuffer.data(), to_uint32(dracoBuffer.size()));
|
||||||
primitive->NoteDracoBuffer(*view);
|
primitive->NoteDracoBuffer(*view);
|
||||||
dracoBuffer.Clear();
|
dracoBuffer.Clear();
|
||||||
|
|
||||||
for (auto accessor : accessors)
|
for (auto accessor : accessors)
|
||||||
{
|
{
|
||||||
accessor->bufferView = view->ix;
|
accessor->bufferView = view->ix;
|
||||||
accessor->byteOffset = -1;
|
accessor->byteOffset = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
accessors.clear();
|
accessors.clear();
|
||||||
mesh->AddPrimitive(primitive);
|
mesh->AddPrimitive(primitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -890,10 +890,10 @@ ModelData* Raw2Gltf(
|
||||||
extensionsUsed.push_back(KHR_DRACO_MESH_COMPRESSION);
|
extensionsUsed.push_back(KHR_DRACO_MESH_COMPRESSION);
|
||||||
extensionsRequired.push_back(KHR_DRACO_MESH_COMPRESSION);
|
extensionsRequired.push_back(KHR_DRACO_MESH_COMPRESSION);
|
||||||
}
|
}
|
||||||
if (options.draco.enabledAnimation) {
|
if (options.draco.enabledAnimation) {
|
||||||
extensionsUsed.push_back(DRACO_ANIMATION_COMPRESSION);
|
extensionsUsed.push_back(DRACO_ANIMATION_COMPRESSION);
|
||||||
extensionsRequired.push_back(DRACO_ANIMATION_COMPRESSION);
|
extensionsRequired.push_back(DRACO_ANIMATION_COMPRESSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
json glTFJson{{"asset", {{"generator", "FBX2glTF v" + FBX2GLTF_VERSION}, {"version", "2.0"}}},
|
json glTFJson{{"asset", {{"generator", "FBX2glTF v" + FBX2GLTF_VERSION}, {"version", "2.0"}}},
|
||||||
{"scene", rootScene.ix}};
|
{"scene", rootScene.ix}};
|
||||||
|
|
Loading…
Reference in New Issue