Skip to main content
gamedev.net
🔒 Locked

Animation Controller & Weights

Started by e3d_ALiVE Sep 18, 2010 at 6:13 AM 3 replies 1.1k views
Original Post
e3d_ALiVE
e3d_ALiVE
i'v been implementing my own animation controller, based off id3dxanimationcontroller, my problem is that i can't completly understood how weights work
so far i'v come up with

[original_position or identity] ->weight0 -> anim0-> weight1 ->anim1 ->result
which for 2 tracks go like this

result=Lerp( Lerp(original,anim0,weight0), anim1,weight1)

which i for now implemented by decomposing matrix from previous frame
D3DXVECTOR3 LerpV(D3DXVECTOR3 a,D3DXVECTOR3 b,float weight){	D3DXVECTOR3 res;	res=a * (1.0f - weight) + b * weight;	return res;}D3DXQUATERNION LerpQ(D3DXQUATERNION a,D3DXQUATERNION b,float weight){	D3DXQUATERNION res;	D3DXQuaternionSlerp(&res,&a,&b,weight);//will be replaced by nlerp	return res;}...D3DXVECTOR3 s0,t0;				D3DXQUATERNION quat0;				s0=D3DXVECTOR3(1,1,1);				t0=D3DXVECTOR3(0,0,0);				quat0=qid;				D3DXMatrixDecompose(&s0,&quat0,&t0,pMatrix);				t=LerpV(t0,t,track.weight);				s=LerpV(s0,s,track.weight);				quat=LerpQ(quat0,quat,track.weight);				D3DXMatrixTransformation(&result, NULL, NULL, &s, NULL, &quat, &t);				*pMatrix = result;


my question is how real world weights in animation controller are working and implemented?
Crazy dude smoking D3D11, AngelScript, PhysX, 3D Sound, Network, DB, FBX, and some other weird things, doing that on Visual Studio 2010 + Visual Assist X on Overclocked CPU
Zahlman
Zahlman
I have no idea what you think "real world weights" means here.

For these functions, the "weight" is just how much of each input is used. In animation, you're interpolating from vector A to vector B, starting with A and ending with B, over some period of time. The "weight", here, is how much of that period of time has elapsed: At 0 (none of the time elapsed) we are at A, and at 1 (all of the time elapsed) we are at B, and in between we are in between.
e3d_ALiVE
e3d_ALiVE
i'm just trying to mimic how KeyTrackWeight works, it linearly changes the weights, so one tracks slowly blend into another, and i can understood that for 2 animation, you lerp pos/scale/rot from the results of the first one, but from what data should i fetch source data if i SetTrackWeight for first track.

In any cause i need to understand how AdvanceTime working with weights for certain animation, given animation already computer Pos/Rot/Scale.
Also does my code look anything like that?

p.s. it blends correctly if i set weight for 2 tracks, but not for the first track

for now it looks like that

Time += TimeDelta;	D3DXQUATERNION qid;	for(UINT i = 0; i < trackList.size(); i++)	{		Track & track = trackList;		if (track.enable == false)			continue;		if(track.weight<0.00001f) continue;		CE3DKeyframedAnimationSet * animSet = track.animSet;		//hack				track.position+=TimeDelta;				double animTime = track.position * animSet->TicksPerSecond * track.speed;		float MaxTime=animSet->GetMaxT();				track.isfinished=false;		if(animTime>MaxTime) 		{			track.isfinished=true;			if(track.loop) 			{				animTime=0;				SetTrackPosition(i,0);			}		}		BoneToKeyFrameSetMap::iterator it;		FOR_EACH(animSet->boneToKeyFrameSetMap, it)		{			const std::string &boneName = it->first;			KeyFrameSet  *keyFrameSet = it->second;			D3DXVECTOR3 s,t;			s.x = keyFrameSet->Sx.Evaluate(animTime, 1);			s.y = keyFrameSet->Sy.Evaluate(animTime, 1);			s.z = keyFrameSet->Sz.Evaluate(animTime, 1);			t.x = keyFrameSet->Tx.Evaluate(animTime, 0);			t.y = keyFrameSet->Ty.Evaluate(animTime, 0);			t.z = keyFrameSet->Tz.Evaluate(animTime, 0);			D3DXQUATERNION quat = keyFrameSet->Q.Evaluate(animTime, qid);			D3DXMATRIXA16 result;			BoneToMatrixMap::iterator it;			D3DXMATRIX * pMatrix=NULL;			it = boneToMatrixMap.find(boneName);			if(it != boneToMatrixMap.end())			{				pMatrix = it->second;			}			if(pMatrix)//save them			{				D3DXVECTOR3 s0,t0;				D3DXQUATERNION quat0;				s0=D3DXVECTOR3(1,1,1);				t0=D3DXVECTOR3(0,0,0);				quat0=qid;				D3DXMatrixDecompose(&s0,&quat0,&t0,pMatrix);				if(i==0)				{					t0=t;					s0=s;					quat0=quat;				}				t=LerpV(t0,t,track.weight);				s=LerpV(s0,s,track.weight);				quat=LerpQ(quat0,quat,track.weight);				D3DXMatrixTransformation(&result, NULL, NULL, &s, NULL, &quat, &t);				*pMatrix = result;			}		}	}	return S_OK;


[Edited by - e3d_ALiVE on September 18, 2010 8:31:04 AM]
Crazy dude smoking D3D11, AngelScript, PhysX, 3D Sound, Network, DB, FBX, and some other weird things, doing that on Visual Studio 2010 + Visual Assist X on Overclocked CPU
kilah
kilah
Haven't played with D3DX, but as an animation concept weights equals the percentage of influence of a bone matrix for said vertex. The sum of all weight must be 1. Thus that might be the reason why your animation is not skinning properly (therefore not working properly) as you are only using one weight which might be a low % of the global binding.
e3d_ALiVE
e3d_ALiVE
i'm testing weight correctly 0.2 for first track and 0.8 for second, the problem is, whatever first track weight [0.001..1] it does't affect anything, only when i'm setting 2 track weight, it works correctly
Crazy dude smoking D3D11, AngelScript, PhysX, 3D Sound, Network, DB, FBX, and some other weird things, doing that on Visual Studio 2010 + Visual Assist X on Overclocked CPU

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.