Changeset 401
- Timestamp:
- 10/06/11 10:50:23 (8 months ago)
- Location:
- cafu/trunk/Libs/Models
- Files:
-
- 2 modified
-
AnimPose.cpp (modified) (31 diffs)
-
AnimPose.hpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cafu/trunk/Libs/Models/AnimPose.cpp
r400 r401 32 32 : m_Model(Model), 33 33 m_SequNr(SequNr), 34 m_FrameNr(FrameNr), 34 35 m_Super(NULL), 35 m_FrameNr(FrameNr),36 36 m_NeedsRecache(true), 37 37 m_BoundingBox() … … 131 131 case MatSys::RendererI::AMBIENT: 132 132 { 133 for (unsigned long MeshNr=0; MeshNr<m_ Meshes.Size(); MeshNr++)133 for (unsigned long MeshNr=0; MeshNr<m_Draw_Meshes.Size(); MeshNr++) 134 134 { 135 135 MatSys::Renderer->SetCurrentMaterial(m_Model.GetRenderMaterial(MeshNr, SkinNr)); … … 190 190 case MatSys::RendererI::LIGHTING: 191 191 { 192 for (unsigned long MeshNr=0; MeshNr<m_ Meshes.Size(); MeshNr++)192 for (unsigned long MeshNr=0; MeshNr<m_Draw_Meshes.Size(); MeshNr++) 193 193 { 194 194 MatSys::Renderer->SetCurrentMaterial(m_Model.GetRenderMaterial(MeshNr, SkinNr)); … … 200 200 case MatSys::RendererI::STENCILSHADOW: 201 201 { 202 const Vector3fT LightPos(MatSys::Renderer->GetCurrentLightSourcePosition()); 203 204 for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 205 { 206 const CafuModelT::MeshT& Mesh =m_Model.GetMeshes()[MeshNr]; 207 const AnimPoseT::MeshT& PoseMesh=m_Meshes[MeshNr]; 208 const MaterialT* MeshMat =m_Model.GetMaterial(MeshNr, SkinNr); 202 typedef CafuModelT::MeshT MeshT; 203 204 const ArrayT<MeshT>& Meshes=m_Model.GetMeshes(); 205 const Vector3fT LightPos(MatSys::Renderer->GetCurrentLightSourcePosition()); 206 207 for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 208 { 209 const MeshT& Mesh =Meshes[MeshNr]; 210 const MeshInfoT& MeshInfo=m_MeshInfos[MeshNr]; 211 const MaterialT* MeshMat =m_Model.GetMaterial(MeshNr, SkinNr); 209 212 210 213 if (MeshMat==NULL || MeshMat->NoShadows) continue; … … 216 219 for (unsigned long TriNr=0; TriNr<Mesh.Triangles.Size(); TriNr++) 217 220 { 218 const CafuModelT::MeshT::TriangleT&Tri =Mesh.Triangles[TriNr];219 const AnimPoseT::MeshT::TriangleT& PoseTri=PoseMesh.Triangles[TriNr];220 221 const float Dot=(LightPos- PoseMesh.Vertices[Tri.VertexIdx[0]].Draw_Pos).dot(PoseTri.Draw_Normal);221 const MeshT::TriangleT& Tri =Mesh.Triangles[TriNr]; 222 const MeshInfoT::TriangleT& TriInfo=MeshInfo.Triangles[TriNr]; 223 224 const float Dot=(LightPos-MeshInfo.Vertices[Tri.VertexIdx[0]].Pos).dot(TriInfo.Normal); 222 225 223 226 TriangleIsFrontFacing[TriNr]=Dot>0; … … 234 237 235 238 // This triangle is front-facing wrt. the light source. 236 const CafuModelT::MeshT::TriangleT& Tri=Mesh.Triangles[TriNr];239 const MeshT::TriangleT& Tri=Mesh.Triangles[TriNr]; 237 240 238 241 for (unsigned long EdgeNr=0; EdgeNr<3; EdgeNr++) … … 246 249 const unsigned long v1=EdgeNr; 247 250 const unsigned long v2=(EdgeNr+1) % 3; 248 const Vector3fT LA= PoseMesh.Vertices[Tri.VertexIdx[v1]].Draw_Pos-LightPos;249 const Vector3fT LB= PoseMesh.Vertices[Tri.VertexIdx[v2]].Draw_Pos-LightPos;251 const Vector3fT LA=MeshInfo.Vertices[Tri.VertexIdx[v1]].Pos-LightPos; 252 const Vector3fT LB=MeshInfo.Vertices[Tri.VertexIdx[v2]].Pos-LightPos; 250 253 251 254 MeshSilhouette.Vertices.PushBackEmpty(4); … … 253 256 const unsigned long MeshSize=MeshSilhouette.Vertices.Size(); 254 257 255 MeshSilhouette.Vertices[MeshSize-4].SetOrigin( PoseMesh.Vertices[Tri.VertexIdx[v2]].Draw_Pos);256 MeshSilhouette.Vertices[MeshSize-3].SetOrigin( PoseMesh.Vertices[Tri.VertexIdx[v1]].Draw_Pos);258 MeshSilhouette.Vertices[MeshSize-4].SetOrigin(MeshInfo.Vertices[Tri.VertexIdx[v2]].Pos); 259 MeshSilhouette.Vertices[MeshSize-3].SetOrigin(MeshInfo.Vertices[Tri.VertexIdx[v1]].Pos); 257 260 MeshSilhouette.Vertices[MeshSize-2].SetOrigin(LA, 0.0); 258 261 MeshSilhouette.Vertices[MeshSize-1].SetOrigin(LB, 0.0); … … 279 282 280 283 // Render the occluder (front-facing wrt. the light source). 281 const Vector3fT& A= PoseMesh.Vertices[Tri.VertexIdx[0]].Draw_Pos;282 const Vector3fT& B= PoseMesh.Vertices[Tri.VertexIdx[1]].Draw_Pos;283 const Vector3fT& C= PoseMesh.Vertices[Tri.VertexIdx[2]].Draw_Pos;284 const Vector3fT& A=MeshInfo.Vertices[Tri.VertexIdx[0]].Pos; 285 const Vector3fT& B=MeshInfo.Vertices[Tri.VertexIdx[1]].Pos; 286 const Vector3fT& C=MeshInfo.Vertices[Tri.VertexIdx[2]].Pos; 284 287 285 288 MeshCaps.Vertices[MeshSize-6].SetOrigin(A); … … 308 311 bool AnimPoseT::TraceRay(int SkinNr, const Vector3fT& RayOrigin, const Vector3fT& RayDir, ModelT::TraceResultT& Result) const 309 312 { 313 Recache(); 314 315 // If we miss the bounding-box, then we miss all the triangles as well. 310 316 float Fraction=0.0f; 311 312 Recache();313 314 // If we miss the bounding-box, then we miss all the triangles as well.315 317 if (!GetBB().TraceRay(RayOrigin, RayDir, Fraction)) return false; 316 318 317 for (unsigned long MeshNr=0; MeshNr<m_Meshes.Size(); MeshNr++) 318 { 319 const CafuModelT::MeshT& Mesh =m_Model.GetMeshes()[MeshNr]; 320 const MeshT& DrawMesh=m_Meshes[MeshNr]; 321 const MaterialT* MeshMat =m_Model.GetMaterial(MeshNr, SkinNr); 319 typedef CafuModelT::MeshT MeshT; 320 321 const ArrayT<MeshT>& Meshes=m_Model.GetMeshes(); 322 323 for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 324 { 325 const MeshT& Mesh =Meshes[MeshNr]; 326 const MeshInfoT& MeshInfo=m_MeshInfos[MeshNr]; 327 const MaterialT* MeshMat =m_Model.GetMaterial(MeshNr, SkinNr); 322 328 323 329 // If the ClipFlags don't match the ClipMask, this polygon doesn't interfere with the trace. … … 330 336 // see there for details and additional information. 331 337 using namespace cf::math; 332 const CafuModelT::MeshT::TriangleT&Tri =Mesh.Triangles[TriNr];333 const AnimPoseT::MeshT::TriangleT& DrawTri=DrawMesh.Triangles[TriNr];334 335 const Vector3fT& A= DrawMesh.Vertices[Tri.VertexIdx[0]].Draw_Pos;336 const Vector3fT& B= DrawMesh.Vertices[Tri.VertexIdx[1]].Draw_Pos;337 const Vector3fT& C= DrawMesh.Vertices[Tri.VertexIdx[2]].Draw_Pos;338 const MeshT::TriangleT& Tri =Mesh.Triangles[TriNr]; 339 const MeshInfoT::TriangleT& TriInfo=MeshInfo.Triangles[TriNr]; 340 341 const Vector3fT& A=MeshInfo.Vertices[Tri.VertexIdx[0]].Pos; 342 const Vector3fT& B=MeshInfo.Vertices[Tri.VertexIdx[1]].Pos; 343 const Vector3fT& C=MeshInfo.Vertices[Tri.VertexIdx[2]].Pos; 338 344 339 345 const PlueckerfT R=PlueckerfT::CreateFromRay(RayOrigin, RayDir); … … 361 367 362 368 // The "aperture" test passed, now compute the fraction at which RayDir intersects the triangle plane. 363 const float Nenner=dot( DrawTri.Draw_Normal, RayDir);364 365 if (Nenner==0) continue; // If Nenner==0, then RayDir is parallel to the triangle plane (no intersection).366 assert(MeshMat->TwoSided || Nenner<0); // If the material is single sided, then Nenner<0, a consequence of the Pluecker tests above.367 368 const float Dist=dot( DrawTri.Draw_Normal, RayOrigin-A);// The distance of RayOrigin to the triangle plane.369 const float Nenner=dot(TriInfo.Normal, RayDir); 370 371 if (Nenner==0) continue; // If Nenner==0, then RayDir is parallel to the triangle plane (no intersection). 372 assert(MeshMat->TwoSided || Nenner<0); // If the material is single sided, then Nenner<0, a consequence of the Pluecker tests above. 373 374 const float Dist=dot(TriInfo.Normal, RayOrigin-A); // The distance of RayOrigin to the triangle plane. 369 375 const float F =-(Dist-0.03125f)/Nenner; 370 376 … … 374 380 // Hit the triangle! 375 381 Result.Fraction=F; 376 Result.Normal =(Nenner<0) ? DrawTri.Draw_Normal : -DrawTri.Draw_Normal;// Handle two-sided materials properly.382 Result.Normal =(Nenner<0) ? TriInfo.Normal : -TriInfo.Normal; // Handle two-sided materials properly. 377 383 Result.Material=MeshMat; 378 384 Result.MeshNr =MeshNr; … … 396 402 { 397 403 const unsigned int VertexNr=m_Model.GetMeshes()[MeshNr].Triangles[TriNr].VertexIdx[i]; 398 const Vector3fT& DrawPos =m_Mesh es[MeshNr].Vertices[VertexNr].Draw_Pos;404 const Vector3fT& DrawPos =m_MeshInfos[MeshNr].Vertices[VertexNr].Pos; 399 405 const float Dist =length(DrawPos-P); 400 406 … … 414 420 Recache(); 415 421 416 return m_Mesh es[MeshNr].Vertices[VertexNr].Draw_Pos;422 return m_MeshInfos[MeshNr].Vertices[VertexNr].Pos; 417 423 } 418 424 … … 464 470 } 465 471 466 if (m_Mesh es.Size()!=m_Model.GetMeshes().Size())467 { 468 m_Mesh es.Overwrite();469 m_Mesh es.PushBackEmptyExact(m_Model.GetMeshes().Size());472 if (m_MeshInfos.Size()!=m_Model.GetMeshes().Size()) 473 { 474 m_MeshInfos.Overwrite(); 475 m_MeshInfos.PushBackEmptyExact(m_Model.GetMeshes().Size()); 470 476 } 471 477 … … 481 487 const CafuModelT::MeshT& Mesh=m_Model.GetMeshes()[MeshNr]; 482 488 483 if (m_Mesh es[MeshNr].Vertices.Size()!=Mesh.Vertices.Size())484 { 485 m_Mesh es[MeshNr].Vertices.Overwrite();486 m_Mesh es[MeshNr].Vertices.PushBackEmptyExact(Mesh.Vertices.Size());487 } 488 489 if (m_Mesh es[MeshNr].Triangles.Size()!=Mesh.Triangles.Size())490 { 491 m_Mesh es[MeshNr].Triangles.Overwrite();492 m_Mesh es[MeshNr].Triangles.PushBackEmptyExact(Mesh.Triangles.Size());489 if (m_MeshInfos[MeshNr].Vertices.Size()!=Mesh.Vertices.Size()) 490 { 491 m_MeshInfos[MeshNr].Vertices.Overwrite(); 492 m_MeshInfos[MeshNr].Vertices.PushBackEmptyExact(Mesh.Vertices.Size()); 493 } 494 495 if (m_MeshInfos[MeshNr].Triangles.Size()!=Mesh.Triangles.Size()) 496 { 497 m_MeshInfos[MeshNr].Triangles.Overwrite(); 498 m_MeshInfos[MeshNr].Triangles.PushBackEmptyExact(Mesh.Triangles.Size()); 493 499 } 494 500 … … 519 525 void AnimPoseT::UpdateData() const 520 526 { 521 const int SequenceNr=m_SequNr;522 const float FrameNr =m_FrameNr;523 const SuperT* Super =m_Super;524 const bool m_UseGivenTangentSpace=m_Model.GetUseGivenTS();525 526 const ArrayT<CafuModelT::JointT>& m_Joints=m_Model.GetJoints();527 const ArrayT<CafuModelT::AnimT>& m_Anims =m_Model.GetAnims();528 527 typedef CafuModelT::JointT JointT; 529 typedef CafuModelT::AnimT AnimT; 528 typedef CafuModelT::MeshT MeshT; 529 typedef CafuModelT::AnimT AnimT; 530 531 const ArrayT<JointT>& Joints=m_Model.GetJoints(); 532 const ArrayT<MeshT>& Meshes=m_Model.GetMeshes(); 533 const ArrayT<AnimT>& Anims =m_Model.GetAnims(); 530 534 531 535 532 536 // ************************************************************************************************************** 533 // Obtain a joints (bone) hierarchy for the desired frame FrameNr of the desired animation sequence SequenceNr.537 // Obtain a joints (bone) hierarchy for the desired frame m_FrameNr of the desired animation sequence m_SequNr. 534 538 // The result will be a transformation matrix for each joint (bone). 535 539 // ************************************************************************************************************** 536 540 537 if ( SequenceNr==-1)541 if (m_SequNr==-1) 538 542 { 539 543 // Don't animate, just use the bind pose defined in the model file. 540 for (unsigned long JointNr=0; JointNr< m_Joints.Size(); JointNr++)541 { 542 if ( Super &&Super->HasMatrix(JointNr))543 { 544 m_JointMatrices[JointNr]= Super->GetMatrix(JointNr);544 for (unsigned long JointNr=0; JointNr<Joints.Size(); JointNr++) 545 { 546 if (m_Super && m_Super->HasMatrix(JointNr)) 547 { 548 m_JointMatrices[JointNr]=m_Super->GetMatrix(JointNr); 545 549 continue; 546 550 } 547 551 548 const JointT& J= m_Joints[JointNr];552 const JointT& J=Joints[JointNr]; 549 553 const MatrixT RelMatrix(J.Pos, cf::math::QuaternionfT::FromXYZ(J.Qtr), J.Scale); 550 554 … … 554 558 else 555 559 { 556 // SequenceNr is a valid index into m_Anims, so use that.557 const AnimT& Anim= m_Anims[SequenceNr];558 const int Frame_0=int( FrameNr); // IfFrameNr == 17.83, then Frame_0 == 17559 const float Frame_f= FrameNr-Frame_0; //Frame_f == 0.83560 const int Frame_1=(Frame_0+1>=int(Anim.Frames.Size())) ? 0 : Frame_0+1; // Frame_1 == 18561 562 for (unsigned long JointNr=0; JointNr< m_Joints.Size(); JointNr++)563 { 564 if ( Super &&Super->HasMatrix(JointNr))565 { 566 m_JointMatrices[JointNr]= Super->GetMatrix(JointNr);560 // m_SequNr is a valid index into Anims, so use that. 561 const AnimT& Anim=Anims[m_SequNr]; 562 const int Frame_0=int(m_FrameNr); // If m_FrameNr == 17.83, then Frame_0 == 17 563 const float Frame_f=m_FrameNr-Frame_0; // Frame_f == 0.83 564 const int Frame_1=(Frame_0+1>=int(Anim.Frames.Size())) ? 0 : Frame_0+1; // Frame_1 == 18 565 566 for (unsigned long JointNr=0; JointNr<Joints.Size(); JointNr++) 567 { 568 if (m_Super && m_Super->HasMatrix(JointNr)) 569 { 570 m_JointMatrices[JointNr]=m_Super->GetMatrix(JointNr); 567 571 continue; 568 572 } 569 573 570 574 const AnimT::AnimJointT& AJ=Anim.AnimJoints[JointNr]; 571 Vector3fT Data_0[3]={ AJ.DefaultPos, AJ.DefaultQtr, AJ.DefaultScale }; 572 Vector3fT Data_1[3]={ AJ.DefaultPos, AJ.DefaultQtr, AJ.DefaultScale }; 575 576 Vector3fT Data_0[3]={ AJ.DefaultPos, AJ.DefaultQtr, AJ.DefaultScale }; 577 Vector3fT Data_1[3]={ AJ.DefaultPos, AJ.DefaultQtr, AJ.DefaultScale }; 573 578 574 579 // Determine the position, quaternion and scale for Frame_0 and Frame_1. … … 593 598 // Compute the matrix that is relative to the parent bone, and finally obtain the absolute matrix for that bone! 594 599 const MatrixT RelMatrix(Pos, Quat, Scale); 595 const JointT& J= m_Joints[JointNr];600 const JointT& J=Joints[JointNr]; 596 601 597 602 m_JointMatrices[JointNr]=(J.Parent==-1) ? RelMatrix : m_JointMatrices[J.Parent]*RelMatrix; … … 605 610 // ******************************************************************************************************************* 606 611 607 for (unsigned long MeshNr=0; MeshNr< m_Meshes.Size(); MeshNr++)608 { 609 const CafuModelT::MeshT& Mesh=m_Model.GetMeshes()[MeshNr];610 Mesh T& DrawMesh=m_Meshes[MeshNr];612 for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 613 { 614 const MeshT& Mesh =Meshes[MeshNr]; 615 MeshInfoT& MeshInfo=m_MeshInfos[MeshNr]; 611 616 612 617 for (unsigned long VertexNr=0; VertexNr<Mesh.Vertices.Size(); VertexNr++) 613 618 { 614 const CafuModelT::MeshT::VertexT& Vertex=Mesh.Vertices[VertexNr];615 Mesh T::VertexT& DrawVertex=DrawMesh.Vertices[VertexNr];619 const MeshT::VertexT& Vertex =Mesh.Vertices[VertexNr]; 620 MeshInfoT::VertexT& VertexInfo=MeshInfo.Vertices[VertexNr]; 616 621 617 622 if (Vertex.GeoDups.Size()>0 && Vertex.GeoDups[0]<VertexNr) … … 619 624 // This vertex has a geometrically identical duplicate that has already been computed. 620 625 // Therefore, don't bother to recompute the same position again, just copy it from the duplicate. 621 DrawVertex.Draw_Pos=DrawMesh.Vertices[Vertex.GeoDups[0]].Draw_Pos;626 VertexInfo.Pos=MeshInfo.Vertices[Vertex.GeoDups[0]].Pos; 622 627 continue; 623 628 } … … 625 630 if (Vertex.NumWeights==1) 626 631 { 627 const CafuModelT::MeshT::WeightT& Weight=Mesh.Weights[Vertex.FirstWeightIdx];628 629 DrawVertex.Draw_Pos=m_JointMatrices[Weight.JointIdx].Mul_xyz1(Weight.Pos);632 const MeshT::WeightT& Weight=Mesh.Weights[Vertex.FirstWeightIdx]; 633 634 VertexInfo.Pos=m_JointMatrices[Weight.JointIdx].Mul_xyz1(Weight.Pos); 630 635 } 631 636 else 632 637 { 633 DrawVertex.Draw_Pos=Vector3fT(0.0f, 0.0f, 0.0f);638 VertexInfo.Pos=Vector3fT(0.0f, 0.0f, 0.0f); 634 639 635 640 for (unsigned int WeightNr=0; WeightNr<Vertex.NumWeights; WeightNr++) 636 641 { 637 const CafuModelT::MeshT::WeightT& Weight=Mesh.Weights[Vertex.FirstWeightIdx+WeightNr];638 639 DrawVertex.Draw_Pos+=m_JointMatrices[Weight.JointIdx].Mul_xyz1(Weight.Pos) * Weight.Weight;642 const MeshT::WeightT& Weight=Mesh.Weights[Vertex.FirstWeightIdx+WeightNr]; 643 644 VertexInfo.Pos+=m_JointMatrices[Weight.JointIdx].Mul_xyz1(Weight.Pos) * Weight.Weight; 640 645 } 641 646 } … … 651 656 // ******************************************************************************************* 652 657 653 if (m_ UseGivenTangentSpace)654 { 655 assert( m_Anims.Size()==0); // It doesn't make sense to have statically given tangent-space axes with *animated* geometry...658 if (m_Model.GetUseGivenTS()) 659 { 660 assert(Anims.Size()==0); // It doesn't make sense to have statically given tangent-space axes with *animated* geometry... 656 661 goto DoneComputingTS; 657 662 } 658 663 659 664 // For all vertices, zero the tangent-space vectors for the subsequent average accumulation. 660 for (unsigned long MeshNr=0; MeshNr< m_Meshes.Size(); MeshNr++)661 { 662 Mesh T& Mesh=m_Meshes[MeshNr];663 664 for (unsigned long VertexNr=0; VertexNr<Mesh .Vertices.Size(); VertexNr++)665 { 666 Mesh T::VertexT& Vertex=Mesh.Vertices[VertexNr];667 668 Vertex .Draw_Normal =Vector3fT(0, 0, 0);669 Vertex .Draw_Tangent =Vector3fT(0, 0, 0);670 Vertex .Draw_BiNormal=Vector3fT(0, 0, 0);665 for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 666 { 667 MeshInfoT& MeshInfo=m_MeshInfos[MeshNr]; 668 669 for (unsigned long VertexNr=0; VertexNr<MeshInfo.Vertices.Size(); VertexNr++) 670 { 671 MeshInfoT::VertexT& VertexInfo=MeshInfo.Vertices[VertexNr]; 672 673 VertexInfo.Normal =Vector3fT(0, 0, 0); 674 VertexInfo.Tangent =Vector3fT(0, 0, 0); 675 VertexInfo.BiNormal=Vector3fT(0, 0, 0); 671 676 } 672 677 } 673 678 674 679 // Compute the per-triangle tangent-space axes and distribute them over the relevant vertices appropriately. 675 for (unsigned long MeshNr=0; MeshNr< m_Meshes.Size(); MeshNr++)676 { 677 const CafuModelT::MeshT& Mesh=m_Model.GetMeshes()[MeshNr];678 Mesh T& DrawMesh=m_Meshes[MeshNr];680 for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 681 { 682 const MeshT& Mesh =Meshes[MeshNr]; 683 MeshInfoT& MeshInfo=m_MeshInfos[MeshNr]; 679 684 680 685 for (unsigned long TriangleNr=0; TriangleNr<Mesh.Triangles.Size(); TriangleNr++) 681 686 { 682 const CafuModelT::MeshT::TriangleT& Tri=Mesh.Triangles[TriangleNr];683 const CafuModelT::MeshT::VertexT& V_0=Mesh.Vertices[Tri.VertexIdx[0]];684 const CafuModelT::MeshT::VertexT& V_1=Mesh.Vertices[Tri.VertexIdx[1]];685 const CafuModelT::MeshT::VertexT& V_2=Mesh.Vertices[Tri.VertexIdx[2]];686 687 Mesh T::TriangleT& DrawTri=DrawMesh.Triangles[TriangleNr];688 Mesh T::VertexT& DrawV_0=DrawMesh.Vertices[Tri.VertexIdx[0]];689 Mesh T::VertexT& DrawV_1=DrawMesh.Vertices[Tri.VertexIdx[1]];690 Mesh T::VertexT& DrawV_2=DrawMesh.Vertices[Tri.VertexIdx[2]];691 692 const Vector3fT Edge01=DrawV_1.Draw_Pos-DrawV_0.Draw_Pos;693 const Vector3fT Edge02=DrawV_2.Draw_Pos-DrawV_0.Draw_Pos;687 const MeshT::TriangleT& Tri=Mesh.Triangles[TriangleNr]; 688 const MeshT::VertexT& V_0=Mesh.Vertices[Tri.VertexIdx[0]]; 689 const MeshT::VertexT& V_1=Mesh.Vertices[Tri.VertexIdx[1]]; 690 const MeshT::VertexT& V_2=Mesh.Vertices[Tri.VertexIdx[2]]; 691 692 MeshInfoT::TriangleT& TriInfo=MeshInfo.Triangles[TriangleNr]; 693 MeshInfoT::VertexT& V_0Info=MeshInfo.Vertices[Tri.VertexIdx[0]]; 694 MeshInfoT::VertexT& V_1Info=MeshInfo.Vertices[Tri.VertexIdx[1]]; 695 MeshInfoT::VertexT& V_2Info=MeshInfo.Vertices[Tri.VertexIdx[2]]; 696 697 const Vector3fT Edge01=V_1Info.Pos-V_0Info.Pos; 698 const Vector3fT Edge02=V_2Info.Pos-V_0Info.Pos; 694 699 695 700 // Triangles are ordered CW for md5 models and CCW for ase models, so we write 696 701 // Normal=VectorCross(Edge02, Edge01) for md5 models and Normal=VectorCross(Edge01, Edge02) for ase models. 697 DrawTri.Draw_Normal=myNormalize(Edge02.cross(Edge01));702 TriInfo.Normal=myNormalize(Edge02.cross(Edge01)); 698 703 699 704 // Understanding what's going on here is easy. The key statement is … … 705 710 const float f =uv01.x*uv02.y-uv01.y*uv02.x>0.0 ? 1.0f : -1.0f; 706 711 707 const Vector3fT Tri _Draw_Tangent =myNormalize(Edge02.GetScaled(-uv01.y*f) + Edge01.GetScaled(uv02.y*f));708 const Vector3fT Tri _Draw_BiNormal=myNormalize(Edge02.GetScaled( uv01.x*f) - Edge01.GetScaled(uv02.x*f));712 const Vector3fT TriInfo_Draw_Tangent =myNormalize(Edge02.GetScaled(-uv01.y*f) + Edge01.GetScaled(uv02.y*f)); 713 const Vector3fT TriInfo_Draw_BiNormal=myNormalize(Edge02.GetScaled( uv01.x*f) - Edge01.GetScaled(uv02.x*f)); 709 714 710 715 … … 714 719 715 720 const float c0=dot(myNormalize(Edge01), myNormalize(Edge02)); 716 const float c1=dot(myNormalize(Edge01), myNormalize( DrawV_1.Draw_Pos-DrawV_2.Draw_Pos));721 const float c1=dot(myNormalize(Edge01), myNormalize(V_1Info.Pos-V_2Info.Pos)); 717 722 718 723 const float w0=(c0>=1.0f) ? 0.0f : ( (c0<=-1.0f) ? Pi : acos(c0) ); … … 726 731 for (int i=0; i<3; i++) 727 732 { 728 const CafuModelT::MeshT::VertexT& Vertex=Mesh.Vertices[Tri.VertexIdx[i]];729 Mesh T::VertexT& DrawVertex=DrawMesh.Vertices[Tri.VertexIdx[i]];733 const MeshT::VertexT& Vertex =Mesh.Vertices[Tri.VertexIdx[i]]; 734 MeshInfoT::VertexT& VertexInfo=MeshInfo.Vertices[Tri.VertexIdx[i]]; 730 735 731 736 assert(Tri.Polarity==Vertex.Polarity); 732 737 733 DrawVertex.Draw_Normal +=DrawTri.Draw_Normal*TriWeight[i];734 DrawVertex.Draw_Tangent +=Tri_Draw_Tangent*TriWeight[i];735 DrawVertex.Draw_BiNormal+=Tri_Draw_BiNormal*TriWeight[i];738 VertexInfo.Normal +=TriInfo.Normal*TriWeight[i]; 739 VertexInfo.Tangent +=TriInfo_Draw_Tangent*TriWeight[i]; 740 VertexInfo.BiNormal+=TriInfo_Draw_BiNormal*TriWeight[i]; 736 741 737 742 for (unsigned long DupNr=0; DupNr<Vertex.GeoDups.Size(); DupNr++) 738 743 { 739 const CafuModelT::MeshT::VertexT& DupVertex=Mesh.Vertices[Vertex.GeoDups[DupNr]];740 Mesh T::VertexT& DrawDupVertex=DrawMesh.Vertices[Vertex.GeoDups[DupNr]];741 742 D rawDupVertex.Draw_Normal +=DrawTri.Draw_Normal*TriWeight[i];743 D rawDupVertex.Draw_Tangent +=Tri_Draw_Tangent*(Tri.Polarity==DupVertex.Polarity ? TriWeight[i] : -TriWeight[i]);744 D rawDupVertex.Draw_BiNormal+=Tri_Draw_BiNormal*TriWeight[i];744 const MeshT::VertexT& DupVertex =Mesh.Vertices[Vertex.GeoDups[DupNr]]; 745 MeshInfoT::VertexT& DupVertexInfo=MeshInfo.Vertices[Vertex.GeoDups[DupNr]]; 746 747 DupVertexInfo.Normal +=TriInfo.Normal*TriWeight[i]; 748 DupVertexInfo.Tangent +=TriInfo_Draw_Tangent*(Tri.Polarity==DupVertex.Polarity ? TriWeight[i] : -TriWeight[i]); 749 DupVertexInfo.BiNormal+=TriInfo_Draw_BiNormal*TriWeight[i]; 745 750 } 746 751 } … … 749 754 750 755 // Finally normalize the per-vertex tangent-space axes; this is quasi the "division" in the average computations. 751 for (unsigned long MeshNr=0; MeshNr< m_Meshes.Size(); MeshNr++)752 { 753 Mesh T& Mesh=m_Meshes[MeshNr];754 755 for (unsigned long VertexNr=0; VertexNr<Mesh .Vertices.Size(); VertexNr++)756 { 757 Mesh T::VertexT& Vertex=Mesh.Vertices[VertexNr];756 for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 757 { 758 MeshInfoT& MeshInfo=m_MeshInfos[MeshNr]; 759 760 for (unsigned long VertexNr=0; VertexNr<MeshInfo.Vertices.Size(); VertexNr++) 761 { 762 MeshInfoT::VertexT& VertexInfo=MeshInfo.Vertices[VertexNr]; 758 763 759 764 // Normalize the tangent-space axes. 760 Vertex .Draw_Normal =myNormalize(Vertex.Draw_Normal );761 Vertex .Draw_Tangent =myNormalize(Vertex.Draw_Tangent );762 Vertex .Draw_BiNormal=myNormalize(Vertex.Draw_BiNormal);765 VertexInfo.Normal =myNormalize(VertexInfo.Normal ); 766 VertexInfo.Tangent =myNormalize(VertexInfo.Tangent ); 767 VertexInfo.BiNormal=myNormalize(VertexInfo.BiNormal); 763 768 } 764 769 } … … 772 777 // *************************************************************************************************************** 773 778 774 for (unsigned long MeshNr=0; MeshNr< m_Meshes.Size(); MeshNr++)775 { 776 const CafuModelT::MeshT& Mesh =m_Model.GetMeshes()[MeshNr];777 const AnimPoseT::MeshT& DrawMesh=m_Meshes[MeshNr];779 for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 780 { 781 const MeshT& Mesh =Meshes[MeshNr]; 782 const MeshInfoT& MeshInfo=m_MeshInfos[MeshNr]; 778 783 779 784 for (unsigned long TriNr=0; TriNr<Mesh.Triangles.Size(); TriNr++) … … 781 786 for (unsigned long i=0; i<3; i++) 782 787 { 783 unsigned long VertexIdx=Mesh.Triangles[TriNr].VertexIdx[i];784 const Mesh T::VertexT& DrawVertex=DrawMesh.Vertices[VertexIdx];785 786 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetOrigin( DrawVertex.Draw_Pos.x, DrawVertex.Draw_Pos.y, DrawVertex.Draw_Pos.z);788 const unsigned long VertexIdx =Mesh.Triangles[TriNr].VertexIdx[i]; 789 const MeshInfoT::VertexT& VertexInfo=MeshInfo.Vertices[VertexIdx]; 790 791 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetOrigin(VertexInfo.Pos.x, VertexInfo.Pos.y, VertexInfo.Pos.z); 787 792 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetTextureCoord(Mesh.Vertices[VertexIdx].u, Mesh.Vertices[VertexIdx].v); 788 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetNormal ( DrawVertex.Draw_Normal.x, DrawVertex.Draw_Normal.y, DrawVertex.Draw_Normal.z );789 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetTangent ( DrawVertex.Draw_Tangent.x, DrawVertex.Draw_Tangent.y, DrawVertex.Draw_Tangent.z );790 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetBiNormal( DrawVertex.Draw_BiNormal.x, DrawVertex.Draw_BiNormal.y, DrawVertex.Draw_BiNormal.z);793 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetNormal (VertexInfo.Normal.x, VertexInfo.Normal.y, VertexInfo.Normal.z ); 794 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetTangent (VertexInfo.Tangent.x, VertexInfo.Tangent.y, VertexInfo.Tangent.z ); 795 m_Draw_Meshes[MeshNr].Vertices[TriNr*3+i].SetBiNormal(VertexInfo.BiNormal.x, VertexInfo.BiNormal.y, VertexInfo.BiNormal.z); 791 796 } 792 797 } … … 800 805 m_BoundingBox=BoundingBox3fT(); 801 806 802 for (unsigned long MeshNr=0; MeshNr< m_Meshes.Size(); MeshNr++)803 { 804 const Mesh T& DrawMesh=m_Meshes[MeshNr];805 806 for (unsigned long VertexNr=0; VertexNr< DrawMesh.Vertices.Size(); VertexNr++)807 m_BoundingBox+= DrawMesh.Vertices[VertexNr].Draw_Pos;807 for (unsigned long MeshNr=0; MeshNr<Meshes.Size(); MeshNr++) 808 { 809 const MeshInfoT& MeshInfo=m_MeshInfos[MeshNr]; 810 811 for (unsigned long VertexNr=0; VertexNr<MeshInfo.Vertices.Size(); VertexNr++) 812 m_BoundingBox+=MeshInfo.Vertices[VertexNr].Pos; 808 813 } 809 814 } -
cafu/trunk/Libs/Models/AnimPose.hpp
r400 r401 133 133 134 134 /// The instances of this struct parallel and augment the \c CafuModelT::MeshT instances in the related \c CafuModelT. 135 struct Mesh T135 struct MeshInfoT 136 136 { 137 137 struct TriangleT 138 138 { 139 Vector3fT Draw_Normal;///< The normal vector of this triangle, required for the shadow-silhouette determination.139 Vector3fT Normal; ///< The normal vector of this triangle, required for the shadow-silhouette determination. 140 140 }; 141 141 142 142 struct VertexT 143 143 { 144 Vector3fT Draw_Pos;///< The spatial position of this vertex.145 Vector3fT Draw_Normal;///< The tangent-space normal vector of this vertex.146 Vector3fT Draw_Tangent;///< The tangent-space tangent vector of this vertex.147 Vector3fT Draw_BiNormal;///< The tangent-space binormal vector of this vertex.144 Vector3fT Pos; ///< The spatial position of this vertex. 145 Vector3fT Normal; ///< The tangent-space normal vector of this vertex. 146 Vector3fT Tangent; ///< The tangent-space tangent vector of this vertex. 147 Vector3fT BiNormal; ///< The tangent-space binormal vector of this vertex. 148 148 }; 149 149 … … 158 158 void Recache() const; 159 159 160 const CafuModelT& m_Model;161 int m_SequNr; ///< The animation sequence number at which we have computed the cache data.162 float m_FrameNr; ///< The animation frame number at which we have computed the cache data.163 const SuperT* m_Super;164 // ArrayT<...> m_Def; ///< Array of { channel, sequence, framenr, (forceloop), blendweight } tuples.165 // bool m_DoCache; ///< Cache the computed data? (Set to true by the user if he want to re-use this instance.)160 const CafuModelT& m_Model; ///< The related model that this is a pose for. 161 int m_SequNr; ///< The animation sequence number at which we have computed the cache data. 162 float m_FrameNr; ///< The animation frame number at which we have computed the cache data. 163 const SuperT* m_Super; 164 // ArrayT<...> m_Def; ///< Array of { channel, sequence, framenr, (forceloop), blendweight } tuples. 165 // bool m_DoCache; ///< Cache the computed data? (Set to true by the user if he want to re-use this instance.) 166 166 167 167 mutable bool m_NeedsRecache; ///< wird auf 'true' gesetzt wann immer SetSequ(), SetFrameNr() oder AdvanceAll() o.ä. aufgerufen wird, übernimmt m_Draw_CachedDataAt*Nr Funktionalität. 168 168 mutable ArrayT<MatrixT> m_JointMatrices; ///< The transformation matrices that represent the pose of the skeleton at the given animation sequence and frame number. 169 mutable ArrayT<Mesh T> m_Meshes;170 mutable ArrayT<MatSys::MeshT> m_Draw_Meshes; ///< The draw meshes resulting from m_JointMatrices.171 mutable BoundingBox3fT m_BoundingBox; 169 mutable ArrayT<MeshInfoT> m_MeshInfos; ///< Additional data for each mesh in m_Model. 170 mutable ArrayT<MatSys::MeshT> m_Draw_Meshes; ///< The draw meshes resulting from the m_JointMatrices. 171 mutable BoundingBox3fT m_BoundingBox; ///< The bounding-box for the model in this pose. 172 172 }; 173 173
