-
Notifications
You must be signed in to change notification settings - Fork 51
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 2d text (as the texture of a plane) #43
Conversation
Yeah, awesome! So, one question we should resolve is how we want to represent this in the meshcat interface. For example, one way to do it would be to add a new kind of object (like the way I think I prefer the second option: it requires a bit more logic on the Python side, but it means that we can write text on anything, rather than just planes. And we can create convenience functions in Python so that simple tasks like drawing text on a flat surface is still easy. What do you think? |
Agreed, option 2 is more versatile and python friendly, which I guess is the point. I think here’s what’s probably necessary for the job:
class SetText:
__slots__ = ["object", "path"]
def __init__(self, text, geometry_or_object=None, material=None, path=[]):
if geometry_or_object is None:
geometry_or_object = Plane(width, height, h_segments, v_segments)
text_texture = TextTexture(text)
material = MeshBasicMaterial(map=text_texture)
# may also need a separate treatment if the object already has material
# and we are replacing the texture instead of initializing it like in here
self.object = Mesh(geometry_or_object, material)
self.path = path
def lower(self):
return {
u"type": u"set_object",
u"object": self.object.lower(),
u"path": self.path.lower()
}
The only part I don’t immediately know how to do is actually creating |
Yeah, this sounds pretty good. Right, writing text into a canvas is possible in python, but I'd rather not bother with it. Instead, I think we can send a {
uuid: "<insert uuid here>",
type: "_texttexture"
text: "Hello world",
font: "sans-serif",
width: 200,
height: 100,
position: [10, 10],
} Then on the Javascript side, we would need a little bit of logic to look for In that way, we can still rely on the browser's very convenient text rendering, while still staying very generic and composable. Does that seem reasonable? |
Yep, sounds very good and doable. Will try it and update here. |
Hey Shen! Are you still working on this branch? Anything I can do to help? |
Hey Robin, sorry for leaving it hanging here. I honestly had forgotten about this -- functionally it was working properly and hardcoding a few parameters served me well enough for then, so I lost track of cleaning it up here... But yeah, I still do want it in. Will revisit it by the weekend and hopefully it will be pretty quick. But will definitely bother you if needed help :) |
Ok, sounds good! Thanks! |
Hey @rdeits, the PR is ready for review now. |
Hey @shensquared I just wanted to let you know I haven't forgotten about this! I'm playing around with some ways to simplify the text loading logic (and also simplify some of the mesh loaders as well). I'll let you know if it works out (or if it doesn't...). |
This commit adds the ExtensibleObjectLoader class, which lets us insert some hooks for special geometry types into the normal THREE.ObjectLoader. In this way, we can avoid some unnecessary conversions to and from JSON, and we no longer have to do things like inspect the objects after they are loaded and swap in replacement textures. It also eliminates the `set_text` method, since text is now just another kind of texture that any object might happen to have.
Ah, sounds good, thanks for letting me know. |
I think shensquared#1 should work pretty well, and it avoids the complexity of needing a separate SetText command type. |
Make text texture and meshfile geometry loading transparent
Oh, fascinating (and baffling). Thanks for figuring that out. This looks great, so I'm going to merge it! We can still make more changes if necessary, since |
Following the suggestions in #41

Here's an initial attempt
Still a lot to clean up but want to first check, does this look like what you had in mind?