载入中...
搜索中...
未找到
FootIKSolver.cpp
浏览该文件的文档.
39 if(!leg.configured||!skeleton_||toe<0||toe>=skeleton_->getBoneCount()||skeleton_->getParent(toe)!=leg.foot)
45void FootIKSolver::setGroundQuery(float startHeight,float distance){groundStartHeight_=std::max(startHeight,0.f);groundQueryDistance_=std::max(distance,0.f);}
46void FootIKSolver::contact(Leg& leg,bool hit,float x,float y,float z,float nx,float ny,float nz,float weight) {
64void FootIKSolver::setFootLockEnabled(bool enabled){footLockEnabled_=enabled;if(!enabled){left_.locked=false;right_.locked=false;}}
65void FootIKSolver::setFootLockThresholds(float enter,float exit){lockEnterWeight_=clamp01(enter);lockExitWeight_=std::min(clamp01(exit),lockEnterWeight_);}
66void FootIKSolver::reset(){left_.initialized=right_.initialized=false;left_.toeInitialized=right_.toeInitialized=false;left_.locked=right_.locked=false;left_.missingTime=right_.missingTime=0.f;}
70 if(!leg.locked&&leg.target.weight>=lockEnterWeight_){leg.locked=true;leg.lockedContact=leg.target;}
76 const auto status=groundProvider_->queryGround(foot.px,foot.py+groundStartHeight_,foot.pz,groundStartHeight_+groundQueryDistance_,x,y,z,nx,ny,nz);
77 if(status==FootIKGroundQueryStatus::Hit){leg.missingTime=0.f;contact(leg,true,x,y,z,nx,ny,nz,1.f);}
78 else if(status==FootIKGroundQueryStatus::NoHit){leg.missingTime+=std::max(dt,0.f);if(leg.missingTime>contactGraceTime_)contact(leg,false,0.f,0.f,0.f,0.f,1.f,0.f,0.f);}
81 const auto toeStatus=groundProvider_->queryGround(toe.px,toe.py+groundStartHeight_,toe.pz,groundStartHeight_+groundQueryDistance_,x,y,z,nx,ny,nz);
82 if(toeStatus==FootIKGroundQueryStatus::Hit){const float n=std::sqrt(nx*nx+ny*ny+nz*nz);if(n>1e-6f){leg.toeTarget={x,y,z,nx/n,ny/n,nz/n,ny/n>=minGroundNormalY_?1.f:0.f};}}
92 leg.smooth.z+=(leg.target.z-leg.smooth.z)*p; leg.smooth.weight+=(leg.target.weight-leg.smooth.weight)*p;
95 const float n=std::sqrt(leg.smooth.nx*leg.smooth.nx+leg.smooth.ny*leg.smooth.ny+leg.smooth.nz*leg.smooth.nz);
110 if(leg.toeConfigured&&leg.toeSmooth.weight>1e-4f){pose.computeWorld(skeleton_);pose.aimBone(skeleton_,leg.toe,leg.toeSmooth.x,leg.toeSmooth.y+leg.toeSoleOffset,leg.toeSmooth.z,rotationWeight*leg.toeSmooth.weight);}
115 if(pose->getBoneCount()!=skeleton_->getBoneCount())throw Exception("FootIKSolver.apply: bone count mismatch");
118 auto interpolateToe=[&](Leg& leg){if(!leg.toeConfigured)return;if(!leg.toeInitialized){leg.toeSmooth=leg.toeTarget;leg.toeInitialized=true;return;}const float p=blendRate(positionResponse_,dt);leg.toeSmooth.x+=(leg.toeTarget.x-leg.toeSmooth.x)*p;leg.toeSmooth.y+=(leg.toeTarget.y-leg.toeSmooth.y)*p;leg.toeSmooth.z+=(leg.toeTarget.z-leg.toeSmooth.z)*p;leg.toeSmooth.weight+=(leg.toeTarget.weight-leg.toeSmooth.weight)*p;};
130 auto capture=[](const Leg& leg){FootIKDebugFoot out;out.configured=leg.configured;out.contact=leg.smooth.weight>1e-4f;out.locked=leg.locked;out.toeConfigured=leg.toeConfigured;out.x=leg.smooth.x;out.y=leg.smooth.y;out.z=leg.smooth.z;out.nx=leg.smooth.nx;out.ny=leg.smooth.ny;out.nz=leg.smooth.nz;out.toeX=leg.toeSmooth.x;out.toeY=leg.toeSmooth.y;out.toeZ=leg.toeSmooth.z;return out;};
Evaluated local (and optional world) pose for an AnimSkeleton. Script type: AnimPose.
Definition AnimPose.h:17
3D bone hierarchy + bind-pose local TRS for skeletal animation. Independent of ik::Skeleton3D (FABRIK...
Definition AnimSkeleton.h:16
virtual FootIKGroundQueryStatus queryGround(float originX, float originY, float originZ, float maxDistance, float &hitX, float &hitY, float &hitZ, float &normalX, float &normalY, float &normalZ) const =0
Query ground below an origin and return model-space contact data.
void setMinGroundNormalY(float value)
Set minimum accepted upward normal cosine in [0, 1].
Definition FootIKSolver.cpp:60
FootIKDebugSnapshot debugSnapshot() const
Copy smoothed contacts and lock state for tooling visualization.
Definition FootIKSolver.cpp:129
void setMaxPelvisOffset(float distance)
Set maximum pelvis compensation distance.
Definition FootIKSolver.cpp:59
void setGroundQuery(float startHeight, float distance)
Set ray origin height and downward query distance.
Definition FootIKSolver.cpp:45
FootIKSolver(AnimSkeleton *skeleton)
Construct for a non-null borrowed skeleton.
Definition FootIKSolver.cpp:15
void configureLeftToe(int toe, float soleOffset=0.f)
Configure an optional left toe child and its sole offset.
Definition FootIKSolver.cpp:43
void configureRightLeg(int hip, int knee, int foot, float soleOffset=0.f)
Configure the right hip-knee-foot chain and sole offset.
Definition FootIKSolver.cpp:37
void setFootLockEnabled(bool enabled)
Enable or disable world-space foot locking.
Definition FootIKSolver.cpp:64
void setRightContact(bool hit, float x, float y, float z, float nx, float ny, float nz, float weight=1.f)
Supply the right model-space ground contact.
Definition FootIKSolver.cpp:56
void setPositionResponse(float value)
Set contact interpolation response in inverse seconds.
Definition FootIKSolver.cpp:61
void setRotationResponse(float value)
Set foot-normal interpolation response in inverse seconds.
Definition FootIKSolver.cpp:62
void setContactGraceTime(float seconds)
Set how long a missing automatic contact retains its prior target.
Definition FootIKSolver.cpp:63
void apply(AnimPose *pose, float dt)
Apply using injected delta time and owning contact values.
Definition FootIKSolver.cpp:112
void setFootLockThresholds(float enterWeight, float exitWeight)
Set lock enter and release contact-weight thresholds.
Definition FootIKSolver.cpp:65
void configureLeftLeg(int hip, int knee, int foot, float soleOffset=0.f)
Configure the left hip-knee-foot chain and sole offset.
Definition FootIKSolver.cpp:36
void configureRightToe(int toe, float soleOffset=0.f)
Configure an optional right toe child and its sole offset.
Definition FootIKSolver.cpp:44
void setLeftContact(bool hit, float x, float y, float z, float nx, float ny, float nz, float weight=1.f)
Supply the left model-space ground contact.
Definition FootIKSolver.cpp:53
void setSkeleton(AnimSkeleton *skeleton)
Rebind; changing skeleton clears all bone-index configuration.
Definition FootIKSolver.cpp:19
Definition Animation.cpp:58
Immutable model-space state for one foot in a tooling snapshot.
Definition FootIKSolver.h:24
Owning renderer-neutral paired-foot tooling snapshot.
Definition FootIKSolver.h:26