-
Notifications
You must be signed in to change notification settings - Fork 67
add interfacing to javascript side 2d text rendering #32
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
base: master
Are you sure you want to change the base?
Changes from 12 commits
a374add
378806f
ffb5233
253007b
3b33b39
ae852a3
acd6694
4677e2e
adf3cdd
bee1a23
ae90a3a
7474b56
940acbc
9063953
9932bb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,25 @@ def intrinsic_transform(self): | |
return np.diag(np.hstack((self.radii, 1.0))) | ||
|
||
|
||
class Plane(Geometry): | ||
|
||
def __init__(self, width=1, height=1, widthSegments=1, heightSegments=1): | ||
super(Plane, self).__init__() | ||
self.width = width | ||
self.height = height | ||
self.widthSegments = widthSegments | ||
self.heightSegments = heightSegments | ||
|
||
def lower(self, object_data): | ||
return { | ||
u"uuid": self.uuid, | ||
u"type": u"PlaneGeometry", | ||
u"width": self.width, | ||
u"height": self.height, | ||
u"widthSegments": self.widthSegments, | ||
u"heightSegments": self.heightSegments, | ||
} | ||
|
||
""" | ||
A cylinder of the given height and radius. By Three.js convention, the axis of | ||
rotational symmetry is aligned with the y-axis. | ||
|
@@ -184,6 +203,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]): | ||
super(TextTexture, self).__init__() | ||
self.text = text | ||
# font_size will be passed to the JS side as is; however if the | ||
# text width exceeds canvas width, font_size will be reduced. | ||
self.font_size = font_size | ||
self.font_face = font_face | ||
|
||
def lower(self, object_data): | ||
return { | ||
u"uuid": self.uuid, | ||
u"type": u"_text", | ||
u"text": unicode(self.text), | ||
u"font_size": self.font_size, | ||
u"font_face": self.font_face, | ||
} | ||
|
||
class GenericTexture(Texture): | ||
def __init__(self, properties): | ||
super(GenericTexture, self).__init__() | ||
|
@@ -388,3 +427,16 @@ def PointCloud(position, color, **kwargs): | |
PointsGeometry(position, color), | ||
PointsMaterial(**kwargs) | ||
) | ||
|
||
|
||
def SceneText(text, **kwargs): | ||
if 'width' in kwargs and 'height' in kwargs: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is quite right. If the user only provides def SceneText(text, width=10, height=10, **kwargs):
... ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, agreed. Changed it. |
||
plane = Plane(kwargs.pop('width'), kwargs.pop('height')) | ||
else: | ||
plane = Plane(width=10,height=10) | ||
return Mesh( | ||
plane, | ||
MeshPhongMaterial(map=TextTexture(text,**kwargs),transparent=True, | ||
needsUpdate=True) | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,8 +134,9 @@ def jupyter_cell(self): | |
def __getitem__(self, path): | ||
return Visualizer.view_into(self.window, self.path.append(path)) | ||
|
||
def set_object(self, geometry, material=None): | ||
return self.window.send(SetObject(geometry, material, self.path)) | ||
def set_object(self, geometry, material=None, texts=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we get rid of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
return self.window.send(SetObject(geometry, material, texts, | ||
self.path)) | ||
|
||
def set_transform(self, matrix=np.eye(4)): | ||
return self.window.send(SetTransform(matrix, self.path)) | ||
|
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.
Do we still need this code?
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.
Right, they only serve to simplify the call a little, but it's not too verbose otherwise either. Removed them.