31#include <visp3/ar/vpPanda3DBaseRenderer.h>
33#if defined(VISP_HAVE_PANDA3D)
35#include <visp3/ar/vpPanda3DFrameworkManager.h>
36#include <visp3/core/vpMath.h>
39#include <antialiasAttrib.h>
40#include "boundingSphere.h"
41#include "boundingBox.h"
43#include "load_prc_file.h"
44#include "windowFramework.h"
45#include "graphicsOutput.h"
70 buffer->set_active(
false);
71 buffer->clear_render_textures();
85 PandaFramework &framework = frameworkManager.
getFramework();
90 "Panda3D renderer: Cannot create a window with 0 height or width.");
95 WindowProperties winProps;
97 int flags = GraphicsPipe::BF_refuse_window;
98 m_window = framework.open_window(winProps, flags,
nullptr,
nullptr);
101 winProps.set_minimized(
true);
102 m_window = framework.open_window(winProps, 0,
nullptr,
nullptr);
106 "Panda3D renderer: Could not create the requested window when performing initialization.");
108 m_window->set_background_type(WindowFramework::BackgroundType::BT_black);
151 m_window->get_graphics_output()->get_engine()->render_frame();
159 if (mainBuffer !=
nullptr) {
160 mainBuffer->get_engine()->extract_texture_data(mainBuffer->get_texture(), mainBuffer->get_gsg());
172 for (GraphicsOutput *buffer:
m_buffers) {
174 GraphicsBuffer *buf =
dynamic_cast<GraphicsBuffer *
>(buffer);
175 if (buf ==
nullptr) {
217 object.set_pos(t[0], t[1], t[2]);
218 object.set_quat(LQuaternion(q.
w(), q.
x(), q.
y(), q.
z()));
224 if (
object.is_empty()) {
232 const LPoint3 pos =
object.get_pos();
233 const LQuaternion quat =
object.get_quat();
245 if (
object.is_empty()) {
250 object.calc_tight_bounds(minP, maxP);
251 const BoundingBox box(minP, maxP);
252 float minZ = std::numeric_limits<float>::max(), maxZ = 0.f;
256 for (
unsigned int i = 0; i < 8; ++i) {
257 const LPoint3 p = box.get_point(i);
274 const BoundingVolume *volume =
object.node()->get_bounds();
275 if (volume->get_type() == BoundingSphere::get_class_type()) {
276 const BoundingSphere *sphere = (
const BoundingSphere *)volume;
277 const LPoint3 center = sphere->get_center();
278 const float distCenter = (center -
m_cameraPath.get_pos()).length();
282 else if (volume->get_type() == BoundingBox::get_class_type()) {
286 const BoundingBox *box = (
const BoundingBox *)volume;
287 double minZ = std::numeric_limits<double>::max(), maxZ = 0.0;
289 for (
unsigned int i = 0; i < 8; ++i) {
290 const LPoint3 p = box->get_point(i);
292 double Z = cp[2] / cp[3];
313 if (buffer !=
nullptr) {
314 buffer->set_clear_depth_active(
false);
326 for (GraphicsOutput *buffer:
m_buffers) {
327 buffer->set_sort(buffer->get_sort() + (order - previousOrder));
334 NodePath model =
m_window->load_model(framework.get_models(), modelPath);
335 if (model.is_empty()) {
338 for (
int i = 0; i < model.get_num_children(); ++i) {
339 model.get_child(i).clear_transform();
343 model.set_name(nodeName);
353 objectInScene.set_name(
object.get_name());
365 load_prc_file_data(
"",
"sync-video true");
368 load_prc_file_data(
"",
"sync-video false");
374 load_prc_file_data(
"",
"assert-abort 1");
377 load_prc_file_data(
"",
"assert-abort 0");
383 load_prc_file_data(
"",
"gl-debug 1");
384 load_prc_file_data(
"",
"notify-level-display spam");
390 pandaPos /= pandaPos[3];
406#elif !defined(VISP_BUILD_SHARED_LIBS)
408void 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.
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpRotationMatrix getRotationMatrix() const
vpHomogeneousMatrix inverse() const
vpTranslationVector getTranslationVector() const
static Type maximum(const Type &a, const Type &b)
vpPanda3DBaseRenderer(const std::string &rendererName)
virtual ~vpPanda3DBaseRenderer()
void setRenderOrder(int order)
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...
NodePath m_renderRoot
Rendering parameters.
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 addObjectToScene(const std::string &name, const std::string &path)
Load and and an object to the scene.
bool m_isWindowOwner
Set of buffers that this renderer uses. This storage contains weak refs to those buffers and should n...
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 & pandaToVisp()
static const vpHomogeneousMatrix & vispToPanda()
static const vpHomogeneousMatrix VISP_T_PANDA
std::vector< PointerTo< GraphicsOutput > > m_buffers
NodePath of the camera.
virtual void afterFrameRendered()
PointerTo< WindowFramework > m_window
Rendering priority for this renderer and its buffers. A lower value will be rendered first....
virtual PointerTo< GraphicsOutput > getMainOutputBuffer()
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...
virtual void initFromParent(PointerTo< WindowFramework > window)
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.
int m_renderOrder
name of the renderer
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).
vpPanda3DRenderParameters m_renderParameters
Pointer to owning window, which can create buffers etc. It is not necessarily visible.
void computeNearAndFarPlanesFromNode(const std::string &name, float &nearV, float &farV, bool fast)
Compute the near and far planes for the camera at the current pose, given a certain node/part of the ...
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).
Base class for a panda3D renderer. This class handles basic functionalities, such as loading object,...
void registerDisabledWindow(PointerTo< WindowFramework > wf)
static vpPanda3DFrameworkManager & getInstance()
PandaFramework & getFramework()
void disableAllOtherRenderers(PointerTo< WindowFramework > &active)
void enableAllRenderers()
Rendering parameters for a panda3D simulation.
unsigned int getImageWidth() const
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.