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"
68 buffer->set_active(
false);
69 buffer->clear_render_textures();
83 PandaFramework &framework = frameworkManager.
getFramework();
88 "Panda3D renderer: Cannot create a window with 0 height or width.");
93 WindowProperties winProps;
95 int flags = GraphicsPipe::BF_refuse_window;
96 m_window = framework.open_window(winProps, flags,
nullptr,
nullptr);
99 winProps.set_minimized(
true);
100 m_window = framework.open_window(winProps, 0,
nullptr,
nullptr);
104 "Panda3D renderer: Could not create the requested window when performing initialization.");
106 m_window->set_background_type(WindowFramework::BackgroundType::BT_black);
149 m_window->get_graphics_output()->get_engine()->render_frame();
157 if (mainBuffer !=
nullptr) {
158 mainBuffer->get_engine()->extract_texture_data(mainBuffer->get_texture(), mainBuffer->get_gsg());
170 for (GraphicsOutput *buffer:
m_buffers) {
172 GraphicsBuffer *buf =
dynamic_cast<GraphicsBuffer *
>(buffer);
173 if (buf ==
nullptr) {
215 object.set_pos(t[0], t[1], t[2]);
216 object.set_quat(LQuaternion(q.
w(), q.
x(), q.
y(), q.
z()));
222 if (
object.is_empty()) {
230 const LPoint3 pos =
object.get_pos();
231 const LQuaternion quat =
object.get_quat();
243 if (
object.is_empty()) {
248 object.calc_tight_bounds(minP, maxP);
249 const BoundingBox box(minP, maxP);
250 float minZ = std::numeric_limits<float>::max(), maxZ = 0.f;
254 for (
unsigned int i = 0; i < 8; ++i) {
255 const LPoint3 p = box.get_point(i);
272 const BoundingVolume *volume =
object.node()->get_bounds();
273 if (volume->get_type() == BoundingSphere::get_class_type()) {
274 const BoundingSphere *sphere = (
const BoundingSphere *)volume;
275 const LPoint3 center = sphere->get_center();
276 const float distCenter = (center -
m_cameraPath.get_pos()).length();
277 nearV = vpMath::maximum<float>(0.f, distCenter - sphere->get_radius());
278 farV = vpMath::maximum<float>(nearV, distCenter + sphere->get_radius());
280 else if (volume->get_type() == BoundingBox::get_class_type()) {
284 const BoundingBox *box = (
const BoundingBox *)volume;
285 double minZ = std::numeric_limits<double>::max(), maxZ = 0.0;
287 for (
unsigned int i = 0; i < 8; ++i) {
288 const LPoint3 p = box->get_point(i);
290 double Z = cp[2] / cp[3];
311 if (buffer !=
nullptr) {
312 buffer->set_clear_depth_active(
false);
324 for (GraphicsOutput *buffer:
m_buffers) {
325 buffer->set_sort(buffer->get_sort() + (order - previousOrder));
332 NodePath model =
m_window->load_model(framework.get_models(), modelPath);
333 if (model.is_empty()) {
336 for (
int i = 0; i < model.get_num_children(); ++i) {
337 model.get_child(i).clear_transform();
341 model.set_name(nodeName);
348 objectInScene.set_name(
object.get_name());
355 load_prc_file_data(
"",
"sync-video true");
358 load_prc_file_data(
"",
"sync-video false");
364 load_prc_file_data(
"",
"assert-abort 1");
367 load_prc_file_data(
"",
"assert-abort 0");
373 load_prc_file_data(
"",
"gl-debug 1");
374 load_prc_file_data(
"",
"notify-level-display spam");
380 pandaPos /= pandaPos[3];
396 #elif !defined(VISP_BUILD_SHARED_LIBS)
398 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.
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 ~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.
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.
bool m_isWindowOwner
Set of buffers that this renderer uses. This storage contains weak refs to those buffers and should n...
virtual PointerTo< GraphicsOutput > getMainOutputBuffer()
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
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 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.
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,...
PandaFramework & getFramework()
void registerDisabledWindow(PointerTo< WindowFramework > wf)
static vpPanda3DFrameworkManager & getInstance()
void disableAllOtherRenderers(PointerTo< WindowFramework > &active)
void enableAllRenderers()
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.