31 #include <visp3/ar/vpPanda3DBaseRenderer.h>
33 #if defined(VISP_HAVE_PANDA3D)
35 #include <visp3/core/vpMath.h>
37 #include "load_prc_file.h"
38 #include <antialiasAttrib.h>
39 #include "boundingSphere.h"
40 #include "boundingBox.h"
55 "Panda3D renderer: Reinitializing is not supported!");
57 m_framework = std::shared_ptr<PandaFramework>(
new PandaFramework());
59 WindowProperties winProps;
61 int flags = GraphicsPipe::BF_refuse_window;
65 winProps.set_minimized(
true);
70 "Panda3D renderer: Could not create the requested window when performing initialization.");
72 m_window->set_background_type(WindowFramework::BackgroundType::BT_black);
112 m_framework->get_graphics_engine()->render_frame();
124 for (GraphicsOutput *buffer:
m_buffers) {
126 GraphicsBuffer *buf =
dynamic_cast<GraphicsBuffer *
>(buffer);
127 if (buf ==
nullptr) {
169 object.set_pos(t[0], t[1], t[2]);
170 object.set_quat(LQuaternion(q.
w(), q.
x(), q.
y(), q.
z()));
176 if (
object.is_empty()) {
184 const LPoint3 pos =
object.get_pos();
185 const LQuaternion quat =
object.get_quat();
197 if (
object.is_empty()) {
202 object.calc_tight_bounds(minP, maxP);
203 const BoundingBox box(minP, maxP);
204 float minZ = std::numeric_limits<float>::max(), maxZ = 0.f;
208 for (
unsigned int i = 0; i < 8; ++i) {
209 const LPoint3 p = box.get_point(i);
226 const BoundingVolume *volume =
object.node()->get_bounds();
227 if (volume->get_type() == BoundingSphere::get_class_type()) {
228 const BoundingSphere *sphere = (
const BoundingSphere *)volume;
229 const LPoint3 center = sphere->get_center();
230 const float distCenter = (center -
m_cameraPath.get_pos()).length();
231 nearV = vpMath::maximum<float>(0.f, distCenter - sphere->get_radius());
232 farV = vpMath::maximum<float>(nearV, distCenter + sphere->get_radius());
234 else if (volume->get_type() == BoundingBox::get_class_type()) {
238 const BoundingBox *box = (
const BoundingBox *)volume;
239 double minZ = std::numeric_limits<double>::max(), maxZ = 0.0;
241 for (
unsigned int i = 0; i < 8; ++i) {
242 const LPoint3 p = box->get_point(i);
244 double Z = cp[2] / cp[3];
265 if (buffer !=
nullptr) {
266 buffer->set_clear_depth_active(
false);
277 for (
int i = 0; i < model.get_num_children(); ++i) {
278 model.get_child(i).clear_transform();
282 model.set_name(nodeName);
289 objectInScene.set_name(
object.get_name());
296 load_prc_file_data(
"",
"sync-video true");
299 load_prc_file_data(
"",
"sync-video false");
305 load_prc_file_data(
"",
"assert-abort 1");
308 load_prc_file_data(
"",
"assert-abort 0");
314 load_prc_file_data(
"",
"gl-debug 1");
315 load_prc_file_data(
"",
"notify-level-display spam");
321 pandaPos /= pandaPos[3];
337 #elif !defined(VISP_BUILD_SHARED_LIBS)
339 void dummy_vpPanda3DBaseRenderer() { };
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
@ notInitialized
Used to indicate that a parameter is not initialized.
@ notImplementedError
Not implemented.
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpRotationMatrix getRotationMatrix() const
vpHomogeneousMatrix inverse() const
vpTranslationVector getTranslationVector() const
Base class for a panda3D renderer. This class handles basic functionalities, such as loading object,...
virtual void setupCamera()
Initialize camera. Should be called when the scene root of this render has already been created.
virtual void setupScene()
Initialize the scene for this specific renderer.
virtual void renderFrame()
virtual vpHomogeneousMatrix getCameraPose()
Retrieve the camera's pose, in the world frame. The pose is specified using the ViSP convention (Y-do...
std::shared_ptr< PandaFramework > m_framework
Rendering priority for this renderer and its buffers. A lower value will be rendered first....
virtual GraphicsOutput * getMainOutputBuffer()
NodePath m_renderRoot
Rendering parameters.
void computeNearAndFarPlanesFromNode(const std::string &name, float &near, float &far, bool fast)
Compute the near and far planes for the camera at the current pose, given a certain node/part of the ...
PointerTo< Camera > m_camera
Node containing all the objects and the camera for this renderer.
virtual bool isRendering3DScene() const
Returns true if this renderer process 3D data and its scene root can be interacted with.
static vpColVector vispPointToPanda(const vpColVector &point)
virtual void initFramework()
Initialize the whole Panda3D framework. Create a new PandaFramework object and a new window.
void setVerticalSyncEnabled(bool useVsync)
set whether vertical sync is enabled. When vertical sync is enabled, render speed will be limited by ...
static const vpHomogeneousMatrix PANDA_T_VISP
Homogeneous transformation matrix to convert from the Panda coordinate system (right-handed Z-up) to ...
std::string m_name
Inverse of VISP_T_PANDA.
virtual void addNodeToScene(const NodePath &object)
Add a node to the scene. Its pose is set as the identity matrix.
void setAbortOnPandaError(bool abort)
Set the behaviour when a Panda3D assertion fails. If abort is true, the program will stop....
static const vpHomogeneousMatrix VISP_T_PANDA
virtual void initFromParent(std::shared_ptr< PandaFramework > framework, PointerTo< WindowFramework > window)
virtual void afterFrameRendered()
PointerTo< WindowFramework > m_window
Pointer to the active panda framework.
virtual void enableSharedDepthBuffer(vpPanda3DBaseRenderer &sourceBuffer)
virtual void setupRenderTarget()
Initialize buffers and other objects that are required to save the render.
static vpColVector vispVectorToPanda(const vpColVector &vec)
virtual void setRenderParameters(const vpPanda3DRenderParameters ¶ms)
Set new rendering parameters. If the scene has already been initialized, the renderer camera is updat...
NodePath loadObject(const std::string &nodeName, const std::string &modelPath)
Load a 3D object. To load an .obj file, Panda3D must be compiled with assimp support.
virtual void setNodePose(const std::string &name, const vpHomogeneousMatrix &wTo)
Set the pose of a node. This node can be any Panda object (light, mesh, camera). The pose is specifie...
virtual void beforeFrameRendered()
virtual void setCameraPose(const vpHomogeneousMatrix &wTc)
Set the camera's pose. The pose is specified using the ViSP convention (Y-down right handed).
std::vector< GraphicsOutput * > m_buffers
NodePath of the camera.
vpPanda3DRenderParameters m_renderParameters
Pointer to owning window, which can create buffers etc. It is not necessarily visible.
virtual vpHomogeneousMatrix getNodePose(const std::string &name)
Get the pose of a Panda node, in world frame in the ViSP convention (Y-down right handed).
Rendering parameters for a panda3D simulation.
unsigned int getImageWidth() const
void setupPandaCamera(Camera *camera)
Update a Panda3D camera object to use this objects's parameters.
unsigned int getImageHeight() const
Implementation of a rotation vector as quaternion angle minimal representation.
const double & z() const
Returns the z-component of the quaternion.
const double & x() const
Returns the x-component of the quaternion.
const double & y() const
Returns the y-component of the quaternion.
const double & w() const
Returns the w-component of the quaternion.
Class that consider the case of a translation vector.