s3m-three 0.4.24 → 0.4.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "s3m-three",
3
- "version": "0.4.24",
3
+ "version": "0.4.25",
4
4
  "description": "SuperMap S3M 三维模型格式的 three.js 渲染内核:浏览器内直接解析 .s3mb 瓦片,无需转 3D Tiles,支持 LOD 调度、白膜/按高度/按单体/动态扫描着色、单体级 GPU 拾取。宿主无关,可单独用于任意 three 场景。",
5
5
  "type": "module",
6
6
  "repository": {
@@ -2,10 +2,13 @@
2
2
  * DXT1 / DXT3 / DXT5 纹理解码(squish 算法的 JS 移植)
3
3
  *
4
4
  * 来源:SuperMap iClient3D S3M SDK(Apache-2.0)。
5
- * 迁移到 TS 时做了两件事,算法本身未改:
5
+ * 迁移到 TS 时做了三件事,算法本身未改:
6
6
  * 1. 补齐类型;
7
7
  * 2. 修掉 `DecompressAlphaDxt3` 里把 `block` 误写成未定义全局 `bytes` 的笔误
8
- * (DXT3 纹理此前会直接 ReferenceError)。
8
+ * (DXT3 纹理此前会直接 ReferenceError);
9
+ * 3. 修掉 `DecompressImage565` 的两处 flipY 笔误(见下方函数内注释:
10
+ * 块行下标少减 1 让 format ≤ 11 的 DXT1 顶部块行整行变黑;块内 4 行
11
+ * 没倒着写,导致行序和 `DecompressImage` 主路径对不上)。
9
12
  */
10
13
 
11
14
  const kDxt1 = 1 << 0;
@@ -158,7 +161,13 @@ function DecompressImage565(rgb565: Uint16Array, width: number, height: number,
158
161
  const blockHeight = height / 4;
159
162
  for (let blockY = 0; blockY < blockHeight; blockY++) {
160
163
  for (let blockX = 0; blockX < blockWidth; blockX++) {
161
- i = 4 * ((blockHeight - blockY) * blockWidth + blockX);
164
+ // flipY 分两级做,才和 DecompressImage 的 height - 1 - sy 真正同口径:
165
+ // ① 块行倒着取(blockHeight - 1 - blockY);
166
+ // ② 块内 4 行也倒着写(下面 dstI 从块底行起、逐行 -= width)。
167
+ // 只做 ① 会变成「块带倒序、带内行正序」的错位图,和主路径对不上。
168
+ // 写成 blockHeight - blockY 则会让 blockY=0 读到数组界外(Uint16Array 越界读
169
+ // 得 undefined,位运算后归 0),顶部块行解成全黑、其余块行整体错位一行。
170
+ i = 4 * ((blockHeight - 1 - blockY) * blockWidth + blockX);
162
171
  c[0] = blocks[i];
163
172
  c[1] = blocks[i + 1];
164
173
  r0 = c[0] & 0x1f;
@@ -172,23 +181,24 @@ function DecompressImage565(rgb565: Uint16Array, width: number, height: number,
172
181
  c[2] = ((5 * r0 + 3 * r1) >> 3) | (((5 * g0 + 3 * g1) >> 3) & 0x7e0) | (((5 * b0 + 3 * b1) >> 3) & 0xf800);
173
182
  c[3] = ((5 * r1 + 3 * r0) >> 3) | (((5 * g1 + 3 * g0) >> 3) & 0x7e0) | (((5 * b1 + 3 * b0) >> 3) & 0xf800);
174
183
  m = blocks[i + 2];
175
- dstI = blockY * 4 * width + blockX * 4;
184
+ // 块内第 0 行写到块底行,逐行往上走 —— 逐行 flipY
185
+ dstI = (blockY * 4 + 3) * width + blockX * 4;
176
186
  dst[dstI] = c[m & 0x3];
177
187
  dst[dstI + 1] = c[(m >> 2) & 0x3];
178
188
  dst[dstI + 2] = c[(m >> 4) & 0x3];
179
189
  dst[dstI + 3] = c[(m >> 6) & 0x3];
180
- dstI += width;
190
+ dstI -= width;
181
191
  dst[dstI] = c[(m >> 8) & 0x3];
182
192
  dst[dstI + 1] = c[(m >> 10) & 0x3];
183
193
  dst[dstI + 2] = c[(m >> 12) & 0x3];
184
194
  dst[dstI + 3] = c[(m >> 14) & 0x3];
185
195
  m = blocks[i + 3];
186
- dstI += width;
196
+ dstI -= width;
187
197
  dst[dstI] = c[m & 0x3];
188
198
  dst[dstI + 1] = c[(m >> 2) & 0x3];
189
199
  dst[dstI + 2] = c[(m >> 4) & 0x3];
190
200
  dst[dstI + 3] = c[(m >> 6) & 0x3];
191
- dstI += width;
201
+ dstI -= width;
192
202
  dst[dstI] = c[(m >> 8) & 0x3];
193
203
  dst[dstI + 1] = c[(m >> 10) & 0x3];
194
204
  dst[dstI + 2] = c[(m >> 12) & 0x3];
@@ -41,7 +41,7 @@ interface MeshUserData {
41
41
  }
42
42
 
43
43
  /** 拾取 ID 只有 2 个字节(RG 两个通道),65534 是安全上限 */
44
- const MAX_PICK_ID = 65534;
44
+ export const MAX_PICK_ID = 65534;
45
45
 
46
46
  export interface PickHost {
47
47
  readonly picker: Picker | null;