Skip to content

Commit b43e6a6

Browse files
committed
FIX simplify animator logic
1 parent 608be29 commit b43e6a6

File tree

4 files changed

+23
-68
lines changed

4 files changed

+23
-68
lines changed

src/animation/AnimationSystem.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,7 @@ namespace animation
438438
if (!playB.m_active) {
439439
changed = animator.animate(
440440
*rig,
441-
glm::mat4{ 1.f },
442441
nodeTransforms,
443-
jointPalette,
444-
socketPalette,
445442
playA.m_clipIndex,
446443
playA.m_startTime,
447444
playA.m_speed,
@@ -451,10 +448,7 @@ namespace animation
451448
else {
452449
changed = animator.animateBlended(
453450
*rig,
454-
glm::mat4{ 1.f },
455451
nodeTransforms,
456-
jointPalette,
457-
socketPalette,
458452
playA.m_clipIndex,
459453
playA.m_startTime,
460454
playA.m_speed,
@@ -471,6 +465,23 @@ namespace animation
471465
playB.m_active = false;
472466
}
473467

468+
if (changed) {
469+
// STEP 2: update Joint Palette
470+
for (const auto& joint : rig->m_jointContainer.m_joints)
471+
{
472+
const auto& globalTransform = nodeTransforms[joint.m_nodeIndex];
473+
// NOTE KI m_offsetMatrix so that vertex is first converted to local space of joint
474+
jointPalette[joint.m_index] = globalTransform * joint.m_offsetMatrix;
475+
}
476+
477+
// STEP 3: update Socket Palette
478+
for (const auto& socket : rig->m_sockets) {
479+
// NOTE KI see AnimationSystem::registerInstance()
480+
socketPalette[socket.m_index] = socket.calculateGlobalTransform(
481+
nodeTransforms[socket.m_nodeIndex]);
482+
}
483+
}
484+
474485
if (changed) {
475486
rigNodeRegistry.markDirty(rigNodeBaseIndex, nodeTransforms.size());
476487
jointRegistry.markDirty(jointBaseIndex, jointPalette.size());

src/animation/Animator.cpp

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ namespace {
111111
namespace animation {
112112
bool Animator::animate(
113113
const animation::RigContainer& rig,
114-
const glm::mat4& inverseMeshRigTransform,
115114
std::span<glm::mat4> rigNodeTransforms,
116-
std::span<glm::mat4> jointPalette,
117-
std::span<glm::mat4> socketPalette,
118115
uint16_t clipIndex,
119116
double animationStartTime,
120117
float speed,
@@ -167,31 +164,12 @@ namespace animation {
167164
}
168165
}
169166

170-
// STEP 2: update Joint Palette
171-
for (const auto& joint : rig.m_jointContainer.m_joints)
172-
{
173-
const auto& globalTransform = rigNodeTransforms[joint.m_nodeIndex];
174-
// NOTE KI m_offsetMatrix so that vertex is first converted to local space of joint
175-
jointPalette[joint.m_index] = inverseMeshRigTransform * globalTransform * joint.m_offsetMatrix;
176-
}
177-
178-
// STEP 3: update Socket Palette
179-
for (const auto& socket : rig.m_sockets)
180-
{
181-
// NOTE KI see AnimationSystem::registerInstance()
182-
socketPalette[socket.m_index] = socket.calculateGlobalTransform(
183-
rigNodeTransforms[socket.m_nodeIndex]);
184-
}
185-
186167
return true;
187168
}
188169

189170
bool Animator::animateBlended(
190171
const animation::RigContainer& rig,
191-
const glm::mat4& inverseMeshRigTransform,
192172
std::span<glm::mat4> rigNodeTransforms,
193-
std::span<glm::mat4> jointPalette,
194-
std::span<glm::mat4> socketPalette,
195173
uint16_t clipIndexA,
196174
double animationStartTimeA,
197175
float speedA,
@@ -292,34 +270,6 @@ namespace animation {
292270
}
293271
}
294272

295-
//// STEP 2: update Joint Palette
296-
//for (size_t nodeIndex = 0; nodeIndex < rig.m_nodes.size(); nodeIndex++)
297-
//{
298-
// const auto& rigNode = rig.m_nodes[nodeIndex];
299-
// const auto* joint = rig.m_jointContainer.getInfo(rigNode.m_jointIndex);
300-
301-
// if (joint) {
302-
// const auto& globalTransform = rigNodeTransforms[rigNode.m_index];
303-
// // NOTE KI m_offsetMatrix so that vertex is first converted to local space of joint
304-
// jointPalette[joint->m_index] = inverseMeshRigTransform * globalTransform * joint->m_offsetMatrix;
305-
// }
306-
//}
307-
308-
// STEP 2: update Joint Palette
309-
for (const auto& joint : rig.m_jointContainer.m_joints)
310-
{
311-
const auto& globalTransform = rigNodeTransforms[joint.m_nodeIndex];
312-
// NOTE KI m_offsetMatrix so that vertex is first converted to local space of joint
313-
jointPalette[joint.m_index] = inverseMeshRigTransform * globalTransform * joint.m_offsetMatrix;
314-
}
315-
316-
// STEP 3: update Socket Palette
317-
for (const auto& socket : rig.m_sockets) {
318-
// NOTE KI see AnimationSystem::registerInstance()
319-
socketPalette[socket.m_index] = socket.calculateGlobalTransform(
320-
rigNodeTransforms[socket.m_nodeIndex]);
321-
}
322-
323273
return true;
324274
}
325275
}

src/animation/Animator.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ namespace animation {
2020
// @return true if palette was changed
2121
bool animate(
2222
const animation::RigContainer& rig,
23-
const glm::mat4& inverseMeshRigTransform,
2423
std::span<glm::mat4> rigNodeTransforms,
25-
std::span<glm::mat4> jointPalette,
26-
std::span<glm::mat4> socketPalette,
2724
uint16_t clipIndex,
2825
double animationStartTime,
2926
float speed,
@@ -34,10 +31,7 @@ namespace animation {
3431
// @return true if palette was changed
3532
bool animateBlended(
3633
const animation::RigContainer& rig,
37-
const glm::mat4& inverseMeshRigTransform,
3834
std::span<glm::mat4> rigNodeTransforms,
39-
std::span<glm::mat4> jointPalette,
40-
std::span<glm::mat4> socketPalette,
4135
uint16_t clipIndexA,
4236
double animationStartTimeA,
4337
float speedA,

src/mesh/RigNodeTreeGenerator.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ namespace mesh {
2525
auto& vertexJoints = mesh->m_vertexJoints;
2626
auto& indeces = mesh->m_indeces;
2727

28-
vertices.reserve(rig.m_nodes.size());
29-
vertexJoints.reserve(rig.m_nodes.size());
30-
indeces.reserve(rig.m_nodes.size());
28+
vertices.reserve(rig.m_jointContainer.m_joints.size());
29+
vertexJoints.reserve(rig.m_jointContainer.m_joints.size());
30+
indeces.reserve(rig.m_jointContainer.m_joints.size() * 2);
3131

3232
std::map<int16_t, int16_t> jointToVertex;
3333

@@ -101,9 +101,9 @@ namespace mesh {
101101
auto& vertexJoints = mesh->m_vertexJoints;
102102
auto& indeces = mesh->m_indeces;
103103

104-
vertices.reserve(rig.m_nodes.size());
105-
vertexJoints.reserve(rig.m_nodes.size());
106-
indeces.reserve(rig.m_nodes.size());
104+
vertices.reserve(rig.m_jointContainer.m_joints.size());
105+
vertexJoints.reserve(rig.m_jointContainer.m_joints.size());
106+
indeces.reserve(rig.m_jointContainer.m_joints.size());
107107

108108
std::map<int16_t, int16_t> jointToVertex;
109109

0 commit comments

Comments
 (0)