u-space 0.0.0-alpha.2 → 0.0.1

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.
@@ -1,32 +1,32 @@
1
1
  # Objects API
2
2
 
3
- `u-space` provides several object wrappers that make manipulating and loading 3D assets easier, primarily extending Three.js's basic nodes.
3
+ `u-space` 提供了若干对象封装类,主要扩展自 Three.js 的基础节点,使 3D 资产的操作和加载更加便捷。
4
4
 
5
- ## Base Classes
5
+ ## 基础类
6
6
 
7
7
  ### `BaseMesh`
8
8
 
9
- Extends `THREE.Mesh`. All primitive mesh classes in `u-space` inherit from this.
9
+ 继承自 `THREE.Mesh`,`u-space` 中所有基础网格类都继承于此。
10
10
 
11
- **Key property:**
11
+ **关键属性:**
12
12
 
13
- | Property | Type | Default | Description |
14
- | :--------------------------- | :-------- | :------ | :------------------------------------------------------------------------------ |
15
- | `ignoreInvisibleWhenRaycast` | `boolean` | `true` | When `true`, invisible meshes are skipped during raycasting (no hit detection). |
13
+ | 属性 | 类型 | 默认值 | 说明 |
14
+ | :--------------------------- | :-------- | :----- | :------------------------------------------------------------- |
15
+ | `ignoreInvisibleWhenRaycast` | `boolean` | `true` | 为 `true` 时,不可见的网格在射线检测时会被跳过(不参与碰撞)。 |
16
16
 
17
17
  ### `BaseGroup`
18
18
 
19
- Extends `THREE.Group`. `Model` and `Topology` inherit from this.
19
+ 继承自 `THREE.Group`,`Model` 和 `Topology` 均继承于此。
20
20
 
21
- **Key property:**
21
+ **关键属性:**
22
22
 
23
- | Property | Type | Default | Description |
24
- | :--------------------------- | :-------- | :------ | :------------------------------------------------------------------------------- |
25
- | `ignoreInvisibleWhenRaycast` | `boolean` | `true` | When `true`, invisible groups are skipped during raycasting (no hit detection). |
23
+ | 属性 | 类型 | 默认值 | 说明 |
24
+ | :--------------------------- | :-------- | :----- | :--------------------------------------------------------------- |
25
+ | `ignoreInvisibleWhenRaycast` | `boolean` | `true` | 为 `true` 时,不可见的组在射线检测时会被跳过(不参与碰撞)。 |
26
26
 
27
- ## Models
27
+ ## 模型
28
28
 
29
- The `Model` class extends `BaseGroup` (which in turn extends `THREE.Group`) and simplifies the process of asynchronously loading external 3D models like `glb` and `gltf` files. It features built-in support for different caching layers.
29
+ `Model` 类继承自 `BaseGroup`(进而继承自 `THREE.Group`),简化了异步加载 `glb`、`gltf` 等外部 3D 模型的流程,内置多层缓存支持。
30
30
 
31
31
  ```typescript
32
32
  import { Model } from 'u-space';
@@ -34,9 +34,9 @@ import { Model } from 'u-space';
34
34
  const myModel = new Model();
35
35
  ```
36
36
 
37
- ### Loading Assets
37
+ ### 加载资产
38
38
 
39
- The `loadAsync` method handles loading the asset from a URL and adding it to the group.
39
+ `loadAsync` 方法负责从 URL 加载资产并将其添加到组中。
40
40
 
41
41
  ```typescript
42
42
  await myModel.loadAsync(options: ModelLoadOptions)
@@ -44,38 +44,38 @@ await myModel.loadAsync(options: ModelLoadOptions)
44
44
 
45
45
  #### `ModelLoadOptions`
46
46
 
47
- | Property | Type | Description |
48
- | :----------- | :-------- | :------------------------------------------------------------------------------------------------------------------------------- |
49
- | `url` | `string` | The URL of the `.gltf` or `.glb` file. |
50
- | `cache` | `boolean` | (Optional) Enables in-memory caching. If a model has been loaded before, it retrieves it instantly from memory. Default `false`. |
51
- | `persistent` | `boolean` | (Optional) Enables persistent disk-level caching using the browser's Cache API. Good for larger models. Default `false`. |
47
+ | 属性 | 类型 | 说明 |
48
+ | :----------- | :-------- | :----------------------------------------------------------------------------------------------------------------- |
49
+ | `url` | `string` | `.gltf` 或 `.glb` 文件的 URL。 |
50
+ | `cache` | `boolean` | (可选)启用内存缓存。若模型已加载过,则直接从内存中获取。默认 `false`。 |
51
+ | `persistent` | `boolean` | (可选)使用浏览器 Cache API 启用持久化磁盘缓存,适合较大的模型。默认 `false`。 |
52
52
 
53
- #### Caching Example
53
+ #### 缓存示例
54
54
 
55
55
  ```javascript
56
- // Load a model from network and persist it
56
+ // 从网络加载并持久化
57
57
  const model1 = new Model();
58
58
  model1.loadAsync({ url: 'model.glb', persistent: true });
59
59
 
60
- // Sometime later, this will load from Cache API
60
+ // 稍后,将从 Cache API 加载
61
61
  const model2 = new Model();
62
62
  model2.loadAsync({ url: 'model.glb', persistent: true });
63
63
 
64
- // This will load from fast Memory Cache
64
+ // 从内存缓存快速加载
65
65
  const model3 = new Model();
66
66
  model3.loadAsync({ url: 'model.glb', cache: true, persistent: true });
67
67
  ```
68
68
 
69
- ### Clearing Caches
69
+ ### 清除缓存
70
70
 
71
- You can manually clear the internal caches using static methods on the `Model` class:
71
+ 可通过 `Model` 类的静态方法手动清除内部缓存:
72
72
 
73
- - `Model.clearMemoryCache()`: Clears the transient runtime memory cache.
74
- - `await Model.clearPersistentCache()`: Completely clears the browser's persistent cache for `u-space` models.
73
+ - `Model.clearMemoryCache()`:清除运行时内存缓存。
74
+ - `await Model.clearPersistentCache()`:完全清除浏览器中 `u-space` 模型的持久化缓存。
75
75
 
76
- ## Meshes
76
+ ## 网格
77
77
 
78
- `u-space` offers a variety of streamlined Mesh classes extending `BaseMesh`. All use `MeshStandardNodeMaterial` by default, accept a `{ geometryParameters, materialParameters }` constructor shape, and support interaction event dispatching.
78
+ `u-space` 提供了多种精简的网格类,均继承自 `BaseMesh`。所有类默认使用 `MeshStandardNodeMaterial`,构造函数接受 `{ geometryParameters, materialParameters }` 参数,并支持交互事件分发。
79
79
 
80
80
  ### `SphereMesh`
81
81
 
@@ -90,14 +90,14 @@ const sphere = new SphereMesh({
90
90
 
91
91
  **`SphereMeshParameters`**
92
92
 
93
- | Property | Type | Description |
94
- | :-------------------- | :---------------------------------- | :--------------------------------------- |
95
- | `geometryParameters` | `SphereGeometry` constructor params | `radius`, `widthSegments`, `heightSegments`, etc. |
96
- | `materialParameters` | `MeshStandardNodeMaterialParameters`| Standard material options (color, etc.). |
93
+ | 属性 | 类型 | 说明 |
94
+ | :-------------------- | :----------------------------------- | :----------------------------------------------- |
95
+ | `geometryParameters` | `SphereGeometry` 构造函数参数 | `radius`、`widthSegments`、`heightSegments` 等。 |
96
+ | `materialParameters` | `MeshStandardNodeMaterialParameters` | 标准材质选项(颜色等)。 |
97
97
 
98
98
  ### `PlaneMesh`
99
99
 
100
- A flat horizontal plane.
100
+ 水平平面网格。
101
101
 
102
102
  ```typescript
103
103
  import { PlaneMesh } from 'u-space';
@@ -110,7 +110,7 @@ const plane = new PlaneMesh({
110
110
 
111
111
  ### `CircleMesh`
112
112
 
113
- A flat circle.
113
+ 圆形平面网格。
114
114
 
115
115
  ```typescript
116
116
  import { CircleMesh } from 'u-space';
@@ -122,7 +122,7 @@ const circle = new CircleMesh({
122
122
 
123
123
  ### `TubeMesh`
124
124
 
125
- A tube along a given `Curve<Vector3>`.
125
+ 沿指定 `Curve<Vector3>` 曲线生成的管道网格。
126
126
 
127
127
  ```typescript
128
128
  import { TubeMesh } from 'u-space';
@@ -137,21 +137,21 @@ const tube = new TubeMesh({
137
137
 
138
138
  ### `ShapeMesh`
139
139
 
140
- A flat mesh built from a `THREE.Shape` or from 2D points.
140
+ 由 `THREE.Shape` 或 2D 点生成的平面网格。
141
141
 
142
142
  ```typescript
143
143
  import { ShapeMesh } from 'u-space';
144
144
 
145
- // From an explicit shape
145
+ // 从显式 Shape 创建
146
146
  const mesh = new ShapeMesh({ geometryParameters: { shape: myShape } });
147
147
 
148
- // Static helper: from x/z point array
148
+ // 静态辅助方法:从 x/z 点数组创建
149
149
  const mesh2 = ShapeMesh.createFromPoints([{ x: 0, z: 0 }, { x: 5, z: 0 }, { x: 5, z: 5 }]);
150
150
  ```
151
151
 
152
152
  ### `ExtrudeMesh`
153
153
 
154
- An extruded 3D solid from a `THREE.Shape` or from 2D points.
154
+ 由 `THREE.Shape` 或 2D 点拉伸生成的 3D 实体网格。
155
155
 
156
156
  ```typescript
157
157
  import { ExtrudeMesh } from 'u-space';
@@ -164,7 +164,7 @@ const solid = new ExtrudeMesh({
164
164
  materialParameters: { color: 0xff8800 },
165
165
  });
166
166
 
167
- // Static helper
167
+ // 静态辅助方法
168
168
  const solid2 = ExtrudeMesh.createFromPoints(
169
169
  [{ x: 0, z: 0 }, { x: 5, z: 0 }, { x: 5, z: 5 }],
170
170
  { geometryParameters: { options: { depth: 2, bevelEnabled: false } } }
@@ -173,20 +173,20 @@ const solid2 = ExtrudeMesh.createFromPoints(
173
173
 
174
174
  ## Poi
175
175
 
176
- `Poi` is a canvas-rendered billboard (sprite) used for placing icons and labels in the 3D scene. It extends `BaseSprite`.
176
+ `Poi` 是一个基于 canvas 渲染的公告板(精灵),用于在 3D 场景中放置图标和标签,继承自 `BaseSprite`。
177
177
 
178
178
  ```typescript
179
179
  import { Poi } from 'u-space';
180
180
 
181
181
  const poi = new Poi({
182
182
  img: '/icons/marker.png',
183
- text: 'My Location',
183
+ text: '我的位置',
184
184
  fontSize: 28,
185
185
  color: '#ffffff',
186
186
  backgroundColor: 'rgba(0,0,0,0.6)',
187
187
  textPosition: 'right',
188
188
  });
189
- await poi.updateAsync(); // render the canvas texture
189
+ await poi.updateAsync(); // 渲染 canvas 纹理
190
190
 
191
191
  poi.position.set(10, 5, 10);
192
192
  viewer.scene.add(poi);
@@ -194,37 +194,37 @@ viewer.scene.add(poi);
194
194
 
195
195
  ### `PoiParameters`
196
196
 
197
- | Property | Type | Default | Description |
198
- | :---------------- | :------------------------------------------ | :----------------------- | :------------------------------------------------ |
199
- | `img` | `string \| CanvasImageSource` | `''` | Icon image URL or element. |
200
- | `text` | `string` | `''` | Label text. |
201
- | `fontSize` | `number` | `32` | Font size in pixels. |
202
- | `fontFamily` | `string` | `'Arial'` | Font family. |
203
- | `color` | `string` | `'#ffffff'` | Text color. |
204
- | `iconSize` | `number` | `64` | Icon size in pixels. |
205
- | `padding` | `number` | `10` | Padding around content. |
206
- | `backgroundColor` | `string` | `'rgba(0, 0, 0, 0.5)'` | Background fill color. |
207
- | `borderRadius` | `number` | `8` | Background border radius. |
208
- | `textPosition` | `'top' \| 'bottom' \| 'left' \| 'right'` | `'right'` | Text position relative to the icon. |
209
-
210
- ### Methods
197
+ | 属性 | 类型 | 默认值 | 说明 |
198
+ | :---------------- | :------------------------------------------ | :----------------------- | :--------------------------------- |
199
+ | `img` | `string \| CanvasImageSource` | `''` | 图标图片 URL 或元素。 |
200
+ | `text` | `string` | `''` | 标签文字。 |
201
+ | `fontSize` | `number` | `32` | 字体大小(像素)。 |
202
+ | `fontFamily` | `string` | `'Arial'` | 字体族。 |
203
+ | `color` | `string` | `'#ffffff'` | 文字颜色。 |
204
+ | `iconSize` | `number` | `64` | 图标大小(像素)。 |
205
+ | `padding` | `number` | `10` | 内容四周的内边距。 |
206
+ | `backgroundColor` | `string` | `'rgba(0, 0, 0, 0.5)'` | 背景填充颜色。 |
207
+ | `borderRadius` | `number` | `8` | 背景圆角半径。 |
208
+ | `textPosition` | `'top' \| 'bottom' \| 'left' \| 'right'` | `'right'` | 文字相对图标的位置。 |
209
+
210
+ ### 方法
211
211
 
212
212
  #### `updateAsync(parameters?)`
213
213
 
214
- Re-renders the canvas texture with optional parameter overrides.
214
+ 使用可选的参数覆盖重新渲染 canvas 纹理。
215
215
 
216
216
  ```typescript
217
- await poi.updateAsync({ text: 'Updated label', color: '#ffff00' });
217
+ await poi.updateAsync({ text: '更新后的标签', color: '#ffff00' });
218
218
  viewer.render();
219
219
  ```
220
220
 
221
221
  #### `dispose()`
222
222
 
223
- Disposes the canvas texture and material.
223
+ 释放 canvas 纹理和材质。
224
224
 
225
225
  ## Topology
226
226
 
227
- `Topology` is a graph data structure with built-in 3D visualization. It stores nodes (positions) and weighted edges, implements Dijkstra's shortest-path algorithm, and renders the graph as spheres and tubes.
227
+ `Topology` 是一个带有内置 3D 可视化的图数据结构。它存储节点(位置)和带权重的边,实现了 Dijkstra 最短路径算法,并将图渲染为球体和管道。
228
228
 
229
229
  ```typescript
230
230
  import { Topology } from 'u-space';
@@ -243,54 +243,54 @@ topo.addNode('C', new Vector3(5, 0, 5));
243
243
  topo.addEdge('A', 'B');
244
244
  topo.addEdge('B', 'C');
245
245
 
246
- topo.renderGraph(); // Creates sphere + tube meshes
246
+ topo.renderGraph(); // 创建球体 + 管道网格
247
247
  viewer.scene.add(topo);
248
248
  ```
249
249
 
250
250
  ### `TopologyParameters`
251
251
 
252
- | Property | Type | Default | Description |
253
- | :------------ | :------------------- | :---------- | :------------------------------ |
254
- | `nodeColor` | `ColorRepresentation`| `0x0000ff` | Color of node spheres. |
255
- | `nodeRadius` | `number` | `0.5` | Radius of node spheres. |
256
- | `edgeColor` | `ColorRepresentation`| `0x00ff00` | Color of edge tubes. |
257
- | `edgeRadius` | `number` | `0.1` | Radius of edge tubes. |
258
- | `pathColor` | `ColorRepresentation`| `0xff00ff` | Color used for path visualization. |
259
- | `pathRadius` | `number` | `0.2` | Radius of path tubes. |
252
+ | 属性 | 类型 | 默认值 | 说明 |
253
+ | :------------ | :-------------------- | :---------- | :----------------------- |
254
+ | `nodeColor` | `ColorRepresentation` | `0x0000ff` | 节点球体颜色。 |
255
+ | `nodeRadius` | `number` | `0.5` | 节点球体半径。 |
256
+ | `edgeColor` | `ColorRepresentation` | `0x00ff00` | 边管道颜色。 |
257
+ | `edgeRadius` | `number` | `0.1` | 边管道半径。 |
258
+ | `pathColor` | `ColorRepresentation` | `0xff00ff` | 路径可视化颜色。 |
259
+ | `pathRadius` | `number` | `0.2` | 路径管道半径。 |
260
260
 
261
- ### Methods
261
+ ### 方法
262
262
 
263
263
  #### `addNode(id, position)`
264
264
 
265
- Adds a node to the graph.
265
+ 向图中添加一个节点。
266
266
 
267
267
  #### `removeNode(id)`
268
268
 
269
- Removes a node and its associated edges.
269
+ 移除一个节点及其关联的边。
270
270
 
271
271
  #### `addEdge(from, to, weight?, bidirectional?)`
272
272
 
273
- Adds an edge between two nodes. `weight` defaults to Euclidean distance. `bidirectional` defaults to `true`.
273
+ 在两个节点之间添加一条边。`weight` 默认为欧氏距离,`bidirectional` 默认为 `true`(双向)。
274
274
 
275
275
  #### `removeEdge(from, to, bidirectional?)`
276
276
 
277
- Removes an edge between two nodes.
277
+ 移除两个节点之间的边。
278
278
 
279
279
  #### `getShortestPath(startId, endId): Vector3[]`
280
280
 
281
- Returns the shortest path as an array of world-space positions using Dijkstra's algorithm. Returns `[]` if no path exists.
281
+ 使用 Dijkstra 算法返回最短路径(世界坐标位置数组)。若不存在路径则返回 `[]`。
282
282
 
283
283
  #### `renderGraph()`
284
284
 
285
- Builds the sphere/tube scene graph from current nodes and edges. Call this after modifying the graph to refresh the visualization.
285
+ 根据当前节点和边构建球体/管道场景图。修改图后需调用此方法刷新可视化。
286
286
 
287
287
  #### `clearGraph()`
288
288
 
289
- Removes and disposes all graph meshes.
289
+ 移除并释放所有图网格。
290
290
 
291
291
  #### `renderPath(points, color?): TubeMesh`
292
292
 
293
- Renders a smoothed path (CatmullRomCurve3) through the given points as a tube mesh.
293
+ 将给定点通过 CatmullRomCurve3 平滑处理后渲染为管道网格。
294
294
 
295
295
  ```typescript
296
296
  const path = topo.getShortestPath('A', 'C');
@@ -300,12 +300,12 @@ viewer.render();
300
300
 
301
301
  #### `clearPaths()`
302
302
 
303
- Removes and disposes all path meshes.
303
+ 移除并释放所有路径网格。
304
304
 
305
305
  #### `getNeighbors(id): Map<string, number> | undefined`
306
306
 
307
- Returns the adjacency map for a node (neighbor ID → edge weight).
307
+ 返回节点的邻接表(邻居 ID → 边权重)。
308
308
 
309
309
  #### `dispose()`
310
310
 
311
- Clears graph and path meshes.
311
+ 清除图和路径网格。