mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 05:13:11 +02:00
Introduce hfm::Mesh.clusterWeightsPerVertex
This commit is contained in:
parent
5d91d22314
commit
ad6720240f
6 changed files with 9 additions and 5 deletions
|
@ -1671,6 +1671,7 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const
|
||||||
}
|
}
|
||||||
mesh.clusterIndices = std::move(reweightedDeformers.indices);
|
mesh.clusterIndices = std::move(reweightedDeformers.indices);
|
||||||
mesh.clusterWeights = std::move(reweightedDeformers.weights);
|
mesh.clusterWeights = std::move(reweightedDeformers.weights);
|
||||||
|
mesh.clusterWeightsPerVertex = reweightedDeformers.weightsPerVertex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the model's dynamic transform, and put its ID in the shapes
|
// Store the model's dynamic transform, and put its ID in the shapes
|
||||||
|
|
|
@ -250,6 +250,7 @@ public:
|
||||||
// Skinning cluster attributes
|
// Skinning cluster attributes
|
||||||
std::vector<uint16_t> clusterIndices;
|
std::vector<uint16_t> clusterIndices;
|
||||||
std::vector<uint16_t> clusterWeights;
|
std::vector<uint16_t> clusterWeights;
|
||||||
|
uint16_t clusterWeightsPerVertex { 0 };
|
||||||
|
|
||||||
// Blendshape attributes
|
// Blendshape attributes
|
||||||
QVector<Blendshape> blendshapes;
|
QVector<Blendshape> blendshapes;
|
||||||
|
|
|
@ -75,6 +75,7 @@ ReweightedDeformers getReweightedDeformers(const size_t numMeshVertices, const s
|
||||||
size_t numClusterIndices = numMeshVertices * weightsPerVertex;
|
size_t numClusterIndices = numMeshVertices * weightsPerVertex;
|
||||||
reweightedDeformers.indices.resize(numClusterIndices, (uint16_t)(skinClusters.size() - 1));
|
reweightedDeformers.indices.resize(numClusterIndices, (uint16_t)(skinClusters.size() - 1));
|
||||||
reweightedDeformers.weights.resize(numClusterIndices, 0);
|
reweightedDeformers.weights.resize(numClusterIndices, 0);
|
||||||
|
reweightedDeformers.weightsPerVertex = weightsPerVertex;
|
||||||
|
|
||||||
std::vector<float> weightAccumulators;
|
std::vector<float> weightAccumulators;
|
||||||
weightAccumulators.resize(numClusterIndices, 0.0f);
|
weightAccumulators.resize(numClusterIndices, 0.0f);
|
||||||
|
|
|
@ -25,16 +25,17 @@ void calculateExtentsForShape(hfm::Shape& shape, const std::vector<hfm::Mesh>& m
|
||||||
|
|
||||||
void calculateExtentsForModel(Extents& modelExtents, const std::vector<hfm::Shape>& shapes);
|
void calculateExtentsForModel(Extents& modelExtents, const std::vector<hfm::Shape>& shapes);
|
||||||
|
|
||||||
const uint16_t NUM_SKINNING_WEIGHTS_PER_VERTEX = 4;
|
|
||||||
|
|
||||||
class ReweightedDeformers {
|
class ReweightedDeformers {
|
||||||
public:
|
public:
|
||||||
std::vector<uint16_t> indices;
|
std::vector<uint16_t> indices;
|
||||||
std::vector<uint16_t> weights;
|
std::vector<uint16_t> weights;
|
||||||
|
uint16_t weightsPerVertex { 0 };
|
||||||
bool trimmedToMatch { false };
|
bool trimmedToMatch { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
ReweightedDeformers getReweightedDeformers(const size_t numMeshVertices, const std::vector<hfm::SkinCluster> skinClusters, const uint16_t weightsPerVertex = NUM_SKINNING_WEIGHTS_PER_VERTEX);
|
const uint16_t DEFAULT_SKINNING_WEIGHTS_PER_VERTEX = 4;
|
||||||
|
|
||||||
|
ReweightedDeformers getReweightedDeformers(const size_t numMeshVertices, const std::vector<hfm::SkinCluster> skinClusters, const uint16_t weightsPerVertex = DEFAULT_SKINNING_WEIGHTS_PER_VERTEX);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // #define hifi_hfm_ModelMath_h
|
#endif // #define hifi_hfm_ModelMath_h
|
||||||
|
|
|
@ -92,7 +92,7 @@ void buildGraphicsMesh(const hfm::Mesh& hfmMesh, graphics::MeshPointer& graphics
|
||||||
const auto clusterWeightElement = gpu::Element(gpu::VEC4, gpu::NUINT16, gpu::XYZW);
|
const auto clusterWeightElement = gpu::Element(gpu::VEC4, gpu::NUINT16, gpu::XYZW);
|
||||||
|
|
||||||
// Record cluster sizes
|
// Record cluster sizes
|
||||||
const size_t numVertClusters = hfmMesh.clusterIndices.size() / hfm::NUM_SKINNING_WEIGHTS_PER_VERTEX;
|
const size_t numVertClusters = hfmMesh.clusterWeightsPerVertex == 0 ? 0 : hfmMesh.clusterIndices.size() / hfmMesh.clusterWeightsPerVertex;
|
||||||
const size_t clusterIndicesSize = numVertClusters * clusterIndiceElement.getSize();
|
const size_t clusterIndicesSize = numVertClusters * clusterIndiceElement.getSize();
|
||||||
const size_t clusterWeightsSize = numVertClusters * clusterWeightElement.getSize();
|
const size_t clusterWeightsSize = numVertClusters * clusterWeightElement.getSize();
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ void CollectShapeVerticesTask::run(const baker::BakeContextPointer& context, con
|
||||||
const auto& vertices = mesh.vertices;
|
const auto& vertices = mesh.vertices;
|
||||||
const glm::mat4 meshToJoint = cluster.inverseBindMatrix;
|
const glm::mat4 meshToJoint = cluster.inverseBindMatrix;
|
||||||
|
|
||||||
const uint16_t weightsPerVertex = hfm::NUM_SKINNING_WEIGHTS_PER_VERTEX;
|
const uint16_t weightsPerVertex = mesh.clusterWeightsPerVertex;
|
||||||
if (weightsPerVertex == 0) {
|
if (weightsPerVertex == 0) {
|
||||||
for (int vertexIndex = 0; vertexIndex < (int)vertices.size(); ++vertexIndex) {
|
for (int vertexIndex = 0; vertexIndex < (int)vertices.size(); ++vertexIndex) {
|
||||||
const glm::mat4 vertexTransform = meshToJoint * glm::translate(vertices[vertexIndex]);
|
const glm::mat4 vertexTransform = meshToJoint * glm::translate(vertices[vertexIndex]);
|
||||||
|
|
Loading…
Reference in a new issue