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.

88 lines
2.5 KiB

  1. //====== Copyright � 1996-2004, 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. #include "datamodel/dmattributevar.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. //-----------------------------------------------------------------------------
  16. // Expose this class to the scene database
  17. //-----------------------------------------------------------------------------
  18. IMPLEMENT_ELEMENT_FACTORY( DmeMaterial, CDmeMaterial );
  19. //-----------------------------------------------------------------------------
  20. // Constructor, destructor
  21. //-----------------------------------------------------------------------------
  22. void CDmeMaterial::OnConstruction()
  23. {
  24. m_mtlName.Init( this, "mtlName" );
  25. }
  26. //-----------------------------------------------------------------------------
  27. //
  28. //-----------------------------------------------------------------------------
  29. void CDmeMaterial::OnDestruction()
  30. {
  31. }
  32. //-----------------------------------------------------------------------------
  33. // resolve
  34. //-----------------------------------------------------------------------------
  35. void CDmeMaterial::Resolve()
  36. {
  37. BaseClass::Resolve();
  38. if ( m_mtlName.IsDirty() )
  39. {
  40. m_mtlRef.Shutdown();
  41. }
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Sets the material
  45. //-----------------------------------------------------------------------------
  46. void CDmeMaterial::SetMaterial( const char *pMaterialName )
  47. {
  48. m_mtlName = pMaterialName;
  49. }
  50. //-----------------------------------------------------------------------------
  51. // Returns the material name
  52. //-----------------------------------------------------------------------------
  53. const char *CDmeMaterial::GetMaterialName() const
  54. {
  55. return m_mtlName;
  56. }
  57. //-----------------------------------------------------------------------------
  58. // accessor for cached IMaterial
  59. //-----------------------------------------------------------------------------
  60. IMaterial *CDmeMaterial::GetCachedMTL()
  61. {
  62. if ( !m_mtlRef.IsValid() )
  63. {
  64. const char *mtlName = m_mtlName.Get();
  65. if ( mtlName == NULL )
  66. return NULL;
  67. m_mtlRef.Init( g_pMaterialSystem->FindMaterial( mtlName, NULL, false ) );
  68. }
  69. return (IMaterial * )m_mtlRef;
  70. }