StaticModel.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. //! Return resource references
  49. virtual void getResourceRefs(std::vector<Resource*>& dest);
  50. //! Process renderer raycast
  51. virtual void processRayQuery(RayOctreeQuery& query, float initialDistance);
  52. //! Prepare geometry for rendering
  53. virtual void updateGeometry(const FrameInfo& frame, Renderer* renderer);
  54. //! Return number of batches
  55. virtual unsigned getNumBatches();
  56. //! Return geometry by batch index
  57. virtual Geometry* getBatchGeometry(unsigned batchIndex);
  58. //! Return material by batch index
  59. virtual Material* getBatchMaterial(unsigned batchIndex);
  60. //! Draw to occlusion buffer
  61. virtual bool drawOcclusion(OcclusionBuffer* buffer);
  62. //! Set model
  63. void setModel(Model* model);
  64. //! Set material on all geometries
  65. void setMaterial(Material* material);
  66. //! Set material on one geometry
  67. bool setMaterial(unsigned index, Material* material);
  68. //! Return model's bounding box
  69. const BoundingBox& getBoundingBox() const { return mBoundingBox; }
  70. //! Return number of geometries
  71. unsigned getNumGeometries() const { return mGeometries.size(); }
  72. //! Return material by geometry index
  73. Material* getMaterial(unsigned index) const;
  74. //! Return model
  75. Model* getModel() const { return mModel; }
  76. protected:
  77. //! Construct with node flags, initial octant pointer and name
  78. StaticModel(unsigned flags, Octant* octant, const std::string& name);
  79. //! Update the world bounding box
  80. virtual void onWorldBoundingBoxUpdate(BoundingBox& worldBoundingBox);
  81. //! Set the bounding box
  82. void setBoundingBox(const BoundingBox& box);
  83. //! Set number of geometries
  84. void setNumGeometries(unsigned num);
  85. //! Reset LOD levels
  86. void resetLodLevels();
  87. //! Choose LOD levels based on distance
  88. void calculateLodLevels();
  89. //! Geometries
  90. std::vector<std::vector<SharedPtr<Geometry> > > mGeometries;
  91. //! Materials
  92. std::vector<SharedPtr<Material> > mMaterials;
  93. //! LOD levels
  94. std::vector<unsigned> mLodLevels;
  95. //! Bounding box
  96. BoundingBox mBoundingBox;
  97. //! Model
  98. SharedPtr<Model> mModel;
  99. };
  100. #endif // RENDERER_STATICMODEL_H