DGL
https://delphigl.com/forum/

Blending Matrices
https://delphigl.com/forum/viewtopic.php?f=19&t=4098
Seite 1 von 1

Autor:  McCLaw [ Di Mai 03, 2005 19:40 ]
Betreff des Beitrags:  Blending Matrices

Hi All

I am in the process of implementing a Bone Blending animation class, but I have hit a math snag.

I have gotten to the point of getting all the interpolated matrices from the active animations, but I am unsure how to change them according to the weight of each animation, and then how to merge them.

PS: My math knowledge sucks, so speak to me like i'm a three year old :wink:

Any ideas will be greatly appreciated

Autor:  Stucuk [ Mi Mai 04, 2005 16:12 ]
Betreff des Beitrags: 

If i remember MD5's correct u add all the bones positions to the vertex's that it effects with the weight scale thing applyed to the bones position.

Code:
  1.  
  2. V := VertexPosition;
  3.  
  4. For x := 0 to NumOfBones do
  5. If Bone Effects Vertex then
  6. V := V + (Bone * Weight);
  7.  

Autor:  AL [ Mi Mai 04, 2005 23:25 ]
Betreff des Beitrags: 

Nearly. In the MD5 format you need to do 2 things:
First calc the skeleton. Usually there are lots of frames, so you actually don't need any interpolation. However, looks like you somehow managed to do that. Than you have to go through the whole skeleton, and multiply the matrices to get the world-space-matrix of each node. (Dunno, whether you already got that part).
Second thing to do is what Stucuk mentioned:
Code:
  1.  
  2. for i := 0 to High(Vertices) do
  3. begin
  4.      Vertices[i].Position := Vec(0, 0, 0); //At least at MD5 the position is given through the weights and the bones' matrices
  5.      For j := 0 to High(Vertices[i].Weights) do
  6.      begin
  7.           Vertices[i].Position := AddVec(Vertices[i].Position + MultVec(AddVec(MultMat(Bones[Vertices[i].Weight[j].Bone].Rot,
  8.                                                                                        Vertices[i].Weight[j].Weight),
  9.                                                                                Bones[Vertices[i].Weight[j].Bone].Pos),
  10. //I splitted it up into Position and rotation. makes things easier...
  11.                                                                         Vertices[i].Weight[j].Bias)      //And don't forget the bias...
  12.                                         );
  13.      end;
  14. end;
  15.  


This is more or less what I did for MD5s. Worked for most of the models...

Autor:  McCLaw [ Do Mai 05, 2005 22:51 ]
Betreff des Beitrags: 

Thanx for the suggestions :)

I figured out a way of doing this with Nitrogens help (Thanx Dude) :D

Code:
  1.  
  2. SetLength(FMergedMatrices,0);
  3.   if Count > 0 then // We have animations to check
  4.   begin
  5.     for i := 0 to Count - 1 do
  6.     begin
  7.       lAnim := Anims[i];
  8.       if lAnim.Active then
  9.       begin
  10.         lAnim.CalulateCurrentBoneMatrix(FCurrentTime); // Get the interpolated matrix list
  11.         { Merge With Other Bone Matrices }
  12.         for j := 0 to Length(lAnim.MergedMatrices) - 1 do
  13.         begin
  14.           lMergedMatrix := lAnim.MergedMatrices[j];
  15.           { If FMergedMatrices is too small, make it bigger}
  16.           if Length(FMergedMatrices) < j + 1 then
  17.           begin
  18.             SetLength(FMergedMatrices,j + 1);
  19.           end;
  20.           { Scale the matrix according to the Influence the animation has on the mesh }
  21.           ScaleMatrix(lMergedMatrix,lAnim.Influence);
  22.           for n := 0 to 3 do
  23.           begin
  24.             // Concatinate the matrix to the other stored matrices
  25.             VectorAdd(lMergedMatrix[n],FMergedMatrices[j][n],FMergedMatrices[j][n]);
  26.           end;
  27.         end;
  28.       end;
  29.     end;
  30.   end;
  31.  


Obviously this in only the first part of the process, I stil need to add individual bone weights into the algo to allow for feather blending.

The current code basically allows any number of interpolated frames in several animations to be blended by their influence (Value between 0 and 1)

I had a look at doing all the calculations per vertex, but that seemed way too expensive.(My thoughts: Rather do a 16 * amount of bones calculation then an undefined number of calculations for any number of vertices in the mesh) and then just apply the resulting matrix to the correct verts in the inverted mesh.

It seems that the same theory would apply to individual bone weights, but I'll only know once I have finished that :)

PS: I'm using the VectorGeometry.pas file from glscene.

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/