StaticModel.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. /// Handle attribute write access
  38. virtual void OnSetAttribute(const AttributeInfo& attr, const Variant& value);
  39. /// Handle attribute read access
  40. virtual Variant OnGetAttribute(const AttributeInfo& attr);
  41. /// Process renderer raycast
  42. virtual void ProcessRayQuery(RayOctreeQuery& query, float initialDistance);
  43. /// Prepare geometry for rendering
  44. virtual void UpdateGeometry(const FrameInfo& frame);
  45. /// Return number of batches
  46. virtual unsigned GetNumBatches();
  47. /// Return rendering batch
  48. virtual void GetBatch(const FrameInfo& frame, unsigned batchIndex, Batch& batch);
  49. /// Draw to occlusion buffer
  50. virtual bool DrawOcclusion(OcclusionBuffer* buffer);
  51. /// Set model
  52. void SetModel(Model* model);
  53. /// Set material on all geometries
  54. void SetMaterial(Material* material);
  55. /// Set material on one geometry
  56. bool SetMaterial(unsigned index, Material* material);
  57. /// Set software LOD level, used in raycast and occlusion. By default (M_MAX_UNSIGNED) same as visible
  58. void SetSoftwareLodLevel(unsigned level);
  59. /// Return model
  60. Model* GetModel() const { return model_; }
  61. /// Return model's bounding box
  62. const BoundingBox& GetBoundingBox() const { return boundingBox_; }
  63. /// Return number of geometries
  64. unsigned GetNumGeometries() const { return geometries_.Size(); }
  65. /// Return material by geometry index
  66. Material* GetMaterial(unsigned index) const;
  67. /// Return software LOD level
  68. unsigned GetSoftwareLodLevel() const { return softwareLodLevel_; }
  69. protected:
  70. /// Construct with node flags, initial octant pointer and name
  71. StaticModel(unsigned flags, Octant* octant, const String& name);
  72. /// Update the world bounding box
  73. virtual void OnWorldBoundingBoxUpdate();
  74. /// Set the bounding box
  75. void SetBoundingBox(const BoundingBox& box);
  76. /// Set number of geometries
  77. void SetNumGeometries(unsigned num);
  78. /// Reset LOD levels
  79. void ResetLodLevels();
  80. /// Choose LOD levels based on distance
  81. void CalculateLodLevels();
  82. /// Model
  83. SharedPtr<Model> model_;
  84. /// Bounding box
  85. BoundingBox boundingBox_;
  86. /// Geometries
  87. Vector<Vector<SharedPtr<Geometry> > > geometries_;
  88. /// LOD levels
  89. Vector<unsigned> lodLevels_;
  90. /// Materials
  91. Vector<SharedPtr<Material> > materials_;
  92. /// Software LOD level, used in raycast and occlusion
  93. unsigned softwareLodLevel_;
  94. private:
  95. /// Handle model reload finished
  96. void HandleModelReloadFinished(StringHash eventType, VariantMap& eventData);
  97. };