Saga3D API Documentation  1.0-RC4
IMeshSceneNode.h
Go to the documentation of this file.
1 #ifndef __I_MESH_SCENE_NODE_H_INCLUDED__
2 #define __I_MESH_SCENE_NODE_H_INCLUDED__
3 
4 #include "ISceneNode.h"
5 #include "IMesh.h"
6 #include "ISceneManager.h"
7 #include "IMeshBuffer.h"
8 #include "IVideoDriver.h"
9 
10 namespace saga
11 {
12 namespace scene
13 {
14 
15 class IMesh;
16 
18 class IMeshSceneNode : public ISceneNode
19 {
20 public:
21 
23 
26  const std::shared_ptr<IMesh>& mesh,
27  const std::shared_ptr<ISceneNode>& parent,
28  const std::shared_ptr<ISceneManager>& mgr,
29  const glm::vec3& position = glm::vec3(0,0,0),
30  const glm::vec3& rotation = glm::vec3(0,0,0),
31  const glm::vec3& scale = glm::vec3(1,1,1))
32  : ISceneNode(parent, mgr, position, rotation, scale),
33  Mesh(mesh) {}
34 
36  {
37  SceneManager->getVideoDriver()->destroyPipelineBuffer(*this, true);
38  }
39 
40  virtual void setPipeline(video::PipelineHandle pipeline) override
41  {
42  ISceneNode::setPipeline(pipeline);
43  auto& driver = SceneManager->getVideoDriver();
44 
45  if (driver->hasPipelineBuffer(*this, pipeline)) return;
46 
47  auto& mesh = getMesh();
48  auto& meshBuffer = mesh->getMeshBuffer();
49  meshBuffer.buildBuffer(*driver, pipeline);
50  driver->createPipelineBuffer(*this, pipeline);
51  }
52 
53  virtual void onRegisterSceneNode(video::RenderPassHandle pass) override
54  {
55  if (IsVisible)
56  {
57  SceneManager->getNodeList()[pass].push_back(shared_from_this());
59  }
60  }
61 
62  virtual void onUnregisterSceneNode(video::RenderPassHandle pass) override
63  {
64  auto& nodeList = SceneManager->getNodeList(pass);
65  for (auto nodeIt = nodeList.begin(); nodeIt != nodeList.end(); ++nodeIt) {
66  if ((*nodeIt)->getID() == getID()) {
67  nodeList.erase(nodeIt);
68  break;
69  }
70  }
72  }
73 
75  virtual const core::aabbox3d<float>& getBoundingBox() const override
76  { return Mesh ? Mesh->getBoundingBox() : Box; }
77 
83  // virtual video::SMaterial& getMaterial(std::uint32_t i) override;
84 
86  virtual E_SCENE_NODE_TYPE getType() const override { return E_SCENE_NODE_TYPE::MESH; }
87 
89  virtual void setMesh(const std::shared_ptr<IMesh>& mesh) { Mesh = mesh; }
90 
92  virtual const std::shared_ptr<IMesh>& getMesh() const { return Mesh; }
93 
94 protected:
95  std::shared_ptr<IMesh> Mesh = nullptr;
97 };
98 
99 } // namespace scene
100 } // namespace saga
101 
102 
103 #endif
104 
saga::scene::IMeshSceneNode::getBoundingBox
virtual const core::aabbox3d< float > & getBoundingBox() const override
returns the axis aligned bounding box of this node
Definition: IMeshSceneNode.h:75
saga::scene::ISceneNode
Type for list of scene node animators.
Definition: ISceneNode.h:41
saga::scene::IMeshSceneNode
A scene node displaying a static mesh.
Definition: IMeshSceneNode.h:18
saga::video::PipelineHandle
SGPUResource::HandleType PipelineHandle
Definition: SPipeline.h:27
saga::scene::E_SCENE_NODE_TYPE
E_SCENE_NODE_TYPE
An enumeration for all types of built-in scene nodes.
Definition: ESceneNodeTypes.h:17
IVideoDriver.h
saga::scene::IMeshSceneNode::IMeshSceneNode
IMeshSceneNode(const std::shared_ptr< IMesh > &mesh, const std::shared_ptr< ISceneNode > &parent, const std::shared_ptr< ISceneManager > &mgr, const glm::vec3 &position=glm::vec3(0, 0, 0), const glm::vec3 &rotation=glm::vec3(0, 0, 0), const glm::vec3 &scale=glm::vec3(1, 1, 1))
Constructor.
Definition: IMeshSceneNode.h:25
saga::scene::IMeshSceneNode::getMesh
virtual const std::shared_ptr< IMesh > & getMesh() const
Returns the current mesh.
Definition: IMeshSceneNode.h:92
saga::scene::E_SCENE_NODE_TYPE::MESH
@ MESH
Mesh Scene Node.
saga::scene::ISceneNode::IsVisible
bool IsVisible
Is the node visible?
Definition: ISceneNode.h:636
ISceneNode.h
saga::scene::IMeshSceneNode::setMesh
virtual void setMesh(const std::shared_ptr< IMesh > &mesh)
Sets a new mesh.
Definition: IMeshSceneNode.h:89
saga::scene::IMeshSceneNode::onRegisterSceneNode
virtual void onRegisterSceneNode(video::RenderPassHandle pass) override
This method is called just before the rendering process of the whole scene.
Definition: IMeshSceneNode.h:53
saga::scene::IMeshSceneNode::getType
virtual E_SCENE_NODE_TYPE getType() const override
Returns type of the scene node.
Definition: IMeshSceneNode.h:86
saga::scene::IMeshSceneNode::Box
core::aabbox3d< float > Box
Definition: IMeshSceneNode.h:96
saga::scene::IMeshSceneNode::~IMeshSceneNode
~IMeshSceneNode()
Definition: IMeshSceneNode.h:35
saga::core::aabbox3d< float >
saga::scene::ISceneNode::onRegisterSceneNode
virtual void onRegisterSceneNode(video::RenderPassHandle pass)
This method is called just before the rendering process of the whole scene.
Definition: ISceneNode.h:96
saga::scene::ISceneNode::onUnregisterSceneNode
virtual void onUnregisterSceneNode(video::RenderPassHandle pass)
Definition: ISceneNode.h:106
saga::scene::ISceneNode::setPipeline
virtual void setPipeline(video::PipelineHandle pipeline)
Definition: ISceneNode.h:132
saga::scene::ISceneNode::SceneManager
std::shared_ptr< ISceneManager > SceneManager
Pointer to the scene manager.
Definition: ISceneNode.h:622
IMeshBuffer.h
saga::scene::IMeshSceneNode::onUnregisterSceneNode
virtual void onUnregisterSceneNode(video::RenderPassHandle pass) override
Definition: IMeshSceneNode.h:62
saga::video::RenderPassHandle
SGPUResource::HandleType RenderPassHandle
Definition: SRenderPass.h:27
saga::scene::IMeshSceneNode::setPipeline
virtual void setPipeline(video::PipelineHandle pipeline) override
Definition: IMeshSceneNode.h:40
IMesh.h
ISceneManager.h
saga::scene::IMeshSceneNode::Mesh
std::shared_ptr< IMesh > Mesh
Definition: IMeshSceneNode.h:95
saga
Definition: aabbox3d.h:11
saga::scene::ISceneNode::getID
const auto getID() const
Definition: ISceneNode.h:82