vuer 0.0.17__py3-none-any.whl → 0.0.19__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of vuer might be problematic. Click here for more details.

Binary file
Binary file
@@ -118,29 +118,29 @@ class Facemesh(SceneElement):
118
118
  """Renders an oriented MediaPipe face mesh:
119
119
 
120
120
  :param points: An array of 468+ keypoints as returned by google/mediapipe tasks-vision. Defaults to a sample face.
121
- :type points: MediaPipePoints, optional
121
+ :type points: MediaPipePoints, optional
122
122
  :param face: An face object as returned by tensorflow/tfjs-models face-landmarks-detection. This parameter is deprecated.
123
- :type face: MediaPipeFaceMesh, optional
123
+ :type face: MediaPipeFaceMesh, optional
124
124
  :param width: Constant width of the mesh. Defaults to undefined.
125
- :type width: int, optional
125
+ :type width: int, optional
126
126
  :param height: Constant height of the mesh. Defaults to undefined.
127
- :type height: int, optional
127
+ :type height: int, optional
128
128
  :param depth: Constant depth of the mesh. Defaults to 1.
129
- :type depth: int, optional
129
+ :type depth: int, optional
130
130
  :param verticalTri: A landmarks tri supposed to be vertical. Defaults to [159, 386, 200]. See: https://github.com/tensorflow/tfjs-models/tree/master/face-landmarks-detection#mediapipe-facemesh-keypoints
131
- :type verticalTri: Tuple[int, int, int], optional
131
+ :type verticalTri: Tuple[int, int, int], optional
132
132
  :param origin: A landmark index (to get the position from) or a vec3 to be the origin of the mesh. Defaults to undefined (i.e., the bbox center).
133
- :type origin: Union[int, THREE.Vector3], optional
133
+ :type origin: Union[int, THREE.Vector3], optional
134
134
  :param facialTransformationMatrix: A facial transformation matrix, as returned by FaceLandmarkerResult.facialTransformationMatrixes. See: https://developers.google.com/mediapipe/solutions/vision/face_landmarker/web_js#handle_and_display_results
135
- :type facialTransformationMatrix: FacemeshDatas.SAMPLE_FACELANDMARKER_RESULT.facialTransformationMatrixes[0], optional
135
+ :type facialTransformationMatrix: FacemeshDatas.SAMPLE_FACELANDMARKER_RESULT.facialTransformationMatrixes[0], optional
136
136
  :param offset: Apply position offset extracted from `facialTransformationMatrix`.
137
- :type offset: bool, optional
137
+ :type offset: bool, optional
138
138
  :param offsetScalar: Offset sensitivity factor, less is more sensible.
139
- :type offsetScalar: float, optional
139
+ :type offsetScalar: float, optional
140
140
  :param faceBlendshapes: Face blendshapes, as returned by FaceLandmarkerResult.faceBlendshapes. See: https://developers.google.com/mediapipe/solutions/vision/face_landmarker/web_js#handle_and_display_results
141
- :type faceBlendshapes: FacemeshDatas.SAMPLE_FACELANDMARKER_RESULT.faceBlendshapes[0], optional
141
+ :type faceBlendshapes: FacemeshDatas.SAMPLE_FACELANDMARKER_RESULT.faceBlendshapes[0], optional
142
142
  :param eyes: Whether to enable eyes (note: `faceBlendshapes` is required for this). Defaults to True.
143
- :type eyes: bool, optional
143
+ :type eyes: bool, optional
144
144
 
145
145
  Usage::
146
146
 
@@ -30,6 +30,7 @@ class Element:
30
30
  def serialize(self):
31
31
  """
32
32
  Serialize the element to a dictionary for sending over the websocket.
33
+
33
34
  :return: Dictionary representing the element.
34
35
  """
35
36
 
@@ -39,6 +39,56 @@ class SceneElement(BlockElement):
39
39
 
40
40
 
41
41
  class Frustum(SceneElement):
42
+ """Camera Frustum
43
+
44
+ :param position: An optional tuple of three numbers representing the position.
45
+ :type position: tuple[float, float, float]
46
+ :param rotation: An optional tuple of three numbers representing the rotation.
47
+ :type rotation: tuple[float, float, float]
48
+ :param matrix: An optional tuple of sixteen numbers representing the matrix.
49
+ :type matrix: tuple[float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float]
50
+ :param aspect: An optional number representing the aspect.
51
+ :type aspect: float
52
+ :param focus: An optional number representing the focus.
53
+ :type focus: float
54
+ :param fov: An optional number representing the field of view.
55
+ :type fov: float
56
+ :param near: An optional number representing the near field.
57
+ :type near: float
58
+ :param far: An optional number representing the far field.
59
+ :type far: float
60
+ :param scale: An optional number representing the scale.
61
+ :type scale: float
62
+ :param upScale: An optional number representing the up scale.
63
+ :type upScale: float
64
+ :param focalLength: An optional number representing the focal length.
65
+ :type focalLength: float
66
+ :param showUp: An optional boolean indicating whether to show up.
67
+ :type showUp: bool
68
+ :param showFrustum: An optional boolean indicating whether to show the frustum.
69
+ :type showFrustum: bool
70
+ :param showFocalPlane: An optional boolean indicating whether to show the focal plane.
71
+ :type showFocalPlane: bool
72
+ :param showImagePlane: An optional boolean indicating whether to show the image plane.
73
+ :type showImagePlane: bool
74
+ :param src: An optional string representing the source.
75
+ :type src: str
76
+ :param colorOrigin: An optional ColorRepresentation for the origin color.
77
+ :type colorOrigin: ColorRepresentation
78
+ :param colorFrustum: An optional ColorRepresentation for the frustum color.
79
+ :type colorFrustum: ColorRepresentation
80
+ :param colorCone: An optional ColorRepresentation for the cone color.
81
+ :type colorCone: ColorRepresentation
82
+ :param colorFocalPlane: An optional ColorRepresentation for the focal plane color.
83
+ :type colorFocalPlane: ColorRepresentation
84
+ :param colorUp: An optional ColorRepresentation for the up color.
85
+ :type colorUp: ColorRepresentation
86
+ :param colorTarget: An optional ColorRepresentation for the target color.
87
+ :type colorTarget: ColorRepresentation
88
+ :param colorCross: An optional ColorRepresentation for the cross color.
89
+ :type colorCross: ColorRepresentation
90
+ """
91
+
42
92
  tag = "Frustum"
43
93
 
44
94
 
@@ -132,6 +182,9 @@ class PointCloud(SceneElement):
132
182
  self.colors = self.colors.flatten().tobytes()
133
183
 
134
184
 
185
+ p = PointCloud
186
+
187
+
135
188
  class Box(SceneElement):
136
189
  tag = "Box"
137
190
 
@@ -442,9 +495,7 @@ class DefaultScene(Scene):
442
495
  ):
443
496
  rawChildren = [
444
497
  AmbientLight(intensity=1.0, key="default_ambient_light"),
445
- DirectionalLight(
446
- intensity=1, key="default_directional_light", helper=show_helper
447
- ),
498
+ DirectionalLight(intensity=1, key="default_directional_light", helper=show_helper),
448
499
  *(rawChildren or []),
449
500
  ]
450
501
 
@@ -468,4 +519,4 @@ class DefaultScene(Scene):
468
519
  ],
469
520
  up=up,
470
521
  **kwargs,
471
- )
522
+ )
vuer/server.py CHANGED
@@ -2,10 +2,12 @@ import asyncio
2
2
  from asyncio import sleep
3
3
  from collections import deque, defaultdict
4
4
  from functools import partial
5
- from typing import cast, Callable, Coroutine
5
+ from typing import cast, Callable, Coroutine, Dict
6
6
  from uuid import uuid4
7
7
 
8
+ from aiohttp.web_request import Request
8
9
  from aiohttp.web_response import Response
10
+ from aiohttp.web_ws import WebSocketResponse
9
11
  from msgpack import packb, unpackb
10
12
  from params_proto import Proto, PrefixProto
11
13
  from websockets import ConnectionClosedError
@@ -27,7 +29,7 @@ from vuer.events import (
27
29
  Upsert,
28
30
  )
29
31
  from vuer.schemas import Page
30
- from vuer.types import EventHandler, Spawnable
32
+ from vuer.types import EventHandler, SocketHandler
31
33
 
32
34
 
33
35
  class At:
@@ -55,6 +57,24 @@ class VuerSession:
55
57
  self.downlink_queue = que_maker()
56
58
  self.uplink_queue = que_maker()
57
59
 
60
+ @property
61
+ def socket(self):
62
+ """Getter for the websocket object.
63
+
64
+ this is useful for closing the socket session from the client side.
65
+
66
+ Example Usage::
67
+
68
+ @app.spawn(start=True):
69
+ async def main(session: VuerSession):
70
+ print("doing something...")
71
+ await sleep(1.0)
72
+
73
+ print("I am done! closing the socket.")
74
+ session.socket.close()
75
+ """
76
+ return self.vuer.ws[self.CURRENT_WS_ID]
77
+
58
78
  def __matmul__(self, event: ServerEvent):
59
79
  """
60
80
  Send a ServerEvent to the client.
@@ -242,6 +262,22 @@ class Vuer(PrefixProto, Server):
242
262
 
243
263
  app.run()
244
264
 
265
+
266
+ .. automethod:: bind
267
+ .. automethod:: spawn
268
+ .. automethod:: relay
269
+ .. automethod:: bound_fn
270
+ .. automethod:: spawn_task
271
+ .. automethod:: get_url
272
+ .. automethod:: send
273
+ .. automethod:: rpc
274
+ .. automethod:: rpc_stream
275
+ .. automethod:: close_ws
276
+ .. automethod:: uplink
277
+ .. automethod:: downlink
278
+ .. automethod:: add_handler
279
+ .. automethod:: _ttl_handler
280
+ .. automethod:: run
245
281
  """
246
282
 
247
283
  name = "vuer"
@@ -278,8 +314,8 @@ class Vuer(PrefixProto, Server):
278
314
  # todo: can remove
279
315
  self.page = Page()
280
316
 
281
- self.ws = {}
282
- self.spawned_fn: Spawnable = None
317
+ self.ws: Dict[str, WebSocketResponse] = {}
318
+ self.socket_handler: SocketHandler = None
283
319
  self.spawned_coroutines = []
284
320
 
285
321
  async def relay(self, request):
@@ -290,11 +326,11 @@ class Vuer(PrefixProto, Server):
290
326
 
291
327
  Interface:
292
328
  <uri>/relay?sid=<websocket_id>
329
+
293
330
  :return:
294
331
  - Status 200
295
332
  - Status 400
296
333
 
297
-
298
334
  """
299
335
  # todo: need to implement msgpack encoding, interface
300
336
  bytes = request.bytes()
@@ -350,20 +386,18 @@ class Vuer(PrefixProto, Server):
350
386
  loop = asyncio.get_running_loop()
351
387
  return loop.create_task(task)
352
388
 
353
- def spawn(self, fn: Spawnable = None, start=False):
389
+ def spawn(self, fn: SocketHandler = None, start=False):
354
390
  """
355
- Spawn a function as a task. This is useful in the following scenario:
356
-
357
- code::
358
391
 
392
+ Note: this is really a misnomer.
359
393
 
360
394
  :param fn: The function to spawn.
361
395
  :param start: Start server after binding
362
396
  :return: None
363
397
  """
364
398
 
365
- def wrap_fn(fn: Spawnable):
366
- self.spawned_fn = fn
399
+ def wrap_fn(fn: SocketHandler):
400
+ self.socket_handler = fn
367
401
  if start:
368
402
  self.run()
369
403
 
@@ -375,7 +409,7 @@ class Vuer(PrefixProto, Server):
375
409
 
376
410
  def bind(self, fn=None, start=False):
377
411
  """
378
- Bind a function to the Tassa. The function should be a generator that yields Page objects.
412
+ Bind an asynchronous generator function for use in socket connection handler. The function should be a generator that yields Page objects.
379
413
 
380
414
  :param fn: The function to bind.
381
415
  :return: None
@@ -496,7 +530,7 @@ class Vuer(PrefixProto, Server):
496
530
  else:
497
531
  await sleep(0.0)
498
532
 
499
- async def downlink(self, request, ws):
533
+ async def downlink(self, request: Request, ws: WebSocketResponse):
500
534
  """
501
535
  The websocket handler for receiving messages from the client.
502
536
 
@@ -515,8 +549,18 @@ class Vuer(PrefixProto, Server):
515
549
 
516
550
  self._add_task(self.uplink(vuer_proxy))
517
551
 
518
- if self.spawned_fn is not None:
519
- task = self._add_task(self.spawned_fn(vuer_proxy))
552
+ if self.socket_handler is not None:
553
+
554
+ async def handler():
555
+ try:
556
+ await self.socket_handler(vuer_proxy)
557
+ except Exception:
558
+ await self.close_ws(ws_id)
559
+ return
560
+
561
+ await self.close_ws(ws_id)
562
+
563
+ task = self._add_task(handler())
520
564
 
521
565
  if hasattr(generator, "__anext__"):
522
566
  serverEvent = await generator.__anext__()
vuer/types.py CHANGED
@@ -16,7 +16,7 @@ EventHandler = Callable[[ClientEvent, "VuerProxy"], None]
16
16
  """Defines a function that handles a client event. Second argument is the VuerProxy instance bound
17
17
  to a specific client connected through a websocket session."""
18
18
 
19
- Spawnable = Callable[["VuerProxy"], Coroutine]
19
+ SocketHandler = Callable[["VuerProxy"], Coroutine]
20
20
  """Defines a function that spawns a new entity. Argument is the VuerProxy instance."""
21
21
 
22
22
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vuer
3
- Version: 0.0.17
3
+ Version: 0.0.19
4
4
  Home-page: https://github.com/geyang/vuer
5
5
  Author: Ge Yang<ge.ike.yang@gmail.com>
6
6
  Author-email: ge.ike.yang@gmail.com
@@ -3,15 +3,15 @@ vuer/base.py,sha256=R-PtD39ouihiEGmSfJL26chlU0XkFJP-JmBNYzDdEvM,3068
3
3
  vuer/events.py,sha256=8AAzkfbm5jHkeMh17Z57n8YTxF4mheWC3Qbya4XkQSc,7291
4
4
  vuer/schemas.py,sha256=aZOocE02gO43SLLfeYSxxac0x38TmyTcfs_iFh5hsJ4,18152
5
5
  vuer/serdes.py,sha256=gD2iA9Yypu1QjocneOT3Nc0y6q_mdHn9zW1ko5j3I7c,2600
6
- vuer/server.py,sha256=L57AATVFQpCrTyt3_bINixvMarEx9RkiRZeI4cHA2wE,19508
7
- vuer/types.py,sha256=TjRtc2UfRHTDBL0gTr7GGA9bh8FqMMU5Rk1DnJSQoew,1275
6
+ vuer/server.py,sha256=gIYbWwc-25JwtK9eeojQJtPSRMrCZ8rRcmZToDMnrpg,20851
7
+ vuer/types.py,sha256=N2KLa0fl6z8Jm6cJwZoD8Vqrins_AayG5BCGk1p3Eek,1279
8
8
  vuer/__pycache__/__init__.cpython-38.pyc,sha256=rS-9zzAjFEXnObk5q3E5Rex_uvoJ-Ccfz7Hs9DGNVgs,188
9
9
  vuer/__pycache__/base.cpython-38.pyc,sha256=Z5EFlRX9RqZsQUszvqPtAhLv_5QG5wlUXW7JbFd_XDc,3824
10
10
  vuer/__pycache__/events.cpython-38.pyc,sha256=zx3bXeJixqOyCFe2nA7qpq6jiCJ49kRaXO-xONGUyeQ,9616
11
11
  vuer/__pycache__/schemas.cpython-38.pyc,sha256=hvY9Aak8zE-zKcWiwuNe6DghOw9qH_zSe_FtkBOAPPk,23234
12
12
  vuer/__pycache__/serdes.cpython-38.pyc,sha256=KMxTjPEWuSGn2bqBAl5OLIDSCSoqfPDGfk3fvNnRDYA,2253
13
- vuer/__pycache__/server.cpython-38.pyc,sha256=1DKrzznGhC9ReG4UYlDED8GC-YKYOd-UhC5f_yD_BmA,18270
14
- vuer/__pycache__/types.cpython-38.pyc,sha256=OcUWJXEUF2K2w-pmEybOVKY7xJqjtr_N0UuyMIKzEG4,1815
13
+ vuer/__pycache__/server.cpython-38.pyc,sha256=z44pZ0u3x6ZLwDOh2skBFlvNEnGO2re4cdhRAippzy0,19636
14
+ vuer/__pycache__/types.cpython-38.pyc,sha256=IhlXtkT-XWM0V1420FDuoqIYnpvRvekYVkGqEK7fAV8,1819
15
15
  vuer/addons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  vuer/addons/nerf_vuer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  vuer/addons/nerf_vuer/control_components.py,sha256=K4PU0nD572L4J7lLFfShWficWZQnH4t-x6WWMrAVw8g,290
@@ -22,16 +22,16 @@ vuer/addons/nerf_vuer/render_nodes.py,sha256=5TKqIbMPiOtBxfF4FQI6uB0w_9FTfGiwS8x
22
22
  vuer/addons/nerfuer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  vuer/addons/nerfuer/render_nodes.py,sha256=EJK5N3xne5n7abTaAoLPX7SRqQ_tEen9zNypvSnZTTw,4465
24
24
  vuer/schemas/__init__.py,sha256=ZI6UyeLZXqJbHmp6LiE3Q3mHvt1zeV-SJmmcqq-wBZE,94
25
- vuer/schemas/drei_components.py,sha256=Y8c7Oey3IYkJxoSwaH7ry4MfwVfzW6MlSeb6muzVXec,6977
26
- vuer/schemas/html_components.py,sha256=tS_RxkuiAFMdFCJLL7xKaOganvRiYTqgb4j5At76yrY,5925
27
- vuer/schemas/scene_components.py,sha256=vK1ZvgNGf0u43TmGNtdKrRXHh7774lZu7retXBQLJOs,12338
25
+ vuer/schemas/drei_components.py,sha256=U9svEOnNprhZaobLagaFnqEtZxo5hiriSqjDnvQutoA,6989
26
+ vuer/schemas/html_components.py,sha256=NCqmSPic-ExPrXqNPXbKjtTXMB8sGBywIpE6cXpiy08,5926
27
+ vuer/schemas/scene_components.py,sha256=L9GbgFnrhxUYKi4EyexaAun7gmn6aHnCQIeSGSGwIRU,14913
28
28
  vuer/schemas/__pycache__/__init__.cpython-38.pyc,sha256=NRnVrpIDBKne93xOUY1-WpavCG7vwYiqU3VDTEEwuUE,221
29
- vuer/schemas/__pycache__/drei_components.cpython-38.pyc,sha256=gSH1mBOidXpib8V9d2PjRlwhLsbzNZdGR9BG1agIhuo,7700
30
- vuer/schemas/__pycache__/html_components.cpython-38.pyc,sha256=MzfeVcGa2fMgFh_g0qphppvXscmgL8egJQci2Y5dATw,8214
31
- vuer/schemas/__pycache__/scene_components.cpython-38.pyc,sha256=eN-zQIxYDeFsBiKuOeXPh2Q5z24IskdiCBacE_numJg,15548
32
- vuer-0.0.17.dist-info/LICENSE,sha256=MGF-inVBUaGe2mEjqT0g6XsHIXwoNXgNHqD7Z1MzR0k,1063
33
- vuer-0.0.17.dist-info/METADATA,sha256=zHj5jx1Y0W5nhwobQXXFLoT721bXzF4c1wUdy90P0Zo,4277
34
- vuer-0.0.17.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
35
- vuer-0.0.17.dist-info/entry_points.txt,sha256=J_NM6fbpipmD9oP7cdxd1UyBR8mVEQVx0xjlE_56yss,41
36
- vuer-0.0.17.dist-info/top_level.txt,sha256=ermmVkwvGFAK4gfSgDIwOmKpxwpqNt-oo7gVQQUSHok,5
37
- vuer-0.0.17.dist-info/RECORD,,
29
+ vuer/schemas/__pycache__/drei_components.cpython-38.pyc,sha256=g_ufcKxf-XKfZLdUV-HqKnjIrgxGWFv51aHLWQgH-ws,7712
30
+ vuer/schemas/__pycache__/html_components.cpython-38.pyc,sha256=q0DMFwNkYbnaH1A8w3BowMiQAlmGpFWOOKsjLVE6CIk,8215
31
+ vuer/schemas/__pycache__/scene_components.cpython-38.pyc,sha256=eRxB-Tp24yqBR4zbLMGX_4o1P_D-tW1nrDeBPSJKoU4,18135
32
+ vuer-0.0.19.dist-info/LICENSE,sha256=MGF-inVBUaGe2mEjqT0g6XsHIXwoNXgNHqD7Z1MzR0k,1063
33
+ vuer-0.0.19.dist-info/METADATA,sha256=IY8XfDtcj6-Z8xww_0qN2r9Nh-1_j01_63eGS2OLoto,4277
34
+ vuer-0.0.19.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
35
+ vuer-0.0.19.dist-info/entry_points.txt,sha256=J_NM6fbpipmD9oP7cdxd1UyBR8mVEQVx0xjlE_56yss,41
36
+ vuer-0.0.19.dist-info/top_level.txt,sha256=ermmVkwvGFAK4gfSgDIwOmKpxwpqNt-oo7gVQQUSHok,5
37
+ vuer-0.0.19.dist-info/RECORD,,
File without changes
File without changes