u-space 0.0.16 → 0.0.18

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,7 +1,27 @@
1
- import { Box3, Matrix4, Sphere, Vector3, Vector4, type Intersection, type Raycaster } from 'three/webgpu';
2
- import { BaseMesh } from 'u-space';
1
+ import { Box3, BufferGeometry, Matrix4, MeshStandardNodeMaterial, Sphere, Vector3, Vector4, type Intersection, type Raycaster } from 'three/webgpu';
2
+ import { BaseMesh, type InteractionEvent, type InteractionEventMap } from 'u-space';
3
3
  import type { SemanticColor, SemanticGeometryEntry, SemanticKind } from './types';
4
- export declare class FloorMesh extends BaseMesh {
4
+ type FloorMeshEventPayload<T> = T extends {
5
+ event: InteractionEvent;
6
+ } ? {
7
+ event: FloorMeshInteractionEvent;
8
+ } : T;
9
+ export interface FloorMeshIntersection extends Intersection<FloorMesh> {
10
+ semanticId: string;
11
+ semanticKind: SemanticKind;
12
+ semanticName?: string;
13
+ semanticIndex: number;
14
+ instanceId: number;
15
+ }
16
+ export type FloorMeshInteractionEvent = Omit<InteractionEvent, 'target' | 'currentTarget' | 'intersect'> & {
17
+ readonly target: FloorMesh;
18
+ currentTarget: FloorMesh;
19
+ readonly intersect: FloorMeshIntersection | null;
20
+ };
21
+ export type FloorMeshEventMap = {
22
+ [K in keyof InteractionEventMap]: FloorMeshEventPayload<InteractionEventMap[K]>;
23
+ };
24
+ export declare class FloorMesh extends BaseMesh<BufferGeometry, MeshStandardNodeMaterial, FloorMeshEventMap> {
5
25
  #private;
6
26
  isFloorMergedSemanticMesh: boolean;
7
27
  type: string;
@@ -40,3 +60,4 @@ export declare class FloorMesh extends BaseMesh {
40
60
  raycast(raycaster: Raycaster, intersects: Intersection[]): boolean | void;
41
61
  dispose(): void;
42
62
  }
63
+ export {};
@@ -13,6 +13,10 @@ export interface SSGIConfig {
13
13
  thickness?: number;
14
14
  }
15
15
  export type OutputNodeComposer = (scenePass: PassNode) => Node;
16
+ export type OutputNodeEffect = ((scenePass: PassNode, inputNode: Node) => Node) & {
17
+ includesTemporalAntialias?: boolean;
18
+ includesOutputTransform?: boolean;
19
+ };
16
20
  type Args = [ConstructorParameters<typeof RenderPipelineBase>[0], Scene, Camera];
17
21
  export declare class RenderPipeline extends RenderPipelineBase {
18
22
  #private;
@@ -31,6 +35,10 @@ export declare class RenderPipeline extends RenderPipelineBase {
31
35
  /** @deprecated Use `setOutputComposer(null)` instead */
32
36
  resetCurrentOutputNode(): void;
33
37
  setOutputComposer(composer: OutputNodeComposer | null): void;
38
+ addOutputEffect(effect: OutputNodeEffect): this;
39
+ removeOutputEffect(effect: OutputNodeEffect): this;
40
+ addMRTChannel(name: string, node: Node): this;
41
+ removeMRTChannel(name: string): this;
34
42
  enableBloom(config?: BloomConfig): void;
35
43
  disableBloom(): void;
36
44
  updateBloom(config: Partial<BloomConfig>): void;
@@ -12,6 +12,8 @@
12
12
 
13
13
  | 属性 | 类型 | 默认值 | 说明 |
14
14
  | :--------------------------- | :-------- | :----- | :------------------------------------------------------------- |
15
+ | `castShadow` | `boolean` | `true` | 默认参与阴影投射;可在单个对象上改为 `false`。 |
16
+ | `receiveShadow` | `boolean` | `true` | 默认接收阴影;可在不需要阴影的网格上改为 `false`。 |
15
17
  | `ignoreInvisibleWhenRaycast` | `boolean` | `true` | 为 `true` 时,不可见的网格在射线检测时会被跳过(不参与碰撞)。 |
16
18
 
17
19
  ### `BaseGroup`
@@ -1,10 +1,102 @@
1
1
  # atmosphere
2
2
 
3
- 天空和大气渲染插件。目前为占位实现,`enable()` / `disable()` / `dispose()` 方法可用,但尚未实现具体功能。
3
+ 天空和大气渲染插件,基于 `@takram/three-atmosphere` 的 WebGPU 节点实现。启用后会接入 Viewer 的 `renderer.contextNode`、`scene.backgroundNode` 和 RenderPipeline 的 output effect/MRT 扩展点,提供天空背景、太阳光、aerial perspective 大气透视、lens flare、tone mapping 和 temporal antialias。
4
4
 
5
5
  ```typescript
6
6
  import { Atmosphere } from 'u-space/plugins/atmosphere';
7
7
 
8
8
  const atmosphere = new Atmosphere(viewer);
9
- atmosphere.enable();
9
+ atmosphere.enable({
10
+ longitude: 120.002269,
11
+ latitude: 30.284849,
12
+ height: 4,
13
+ });
10
14
  ```
15
+
16
+ ## API
17
+
18
+ ### `new Atmosphere(viewer)`
19
+
20
+ 创建大气插件实例。
21
+
22
+ ### `enable(options?)`
23
+
24
+ 开启大气效果。重复调用时等同于 `update(options)`。
25
+
26
+ ```typescript
27
+ atmosphere.enable({
28
+ longitude: 120.002269,
29
+ latitude: 30.284849,
30
+ height: 4,
31
+ date: new Date(),
32
+ showSun: true,
33
+ showMoon: true,
34
+ showStars: true,
35
+ });
36
+ ```
37
+
38
+ ### `update(options?)`
39
+
40
+ 更新大气参数,不会重新创建插件实例。
41
+
42
+ ```typescript
43
+ atmosphere.update({
44
+ date: new Date('2026-06-16T12:00:00+08:00'),
45
+ showStars: false,
46
+ });
47
+ ```
48
+
49
+ ### `setLocation(longitude, latitude, height?)`
50
+
51
+ 更新场景本地原点对应的 WGS84 经纬高。`longitude`、`latitude` 使用角度,`height` 使用米。
52
+
53
+ ### `setDate(date)`
54
+
55
+ 更新太阳和月亮方向。`date` 支持 `Date` 或时间戳。
56
+
57
+ ### `disable()`
58
+
59
+ 关闭大气效果并恢复启用前的 `backgroundNode`、`environmentNode` 和 `renderer.contextNode`。
60
+
61
+ ### `dispose()`
62
+
63
+ 释放插件资源,等同于 `disable()`。
64
+
65
+ ## Options
66
+
67
+ | 参数 | 类型 | 默认值 | 说明 |
68
+ | --- | --- | --- | --- |
69
+ | `longitude` | `number` | `0` | 本地场景原点的经度,单位为度 |
70
+ | `latitude` | `number` | `0` | 本地场景原点的纬度,单位为度 |
71
+ | `height` | `number` | `0` | 本地场景原点高度,单位为米 |
72
+ | `date` | `Date \| number` | 当天本地时间 08:00 | 用于计算太阳和月亮方向 |
73
+ | `showSun` | `boolean` | `true` | 显示太阳 |
74
+ | `showMoon` | `boolean` | `true` | 显示月亮 |
75
+ | `showStars` | `boolean` | `true` | 显示星空 |
76
+ | `showGround` | `boolean` | `false` | 是否渲染大气地面 |
77
+ | `useSkyEnvironment` | `boolean` | `true` | 是否使用天空节点作为 `scene.environmentNode` |
78
+ | `raymarchScattering` | `boolean` | `true` | 是否启用 raymarch scattering |
79
+ | `lighting` | `boolean` | `true` | aerial perspective 是否包含光照 |
80
+ | `transmittance` | `boolean` | `true` | aerial perspective 是否包含透射 |
81
+ | `inscattering` | `boolean` | `true` | aerial perspective 是否包含内散射 |
82
+ | `moonScattering` | `boolean` | `true` | 是否包含月光散射 |
83
+ | `lensFlare` | `boolean` | `true` | 是否在 aerial perspective 后启用 lens flare |
84
+ | `temporalAntialias` | `boolean` | `true` | 是否在大气后处理链中启用 temporal antialias |
85
+ | `dithering` | `boolean` | `true` | 是否在 temporal antialias 后追加 dithering |
86
+ | `toneMapping` | `ToneMapping \| false` | `AgXPunchyToneMapping` | 大气后处理链使用的 tone mapping;设为 `false` 可跳过 |
87
+ | `toneMappingExposure` | `number` | `3` | 大气 tone mapping 曝光值 |
88
+ | `castShadow` | `boolean` | `true` | 是否让大气太阳光投射阴影 |
89
+ | `shadowMapSize` | `number` | `4096` | 阴影贴图尺寸 |
90
+ | `shadowCameraSize` | `number` | `180` | directional shadow 正交相机覆盖范围,越小越清晰但覆盖范围越窄 |
91
+ | `shadowCameraNear` | `number` | `10` | shadow camera near |
92
+ | `shadowCameraFar` | `number` | `6000` | shadow camera far |
93
+ | `shadowBias` | `number` | `-0.00002` | 阴影深度偏移 |
94
+ | `shadowNormalBias` | `number` | `0.001` | 法线方向阴影偏移,用于缓解 shadow acne;过大会让底部阴影产生脱离感 |
95
+ | `shadowRadius` | `number` | `1.5` | PCF 阴影采样半径,用于柔化轻微锯齿 |
96
+ | `shadowDistance` | `number` | `3000` | 大气方向光与 target 的距离 |
97
+
98
+ ## 注意事项
99
+
100
+ `Atmosphere` 不会占用 `viewer.renderPipeline.setOutputComposer()`。它通过 output effect 追加大气后处理;开启 `temporalAntialias` 时才会注册独立的 `atmosphereVelocity` MRT 通道,并会避免和 RenderPipeline 自带 TRAA 重复运行。业务设置自定义 composer 时,大气 output effect 和它的输出变换开关都会被 RenderPipeline 跳过,让 composer 保持完整接管输出的原语义。
101
+
102
+ 如果看到明显的方形阴影边界,通常是 `shadowCameraSize` 小于当前可见场景范围。可以调大该值,或让相机 target 更贴近需要观察的区域。阴影偏糊时优先减小 `shadowCameraSize` 或增大 `shadowMapSize`;底部阴影有脱离感时优先减小 `shadowNormalBias`;边缘仍有轻微锯齿时可略微增大 `shadowRadius`。
@@ -7,13 +7,15 @@
7
7
  ```
8
8
  Stage 1: pass(scene, camera) + MRT(按需配置 output/emissive/normal/velocity)
9
9
  ↓
10
- Stage 2: 后处理链(二选一)
10
+ Stage 2: 后处理链
11
11
  ├─ 内置模式: SSGI → Bloom(按启用状态组合)
12
12
  └─ 自定义模式: outputComposer(scenePass) → Node
13
13
  ↓
14
- Stage 3: TRAA 时间抗锯齿
14
+ Stage 3: Output Effects(仅默认/内置模式,插件/扩展追加效果)
15
15
  ↓
16
- Stage 4: Overlay Passes(blendColor 叠加 ViewerHelper 等)
16
+ Stage 4: TRAA 时间抗锯齿
17
+ ↓
18
+ Stage 5: Overlay Passes(blendColor 叠加 ViewerHelper 等)
17
19
  ↓
18
20
  outputNode = 最终结果
19
21
  ```
@@ -88,7 +90,7 @@ viewer.renderPipeline.disableTRAA();
88
90
 
89
91
  ## 自定义后处理(OutputComposer)
90
92
 
91
- 使用 `setOutputComposer` 可完全覆盖内置后处理链,接收 `scenePass` 返回自定义的 TSL 节点。
93
+ 使用 `setOutputComposer` 可完全覆盖内置后处理链,接收 `scenePass` 返回自定义的 TSL 节点。自定义 composer 会保持最终输出语义,不再叠加插件注册的 output effects。
92
94
 
93
95
  ```typescript
94
96
  import { luminance, vec4 } from 'three/tsl';
@@ -104,6 +106,20 @@ viewer.renderPipeline.setOutputComposer((scenePass) => {
104
106
  viewer.renderPipeline.setOutputComposer(null);
105
107
  ```
106
108
 
109
+ ## Output Effects
110
+
111
+ 插件可使用 `addOutputEffect` 在默认/内置后处理链之后追加效果,而不占用业务侧的 `setOutputComposer()`。如果业务设置了自定义 composer,output effects 会被跳过,由 composer 自己负责完整输出。
112
+
113
+ ```typescript
114
+ const effect = (scenePass, inputNode) => inputNode;
115
+ viewer.renderPipeline.addOutputEffect(effect);
116
+ viewer.renderPipeline.removeOutputEffect(effect);
117
+ ```
118
+
119
+ 如果 effect 已经调用了 `renderOutput()`,可设置 `effect.includesOutputTransform = true`,管线只会在该 effect 实际生效时关闭默认输出变换。
120
+
121
+ 如需额外 MRT 输出通道,可用 `addMRTChannel` / `removeMRTChannel` 注册,不会污染核心依赖。
122
+
107
123
  ## Overlay Passes
108
124
 
109
125
  用于叠加辅助渲染层(如 ViewerHelper),始终在后处理链之后执行。
package/docs/changelog.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # 更新日志
2
2
 
3
+ ## 0.0.16
4
+
5
+ ### 新增
6
+
7
+ - **u-manager semantics** — `FloorMesh.planish(kind?)`、`FloorMesh.unplanish(kind?)`、`BuildingGroup.planishFloors(kind?)` 和 `BuildingGroup.unplanishFloors(kind?)` 支持按 `Walls`、`Columns`、`Spaces`、`Doors`、`Windows` 语义类型压平或恢复;`setScaleYAt(index, y)` 可只调整单个语义实例的 Y 轴缩放。
8
+ - **BaseMesh** — 默认开启 `castShadow` 与 `receiveShadow`,基础网格和继承自 `BaseMesh` 的对象会直接参与阴影投射与接收。
9
+
10
+ ### 变更
11
+
12
+ - **语义类型命名** — `SemanticKind` 统一为数据源字段风格:`Walls`、`Columns`、`Spaces`、`Doors`、`Windows`。
13
+ - **示例与依赖** — 更新 `load_tiles.html` 示例依赖,新增 `@takram/three-atmosphere`、`postprocessing` peer dependency,并将 Vite 外部依赖边界扩展到所有 `@takram/*` 包。
14
+
3
15
  ## 0.0.12
4
16
 
5
17
  ### 新增
package/docs/mcp.md CHANGED
@@ -86,7 +86,7 @@ export const codingAgent = new Agent({
86
86
 
87
87
  ## 包结构
88
88
 
89
- 源码位于 `packages/u-space-mcp`。发布时会先从根目录 `docs/*.md` 生成内置文档索引,并编译成可发布的 npm 包:
89
+ 源码位于 `packages/u-space-mcp`。根目录只保留一个 MCP 发布入口;执行时会先从 `docs/*.md` 生成内置文档索引,编译 MCP 包,然后发布到 npm:
90
90
 
91
91
  ```bash
92
92
  pnpm publish:mcp
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "u-space",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "type": "module",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "module": "dist/index.js",
@@ -29,8 +29,7 @@
29
29
  "docs:build": "vitepress build docs",
30
30
  "docs:preview": "vitepress preview docs",
31
31
  "docs:deploy": "pnpm docs:build && vercel --prod",
32
- "build:mcp": "pnpm --filter u-space-mcp build",
33
- "publish:mcp": "pnpm build:mcp && npm publish ./packages/u-space-mcp --access public --ignore-scripts",
32
+ "publish:mcp": "pnpm --filter u-space-mcp build && npm publish ./packages/u-space-mcp --access public --ignore-scripts",
34
33
  "release": "npm version patch && pnpm build && npm publish --access=public"
35
34
  },
36
35
  "files": [