Fix loading danglymesh constraints
Constraints are now read from two separate data regions.
This commit is contained in:
parent
b032fe40ae
commit
b1c14c7879
4 changed files with 11 additions and 9 deletions
|
@ -336,21 +336,23 @@ shared_ptr<ModelNode::TriangleMesh> MdlReader::readMesh(int flags) {
|
|||
float displacement = readFloat();
|
||||
float tightness = readFloat();
|
||||
float period = readFloat();
|
||||
ignore(4); // unknown
|
||||
uint32_t offDanglyVertices = readUint32();
|
||||
|
||||
danglyMesh = make_shared<ModelNode::DanglyMesh>();
|
||||
danglyMesh->displacement = 0.5f * displacement; // displacement is allegedly 1/2 meters per unit
|
||||
danglyMesh->tightness = tightness;
|
||||
danglyMesh->period = period;
|
||||
|
||||
danglyMesh->constraints.resize(constraintArrayDef.count);
|
||||
seek(kMdlDataOffset + constraintArrayDef.offset);
|
||||
for (uint32_t i = 0; i < constraintArrayDef.count; ++i) {
|
||||
float multiplier = readFloat();
|
||||
danglyMesh->constraints[i].multiplier = glm::clamp(multiplier / 255.0f, 0.0f, 1.0f);
|
||||
}
|
||||
seek(kMdlDataOffset + offDanglyVertices);
|
||||
for (uint32_t i = 0; i < constraintArrayDef.count; ++i) {
|
||||
vector<float> positionValues(readFloatArray(3));
|
||||
ModelNode::DanglyMeshConstraint constraint;
|
||||
constraint.multiplier = glm::clamp(multiplier / 255.0f, 0.0f, 1.0f);
|
||||
constraint.position = glm::make_vec3(&positionValues[0]);
|
||||
danglyMesh->constraints.push_back(move(constraint));
|
||||
danglyMesh->constraints[i].position = glm::make_vec3(&positionValues[0]);
|
||||
}
|
||||
|
||||
} else if (flags & NodeFlags::aabb) {
|
||||
|
|
|
@ -389,7 +389,8 @@ void main() {
|
|||
(uBones[i4] * normal) * w4;
|
||||
|
||||
} else if (isFeatureEnabled(FEATURE_DANGLYMESH)) {
|
||||
vec3 maxStride = vec3(uDanglymeshDisplacement * uDanglymeshConstraints[gl_VertexID / 4][gl_VertexID % 4]);
|
||||
float multiplier = uDanglymeshConstraints[gl_VertexID / 4][gl_VertexID % 4];
|
||||
vec3 maxStride = vec3(multiplier * uDanglymeshDisplacement);
|
||||
vec3 stride = clamp(uDanglymeshStride.xyz, -maxStride, maxStride);
|
||||
position += vec4(stride, 0.0);
|
||||
}
|
||||
|
|
|
@ -353,8 +353,7 @@ void MeshSceneNode::drawSingle(bool shadowPass) {
|
|||
uniforms.combined.featureMask |= UniformFeatureFlags::danglymesh;
|
||||
uniforms.danglymesh->stride = glm::vec4(_danglymeshAnimation.stride, 0.0f);
|
||||
uniforms.danglymesh->displacement = danglyMesh->displacement;
|
||||
size_t i = 0;
|
||||
for (i = 0; i < danglyMesh->constraints.size(); ++i) {
|
||||
for (size_t i = 0; i < danglyMesh->constraints.size(); ++i) {
|
||||
uniforms.danglymesh->constraints[i / 4][i % 4] = danglyMesh->constraints[i].multiplier;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ private:
|
|||
|
||||
struct DanglymeshAnimation {
|
||||
glm::vec3 force { 0.0f }; /**< net force applied to this scene node */
|
||||
glm::vec3 stride { 0.0f }; /**< how far have vertices traveled from the rest position? */
|
||||
glm::vec3 stride { 0.0f }; /**< how far have vertices traveled from the rest position in object space */
|
||||
} _danglymeshAnimation;
|
||||
|
||||
const ModelSceneNode *_model;
|
||||
|
|
Loading…
Reference in a new issue