-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ArrowVisualizer #97
Conversation
|
||
ArrowVisualizer(vis::AbstractVisualizer) = ArrowVisualizer(vis[:shaft], vis[:head]) | ||
|
||
function setobject!(vis::ArrowVisualizer, material::AbstractMaterial=defaultmaterial(); |
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 guess this is kind of a non-standard method for this function. What do you think?
function settransform!(vis::ArrowVisualizer, base::Point{3}, vec::Vec{3}; | ||
shaft_radius=0.01, | ||
max_head_radius=2*shaft_radius, | ||
max_head_length=max_head_radius) |
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.
The keyword arguments could also be properties of ArrowVisualizer
. Do you think that's better?
Codecov Report
@@ Coverage Diff @@
## master #97 +/- ##
=========================================
+ Coverage 73.65% 75.2% +1.55%
=========================================
Files 12 13 +1
Lines 334 363 +29
=========================================
+ Hits 246 273 +27
- Misses 88 90 +2
Continue to review full report at Codecov.
|
|
Sorry for not responding sooner to this! I think this is a great idea, and I've wanted a nicer way to draw arrows for quite a while. I do think, though, that we should try to make it compatible with the existing animation system. I agree that it's awkward to have to decompose the transform, but I think it's an unavoidable part of dealing with three.js. Three.js only understands how to animate vectors and quaternions, not full transformation matrices. Fortunately, three.js already knows how to animate the "scale" property, so I think I can make this just work with a small tweak to the julia-side animation code. Let me see... |
4f9524e
to
3b70624
Compare
Ready to go? |
Yeah, as long as you're OK with the |
3b70624
to
f4db540
Compare
Actually, with animations, the interpolation seems to be a little problematic. For example: Not sure if this is a bug or just a consequence of the interpolation method in combination with the fact that an arrow is not a single object. As a workaround / way to debug, is there a way to completely disable interpolation on the three.js side? |
Ah, yeah, that's probably an effect of the interpolation. After all, linearly interpolating the shaft and head transforms independently isn't going to necessarily produce a rigid motion of the arrow. I think it's possible to turn off interpolation in three.js, but I don't have an API for it. On the plus side, I think this is pretty easy to fix. The reason we don't see this problem in MeshCatMechanisms is that the mechanism's tree structure is reflected in the MeshCat tree structure, so subtrees always move together even if the interpolation is inaccurate. We should be able to do the same thing here: we can change the arrow visualizer from this:
into this:
We then have to apply the arrow's translation, rotation, and length scaling to the whole arrow_vis, rather than applying it to the shaft and head independently. We'll also need to apply the inverse of the arrow scaling to the head so that it doesn't shrink and grow with the arrow. If we do this right, the transform from shaft to head should stay rigid despite the interpolation. |
Ideally (as it is currently implemented), I want:
I feel the combination of these two features works better for arrows that vary in length a lot, and it's in conflict with naively transforming the whole thing, which would result in either arrows with a huge shaft radius which quickly engulf the whole scene, or weirdly stretched arrowheads. |
Yup, makes sense. I think tkoolen#3 handles all that. After all, I'm applying exactly the same total transformation in that PR that you were previously--the only difference is that by rearranging the visualizer, I'm giving three.js more information about how to animate it properly. |
Ah, great, yes, this looks like a good solution then. |
Ensure arrows are rigid during animation
Good to go now from my perspective. |
Excellent! |
This is very cool! |
(On top of #96).
Adds an
ArrowVisualizer
type, which enables easy visualization of 3D arrows consisting of a cylinder for the shaft and a cone for the head.I took inspiration from
MechanismVisualizer
, in thatArrowVisualizer
is basically a cheap-to-construct abstraction layer around aVisualizer
(in this case twoVisualizer
s) with a higher-level interface for setting the transforms.One issue is that this doesn't work with
AnimationVisualizer
quite yet, because the transformations I'm computing aren't rigid transformations, and so trying to extract out just the translation and rotation doesn't work. @rdeits, what do you think about this? It's quite unfortunate that we have to decompose the transform in this way; can't we just set the matrix directly when creating animations? I guess we can extract out and setscale
as well, but ideally I'd like to avoid going back and forth.