dsh-3d-viewer 0.1.1 → 0.2.0
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.
- package/README.md +180 -114
- package/README.zh.md +180 -114
- package/THIRD_PARTY_NOTICES.md +54 -54
- package/assets/hdri/LICENSE.md +17 -17
- package/dist/client.fbx.js +14 -0
- package/dist/client.gltf.js +14 -0
- package/dist/client.js +4472 -0
- package/dist/client.obj.js +19 -0
- package/dist/client.stl.js +14 -0
- package/dist/client.tex-exr.js +14 -0
- package/dist/client.tex-hdr.js +18 -0
- package/dist/client.tex-tga.js +14 -0
- package/index.js +167 -167
- package/package.json +72 -67
- package/client.js +0 -4462
package/README.md
CHANGED
|
@@ -1,114 +1,180 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
<img src="https://raw.githubusercontent.com/ybniaobu/dsh-3d-viewer/main/assets/icon-180.png" alt="3D Viewer icon" width="96" height="96">
|
|
3
|
-
<h1 align="center">3D Viewer</h1>
|
|
4
|
-
</div>
|
|
5
|
-
|
|
6
|
-
English | [中文](https://github.com/ybniaobu/dsh-3d-viewer/blob/main/README.zh.md)
|
|
7
|
-
|
|
8
|
-
[](https://github.com/ybniaobu/dsh-3d-viewer) [](https://www.npmjs.com/package/dsh-3d-viewer?activeTab=readme)
|
|
9
|
-
|
|
10
|
-
Preview FBX, OBJ, glTF, GLB, and STL models from the current session's workspace in DSH's right sidebar.
|
|
11
|
-
|
|
12
|
-

|
|
13
|
-
|
|
14
|
-
## Installation and enabling
|
|
15
|
-
|
|
16
|
-
Distributed as the npm package `dsh-3d-viewer`. The prebuilt `client.js`
|
|
17
|
-
|
|
18
|
-
### Install from npm (recommended)
|
|
19
|
-
|
|
20
|
-
1. Open DSH Desktop and choose **Plugins** in the sidebar.
|
|
21
|
-
2. Click **Add plugin** → **Install a third-party plugin**.
|
|
22
|
-
3. Enter `dsh-3d-viewer` (or `dsh-3d-viewer@0.
|
|
23
|
-
4. Set **Registry** to the official npm registry (npmmirror also works in mainland China).
|
|
24
|
-
5. Click **Install**, then confirm **3D Viewer** is **On** under **Installed plugins**.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
|
60
|
-
|
|
|
61
|
-
| **
|
|
62
|
-
| **
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
- **
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
|
100
|
-
|
|
|
101
|
-
| `
|
|
102
|
-
| `
|
|
103
|
-
| `
|
|
104
|
-
| `
|
|
105
|
-
| `
|
|
106
|
-
| `
|
|
107
|
-
| `
|
|
108
|
-
| `
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/ybniaobu/dsh-3d-viewer/main/assets/icon-180.png" alt="3D Viewer icon" width="96" height="96">
|
|
3
|
+
<h1 align="center">3D Viewer</h1>
|
|
4
|
+
</div>
|
|
5
|
+
|
|
6
|
+
English | [中文](https://github.com/ybniaobu/dsh-3d-viewer/blob/main/README.zh.md)
|
|
7
|
+
|
|
8
|
+
[](https://github.com/ybniaobu/dsh-3d-viewer) [](https://www.npmjs.com/package/dsh-3d-viewer?activeTab=readme)
|
|
9
|
+
|
|
10
|
+
Preview FBX, OBJ, glTF, GLB, and STL models plus TGA, EXR, and HDR textures from the current session's workspace in DSH's right sidebar. Open a model, orbit, zoom, auto-rotate, switch materials and environments, and play embedded animations.
|
|
11
|
+
|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
## Installation and enabling
|
|
15
|
+
|
|
16
|
+
Distributed as the npm package `dsh-3d-viewer`. The prebuilt `dist/client.js` contains the viewer and Three.js core; model loaders and TGA, EXR, and HDR decoders are package-local lazy chunks fetched only on first use. The four HDRI files ship in the package and are served by a small read-only host route on the local DSH server. React comes from DSH.
|
|
17
|
+
|
|
18
|
+
### Install from npm (recommended)
|
|
19
|
+
|
|
20
|
+
1. Open DSH Desktop and choose **Plugins** in the sidebar.
|
|
21
|
+
2. Click **Add plugin** → **Install a third-party plugin**.
|
|
22
|
+
3. Enter `dsh-3d-viewer` (or `dsh-3d-viewer@0.2.0` to pin a version).
|
|
23
|
+
4. Set **Registry** to the official npm registry (npmmirror also works in mainland China).
|
|
24
|
+
5. Click **Install**, then confirm **3D Viewer** is **On** under **Installed plugins**.
|
|
25
|
+
|
|
26
|
+
> **Updating**: remove the old version under **Plugins**, then install the new one with a higher version.
|
|
27
|
+
|
|
28
|
+
### Install from a local directory (optional)
|
|
29
|
+
|
|
30
|
+
Use this for offline or intranet distribution.
|
|
31
|
+
|
|
32
|
+
1. Unpack the plugin directory anywhere; it must contain `package.json`, `dist/client.js` plus its chunks, `index.js`, `cordis.patch.yml`, and the `assets/hdri/` directory.
|
|
33
|
+
2. Open DSH Desktop and choose **Plugins** in the sidebar.
|
|
34
|
+
3. Click **Add plugin** → **Install a third-party plugin**.
|
|
35
|
+
4. Enter the directory's absolute path (for example `F:\plugins\dsh-3d-viewer`) and click **Install**.
|
|
36
|
+
5. Confirm **3D Viewer** is **On** under **Installed plugins**.
|
|
37
|
+
|
|
38
|
+
> Local installs link to the directory rather than copying it. Do not move, rename, or delete it, or DSH may not find the plugin on the next start.
|
|
39
|
+
>
|
|
40
|
+
> Plugins run inside the DSH process; install only trusted sources.
|
|
41
|
+
|
|
42
|
+
### Requirements
|
|
43
|
+
|
|
44
|
+
- DSH Desktop 0.2.2-rc.1 or newer (built and tested on 0.2.2-rc.1).
|
|
45
|
+
- WebGL 2 support; otherwise the preview reports an error.
|
|
46
|
+
- Model and texture files in the session workspace, reachable through **Files** in the right sidebar.
|
|
47
|
+
|
|
48
|
+
## Open a model or texture
|
|
49
|
+
|
|
50
|
+
In any session, open the right sidebar, then **Files** (`Mod+P`), and click an `.fbx`, `.obj`, `.gltf`, `.glb`, `.stl`, `.tga`, `.exr`, or `.hdr` file. It opens in a preview tab; large files and the first environment switch may take a few seconds.
|
|
51
|
+
|
|
52
|
+
If no preview appears, refresh the page; if it still does not, restart DSH.
|
|
53
|
+
|
|
54
|
+
## Supported formats
|
|
55
|
+
|
|
56
|
+
| Format | Support |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| **FBX** | Meshes, hierarchy, materials, embedded textures, animations, and node data |
|
|
59
|
+
| **OBJ** | Polygons, `o`/`g` groups, normals, UVs, vertex colors, line/point primitives, `mtllib`/MTL, and common textures |
|
|
60
|
+
| **glTF, GLB** | Animations, skinning, embedded resources, and external `.bin` files and textures |
|
|
61
|
+
| **STL** | ASCII and binary STL; neutral double-sided PBR material; binary vertex colors preserved |
|
|
62
|
+
| **TGA, EXR, HDR** | Standalone texture previews and sidecar textures for FBX and OBJ; see [Texture previews](#texture-previews) |
|
|
63
|
+
|
|
64
|
+
External resources (FBX and glTF textures, glTF `.bin`, OBJ MTL and textures) are read from the session workspace.
|
|
65
|
+
|
|
66
|
+
Notes:
|
|
67
|
+
|
|
68
|
+
- **All formats**: lights, cameras, and audio embedded in the file are removed; the preview uses its own lighting and camera.
|
|
69
|
+
- **FBX**: a missing external texture warns but does not block geometry.
|
|
70
|
+
- **OBJ**: a missing MTL falls back to default materials; missing textures use white placeholders.
|
|
71
|
+
- **glTF, GLB**: resources shared by several primitives are read once.
|
|
72
|
+
- **STL**: no materials or animations.
|
|
73
|
+
|
|
74
|
+
### Texture previews
|
|
75
|
+
|
|
76
|
+
TGA, EXR, and HDR files can be opened directly from **Files**. The same decoders are used for external FBX and OBJ texture references.
|
|
77
|
+
|
|
78
|
+
| Format | Decoded data | Preview behavior |
|
|
79
|
+
| --- | --- | --- |
|
|
80
|
+
| **TGA** | 8-bit RGBA (RGBA8) | Pixel data is shown directly; alpha is preserved. |
|
|
81
|
+
| **EXR** | 16-bit half float or 32-bit float, 1–4 channels | Linear HDR data is tone-mapped to SDR for display. |
|
|
82
|
+
| **HDR** | Radiance RGBE, decoded to 16-bit half float by default | Linear HDR data is tone-mapped to SDR for display. |
|
|
83
|
+
|
|
84
|
+
- EXR and HDR previews use exposure 1 and Reinhard tone mapping before sRGB output; material rendering keeps the linear values.
|
|
85
|
+
- The metadata badge shows dimensions, per-channel bit depth, and the current zoom percentage.
|
|
86
|
+
- Direct previews support wheel zoom, drag-to-pan when zoomed, **Fit** / double-click reset, and **Flip Y** for bottom-up sources.
|
|
87
|
+
- Decoder chunks are fetched only on first use; opening a PNG or JPEG, or a model that never uses TGA, EXR, or HDR, does not download them.
|
|
88
|
+
|
|
89
|
+
### Not supported
|
|
90
|
+
|
|
91
|
+
- glTF extensions that need extra decoders: Draco, Meshopt, KTX2.
|
|
92
|
+
- Texture formats without a bundled decoder: DDS, KTX2, PVR, and similar (shown as white placeholders).
|
|
93
|
+
- MTL `map_Ks` / `map_Ns` are not fully mapped to PBR yet (`Kd/Ks/Ns/d` and diffuse/normal/bump/emissive/alpha/displacement textures are supported).
|
|
94
|
+
|
|
95
|
+
## Code structure
|
|
96
|
+
|
|
97
|
+
### Host and package
|
|
98
|
+
|
|
99
|
+
| Path | Responsibility |
|
|
100
|
+
| --- | --- |
|
|
101
|
+
| `index.js` | Host half: registers the read-only `/dsh-3d-viewer/hdri` route |
|
|
102
|
+
| `cordis.patch.yml` | Bundle patch that inserts the plugin row |
|
|
103
|
+
| `package.json` | DSH manifest, exports, engines, and package file list |
|
|
104
|
+
| `dist/client.js` | Prebuilt client entry served through `exports["./client"]` |
|
|
105
|
+
| `dist/client.*.js` | Lazy format and texture decoder chunks, colocated with the entry |
|
|
106
|
+
| `icon.svg` | Plugin icon required at the package root |
|
|
107
|
+
| `locale/*.json` | English/Chinese UI dictionaries |
|
|
108
|
+
| `assets/hdri/` | Packaged Poly Haven CC0 HDRIs served by the host route |
|
|
109
|
+
|
|
110
|
+
### Client entry and shared data
|
|
111
|
+
|
|
112
|
+
| Path | Responsibility |
|
|
113
|
+
| --- | --- |
|
|
114
|
+
| `src/client.js` | Registers document previews and Sidebar slots for each format |
|
|
115
|
+
| `src/formats.js` | Model format ids, extensions, titles, and normalization |
|
|
116
|
+
| `src/texture-formats.js` | Standalone texture format ids, extensions, and titles |
|
|
117
|
+
| `src/bytes.js` | Byte, text, path, MIME, and base64 helpers plus cancellation |
|
|
118
|
+
| `src/model.js` | Model stats, embedded-node stripping, and resource disposal |
|
|
119
|
+
|
|
120
|
+
### UI
|
|
121
|
+
|
|
122
|
+
| Path | Responsibility |
|
|
123
|
+
| --- | --- |
|
|
124
|
+
| `src/ui/model-viewer.js` | Viewer container: load lifecycle, settings, and status |
|
|
125
|
+
| `src/ui/viewer-surface.js` | Pure presentation: toolbar, stats, animation bar, and overlay |
|
|
126
|
+
| `src/ui/texture-viewer.js` | Standalone TGA, EXR, HDR texture preview, tone mapping, wheel zoom, pan, and vertical flip |
|
|
127
|
+
| `src/ui/animation-bar.js` | Animation transport and progress updates |
|
|
128
|
+
| `src/ui/chrome.js` | Toolbar, material/environment popovers, and stats panel |
|
|
129
|
+
| `src/ui/primitives.js` | Shared small UI primitives |
|
|
130
|
+
| `src/ui/icons.js` | Inline icons |
|
|
131
|
+
| `src/ui/styles.js` | Scoped styles |
|
|
132
|
+
| `src/ui/dictionaries.js` | English/Chinese copy |
|
|
133
|
+
| `src/ui/options.js` | Material and environment option metadata |
|
|
134
|
+
|
|
135
|
+
### Scene
|
|
136
|
+
|
|
137
|
+
| Path | Responsibility |
|
|
138
|
+
| --- | --- |
|
|
139
|
+
| `src/scene/create-scene-view.js` | Scene orchestration: renderer, camera, controls, and loop |
|
|
140
|
+
| `src/scene/renderer.js` | Renderer creation and fixed Three settings |
|
|
141
|
+
| `src/scene/renderer-pool.js` | Renderer and PMREM reuse across views |
|
|
142
|
+
| `src/scene/environment.js` | HDRI fetch, PMREM construction, and per-id cache |
|
|
143
|
+
| `src/scene/materials.js` | Phong/Lambert → PBR conversion, presets, and wireframe |
|
|
144
|
+
| `src/scene/ground.js` | Infinite grid shader and shadow receiver |
|
|
145
|
+
| `src/scene/animation.js` | AnimationMixer, clip timeline, and progress |
|
|
146
|
+
| `src/scene/camera.js` | Framing, keyboard orbit, and clip planes |
|
|
147
|
+
| `src/scene/lighting.js` | Key/fill lighting and shadows |
|
|
148
|
+
| `src/scene/render-loop.js` | Coalescing frame scheduler |
|
|
149
|
+
| `src/scene/postprocessing.js` | MSAA/ACES pass and dithering |
|
|
150
|
+
| `src/scene/blue-noise.js` | Blue-noise texture |
|
|
151
|
+
| `src/scene/viewer-error.js` | Typed preview errors |
|
|
152
|
+
|
|
153
|
+
### Loaders and chunks
|
|
154
|
+
|
|
155
|
+
| Path | Responsibility |
|
|
156
|
+
| --- | --- |
|
|
157
|
+
| `src/loaders/model-loader.js` | Lazy chunk dispatch and format loading |
|
|
158
|
+
| `src/loaders/fbx.js` | FBX parsing and texture sidecars |
|
|
159
|
+
| `src/loaders/obj.js` | OBJ parsing and MTL/texture resolution |
|
|
160
|
+
| `src/loaders/stl.js` | STL parsing |
|
|
161
|
+
| `src/loaders/gltf.js` | glTF, GLB buffers, textures, animations, and cleanup |
|
|
162
|
+
| `src/loaders/workspace.js` | Resource addresses, workspace reads, TGA, EXR, HDR dispatch, and texture fallback |
|
|
163
|
+
| `src/loaders/chunk-require.js` | `require.async` bridge for DSH package chunks |
|
|
164
|
+
| `src/loaders/three-bridge.js` | Curated Three exports shared with lazy chunks |
|
|
165
|
+
| `src/loaders/chunks/*.js` | One entry per lazy format or texture chunk |
|
|
166
|
+
| `src/vendor/fbx-loader-pbr.js` | Vendored Three FBXLoader with PBR custom attributes |
|
|
167
|
+
|
|
168
|
+
### Build and tests
|
|
169
|
+
|
|
170
|
+
| Path | Responsibility |
|
|
171
|
+
| --- | --- |
|
|
172
|
+
| `build.mjs` | Bundles `dist/client.js`, format chunks, and texture chunks |
|
|
173
|
+
| `tests/run.mjs` | Runs each `tests/*.mjs` in its own process |
|
|
174
|
+
| `tests/*.mjs` | Loaders, renderer pool, HDRI route, SSR, manifest, chunks, and texture previews |
|
|
175
|
+
|
|
176
|
+
Naming: source files use `kebab-case`; React components and classes use `PascalCase`; functions and variables use `camelCase`; module constants use `UPPER_SNAKE_CASE`. Vendored loader internals keep their upstream names.
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
MIT; see [LICENSE](https://github.com/ybniaobu/dsh-3d-viewer/blob/main/LICENSE). Third-party notices are in [THIRD_PARTY_NOTICES.md](https://github.com/ybniaobu/dsh-3d-viewer/blob/main/THIRD_PARTY_NOTICES.md), including Three.js (MIT) and Poly Haven HDRIs (CC0; see [assets/hdri/LICENSE.md](https://github.com/ybniaobu/dsh-3d-viewer/blob/main/assets/hdri/LICENSE.md)). React is provided by DSH and is not distributed with this package.
|
package/README.zh.md
CHANGED
|
@@ -1,114 +1,180 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
<img src="https://raw.githubusercontent.com/ybniaobu/dsh-3d-viewer/main/assets/icon-180.png" alt="3D Viewer 图标" width="96" height="96">
|
|
3
|
-
<h1 align="center">3D Viewer</h1>
|
|
4
|
-
</div>
|
|
5
|
-
|
|
6
|
-
[English](https://github.com/ybniaobu/dsh-3d-viewer/blob/main/README.md) | 中文
|
|
7
|
-
|
|
8
|
-
[](https://github.com/ybniaobu/dsh-3d-viewer) [](https://www.npmjs.com/package/dsh-3d-viewer?activeTab=readme)
|
|
9
|
-
|
|
10
|
-
在 DSH 右侧边栏预览当前会话工作区里的 FBX、OBJ、glTF、GLB、STL
|
|
11
|
-
|
|
12
|
-

|
|
13
|
-
|
|
14
|
-
## 安装与启用
|
|
15
|
-
|
|
16
|
-
插件通过 npm 包 `dsh-3d-viewer` 分发。包内 `client.js`
|
|
17
|
-
|
|
18
|
-
### 从 npm 安装(推荐)
|
|
19
|
-
|
|
20
|
-
1. 打开 DSH Desktop,点击侧边栏的 **Plugins(插件)**。
|
|
21
|
-
2. 点击 **Add plugin(添加插件)** → **Install a third-party plugin(安装第三方插件)**。
|
|
22
|
-
3. 输入 `dsh-3d-viewer`;需要固定版本时写 `dsh-3d-viewer@0.
|
|
23
|
-
4. **Registry** 选择 npm 官方源(国内也可用 npmmirror)。
|
|
24
|
-
5. 点击 **Install**,在 **Installed plugins(已安装插件)** 中确认 **3D Viewer** 为 **On**。
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
|
60
|
-
|
|
|
61
|
-
| **
|
|
62
|
-
| **
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
-
|
|
81
|
-
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
|
100
|
-
|
|
|
101
|
-
| `
|
|
102
|
-
| `
|
|
103
|
-
| `
|
|
104
|
-
| `
|
|
105
|
-
| `
|
|
106
|
-
| `
|
|
107
|
-
| `
|
|
108
|
-
| `
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/ybniaobu/dsh-3d-viewer/main/assets/icon-180.png" alt="3D Viewer 图标" width="96" height="96">
|
|
3
|
+
<h1 align="center">3D Viewer</h1>
|
|
4
|
+
</div>
|
|
5
|
+
|
|
6
|
+
[English](https://github.com/ybniaobu/dsh-3d-viewer/blob/main/README.md) | 中文
|
|
7
|
+
|
|
8
|
+
[](https://github.com/ybniaobu/dsh-3d-viewer) [](https://www.npmjs.com/package/dsh-3d-viewer?activeTab=readme)
|
|
9
|
+
|
|
10
|
+
在 DSH 右侧边栏预览当前会话工作区里的 FBX、OBJ、glTF、GLB、STL 模型,以及 TGA、EXR、HDR 纹理。打开模型即可旋转、缩放、自动旋转、切换材质与环境,并播放内置动画。
|
|
11
|
+
|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
## 安装与启用
|
|
15
|
+
|
|
16
|
+
插件通过 npm 包 `dsh-3d-viewer` 分发。包内 `dist/client.js` 包含查看器与 Three.js 核心;模型 Loader 与 TGA、EXR、HDR 解码器都是包内懒加载 chunk,只在首次使用时加载。四张 HDRI 随包分发,由只读宿主路由从本机 DSH 服务器提供。React 由 DSH 提供。
|
|
17
|
+
|
|
18
|
+
### 从 npm 安装(推荐)
|
|
19
|
+
|
|
20
|
+
1. 打开 DSH Desktop,点击侧边栏的 **Plugins(插件)**。
|
|
21
|
+
2. 点击 **Add plugin(添加插件)** → **Install a third-party plugin(安装第三方插件)**。
|
|
22
|
+
3. 输入 `dsh-3d-viewer`;需要固定版本时写 `dsh-3d-viewer@0.2.0`。
|
|
23
|
+
4. **Registry** 选择 npm 官方源(国内也可用 npmmirror)。
|
|
24
|
+
5. 点击 **Install**,在 **Installed plugins(已安装插件)** 中确认 **3D Viewer** 为 **On**。
|
|
25
|
+
|
|
26
|
+
> **更新**:先在 **Plugins** 中移除旧版本,再安装更高版本的新包。
|
|
27
|
+
|
|
28
|
+
### 从本地目录安装(可选)
|
|
29
|
+
|
|
30
|
+
适合离线或内网分发。
|
|
31
|
+
|
|
32
|
+
1. 把插件目录解压到任意位置,目录需包含 `package.json`、`dist/client.js` 及其 chunks、`index.js`、`cordis.patch.yml` 和 `assets/hdri/` 目录。
|
|
33
|
+
2. 打开 DSH Desktop,点击侧边栏的 **Plugins(插件)**。
|
|
34
|
+
3. 点击 **Add plugin(添加插件)** → **Install a third-party plugin(安装第三方插件)**。
|
|
35
|
+
4. 填入插件目录的绝对路径(例如 `F:\plugins\dsh-3d-viewer`),点击 **Install**。
|
|
36
|
+
5. 在 **Installed plugins(已安装插件)** 中确认 **3D Viewer** 为 **On**。
|
|
37
|
+
|
|
38
|
+
> 本地安装以链接方式引用目录,安装后不要移动、重命名或删除它,否则 DSH 下次启动可能找不到插件。
|
|
39
|
+
>
|
|
40
|
+
> 插件代码在 DSH 进程中运行,请只安装可信来源。
|
|
41
|
+
|
|
42
|
+
### 运行要求
|
|
43
|
+
|
|
44
|
+
- DSH Desktop 0.2.2-rc.1 或更高版本(在 0.2.2-rc.1 上构建和测试)。
|
|
45
|
+
- 支持 WebGL 2,否则预览会报错。
|
|
46
|
+
- 模型和纹理文件位于会话工作区内,可通过右侧边栏的 **Files** 打开。
|
|
47
|
+
|
|
48
|
+
## 打开模型或纹理
|
|
49
|
+
|
|
50
|
+
在任意会话中打开右侧边栏,再打开 **Files**(`Mod+P`),点击 `.fbx`、`.obj`、`.gltf`、`.glb`、`.stl`、`.tga`、`.exr` 或 `.hdr` 文件,即可在预览标签中打开。大文件和第一次切换环境可能需要几秒钟。
|
|
51
|
+
|
|
52
|
+
若没有出现预览,先刷新页面;仍未出现时重启 DSH。
|
|
53
|
+
|
|
54
|
+
## 支持的文件格式
|
|
55
|
+
|
|
56
|
+
| 格式 | 支持内容 |
|
|
57
|
+
| --- | --- |
|
|
58
|
+
| **FBX** | 网格、层级、材质、内嵌贴图、动画、节点数据 |
|
|
59
|
+
| **OBJ** | 多边形、`o`/`g` 分组、法线、UV、顶点色、线与点图元、`mtllib`/MTL、常用贴图 |
|
|
60
|
+
| **glTF、GLB** | 动画、蒙皮、内嵌资源、外部 `.bin` 与贴图 |
|
|
61
|
+
| **STL** | ASCII 与二进制 STL;中性双面 PBR 材质;保留二进制顶点色 |
|
|
62
|
+
| **TGA、EXR、HDR** | 独立纹理预览,以及 FBX、OBJ 的 sidecar 贴图;见下方 [纹理预览](#纹理预览) |
|
|
63
|
+
|
|
64
|
+
外部资源(FBX、glTF 贴图、glTF `.bin`、OBJ MTL 与贴图)均从会话工作区读取。
|
|
65
|
+
|
|
66
|
+
补充说明:
|
|
67
|
+
|
|
68
|
+
- **所有格式**:文件自带的灯光、相机和音频节点会被移除,预览统一使用自己的灯光和相机。
|
|
69
|
+
- **FBX**:外部贴图缺失时仅告警,不阻断几何显示。
|
|
70
|
+
- **OBJ**:缺少 MTL 时回退默认材质;贴图缺失时使用白色占位。
|
|
71
|
+
- **glTF、GLB**:多个图元共用的资源只读取一次。
|
|
72
|
+
- **STL**:没有材质和动画。
|
|
73
|
+
|
|
74
|
+
### 纹理预览
|
|
75
|
+
|
|
76
|
+
TGA、EXR、HDR 文件可以直接从 **Files** 打开;同一套解码器也用于 FBX、OBJ 的外部贴图引用。
|
|
77
|
+
|
|
78
|
+
| 格式 | 解码数据 | 预览行为 |
|
|
79
|
+
| --- | --- | --- |
|
|
80
|
+
| **TGA** | 8-bit RGBA(RGBA8) | 直接显示像素数据,保留 alpha。 |
|
|
81
|
+
| **EXR** | 16-bit half float 或 32-bit float,1–4 通道 | 线性 HDR 数据经色调映射后显示。 |
|
|
82
|
+
| **HDR** | Radiance RGBE,默认解码为 16-bit half float | 线性 HDR 数据经色调映射后显示。 |
|
|
83
|
+
|
|
84
|
+
- EXR、HDR 预览使用曝光 1 和 Reinhard 色调映射,再输出 sRGB;材质渲染仍使用线性值。
|
|
85
|
+
- 元信息显示尺寸、每通道位深和当前缩放比例。
|
|
86
|
+
- 独立预览支持滚轮缩放、放大后拖拽平移、**适应窗口** / 双击复位,以及 **垂直翻转**。
|
|
87
|
+
- 解码 chunk 只在首次使用时加载;打开 PNG、JPEG 或不使用 TGA、EXR、HDR 的模型不会下载它们。
|
|
88
|
+
|
|
89
|
+
### 暂不支持
|
|
90
|
+
|
|
91
|
+
- 需要额外解码器的 glTF 扩展:Draco、Meshopt、KTX2。
|
|
92
|
+
- 暂无内置解码器的贴图格式:DDS、KTX2、PVR 等(显示白色占位)。
|
|
93
|
+
- MTL 的 `map_Ks` / `map_Ns` 尚未完整映射到 PBR(`Kd/Ks/Ns/d` 和 diffuse/normal/bump/emissive/alpha/displacement 贴图已支持)。
|
|
94
|
+
|
|
95
|
+
## 代码结构
|
|
96
|
+
|
|
97
|
+
### 宿主与打包
|
|
98
|
+
|
|
99
|
+
| 路径 | 职责 |
|
|
100
|
+
| --- | --- |
|
|
101
|
+
| `index.js` | 宿主端:注册只读的 `/dsh-3d-viewer/hdri` 路由 |
|
|
102
|
+
| `cordis.patch.yml` | 插入插件行的 bundle patch |
|
|
103
|
+
| `package.json` | DSH manifest、exports、engines 和打包文件列表 |
|
|
104
|
+
| `dist/client.js` | 预构建客户端入口,经 `exports["./client"]` 提供 |
|
|
105
|
+
| `dist/client.*.js` | FBX、OBJ、glTF、GLB、STL 与 TGA、EXR、HDR 懒加载 chunk,与入口同目录 |
|
|
106
|
+
| `icon.svg` | DSH 元信息要求的包根图标 |
|
|
107
|
+
| `locale/*.json` | 中英文 UI 字典 |
|
|
108
|
+
| `assets/hdri/` | 由宿主路由提供的 Poly Haven CC0 HDRI |
|
|
109
|
+
|
|
110
|
+
### 客户端入口与共享数据
|
|
111
|
+
|
|
112
|
+
| 路径 | 职责 |
|
|
113
|
+
| --- | --- |
|
|
114
|
+
| `src/client.js` | 按格式注册 document preview 与 Sidebar slot |
|
|
115
|
+
| `src/formats.js` | 模型格式 id、扩展名、标题与归一化 |
|
|
116
|
+
| `src/texture-formats.js` | 独立纹理格式的 id、扩展名与标题 |
|
|
117
|
+
| `src/bytes.js` | 字节、文本、路径、MIME、base64 辅助与取消错误 |
|
|
118
|
+
| `src/model.js` | 模型统计、内嵌节点剥离与资源释放 |
|
|
119
|
+
|
|
120
|
+
### UI
|
|
121
|
+
|
|
122
|
+
| 路径 | 职责 |
|
|
123
|
+
| --- | --- |
|
|
124
|
+
| `src/ui/model-viewer.js` | 渲染体容器:加载生命周期、设置与状态 |
|
|
125
|
+
| `src/ui/viewer-surface.js` | 纯展示:工具条、统计、动画条与状态浮层 |
|
|
126
|
+
| `src/ui/texture-viewer.js` | TGA、EXR、HDR 独立纹理预览、色调映射、滚轮缩放、拖拽平移与垂直翻转 |
|
|
127
|
+
| `src/ui/animation-bar.js` | 动画播放控制与进度更新 |
|
|
128
|
+
| `src/ui/chrome.js` | 工具条、材质/环境弹层与统计面板 |
|
|
129
|
+
| `src/ui/primitives.js` | 共用小组件 |
|
|
130
|
+
| `src/ui/icons.js` | 内联图标 |
|
|
131
|
+
| `src/ui/styles.js` | 作用域样式 |
|
|
132
|
+
| `src/ui/dictionaries.js` | 中英文案 |
|
|
133
|
+
| `src/ui/options.js` | 材质/环境选项元数据 |
|
|
134
|
+
|
|
135
|
+
### 场景
|
|
136
|
+
|
|
137
|
+
| 路径 | 职责 |
|
|
138
|
+
| --- | --- |
|
|
139
|
+
| `src/scene/create-scene-view.js` | 场景编排:renderer、camera、controls、渲染循环 |
|
|
140
|
+
| `src/scene/renderer.js` | Renderer 创建与固定的 Three 设置 |
|
|
141
|
+
| `src/scene/renderer-pool.js` | 跨视图复用 renderer 与 PMREM |
|
|
142
|
+
| `src/scene/environment.js` | HDRI 获取、PMREM 构建与按 id 缓存 |
|
|
143
|
+
| `src/scene/materials.js` | Phong/Lambert → PBR、材质预设与线框 |
|
|
144
|
+
| `src/scene/ground.js` | 无限网格 shader 与阴影接收面 |
|
|
145
|
+
| `src/scene/animation.js` | AnimationMixer、片段时间轴与进度 |
|
|
146
|
+
| `src/scene/camera.js` | 取景、键盘旋转与裁剪面 |
|
|
147
|
+
| `src/scene/lighting.js` | 主/补光与阴影 |
|
|
148
|
+
| `src/scene/render-loop.js` | 合并帧调度 |
|
|
149
|
+
| `src/scene/postprocessing.js` | MSAA/ACES 与抖动 |
|
|
150
|
+
| `src/scene/blue-noise.js` | 蓝噪声贴图 |
|
|
151
|
+
| `src/scene/viewer-error.js` | 类型化预览错误 |
|
|
152
|
+
|
|
153
|
+
### 加载器与 chunks
|
|
154
|
+
|
|
155
|
+
| 路径 | 职责 |
|
|
156
|
+
| --- | --- |
|
|
157
|
+
| `src/loaders/model-loader.js` | 懒加载 chunk 分派与格式加载 |
|
|
158
|
+
| `src/loaders/fbx.js` | FBX 解析与贴图 sidecar |
|
|
159
|
+
| `src/loaders/obj.js` | OBJ 解析与 MTL/贴图解析 |
|
|
160
|
+
| `src/loaders/stl.js` | STL 解析 |
|
|
161
|
+
| `src/loaders/gltf.js` | glTF、GLB buffer、贴图、动画与清理 |
|
|
162
|
+
| `src/loaders/workspace.js` | 资源地址、工作区读取、TGA、EXR、HDR 分派与贴图回退 |
|
|
163
|
+
| `src/loaders/chunk-require.js` | DSH 包 chunk 的 `require.async` 桥 |
|
|
164
|
+
| `src/loaders/three-bridge.js` | 与懒加载 chunk 共享的 Three 导出 |
|
|
165
|
+
| `src/loaders/chunks/*.js` | 每个懒加载格式/纹理 chunk 一个入口 |
|
|
166
|
+
| `src/vendor/fbx-loader-pbr.js` | vendored Three FBXLoader,额外支持 PBR 自定义属性 |
|
|
167
|
+
|
|
168
|
+
### 构建与测试
|
|
169
|
+
|
|
170
|
+
| 路径 | 职责 |
|
|
171
|
+
| --- | --- |
|
|
172
|
+
| `build.mjs` | 构建 `dist/client.js`、格式 chunk 与纹理 chunk |
|
|
173
|
+
| `tests/run.mjs` | 每个 `tests/*.mjs` 在独立进程中运行 |
|
|
174
|
+
| `tests/*.mjs` | loader、renderer pool、HDRI 路由、SSR、manifest、chunks 与纹理预览 |
|
|
175
|
+
|
|
176
|
+
命名规范:源码文件用 `kebab-case`;React 组件和类用 `PascalCase`;函数和变量用 `camelCase`;模块常量用 `UPPER_SNAKE_CASE`。vendored loader 的内部实现保留上游命名。
|
|
177
|
+
|
|
178
|
+
## 许可证
|
|
179
|
+
|
|
180
|
+
MIT,见 [LICENSE](https://github.com/ybniaobu/dsh-3d-viewer/blob/main/LICENSE)。第三方声明见 [THIRD_PARTY_NOTICES.md](https://github.com/ybniaobu/dsh-3d-viewer/blob/main/THIRD_PARTY_NOTICES.md),包括 Three.js(MIT)与 Poly Haven HDRI(CC0,见 [assets/hdri/LICENSE.md](https://github.com/ybniaobu/dsh-3d-viewer/blob/main/assets/hdri/LICENSE.md))。React 由 DSH 提供,不随包分发。
|