From 96f864b75986e54a70b16e06c1036119b8ce8e0c Mon Sep 17 00:00:00 2001 From: Christoph Hinze Date: Sat, 17 Aug 2019 17:21:12 +0200 Subject: [PATCH] Fix/py color support osg viewer (#1398) * Add color support for dartpy osg Viewer and ImGuiViewer An Eigen::Vector4f can be passed to the viewer constructor to set the background color. * Fix implicit conversion from python lists to numpy vector only works for double vectors * Add white background color to * Fix wrong comment --- python/dartpy/gui/osg/ImGuiViewer.cpp | 5 +++ python/dartpy/gui/osg/Viewer.cpp | 5 +++ python/examples/hello_world_gui/main.py | 51 +++++++++++++------------ 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/python/dartpy/gui/osg/ImGuiViewer.cpp b/python/dartpy/gui/osg/ImGuiViewer.cpp index f0704f3d4511f..3d5b8550307ae 100644 --- a/python/dartpy/gui/osg/ImGuiViewer.cpp +++ b/python/dartpy/gui/osg/ImGuiViewer.cpp @@ -49,6 +49,11 @@ void ImGuiViewer(py::module& m) dart::gui::osg::Viewer, osg::ref_ptr>(m, "ImGuiViewer") .def(::py::init<>()) + .def( + ::py::init([](const Eigen::Vector4d& clearColor) { + return new ::dart::gui::osg::ImGuiViewer(eigToOsgVec4f(clearColor)); + }), + ::py::arg("clearColor")) .def(::py::init(), ::py::arg("clearColor")) .def( "getImGuiHandler", diff --git a/python/dartpy/gui/osg/Viewer.cpp b/python/dartpy/gui/osg/Viewer.cpp index 93b26dfca082d..231d785504d8a 100644 --- a/python/dartpy/gui/osg/Viewer.cpp +++ b/python/dartpy/gui/osg/Viewer.cpp @@ -59,6 +59,11 @@ void Viewer(py::module& m) dart::common::Subject, ::osg::ref_ptr>(m, "Viewer") .def(::py::init<>()) + .def( + ::py::init([](const Eigen::Vector4f& clearColor) { + return new ::dart::gui::osg::Viewer(eigToOsgVec4d(clearColor)); + }), + ::py::arg("clearColor")) .def(::py::init(), ::py::arg("clearColor")) .def( "captureScreen", diff --git a/python/examples/hello_world_gui/main.py b/python/examples/hello_world_gui/main.py index fe4857c7902ef..c5e15de768ac7 100644 --- a/python/examples/hello_world_gui/main.py +++ b/python/examples/hello_world_gui/main.py @@ -2,29 +2,29 @@ class HelloWorldNode(dart.gui.osg.RealTimeWorldNode): - # Use this function to execute custom code before each time that the - # window is rendered. This function can be deleted if it does not need - # to be used. - def customPreRefresh(self): - pass - - # Use this function to execute custom code after each time that the - # window is rendered. This function can be deleted if it does not need - # to be used. - def customPostRefresh(self): - pass - - # Use this function to execute custom code before each simulation time - # step is performed. This function can be deleted if it does not need - # to be used. - def customPreStep(self): - pass - - # Use this function to execute custom code after each simulation time - # step is performed. This function can be deleted if it does not need - # to be used. - def customPostStep(self): - pass + # Use this function to execute custom code before each time that the + # window is rendered. This function can be deleted if it does not need + # to be used. + def customPreRefresh(self): + pass + + # Use this function to execute custom code after each time that the + # window is rendered. This function can be deleted if it does not need + # to be used. + def customPostRefresh(self): + pass + + # Use this function to execute custom code before each simulation time + # step is performed. This function can be deleted if it does not need + # to be used. + def customPreStep(self): + pass + + # Use this function to execute custom code after each simulation time + # step is performed. This function can be deleted if it does not need + # to be used. + def customPostStep(self): + pass def main(): @@ -37,10 +37,11 @@ def main(): world.addSkeleton(ground) world.setGravity([0, -9.81, 0]) + # Create world node and add it to viewer node = HelloWorldNode(world) - # Create world node and add it to viewer - viewer = dart.gui.osg.Viewer() + # create a viewer with background color (red, green, blue, alpha), here: white + viewer = dart.gui.osg.Viewer([1.0, 1.0, 1.0, 1.0]) viewer.addWorldNode(node) # Grid settings