18 #ifndef GZ_GAZEBO_GUI_SCENE3D_HH_
19 #define GZ_GAZEBO_GUI_SCENE3D_HH_
21 #include <gz/msgs/boolean.pb.h>
22 #include <gz/msgs/gui_camera.pb.h>
23 #include <gz/msgs/stringmsg.pb.h>
24 #include <gz/msgs/vector3d.pb.h>
25 #include <gz/msgs/video_record.pb.h>
31 #include <sdf/Root.hh>
33 #include <gz/math/Color.hh>
34 #include <gz/math/Pose3.hh>
35 #include <gz/math/Vector2.hh>
36 #include <gz/math/Vector3.hh>
38 #include <gz/common/MouseEvent.hh>
39 #include <gz/common/KeyEvent.hh>
41 #include <gz/rendering/Camera.hh>
45 #include "gz/gui/qt.h"
53 inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
54 class IgnRendererPrivate;
55 class RenderWindowItemPrivate;
88 QString errorPopupText
90 WRITE SetErrorPopupText
91 NOTIFY ErrorPopupTextChanged
99 NOTIFY LoadingErrorChanged
109 public:
void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override;
119 public slots:
void OnDropped(const QString &_drop,
120 int _mouseX,
int _mouseY);
125 public slots:
void OnHovered(
int _mouseX,
int _mouseY);
129 public slots:
void OnFocusWindow();
132 protected:
bool eventFilter(QObject *_obj, QEvent *_event) override;
138 private:
bool OnTransformMode(const msgs::StringMsg &_msg,
139 msgs::Boolean &_res);
145 private:
bool OnRecordVideo(const msgs::VideoRecord &_msg,
146 msgs::Boolean &_res);
152 private:
bool OnMoveTo(const msgs::StringMsg &_msg,
153 msgs::Boolean &_res);
159 private:
bool OnFollow(const msgs::StringMsg &_msg,
160 msgs::Boolean &_res);
166 private:
bool OnFollowOffset(const msgs::Vector3d &_msg,
167 msgs::Boolean &_res);
173 private:
bool OnViewAngle(const msgs::Vector3d &_msg,
174 msgs::Boolean &_res);
180 private:
bool OnMoveToPose(const msgs::GUICamera &_msg,
181 msgs::Boolean &_res);
188 private:
bool OnViewTransparent(const msgs::StringMsg &_msg,
189 msgs::Boolean &_res);
196 private:
bool OnViewCOM(const msgs::StringMsg &_msg,
197 msgs::Boolean &_res);
203 private:
bool OnViewInertia(const msgs::StringMsg &_msg,
204 msgs::Boolean &_res);
210 private:
bool OnViewJoints(const msgs::StringMsg &_msg,
211 msgs::Boolean &_res);
217 private:
bool OnViewWireframes(const msgs::StringMsg &_msg,
218 msgs::Boolean &_res);
224 private:
bool OnViewCollisions(const msgs::StringMsg &_msg,
225 msgs::Boolean &_res);
229 public: Q_INVOKABLE QString ErrorPopupText() const;
233 public: Q_INVOKABLE
void SetErrorPopupText(const QString &_errorTxt);
236 signals:
void ErrorPopupTextChanged();
241 signals:
void popupError();
247 private:
bool OnViewControl(const msgs::StringMsg &_msg,
248 msgs::Boolean &_res);
252 public: Q_INVOKABLE QString LoadingError() const;
256 public: Q_INVOKABLE
void SetLoadingError(const QString &_loadingError);
259 signals:
void LoadingErrorChanged();
262 public: QString loadingError;
266 private:
std::unique_ptr<Scene3DPrivate> dataPtr;
290 public:
void Render(RenderSync *_renderSync);
298 public:
void Destroy();
305 public:
void SetTransformMode(
const std::string &_mode);
313 public:
void SetModelPath(
const std::string &_filePath);
318 public:
void SetDropdownMenuEnabled(
bool _enableDropdownMenu);
324 public:
void SetRecordVideo(
bool _record,
const std::string &_format,
329 public:
void SetRecordVideoUseSimTime(
bool _useSimTime);
333 public:
void SetRecordVideoLockstep(
bool _lockstep);
337 public:
void SetRecordVideoBitrate(
unsigned int _bitrate);
341 public:
void SetMoveTo(
const std::string &_target);
348 public:
void SetFollowTarget(
const std::string &_target,
349 bool _waitForTarget =
false);
355 public:
void SetViewAngle(
const math::Vector3d &_direction);
359 public:
void SetMoveToPose(
const math::Pose3d &_pose);
363 public:
void SetViewTransparentTarget(
const std::string &_target);
367 public:
void SetViewCOMTarget(
const std::string &_target);
371 public:
void SetViewInertiaTarget(
const std::string &_target);
375 public:
void SetViewJointsTarget(
const std::string &_target);
379 public:
void SetViewWireframesTarget(
const std::string &_target);
383 public:
void SetViewCollisionsTarget(
const std::string &_target);
387 public:
void SetViewController(
const std::string &_viewController);
391 public:
void SetFollowPGain(
double _gain);
396 public:
void SetFollowWorldFrame(
bool _worldFrame);
400 public:
void SetFollowOffset(
const math::Vector3d &_offset);
408 public:
bool FollowWorldFrame()
const;
412 public: math::Vector3d FollowOffset()
const;
416 public:
void SetInitCameraPose(
const math::Pose3d &_pose);
421 public:
void NewMouseEvent(
const common::MouseEvent &_e,
422 const math::Vector2d &_drag = math::Vector2d::Zero);
426 public:
void NewHoverEvent(
const math::Vector2i &_hoverPos);
430 public:
void HandleKeyPress(QKeyEvent *_e);
434 public:
void HandleKeyRelease(QKeyEvent *_e);
438 public:
void SetXYZSnap(
const math::Vector3d &_xyz);
442 public: math::Vector3d XYZSnap()
const;
446 public:
void SetRPYSnap(
const math::Vector3d &_rpy);
450 public: math::Vector3d RPYSnap()
const;
454 public:
void SetScaleSnap(
const math::Vector3d &_scale);
458 public: math::Vector3d ScaleSnap()
const;
467 public:
void SnapPoint(
468 math::Vector3d &_point,
469 math::Vector3d &_snapVals,
double _sensitivity = 0.4)
const;
476 public:
void RequestSelectionChange(
Entity _selectedEntity,
477 bool _deselectAll,
bool _sendEvent);
487 private:
double SnapValue(
488 double _coord,
double _interval,
double _sensitivity)
const;
492 private:
void XYZConstraint(math::Vector3d &_axis);
495 private:
void HandleMouseEvent();
498 private:
void HandleMouseContextMenu();
501 private:
void HandleMouseViewControl();
504 private:
void HandleMouseTransformControl();
507 private:
void HandleEntitySelection();
510 private:
void HandleModelPlacement();
513 private:
void BroadcastHoverPos();
516 private:
void BroadcastLeftClick();
519 private:
void BroadcastRightClick();
523 private:
Entity UniqueId();
528 public:
bool GeneratePreview(
const sdf::Root &_sdf);
531 public:
void TerminateSpawnPreview();
537 public: math::Vector3d ScreenToPlane(
const math::Vector2i &_screenPos)
544 public: math::Vector3d ScreenToScene(
const math::Vector2i &_screenPos)
549 public: math::Pose3d CameraPose()
const;
552 private:
void OnMoveToComplete();
555 private:
void OnViewAngleComplete();
558 private:
void OnMoveToPoseComplete();
564 private:
void UpdateSelectedEntity(
const rendering::NodePtr &_node,
570 private:
void DeselectAllEntities(
bool _sendEvent);
573 signals:
void ContextMenuRequested(QString _entity);
579 signals:
void FollowTargetChanged(
const std::string &_target,
580 bool _waitForTarget);
589 public: math::Pose3d cameraPose = math::Pose3d(0, 0, 2, 0, 0.4, 0);
595 public: uint32_t visibilityMask = 0xFFFFFFFFu;
598 public:
bool initialized =
false;
601 public: QSize textureSize = QSize(1024, 1024);
604 public:
bool textureDirty =
false;
622 public slots:
void RenderNext(RenderSync *renderSync);
625 public slots:
void ShutDown();
628 public slots:
void SizeChanged();
634 signals:
void TextureReady(uint _id,
const QSize &_size);
638 public:
void SetErrorCb(
std::function<
void(
const QString &)> _cb);
644 public: QOffscreenSurface *surface =
nullptr;
647 public: QOpenGLContext *context =
nullptr;
671 public:
void SetCameraPose(
const math::Pose3d &_pose);
675 public: math::Pose3d CameraPose()
const;
679 public:
void SetInitCameraPose(
const math::Pose3d &_pose);
683 public:
void SetVisibilityMask(uint32_t _mask);
687 public:
void SetTransformMode(
const std::string &_mode);
695 public:
void SetModelPath(
const std::string &_filePath);
700 public:
void SetDropdownMenuEnabled(
bool _enableDropdownMenu);
706 public:
void SetRecordVideo(
bool _record,
const std::string &_format,
711 public:
void SetRecordVideoUseSimTime(
bool _useSimTime);
715 public:
void SetRecordVideoLockstep(
bool _lockstep);
719 public:
void SetRecordVideoBitrate(
unsigned int _bitrate);
723 public:
void SetMoveTo(
const std::string &_target);
730 public Q_SLOTS:
void SetFollowTarget(
const std::string &_target,
731 bool _waitForTarget =
false);
737 public:
void SetViewAngle(
const math::Vector3d &_direction);
741 public:
void SetMoveToPose(
const math::Pose3d &_pose);
745 public:
void SetViewTransparentTarget(
const std::string &_target);
749 public:
void SetViewCOMTarget(
const std::string &_target);
753 public:
void SetViewInertiaTarget(
const std::string &_target);
757 public:
void SetViewJointsTarget(
const std::string &_target);
761 public:
void SetViewWireframesTarget(
const std::string &_target);
765 public:
void SetViewCollisionsTarget(
const std::string &_target);
769 public:
void SetViewController(
const std::string &_viewController);
773 public:
void SetFollowPGain(
double _gain);
778 public:
void SetFollowWorldFrame(
bool _worldFrame);
782 public:
void SetFollowOffset(
const math::Vector3d &_offset);
786 public:
void SetWorldName(
const std::string &_name);
798 public:
void UpdateSelectedEntity(
Entity _entity,
805 public:
void DeselectAllEntities(
bool _sendEvent);
809 public:
void SetXYZSnap(
const math::Vector3d &_xyz);
813 public:
void SetRPYSnap(
const math::Vector3d &_rpy);
817 public:
void SetScaleSnap(
const math::Vector3d &_scale);
823 public: math::Vector3d ScreenToScene(
const math::Vector2i &_screenPos);
828 public:
void OnHovered(
const gz::math::Vector2i &_hoverPos);
834 public:
bool RendererInitialized()
const;
837 public Q_SLOTS:
void Ready();
841 public:
void HandleKeyPress(QKeyEvent *_e);
845 public:
void HandleKeyRelease(QKeyEvent *_e);
848 protected:
void mousePressEvent(QMouseEvent *_e)
override;
851 protected:
void mouseReleaseEvent(QMouseEvent *_e)
override;
854 protected:
void mouseMoveEvent(QMouseEvent *_e)
override;
857 protected:
void wheelEvent(QWheelEvent *_e)
override;
865 private: QSGNode *updatePaintNode(QSGNode *_oldNode,
866 QQuickItem::UpdatePaintNodeData *_data)
override;
872 signals:
void openContextMenu(QString _entity);
876 public slots:
void OnContextMenuRequested(QString _entity);
880 public:
void SetErrorCb(
std::function<
void(
const QString &)> _cb);
896 public:
explicit TextureNode(QQuickWindow *_window,
897 RenderSync &_renderSync);
906 public slots:
void NewTexture(uint _id,
const QSize &_size);
910 public slots:
void PrepareNode();
915 signals:
void TextureInUse(RenderSync *_renderSync);
919 signals:
void PendingNewTexture();
925 public: QSize size = QSize(0, 0);
934 public: QSGTexture *texture =
nullptr;
937 public: QQuickWindow *window =
nullptr;