14
14
15
15
16
16
class SceneElement (object ):
17
+
17
18
def __init__ (self ):
18
19
self .uuid = unicode (uuid .uuid1 ())
19
20
20
21
21
22
class ReferenceSceneElement (SceneElement ):
23
+
22
24
def lower_in_object (self , object_data ):
23
25
object_data .setdefault (self .field , []).append (self .lower (object_data ))
24
26
return self .uuid
@@ -44,6 +46,7 @@ class Image(ReferenceSceneElement):
44
46
45
47
46
48
class Box (Geometry ):
49
+
47
50
def __init__ (self , lengths ):
48
51
super (Box , self ).__init__ ()
49
52
self .lengths = lengths
@@ -59,6 +62,7 @@ def lower(self, object_data):
59
62
60
63
61
64
class Sphere (Geometry ):
65
+
62
66
def __init__ (self , radius ):
63
67
super (Sphere , self ).__init__ ()
64
68
self .radius = radius
@@ -68,8 +72,8 @@ def lower(self, object_data):
68
72
u"uuid" : self .uuid ,
69
73
u"type" : u"SphereGeometry" ,
70
74
u"radius" : self .radius ,
71
- u"widthSegments" : 20 ,
72
- u"heightSegments" : 20
75
+ u"widthSegments" : 20 ,
76
+ u"heightSegments" : 20
73
77
}
74
78
75
79
@@ -78,6 +82,7 @@ class Ellipsoid(Sphere):
78
82
An Ellipsoid is treated as a Sphere of unit radius, with an affine
79
83
transformation applied to distort it into the ellipsoidal shape
80
84
"""
85
+
81
86
def __init__ (self , radii ):
82
87
super (Ellipsoid , self ).__init__ (1.0 )
83
88
self .radii = radii
@@ -86,11 +91,33 @@ def intrinsic_transform(self):
86
91
return np .diag (np .hstack ((self .radii , 1.0 )))
87
92
88
93
94
+ class Plane (Geometry ):
95
+
96
+ def __init__ (self , width = 1 , height = 1 , widthSegments = 1 , heightSegments = 1 ):
97
+ super (Plane , self ).__init__ ()
98
+ self .width = width
99
+ self .height = height
100
+ self .widthSegments = widthSegments
101
+ self .heightSegments = heightSegments
102
+
103
+ def lower (self , object_data ):
104
+ return {
105
+ u"uuid" : self .uuid ,
106
+ u"type" : u"PlaneGeometry" ,
107
+ u"width" : self .width ,
108
+ u"height" : self .height ,
109
+ u"widthSegments" : self .widthSegments ,
110
+ u"heightSegments" : self .heightSegments ,
111
+ }
112
+
89
113
"""
90
114
A cylinder of the given height and radius. By Three.js convention, the axis of
91
115
rotational symmetry is aligned with the y-axis.
92
116
"""
117
+
118
+
93
119
class Cylinder (Geometry ):
120
+
94
121
def __init__ (self , height , radius = 1.0 , radiusTop = None , radiusBottom = None ):
95
122
super (Cylinder , self ).__init__ ()
96
123
if radiusTop is not None and radiusBottom is not None :
@@ -114,11 +141,14 @@ def lower(self, object_data):
114
141
115
142
116
143
class MeshMaterial (Material ):
117
- def __init__ (self , color = 0xffffff , reflectivity = 0.5 , map = None , ** kwargs ):
144
+
145
+ def __init__ (self , color = 0xffffff , reflectivity = 0.5 , map = None ,
146
+ transparent = False , ** kwargs ):
118
147
super (MeshMaterial , self ).__init__ ()
119
148
self .color = color
120
149
self .reflectivity = reflectivity
121
150
self .map = map
151
+ self .transparent = transparent
122
152
self .properties = kwargs
123
153
124
154
def lower (self , object_data ):
@@ -127,6 +157,7 @@ def lower(self, object_data):
127
157
u"type" : self ._type ,
128
158
u"color" : self .color ,
129
159
u"reflectivity" : self .reflectivity ,
160
+ u"transparent" : self .transparent
130
161
}
131
162
data .update (self .properties )
132
163
if self .map is not None :
@@ -135,22 +166,23 @@ def lower(self, object_data):
135
166
136
167
137
168
class MeshBasicMaterial (MeshMaterial ):
138
- _type = u"MeshBasicMaterial"
169
+ _type = u"MeshBasicMaterial"
139
170
140
171
141
172
class MeshPhongMaterial (MeshMaterial ):
142
- _type = u"MeshPhongMaterial"
173
+ _type = u"MeshPhongMaterial"
143
174
144
175
145
176
class MeshLambertMaterial (MeshMaterial ):
146
- _type = u"MeshLambertMaterial"
177
+ _type = u"MeshLambertMaterial"
147
178
148
179
149
180
class MeshToonMaterial (MeshMaterial ):
150
- _type = u"MeshToonMaterial"
181
+ _type = u"MeshToonMaterial"
151
182
152
183
153
184
class PngImage (Image ):
185
+
154
186
def __init__ (self , data ):
155
187
super (PngImage , self ).__init__ ()
156
188
self .data = data
@@ -167,7 +199,49 @@ def lower(self, object_data):
167
199
}
168
200
169
201
202
+ class CanvasImage (Image ):
203
+
204
+ def __init__ (self ):
205
+ super (CanvasImage , self ).__init__ ()
206
+
207
+ def lower (self , object_data ):
208
+ return {
209
+ u"uuid" : self .uuid ,
210
+ u"url" : ""
211
+ }
212
+
213
+
214
+ class TextTexture (Texture ):
215
+
216
+ def __init__ (self , text , font_size = 96 , font_face = 'sans-serif' ,
217
+ width = 200 , height = 100 , position = [10 , 10 ]):
218
+ super (TextTexture , self ).__init__ ()
219
+ self .text = text
220
+ # font_size will be passed to the JS side as is; however if the
221
+ # text width exceeds canvas width, font_size will be reduced.
222
+ self .font_size = font_size
223
+ self .font_face = font_face
224
+ self .width = width
225
+ self .height = height
226
+ self .position = position
227
+ self .image = CanvasImage ()
228
+
229
+ def lower (self , object_data ):
230
+ return {
231
+ u"uuid" : self .uuid ,
232
+ u"type" : u"TextTexture" ,
233
+ u"text" : unicode (self .text ),
234
+ u"font_size" : self .font_size ,
235
+ u"font_face" : self .font_face ,
236
+ u"width" : self .width ,
237
+ u"height" : self .height ,
238
+ u"position" : self .position ,
239
+ u"image" : self .image .lower_in_object (object_data )
240
+ }
241
+
242
+
170
243
class GenericTexture (Texture ):
244
+
171
245
def __init__ (self , properties ):
172
246
super (GenericTexture , self ).__init__ ()
173
247
self .properties = properties
@@ -182,6 +256,7 @@ def lower(self, object_data):
182
256
183
257
184
258
class ImageTexture (Texture ):
259
+
185
260
def __init__ (self , image , wrap = [1001 , 1001 ], repeat = [1 , 1 ], ** kwargs ):
186
261
super (ImageTexture , self ).__init__ ()
187
262
self .image = image
@@ -201,6 +276,7 @@ def lower(self, object_data):
201
276
202
277
203
278
class GenericMaterial (Material ):
279
+
204
280
def __init__ (self , properties ):
205
281
self .properties = properties
206
282
self .uuid = str (uuid .uuid1 ())
@@ -215,6 +291,7 @@ def lower(self, object_data):
215
291
216
292
217
293
class Object (SceneElement ):
294
+
218
295
def __init__ (self , geometry , material = MeshPhongMaterial ()):
219
296
super (Object , self ).__init__ ()
220
297
self .geometry = geometry
@@ -251,7 +328,8 @@ def item_size(array):
251
328
elif array .ndim == 2 :
252
329
return array .shape [0 ]
253
330
else :
254
- raise ValueError ("I can only pack 1- or 2-dimensional numpy arrays, but this one has {:d} dimensions" .format (array .ndim ))
331
+ raise ValueError (
332
+ "I can only pack 1- or 2-dimensional numpy arrays, but this one has {:d} dimensions" .format (array .ndim ))
255
333
256
334
257
335
def threejs_type (dtype ):
@@ -280,6 +358,7 @@ def pack_numpy_array(x):
280
358
281
359
282
360
class ObjMeshGeometry (Geometry ):
361
+
283
362
def __init__ (self , contents ):
284
363
super (ObjMeshGeometry , self ).__init__ ()
285
364
self .contents = contents
@@ -299,6 +378,7 @@ def from_file(fname):
299
378
300
379
301
380
class PointsGeometry (Geometry ):
381
+
302
382
def __init__ (self , position , color = None ):
303
383
super (PointsGeometry , self ).__init__ ()
304
384
self .position = position
@@ -318,6 +398,7 @@ def lower(self, object_data):
318
398
319
399
320
400
class PointsMaterial (Material ):
401
+
321
402
def __init__ (self , size = 0.001 , color = 0xffffff ):
322
403
super (PointsMaterial , self ).__init__ ()
323
404
self .size = size
@@ -336,6 +417,8 @@ def lower(self, object_data):
336
417
class Points (Object ):
337
418
_type = u"Points"
338
419
420
+ class Texts (Object ):
421
+ _type = u"_texttexture"
339
422
340
423
def PointCloud (position , color , ** kwargs ):
341
424
return Points (
0 commit comments