@avatar-platform/avatar-render 0.1.0 → 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 +19 -1
- package/assets/overcast.hdr +0 -0
- package/assets/soft-studio.hdr +0 -0
- package/assets/studio.hdr +0 -0
- package/assets/window.hdr +0 -0
- package/dist/environments.d.ts +20 -0
- package/dist/environments.js +8 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +10 -0
- package/package.json +15 -4
package/README.md
CHANGED
|
@@ -61,7 +61,25 @@ await viewer.loadEnvironment('/signed-download?id=123', 'exr');
|
|
|
61
61
|
- 模型只在显示层居中、统一尺寸,保留模型原始节点变换、骨骼及 PBR 材质。不拼装/导出模型,不播放动画。Y 轴向上、默认面向 +Z,其他朝向可用 `modelRotation` 调整。
|
|
62
62
|
- 同一类资源连续加载采用最后一次调用优先;旧请求完成后释放资源并抛 `AbortError`,不覆盖新请求。替换失败保留先前有效资源。`dispose()` 后的迟到加载同样释放并抛 `AbortError`。底层请求不保证中途停止下载。
|
|
63
63
|
- Draco / KTX2 压缩模型可通过构造参数 `configureModelLoader(loader, renderer)` 配置 Three.js 解码器;解码器地址、加载及解码器自身销毁由宿主负责。默认 GLTFLoader 不配置远端解码设施。
|
|
64
|
-
-
|
|
64
|
+
- 包内置原摄影棚和三套柔光 HDR(合计约 4.34 MB);模型、其他 HDR / EXR、凭据、业务地址不打包。PNG 全景预览图不作为 HDR 环境输入。
|
|
65
|
+
|
|
66
|
+
## 内置 HDR 场景
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { ENVIRONMENT_PRESETS } from '@avatar-platform/avatar-render';
|
|
70
|
+
|
|
71
|
+
await viewer.loadEnvironmentPreset(); // studio:原默认摄影棚
|
|
72
|
+
await viewer.loadEnvironmentPreset('overcast'); // 阴天户外 · 柔和天空
|
|
73
|
+
await viewer.loadEnvironmentPreset('window'); // 室内大窗 · 柔光
|
|
74
|
+
await viewer.loadEnvironmentPreset('soft-studio'); // 均匀展示棚 · 低反差
|
|
75
|
+
// ENVIRONMENT_PRESETS 的只读 id / name / url 可用于创建宿主下拉菜单。
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
构造器仍不自动加载环境;需要默认摄影棚时显式调用 `loadEnvironmentPreset()`。切换只替换环境照明,保留曝光、强度、旋转及模型材质,加载失败保留当前环境。`reset()` 只重置渲染配置和视角,不切换 HDR。`/render-lab` 默认使用原摄影棚,提供四个场景及自定义文件入口。
|
|
79
|
+
|
|
80
|
+
HDR 随 npm 包的 `assets/` 分发,通过相对模块的 `new URL(..., import.meta.url)` 解析;Vite 等支持此写法的构建器会复制资源。直接以原生 ESM 部署时,保留 `dist/` 与 `assets/` 的相对目录;其他构建器需配置 HDR 静态资源处理,或部署 assets 后使用 `loadEnvironment(url, 'hdr')`。按选择加载一套,不会预加载全部 HDR。
|
|
81
|
+
|
|
82
|
+
新增三套为建模师提供的原创程序化 2048×1024 Radiance RGBE、线性光环境,分别为微冷天空、暖中性侧窗和中性低反差棚光;名称描述照明风格,不是真实场景照片。可保持强度 1 对比,过亮时尝试 0.7;不覆盖原模型 roughness / metalness。包仅包含 HDR,不包含材质球测试或全景预览 PNG。
|
|
65
83
|
|
|
66
84
|
## 配置
|
|
67
85
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Bundled HDR assets, resolved relative to this module by browser bundlers. */
|
|
2
|
+
export declare const ENVIRONMENT_PRESETS: readonly [Readonly<{
|
|
3
|
+
id: "studio";
|
|
4
|
+
name: "默认摄影棚";
|
|
5
|
+
url: string;
|
|
6
|
+
}>, Readonly<{
|
|
7
|
+
id: "overcast";
|
|
8
|
+
name: "阴天户外 · 柔和天空";
|
|
9
|
+
url: string;
|
|
10
|
+
}>, Readonly<{
|
|
11
|
+
id: "window";
|
|
12
|
+
name: "室内大窗 · 柔光";
|
|
13
|
+
url: string;
|
|
14
|
+
}>, Readonly<{
|
|
15
|
+
id: "soft-studio";
|
|
16
|
+
name: "均匀展示棚 · 低反差";
|
|
17
|
+
url: string;
|
|
18
|
+
}>];
|
|
19
|
+
export type EnvironmentPresetId = typeof ENVIRONMENT_PRESETS[number]['id'];
|
|
20
|
+
export declare const DEFAULT_ENVIRONMENT_PRESET: EnvironmentPresetId;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Bundled HDR assets, resolved relative to this module by browser bundlers. */
|
|
2
|
+
export const ENVIRONMENT_PRESETS = Object.freeze([
|
|
3
|
+
Object.freeze({ id: 'studio', name: '默认摄影棚', url: new URL('../assets/studio.hdr', import.meta.url).href }),
|
|
4
|
+
Object.freeze({ id: 'overcast', name: '阴天户外 · 柔和天空', url: new URL('../assets/overcast.hdr', import.meta.url).href }),
|
|
5
|
+
Object.freeze({ id: 'window', name: '室内大窗 · 柔光', url: new URL('../assets/window.hdr', import.meta.url).href }),
|
|
6
|
+
Object.freeze({ id: 'soft-studio', name: '均匀展示棚 · 低反差', url: new URL('../assets/soft-studio.hdr', import.meta.url).href })
|
|
7
|
+
]);
|
|
8
|
+
export const DEFAULT_ENVIRONMENT_PRESET = 'studio';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
|
3
3
|
import { type RenderConfig } from './config.js';
|
|
4
|
+
import { type EnvironmentPresetId } from './environments.js';
|
|
5
|
+
export { DEFAULT_ENVIRONMENT_PRESET, ENVIRONMENT_PRESETS, type EnvironmentPresetId } from './environments.js';
|
|
4
6
|
export { DEFAULT_RENDER_CONFIG, type RenderConfig } from './config.js';
|
|
5
7
|
export type AssetSource = string | File;
|
|
6
8
|
export type EnvironmentFormat = 'hdr' | 'exr';
|
|
@@ -39,6 +41,8 @@ export declare class AvatarRenderer {
|
|
|
39
41
|
reset(): void;
|
|
40
42
|
/** Latest request wins. Failed replacements preserve the last valid model. */
|
|
41
43
|
loadModel(source: AssetSource): Promise<void>;
|
|
44
|
+
/** Load bundled lighting without changing render settings. Defaults to the original studio. */
|
|
45
|
+
loadEnvironmentPreset(id?: EnvironmentPresetId): Promise<void>;
|
|
42
46
|
/** Format is inferred from file name or URL path; pass it explicitly for opaque URLs. */
|
|
43
47
|
loadEnvironment(source: AssetSource, format?: EnvironmentFormat): Promise<void>;
|
|
44
48
|
/** Fit the entire model and return the camera to the front. */
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,8 @@ import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
|
|
|
4
4
|
import { EXRLoader } from 'three/addons/loaders/EXRLoader.js';
|
|
5
5
|
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
|
6
6
|
import { DEFAULT_RENDER_CONFIG, resolveConfig } from './config.js';
|
|
7
|
+
import { DEFAULT_ENVIRONMENT_PRESET, ENVIRONMENT_PRESETS } from './environments.js';
|
|
8
|
+
export { DEFAULT_ENVIRONMENT_PRESET, ENVIRONMENT_PRESETS } from './environments.js';
|
|
7
9
|
export { DEFAULT_RENDER_CONFIG } from './config.js';
|
|
8
10
|
function disposeModel(root) {
|
|
9
11
|
const geometries = new Set();
|
|
@@ -144,6 +146,14 @@ export class AvatarRenderer {
|
|
|
144
146
|
asset.release();
|
|
145
147
|
}
|
|
146
148
|
}
|
|
149
|
+
/** Load bundled lighting without changing render settings. Defaults to the original studio. */
|
|
150
|
+
async loadEnvironmentPreset(id = DEFAULT_ENVIRONMENT_PRESET) {
|
|
151
|
+
this.assertActive();
|
|
152
|
+
const preset = ENVIRONMENT_PRESETS.find((entry) => entry.id === id);
|
|
153
|
+
if (!preset)
|
|
154
|
+
throw new TypeError(`Unknown environment preset: ${id}`);
|
|
155
|
+
await this.loadEnvironment(preset.url, 'hdr');
|
|
156
|
+
}
|
|
147
157
|
/** Format is inferred from file name or URL path; pass it explicitly for opaque URLs. */
|
|
148
158
|
async loadEnvironment(source, format) {
|
|
149
159
|
this.assertActive();
|
package/package.json
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avatar-platform/avatar-render",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Framework-independent GLB viewer with configurable HDR/EXR studio lighting",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"assets",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
10
19
|
"sideEffects": false,
|
|
11
20
|
"publishConfig": {
|
|
12
21
|
"access": "public",
|
|
@@ -18,7 +27,9 @@
|
|
|
18
27
|
"test": "vitest run",
|
|
19
28
|
"prepack": "pnpm build"
|
|
20
29
|
},
|
|
21
|
-
"peerDependencies": {
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"three": "^0.180.0"
|
|
32
|
+
},
|
|
22
33
|
"devDependencies": {
|
|
23
34
|
"three": "^0.180.0",
|
|
24
35
|
"@types/three": "^0.180.0",
|