@rtzh/engine 0.0.10 → 0.0.11

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 CHANGED
@@ -1,9 +1,69 @@
1
- # @rtzh/engine
2
-
3
- > ⚠️ 本项目是基于 CesiumJS 的 `@cesium/engine` 22.1.0 包修改而来的定制版本。
4
- >
5
- > 原始项目来源:[CesiumGS/cesium](https://github.com/CesiumGS/cesium)
6
-
7
- ## License
8
-
9
- [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0.html). CesiumJS is free for both commercial and non-commercial use.
1
+ # @rtzh/engine
2
+
3
+ > ⚠️ 本项目是基于 CesiumJS 的 `@cesium/engine` 22.1.0 包修改而来的定制版本。
4
+ >
5
+ > 原始项目来源:[CesiumGS/cesium](https://github.com/CesiumGS/cesium)
6
+
7
+ ## License
8
+
9
+ [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0.html). CesiumJS is free for both commercial and non-commercial use.
10
+
11
+ ## 变更日志
12
+
13
+ ### 功能新增(Features)
14
+
15
+ #### 模型及3D图块线框显示功能
16
+
17
+ - 在 `Model` 类中新增 `showWireframe`、`hideWireframe` 和 `toggleWireframe` 方法,实现模型的线框渲染切换
18
+ - 在 `Cesium3DTileset` 类中新增对应的线框显示方法,支持对整个3D图块集切换线框模式
19
+ - 支持设置线框颜色及颜色混合模式
20
+ - 支持链式调用以方便设置和切换线框状态
21
+ - 对WebGL1环境添加提示,需启用 `enableDebugWireframe` 才能生效
22
+
23
+ #### 基于重心坐标的线框调试模式支持
24
+
25
+ - 在 `Model` 和 `Cesium3DTileset` 中新增 `debugWireframeMode` 属性,支持 `"lines"` 和 `"barycentric"` 两种模式切换
26
+ - 新增 `debugWireframeColor`、`debugWireframeFillAlpha`、`debugWireframeLineWidth` 和 `debugWireframeOverlay` 属性,丰富线框渲染配置
27
+ - 实现基于重心坐标的线框渲染管线,添加 `BarycentricWireframePipelineStage`
28
+ - 修改顶点着色器(`ModelVS.glsl`)和片段着色器(`ModelFS.glsl`)以支持重心线框效果及叠加选项
29
+ - 在 `WireframePipelineStage` 中增加对 barycentric 模式的跳过逻辑,避免重复渲染和冲突
30
+ - 在 `Model3DTileContent` 中同步新线框调试属性,保证瓦片模型线框一致性
31
+ - 兼容WebGL1和WebGL2环境,lines模式需启用 `enableDebugWireframe`,barycentric模式无需
32
+
33
+ #### 线框扫描线和发光效果支持
34
+
35
+ - 在 `Model` 和 `Cesium3DTileset` 中添加 `effects` 参数支持扫描线和发光配置
36
+ - 实现扫描线方向、速度和发光强度的计算逻辑
37
+ - 根据扫描线方向计算扫描范围和模型高度范围
38
+ - 在 `Model3DTileContent` 中传递相关有线框效果参数
39
+ - 修改片段着色器(`ModelFS.glsl`)添加扫描线高亮和发光效果的计算与混合
40
+ - 修改顶点着色器(`ModelVS.glsl`)传递模型世界坐标,支持扫描线效果
41
+
42
+ #### 点光源照明支持
43
+
44
+ - 新增 `PointLight` 类描述点光源属性及构造方法
45
+ - 在 `Scene` 中添加点光数组以支持额外光照
46
+ - `UniformState` 中添加点光相关状态及自动uniform支持
47
+ - `LightingPipelineStage` 新增点光相关宏定义和光照计算逻辑
48
+ - `Model` 增加点光变化检测并触发绘制命令重建
49
+ - 实现点光位置、颜色及范围等数据上传至GPU uniform数组
50
+ - 维护点光数量限制为8并确保对应uniform数组长度匹配
51
+ - 优化点光范围衰减和平滑过渡计算保障渲染效果
52
+ - 在 `AutomaticUniforms.js` 中新增自动uniform以支持点光源数据传递到GLSL着色器
53
+ - 在 `LightingStageFS.glsl` 中实现点光源光照计算代码,支持范围衰减和距离衰减
54
+ - 在 `FrameState` 中新增 `pointLights` 字段以传递点光源信息
55
+
56
+ ### Bug修复(Fixes)
57
+
58
+ - **优化 Model 的调试线框属性设置逻辑**
59
+ - 修正 `debugWireframeColor` 赋值时避免无效克隆和重复设置
60
+ - 添加 `debugWireframeFillAlpha` 赋值的重复值检测以减少无谓重绘
61
+ - 在 `Model3DTileContent` 中仅当 `debugWireframe` 开启时赋值相关调试线框属性
62
+ - 移除未启用 `debugWireframe` 时对 `model.color` 的无效赋值
63
+ - 统一默认的 `_debugWireframeScanAxis` 为 `Cartesian3(0, 0, 1)` 实例
64
+
65
+ ### 重构(Refactors)
66
+
67
+ - 优化多个模块的代码结构和逻辑
68
+ - 修正 Model 加载中 Feature ID 属性的类名称
69
+ - 移除调试扫描线相关的多余高度变量和优化着色器逻辑
@@ -65,6 +65,23 @@ MaterialPipelineStage.process = function (
65
65
  const hasClassification = defined(model.classificationType);
66
66
  const disableTextures = hasClassification;
67
67
 
68
+ // Collect the texture coordinate sets actually present in the geometry.
69
+ // Some models reference a texture whose UV set (e.g. TEXCOORD_0) does not
70
+ // exist on the mesh. If we still generate a `TEXCOORD_*` define for such a
71
+ // texture, the fragment shader would reference an undeclared
72
+ // `v_texCoord_n` varying and fail to compile, so those textures are skipped.
73
+ const texCoordSets = new Set();
74
+ const attributes = primitive.attributes;
75
+ for (let i = 0; i < attributes.length; i++) {
76
+ const attribute = attributes[i];
77
+ if (
78
+ attribute.semantic === VertexAttributeSemantic.TEXCOORD &&
79
+ defined(attribute.setIndex)
80
+ ) {
81
+ texCoordSets.add(attribute.setIndex);
82
+ }
83
+ }
84
+
68
85
  // When textures are loaded incrementally, fall back to a default 1x1 texture
69
86
  const { defaultTexture, defaultNormalTexture, defaultEmissiveTexture } =
70
87
  frameState.context;
@@ -77,6 +94,7 @@ MaterialPipelineStage.process = function (
77
94
  defaultNormalTexture,
78
95
  defaultEmissiveTexture,
79
96
  disableTextures,
97
+ texCoordSets,
80
98
  );
81
99
 
82
100
  if (defined(material.specularGlossiness)) {
@@ -86,6 +104,7 @@ MaterialPipelineStage.process = function (
86
104
  shaderBuilder,
87
105
  defaultTexture,
88
106
  disableTextures,
107
+ texCoordSets,
89
108
  );
90
109
  } else {
91
110
  if (
@@ -98,6 +117,7 @@ MaterialPipelineStage.process = function (
98
117
  shaderBuilder,
99
118
  defaultTexture,
100
119
  disableTextures,
120
+ texCoordSets,
101
121
  );
102
122
  }
103
123
  if (
@@ -110,6 +130,7 @@ MaterialPipelineStage.process = function (
110
130
  shaderBuilder,
111
131
  defaultTexture,
112
132
  disableTextures,
133
+ texCoordSets,
113
134
  );
114
135
  }
115
136
  if (
@@ -122,6 +143,7 @@ MaterialPipelineStage.process = function (
122
143
  shaderBuilder,
123
144
  defaultTexture,
124
145
  disableTextures,
146
+ texCoordSets,
125
147
  );
126
148
  }
127
149
  processMetallicRoughnessUniforms(
@@ -130,6 +152,7 @@ MaterialPipelineStage.process = function (
130
152
  shaderBuilder,
131
153
  defaultTexture,
132
154
  disableTextures,
155
+ texCoordSets,
133
156
  );
134
157
  }
135
158
 
@@ -272,7 +295,15 @@ function processTexture(
272
295
  uniformName,
273
296
  defineName,
274
297
  defaultTexture,
298
+ texCoordSets,
275
299
  ) {
300
+ // If the texture references a texture coordinate set that is not present in
301
+ // the geometry, skip it entirely. Otherwise the generated fragment shader
302
+ // would use an undeclared `v_texCoord_n` varying and fail to compile.
303
+ if (!texCoordSets.has(textureReader.texCoord)) {
304
+ return;
305
+ }
306
+
276
307
  // Add a uniform for the texture itself
277
308
  shaderBuilder.addUniform(
278
309
  "sampler2D",
@@ -333,6 +364,7 @@ function processMaterialUniforms(
333
364
  defaultNormalTexture,
334
365
  defaultEmissiveTexture,
335
366
  disableTextures,
367
+ texCoordSets,
336
368
  ) {
337
369
  const { emissiveFactor, emissiveTexture, normalTexture, occlusionTexture } =
338
370
  material;
@@ -363,6 +395,7 @@ function processMaterialUniforms(
363
395
  "u_emissiveTexture",
364
396
  "EMISSIVE",
365
397
  defaultEmissiveTexture,
398
+ texCoordSets,
366
399
  );
367
400
  }
368
401
  }
@@ -375,6 +408,7 @@ function processMaterialUniforms(
375
408
  "u_normalTexture",
376
409
  "NORMAL",
377
410
  defaultNormalTexture,
411
+ texCoordSets,
378
412
  );
379
413
  }
380
414
 
@@ -386,6 +420,7 @@ function processMaterialUniforms(
386
420
  "u_occlusionTexture",
387
421
  "OCCLUSION",
388
422
  defaultTexture,
423
+ texCoordSets,
389
424
  );
390
425
  }
391
426
  }
@@ -406,6 +441,7 @@ function processSpecularGlossinessUniforms(
406
441
  shaderBuilder,
407
442
  defaultTexture,
408
443
  disableTextures,
444
+ texCoordSets,
409
445
  ) {
410
446
  const {
411
447
  diffuseTexture,
@@ -429,6 +465,7 @@ function processSpecularGlossinessUniforms(
429
465
  "u_diffuseTexture",
430
466
  "DIFFUSE",
431
467
  defaultTexture,
468
+ texCoordSets,
432
469
  );
433
470
  }
434
471
 
@@ -459,6 +496,7 @@ function processSpecularGlossinessUniforms(
459
496
  "u_specularGlossinessTexture",
460
497
  "SPECULAR_GLOSSINESS",
461
498
  defaultTexture,
499
+ texCoordSets,
462
500
  );
463
501
  }
464
502
 
@@ -520,6 +558,7 @@ function processSpecularUniforms(
520
558
  shaderBuilder,
521
559
  defaultTexture,
522
560
  disableTextures,
561
+ texCoordSets,
523
562
  ) {
524
563
  const {
525
564
  specularTexture,
@@ -542,6 +581,7 @@ function processSpecularUniforms(
542
581
  "u_specularTexture",
543
582
  "SPECULAR",
544
583
  defaultTexture,
584
+ texCoordSets,
545
585
  );
546
586
  }
547
587
 
@@ -572,6 +612,7 @@ function processSpecularUniforms(
572
612
  "u_specularColorTexture",
573
613
  "SPECULAR_COLOR",
574
614
  defaultTexture,
615
+ texCoordSets,
575
616
  );
576
617
  }
577
618
 
@@ -616,6 +657,7 @@ function processAnisotropyUniforms(
616
657
  shaderBuilder,
617
658
  defaultTexture,
618
659
  disableTextures,
660
+ texCoordSets,
619
661
  ) {
620
662
  const { anisotropyStrength, anisotropyRotation, anisotropyTexture } =
621
663
  anisotropy;
@@ -634,6 +676,7 @@ function processAnisotropyUniforms(
634
676
  "u_anisotropyTexture",
635
677
  "ANISOTROPY",
636
678
  defaultTexture,
679
+ texCoordSets,
637
680
  );
638
681
  }
639
682
 
@@ -668,6 +711,7 @@ function processClearcoatUniforms(
668
711
  shaderBuilder,
669
712
  defaultTexture,
670
713
  disableTextures,
714
+ texCoordSets,
671
715
  ) {
672
716
  const {
673
717
  clearcoatFactor,
@@ -710,6 +754,7 @@ function processClearcoatUniforms(
710
754
  "u_clearcoatTexture",
711
755
  "CLEARCOAT",
712
756
  defaultTexture,
757
+ texCoordSets,
713
758
  );
714
759
  }
715
760
 
@@ -740,6 +785,7 @@ function processClearcoatUniforms(
740
785
  "u_clearcoatRoughnessTexture",
741
786
  "CLEARCOAT_ROUGHNESS",
742
787
  defaultTexture,
788
+ texCoordSets,
743
789
  );
744
790
  }
745
791
 
@@ -751,6 +797,7 @@ function processClearcoatUniforms(
751
797
  "u_clearcoatNormalTexture",
752
798
  "CLEARCOAT_NORMAL",
753
799
  defaultTexture,
800
+ texCoordSets,
754
801
  );
755
802
  }
756
803
  }
@@ -771,6 +818,7 @@ function processMetallicRoughnessUniforms(
771
818
  shaderBuilder,
772
819
  defaultTexture,
773
820
  disableTextures,
821
+ texCoordSets,
774
822
  ) {
775
823
  shaderBuilder.addDefine(
776
824
  "USE_METALLIC_ROUGHNESS",
@@ -787,6 +835,7 @@ function processMetallicRoughnessUniforms(
787
835
  "u_baseColorTexture",
788
836
  "BASE_COLOR",
789
837
  defaultTexture,
838
+ texCoordSets,
790
839
  );
791
840
  }
792
841
 
@@ -822,6 +871,7 @@ function processMetallicRoughnessUniforms(
822
871
  "u_metallicRoughnessTexture",
823
872
  "METALLIC_ROUGHNESS",
824
873
  defaultTexture,
874
+ texCoordSets,
825
875
  );
826
876
  }
827
877
 
package/index.js CHANGED
@@ -494,7 +494,6 @@ export { default as _shadersVector3DTilePolylinesVS } from './Source/Shaders/Vec
494
494
  export { default as _shadersVectorTileVS } from './Source/Shaders/VectorTileVS.js';
495
495
  export { default as _shadersViewportQuadFS } from './Source/Shaders/ViewportQuadFS.js';
496
496
  export { default as _shadersViewportQuadVS } from './Source/Shaders/ViewportQuadVS.js';
497
- export { default as CesiumWidget } from './Source/Widget/CesiumWidget.js';
498
497
  export { default as AlphaMode } from './Source/Scene/AlphaMode.js';
499
498
  export { default as Appearance } from './Source/Scene/Appearance.js';
500
499
  export { default as ArcGisBaseMapType } from './Source/Scene/ArcGisBaseMapType.js';
@@ -851,6 +850,7 @@ export { default as VoxelShapeType } from './Source/Scene/VoxelShapeType.js';
851
850
  export { default as VoxelTraversal } from './Source/Scene/VoxelTraversal.js';
852
851
  export { default as WebMapServiceImageryProvider } from './Source/Scene/WebMapServiceImageryProvider.js';
853
852
  export { default as WebMapTileServiceImageryProvider } from './Source/Scene/WebMapTileServiceImageryProvider.js';
853
+ export { default as CesiumWidget } from './Source/Widget/CesiumWidget.js';
854
854
  export { default as _shadersAllMaterialAppearanceFS } from './Source/Shaders/Appearances/AllMaterialAppearanceFS.js';
855
855
  export { default as _shadersAllMaterialAppearanceVS } from './Source/Shaders/Appearances/AllMaterialAppearanceVS.js';
856
856
  export { default as _shadersBasicMaterialAppearanceFS } from './Source/Shaders/Appearances/BasicMaterialAppearanceFS.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rtzh/engine",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "CesiumJS is a JavaScript library for creating 3D globes and 2D maps in a web browser without a plugin.",
5
5
  "keywords": [
6
6
  "3D",