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.

82 lines
2.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "movieobjects/dmematerial.h"
  7. #include "datamodel/dmelementfactoryhelper.h"
  8. #include "movieobjects_interfaces.h"
  9. #include "materialsystem/imaterial.h"
  10. #include "materialsystem/imaterialsystem.h"
  11. #include "tier2/tier2.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. //-----------------------------------------------------------------------------
  15. // Expose this class to the scene database
  16. //-----------------------------------------------------------------------------
  17. IMPLEMENT_ELEMENT_FACTORY( DmeMaterial, CDmeMaterial );
  18. //-----------------------------------------------------------------------------
  19. // Constructor, destructor
  20. //-----------------------------------------------------------------------------
  21. void CDmeMaterial::OnConstruction()
  22. {
  23. m_pMTL = NULL;
  24. m_mtlName.Init( this, "mtlName" );
  25. }
  26. void CDmeMaterial::OnDestruction()
  27. {
  28. }
  29. //-----------------------------------------------------------------------------
  30. // resolve
  31. //-----------------------------------------------------------------------------
  32. void CDmeMaterial::Resolve()
  33. {
  34. BaseClass::Resolve();
  35. if ( m_mtlName.IsDirty() )
  36. {
  37. m_pMTL = NULL; // no cleanup necessary
  38. }
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Sets the material
  42. //-----------------------------------------------------------------------------
  43. void CDmeMaterial::SetMaterial( const char *pMaterialName )
  44. {
  45. m_mtlName = pMaterialName;
  46. }
  47. //-----------------------------------------------------------------------------
  48. // Returns the material name
  49. //-----------------------------------------------------------------------------
  50. const char *CDmeMaterial::GetMaterialName() const
  51. {
  52. return m_mtlName;
  53. }
  54. //-----------------------------------------------------------------------------
  55. // accessor for cached IMaterial
  56. //-----------------------------------------------------------------------------
  57. IMaterial *CDmeMaterial::GetCachedMTL()
  58. {
  59. if ( m_pMTL == NULL )
  60. {
  61. const char *mtlName = m_mtlName.Get();
  62. if ( mtlName == NULL )
  63. return NULL;
  64. m_pMTL = g_pMaterialSystem->FindMaterial( mtlName, NULL, false );
  65. }
  66. return m_pMTL;
  67. }