StaticModelGroup.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // Copyright (c) 2008-2013 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "StaticModel.h"
  24. namespace Urho3D
  25. {
  26. /// Renders several instances of static models while culling and receiving light as one unit. Using this class is not necessary for instanced rendering, but can be used as a CPU-side optimization.
  27. class URHO3D_API StaticModelGroup : public StaticModel
  28. {
  29. OBJECT(StaticModelGroup);
  30. public:
  31. /// Construct.
  32. StaticModelGroup(Context* context);
  33. /// Destruct.
  34. virtual ~StaticModelGroup();
  35. /// Register object factory. StaticModel must be registered first.
  36. static void RegisterObject(Context* context);
  37. /// Process octree raycast. May be called from a worker thread.
  38. //virtual void ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results);
  39. /// Calculate distance and prepare batches for rendering. May be called from worker thread(s), possibly re-entrantly.
  40. virtual void UpdateBatches(const FrameInfo& frame);
  41. /// Return number of occlusion geometry triangles.
  42. //virtual unsigned GetNumOccluderTriangles();
  43. /// Draw to occlusion buffer. Return true if did not run out of triangles.
  44. //virtual bool DrawOcclusion(OcclusionBuffer* buffer);
  45. /// Add an instance scene node. It does not need any drawable components of its own.
  46. void AddInstanceNode(Node* node);
  47. /// Remove an instance scene node.
  48. void RemoveInstanceNode(Node* node);
  49. /// Return number of instance nodes.
  50. unsigned GetNumInstanceNodes() const { return instanceNodes_.Size(); }
  51. /// Return instance node by index.
  52. Node* GetInstanceNode(unsigned index) const;
  53. protected:
  54. /// Handle node transform being dirtied.
  55. virtual void OnMarkedDirty(Node* node);
  56. /// Handle scene node enabled status changing.
  57. virtual void OnNodeSetEnabled(Node* node);
  58. /// Recalculate the world-space bounding box.
  59. virtual void OnWorldBoundingBoxUpdate();
  60. private:
  61. /// Gather the instances' transforms.
  62. void UpdateTransforms();
  63. /// Instance nodes.
  64. Vector<WeakPtr<Node> > instanceNodes_;
  65. /// World transforms of enabled instances.
  66. PODVector<Matrix3x4> worldTransforms_;
  67. /// Instance transforms dirty flag.
  68. bool transformsDirty_;
  69. };
  70. }