Lugdunum  0.1.0
Node.cpp
Go to the documentation of this file.
4 
5 namespace lug {
6 namespace Graphics {
7 namespace Scene {
8 
9 Node::Node(Scene& scene, const std::string& name) : ::lug::Graphics::Node(name), _scene(scene) {}
10 
11 Node* Node::createSceneNode(const std::string& name) {
12  return _scene.createSceneNode(name);
13 }
14 
16  _light = light;
17 }
18 
20  _meshInstance.mesh = mesh;
21 
22  const auto& primitiveSets = mesh->getPrimitiveSets();
23  if (material) {
24  _meshInstance.materials.resize(primitiveSets.size(), material);
25  } else {
26  _meshInstance.materials.resize(primitiveSets.size());
27  for (uint32_t i = 0; i < primitiveSets.size(); ++i) {
28  _meshInstance.materials[i] = primitiveSets[i].material;
29  }
30  }
31 }
32 
34  camera->setParent(this);
35  _camera = std::move(camera);
36 }
37 
38 void Node::fetchVisibleObjects(const Renderer& renderer, const Render::View& renderView, const Render::Camera::Camera& camera, Render::Queue& renderQueue) const {
39  for (const auto& child : _children) {
40  static_cast<const Node*>(child)->fetchVisibleObjects(renderer, renderView, camera, renderQueue);
41  }
42 
43  if (_meshInstance.mesh) {
44  renderQueue.addMeshInstance(*const_cast<Node*>(this), renderer);
45  }
46 
47  // Check the distance with the light
48  if (_light && (_light->getDistance() == 0.0f || _light->getDistance() >= fabs((Math::Vec3f(const_cast<Node*>(this)->getAbsolutePosition() - camera.getParent()->getAbsolutePosition())).length()))) {
49  renderQueue.addLight(*const_cast<Node*>(this));
50  }
51 }
52 
56 
57  if (_camera) {
58  _camera->needUpdateView();
59  }
60 }
61 
62 } // Scene
63 } // Graphics
64 } // lug
virtual void addLight(Scene::Node &node)=0
std::vector< Node * > _children
Definition: Node.hpp:87
virtual void addMeshInstance(Scene::Node &node, const Renderer &renderer)=0
std::vector< Resource::SharedPtr< Render::Material > > materials
Definition: Node.hpp:33
Scene::Node * getParent() const
Definition: Camera.inl:24
virtual void needUpdate() override
Definition: Node.cpp:53
void attachCamera(Resource::SharedPtr< Render::Camera::Camera > camera)
Definition: Node.cpp:33
const Math::Vec3f & getAbsolutePosition()
Definition: Node.inl:14
void attachLight(Resource::SharedPtr< Render::Light > light)
Definition: Node.cpp:15
Dummy class for a shared pointer.
Definition: Resource.hpp:66
void attachMeshInstance(Resource::SharedPtr< Render::Mesh > mesh, Resource::SharedPtr< Render::Material > material=nullptr)
Definition: Node.cpp:19
Node * createSceneNode(const std::string &name)
Definition: Scene.cpp:11
Resource::SharedPtr< Render::Light > _light
Definition: Node.hpp:73
Node * createSceneNode(const std::string &name)
Definition: Node.cpp:11
void fetchVisibleObjects(const Renderer &renderer, const Render::View &renderView, const Render::Camera::Camera &camera, Render::Queue &renderQueue) const
Definition: Node.cpp:38
Resource::SharedPtr< Render::Camera::Camera > _camera
Definition: Node.hpp:75
Node(Scene &scene, const std::string &name)
Definition: Node.cpp:9
Class for graphics.
Definition: Graphics.hpp:25
MeshInstance _meshInstance
Definition: Node.hpp:74
virtual void needUpdate()
Definition: Node.cpp:168
Resource::SharedPtr< Render::Mesh > mesh
Definition: Node.hpp:32