Format everything.

This commit is contained in:
K. S. Ernest (iFire) Lee 2021-11-28 11:45:31 -08:00
parent b89d4cd0e0
commit 1bcdf9271e
16 changed files with 129 additions and 116 deletions

View File

@ -229,8 +229,8 @@ static void ReadMesh(
targetShapes.push_back(&shape);
auto& blendChannel = blendShapes.GetBlendChannel(channelIx);
rawSurface.blendChannels.push_back(
RawBlendChannel{static_cast<float>(blendChannel.deformPercent),
rawSurface.blendChannels.push_back(RawBlendChannel{
static_cast<float>(blendChannel.deformPercent),
shape.normals.LayerPresent(),
shape.tangents.LayerPresent(),
blendChannel.name});

View File

@ -59,14 +59,13 @@ FbxSkinningAccess::FbxSkinningAccess(const FbxMesh* pMesh, FbxScene* pScene, Fbx
continue;
}
vertexSkinning[clusterIndices[i]].push_back(FbxVertexSkinningInfo{(int) clusterIndex, (float)clusterWeights[i]});
vertexSkinning[clusterIndices[i]].push_back(
FbxVertexSkinningInfo{(int)clusterIndex, (float)clusterWeights[i]});
}
}
for (int i = 0; i < vertexSkinning.size(); i++)
maxBoneInfluences = std::max((int)vertexSkinning[i].size(), maxBoneInfluences);
}
}

View File

@ -23,17 +23,14 @@ struct FbxVertexSkinningInfo {
float weight;
};
class FbxSkinningAccess {
public:
FbxSkinningAccess(const FbxMesh* pMesh, FbxScene* pScene, FbxNode* pNode);
bool IsSkinned() const {
return (vertexSkinning.size() > 0);
}
int GetNodeCount() const {
return (int)jointNodes.size();
}
@ -63,7 +60,8 @@ class FbxSkinningAccess {
return inverseBindMatrices[jointIndex];
}
const std::vector<FbxVertexSkinningInfo> GetVertexSkinningInfo(const int controlPointIndex) const {
const std::vector<FbxVertexSkinningInfo> GetVertexSkinningInfo(
const int controlPointIndex) const {
return vertexSkinning[controlPointIndex];
}

View File

@ -45,8 +45,7 @@ FbxMaterialsAccess::FbxMaterialsAccess(
continue;
}
auto* surfaceMaterial =
mesh->GetNode()->GetSrcObject<FbxSurfaceMaterial>(materialNum);
auto* surfaceMaterial = mesh->GetNode()->GetSrcObject<FbxSurfaceMaterial>(materialNum);
if (!surfaceMaterial) {
if (++warnMtrCount == 1) {
@ -67,7 +66,6 @@ FbxMaterialsAccess::FbxMaterialsAccess(
userProperties.resize(materialNum + 1);
}
if (surfaceMaterial && userProperties[materialNum].empty()) {
FbxProperty objectProperty = surfaceMaterial->GetFirstProperty();
while (objectProperty.IsValid()) {
if (objectProperty.GetFlag(FbxPropertyFlags::eUserDefined)) {

View File

@ -640,7 +640,8 @@ ModelData* Raw2Gltf(
for (int jj = 0; jj < surfaceModel.GetVertexCount(); jj++) {
auto blendVertex = surfaceModel.GetVertex(jj).blends[channelIx];
shapeBounds.AddPoint(blendVertex.position);
bool isSparseVertex = options.disableSparseBlendShapes; // If sparse is off, add all vertices
bool isSparseVertex =
options.disableSparseBlendShapes; // If sparse is off, add all vertices
// Check to see whether position, normal or tangent deviates from base mesh and flag as
// sparse.
if (blendVertex.position.Length() > 0.00) {

View File

@ -213,7 +213,8 @@ std::shared_ptr<TextureData> TextureBuilder::simple(int rawTexIndex, const std::
}
if (!image) {
// fallback is tiny transparent PNG
// image = new ImageData(textureName, "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==");
// image = new ImageData(textureName,
// "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==");
return nullptr;
}

View File

@ -18,7 +18,12 @@ AccessorData::AccessorData(const BufferViewData& bufferView, GLType type, std::s
name(name),
sparse(false) {}
AccessorData::AccessorData(const AccessorData& baseAccessor, const BufferViewData& sparseIdxBufferView, const BufferViewData& sparseDataBufferView, GLType type, std::string name)
AccessorData::AccessorData(
const AccessorData& baseAccessor,
const BufferViewData& sparseIdxBufferView,
const BufferViewData& sparseDataBufferView,
GLType type,
std::string name)
: Holdable(),
bufferView(baseAccessor.bufferView),
type(std::move(type)),
@ -51,12 +56,13 @@ json AccessorData::serialize() const {
}
if (sparse) {
json sparseData = {{"count", sparseIdxCount}};
sparseData["indices"] = { {"bufferView", sparseIdxBufferView},
sparseData["indices"] = {
{"bufferView", sparseIdxBufferView},
{"byteOffset", sparseIdxBufferViewOffset},
{"componentType", sparseIdxBufferViewType}};
sparseData["values"] = { {"bufferView", sparseDataBufferView},
{"byteOffset", sparseDataBufferViewOffset}};
sparseData["values"] = {
{"bufferView", sparseDataBufferView}, {"byteOffset", sparseDataBufferViewOffset}};
result["sparse"] = sparseData;
}

View File

@ -13,7 +13,12 @@
struct AccessorData : Holdable {
AccessorData(const BufferViewData& bufferView, GLType type, std::string name);
explicit AccessorData(GLType type);
AccessorData(const AccessorData& baseAccessor, const BufferViewData& sparseIdxBufferView, const BufferViewData& sparseDataBufferView, GLType type, std::string name);
AccessorData(
const AccessorData& baseAccessor,
const BufferViewData& sparseIdxBufferView,
const BufferViewData& sparseDataBufferView,
GLType type,
std::string name);
json serialize() const override;

View File

@ -38,7 +38,8 @@ AnimationData::channel_t::channel_t(uint32_t ix, const NodeData& node, std::stri
AnimationData::sampler_t::sampler_t(uint32_t time, uint32_t output) : time(time), output(output) {}
void to_json(json& j, const AnimationData::channel_t& data) {
j = json{{"sampler", data.ix},
j = json{
{"sampler", data.ix},
{
"target",
{{"node", data.node}, {"path", data.path}},

View File

@ -92,7 +92,8 @@ MaterialData::MaterialData(
pbrMetallicRoughness(pbrMetallicRoughness) {}
json MaterialData::serialize() const {
json result = {{"name", name},
json result = {
{"name", name},
{"alphaMode", isTransparent ? "BLEND" : "OPAQUE"},
{"extras",
{{"fromFBX",

View File

@ -73,7 +73,8 @@ void to_json(json& j, const PrimitiveData& d) {
j["targets"] = targets;
}
if (!d.dracoAttributes.empty()) {
j["extensions"] = {{KHR_DRACO_MESH_COMPRESSION,
j["extensions"] = {
{KHR_DRACO_MESH_COMPRESSION,
{{"bufferView", d.dracoBufferView}, {"attributes", d.dracoAttributes}}}};
}
}

View File

@ -60,7 +60,9 @@ struct PrimitiveData {
}
template <class T>
void AddDracoArrayAttrib(const AttributeArrayDefinition<T> attribute, const std::vector<T>& attribArr) {
void AddDracoArrayAttrib(
const AttributeArrayDefinition<T> attribute,
const std::vector<T>& attribArr) {
draco::PointAttribute att;
int8_t componentCount = attribute.glType.count;
att.Init(

View File

@ -21,7 +21,8 @@ SkinData::SkinData(
skeletonRootNode(skeletonRootNode.ix) {}
json SkinData::serialize() const {
return {{"joints", joints},
return {
{"joints", joints},
{"inverseBindMatrices", inverseBindMatrices},
{"skeleton", skeletonRootNode}};
}

View File

@ -34,9 +34,8 @@ size_t VertexHasher::operator()(const RawVertex& v) const {
bool RawVertex::operator==(const RawVertex& other) const {
return (position == other.position) && (normal == other.normal) && (tangent == other.tangent) &&
(binormal == other.binormal) && (color == other.color) && (uv0 == other.uv0) &&
(uv1 == other.uv1) &&
(jointWeights == other.jointWeights) && (jointIndices == other.jointIndices) &&
(polarityUv0 == other.polarityUv0) &&
(uv1 == other.uv1) && (jointWeights == other.jointWeights) &&
(jointIndices == other.jointIndices) && (polarityUv0 == other.polarityUv0) &&
(blendSurfaceIx == other.blendSurfaceIx) && (blends == other.blends);
}
@ -407,9 +406,11 @@ void RawModel::Condense(const int maxSkinningWeights, const bool normalizeWeight
{
globalMaxWeights = 0;
for (auto& vertex : vertices) {
// Sort from largest to smallest weight.
std::sort(vertex.skinningInfo.begin(), vertex.skinningInfo.end(), std::greater<RawVertexSkinningInfo>());
std::sort(
vertex.skinningInfo.begin(),
vertex.skinningInfo.end(),
std::greater<RawVertexSkinningInfo>());
// Reduce to fit the requirements.
if (maxSkinningWeights < vertex.skinningInfo.size())
@ -432,13 +433,13 @@ void RawModel::Condense(const int maxSkinningWeights, const bool normalizeWeight
AddVertexAttribute(RAW_VERTEX_ATTRIBUTE_JOINT_WEIGHTS);
}
assert(globalMaxWeights >= 0);
// Copy to gltf friendly structure
for (auto& vertex : vertices) {
vertex.jointIndices.reserve(globalMaxWeights);
vertex.jointWeights.reserve(globalMaxWeights);
for (int i = 0; i < globalMaxWeights; i += 4) { // ensure every vertex has the same amount of weights
for (int i = 0; i < globalMaxWeights;
i += 4) { // ensure every vertex has the same amount of weights
Vec4f weights{0.0};
Vec4i jointIds{0, 0, 0, 0};
for (int j = i; j < i + 4 && j < vertex.skinningInfo.size(); j++) {

View File

@ -38,8 +38,7 @@ struct RawBlendVertex {
}
};
struct RawVertexSkinningInfo
{
struct RawVertexSkinningInfo {
int jointIndex;
float jointWeight;
@ -359,7 +358,6 @@ struct RawNode {
class RawModel {
public:
RawModel();
// Add geometry.
@ -527,10 +525,10 @@ class RawModel {
// Create individual attribute arrays, with the source as an array.
// Returns true if the vertices store the particular attribute.
template <typename _attrib_type_>
void GetArrayAttributeArray(std::vector<_attrib_type_>& out,
void GetArrayAttributeArray(
std::vector<_attrib_type_>& out,
const std::vector<_attrib_type_> RawVertex::*ptr,
const int arrayOffset)
const;
const int arrayOffset) const;
// Create an array with a raw model for each material.
// Multiple surfaces with the same material will turn into a single model.