From 3030e3aedd7f395183bde3d9a00bee2a68bc56b0 Mon Sep 17 00:00:00 2001 From: owilliamailliwo <23960022aa> Date: Mon, 17 Jun 2019 10:10:06 +0800 Subject: [PATCH] Format code. --- src/gltf/Raw2Gltf.cpp | 224 +++++++++++++++++++++--------------------- 1 file changed, 112 insertions(+), 112 deletions(-) diff --git a/src/gltf/Raw2Gltf.cpp b/src/gltf/Raw2Gltf.cpp index 6463e15..4bbed12 100644 --- a/src/gltf/Raw2Gltf.cpp +++ b/src/gltf/Raw2Gltf.cpp @@ -149,7 +149,7 @@ ModelData* Raw2Gltf( nodesById.insert(std::make_pair(node.id, nodeData)); } - std::vector> accessors; + std::vector> accessors; // // animations @@ -164,21 +164,21 @@ ModelData* Raw2Gltf( continue; } - AnimationData* animationData = nullptr; - if (options.draco.enabledAnimation) { - // create Draco KeyframeAnimation - auto dracoKeyframeAnimation(std::make_shared()); - animationData = new AnimationData(animation.name, dracoKeyframeAnimation); - } else { - animationData = new AnimationData(animation.name); - } - AnimationData& aDat = *gltf->animations.hold(animationData); + AnimationData* animationData = nullptr; + if (options.draco.enabledAnimation) { + // create Draco KeyframeAnimation + auto dracoKeyframeAnimation(std::make_shared()); + animationData = new AnimationData(animation.name, dracoKeyframeAnimation); + } else { + animationData = new AnimationData(animation.name); + } + AnimationData& aDat = *gltf->animations.hold(animationData); - const auto timestampsAccessor = - gltf->AddTimestampsToAnimation(buffer, aDat, animation.times, GLT_FLOAT, draco::DT_FLOAT32); - 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)) }; - accessors.emplace_back(timestampsAccessor); + const auto timestampsAccessor = + gltf->AddTimestampsToAnimation(buffer, aDat, animation.times, GLT_FLOAT, draco::DT_FLOAT32); + 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)) }; + accessors.emplace_back(timestampsAccessor); if (verboseOutput) { fmt::printf( @@ -203,83 +203,83 @@ ModelData* Raw2Gltf( } NodeData& nDat = require(nodesById, node.id); - if (!channel.translations.empty()) { - const ChannelDefinition CHANNEL_TRANSLATIONS( - "translation", - channel.translations, - GLT_VEC3F, - draco::DT_FLOAT32); - const auto _ = - gltf->AddChannelToAnimation(buffer, aDat, nDat, CHANNEL_TRANSLATIONS); - accessors.emplace_back(_); - } - if (!channel.rotations.empty()) { - const ChannelDefinition CHANNEL_ROTATIONS( - "rotation", - channel.rotations, - GLT_QUATF, - draco::DT_FLOAT32); - const auto _ = - gltf->AddChannelToAnimation(buffer, aDat, nDat, CHANNEL_ROTATIONS); - accessors.emplace_back(_); - } - if (!channel.scales.empty()) { - const ChannelDefinition CHANNEL_SCALES( - "scale", - channel.scales, - GLT_VEC3F, - draco::DT_FLOAT32); - const auto _ = - gltf->AddChannelToAnimation(buffer, aDat, nDat, CHANNEL_SCALES); - accessors.emplace_back(_); - } - if (!channel.weights.empty()) { - const ChannelDefinition CHANNEL_WEIGHTS( - "weights", - channel.weights, - { CT_FLOAT, 1, "SCALAR" }, - draco::DT_FLOAT32); - const auto _ = - gltf->AddChannelToAnimation(buffer, aDat, nDat, CHANNEL_WEIGHTS); - accessors.emplace_back(_); - } + if (!channel.translations.empty()) { + const ChannelDefinition CHANNEL_TRANSLATIONS( + "translation", + channel.translations, + GLT_VEC3F, + draco::DT_FLOAT32); + const auto _ = + gltf->AddChannelToAnimation(buffer, aDat, nDat, CHANNEL_TRANSLATIONS); + accessors.emplace_back(_); + } + if (!channel.rotations.empty()) { + const ChannelDefinition CHANNEL_ROTATIONS( + "rotation", + channel.rotations, + GLT_QUATF, + draco::DT_FLOAT32); + const auto _ = + gltf->AddChannelToAnimation(buffer, aDat, nDat, CHANNEL_ROTATIONS); + accessors.emplace_back(_); + } + if (!channel.scales.empty()) { + const ChannelDefinition CHANNEL_SCALES( + "scale", + channel.scales, + GLT_VEC3F, + draco::DT_FLOAT32); + const auto _ = + gltf->AddChannelToAnimation(buffer, aDat, nDat, CHANNEL_SCALES); + accessors.emplace_back(_); + } + if (!channel.weights.empty()) { + const ChannelDefinition CHANNEL_WEIGHTS( + "weights", + channel.weights, + { CT_FLOAT, 1, "SCALAR" }, + draco::DT_FLOAT32); + const auto _ = + gltf->AddChannelToAnimation(buffer, aDat, nDat, CHANNEL_WEIGHTS); + accessors.emplace_back(_); + } } - if (options.draco.enabledAnimation) { - draco::EncoderOptions encodeOptions = draco::EncoderOptions::CreateDefaultOptions(); - if (options.draco.animationCompressionLevel != -1) { - int dracoSpeed = 10 - options.draco.animationCompressionLevel; - int en = dracoSpeed; - int de = dracoSpeed; - encodeOptions.SetSpeed(en, de); - } + if (options.draco.enabledAnimation) { + draco::EncoderOptions encodeOptions = draco::EncoderOptions::CreateDefaultOptions(); + if (options.draco.animationCompressionLevel != -1) { + int dracoSpeed = 10 - options.draco.animationCompressionLevel; + int en = dracoSpeed; + int de = dracoSpeed; + encodeOptions.SetSpeed(en, de); + } - if (-1 != options.draco.quantBitsTimestamp) { - // set quantization for timestamps. - encodeOptions.SetAttributeInt(0, "quantization_bits", options.draco.quantBitsTimestamp); - } + if (-1 != options.draco.quantBitsTimestamp) { + // set quantization for timestamps. + encodeOptions.SetAttributeInt(0, "quantization_bits", options.draco.quantBitsTimestamp); + } - if (-1 != options.draco.quantBitsKeyframe) { - // set quantization for keyframes. - for (int i = 1; i <= aDat.dracoKeyframeAnimation->num_animations(); ++i) { - encodeOptions.SetAttributeInt(i, "quantization_bits", options.draco.quantBitsKeyframe); - } - } + if (-1 != options.draco.quantBitsKeyframe) { + // set quantization for keyframes. + for (int i = 1; i <= aDat.dracoKeyframeAnimation->num_animations(); ++i) { + encodeOptions.SetAttributeInt(i, "quantization_bits", options.draco.quantBitsKeyframe); + } + } - draco::EncoderBuffer dracoBuffer; - draco::KeyframeAnimationEncoder encoder; - draco::Status status = encoder.EncodeKeyframeAnimation(*(aDat.dracoKeyframeAnimation), encodeOptions, &dracoBuffer); - assert(status.code() == draco::Status::OK); - auto view = gltf->AddRawBufferView(buffer, dracoBuffer.data(), to_uint32(dracoBuffer.size())); - dracoBuffer.Clear(); + draco::EncoderBuffer dracoBuffer; + draco::KeyframeAnimationEncoder encoder; + draco::Status status = encoder.EncodeKeyframeAnimation(*(aDat.dracoKeyframeAnimation), encodeOptions, &dracoBuffer); + assert(status.code() == draco::Status::OK); + auto view = gltf->AddRawBufferView(buffer, dracoBuffer.data(), to_uint32(dracoBuffer.size())); + dracoBuffer.Clear(); - for (auto accessor : accessors) - { - accessor->bufferView = view->ix; - accessor->byteOffset = -1; - } - } - accessors.clear(); + for (auto accessor : accessors) + { + accessor->bufferView = view->ix; + accessor->byteOffset = -1; + } + } + accessors.clear(); } // @@ -523,11 +523,11 @@ ModelData* Raw2Gltf( dracoMesh->SetFace(draco::FaceIndex(ii), face); } - std::shared_ptr indexes = - gltf->accessors.hold(new AccessorData(useLongIndices ? GLT_UINT : GLT_USHORT)); + std::shared_ptr indexes = + gltf->accessors.hold(new AccessorData(useLongIndices ? GLT_UINT : GLT_USHORT)); indexes->count = to_uint32(3 * triangleCount); primitive.reset(new PrimitiveData(*indexes, mData, dracoMesh)); - accessors.emplace_back(indexes); + accessors.emplace_back(indexes); } else { const AccessorData& indexes = *gltf->AddAccessorWithView( @@ -554,7 +554,7 @@ ModelData* Raw2Gltf( accessor->min = toStdVec(rawSurface.bounds.min); accessor->max = toStdVec(rawSurface.bounds.max); - accessors.emplace_back(accessor); + accessors.emplace_back(accessor); } if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_NORMAL) != 0) { const AttributeDefinition ATTR_NORMAL( @@ -564,13 +564,13 @@ ModelData* Raw2Gltf( draco::GeometryAttribute::NORMAL, draco::DT_FLOAT32); const auto _ = - gltf->AddAttributeToPrimitive(buffer, surfaceModel, *primitive, ATTR_NORMAL); - accessors.emplace_back(_); + gltf->AddAttributeToPrimitive(buffer, surfaceModel, *primitive, ATTR_NORMAL); + accessors.emplace_back(_); } if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_TANGENT) != 0) { const AttributeDefinition ATTR_TANGENT("TANGENT", &RawVertex::tangent, GLT_VEC4F); const auto _ = gltf->AddAttributeToPrimitive(buffer, surfaceModel, *primitive, ATTR_TANGENT); - accessors.emplace_back(_); + accessors.emplace_back(_); } if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_COLOR) != 0) { const AttributeDefinition ATTR_COLOR( @@ -581,8 +581,8 @@ ModelData* Raw2Gltf( draco::DT_FLOAT32); const auto _ = gltf->AddAttributeToPrimitive(buffer, surfaceModel, *primitive, ATTR_COLOR); - accessors.emplace_back(_); - } + accessors.emplace_back(_); + } if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_UV0) != 0) { const AttributeDefinition ATTR_TEXCOORD_0( "TEXCOORD_0", @@ -592,7 +592,7 @@ ModelData* Raw2Gltf( draco::DT_FLOAT32); const auto _ = gltf->AddAttributeToPrimitive( buffer, surfaceModel, *primitive, ATTR_TEXCOORD_0); - accessors.emplace_back(_); + accessors.emplace_back(_); } if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_UV1) != 0) { const AttributeDefinition ATTR_TEXCOORD_1( @@ -603,7 +603,7 @@ ModelData* Raw2Gltf( draco::DT_FLOAT32); const auto _ = gltf->AddAttributeToPrimitive( buffer, surfaceModel, *primitive, ATTR_TEXCOORD_1); - accessors.emplace_back(_); + accessors.emplace_back(_); } if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_JOINT_INDICES) != 0) { const AttributeDefinition ATTR_JOINTS( @@ -614,8 +614,8 @@ ModelData* Raw2Gltf( draco::DT_UINT16); const auto _ = gltf->AddAttributeToPrimitive(buffer, surfaceModel, *primitive, ATTR_JOINTS); - accessors.emplace_back(_); - } + accessors.emplace_back(_); + } if ((surfaceModel.GetVertexAttributes() & RAW_VERTEX_ATTRIBUTE_JOINT_WEIGHTS) != 0) { const AttributeDefinition ATTR_WEIGHTS( "WEIGHTS_0", @@ -625,8 +625,8 @@ ModelData* Raw2Gltf( draco::DT_FLOAT32); const auto _ = gltf->AddAttributeToPrimitive(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 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())); primitive->NoteDracoBuffer(*view); - dracoBuffer.Clear(); + dracoBuffer.Clear(); - for (auto accessor : accessors) - { - accessor->bufferView = view->ix; - accessor->byteOffset = -1; - } + for (auto accessor : accessors) + { + accessor->bufferView = view->ix; + accessor->byteOffset = -1; + } } - accessors.clear(); + accessors.clear(); mesh->AddPrimitive(primitive); } @@ -890,10 +890,10 @@ ModelData* Raw2Gltf( extensionsUsed.push_back(KHR_DRACO_MESH_COMPRESSION); extensionsRequired.push_back(KHR_DRACO_MESH_COMPRESSION); } - if (options.draco.enabledAnimation) { - extensionsUsed.push_back(DRACO_ANIMATION_COMPRESSION); - extensionsRequired.push_back(DRACO_ANIMATION_COMPRESSION); - } + if (options.draco.enabledAnimation) { + extensionsUsed.push_back(DRACO_ANIMATION_COMPRESSION); + extensionsRequired.push_back(DRACO_ANIMATION_COMPRESSION); + } json glTFJson{{"asset", {{"generator", "FBX2glTF v" + FBX2GLTF_VERSION}, {"version", "2.0"}}}, {"scene", rootScene.ix}};