Allow arbitrary number of skinning weights. Controlled through command line parameter. Defaults to 4.
This commit is contained in:
parent
c4395b9b92
commit
10f4ac856f
|
@ -151,7 +151,7 @@ int main(int argc, char* argv[]) {
|
|||
gltfOptions.maxSkinningWeights,
|
||||
"How many joint influences per vertex are allowed.",
|
||||
true)
|
||||
->check(CLI::Range(1, RawModel::MAX_SUPPORTED_WEIGHTS));
|
||||
->check(CLI::Range(0, 512));
|
||||
|
||||
app.add_option(
|
||||
"-k,--keep-attribute",
|
||||
|
|
|
@ -536,7 +536,6 @@ ModelData* Raw2Gltf(
|
|||
for (int i = 0; i < surfaceModel.GetGlobalWeightCount(); i += 4) {
|
||||
const AttributeArrayDefinition<Vec4i> ATTR_JOINTS(
|
||||
std::string("JOINTS_") + std::to_string(i/4),
|
||||
//"JOINTS_0",
|
||||
&RawVertex::jointIndices,
|
||||
GLT_VEC4I,
|
||||
draco::GeometryAttribute::GENERIC,
|
||||
|
@ -549,7 +548,6 @@ ModelData* Raw2Gltf(
|
|||
for (int i = 0; i < surfaceModel.GetGlobalWeightCount(); i += 4) {
|
||||
const AttributeArrayDefinition<Vec4f> ATTR_WEIGHTS(
|
||||
std::string("WEIGHTS_") + std::to_string(i/4),
|
||||
//"WEIGHTS_0",
|
||||
&RawVertex::jointWeights,
|
||||
GLT_VEC4F,
|
||||
draco::GeometryAttribute::GENERIC,
|
||||
|
|
|
@ -173,7 +173,7 @@ struct AttributeDefinition {
|
|||
template <class T>
|
||||
struct AttributeArrayDefinition {
|
||||
const std::string gltfName;
|
||||
const T (RawVertex::*rawAttributeIx)[(RawModel::MAX_SUPPORTED_WEIGHTS -1 ) / 4 + 1];
|
||||
const std::vector<T> RawVertex::*rawAttributeIx;
|
||||
const GLType glType;
|
||||
const int arrayOffset;
|
||||
const draco::GeometryAttribute::Type dracoAttribute;
|
||||
|
@ -181,7 +181,7 @@ struct AttributeArrayDefinition {
|
|||
|
||||
AttributeArrayDefinition(
|
||||
const std::string gltfName,
|
||||
const T (RawVertex::*rawAttributeIx)[(RawModel::MAX_SUPPORTED_WEIGHTS - 1) / 4 + 1],
|
||||
const std::vector<T> RawVertex::*rawAttributeIx,
|
||||
const GLType& _glType,
|
||||
const draco::GeometryAttribute::Type dracoAttribute,
|
||||
const draco::DataType dracoComponentType,
|
||||
|
|
|
@ -425,19 +425,20 @@ void RawModel::Condense(const int maxSkinningWeights, const bool normalizeWeight
|
|||
}
|
||||
|
||||
|
||||
assert(globalMaxWeights <= RawModel::MAX_SUPPORTED_WEIGHTS);
|
||||
assert(globalMaxWeights >= 0);
|
||||
// Copy to gltf friendly structure
|
||||
for (auto& vertex : vertices) {
|
||||
for (int i = 0; i < globalMaxWeights; i += 4) {
|
||||
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
|
||||
Vec4f weights{0.0};
|
||||
Vec4i jointIds{0,0,0,0};
|
||||
for (int j = i; j < i + 4 && j < vertex.skinningInfo.size(); j++) {
|
||||
weights[j - i] = vertex.skinningInfo[j].jointWeight;
|
||||
jointIds[j - i] = vertex.skinningInfo[j].jointIndex;
|
||||
}
|
||||
const int vertexStream = i / 4;
|
||||
vertex.jointIndices[vertexStream] = jointIds;
|
||||
vertex.jointWeights[vertexStream] = weights;
|
||||
vertex.jointIndices.push_back(jointIds);
|
||||
vertex.jointWeights.push_back(weights);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -660,12 +661,10 @@ void RawModel::CreateMaterialModels(
|
|||
vertex.uv1 = defaultVertex.uv1;
|
||||
}
|
||||
if ((keep & RAW_VERTEX_ATTRIBUTE_JOINT_INDICES) == 0) {
|
||||
for (int i = 0; i < RawModel::MAX_SUPPORTED_WEIGHTS ; i++)
|
||||
vertex.jointIndices[i] = defaultVertex.jointIndices[i];
|
||||
vertex.jointIndices = defaultVertex.jointIndices;
|
||||
}
|
||||
if ((keep & RAW_VERTEX_ATTRIBUTE_JOINT_WEIGHTS) == 0) {
|
||||
for (int i = 0; i < RawModel::MAX_SUPPORTED_WEIGHTS; i++)
|
||||
vertex.jointWeights[i] = defaultVertex.jointWeights[i];
|
||||
vertex.jointWeights = defaultVertex.jointWeights;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
|
||||
#include "FBX2glTF.h"
|
||||
|
||||
#define MAX_SKINNING_WEIGHTS 32
|
||||
|
||||
enum RawVertexAttribute {
|
||||
RAW_VERTEX_ATTRIBUTE_POSITION = 1 << 0,
|
||||
RAW_VERTEX_ATTRIBUTE_NORMAL = 1 << 1,
|
||||
|
@ -61,8 +59,8 @@ struct RawVertex {
|
|||
Vec4f color{0.0f};
|
||||
Vec2f uv0{0.0f};
|
||||
Vec2f uv1{0.0f};
|
||||
Vec4i jointIndices[(MAX_SKINNING_WEIGHTS - 1) / 4 + 1];
|
||||
Vec4f jointWeights[(MAX_SKINNING_WEIGHTS - 1) / 4 + 1];
|
||||
std::vector<Vec4i> jointIndices;
|
||||
std::vector<Vec4f> jointWeights;
|
||||
|
||||
|
||||
std::vector<RawVertexSkinningInfo> skinningInfo;
|
||||
|
@ -372,7 +370,6 @@ struct RawNode {
|
|||
|
||||
class RawModel {
|
||||
public:
|
||||
static const int MAX_SUPPORTED_WEIGHTS = MAX_SKINNING_WEIGHTS;
|
||||
|
||||
RawModel();
|
||||
|
||||
|
@ -542,7 +539,7 @@ class RawModel {
|
|||
// Returns true if the vertices store the particular attribute.
|
||||
template <typename _attrib_type_>
|
||||
void GetArrayAttributeArray(std::vector<_attrib_type_>& out,
|
||||
const _attrib_type_ (RawVertex::*ptr)[(RawModel::MAX_SUPPORTED_WEIGHTS - 1) / 4 + 1],
|
||||
const std::vector<_attrib_type_> RawVertex::*ptr,
|
||||
const int arrayOffset)
|
||||
const;
|
||||
|
||||
|
@ -586,7 +583,7 @@ void RawModel::GetAttributeArray(
|
|||
template <typename _attrib_type_>
|
||||
void RawModel::GetArrayAttributeArray(
|
||||
std::vector<_attrib_type_>& out,
|
||||
const _attrib_type_ (RawVertex::*ptr)[(RawModel::MAX_SUPPORTED_WEIGHTS - 1) / 4 + 1],
|
||||
const std::vector<_attrib_type_> RawVertex::*ptr,
|
||||
const int arrayOffset) const {
|
||||
out.resize(vertices.size());
|
||||
for (size_t i = 0; i < vertices.size(); i++) {
|
||||
|
|
Loading…
Reference in New Issue