StaticModel.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #ifndef RENDERER_STATICMODEL_H
  24. #define RENDERER_STATICMODEL_H
  25. #include "GeometryNode.h"
  26. class Model;
  27. //! A static model scene node
  28. class StaticModel : public GeometryNode
  29. {
  30. DEFINE_TYPE(StaticModel);
  31. public:
  32. //! Construct with initial octant pointer and name
  33. StaticModel(Octant* octant = 0, const std::string& name = std::string());
  34. //! Destruct
  35. ~StaticModel();
  36. //! Write component state to a stream
  37. virtual void save(Serializer& dest);
  38. //! Read component state from a stream
  39. virtual void load(Deserializer& source, ResourceCache* cache);
  40. //! Write component state to an XML element
  41. virtual void saveXML(XMLElement& dest);
  42. //! Read component state from an XML element
  43. virtual void loadXML(const XMLElement& source, ResourceCache* cache);
  44. //! Write a network update
  45. virtual bool writeNetUpdate(Serializer& dest, Serializer& destRevision, Deserializer& baseRevision, const NetUpdateInfo& info);
  46. //! Read a network update
  47. virtual void readNetUpdate(Deserializer& source, ResourceCache* cache, const NetUpdateInfo& info);
  48. //! Process renderer raycast
  49. virtual void processRayQuery(RayOctreeQuery& query, float initialDistance);
  50. //! Prepare geometry for rendering
  51. virtual void updateGeometry(const FrameInfo& frame, Renderer* renderer);
  52. //! Return number of batches
  53. virtual unsigned getNumBatches();
  54. //! Return geometry by batch index
  55. virtual Geometry* getBatchGeometry(unsigned batchIndex);
  56. //! Return material by batch index
  57. virtual Material* getBatchMaterial(unsigned batchIndex);
  58. //! Draw to occlusion buffer
  59. virtual bool drawOcclusion(OcclusionBuffer* buffer);
  60. //! Set model
  61. void setModel(Model* model);
  62. //! Set material on all geometries
  63. void setMaterial(Material* material);
  64. //! Set material on one geometry
  65. bool setMaterial(unsigned index, Material* material);
  66. //! Return model's bounding box
  67. const BoundingBox& getBoundingBox() const { return mBoundingBox; }
  68. //! Return number of geometries
  69. unsigned getNumGeometries() const { return mGeometries.size(); }
  70. //! Return material by geometry index
  71. Material* getMaterial(unsigned index) const;
  72. //! Return model
  73. Model* getModel() const { return mModel; }
  74. protected:
  75. //! Construct with node flags, initial octant pointer and name
  76. StaticModel(unsigned flags, Octant* octant, const std::string& name);
  77. //! Update the world bounding box
  78. virtual void onWorldBoundingBoxUpdate(BoundingBox& worldBoundingBox);
  79. //! Set the bounding box
  80. void setBoundingBox(const BoundingBox& box);
  81. //! Set number of geometries
  82. void setNumGeometries(unsigned num);
  83. //! Reset LOD levels
  84. void resetLodLevels();
  85. //! Choose LOD levels based on distance
  86. void calculateLodLevels();
  87. //! Geometries
  88. std::vector<std::vector<SharedPtr<Geometry> > > mGeometries;
  89. //! Materials
  90. std::vector<SharedPtr<Material> > mMaterials;
  91. //! LOD levels
  92. std::vector<unsigned> mLodLevels;
  93. //! Bounding box
  94. BoundingBox mBoundingBox;
  95. //! Model
  96. SharedPtr<Model> mModel;
  97. };
  98. #endif // RENDERER_STATICMODEL_H