Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Dme version of a model attachment point
  4. //
  5. //=============================================================================
  6. #include "movieobjects/dmeattachment.h"
  7. #include "datamodel/dmelementfactoryhelper.h"
  8. #include "materialsystem/imaterialsystem.h"
  9. #include "materialsystem/imesh.h"
  10. #include "tier1/KeyValues.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. //-----------------------------------------------------------------------------
  14. // Expose this class to the scene database
  15. //-----------------------------------------------------------------------------
  16. IMPLEMENT_ELEMENT_FACTORY( DmeAttachment, CDmeAttachment );
  17. //-----------------------------------------------------------------------------
  18. // Purpose:
  19. //-----------------------------------------------------------------------------
  20. void CDmeAttachment::OnConstruction()
  21. {
  22. if ( !g_pMaterialSystem )
  23. return;
  24. m_bIsRigid.Init( this, "isRigid" );
  25. m_bIsWorldAligned.Init( this, "isWorldAligned" );
  26. KeyValues *pVMTKeyValues = new KeyValues( "wireframe" );
  27. pVMTKeyValues->SetInt( "$vertexcolor", 1 );
  28. pVMTKeyValues->SetInt( "$ignorez", 0 );
  29. m_AttachmentMaterial.Init( "__DmeJointMaterial", pVMTKeyValues );
  30. }
  31. void CDmeAttachment::OnDestruction()
  32. {
  33. if ( !g_pMaterialSystem )
  34. return;
  35. m_AttachmentMaterial.Shutdown();
  36. }
  37. //-----------------------------------------------------------------------------
  38. // For rendering joints
  39. //-----------------------------------------------------------------------------
  40. #define AXIS_SIZE 6.0f
  41. //-----------------------------------------------------------------------------
  42. // Rendering method for the dag
  43. //-----------------------------------------------------------------------------
  44. void CDmeAttachment::Draw( const matrix3x4_t &shapeToWorld, CDmeDrawSettings *pDrawSettings /* = NULL */ )
  45. {
  46. if ( !g_pMaterialSystem )
  47. return;
  48. CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
  49. pRenderContext->MatrixMode( MATERIAL_MODEL );
  50. pRenderContext->PushMatrix();
  51. pRenderContext->LoadMatrix( shapeToWorld );
  52. pRenderContext->Bind( m_AttachmentMaterial );
  53. IMesh *pMesh = pRenderContext->GetDynamicMesh( );
  54. CMeshBuilder meshBuilder;
  55. meshBuilder.Begin( pMesh, MATERIAL_LINES, 3 );
  56. meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
  57. meshBuilder.Color4ub( 255, 0, 0, 255 );
  58. meshBuilder.AdvanceVertex();
  59. meshBuilder.Position3f( AXIS_SIZE, 0.0f, 0.0f );
  60. meshBuilder.Color4ub( 255, 0, 0, 255 );
  61. meshBuilder.AdvanceVertex();
  62. meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
  63. meshBuilder.Color4ub( 0, 255, 0, 255 );
  64. meshBuilder.AdvanceVertex();
  65. meshBuilder.Position3f( 0.0f, AXIS_SIZE, 0.0f );
  66. meshBuilder.Color4ub( 0, 255, 0, 255 );
  67. meshBuilder.AdvanceVertex();
  68. meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
  69. meshBuilder.Color4ub( 0, 0, 255, 255 );
  70. meshBuilder.AdvanceVertex();
  71. meshBuilder.Position3f( 0.0f, 0.0f, AXIS_SIZE );
  72. meshBuilder.Color4ub( 0, 0, 255, 255 );
  73. meshBuilder.AdvanceVertex();
  74. meshBuilder.End();
  75. pMesh->Draw();
  76. pRenderContext->MatrixMode( MATERIAL_MODEL );
  77. pRenderContext->PopMatrix();
  78. }