LMStaticModel.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "Precompiled.h"
  5. #include "../Core/Context.h"
  6. #include "../Resource/ResourceCache.h"
  7. #include "../Graphics/Technique.h"
  8. #include "LMStaticModel.h"
  9. #ifdef __DISABLED
  10. namespace Atomic
  11. {
  12. extern const char* GEOMETRY_CATEGORY;
  13. LMStaticModel::LMStaticModel(Context* context) :
  14. StaticModel(context),
  15. lightmapTilingOffset_(1.0f, 1.0f, 0.0f, 0.0f)
  16. {
  17. }
  18. LMStaticModel::~LMStaticModel()
  19. {
  20. }
  21. void LMStaticModel::RegisterObject(Context* context)
  22. {
  23. context->RegisterFactory<LMStaticModel>(GEOMETRY_CATEGORY);
  24. ATOMIC_COPY_BASE_ATTRIBUTES(StaticModel);
  25. ATOMIC_ATTRIBUTE("Lightmap Tiling Offset", Vector4, lightmapTilingOffset_ , Vector4(1.0f, 1.0f, 0.0f, 0.0f), AM_DEFAULT);
  26. ATOMIC_MIXED_ACCESSOR_ATTRIBUTE("LightmapTexture", GetLightmapTextureAttr, SetLightmapTextureAttr, ResourceRef, ResourceRef(Texture2D::GetTypeStatic()), AM_DEFAULT);
  27. }
  28. void LMStaticModel::SetLightmapTextureAttr(const ResourceRef& value)
  29. {
  30. ResourceCache* cache = GetSubsystem<ResourceCache>();
  31. if (value.name_.Length())
  32. {
  33. lightmapTexture_ = cache->GetResource<Texture2D>(value.name_);
  34. }
  35. else
  36. {
  37. lightmapTexture_ = NULL;
  38. }
  39. // TODO: This is making a separate material for each model
  40. // we should be able to factor this into batching
  41. if (lightmapTexture_.NotNull() && lightmapMaterial_.Null())
  42. {
  43. Material* base = GetMaterial(0);
  44. if (base)
  45. {
  46. ResourceCache* cache = GetSubsystem<ResourceCache>();
  47. lightmapMaterial_ = base->Clone();
  48. Technique* technique = cache->GetResource<Technique>("Techniques/DiffLightMap.xml");
  49. lightmapMaterial_->SetTechnique(0, technique);
  50. lightmapMaterial_->SetTexture(TU_EMISSIVE, lightmapTexture_);
  51. }
  52. }
  53. }
  54. ResourceRef LMStaticModel::GetLightmapTextureAttr() const
  55. {
  56. return GetResourceRef(lightmapTexture_, Texture2D::GetTypeStatic());
  57. }
  58. void LMStaticModel::UpdateBatches(const FrameInfo& frame)
  59. {
  60. /*
  61. StaticModel::UpdateBatches(frame);
  62. if (batches_.Size() > 1)
  63. {
  64. for (unsigned i = 0; i < batches_.Size(); ++i)
  65. {
  66. batches_[i].lightmapTilingOffset_ = &lightmapTilingOffset_;
  67. batches_[i].geometryType_ = GEOM_STATIC_NOINSTANCING;
  68. if (!lightmapMaterial_.Null())
  69. batches_[i].material_ = lightmapMaterial_;
  70. }
  71. }
  72. else if (batches_.Size() == 1)
  73. {
  74. batches_[0].lightmapTilingOffset_ = &lightmapTilingOffset_;
  75. batches_[0].geometryType_ = GEOM_STATIC_NOINSTANCING;
  76. if (!lightmapMaterial_.Null())
  77. batches_[0].material_ = lightmapMaterial_;
  78. }
  79. */
  80. }
  81. }
  82. #endif