StaticModel.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "Drawable.h"
  25. class Model;
  26. /// Static model component
  27. class StaticModel : public Drawable
  28. {
  29. OBJECT(StaticModel);
  30. public:
  31. /// Construct
  32. StaticModel(Context* context);
  33. /// Destruct
  34. ~StaticModel();
  35. /// Register object factory
  36. static void RegisterObject(Context* context);
  37. /// Process renderer raycast
  38. virtual void ProcessRayQuery(RayOctreeQuery& query, float initialDistance);
  39. /// Prepare geometry for rendering
  40. virtual void UpdateGeometry(const FrameInfo& frame);
  41. /// Return number of batches
  42. virtual unsigned GetNumBatches();
  43. /// Return rendering batch
  44. virtual void GetBatch(const FrameInfo& frame, unsigned batchIndex, Batch& batch);
  45. /// Draw to occlusion buffer
  46. virtual bool DrawOcclusion(OcclusionBuffer* buffer);
  47. /// Set model
  48. void SetModel(Model* model);
  49. /// Set material on all geometries
  50. void SetMaterial(Material* material);
  51. /// Set material on one geometry
  52. bool SetMaterial(unsigned index, Material* material);
  53. /// Set software LOD level, used in raycast and occlusion. By default (M_MAX_UNSIGNED) same as visible
  54. void SetSoftwareLodLevel(unsigned level);
  55. /// Return model
  56. Model* GetModel() const { return model_; }
  57. /// Return model's bounding box
  58. const BoundingBox& GetBoundingBox() const { return boundingBox_; }
  59. /// Return number of geometries
  60. unsigned GetNumGeometries() const { return geometries_.Size(); }
  61. /// Return material by geometry index
  62. Material* GetMaterial(unsigned index) const;
  63. /// Return software LOD level
  64. unsigned GetSoftwareLodLevel() const { return softwareLodLevel_; }
  65. /// Set model attribute
  66. void SetModelAttr(ResourceRef value);
  67. /// Set materials attribute
  68. void SetMaterialsAttr(ResourceRefList value);
  69. /// Return model attribute
  70. ResourceRef GetModelAttr() const;
  71. /// Return materials attribute
  72. ResourceRefList GetMaterialsAttr() const;
  73. protected:
  74. /// Update the world bounding box
  75. virtual void OnWorldBoundingBoxUpdate();
  76. /// Set the bounding box
  77. void SetBoundingBox(const BoundingBox& box);
  78. /// Set number of geometries
  79. void SetNumGeometries(unsigned num);
  80. /// Reset LOD levels
  81. void ResetLodLevels();
  82. /// Choose LOD levels based on distance
  83. void CalculateLodLevels();
  84. /// Model
  85. SharedPtr<Model> model_;
  86. /// Bounding box
  87. BoundingBox boundingBox_;
  88. /// Geometries
  89. Vector<Vector<SharedPtr<Geometry> > > geometries_;
  90. /// LOD levels
  91. PODVector<unsigned> lodLevels_;
  92. /// Materials
  93. Vector<SharedPtr<Material> > materials_;
  94. /// Software LOD level, used in raycast and occlusion
  95. unsigned softwareLodLevel_;
  96. private:
  97. /// Handle model reload finished
  98. void HandleModelReloadFinished(StringHash eventType, VariantMap& eventData);
  99. };