-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Create basic visualiser #17
Conversation
Visualiser basic
Adding comments
Current status: basic viewer that displays the model, but no interactivity yet. We should try to use the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this PR, I suggest we can commit the files in vis
(except for basic.cc
) after some minor tweaks, but we should remove the lyceum-vis
from this branch and put it in the next PR. You can ignore all the comments on the lyceum code for now, as it will only be useful as a guide for the next PR.
We should probably move to package extensions in the next PR. It doesn't seem too involved. We can follow this post for a guide, and also the docs. This should allow us to use Requires.jl
as well to support people on older versions, before v1.9
.
examples/vis/visualiser.jl
Outdated
scn::Ptr{mjvScene} = alloc(mjvScene) | ||
cam::Ptr{mjvCamera} = alloc(mjvCamera) | ||
vopt::Ptr{mjvOption} = alloc(mjvOption) | ||
con::Ptr{mjrContext} = alloc(mjrContext) | ||
figsensor::Ptr{mjvFigure} = alloc(mjvFigure) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alloc is fine here, but we should add a finaliser to GC the objects since this is a mutable struct.
m.internal_pointer, | ||
d.internal_pointer, | ||
viewer.ui.vopt, | ||
C_NULL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remind me what this C_NULL is again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just NULL but in C.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the argument to the function, why are we setting it to null? The function calls it pert
but I'm not sure what that is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's either perturbations to the scene (eg: dragging around the view with the mouse) or perturbations to the environment (eg: due to dragging around objects in the environment). I've set it as null for now because we don't need either of those for the most basic visualiser.
examples/vis/visualiser.jl
Outdated
function close_viewer!(viewer::MuJoCoViewer) | ||
|
||
LibMuJoCo.mjv_freeScene(viewer.ui.scn) | ||
LibMuJoCo.mjr_freeContext(viewer.ui.con) | ||
|
||
Libc.free(viewer.ui.cam) | ||
Libc.free(viewer.ui.vopt) | ||
Libc.free(viewer.ui.scn) | ||
Libc.free(viewer.ui.con) | ||
|
||
GLFW.DestroyWindow(viewer.manager.state.window) | ||
|
||
return nothing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all great - we should move the frees into the GC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. How do we go about doing that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably wrap these objects in a type just like Model
and Data
to make things easier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. That's happening in #35 right?
src/MuJoCo.jl
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need the using UnsafeArrays
?
Also, good idea to validate the path. Perhaps there is a mj function which also validates an xml
file that we can use? But that's for a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly not, I'll check.
There was a warning for the mjrContext object which has some more padding than expected
This is to track progress on development of a basic visualiser - don't merge to main just yet :)
The main idea is to create a visualiser built off the LyceumMuJoCoViz.jl package that is easy to use and integrate into custom simulation/control loops. As per #3, the syntax we want is something like this:
The
render!(viewer)
step should be set up with mouse/button callbacks to make the visualisation interactive.