Counter Strike : Global Offensive Source Code
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.

122 lines
4.1 KiB

  1. //====== Copyright � 1996-2004, 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. // Statics
  15. //-----------------------------------------------------------------------------
  16. IMaterial *CDmeAttachment::sm_pMatAttachment = NULL;
  17. //-----------------------------------------------------------------------------
  18. // Expose this class to the scene database
  19. //-----------------------------------------------------------------------------
  20. IMPLEMENT_ELEMENT_FACTORY( DmeAttachment, CDmeAttachment );
  21. //-----------------------------------------------------------------------------
  22. // Purpose:
  23. //-----------------------------------------------------------------------------
  24. void CDmeAttachment::OnConstruction()
  25. {
  26. m_bIsRigid.Init( this, "isRigid" );
  27. m_bIsWorldAligned.Init( this, "isWorldAligned" );
  28. if ( !g_pMaterialSystem )
  29. return;
  30. if ( !sm_pMatAttachment )
  31. {
  32. KeyValues *pVMTKeyValues = new KeyValues( "wireframe" );
  33. pVMTKeyValues->SetInt( "$vertexcolor", 1 );
  34. pVMTKeyValues->SetInt( "$ignorez", 0 );
  35. sm_pMatAttachment = g_pMaterialSystem->CreateMaterial( "__DmeAttachment", pVMTKeyValues );
  36. if ( sm_pMatAttachment )
  37. {
  38. m_MatRefAttachment.Init( sm_pMatAttachment );
  39. sm_pMatAttachment->DecrementReferenceCount(); // CreateMaterial adds a ref, just want the CMaterialReference's
  40. // Cache material now to avoid an unwanted implicit Ref that occurs on first use which is never cleared
  41. g_pMaterialSystem->CacheUsedMaterials();
  42. }
  43. }
  44. else
  45. {
  46. m_MatRefAttachment.Init( sm_pMatAttachment );
  47. }
  48. }
  49. //-----------------------------------------------------------------------------
  50. //
  51. //-----------------------------------------------------------------------------
  52. void CDmeAttachment::OnDestruction()
  53. {
  54. }
  55. //-----------------------------------------------------------------------------
  56. // For rendering joints
  57. //-----------------------------------------------------------------------------
  58. #define AXIS_SIZE 6.0f
  59. //-----------------------------------------------------------------------------
  60. // Rendering method for the dag
  61. //-----------------------------------------------------------------------------
  62. void CDmeAttachment::Draw( const matrix3x4_t &shapeToWorld, CDmeDrawSettings *pDrawSettings /* = NULL */ )
  63. {
  64. if ( !g_pMaterialSystem )
  65. return;
  66. CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
  67. pRenderContext->MatrixMode( MATERIAL_MODEL );
  68. pRenderContext->PushMatrix();
  69. pRenderContext->LoadMatrix( shapeToWorld );
  70. pRenderContext->Bind( sm_pMatAttachment );
  71. IMesh *pMesh = pRenderContext->GetDynamicMesh();
  72. CMeshBuilder meshBuilder;
  73. meshBuilder.Begin( pMesh, MATERIAL_LINES, 3 );
  74. meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
  75. meshBuilder.Color4ub( 255, 0, 0, 255 );
  76. meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
  77. meshBuilder.Position3f( AXIS_SIZE, 0.0f, 0.0f );
  78. meshBuilder.Color4ub( 255, 0, 0, 255 );
  79. meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
  80. meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
  81. meshBuilder.Color4ub( 0, 255, 0, 255 );
  82. meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
  83. meshBuilder.Position3f( 0.0f, AXIS_SIZE, 0.0f );
  84. meshBuilder.Color4ub( 0, 255, 0, 255 );
  85. meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
  86. meshBuilder.Position3f( 0.0f, 0.0f, 0.0f );
  87. meshBuilder.Color4ub( 0, 0, 255, 255 );
  88. meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
  89. meshBuilder.Position3f( 0.0f, 0.0f, AXIS_SIZE );
  90. meshBuilder.Color4ub( 0, 0, 255, 255 );
  91. meshBuilder.AdvanceVertexF<VTX_HAVEPOS | VTX_HAVECOLOR, 0>();
  92. meshBuilder.End();
  93. pMesh->Draw();
  94. pRenderContext->MatrixMode( MATERIAL_MODEL );
  95. pRenderContext->PopMatrix();
  96. }