threejs-viewer 0.0.76__tar.gz → 0.0.78__tar.gz
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.
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/.gitignore +1 -1
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/PKG-INFO +68 -1
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/README.md +67 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/__init__.py +2 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/client.py +430 -2
- threejs_viewer-0.0.78/src/threejs_viewer/vector.py +470 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/viewer/controls.js +89 -14
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/viewer/template.html +30 -30
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/viewer/viewer.css +42 -27
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/viewer/viewer.js +1464 -54
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/viewer.html +1625 -125
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/DESIGN.md +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/THIRD_PARTY_NOTICES.md +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/pyproject.toml +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/__main__.py +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/_colormap_data.py +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/animation.py +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/kinematics.py +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/points_lod.py +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/toolpath.py +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/usd.py +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/viewer/build.py +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/viewer/static/cubemaps/index.json +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/viewer/static/cubemaps/paul-lobe-haus/nx.hdr +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/viewer/static/cubemaps/paul-lobe-haus/ny.hdr +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/viewer/static/cubemaps/paul-lobe-haus/nz.hdr +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/viewer/static/cubemaps/paul-lobe-haus/px.hdr +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/viewer/static/cubemaps/paul-lobe-haus/py.hdr +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/viewer/static/cubemaps/paul-lobe-haus/pz.hdr +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/viewer/static/draco/draco_decoder.wasm +0 -0
- {threejs_viewer-0.0.76 → threejs_viewer-0.0.78}/src/threejs_viewer/viewer/static/draco/draco_wasm_wrapper.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: threejs-viewer
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.78
|
|
4
4
|
Summary: Lightweight Three.js viewer controlled from Python via WebSocket
|
|
5
5
|
Project-URL: Homepage, https://github.com/thijsdamsma/threejs-viewer
|
|
6
6
|
Project-URL: Repository, https://github.com/thijsdamsma/threejs-viewer
|
|
@@ -173,6 +173,60 @@ v.set_opacity("box1", 0.5)
|
|
|
173
173
|
v.set_color("ball", 0xFF0000, opacity=0.3)
|
|
174
174
|
```
|
|
175
175
|
|
|
176
|
+
### Vector entities (DXF-style curves)
|
|
177
|
+
|
|
178
|
+
Circles, arcs, ellipses, NURBS splines, polylines with DXF bulges, lines and
|
|
179
|
+
points keep their exact definitions in the viewer and re-tessellate as the
|
|
180
|
+
camera moves, so they stay smooth at any zoom. Layers and linetypes work as
|
|
181
|
+
in DXF: entities default to their layer's colour, linetype and width.
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
import math
|
|
185
|
+
from threejs_viewer import vector
|
|
186
|
+
|
|
187
|
+
v.set_layer("CENTER", color=0xFF6E6E, linetype="CENTER", line_width=1)
|
|
188
|
+
v.set_linetype("MYDASH", [0.01, -0.005, 0, -0.005]) # dash, gap, dot, gap (scene units)
|
|
189
|
+
|
|
190
|
+
v.add_circle("hole", [0, 0, 0], 0.035, color=0x5AB4FF)
|
|
191
|
+
v.add_arc("arc", [0, 0, 0], 0.09, 0, math.pi / 2, layer="CENTER")
|
|
192
|
+
v.add_spline("cam", control_points, degree=3, weights=w, closed=True)
|
|
193
|
+
|
|
194
|
+
# Many entities in one object, batched into a few draw calls per layer
|
|
195
|
+
v.add_vector_entities("drawing", [
|
|
196
|
+
vector.line([-0.1, 0, 0], [0.1, 0, 0], layer="CENTER"),
|
|
197
|
+
vector.polyline(slot_corners, bulges=[0, 1, 0, 1], closed=True),
|
|
198
|
+
vector.ellipse([0, 0, 0], [0.02, 0, 0], 0.5, linetype="MYDASH"),
|
|
199
|
+
])
|
|
200
|
+
v.set_layer("CENTER", visible=False) # hides the layer in every object
|
|
201
|
+
|
|
202
|
+
# Blocks and inserts (DXF BLOCK / INSERT / MINSERT): define once, place many
|
|
203
|
+
# times. The block is tessellated once per detail level; copies are transformed.
|
|
204
|
+
v.add_vector_entities(
|
|
205
|
+
"bolt_pattern",
|
|
206
|
+
[vector.insert("HOLE", bolt_centres, layer="HOLES"),
|
|
207
|
+
vector.insert("HOLE", [0, 0, 0], rows=4, columns=6,
|
|
208
|
+
row_spacing=0.02, column_spacing=0.02, scale=0.5)],
|
|
209
|
+
blocks={"HOLE": [vector.circle([0, 0, 0], 0.004), vector.circle([0, 0, 0], 0.006, linetype="HIDDEN")]},
|
|
210
|
+
)
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
`examples/42_vector_entities.py` draws a flange with bolt holes, slots, centre
|
|
214
|
+
lines and a NURBS cam.
|
|
215
|
+
|
|
216
|
+
Layers and linetypes are viewer-wide: every vector object, including those
|
|
217
|
+
loaded from glTF files, shares one table per name. A curve piece is drawn with
|
|
218
|
+
at most 8192 segments, so a very large arc viewed at extreme zoom (radius above
|
|
219
|
+
roughly ten million pixels) shows facets. `set_highlight` draws nothing on
|
|
220
|
+
vector objects.
|
|
221
|
+
|
|
222
|
+
glTF and GLB files can carry the same entities in root
|
|
223
|
+
`extras.TJSV_vector_entities` (the only place that survives glTF-Transform,
|
|
224
|
+
Draco included). `add_model` / `add_model_binary` draw them with the model,
|
|
225
|
+
merge the file's layers and linetypes (tables set from Python win), and hide
|
|
226
|
+
fallback line primitives whose material extras carry
|
|
227
|
+
`{"TJSV_vector_entities": {"fallback": true}}`. The format is described in
|
|
228
|
+
`plans/gltf-vector-entities.md`.
|
|
229
|
+
|
|
176
230
|
### USD BRep geometry
|
|
177
231
|
|
|
178
232
|
```python
|
|
@@ -332,6 +386,19 @@ client.add_model_binary("fox", "fox.glb", format="glb")
|
|
|
332
386
|
client.set_clip_time("fox", 1.5)
|
|
333
387
|
```
|
|
334
388
|
|
|
389
|
+
### Draw layers for coplanar glTF meshes
|
|
390
|
+
|
|
391
|
+
Surfaces that share a plane in one model (a floor, a path painted on it,
|
|
392
|
+
borders on the path) flicker against each other. Give each node an integer
|
|
393
|
+
`extras.draw_layer` from 0 to 15 (in Blender, an object custom property with
|
|
394
|
+
"Include > Custom Properties" ticked on export). A higher layer always draws
|
|
395
|
+
over a lower one in the same plane, for opaque and for transparent materials.
|
|
396
|
+
Depth testing against the rest of the scene stays on, so a wall in front still
|
|
397
|
+
hides the floor. The value must be a number; anything else is ignored with a
|
|
398
|
+
console warning. Nodes inherit the
|
|
399
|
+
layer of their nearest ancestor that sets one, and nodes without the property
|
|
400
|
+
draw as before.
|
|
401
|
+
|
|
335
402
|
## Documentation
|
|
336
403
|
|
|
337
404
|
- [DESIGN.md](DESIGN.md) - Architecture and protocol details
|
|
@@ -150,6 +150,60 @@ v.set_opacity("box1", 0.5)
|
|
|
150
150
|
v.set_color("ball", 0xFF0000, opacity=0.3)
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
+
### Vector entities (DXF-style curves)
|
|
154
|
+
|
|
155
|
+
Circles, arcs, ellipses, NURBS splines, polylines with DXF bulges, lines and
|
|
156
|
+
points keep their exact definitions in the viewer and re-tessellate as the
|
|
157
|
+
camera moves, so they stay smooth at any zoom. Layers and linetypes work as
|
|
158
|
+
in DXF: entities default to their layer's colour, linetype and width.
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
import math
|
|
162
|
+
from threejs_viewer import vector
|
|
163
|
+
|
|
164
|
+
v.set_layer("CENTER", color=0xFF6E6E, linetype="CENTER", line_width=1)
|
|
165
|
+
v.set_linetype("MYDASH", [0.01, -0.005, 0, -0.005]) # dash, gap, dot, gap (scene units)
|
|
166
|
+
|
|
167
|
+
v.add_circle("hole", [0, 0, 0], 0.035, color=0x5AB4FF)
|
|
168
|
+
v.add_arc("arc", [0, 0, 0], 0.09, 0, math.pi / 2, layer="CENTER")
|
|
169
|
+
v.add_spline("cam", control_points, degree=3, weights=w, closed=True)
|
|
170
|
+
|
|
171
|
+
# Many entities in one object, batched into a few draw calls per layer
|
|
172
|
+
v.add_vector_entities("drawing", [
|
|
173
|
+
vector.line([-0.1, 0, 0], [0.1, 0, 0], layer="CENTER"),
|
|
174
|
+
vector.polyline(slot_corners, bulges=[0, 1, 0, 1], closed=True),
|
|
175
|
+
vector.ellipse([0, 0, 0], [0.02, 0, 0], 0.5, linetype="MYDASH"),
|
|
176
|
+
])
|
|
177
|
+
v.set_layer("CENTER", visible=False) # hides the layer in every object
|
|
178
|
+
|
|
179
|
+
# Blocks and inserts (DXF BLOCK / INSERT / MINSERT): define once, place many
|
|
180
|
+
# times. The block is tessellated once per detail level; copies are transformed.
|
|
181
|
+
v.add_vector_entities(
|
|
182
|
+
"bolt_pattern",
|
|
183
|
+
[vector.insert("HOLE", bolt_centres, layer="HOLES"),
|
|
184
|
+
vector.insert("HOLE", [0, 0, 0], rows=4, columns=6,
|
|
185
|
+
row_spacing=0.02, column_spacing=0.02, scale=0.5)],
|
|
186
|
+
blocks={"HOLE": [vector.circle([0, 0, 0], 0.004), vector.circle([0, 0, 0], 0.006, linetype="HIDDEN")]},
|
|
187
|
+
)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
`examples/42_vector_entities.py` draws a flange with bolt holes, slots, centre
|
|
191
|
+
lines and a NURBS cam.
|
|
192
|
+
|
|
193
|
+
Layers and linetypes are viewer-wide: every vector object, including those
|
|
194
|
+
loaded from glTF files, shares one table per name. A curve piece is drawn with
|
|
195
|
+
at most 8192 segments, so a very large arc viewed at extreme zoom (radius above
|
|
196
|
+
roughly ten million pixels) shows facets. `set_highlight` draws nothing on
|
|
197
|
+
vector objects.
|
|
198
|
+
|
|
199
|
+
glTF and GLB files can carry the same entities in root
|
|
200
|
+
`extras.TJSV_vector_entities` (the only place that survives glTF-Transform,
|
|
201
|
+
Draco included). `add_model` / `add_model_binary` draw them with the model,
|
|
202
|
+
merge the file's layers and linetypes (tables set from Python win), and hide
|
|
203
|
+
fallback line primitives whose material extras carry
|
|
204
|
+
`{"TJSV_vector_entities": {"fallback": true}}`. The format is described in
|
|
205
|
+
`plans/gltf-vector-entities.md`.
|
|
206
|
+
|
|
153
207
|
### USD BRep geometry
|
|
154
208
|
|
|
155
209
|
```python
|
|
@@ -309,6 +363,19 @@ client.add_model_binary("fox", "fox.glb", format="glb")
|
|
|
309
363
|
client.set_clip_time("fox", 1.5)
|
|
310
364
|
```
|
|
311
365
|
|
|
366
|
+
### Draw layers for coplanar glTF meshes
|
|
367
|
+
|
|
368
|
+
Surfaces that share a plane in one model (a floor, a path painted on it,
|
|
369
|
+
borders on the path) flicker against each other. Give each node an integer
|
|
370
|
+
`extras.draw_layer` from 0 to 15 (in Blender, an object custom property with
|
|
371
|
+
"Include > Custom Properties" ticked on export). A higher layer always draws
|
|
372
|
+
over a lower one in the same plane, for opaque and for transparent materials.
|
|
373
|
+
Depth testing against the rest of the scene stays on, so a wall in front still
|
|
374
|
+
hides the floor. The value must be a number; anything else is ignored with a
|
|
375
|
+
console warning. Nodes inherit the
|
|
376
|
+
layer of their nearest ancestor that sets one, and nodes without the property
|
|
377
|
+
draw as before.
|
|
378
|
+
|
|
312
379
|
## Documentation
|
|
313
380
|
|
|
314
381
|
- [DESIGN.md](DESIGN.md) - Architecture and protocol details
|
|
@@ -16,6 +16,7 @@ from .animation import (
|
|
|
16
16
|
merge_animation_points,
|
|
17
17
|
toolpath_frame_times,
|
|
18
18
|
)
|
|
19
|
+
from . import vector
|
|
19
20
|
from .client import ViewerClient, viewer
|
|
20
21
|
from .toolpath import Toolpath
|
|
21
22
|
|
|
@@ -29,6 +30,7 @@ __all__ = [
|
|
|
29
30
|
"merge_animation_points",
|
|
30
31
|
"toolpath_frame_times",
|
|
31
32
|
"Toolpath",
|
|
33
|
+
"vector",
|
|
32
34
|
]
|
|
33
35
|
|
|
34
36
|
try:
|
|
@@ -20,12 +20,12 @@ import uuid
|
|
|
20
20
|
import webbrowser
|
|
21
21
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
22
22
|
from pathlib import Path
|
|
23
|
-
from typing import Any, Dict, List, Literal, Optional, Tuple, Union
|
|
23
|
+
from typing import Any, Dict, List, Literal, Optional, Sequence, Tuple, Union
|
|
24
24
|
|
|
25
25
|
import numpy as np
|
|
26
26
|
from websockets.sync.server import serve as sync_serve
|
|
27
27
|
|
|
28
|
-
from . import kinematics
|
|
28
|
+
from . import kinematics, vector
|
|
29
29
|
from .points_lod import (
|
|
30
30
|
DEFAULT_MAX_DEPTH,
|
|
31
31
|
DEFAULT_NODE_CAPACITY,
|
|
@@ -921,6 +921,10 @@ class ViewerClient:
|
|
|
921
921
|
# interactive gizmo above; any number can be active at once, each with its
|
|
922
922
|
# own axis constraint. Re-sent on reconnect so they survive a refresh.
|
|
923
923
|
self._gizmos: List[dict] = []
|
|
924
|
+
# Vector-entity linetypes and layers (set_linetype / set_layer),
|
|
925
|
+
# name -> merged message, replayed on reconnect (linetypes first).
|
|
926
|
+
self._vector_linetypes: Dict[str, dict] = {}
|
|
927
|
+
self._vector_layers: Dict[str, dict] = {}
|
|
924
928
|
|
|
925
929
|
def connect(self, timeout: float = 30.0):
|
|
926
930
|
"""Start WebSocket server and wait for browser to connect.
|
|
@@ -1238,6 +1242,13 @@ class ViewerClient:
|
|
|
1238
1242
|
except Exception:
|
|
1239
1243
|
pass
|
|
1240
1244
|
|
|
1245
|
+
# Re-declare vector linetypes, then the layers that may use them.
|
|
1246
|
+
for spec in [*self._vector_linetypes.values(), *self._vector_layers.values()]:
|
|
1247
|
+
try:
|
|
1248
|
+
websocket.send(json.dumps(spec))
|
|
1249
|
+
except Exception:
|
|
1250
|
+
pass
|
|
1251
|
+
|
|
1241
1252
|
try:
|
|
1242
1253
|
for message in websocket:
|
|
1243
1254
|
try:
|
|
@@ -2197,6 +2208,423 @@ class ViewerClient:
|
|
|
2197
2208
|
header["transform"] = transform
|
|
2198
2209
|
self._send_binary(header, raw_bytes)
|
|
2199
2210
|
|
|
2211
|
+
# === Vector entities ===
|
|
2212
|
+
|
|
2213
|
+
def add_vector_entities(
|
|
2214
|
+
self,
|
|
2215
|
+
id: str,
|
|
2216
|
+
entities: List[dict],
|
|
2217
|
+
*,
|
|
2218
|
+
layer: Optional[str] = None,
|
|
2219
|
+
color: Optional[int] = None,
|
|
2220
|
+
linetype: Optional[str] = None,
|
|
2221
|
+
line_width: Optional[float] = None,
|
|
2222
|
+
linetype_scale: Optional[float] = None,
|
|
2223
|
+
blocks: Optional[Dict[str, List[dict]]] = None,
|
|
2224
|
+
parent: Optional[str] = None,
|
|
2225
|
+
position: Optional[List[float]] = None,
|
|
2226
|
+
rotation: Optional[List[float]] = None,
|
|
2227
|
+
scale: Optional[List[float]] = None,
|
|
2228
|
+
matrix: Optional[List[float]] = None,
|
|
2229
|
+
visible: bool = True,
|
|
2230
|
+
pickable: bool = True,
|
|
2231
|
+
) -> None:
|
|
2232
|
+
"""Add (or replace) one object holding any number of vector entities.
|
|
2233
|
+
|
|
2234
|
+
Entities are exact curves built with :mod:`threejs_viewer.vector`
|
|
2235
|
+
(``point``, ``points``, ``line``, ``polyline`` with DXF bulges,
|
|
2236
|
+
``circle``, ``arc``, ``ellipse``, ``spline``). The viewer keeps their
|
|
2237
|
+
definitions and re-tessellates them as the camera moves, so curves
|
|
2238
|
+
stay within about half a pixel of their true shape at any zoom.
|
|
2239
|
+
|
|
2240
|
+
Styling follows DXF: each entity sits on a layer (default ``"0"``),
|
|
2241
|
+
and colour, linetype and line width fall back to the layer's settings
|
|
2242
|
+
from :meth:`set_layer`. ``layer``, ``color``, ``linetype``,
|
|
2243
|
+
``line_width`` and ``linetype_scale`` given here apply to entities
|
|
2244
|
+
that don't set their own. ``line_width`` is in screen pixels.
|
|
2245
|
+
|
|
2246
|
+
``blocks`` maps a block name to a list of entities, drawn wherever a
|
|
2247
|
+
:func:`threejs_viewer.vector.insert` places it (DXF ``BLOCK`` and
|
|
2248
|
+
``INSERT``). A block is tessellated once per detail level and its
|
|
2249
|
+
placements are transformed copies, so a pattern of thousands of
|
|
2250
|
+
identical holes costs about as much as one hole to refine.
|
|
2251
|
+
|
|
2252
|
+
Entities sharing a layer, linetype and width draw as one batch, so
|
|
2253
|
+
thousands of entities in one call stay cheap. An invalid entity that
|
|
2254
|
+
reaches the viewer is skipped with a console warning; the rest draw.
|
|
2255
|
+
|
|
2256
|
+
Args:
|
|
2257
|
+
id: Object id; replaces an existing object with the same id.
|
|
2258
|
+
entities: Entity dicts from :mod:`threejs_viewer.vector`.
|
|
2259
|
+
parent: Optional parent group id.
|
|
2260
|
+
position, rotation, scale: Object transform (Euler radians).
|
|
2261
|
+
matrix: Column-major 4x4 transform instead of position/rotation/scale.
|
|
2262
|
+
visible: Initial visibility.
|
|
2263
|
+
pickable: When False, clicks pass through the object.
|
|
2264
|
+
"""
|
|
2265
|
+
ents = list(entities)
|
|
2266
|
+
for i, e in enumerate(ents):
|
|
2267
|
+
if not isinstance(e, dict) or not isinstance(e.get("type"), str):
|
|
2268
|
+
raise ValueError(f"entities[{i}] must be an entity dict with a 'type'")
|
|
2269
|
+
spec: dict = vector._style(
|
|
2270
|
+
{"entities": ents}, layer, color, linetype, line_width, linetype_scale
|
|
2271
|
+
)
|
|
2272
|
+
vector.check_blocks(ents, blocks or {})
|
|
2273
|
+
if blocks:
|
|
2274
|
+
spec["blocks"] = {name: list(b) for name, b in blocks.items()}
|
|
2275
|
+
if not pickable:
|
|
2276
|
+
spec["pickable"] = False
|
|
2277
|
+
transform: dict = {}
|
|
2278
|
+
if matrix is not None:
|
|
2279
|
+
m = np.asarray(matrix, dtype=float).reshape(-1)
|
|
2280
|
+
if m.shape != (16,) or not np.all(np.isfinite(m)):
|
|
2281
|
+
raise ValueError("matrix must be 16 finite numbers")
|
|
2282
|
+
transform["matrix"] = m.tolist()
|
|
2283
|
+
else:
|
|
2284
|
+
if position is not None:
|
|
2285
|
+
transform["position"] = vector._vec3("position", position)
|
|
2286
|
+
if rotation is not None:
|
|
2287
|
+
transform["rotation"] = vector._vec3("rotation", rotation)
|
|
2288
|
+
if scale is not None:
|
|
2289
|
+
transform["scale"] = vector._vec3("scale", scale)
|
|
2290
|
+
msg: dict = {
|
|
2291
|
+
"type": "add_object",
|
|
2292
|
+
"id": id,
|
|
2293
|
+
"object": {"vector": spec, "transform": transform or None},
|
|
2294
|
+
}
|
|
2295
|
+
if parent:
|
|
2296
|
+
msg["parent"] = parent
|
|
2297
|
+
if not visible:
|
|
2298
|
+
msg["visible"] = False
|
|
2299
|
+
msg["object"]["visible"] = False
|
|
2300
|
+
self._send(msg)
|
|
2301
|
+
|
|
2302
|
+
def add_line(
|
|
2303
|
+
self,
|
|
2304
|
+
id: str,
|
|
2305
|
+
start: List[float],
|
|
2306
|
+
end: List[float],
|
|
2307
|
+
*,
|
|
2308
|
+
layer: Optional[str] = None,
|
|
2309
|
+
color: Optional[int] = None,
|
|
2310
|
+
linetype: Optional[str] = None,
|
|
2311
|
+
line_width: Optional[float] = None,
|
|
2312
|
+
linetype_scale: Optional[float] = None,
|
|
2313
|
+
parent: Optional[str] = None,
|
|
2314
|
+
position: Optional[List[float]] = None,
|
|
2315
|
+
rotation: Optional[List[float]] = None,
|
|
2316
|
+
scale: Optional[List[float]] = None,
|
|
2317
|
+
matrix: Optional[List[float]] = None,
|
|
2318
|
+
visible: bool = True,
|
|
2319
|
+
pickable: bool = True,
|
|
2320
|
+
) -> None:
|
|
2321
|
+
"""Add a straight vector line. See :meth:`add_vector_entities` for
|
|
2322
|
+
styling and for the ``parent``/``position``/``rotation``/``scale``/
|
|
2323
|
+
``matrix``/``visible``/``pickable`` placement keywords."""
|
|
2324
|
+
entity = vector.line(
|
|
2325
|
+
start,
|
|
2326
|
+
end,
|
|
2327
|
+
layer=layer,
|
|
2328
|
+
color=color,
|
|
2329
|
+
linetype=linetype,
|
|
2330
|
+
line_width=line_width,
|
|
2331
|
+
linetype_scale=linetype_scale,
|
|
2332
|
+
)
|
|
2333
|
+
self.add_vector_entities(
|
|
2334
|
+
id,
|
|
2335
|
+
[entity],
|
|
2336
|
+
parent=parent,
|
|
2337
|
+
position=position,
|
|
2338
|
+
rotation=rotation,
|
|
2339
|
+
scale=scale,
|
|
2340
|
+
matrix=matrix,
|
|
2341
|
+
visible=visible,
|
|
2342
|
+
pickable=pickable,
|
|
2343
|
+
)
|
|
2344
|
+
|
|
2345
|
+
def add_circle(
|
|
2346
|
+
self,
|
|
2347
|
+
id: str,
|
|
2348
|
+
center: List[float] = (0.0, 0.0, 0.0),
|
|
2349
|
+
radius: float = 1.0,
|
|
2350
|
+
*,
|
|
2351
|
+
normal: Optional[List[float]] = None,
|
|
2352
|
+
layer: Optional[str] = None,
|
|
2353
|
+
color: Optional[int] = None,
|
|
2354
|
+
linetype: Optional[str] = None,
|
|
2355
|
+
line_width: Optional[float] = None,
|
|
2356
|
+
linetype_scale: Optional[float] = None,
|
|
2357
|
+
parent: Optional[str] = None,
|
|
2358
|
+
position: Optional[List[float]] = None,
|
|
2359
|
+
rotation: Optional[List[float]] = None,
|
|
2360
|
+
scale: Optional[List[float]] = None,
|
|
2361
|
+
matrix: Optional[List[float]] = None,
|
|
2362
|
+
visible: bool = True,
|
|
2363
|
+
pickable: bool = True,
|
|
2364
|
+
) -> None:
|
|
2365
|
+
"""Add a circle that stays smooth at any zoom.
|
|
2366
|
+
|
|
2367
|
+
The circle lies in the plane through ``center`` perpendicular to
|
|
2368
|
+
``normal`` (default +Z). See :meth:`add_vector_entities` for styling
|
|
2369
|
+
and the placement keywords.
|
|
2370
|
+
"""
|
|
2371
|
+
entity = vector.circle(
|
|
2372
|
+
center,
|
|
2373
|
+
radius,
|
|
2374
|
+
normal=normal,
|
|
2375
|
+
layer=layer,
|
|
2376
|
+
color=color,
|
|
2377
|
+
linetype=linetype,
|
|
2378
|
+
line_width=line_width,
|
|
2379
|
+
linetype_scale=linetype_scale,
|
|
2380
|
+
)
|
|
2381
|
+
self.add_vector_entities(
|
|
2382
|
+
id,
|
|
2383
|
+
[entity],
|
|
2384
|
+
parent=parent,
|
|
2385
|
+
position=position,
|
|
2386
|
+
rotation=rotation,
|
|
2387
|
+
scale=scale,
|
|
2388
|
+
matrix=matrix,
|
|
2389
|
+
visible=visible,
|
|
2390
|
+
pickable=pickable,
|
|
2391
|
+
)
|
|
2392
|
+
|
|
2393
|
+
def add_arc(
|
|
2394
|
+
self,
|
|
2395
|
+
id: str,
|
|
2396
|
+
center: List[float],
|
|
2397
|
+
radius: float,
|
|
2398
|
+
start_angle: float,
|
|
2399
|
+
end_angle: float,
|
|
2400
|
+
*,
|
|
2401
|
+
normal: Optional[List[float]] = None,
|
|
2402
|
+
layer: Optional[str] = None,
|
|
2403
|
+
color: Optional[int] = None,
|
|
2404
|
+
linetype: Optional[str] = None,
|
|
2405
|
+
line_width: Optional[float] = None,
|
|
2406
|
+
linetype_scale: Optional[float] = None,
|
|
2407
|
+
parent: Optional[str] = None,
|
|
2408
|
+
position: Optional[List[float]] = None,
|
|
2409
|
+
rotation: Optional[List[float]] = None,
|
|
2410
|
+
scale: Optional[List[float]] = None,
|
|
2411
|
+
matrix: Optional[List[float]] = None,
|
|
2412
|
+
visible: bool = True,
|
|
2413
|
+
pickable: bool = True,
|
|
2414
|
+
) -> None:
|
|
2415
|
+
"""Add a circular arc, counter-clockwise about ``normal`` from
|
|
2416
|
+
``start_angle`` to ``end_angle`` (radians, DXF ``ARC`` convention).
|
|
2417
|
+
See :meth:`add_vector_entities` for styling and placement."""
|
|
2418
|
+
entity = vector.arc(
|
|
2419
|
+
center,
|
|
2420
|
+
radius,
|
|
2421
|
+
start_angle,
|
|
2422
|
+
end_angle,
|
|
2423
|
+
normal=normal,
|
|
2424
|
+
layer=layer,
|
|
2425
|
+
color=color,
|
|
2426
|
+
linetype=linetype,
|
|
2427
|
+
line_width=line_width,
|
|
2428
|
+
linetype_scale=linetype_scale,
|
|
2429
|
+
)
|
|
2430
|
+
self.add_vector_entities(
|
|
2431
|
+
id,
|
|
2432
|
+
[entity],
|
|
2433
|
+
parent=parent,
|
|
2434
|
+
position=position,
|
|
2435
|
+
rotation=rotation,
|
|
2436
|
+
scale=scale,
|
|
2437
|
+
matrix=matrix,
|
|
2438
|
+
visible=visible,
|
|
2439
|
+
pickable=pickable,
|
|
2440
|
+
)
|
|
2441
|
+
|
|
2442
|
+
def add_ellipse(
|
|
2443
|
+
self,
|
|
2444
|
+
id: str,
|
|
2445
|
+
center: List[float],
|
|
2446
|
+
major_axis: List[float],
|
|
2447
|
+
ratio: float,
|
|
2448
|
+
*,
|
|
2449
|
+
start_param: float = 0.0,
|
|
2450
|
+
end_param: float = 2 * math.pi,
|
|
2451
|
+
normal: Optional[List[float]] = None,
|
|
2452
|
+
layer: Optional[str] = None,
|
|
2453
|
+
color: Optional[int] = None,
|
|
2454
|
+
linetype: Optional[str] = None,
|
|
2455
|
+
line_width: Optional[float] = None,
|
|
2456
|
+
linetype_scale: Optional[float] = None,
|
|
2457
|
+
parent: Optional[str] = None,
|
|
2458
|
+
position: Optional[List[float]] = None,
|
|
2459
|
+
rotation: Optional[List[float]] = None,
|
|
2460
|
+
scale: Optional[List[float]] = None,
|
|
2461
|
+
matrix: Optional[List[float]] = None,
|
|
2462
|
+
visible: bool = True,
|
|
2463
|
+
pickable: bool = True,
|
|
2464
|
+
) -> None:
|
|
2465
|
+
"""Add an ellipse or elliptical arc (DXF ``ELLIPSE``); see
|
|
2466
|
+
:func:`threejs_viewer.vector.ellipse` for the parameters and
|
|
2467
|
+
:meth:`add_vector_entities` for styling and placement."""
|
|
2468
|
+
entity = vector.ellipse(
|
|
2469
|
+
center,
|
|
2470
|
+
major_axis,
|
|
2471
|
+
ratio,
|
|
2472
|
+
start_param=start_param,
|
|
2473
|
+
end_param=end_param,
|
|
2474
|
+
normal=normal,
|
|
2475
|
+
layer=layer,
|
|
2476
|
+
color=color,
|
|
2477
|
+
linetype=linetype,
|
|
2478
|
+
line_width=line_width,
|
|
2479
|
+
linetype_scale=linetype_scale,
|
|
2480
|
+
)
|
|
2481
|
+
self.add_vector_entities(
|
|
2482
|
+
id,
|
|
2483
|
+
[entity],
|
|
2484
|
+
parent=parent,
|
|
2485
|
+
position=position,
|
|
2486
|
+
rotation=rotation,
|
|
2487
|
+
scale=scale,
|
|
2488
|
+
matrix=matrix,
|
|
2489
|
+
visible=visible,
|
|
2490
|
+
pickable=pickable,
|
|
2491
|
+
)
|
|
2492
|
+
|
|
2493
|
+
def add_spline(
|
|
2494
|
+
self,
|
|
2495
|
+
id: str,
|
|
2496
|
+
control_points,
|
|
2497
|
+
*,
|
|
2498
|
+
degree: int = 3,
|
|
2499
|
+
knots: Optional[List[float]] = None,
|
|
2500
|
+
weights: Optional[List[float]] = None,
|
|
2501
|
+
closed: bool = False,
|
|
2502
|
+
layer: Optional[str] = None,
|
|
2503
|
+
color: Optional[int] = None,
|
|
2504
|
+
linetype: Optional[str] = None,
|
|
2505
|
+
line_width: Optional[float] = None,
|
|
2506
|
+
linetype_scale: Optional[float] = None,
|
|
2507
|
+
parent: Optional[str] = None,
|
|
2508
|
+
position: Optional[List[float]] = None,
|
|
2509
|
+
rotation: Optional[List[float]] = None,
|
|
2510
|
+
scale: Optional[List[float]] = None,
|
|
2511
|
+
matrix: Optional[List[float]] = None,
|
|
2512
|
+
visible: bool = True,
|
|
2513
|
+
pickable: bool = True,
|
|
2514
|
+
) -> None:
|
|
2515
|
+
"""Add a NURBS curve (DXF ``SPLINE``); see
|
|
2516
|
+
:func:`threejs_viewer.vector.spline` for the parameters and
|
|
2517
|
+
:meth:`add_vector_entities` for styling and placement."""
|
|
2518
|
+
entity = vector.spline(
|
|
2519
|
+
control_points,
|
|
2520
|
+
degree=degree,
|
|
2521
|
+
knots=knots,
|
|
2522
|
+
weights=weights,
|
|
2523
|
+
closed=closed,
|
|
2524
|
+
layer=layer,
|
|
2525
|
+
color=color,
|
|
2526
|
+
linetype=linetype,
|
|
2527
|
+
line_width=line_width,
|
|
2528
|
+
linetype_scale=linetype_scale,
|
|
2529
|
+
)
|
|
2530
|
+
self.add_vector_entities(
|
|
2531
|
+
id,
|
|
2532
|
+
[entity],
|
|
2533
|
+
parent=parent,
|
|
2534
|
+
position=position,
|
|
2535
|
+
rotation=rotation,
|
|
2536
|
+
scale=scale,
|
|
2537
|
+
matrix=matrix,
|
|
2538
|
+
visible=visible,
|
|
2539
|
+
pickable=pickable,
|
|
2540
|
+
)
|
|
2541
|
+
|
|
2542
|
+
def set_layer(
|
|
2543
|
+
self,
|
|
2544
|
+
name: str,
|
|
2545
|
+
*,
|
|
2546
|
+
color: Optional[int] = None,
|
|
2547
|
+
linetype: Optional[str] = None,
|
|
2548
|
+
line_width: Optional[float] = None,
|
|
2549
|
+
visible: Optional[bool] = None,
|
|
2550
|
+
reset: Sequence[str] = (),
|
|
2551
|
+
) -> None:
|
|
2552
|
+
"""Create or update a vector-entity layer (DXF ``LAYER``).
|
|
2553
|
+
|
|
2554
|
+
Entities that don't set their own colour, linetype or line width use
|
|
2555
|
+
the layer's. ``visible=False`` hides the layer in every vector
|
|
2556
|
+
object. Omitted arguments keep their current value; ``reset`` names
|
|
2557
|
+
the ones to return to their default (any of ``"color"``,
|
|
2558
|
+
``"linetype"``, ``"line_width"``, ``"visible"``). Layers are viewer
|
|
2559
|
+
settings, not scene objects, and shared by every vector object,
|
|
2560
|
+
including those loaded from glTF files: :meth:`clear` leaves them and
|
|
2561
|
+
a reconnect replays them.
|
|
2562
|
+
"""
|
|
2563
|
+
if not isinstance(name, str) or not name:
|
|
2564
|
+
raise ValueError("layer name must be a non-empty string")
|
|
2565
|
+
fields = {
|
|
2566
|
+
"color": "color",
|
|
2567
|
+
"linetype": "linetype",
|
|
2568
|
+
"line_width": "lineWidth",
|
|
2569
|
+
"visible": "visible",
|
|
2570
|
+
}
|
|
2571
|
+
given = {
|
|
2572
|
+
"color": color,
|
|
2573
|
+
"linetype": linetype,
|
|
2574
|
+
"line_width": line_width,
|
|
2575
|
+
"visible": visible,
|
|
2576
|
+
}
|
|
2577
|
+
for key in reset:
|
|
2578
|
+
if key not in fields:
|
|
2579
|
+
raise ValueError(f"reset: unknown layer attribute {key!r}")
|
|
2580
|
+
if given[key] is not None:
|
|
2581
|
+
raise ValueError(f"{key} is both set and reset")
|
|
2582
|
+
msg: dict = {"type": "set_vector_layer", "name": name}
|
|
2583
|
+
if color is not None:
|
|
2584
|
+
msg["color"] = vector._color(color)
|
|
2585
|
+
if linetype is not None:
|
|
2586
|
+
msg["linetype"] = str(linetype)
|
|
2587
|
+
if line_width is not None:
|
|
2588
|
+
if not vector._finite("line_width", line_width) > 0:
|
|
2589
|
+
raise ValueError("line_width must be positive")
|
|
2590
|
+
msg["lineWidth"] = float(line_width)
|
|
2591
|
+
if visible is not None:
|
|
2592
|
+
msg["visible"] = bool(visible)
|
|
2593
|
+
stored = self._vector_layers.setdefault(
|
|
2594
|
+
name, {"type": "set_vector_layer", "name": name}
|
|
2595
|
+
)
|
|
2596
|
+
stored.update(msg)
|
|
2597
|
+
for key in reset:
|
|
2598
|
+
# The viewer reads null as "back to the default"; the replay
|
|
2599
|
+
# simply no longer carries the attribute.
|
|
2600
|
+
stored.pop(fields[key], None)
|
|
2601
|
+
msg[fields[key]] = None
|
|
2602
|
+
if self._ws is not None:
|
|
2603
|
+
self._send(msg)
|
|
2604
|
+
|
|
2605
|
+
def set_linetype(self, name: str, pattern: List[float]) -> None:
|
|
2606
|
+
"""Define (or redefine) a linetype (DXF ``LTYPE``).
|
|
2607
|
+
|
|
2608
|
+
``pattern`` lists up to 12 lengths in scene units: positive draws a
|
|
2609
|
+
dash, negative leaves a gap and ``0`` draws a dot. The pattern
|
|
2610
|
+
restarts at the start of each entity and scales with the entity's
|
|
2611
|
+
``linetype_scale``. Names are case-insensitive. Built in, with
|
|
2612
|
+
acadiso.lin lengths in metres: ``CONTINUOUS``, ``DASHED``, ``HIDDEN``,
|
|
2613
|
+
``CENTER``, ``PHANTOM``, ``DOT``, ``DASHDOT``, ``BORDER``, ``DIVIDE``.
|
|
2614
|
+
Replayed on reconnect.
|
|
2615
|
+
"""
|
|
2616
|
+
if not isinstance(name, str) or not name:
|
|
2617
|
+
raise ValueError("linetype name must be a non-empty string")
|
|
2618
|
+
values = [float(x) for x in np.asarray(pattern, dtype=float).reshape(-1)]
|
|
2619
|
+
if not all(math.isfinite(x) for x in values):
|
|
2620
|
+
raise ValueError("pattern must be finite")
|
|
2621
|
+
if len(values) > 12:
|
|
2622
|
+
raise ValueError("pattern supports at most 12 elements")
|
|
2623
|
+
msg = {"type": "set_vector_linetype", "name": name.upper(), "pattern": values}
|
|
2624
|
+
self._vector_linetypes[name.upper()] = msg
|
|
2625
|
+
if self._ws is not None:
|
|
2626
|
+
self._send(msg)
|
|
2627
|
+
|
|
2200
2628
|
def add_mesh(
|
|
2201
2629
|
self,
|
|
2202
2630
|
id: str,
|