* Now always works, regardless of whether or not Rig or AnimGraph animations are enabled. * Changed joint radius to 1 cm. * Changed xyz axis length to 4 cm.
Showing the changes to libraries/render-utils/src/AnimDebugDraw.cpp (1 of 9 files). Show all
Unified · Split
| @@ -152,22 +152,30 @@ AnimDebugDraw::~AnimDebugDraw() { · 151 unmodified lines | |||
| 152 | } | 152 | } |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | void AnimDebugDraw::addSkeleton(std::string key, AnimSkeleton::ConstPointer skeleton, const AnimPose& rootPose, const glm::vec4& color) { | 155 | void AnimDebugDraw::addSkeleton(const std::string& key, AnimSkeleton::ConstPointer skeleton, const AnimPose& rootPose, const glm::vec4& color) { |
| 156 | _skeletons[key] = SkeletonInfo(skeleton, rootPose, color); | 156 | _skeletons[key] = SkeletonInfo(skeleton, rootPose, color); |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | void AnimDebugDraw::removeSkeleton(std::string key) { | 159 | void AnimDebugDraw::removeSkeleton(const std::string& key) { |
| 160 | _skeletons.erase(key); | 160 | _skeletons.erase(key); |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | void AnimDebugDraw::addAnimNode(std::string key, AnimNode::ConstPointer animNode, const AnimPose& rootPose, const glm::vec4& color) { | 163 | void AnimDebugDraw::addAnimNode(const std::string& key, AnimNode::ConstPointer animNode, const AnimPose& rootPose, const glm::vec4& color) { |
| 164 | _animNodes[key] = AnimNodeInfo(animNode, rootPose, color); | 164 | _animNodes[key] = AnimNodeInfo(animNode, rootPose, color); |
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | void AnimDebugDraw::removeAnimNode(std::string key) { | 167 | void AnimDebugDraw::removeAnimNode(const std::string& key) { |
| 168 | _animNodes.erase(key); | 168 | _animNodes.erase(key); |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | void AnimDebugDraw::addPoses(const std::string& key, AnimSkeleton::ConstPointer skeleton, const AnimPoseVec& poses, const AnimPose& rootPose, const glm::vec4& color) { | ||
| 172 | _poses[key] = PosesInfo(skeleton, poses, rootPose, color); | ||
| 173 | } | ||
| 174 | |||
| 175 | void AnimDebugDraw::removePoses(const std::string& key) { | ||
| 176 | _poses.erase(key); | ||
| 177 | } | ||
| 178 | |||
| 171 | static const uint32_t red = toRGBA(255, 0, 0, 255); | 179 | static const uint32_t red = toRGBA(255, 0, 0, 255); |
| 172 | static const uint32_t green = toRGBA(0, 255, 0, 255); | 180 | static const uint32_t green = toRGBA(0, 255, 0, 255); |
| 173 | static const uint32_t blue = toRGBA(0, 0, 255, 255); | 181 | static const uint32_t blue = toRGBA(0, 0, 255, 255); |
| @@ -176,6 +184,8 @@ const int NUM_CIRCLE_SLICES = 24; · 2 unmodified lines | |||
| 176 | 184 | ||
| 177 | static void addBone(const AnimPose& rootPose, const AnimPose& pose, float radius, Vertex*& v) { | 185 | static void addBone(const AnimPose& rootPose, const AnimPose& pose, float radius, Vertex*& v) { |
| 178 | 186 | ||
| 187 | const float XYZ_AXIS_LENGTH = radius * 4.0f; | ||
| 188 | |||
| 179 | AnimPose finalPose = rootPose * pose; | 189 | AnimPose finalPose = rootPose * pose; |
| 180 | glm::vec3 base = rootPose * pose.trans; | 190 | glm::vec3 base = rootPose * pose.trans; |
| 181 | 191 | ||
| @@ -195,7 +205,7 @@ static void addBone(const AnimPose& rootPose, const AnimPose& pose, float radius · 13 unmodified lines | |||
| 195 | v->pos = base; | 205 | v->pos = base; |
| 196 | v->rgba = red; | 206 | v->rgba = red; |
| 197 | v++; | 207 | v++; |
| 198 | v->pos = finalPose * glm::vec3(radius * 2.0f, 0.0f, 0.0f); | 208 | v->pos = finalPose * glm::vec3(XYZ_AXIS_LENGTH, 0.0f, 0.0f); |
| 199 | v->rgba = red; | 209 | v->rgba = red; |
| 200 | v++; | 210 | v++; |
| 201 | 211 | ||
| @@ -213,7 +223,7 @@ static void addBone(const AnimPose& rootPose, const AnimPose& pose, float radius · 11 unmodified lines | |||
| 213 | v->pos = base; | 223 | v->pos = base; |
| 214 | v->rgba = green; | 224 | v->rgba = green; |
| 215 | v++; | 225 | v++; |
| 216 | v->pos = finalPose * glm::vec3(0.0f, radius * 2.0f, 0.0f); | 226 | v->pos = finalPose * glm::vec3(0.0f, XYZ_AXIS_LENGTH, 0.0f); |
| 217 | v->rgba = green; | 227 | v->rgba = green; |
| 218 | v++; | 228 | v++; |
| 219 | 229 | ||
| @@ -231,7 +241,7 @@ static void addBone(const AnimPose& rootPose, const AnimPose& pose, float radius · 11 unmodified lines | |||
| 231 | v->pos = base; | 241 | v->pos = base; |
| 232 | v->rgba = blue; | 242 | v->rgba = blue; |
| 233 | v++; | 243 | v++; |
| 234 | v->pos = finalPose * glm::vec3(0.0f, 0.0f, radius * 2.0f); | 244 | v->pos = finalPose * glm::vec3(0.0f, 0.0f, XYZ_AXIS_LENGTH); |
| 235 | v->rgba = blue; | 245 | v->rgba = blue; |
| 236 | v++; | 246 | v++; |
| 237 | 247 | ||
| @@ -322,7 +332,7 @@ void AnimDebugDraw::update() { · 84 unmodified lines | |||
| 322 | const size_t VERTICES_PER_BONE = (6 + (NUM_CIRCLE_SLICES * 2) * 3); | 332 | const size_t VERTICES_PER_BONE = (6 + (NUM_CIRCLE_SLICES * 2) * 3); |
| 323 | const size_t VERTICES_PER_LINK = 8 * 2; | 333 | const size_t VERTICES_PER_LINK = 8 * 2; |
| 324 | 334 | ||
| 325 | const float BONE_RADIUS = 0.0075f; | 335 | const float BONE_RADIUS = 0.01f; // 1 cm |
| 326 | 336 | ||
| 327 | // figure out how many verts we will need. | 337 | // figure out how many verts we will need. |
| 328 | int numVerts = 0; | 338 | int numVerts = 0; |
| @@ -350,6 +360,17 @@ void AnimDebugDraw::update() { · 21 unmodified lines | |||
| 350 | } | 360 | } |
| 351 | } | 361 | } |
| 352 | 362 | ||
| 363 | for (auto&& iter : _poses) { | ||
| 364 | AnimSkeleton::ConstPointer& skeleton = std::get<0>(iter.second); | ||
| 365 | numVerts += skeleton->getNumJoints() * VERTICES_PER_BONE; | ||
| 366 | for (int i = 0; i < skeleton->getNumJoints(); i++) { | ||
| 367 | auto parentIndex = skeleton->getParentIndex(i); | ||
| 368 | if (parentIndex >= 0) { | ||
| 369 | numVerts += VERTICES_PER_LINK; | ||
| 370 | } | ||
| 371 | } | ||
| 372 | } | ||
| 373 | |||
| 353 | data._vertexBuffer->resize(sizeof(Vertex) * numVerts); | 374 | data._vertexBuffer->resize(sizeof(Vertex) * numVerts); |
| 354 | Vertex* verts = (Vertex*)data._vertexBuffer->editData(); | 375 | Vertex* verts = (Vertex*)data._vertexBuffer->editData(); |
| 355 | Vertex* v = verts; | 376 | Vertex* v = verts; |
| @@ -418,6 +439,43 @@ void AnimDebugDraw::update() { · 62 unmodified lines | |||
| 418 | } | 439 | } |
| 419 | } | 440 | } |
| 420 | 441 | ||
| 442 | for (auto&& iter : _poses) { | ||
| 443 | AnimSkeleton::ConstPointer& skeleton = std::get<0>(iter.second); | ||
| 444 | AnimPoseVec& poses = std::get<1>(iter.second); | ||
| 445 | AnimPose rootPose = std::get<2>(iter.second); | ||
| 446 | int hipsIndex = skeleton->nameToJointIndex("Hips"); | ||
| 447 | if (hipsIndex >= 0) { | ||
| 448 | rootPose.trans -= skeleton->getRelativeBindPose(hipsIndex).trans; | ||
| 449 | } | ||
| 450 | glm::vec4 color = std::get<3>(iter.second); | ||
| 451 | |||
| 452 | std::vector<AnimPose> absAnimPose; | ||
| 453 | absAnimPose.resize(skeleton->getNumJoints()); | ||
| 454 | |||
| 455 | for (int i = 0; i < skeleton->getNumJoints(); i++) { | ||
| 456 | AnimPose pose = poses[i]; | ||
| 457 | |||
| 458 | const float radius = BONE_RADIUS / (pose.scale.x * rootPose.scale.x); | ||
| 459 | |||
| 460 | auto parentIndex = skeleton->getParentIndex(i); | ||
| 461 | if (parentIndex >= 0) { | ||
| 462 | absAnimPose[i] = absAnimPose[parentIndex] * poses[i]; | ||
| 463 | } else { | ||
| 464 | absAnimPose[i] = poses[i]; | ||
| 465 | } | ||
| 466 | |||
| 467 | // draw bone | ||
| 468 | addBone(rootPose, absAnimPose[i], radius, v); | ||
| 469 | |||
| 470 | // draw link to parent | ||
| 471 | if (parentIndex >= 0) { | ||
| 472 | assert(parentIndex < skeleton->getNumJoints()); | ||
| 473 | AnimPose parentPose = poses[parentIndex]; | ||
| 474 | addLink(rootPose, absAnimPose[i], absAnimPose[parentIndex], radius, color, v); | ||
| 475 | } | ||
| 476 | } | ||
| 477 | } | ||
| 478 | |||
| 421 | assert(numVerts == (v - verts)); | 479 | assert(numVerts == (v - verts)); |
| 422 | 480 | ||
| 423 | data._indexBuffer->resize(sizeof(uint16_t) * numVerts); | 481 | data._indexBuffer->resize(sizeof(uint16_t) * numVerts); |