forked from bartvdbraak/blender
Cleanup: don't use Blender structs in iTaSC module.
This commit is contained in:
parent
9599ed3ba7
commit
b92d78553b
@ -21,7 +21,7 @@ public:
|
|||||||
|
|
||||||
int addFrame(const std::string& name, const Frame& frame);
|
int addFrame(const std::string& name, const Frame& frame);
|
||||||
|
|
||||||
virtual void updateCoordinates(const struct EvaluationContext *eval_ctx, const Timestamp& timestamp) {};
|
virtual void updateCoordinates(const Timestamp& timestamp) {};
|
||||||
virtual int addEndEffector(const std::string& name);
|
virtual int addEndEffector(const std::string& name);
|
||||||
virtual bool finalize();
|
virtual bool finalize();
|
||||||
virtual const Frame& getPose(const unsigned int frameIndex);
|
virtual const Frame& getPose(const unsigned int frameIndex);
|
||||||
|
@ -90,7 +90,7 @@ bool MovingFrame::setCallback(MovingFrameCallback _function, void* _param)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MovingFrame::updateCoordinates(const struct EvaluationContext *eval_ctx, const Timestamp& timestamp)
|
void MovingFrame::updateCoordinates(const Timestamp& timestamp)
|
||||||
{
|
{
|
||||||
// don't compute the velocity during substepping, it is assumed constant.
|
// don't compute the velocity during substepping, it is assumed constant.
|
||||||
if (!timestamp.substep) {
|
if (!timestamp.substep) {
|
||||||
@ -98,7 +98,7 @@ void MovingFrame::updateCoordinates(const struct EvaluationContext *eval_ctx, co
|
|||||||
if (!timestamp.reiterate) {
|
if (!timestamp.reiterate) {
|
||||||
cacheAvail = popInternalFrame(timestamp.cacheTimestamp);
|
cacheAvail = popInternalFrame(timestamp.cacheTimestamp);
|
||||||
if (m_function)
|
if (m_function)
|
||||||
(*m_function)(eval_ctx, timestamp, m_internalPose, m_nextPose, m_param);
|
(*m_function)(timestamp, m_internalPose, m_nextPose, m_param);
|
||||||
}
|
}
|
||||||
// only compute velocity if we have a previous pose
|
// only compute velocity if we have a previous pose
|
||||||
if (cacheAvail && timestamp.interpolate) {
|
if (cacheAvail && timestamp.interpolate) {
|
||||||
|
@ -11,12 +11,10 @@
|
|||||||
#include "UncontrolledObject.hpp"
|
#include "UncontrolledObject.hpp"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
struct EvaluationContext;
|
|
||||||
|
|
||||||
namespace iTaSC{
|
namespace iTaSC{
|
||||||
|
|
||||||
typedef bool (*MovingFrameCallback)(
|
typedef bool (*MovingFrameCallback)(
|
||||||
const struct EvaluationContext *eval_ctx,
|
|
||||||
const Timestamp& timestamp,
|
const Timestamp& timestamp,
|
||||||
const Frame& _current,
|
const Frame& _current,
|
||||||
Frame& _next,
|
Frame& _next,
|
||||||
@ -30,7 +28,7 @@ public:
|
|||||||
bool setFrame(const Frame& frame);
|
bool setFrame(const Frame& frame);
|
||||||
bool setCallback(MovingFrameCallback _function, void* _param);
|
bool setCallback(MovingFrameCallback _function, void* _param);
|
||||||
|
|
||||||
virtual void updateCoordinates(const struct EvaluationContext *eval_ctx, const Timestamp& timestamp);
|
virtual void updateCoordinates(const Timestamp& timestamp);
|
||||||
virtual void updateKinematics(const Timestamp& timestamp);
|
virtual void updateKinematics(const Timestamp& timestamp);
|
||||||
virtual void pushCache(const Timestamp& timestamp);
|
virtual void pushCache(const Timestamp& timestamp);
|
||||||
virtual void initCache(Cache *_cache);
|
virtual void initCache(Cache *_cache);
|
||||||
|
@ -257,7 +257,7 @@ bool Scene::getConstraintPose(ConstraintSet* constraint, void *_param, KDL::Fram
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Scene::update(const struct EvaluationContext *eval_ctx, double timestamp, double timestep, unsigned int numsubstep, bool reiterate, bool cache, bool interpolate)
|
bool Scene::update(double timestamp, double timestep, unsigned int numsubstep, bool reiterate, bool cache, bool interpolate)
|
||||||
{
|
{
|
||||||
// we must have valid timestep and timestamp
|
// we must have valid timestep and timestamp
|
||||||
if (timestamp < KDL::epsilon || timestep < 0.0)
|
if (timestamp < KDL::epsilon || timestep < 0.0)
|
||||||
@ -316,7 +316,7 @@ bool Scene::update(const struct EvaluationContext *eval_ctx, double timestamp, d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (os->object->getType()==Object::UnControlled && ((UncontrolledObject*)os->object)->getNrOfCoordinates() != 0) {
|
if (os->object->getType()==Object::UnControlled && ((UncontrolledObject*)os->object)->getNrOfCoordinates() != 0) {
|
||||||
((UncontrolledObject*)(os->object))->updateCoordinates(eval_ctx, ts);
|
((UncontrolledObject*)(os->object))->updateCoordinates(ts);
|
||||||
if (!ts.substep) {
|
if (!ts.substep) {
|
||||||
// velocity of uncontrolled object remains constant during substepping
|
// velocity of uncontrolled object remains constant during substepping
|
||||||
project(m_xdot,os->coordinaterange) = ((UncontrolledObject*)(os->object))->getXudot();
|
project(m_xdot,os->coordinaterange) = ((UncontrolledObject*)(os->object))->getXudot();
|
||||||
|
@ -39,7 +39,7 @@ public:
|
|||||||
bool addSolver(Solver* _solver);
|
bool addSolver(Solver* _solver);
|
||||||
bool addCache(Cache* _cache);
|
bool addCache(Cache* _cache);
|
||||||
bool initialize();
|
bool initialize();
|
||||||
bool update(const struct EvaluationContext *eval_ctx, double timestamp, double timestep, unsigned int numsubstep=1, bool reiterate=false, bool cache=true, bool interpolate=true);
|
bool update(double timestamp, double timestep, unsigned int numsubstep=1, bool reiterate=false, bool cache=true, bool interpolate=true);
|
||||||
bool setParam(SceneParam paramId, double value);
|
bool setParam(SceneParam paramId, double value);
|
||||||
|
|
||||||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
||||||
|
@ -11,9 +11,6 @@
|
|||||||
#include "eigen_types.hpp"
|
#include "eigen_types.hpp"
|
||||||
|
|
||||||
#include "Object.hpp"
|
#include "Object.hpp"
|
||||||
|
|
||||||
struct EvaluationContext;
|
|
||||||
|
|
||||||
namespace iTaSC{
|
namespace iTaSC{
|
||||||
|
|
||||||
class UncontrolledObject: public Object {
|
class UncontrolledObject: public Object {
|
||||||
@ -29,7 +26,7 @@ public:
|
|||||||
virtual void initialize(unsigned int _nu, unsigned int _nf);
|
virtual void initialize(unsigned int _nu, unsigned int _nf);
|
||||||
virtual const e_matrix& getJu(unsigned int frameIndex) const;
|
virtual const e_matrix& getJu(unsigned int frameIndex) const;
|
||||||
virtual const e_vector& getXudot() const {return m_xudot;}
|
virtual const e_vector& getXudot() const {return m_xudot;}
|
||||||
virtual void updateCoordinates(const struct EvaluationContext *eval_ctx, const Timestamp& timestamp)=0;
|
virtual void updateCoordinates(const Timestamp& timestamp)=0;
|
||||||
virtual const unsigned int getNrOfCoordinates(){return m_nu;};
|
virtual const unsigned int getNrOfCoordinates(){return m_nu;};
|
||||||
virtual const unsigned int getNrOfFrames(){return m_nf;};
|
virtual const unsigned int getNrOfFrames(){return m_nf;};
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ public:
|
|||||||
WorldObject();
|
WorldObject();
|
||||||
virtual ~WorldObject();
|
virtual ~WorldObject();
|
||||||
|
|
||||||
virtual void updateCoordinates(const struct EvaluationContext *eval_ctx, const Timestamp& timestamp) {};
|
virtual void updateCoordinates(const Timestamp& timestamp) {};
|
||||||
virtual void updateKinematics(const Timestamp& timestamp) {};
|
virtual void updateKinematics(const Timestamp& timestamp) {};
|
||||||
virtual void pushCache(const Timestamp& timestamp) {};
|
virtual void pushCache(const Timestamp& timestamp) {};
|
||||||
virtual void initCache(Cache *_cache) {};
|
virtual void initCache(Cache *_cache) {};
|
||||||
|
@ -90,6 +90,7 @@ typedef void (*ErrorCallback)(const iTaSC::ConstraintValues *values, unsigned in
|
|||||||
|
|
||||||
// one structure for each target in the scene
|
// one structure for each target in the scene
|
||||||
struct IK_Target {
|
struct IK_Target {
|
||||||
|
const struct EvaluationContext *eval_ctx;
|
||||||
struct Scene *blscene;
|
struct Scene *blscene;
|
||||||
iTaSC::MovingFrame* target;
|
iTaSC::MovingFrame* target;
|
||||||
iTaSC::ConstraintSet* constraint;
|
iTaSC::ConstraintSet* constraint;
|
||||||
@ -107,6 +108,7 @@ struct IK_Target {
|
|||||||
float eeRest[4][4]; //end effector initial pose relative to armature
|
float eeRest[4][4]; //end effector initial pose relative to armature
|
||||||
|
|
||||||
IK_Target() {
|
IK_Target() {
|
||||||
|
eval_ctx = NULL;
|
||||||
blscene = NULL;
|
blscene = NULL;
|
||||||
target = NULL;
|
target = NULL;
|
||||||
constraint = NULL;
|
constraint = NULL;
|
||||||
@ -157,6 +159,7 @@ struct IK_Channel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct IK_Scene {
|
struct IK_Scene {
|
||||||
|
const struct EvaluationContext *eval_ctx;
|
||||||
struct Scene *blscene;
|
struct Scene *blscene;
|
||||||
IK_Scene* next;
|
IK_Scene* next;
|
||||||
int numchan; // number of channel in pchan
|
int numchan; // number of channel in pchan
|
||||||
@ -177,6 +180,7 @@ struct IK_Scene {
|
|||||||
std::vector<IK_Target*> targets;
|
std::vector<IK_Target*> targets;
|
||||||
|
|
||||||
IK_Scene() {
|
IK_Scene() {
|
||||||
|
eval_ctx = NULL;
|
||||||
blscene = NULL;
|
blscene = NULL;
|
||||||
next = NULL;
|
next = NULL;
|
||||||
channels = NULL;
|
channels = NULL;
|
||||||
@ -542,7 +546,7 @@ static void GetJointRotation(KDL::Rotation& boneRot, int type, double *rot)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool target_callback(const struct EvaluationContext *eval_ctx, const iTaSC::Timestamp& timestamp, const iTaSC::Frame& current, iTaSC::Frame& next, void *param)
|
static bool target_callback(const iTaSC::Timestamp& timestamp, const iTaSC::Frame& current, iTaSC::Frame& next, void *param)
|
||||||
{
|
{
|
||||||
IK_Target *target = (IK_Target *)param;
|
IK_Target *target = (IK_Target *)param;
|
||||||
// compute next target position
|
// compute next target position
|
||||||
@ -550,7 +554,7 @@ static bool target_callback(const struct EvaluationContext *eval_ctx, const iTaS
|
|||||||
bConstraint *constraint = (bConstraint *)target->blenderConstraint;
|
bConstraint *constraint = (bConstraint *)target->blenderConstraint;
|
||||||
float tarmat[4][4];
|
float tarmat[4][4];
|
||||||
|
|
||||||
BKE_constraint_target_matrix_get(eval_ctx, target->blscene, constraint, 0, CONSTRAINT_OBTYPE_OBJECT, target->owner, tarmat, 1.0);
|
BKE_constraint_target_matrix_get(target->eval_ctx, target->blscene, constraint, 0, CONSTRAINT_OBTYPE_OBJECT, target->owner, tarmat, 1.0);
|
||||||
|
|
||||||
// rootmat contains the target pose in world coordinate
|
// rootmat contains the target pose in world coordinate
|
||||||
// if enforce is != 1.0, blend the target position with the end effector position
|
// if enforce is != 1.0, blend the target position with the end effector position
|
||||||
@ -577,7 +581,7 @@ static bool target_callback(const struct EvaluationContext *eval_ctx, const iTaS
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool base_callback(const struct EvaluationContext *eval_ctx, const iTaSC::Timestamp& timestamp, const iTaSC::Frame& current, iTaSC::Frame& next, void *param)
|
static bool base_callback(const iTaSC::Timestamp& timestamp, const iTaSC::Frame& current, iTaSC::Frame& next, void *param)
|
||||||
{
|
{
|
||||||
IK_Scene *ikscene = (IK_Scene *)param;
|
IK_Scene *ikscene = (IK_Scene *)param;
|
||||||
// compute next armature base pose
|
// compute next armature base pose
|
||||||
@ -619,7 +623,7 @@ static bool base_callback(const struct EvaluationContext *eval_ctx, const iTaSC:
|
|||||||
IK_Channel &rootchan = ikscene->channels[0];
|
IK_Channel &rootchan = ikscene->channels[0];
|
||||||
|
|
||||||
// get polar target matrix in world space
|
// get polar target matrix in world space
|
||||||
BKE_constraint_target_matrix_get(eval_ctx, ikscene->blscene, ikscene->polarConstraint, 1, CONSTRAINT_OBTYPE_OBJECT, ikscene->blArmature, mat, 1.0);
|
BKE_constraint_target_matrix_get(ikscene->eval_ctx, ikscene->blscene, ikscene->polarConstraint, 1, CONSTRAINT_OBTYPE_OBJECT, ikscene->blArmature, mat, 1.0);
|
||||||
// convert to armature space
|
// convert to armature space
|
||||||
mul_m4_m4m4(polemat, imat, mat);
|
mul_m4_m4m4(polemat, imat, mat);
|
||||||
// get the target in world space (was computed before as target object are defined before base object)
|
// get the target in world space (was computed before as target object are defined before base object)
|
||||||
@ -1082,6 +1086,7 @@ static IK_Scene *convert_tree(const struct EvaluationContext *eval_ctx, Scene *b
|
|||||||
|
|
||||||
ikscene = new IK_Scene;
|
ikscene = new IK_Scene;
|
||||||
ikscene->blscene = blscene;
|
ikscene->blscene = blscene;
|
||||||
|
ikscene->eval_ctx = eval_ctx;
|
||||||
arm = new iTaSC::Armature();
|
arm = new iTaSC::Armature();
|
||||||
scene = new iTaSC::Scene();
|
scene = new iTaSC::Scene();
|
||||||
ikscene->channels = new IK_Channel[tree->totchannel];
|
ikscene->channels = new IK_Channel[tree->totchannel];
|
||||||
@ -1397,7 +1402,7 @@ static IK_Scene *convert_tree(const struct EvaluationContext *eval_ctx, Scene *b
|
|||||||
// we can now add the armature
|
// we can now add the armature
|
||||||
// the armature is based on a moving frame.
|
// the armature is based on a moving frame.
|
||||||
// initialize with the correct position in case there is no cache
|
// initialize with the correct position in case there is no cache
|
||||||
base_callback(eval_ctx, iTaSC::Timestamp(), iTaSC::F_identity, initPose, ikscene);
|
base_callback(iTaSC::Timestamp(), iTaSC::F_identity, initPose, ikscene);
|
||||||
ikscene->base = new iTaSC::MovingFrame(initPose);
|
ikscene->base = new iTaSC::MovingFrame(initPose);
|
||||||
ikscene->base->setCallback(base_callback, ikscene);
|
ikscene->base->setCallback(base_callback, ikscene);
|
||||||
std::string armname;
|
std::string armname;
|
||||||
@ -1439,6 +1444,7 @@ static IK_Scene *convert_tree(const struct EvaluationContext *eval_ctx, Scene *b
|
|||||||
for (t = 0; t < ikscene->targets.size(); t++) {
|
for (t = 0; t < ikscene->targets.size(); t++) {
|
||||||
IK_Target *iktarget = ikscene->targets[t];
|
IK_Target *iktarget = ikscene->targets[t];
|
||||||
iktarget->blscene = blscene;
|
iktarget->blscene = blscene;
|
||||||
|
iktarget->eval_ctx = eval_ctx;
|
||||||
condata = (bKinematicConstraint *)iktarget->blenderConstraint->data;
|
condata = (bKinematicConstraint *)iktarget->blenderConstraint->data;
|
||||||
pchan = tree->pchan[iktarget->channel];
|
pchan = tree->pchan[iktarget->channel];
|
||||||
unsigned int controltype, bonecnt;
|
unsigned int controltype, bonecnt;
|
||||||
@ -1458,7 +1464,7 @@ static IK_Scene *convert_tree(const struct EvaluationContext *eval_ctx, Scene *b
|
|||||||
mul_m4_m4m4(iktarget->eeRest, invBaseFrame, mat);
|
mul_m4_m4m4(iktarget->eeRest, invBaseFrame, mat);
|
||||||
iktarget->eeBlend = (!ikscene->polarConstraint && condata->type == CONSTRAINT_IK_COPYPOSE) ? true : false;
|
iktarget->eeBlend = (!ikscene->polarConstraint && condata->type == CONSTRAINT_IK_COPYPOSE) ? true : false;
|
||||||
// use target_callback to make sure the initPose includes enforce coefficient
|
// use target_callback to make sure the initPose includes enforce coefficient
|
||||||
target_callback(eval_ctx, iTaSC::Timestamp(), iTaSC::F_identity, initPose, iktarget);
|
target_callback(iTaSC::Timestamp(), iTaSC::F_identity, initPose, iktarget);
|
||||||
iktarget->target = new iTaSC::MovingFrame(initPose);
|
iktarget->target = new iTaSC::MovingFrame(initPose);
|
||||||
iktarget->target->setCallback(target_callback, iktarget);
|
iktarget->target->setCallback(target_callback, iktarget);
|
||||||
ret = scene->addObject(iktarget->targetName, iktarget->target);
|
ret = scene->addObject(iktarget->targetName, iktarget->target);
|
||||||
@ -1647,7 +1653,7 @@ static void execute_scene(const struct EvaluationContext *eval_ctx, Scene *blsce
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// don't cache if we are reiterating because we don't want to destroy the cache unnecessarily
|
// don't cache if we are reiterating because we don't want to destroy the cache unnecessarily
|
||||||
ikscene->scene->update(eval_ctx, timestamp, timestep, numstep, false, !reiterate, simulation);
|
ikscene->scene->update(timestamp, timestep, numstep, false, !reiterate, simulation);
|
||||||
if (reiterate) {
|
if (reiterate) {
|
||||||
// how many times do we reiterate?
|
// how many times do we reiterate?
|
||||||
for (i = 0; i < ikparam->numiter; i++) {
|
for (i = 0; i < ikparam->numiter; i++) {
|
||||||
@ -1656,11 +1662,11 @@ static void execute_scene(const struct EvaluationContext *eval_ctx, Scene *blsce
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ikscene->scene->update(eval_ctx, timestamp, timestep, numstep, true, false, simulation);
|
ikscene->scene->update(timestamp, timestep, numstep, true, false, simulation);
|
||||||
}
|
}
|
||||||
if (simulation) {
|
if (simulation) {
|
||||||
// one more fake iteration to cache
|
// one more fake iteration to cache
|
||||||
ikscene->scene->update(eval_ctx, timestamp, 0.0, 1, true, true, true);
|
ikscene->scene->update(timestamp, 0.0, 1, true, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// compute constraint error
|
// compute constraint error
|
||||||
|
Loading…
Reference in New Issue
Block a user