Skip to content

Commit 672e2ad

Browse files
committed
WIP add transparency parameter to differentiate scene and object texts
1 parent f00ea47 commit 672e2ad

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/meshcat/commands.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ def __init__(self, text, geometry_or_object, material=None, path=[]):
4646
else:
4747
if geometry_or_object is None:
4848
geometry_or_object = Plane()
49+
# if writing onto the scene, default material is transparent
50+
material = MeshPhongMaterial(map=self.text_texture,
51+
needsUpdate=True, opacity = 0.0)
4952
if material is None:
50-
material = MeshPhongMaterial(
51-
map=self.text_texture, needsUpdate=True)
53+
material = MeshPhongMaterial(map=self.text_texture,
54+
needsUpdate=True)
5255
if isinstance(material, PointsMaterial):
5356
raise(ArgumentError(
5457
"Cannot write text onto points; please supply a mesh material"))

src/meshcat/geometry.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def lower(self, object_data):
164164
# u"height": self.height,
165165
# u"curveSegments": self.curveSegments
166166
# }
167-
167+
168168

169169

170170

@@ -220,11 +220,13 @@ def lower(self, object_data):
220220

221221
class MeshMaterial(Material):
222222

223-
def __init__(self, color=0xffffff, reflectivity=0.5, map=None, **kwargs):
223+
def __init__(self, color=0xffffff, reflectivity=0.5, map=None,
224+
opacity = 1.0, **kwargs):
224225
super(MeshMaterial, self).__init__()
225226
self.color = color
226227
self.reflectivity = reflectivity
227228
self.map = map
229+
self.opacity = opacity
228230
self.properties = kwargs
229231

230232
def lower(self, object_data):
@@ -233,6 +235,7 @@ def lower(self, object_data):
233235
u"type": self._type,
234236
u"color": self.color,
235237
u"reflectivity": self.reflectivity,
238+
u"opacity": self.opacity
236239
}
237240
data.update(self.properties)
238241
if self.map is not None:
@@ -276,27 +279,29 @@ def lower(self, object_data):
276279

277280
class CanvasImage(Image):
278281

279-
def __init__(self):
282+
def __init__(self, alpha):
280283
super(CanvasImage, self).__init__()
281-
# self.data = data
284+
self.alpha = alpha
282285

283286
def lower(self, object_data):
284287
return {
285288
u"uuid": self.uuid,
286-
u"url": u'place_holder'
289+
u"url": u'place_holder',
290+
u"alpha": self.alpha
287291
}
288292

289293

290294
class TextTexture(Texture):
291295

292-
def __init__(self, text, font='96px sans-serif', width=200, height=100, position=[10, 10]):
296+
def __init__(self, text, font='96px sans-serif', width=200, height=100,
297+
position=[10, 10],alpha=True):
293298
super(TextTexture, self).__init__()
294299
self.text = text
295300
self.font = font
296301
self.width = width
297302
self.height = height
298303
self.position = position
299-
self.image = CanvasImage()
304+
self.image = CanvasImage(alpha)
300305

301306
def lower(self, object_data):
302307
return {

0 commit comments

Comments
 (0)