Skip to content
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

[rebased] Text rendering: python-side #111

Merged
merged 3 commits into from
Mar 25, 2022

Conversation

Arpafaucon
Copy link

@Arpafaucon Arpafaucon commented Feb 15, 2022

I do not claim any credit for this work, I merely squashed & rebased @shensquared's work in #32. The only "intelligent" change I had to do is remove a use of unicode since we're python3 now.

I tested the relevant demo.ipynb and was able to reproduce the results. Here's the state after the final cell is run:

image

I hope this will save you some work, and help merge this nice feature to meshcat :)

@@ -195,6 +215,26 @@ def lower(self, object_data):
}


class TextTexture(Texture):
def __init__(self, text, font_size=100, font_face='sans-serif',
width=200, height=100, position=[10, 10]):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

width, height, position are not used. Should I delete them ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes please

@Arpafaucon
Copy link
Author

Arpafaucon commented Feb 22, 2022

Hi maintainers (@rdeits and @shensquared ?), a gentle reminder of this PR waiting for your feedback :)


Also, while thinking about it, I was wondering how hard it would be to be able to extend this work and apply a texture only on some faces of 3D shapes (especially boxes).

An illustration explaining why is below:
image

This is a screenshot of a little project I did to visualize the position of some frames of a robot. I draw 3 cylinders for each frame pointing in the X,Y,Z directions.

I wanted to add the frame name on the X cylinder (colored red). Ideally I would have liked to have this text readable on all 4 sides of the cylinder, for now I only did it on 2 opposite sides, by creating a transparent box around the red cylinder, and having the frame name painted as a TextTexture on it. To have the text rendered in a correct aspect ratio, I found no better way than to create a box of size h,h,2*r, where:

  • h is the height of the cylinder
  • r its radius

I highlighted 2 small issues with the current solution:

  • in green: you can see the very distorted text that is rendered as a texture for the top part of the box
  • in pink: the transparent box of RightInternalToe is hiding the text texture of another box behind it ( we should be able to read RightMetatarsus)

I feel that those 2 issues could be solved by:

  • being able to choose on which side of the geometry the texture is applied
  • a better control of the scaling of the texture: for now, I believe we draw the text on a square canvas and give this as a texture, and it is scaled to fit the face dimensions. An option to choose between scaling and cropping would fix the distortion issues

Despite those slight inconvenience (for which there is maybe an already existing solution ?), I'd be very happy if we could merge this first PR into meshcat. I'm also available to think about the subject further with you then :)

Copy link
Collaborator

@rdeits rdeits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for forgetting about this, and thanks for the contribution. If you can delete those unused attributes I'm happy to get this merged.

@@ -195,6 +215,26 @@ def lower(self, object_data):
}


class TextTexture(Texture):
def __init__(self, text, font_size=100, font_face='sans-serif',
width=200, height=100, position=[10, 10]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes please

@Arpafaucon
Copy link
Author

@rdeits I removed the attributes :)

@rdeits rdeits merged commit 0f25add into meshcat-dev:master Mar 25, 2022
@district10
Copy link

TextTexture appears in examples/demo.ipynb, but it's not officially released yet.

Install from source works for me:

pip uninstall meshcat -y
pip install git+https://github.com/rdeits/meshcat-python.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants