Skip to content

Commit

Permalink
Fix/py color support osg viewer (#1398)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
chhinze authored and jslee02 committed Aug 17, 2019
1 parent bd37098 commit 96f864b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
5 changes: 5 additions & 0 deletions python/dartpy/gui/osg/ImGuiViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ void ImGuiViewer(py::module& m)
dart::gui::osg::Viewer,
osg::ref_ptr<dart::gui::osg::ImGuiViewer>>(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<const osg::Vec4&>(), ::py::arg("clearColor"))
.def(
"getImGuiHandler",
Expand Down
5 changes: 5 additions & 0 deletions python/dartpy/gui/osg/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ void Viewer(py::module& m)
dart::common::Subject,
::osg::ref_ptr<dart::gui::osg::Viewer>>(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<const osg::Vec4&>(), ::py::arg("clearColor"))
.def(
"captureScreen",
Expand Down
51 changes: 26 additions & 25 deletions python/examples/hello_world_gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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
Expand Down

0 comments on commit 96f864b

Please sign in to comment.