@soonspacejs/plugin-fds 2.15.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.
@@ -0,0 +1,48 @@
1
+ import { TSimulatesManifest, TSliceData, TVolumePointsShape } from './fds.types';
2
+ /** 播放时预取的前瞻秒数。 */
3
+ declare const PLAYBACK_CHUNK_LOOKAHEAD_SEC = 1;
4
+ /** 统一路径格式,避免 zip 内路径和运行时路径分隔符不一致。 */
5
+ declare function normalizeFdsPath(path: string): string;
6
+ /** 根据全局帧索引定位它所在的数据分片。 */
7
+ declare function findItemForGlobalFrame(manifest: TSimulatesManifest, globalFrameIndex: number): {
8
+ item: {
9
+ seq: number;
10
+ grids: number;
11
+ frames: number;
12
+ url: string;
13
+ };
14
+ chunkStartFrame: number;
15
+ };
16
+ /** 判断一个分片的所有帧是否都已经进入内存缓存。 */
17
+ declare function isChunkFramesLoaded(frames: (Uint8ClampedArray | undefined)[], chunkStartFrame: number, chunkFrameCount: number): boolean;
18
+ /** 找出和目标帧区间有交集的所有分片起始帧。 */
19
+ declare function chunkStartFramesOverlappingFrameRange(manifest: TSimulatesManifest, fMin: number, fMax: number): number[];
20
+ /**
21
+ * 优先返回目标帧;如果该帧尚未解码,就退而求其次取最近的已解码帧。
22
+ * 这样时间轴可以继续推进,不必硬等精确帧解码完成。
23
+ */
24
+ declare function findBestRenderableFrame(frames: (Uint8ClampedArray | undefined)[], preferredFrameIndex: number): number;
25
+ /** 推断整段模拟时长,优先使用导出时携带的真实秒数。 */
26
+ declare function inferSimulationDurationSec(manifest: TSimulatesManifest, slice: TSliceData, totalFrames: number, preferredDurationSec?: number): number;
27
+ /** 把外部传入的帧索引收敛到合法范围内。 */
28
+ declare function clampFrameIndex(frameIndex: number, totalFrames: number): number;
29
+ /** 把帧索引换算成物理秒数。 */
30
+ declare function frameIndexToTime(frameIndex: number, maxTime: number, totalFrames: number, slice?: TSliceData): number;
31
+ /** 把物理秒数换算成最接近的帧索引。 */
32
+ declare function timeToFrameIndex(timeSec: number, maxTime: number, totalFrames: number, slice?: TSliceData): number;
33
+ /** 保证传给 worker 的是可安全转移所有权的独立 ArrayBuffer。 */
34
+ declare function toTransferableArrayBuffer(bytes: Uint8Array): ArrayBuffer;
35
+ /**
36
+ * 对解码 worker 做一层包装,把消息分发、Promise 生命周期和销毁逻辑
37
+ * 集中在这里,主加载流程只关心“请求一个分片并拿到帧数组”。
38
+ */
39
+ declare function createChunkFramesReader(shape: TVolumePointsShape): {
40
+ /** 解码已经从 zip 中读出的分片字节。 */
41
+ readChunk(arrayBuffer: ArrayBuffer, item: TSimulatesManifest["items"][number], startFrameIndex: number): Promise<{
42
+ frames: Uint8ClampedArray[];
43
+ startFrameIndex: number;
44
+ }>;
45
+ /** 终止 worker,并让所有挂起请求立刻失败。 */
46
+ dispose(): void;
47
+ };
48
+ export { PLAYBACK_CHUNK_LOOKAHEAD_SEC, chunkStartFramesOverlappingFrameRange, clampFrameIndex, createChunkFramesReader, findBestRenderableFrame, findItemForGlobalFrame, frameIndexToTime, inferSimulationDurationSec, isChunkFramesLoaded, normalizeFdsPath, timeToFrameIndex, toTransferableArrayBuffer, };
@@ -0,0 +1,15 @@
1
+ import { default as SoonSpace } from 'soonspacejs';
2
+ import { Box3, Object3D } from 'three';
3
+ import { FdsMesh } from '../class/FdsMesh';
4
+ import { TVolumePointsShape } from './fds.types';
5
+ /**
6
+ * 统计场景里可见、可渲染对象的包围盒。
7
+ * 已经存在的 FDS 对象会被跳过,避免重复加载时把旧体渲染结果算进去。
8
+ */
9
+ declare function getRenderableSceneBox(ssp: SoonSpace, root?: Object3D): Box3;
10
+ /**
11
+ * 根据场景包围盒创建 FDS 网格。
12
+ * 如果场景里暂时没有可用几何,则退回到一个以原点为中心的默认盒子。
13
+ */
14
+ declare function createFdsMeshBySceneBox(ssp: SoonSpace, shape: TVolumePointsShape, root?: Object3D): FdsMesh;
15
+ export { createFdsMeshBySceneBox, getRenderableSceneBox, };
@@ -0,0 +1,3 @@
1
+ import { Matrix4 } from 'three';
2
+ export declare const fdsSpaceMatrix: Matrix4;
3
+ export declare const threeToFdsSpaceMatrix: Matrix4;
@@ -0,0 +1,55 @@
1
+ export type TVolumePointsShape = {
2
+ /** 体素宽度。 */
3
+ width: number;
4
+ /** 体素高度。 */
5
+ height: number;
6
+ /** 体素深度。 */
7
+ depth: number;
8
+ };
9
+ /** FDS 网格在 x/y/z 三个轴上的离散尺寸。 */
10
+ export type TFdsMeshIjk = {
11
+ x: number;
12
+ y: number;
13
+ z: number;
14
+ };
15
+ /** FDS 网格在 FDS 坐标系中的包围盒范围。 */
16
+ export type TFdsMeshXb = {
17
+ minX: number;
18
+ minY: number;
19
+ minZ: number;
20
+ maxX: number;
21
+ maxY: number;
22
+ maxZ: number;
23
+ };
24
+ /** 加载 FDS 时允许外部传入的覆盖参数。 */
25
+ export type TFdsLoadOptions = {
26
+ meshIjk?: TFdsMeshIjk;
27
+ meshXb?: TFdsMeshXb;
28
+ simulationDurationSec?: number;
29
+ initialTimeSec?: number;
30
+ /** 指定要读取的 FDS 字段。 */
31
+ field?: 'temperature' | 'soot_density' | 'hrrpuv';
32
+ };
33
+ /** 构建端导出的分片清单,`shape` 为 `[宽, 高, 深, 总帧数]`。 */
34
+ export type TSimulatesManifest = {
35
+ multiple?: number;
36
+ simulationDurationSec?: number;
37
+ headers: {
38
+ shape: [number, number, number, number];
39
+ maxValue?: number;
40
+ };
41
+ items: {
42
+ seq: number;
43
+ grids: number;
44
+ frames: number;
45
+ url: string;
46
+ }[];
47
+ };
48
+ /** 可选的帧时间映射,用于把帧索引还原成物理秒数。 */
49
+ export type TSliceData = {
50
+ frames?: {
51
+ seq: number;
52
+ time: number;
53
+ url: string;
54
+ }[];
55
+ };
@@ -0,0 +1,9 @@
1
+ /** 严格按 gzip 解压,调用方应确保输入本身就是 gzip。 */
2
+ export declare function gunzipArrayBuffer(buf: ArrayBufferLike): Uint8Array;
3
+ /** 如果是 gzip 则解压,否则保持原样返回。 */
4
+ export declare function gunzipArrayBufferIfNeeded(buf: ArrayBufferLike): Uint8Array;
5
+ /**
6
+ * 循环剥离可能叠加的 gzip 包装,直到拿到真正的 NDAV2 负载。
7
+ * 这样可以兼容对象存储、代理层或构建产物里多层 gzip 的情况。
8
+ */
9
+ export declare function prepareNdav2ChunkPayload(buf: ArrayBufferLike): Uint8Array;
@@ -0,0 +1,10 @@
1
+ import { default as SoonSpace } from 'soonspacejs';
2
+ import { Object3D } from 'three';
3
+ import { VolumePoints } from '../class/VolumePoints';
4
+ import { TFdsLoadOptions } from './fds.types';
5
+ /**
6
+ * 加载 FDS 压缩包,按需解码分片数据,并挂载成 `VolumePoints`。
7
+ * 对外暴露的是“按秒播放”的能力,内部仍然按帧和分片做缓存。
8
+ */
9
+ declare function loadFDS(ssp: SoonSpace, url: string, parent?: Object3D | null, options?: TFdsLoadOptions): Promise<VolumePoints>;
10
+ export { loadFDS, };
@@ -0,0 +1,10 @@
1
+ import { default as ndarray } from 'ndarray';
2
+ /**
3
+ * 读取 NDAV2 浮点体素数据。
4
+ * 文件头为 `NDAV2`,后面紧跟 `gridFloats` 个 float32 数据。
5
+ */
6
+ export declare function readNdav2Floats(buf: Uint8Array, gridFloats: number): Float32Array;
7
+ /** 如果输入是 gzip 包装,则先解压再按 NDA 解析。 */
8
+ export declare function readAsNdArrayMaybeGzip(buf: Uint8Array): Promise<ndarray.NdArray<Float32Array<ArrayBuffer>> | undefined>;
9
+ /** 读取 NDA 数据并解析成 `ndarray` 结构。 */
10
+ export declare function readAsNdArray(buf: Uint8Array): Promise<ndarray.NdArray<Float32Array<ArrayBuffer>> | undefined>;
@@ -0,0 +1,19 @@
1
+ /** 返回给主线程的体素尺寸描述。 */
2
+ type TVolumePointsShape = {
3
+ width: number;
4
+ height: number;
5
+ depth: number;
6
+ };
7
+ /** 读取旧版 NDA v1 文件,同时兼容 gzip 包装。 */
8
+ export declare function readNdaSingle(url: string, pageOrigin?: string): Promise<{
9
+ shape: TVolumePointsShape;
10
+ frames: Uint8ClampedArray<ArrayBufferLike>[];
11
+ transfers: ArrayBuffer[];
12
+ }>;
13
+ /** 拉取并解码一个 NDAV2 分片。 */
14
+ export declare function readNdav2ChunkOnly(chunkUrl: string, grids: number, chunkFrameCount: number, xs: number, ys: number, zs: number, pageOrigin?: string): Promise<{
15
+ shape: TVolumePointsShape;
16
+ frames: Uint8ClampedArray<ArrayBuffer>[];
17
+ transfers: ArrayBuffer[];
18
+ }>;
19
+ export {};
@@ -0,0 +1,14 @@
1
+ /** 轻量 zip 读取器,只实现当前 FDS 压缩包所需的读取能力。 */
2
+ declare class ZipArchive {
3
+ #private;
4
+ constructor(bytes: ArrayBuffer | Uint8Array);
5
+ /** 判断指定文件是否存在于 zip 包中。 */
6
+ has(name: string): boolean;
7
+ /** 读取并按压缩方式解出指定文件的原始字节。 */
8
+ read(name: string): Uint8Array<ArrayBufferLike>;
9
+ /** 读取文本文件。 */
10
+ readText(name: string): string;
11
+ /** 读取 JSON 文件并直接反序列化。 */
12
+ readJson<T>(name: string): T;
13
+ }
14
+ export { ZipArchive, };
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@soonspacejs/plugin-fds",
3
+ "pluginName": "FdsPlugin",
4
+ "version": "2.15.1",
5
+ "description": "FDS plugin for SoonSpace.js",
6
+ "main": "dist/index.esm.js",
7
+ "module": "dist/index.esm.js",
8
+ "unpkg": "dist/index.esm.js",
9
+ "typings": "dist/index.d.ts",
10
+ "keywords": [
11
+ "soonspacejs",
12
+ "fds"
13
+ ],
14
+ "author": "xunwei",
15
+ "license": "UNLICENSED",
16
+ "gitHead": "4a87dd85050651088e11c3da777c49fab3db7e5d",
17
+ "peerDependencies": {
18
+ "soonspacejs": "2.15.1",
19
+ "fflate": "^0.8.2",
20
+ "ndarray": "^1.0.19",
21
+ "three": "^0.183.0"
22
+ }
23
+ }