Skip to content

Commit

Permalink
Added 'Display skeleton' attribute in EC_AnimationController to draw …
Browse files Browse the repository at this point in the history
…the skeleton. Closes realXtend#221
  • Loading branch information
cvetan5 committed Dec 7, 2012
1 parent 5a25383 commit d0a8838
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/Core/OgreRenderingModule/EC_AnimationController.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// For conditions of distribution and use, see copyright notice in LICENSE

#define MATH_OGRE_INTEROP

#include "StableHeaders.h"
#include "DebugOperatorNew.h"
#include "EC_Mesh.h"
Expand All @@ -9,18 +11,22 @@
#include "OgreRenderingModule.h"
#include "CoreStringUtils.h"
#include "Profiler.h"
#include "Scene.h"
#include "OgreWorld.h"

#include <Ogre.h>

#include "LoggingFunctions.h"

#include "MemoryLeakCheck.h"


using namespace OgreRenderer;

EC_AnimationController::EC_AnimationController(Scene* scene) :
IComponent(scene),
animationState(this, "Animation state", ""),
drawSkeleton(this, "Draw skeleton", false),

This comment has been minimized.

Copy link
@jonnenauha

jonnenauha Feb 9, 2013

Member

This should be changed to drawDebug before we send a pull request over.

mesh(0)
{
ResetState();
Expand Down Expand Up @@ -276,6 +282,48 @@ void EC_AnimationController::Update(float frametime)
animstate->_setBlendMaskData(&lowpriority_mask_[0]);
}
}
if (getdrawSkeleton())
DrawSkeleton(frametime);
}

void EC_AnimationController::DrawSkeleton(float frametime)
{
Ogre::Entity *oEnt = GetEntity();
if (oEnt && oEnt->hasSkeleton())
{
Scene *scene = ParentScene();
if (!scene)
return;

OgreWorldPtr world = scene->GetWorld<OgreWorld>();
if (!world)
return;

Ogre::Vector3 parentPos = Ogre::Vector3::ZERO;
Ogre::Quaternion parentOrt = Ogre::Quaternion::IDENTITY;
if (oEnt->getParentNode())
{
parentPos = oEnt->getParentNode()->_getDerivedPosition();
parentOrt = oEnt->getParentNode()->_getDerivedOrientation();
}

Ogre::SkeletonInstance *skeleton = oEnt->getSkeleton();
bool red = true;
for(ushort i = 0; i < skeleton->getNumBones(); ++i)
{
Ogre::Bone *bone = skeleton->getBone(i);
Ogre::Vector3 pos = parentPos + (parentOrt * bone->_getDerivedPosition());
for(ushort ci = 0; ci < bone->numChildren(); ++ci)
{
Ogre::Vector3 childPos = parentPos + (parentOrt * bone->getChild(ci)->_getDerivedPosition());
if (red)
world->DebugDrawLine(pos, childPos, 1.f, 0.f, 0.f, false);
else
world->DebugDrawLine(pos, childPos, 0.f, 1.f, 0.f, false);
}
red = !red;
}
}
}

Ogre::Entity* EC_AnimationController::GetEntity()
Expand Down
6 changes: 6 additions & 0 deletions src/Core/OgreRenderingModule/EC_AnimationController.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class OGRE_MODULE_API EC_AnimationController : public IComponent
Q_PROPERTY(QString animationState READ getanimationState WRITE setanimationState);
DEFINE_QPROPERTY_ATTRIBUTE(QString, animationState);

Q_PROPERTY(bool drawSkeleton READ getdrawSkeleton WRITE setdrawSkeleton);
DEFINE_QPROPERTY_ATTRIBUTE(bool, drawSkeleton);

/// Gets mesh entity component
EC_Mesh *GetMeshEntity() const { return mesh; }

Expand Down Expand Up @@ -144,6 +147,9 @@ public slots:

/// Updates animation(s) by elapsed time
void Update(float frametime);

/// Draws the mesh skeleton
void DrawSkeleton(float frametime);

/// Enables animation with optional fade-in time
/* @param name Animation name
Expand Down

0 comments on commit d0a8838

Please sign in to comment.