Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpPanda3DLight.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 */
30
31#ifndef VP_PANDA3D_LIGHT_H
32#define VP_PANDA3D_LIGHT_H
33
34#include <visp3/core/vpConfig.h>
35
36#if defined(VISP_HAVE_PANDA3D)
37
38#include <string>
39#include <visp3/core/vpPoint.h>
40#include <visp3/core/vpRGBf.h>
41#include <visp3/ar/vpPanda3DBaseRenderer.h>
42
43#include "nodePath.h"
44#include "ambientLight.h"
45#include "directionalLight.h"
46#include "pointLight.h"
47#include "directionalLight.h"
48
68class VISP_EXPORT vpPanda3DLight
69{
70public:
78 vpPanda3DLight(const std::string &name, const vpRGBf &color) : m_name(name), m_color(color) { }
79
80 virtual ~vpPanda3DLight() = default;
81
87 const std::string &getName() const { return m_name; }
93 const vpRGBf &getColor() const { return m_color; }
94
100 virtual void addToScene(NodePath &scene) const = 0;
101
102protected:
103 std::string m_name;
105};
106
125class VISP_EXPORT vpPanda3DAmbientLight : public vpPanda3DLight
126{
127public:
128 vpPanda3DAmbientLight(const std::string &name, const vpRGBf &color) : vpPanda3DLight(name, color) { }
129
130 virtual ~vpPanda3DAmbientLight() = default;
131
132 void addToScene(NodePath &scene) const VP_OVERRIDE
133 {
134 PT(AmbientLight) light = new AmbientLight(m_name);
135 light->set_color(LColor(m_color.R, m_color.G, m_color.B, 1));
136 NodePath alnp = scene.attach_new_node(light);
137 scene.set_light(alnp);
138 }
139};
140
156class VISP_EXPORT vpPanda3DPointLight : public vpPanda3DLight
157{
158public:
173 vpPanda3DPointLight(const std::string &name, const vpRGBf &color, const vpColVector &position, const vpColVector &attenuation)
174 : vpPanda3DLight(name, color), m_attenuation(attenuation)
175 {
176 if (position.size() != 3) {
177 throw vpException(vpException::dimensionError, "Point light position must be a 3 dimensional vector");
178 }
179 m_position.resize(4, false);
180 m_position.insert(0, position);
181 m_position[3] = 1.0;
182 if (attenuation.size() != 3) {
183 throw vpException(vpException::dimensionError, "Point light attenuation components must be a 3 dimensional vector");
184 }
185 }
186
187 virtual ~vpPanda3DPointLight() = default;
188
189 void addToScene(NodePath &scene) const VP_OVERRIDE
190 {
191 PT(PointLight) light = new PointLight(m_name);
192 light->set_color(LColor(m_color.R, m_color.G, m_color.B, 1));
193 light->set_attenuation(LVecBase3(m_attenuation[0], m_attenuation[1], m_attenuation[2]));
194 NodePath np = scene.attach_new_node(light);
195 //vpColVector posPanda = vpPanda3DBaseRenderer::vispPointToPanda(m_position);
196 np.set_pos(m_position[0], m_position[1], m_position[2]);
197 scene.set_light(np);
198 }
199
200private:
201 vpColVector m_position;
202 vpColVector m_attenuation;
203};
204
220{
221public:
231 vpPanda3DDirectionalLight(const std::string &name, const vpRGBf &color, const vpColVector &direction)
232 : vpPanda3DLight(name, color), m_direction(direction)
233 {
234 if (m_direction.size() != 3) {
235 throw vpException(vpException::dimensionError, "Direction light direction must be a 3 dimensional vector");
236 }
237 m_direction.normalize();
238 }
239
240 virtual ~vpPanda3DDirectionalLight() = default;
241
242 void addToScene(NodePath &scene) const VP_OVERRIDE
243 {
244 PT(DirectionalLight) light = new DirectionalLight(m_name);
245 light->set_color(LColor(m_color.R, m_color.G, m_color.B, 1));
247 light->set_direction(LVector3f(m_direction[0], m_direction[1], m_direction[2]));
248 NodePath np = scene.attach_new_node(light);
249 scene.set_light(np);
250 }
251
252private:
253 vpColVector m_direction;
254};
255
267class VISP_EXPORT vpPanda3DLightable
268{
269public:
270 virtual ~vpPanda3DLightable() = default;
276 virtual void addLight(const vpPanda3DLight &light) = 0;
277};
278
292{
293public:
296
297 vpPanda3DLightableScene(NodePath &scene) : vpPanda3DLightable(), m_lightableScene(scene)
298 { }
299
300 virtual ~vpPanda3DLightableScene() = default;
301
308 void addLight(const vpPanda3DLight &light) VP_OVERRIDE
309 {
310 if (m_lightableScene.is_empty()) {
311 throw vpException(vpException::notInitialized, "Tried to add a light to a scene that is not initialized.");
312 }
313 light.addToScene(m_lightableScene);
314 }
315protected:
316 void setLightableScene(NodePath &scene) { m_lightableScene = scene; }
317private:
318 NodePath m_lightableScene;
319};
320
321END_VISP_NAMESPACE
322
323#endif
324#endif
unsigned int size() const
Return the number of elements of the 2D array.
Definition vpArray2D.h:435
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ notInitialized
Used to indicate that a parameter is not initialized.
Definition vpException.h:74
void addToScene(NodePath &scene) const VP_OVERRIDE
Add the light to the scene.
virtual ~vpPanda3DAmbientLight()=default
vpPanda3DAmbientLight(const std::string &name, const vpRGBf &color)
static vpColVector vispVectorToPanda(const vpColVector &vec)
virtual ~vpPanda3DDirectionalLight()=default
void addToScene(NodePath &scene) const VP_OVERRIDE
Add the light to the scene.
vpPanda3DDirectionalLight(const std::string &name, const vpRGBf &color, const vpColVector &direction)
Build a new directional light.
Base class for a Light that can be added to a Panda3D scene.
std::string m_name
const std::string & getName() const
Get the name of the light.
const vpRGBf & getColor() const
Get the light's color.
virtual void addToScene(NodePath &scene) const =0
Add the light to the scene.
vpRGBf m_color
Name of the light. Should be unique in the scene.
virtual ~vpPanda3DLight()=default
vpPanda3DLight(const std::string &name, const vpRGBf &color)
Build a new Panda3D light, given a unique name and an RGB color.
void addLight(const vpPanda3DLight &light) VP_OVERRIDE
Add a light to the scene. All of the objects in the scene will be lit.
void setLightableScene(NodePath &scene)
vpPanda3DLightableScene(NodePath &scene)
virtual ~vpPanda3DLightableScene()=default
Interface for objects, scenes or other Panda3D related data that can be lit by a vpPanda3DLight.
virtual ~vpPanda3DLightable()=default
virtual void addLight(const vpPanda3DLight &light)=0
Light this lightable object with a new light.
void addToScene(NodePath &scene) const VP_OVERRIDE
Add the light to the scene.
virtual ~vpPanda3DPointLight()=default
vpPanda3DPointLight(const std::string &name, const vpRGBf &color, const vpColVector &position, const vpColVector &attenuation)
Build a new point light.