bplinejs 0.0.101-beta.10
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 +215 -0
- package/docs/API.md +471 -0
- package/lib/Camera/index.d.ts +88 -0
- package/lib/Camera/index.js +178 -0
- package/lib/Camera/index.js.map +1 -0
- package/lib/Color/index.d.ts +99 -0
- package/lib/Color/index.js +178 -0
- package/lib/Color/index.js.map +1 -0
- package/lib/Geometry/Geo.d.ts +131 -0
- package/lib/Geometry/Geo.js +180 -0
- package/lib/Geometry/Geo.js.map +1 -0
- package/lib/Geometry/Poly2D.d.ts +53 -0
- package/lib/Geometry/Poly2D.js +133 -0
- package/lib/Geometry/Poly2D.js.map +1 -0
- package/lib/Geometry/Rect2d.d.ts +89 -0
- package/lib/Geometry/Rect2d.js +128 -0
- package/lib/Geometry/Rect2d.js.map +1 -0
- package/lib/Geometry/index.d.ts +6 -0
- package/lib/Geometry/index.js +4 -0
- package/lib/Group/index.d.ts +70 -0
- package/lib/Group/index.js +110 -0
- package/lib/Group/index.js.map +1 -0
- package/lib/ID.d.ts +6 -0
- package/lib/ID.js +15 -0
- package/lib/ID.js.map +1 -0
- package/lib/IMesh/index.d.ts +104 -0
- package/lib/IMesh/index.js +333 -0
- package/lib/IMesh/index.js.map +1 -0
- package/lib/Material/Material.d.ts +158 -0
- package/lib/Material/Material.js +229 -0
- package/lib/Material/Material.js.map +1 -0
- package/lib/Material/baseMaterial.d.ts +15 -0
- package/lib/Material/baseMaterial.js +24 -0
- package/lib/Material/baseMaterial.js.map +1 -0
- package/lib/Material/index.d.ts +4 -0
- package/lib/Material/index.js +3 -0
- package/lib/Material/shaders/base/poly/fragment.js +6 -0
- package/lib/Material/shaders/base/poly/fragment.js.map +1 -0
- package/lib/Material/shaders/base/poly/vertex.js +6 -0
- package/lib/Material/shaders/base/poly/vertex.js.map +1 -0
- package/lib/Material/shaders/base/rect/fragment.js +6 -0
- package/lib/Material/shaders/base/rect/fragment.js.map +1 -0
- package/lib/Material/shaders/base/rect/vertex.js +6 -0
- package/lib/Material/shaders/base/rect/vertex.js.map +1 -0
- package/lib/Material/shaders/line/fragment.js +6 -0
- package/lib/Material/shaders/line/fragment.js.map +1 -0
- package/lib/Material/shaders/line/vertex.js +6 -0
- package/lib/Material/shaders/line/vertex.js.map +1 -0
- package/lib/Mesh/index.d.ts +154 -0
- package/lib/Mesh/index.js +254 -0
- package/lib/Mesh/index.js.map +1 -0
- package/lib/Object/index.d.ts +95 -0
- package/lib/Object/index.js +212 -0
- package/lib/Object/index.js.map +1 -0
- package/lib/Raws/index.d.ts +87 -0
- package/lib/Raws/index.js +164 -0
- package/lib/Raws/index.js.map +1 -0
- package/lib/Render/BufferManager.d.ts +93 -0
- package/lib/Render/BufferManager.js +281 -0
- package/lib/Render/BufferManager.js.map +1 -0
- package/lib/Render/DepthManager.d.ts +22 -0
- package/lib/Render/DepthManager.js +95 -0
- package/lib/Render/DepthManager.js.map +1 -0
- package/lib/Render/DestroyManager.d.ts +74 -0
- package/lib/Render/DestroyManager.js +221 -0
- package/lib/Render/DestroyManager.js.map +1 -0
- package/lib/Render/DevelopmentValidator.d.ts +73 -0
- package/lib/Render/DevelopmentValidator.js +188 -0
- package/lib/Render/DevelopmentValidator.js.map +1 -0
- package/lib/Render/DrawCallManager.d.ts +58 -0
- package/lib/Render/DrawCallManager.js +267 -0
- package/lib/Render/DrawCallManager.js.map +1 -0
- package/lib/Render/PipelineManager.d.ts +46 -0
- package/lib/Render/PipelineManager.js +254 -0
- package/lib/Render/PipelineManager.js.map +1 -0
- package/lib/Render/SamplerManager.d.ts +26 -0
- package/lib/Render/SamplerManager.js +42 -0
- package/lib/Render/SamplerManager.js.map +1 -0
- package/lib/Render/SceneUpdate.d.ts +9 -0
- package/lib/Render/SceneUpdate.js +18 -0
- package/lib/Render/SceneUpdate.js.map +1 -0
- package/lib/Render/TextureManager.d.ts +33 -0
- package/lib/Render/TextureManager.js +152 -0
- package/lib/Render/TextureManager.js.map +1 -0
- package/lib/Render/index.d.ts +212 -0
- package/lib/Render/index.js +347 -0
- package/lib/Render/index.js.map +1 -0
- package/lib/Render/types.d.ts +191 -0
- package/lib/Scene/index.d.ts +124 -0
- package/lib/Scene/index.js +225 -0
- package/lib/Scene/index.js.map +1 -0
- package/lib/Style/EdgeStyle.d.ts +28 -0
- package/lib/Style/EdgeStyle.js +67 -0
- package/lib/Style/EdgeStyle.js.map +1 -0
- package/lib/Style/JoinStyle.d.ts +27 -0
- package/lib/Style/JoinStyle.js +53 -0
- package/lib/Style/JoinStyle.js.map +1 -0
- package/lib/Style/PartStyle.d.ts +50 -0
- package/lib/Style/PartStyle.js +92 -0
- package/lib/Style/PartStyle.js.map +1 -0
- package/lib/Style/PointsStyle.d.ts +43 -0
- package/lib/Style/PointsStyle.js +98 -0
- package/lib/Style/PointsStyle.js.map +1 -0
- package/lib/Style/SolidStyle.d.ts +37 -0
- package/lib/Style/SolidStyle.js +83 -0
- package/lib/Style/SolidStyle.js.map +1 -0
- package/lib/Style/TexturedStyle.d.ts +29 -0
- package/lib/Style/TexturedStyle.js +66 -0
- package/lib/Style/TexturedStyle.js.map +1 -0
- package/lib/Style/WireframeStyle.d.ts +7 -0
- package/lib/Style/WireframeStyle.js +13 -0
- package/lib/Style/WireframeStyle.js.map +1 -0
- package/lib/Style/WriteStyleData.d.ts +10 -0
- package/lib/Style/WriteStyleData.js +59 -0
- package/lib/Style/WriteStyleData.js.map +1 -0
- package/lib/Style/index.d.ts +50 -0
- package/lib/Style/index.js +92 -0
- package/lib/Style/index.js.map +1 -0
- package/lib/Style/types.d.ts +21 -0
- package/lib/Texture/Layers.d.ts +26 -0
- package/lib/Texture/Layers.js +42 -0
- package/lib/Texture/Layers.js.map +1 -0
- package/lib/Texture/index.d.ts +116 -0
- package/lib/Texture/index.js +198 -0
- package/lib/Texture/index.js.map +1 -0
- package/lib/global-types.d.ts +8 -0
- package/lib/index.d.ts +43 -0
- package/lib/index.js +34 -0
- package/package.json +130 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { AddObject, Geometry2d, Material2d } from "../global-types";
|
|
2
|
+
import Group from "../Group";
|
|
3
|
+
import type { GroupLike } from "../Group";
|
|
4
|
+
import type { MeshLike } from "../Mesh";
|
|
5
|
+
import type { TextureResource } from "../Texture/Layers";
|
|
6
|
+
type DrawList = MeshLike;
|
|
7
|
+
type GeometryList = Geometry2d;
|
|
8
|
+
type MaterialList = Material2d;
|
|
9
|
+
type TextureList = TextureResource;
|
|
10
|
+
interface SceneLike extends GroupLike {
|
|
11
|
+
drawList: DrawList[];
|
|
12
|
+
geometryList: GeometryList[];
|
|
13
|
+
materialList: MaterialList[];
|
|
14
|
+
textureList: TextureList[];
|
|
15
|
+
ensureLists(): DrawList[];
|
|
16
|
+
addToLists(child: AddObject): void;
|
|
17
|
+
removeFromLists(child: AddObject): void;
|
|
18
|
+
updateLists(): DrawList[];
|
|
19
|
+
updateResourceLists(): void;
|
|
20
|
+
updateDrawList(): DrawList[];
|
|
21
|
+
updateTextureList(): TextureList[];
|
|
22
|
+
getMaterialGeometryTypes(materialId: number): ReadonlySet<string>;
|
|
23
|
+
updateDrawOrder(): void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 场景对象
|
|
27
|
+
* 作为场景树的根级容器使用
|
|
28
|
+
* @class
|
|
29
|
+
*/
|
|
30
|
+
declare class Scene extends Group implements SceneLike {
|
|
31
|
+
/**
|
|
32
|
+
* 对象类型
|
|
33
|
+
*/
|
|
34
|
+
readonly type: string;
|
|
35
|
+
/** CPU 四个列表与贴图列表分别处理到的版本快照,不是额外版本源。 */
|
|
36
|
+
private _listsSnapshot;
|
|
37
|
+
private _textureSnapshot;
|
|
38
|
+
/**
|
|
39
|
+
* 当前 Scene 中材质实际搭配的几何类型,不使用材质历史类型创建闲置模板。
|
|
40
|
+
*/
|
|
41
|
+
private readonly _materialGeometryTypes;
|
|
42
|
+
/**
|
|
43
|
+
* 当前绘制列表
|
|
44
|
+
*/
|
|
45
|
+
drawList: DrawList[];
|
|
46
|
+
/**
|
|
47
|
+
* 当前场景使用的去重 Geometry 列表。
|
|
48
|
+
* 多个 Mesh 共用同一 Geometry 时只保留一个对象引用。
|
|
49
|
+
*/
|
|
50
|
+
geometryList: GeometryList[];
|
|
51
|
+
/**
|
|
52
|
+
* 当前场景使用的去重 Material 列表。
|
|
53
|
+
* Material 对象同时提供 id 和 key,分别用于资源销毁与 Pipeline 复用。
|
|
54
|
+
*/
|
|
55
|
+
materialList: MaterialList[];
|
|
56
|
+
/**
|
|
57
|
+
* 当前场景使用的去重 Texture 列表。
|
|
58
|
+
*/
|
|
59
|
+
textureList: TextureList[];
|
|
60
|
+
/**
|
|
61
|
+
* 创建场景对象
|
|
62
|
+
*/
|
|
63
|
+
constructor();
|
|
64
|
+
/** 版本变化后统一重建四个列表;一个 Render 处理后不影响其他 Render 的缓存快照。 */
|
|
65
|
+
ensureLists(): DrawList[];
|
|
66
|
+
/**
|
|
67
|
+
* 将新加入场景的节点及其后代增量写入四个列表。
|
|
68
|
+
* 该方法只负责补充引用;删除节点时由 removeFromLists 处理共享资源校准。
|
|
69
|
+
* @param child 新加入场景树的节点
|
|
70
|
+
* @returns 无返回值
|
|
71
|
+
*/
|
|
72
|
+
addToLists(child: AddObject): void;
|
|
73
|
+
/**
|
|
74
|
+
* 从 drawList 中移除节点及其后代包含的 Mesh。
|
|
75
|
+
* 资源可能仍被其他 Mesh 共用,因此只标记下一帧重建另外三个资源列表。
|
|
76
|
+
* @param child 从场景树删除的节点
|
|
77
|
+
* @returns 无返回值
|
|
78
|
+
*/
|
|
79
|
+
removeFromLists(child: AddObject): void;
|
|
80
|
+
/**
|
|
81
|
+
* 一次递归更新场景的 Mesh、Geometry、Material 和 Texture 四个列表。
|
|
82
|
+
* Geometry、Material 与 Texture 按全局 ID 去重,供 Render 创建和回收缓存。
|
|
83
|
+
* @returns 更新后的绘制列表
|
|
84
|
+
*/
|
|
85
|
+
updateLists(): DrawList[];
|
|
86
|
+
/**
|
|
87
|
+
* 根据当前 drawList 重建 Geometry、Material 和 Texture 三个资源列表。
|
|
88
|
+
* 资源按全局 ID 去重,避免删除共享资源时误伤仍在场景中的 Mesh。
|
|
89
|
+
* @returns 无返回值
|
|
90
|
+
*/
|
|
91
|
+
updateResourceLists(): void;
|
|
92
|
+
/**
|
|
93
|
+
* 更新绘制列表及其关联资源列表。
|
|
94
|
+
* 保留原方法名,现有调用会同步更新全部四个列表。
|
|
95
|
+
* @returns 更新后的绘制列表
|
|
96
|
+
*/
|
|
97
|
+
updateDrawList(): DrawList[];
|
|
98
|
+
/**
|
|
99
|
+
* 根据材质列表单独刷新 Texture 列表。
|
|
100
|
+
* 适用于只替换 Style 中 solid、edge、points.texture 的普通渲染帧。
|
|
101
|
+
* @returns 更新后的贴图列表
|
|
102
|
+
*/
|
|
103
|
+
updateTextureList(): TextureList[];
|
|
104
|
+
/**
|
|
105
|
+
* 获取当前场景中一个材质实际使用的几何类型,供 materialList 创建管线。
|
|
106
|
+
* @param materialId 材质 ID
|
|
107
|
+
* @returns 几何类型只读集合;不要修改返回的内部集合
|
|
108
|
+
*/
|
|
109
|
+
getMaterialGeometryTypes(materialId: number): ReadonlySet<string>;
|
|
110
|
+
/**
|
|
111
|
+
* 记录一个实际 Mesh 的材质与几何类型组合。
|
|
112
|
+
* @param materialId 材质 ID
|
|
113
|
+
* @param geometryType 几何类型
|
|
114
|
+
*/
|
|
115
|
+
private addMaterialGeometryType;
|
|
116
|
+
/**
|
|
117
|
+
* 更新场景绘制顺序。
|
|
118
|
+
* 仅按照 Mesh 的 order 从小到大重新排列 drawList,不重建其他资源列表。
|
|
119
|
+
* @returns 无返回值
|
|
120
|
+
*/
|
|
121
|
+
updateDrawOrder(): void;
|
|
122
|
+
}
|
|
123
|
+
export default Scene;
|
|
124
|
+
export type { DrawList, GeometryList, MaterialList, SceneLike, TextureList };
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import Group from "../Group/index.js";
|
|
2
|
+
import Mesh from "../Mesh/index.js";
|
|
3
|
+
//#region src/scripts/Scene/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* 场景对象
|
|
6
|
+
* 作为场景树的根级容器使用
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
var Scene = class extends Group {
|
|
10
|
+
/**
|
|
11
|
+
* 对象类型
|
|
12
|
+
*/
|
|
13
|
+
type = "Scene";
|
|
14
|
+
/** CPU 四个列表与贴图列表分别处理到的版本快照,不是额外版本源。 */
|
|
15
|
+
_listsSnapshot = -1;
|
|
16
|
+
_textureSnapshot = -1;
|
|
17
|
+
/**
|
|
18
|
+
* 当前 Scene 中材质实际搭配的几何类型,不使用材质历史类型创建闲置模板。
|
|
19
|
+
*/
|
|
20
|
+
_materialGeometryTypes = /* @__PURE__ */ new Map();
|
|
21
|
+
/**
|
|
22
|
+
* 当前绘制列表
|
|
23
|
+
*/
|
|
24
|
+
drawList = [];
|
|
25
|
+
/**
|
|
26
|
+
* 当前场景使用的去重 Geometry 列表。
|
|
27
|
+
* 多个 Mesh 共用同一 Geometry 时只保留一个对象引用。
|
|
28
|
+
*/
|
|
29
|
+
geometryList = [];
|
|
30
|
+
/**
|
|
31
|
+
* 当前场景使用的去重 Material 列表。
|
|
32
|
+
* Material 对象同时提供 id 和 key,分别用于资源销毁与 Pipeline 复用。
|
|
33
|
+
*/
|
|
34
|
+
materialList = [];
|
|
35
|
+
/**
|
|
36
|
+
* 当前场景使用的去重 Texture 列表。
|
|
37
|
+
*/
|
|
38
|
+
textureList = [];
|
|
39
|
+
/**
|
|
40
|
+
* 创建场景对象
|
|
41
|
+
*/
|
|
42
|
+
constructor() {
|
|
43
|
+
super(0, 0);
|
|
44
|
+
}
|
|
45
|
+
/** 版本变化后统一重建四个列表;一个 Render 处理后不影响其他 Render 的缓存快照。 */
|
|
46
|
+
ensureLists() {
|
|
47
|
+
if (this._listsSnapshot !== this.version) this.updateLists();
|
|
48
|
+
return this.drawList;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 将新加入场景的节点及其后代增量写入四个列表。
|
|
52
|
+
* 该方法只负责补充引用;删除节点时由 removeFromLists 处理共享资源校准。
|
|
53
|
+
* @param child 新加入场景树的节点
|
|
54
|
+
* @returns 无返回值
|
|
55
|
+
*/
|
|
56
|
+
addToLists(child) {
|
|
57
|
+
const collect = (node) => {
|
|
58
|
+
if (node instanceof Mesh && node.data !== void 0 && node.material !== void 0) {
|
|
59
|
+
if (!this.drawList.some((mesh) => mesh.id === node.id)) this.drawList.push(node);
|
|
60
|
+
if (!this.geometryList.some((geometry) => geometry.id === node.data?.id)) this.geometryList.push(node.data);
|
|
61
|
+
if (!this.materialList.some((material) => material.id === node.material?.id)) this.materialList.push(node.material);
|
|
62
|
+
this.addMaterialGeometryType(node.material.id, node.data.type);
|
|
63
|
+
for (const texture of GetMeshTextures(node)) if (!this.textureList.some((item) => item.id === texture.id)) this.textureList.push(texture);
|
|
64
|
+
}
|
|
65
|
+
if (node instanceof Group) for (const nextChild of node.children) collect(nextChild);
|
|
66
|
+
};
|
|
67
|
+
collect(child);
|
|
68
|
+
this.updateDrawOrder();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 从 drawList 中移除节点及其后代包含的 Mesh。
|
|
72
|
+
* 资源可能仍被其他 Mesh 共用,因此只标记下一帧重建另外三个资源列表。
|
|
73
|
+
* @param child 从场景树删除的节点
|
|
74
|
+
* @returns 无返回值
|
|
75
|
+
*/
|
|
76
|
+
removeFromLists(child) {
|
|
77
|
+
const removedMeshIds = /* @__PURE__ */ new Set();
|
|
78
|
+
const collect = (node) => {
|
|
79
|
+
if (node instanceof Mesh) removedMeshIds.add(node.id);
|
|
80
|
+
if (node instanceof Group) for (const nextChild of node.children) collect(nextChild);
|
|
81
|
+
};
|
|
82
|
+
collect(child);
|
|
83
|
+
if (removedMeshIds.size === 0) return;
|
|
84
|
+
this.drawList = this.drawList.filter((mesh) => {
|
|
85
|
+
return !removedMeshIds.has(mesh.id);
|
|
86
|
+
});
|
|
87
|
+
this.updateVersion();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 一次递归更新场景的 Mesh、Geometry、Material 和 Texture 四个列表。
|
|
91
|
+
* Geometry、Material 与 Texture 按全局 ID 去重,供 Render 创建和回收缓存。
|
|
92
|
+
* @returns 更新后的绘制列表
|
|
93
|
+
*/
|
|
94
|
+
updateLists() {
|
|
95
|
+
this.updateVersion();
|
|
96
|
+
const drawList = [];
|
|
97
|
+
const collect = (child) => {
|
|
98
|
+
if (child instanceof Mesh && child.data !== void 0 && child.material !== void 0) drawList.push(child);
|
|
99
|
+
if (child instanceof Group) for (const nextChild of child.children) collect(nextChild);
|
|
100
|
+
};
|
|
101
|
+
for (const child of this.children) collect(child);
|
|
102
|
+
this.drawList = drawList;
|
|
103
|
+
this.updateResourceLists();
|
|
104
|
+
this.updateDrawOrder();
|
|
105
|
+
this._listsSnapshot = this.version;
|
|
106
|
+
return this.drawList;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 根据当前 drawList 重建 Geometry、Material 和 Texture 三个资源列表。
|
|
110
|
+
* 资源按全局 ID 去重,避免删除共享资源时误伤仍在场景中的 Mesh。
|
|
111
|
+
* @returns 无返回值
|
|
112
|
+
*/
|
|
113
|
+
updateResourceLists() {
|
|
114
|
+
this._materialGeometryTypes.clear();
|
|
115
|
+
const geometryList = [];
|
|
116
|
+
const materialList = [];
|
|
117
|
+
const textureList = [];
|
|
118
|
+
const geometryIds = /* @__PURE__ */ new Set();
|
|
119
|
+
const materialIds = /* @__PURE__ */ new Set();
|
|
120
|
+
const textureIds = /* @__PURE__ */ new Set();
|
|
121
|
+
for (const mesh of this.drawList) {
|
|
122
|
+
const geometry = mesh.data;
|
|
123
|
+
const material = mesh.material;
|
|
124
|
+
if (geometry !== void 0 && !geometryIds.has(geometry.id)) {
|
|
125
|
+
geometryIds.add(geometry.id);
|
|
126
|
+
geometryList.push(geometry);
|
|
127
|
+
}
|
|
128
|
+
if (material === void 0) continue;
|
|
129
|
+
if (!materialIds.has(material.id)) {
|
|
130
|
+
materialIds.add(material.id);
|
|
131
|
+
materialList.push(material);
|
|
132
|
+
}
|
|
133
|
+
for (const texture of GetMeshTextures(mesh)) if (!textureIds.has(texture.id)) {
|
|
134
|
+
textureIds.add(texture.id);
|
|
135
|
+
textureList.push(texture);
|
|
136
|
+
}
|
|
137
|
+
if (geometry !== void 0) this.addMaterialGeometryType(material.id, geometry.type);
|
|
138
|
+
}
|
|
139
|
+
this.geometryList = geometryList;
|
|
140
|
+
this.materialList = materialList;
|
|
141
|
+
this.textureList = textureList;
|
|
142
|
+
this._textureSnapshot = this.version;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* 更新绘制列表及其关联资源列表。
|
|
146
|
+
* 保留原方法名,现有调用会同步更新全部四个列表。
|
|
147
|
+
* @returns 更新后的绘制列表
|
|
148
|
+
*/
|
|
149
|
+
updateDrawList() {
|
|
150
|
+
return this.updateLists();
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 根据材质列表单独刷新 Texture 列表。
|
|
154
|
+
* 适用于只替换 Style 中 solid、edge、points.texture 的普通渲染帧。
|
|
155
|
+
* @returns 更新后的贴图列表
|
|
156
|
+
*/
|
|
157
|
+
updateTextureList() {
|
|
158
|
+
if (this._textureSnapshot === this.version) return this.textureList;
|
|
159
|
+
const previousTextureList = this.textureList;
|
|
160
|
+
const textureList = [];
|
|
161
|
+
const textureIds = /* @__PURE__ */ new Set();
|
|
162
|
+
for (const mesh of this.drawList) for (const texture of GetMeshTextures(mesh)) if (!textureIds.has(texture.id)) {
|
|
163
|
+
textureIds.add(texture.id);
|
|
164
|
+
textureList.push(texture);
|
|
165
|
+
}
|
|
166
|
+
this.textureList = textureList;
|
|
167
|
+
if (!HaveSameTextureIds(previousTextureList, textureList)) this.updateVersion();
|
|
168
|
+
this._textureSnapshot = this.version;
|
|
169
|
+
return this.textureList;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* 获取当前场景中一个材质实际使用的几何类型,供 materialList 创建管线。
|
|
173
|
+
* @param materialId 材质 ID
|
|
174
|
+
* @returns 几何类型只读集合;不要修改返回的内部集合
|
|
175
|
+
*/
|
|
176
|
+
getMaterialGeometryTypes(materialId) {
|
|
177
|
+
return this._materialGeometryTypes.get(materialId) ?? /* @__PURE__ */ new Set();
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* 记录一个实际 Mesh 的材质与几何类型组合。
|
|
181
|
+
* @param materialId 材质 ID
|
|
182
|
+
* @param geometryType 几何类型
|
|
183
|
+
*/
|
|
184
|
+
addMaterialGeometryType(materialId, geometryType) {
|
|
185
|
+
let types = this._materialGeometryTypes.get(materialId);
|
|
186
|
+
if (types === void 0) {
|
|
187
|
+
types = /* @__PURE__ */ new Set();
|
|
188
|
+
this._materialGeometryTypes.set(materialId, types);
|
|
189
|
+
}
|
|
190
|
+
types.add(geometryType);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* 更新场景绘制顺序。
|
|
194
|
+
* 仅按照 Mesh 的 order 从小到大重新排列 drawList,不重建其他资源列表。
|
|
195
|
+
* @returns 无返回值
|
|
196
|
+
*/
|
|
197
|
+
updateDrawOrder() {
|
|
198
|
+
this.drawList.sort((left, right) => {
|
|
199
|
+
return left.order - right.order;
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* 获取网格使用的单层图片或实例层表;列表由调用者按 ID 去重。
|
|
205
|
+
* @param mesh 普通或实例网格
|
|
206
|
+
* @returns 材质引用的贴图列表
|
|
207
|
+
*/
|
|
208
|
+
var GetMeshTextures = (mesh) => {
|
|
209
|
+
return mesh.textures.filter((texture) => texture !== void 0);
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* 比较两个贴图列表是否包含相同 ID。
|
|
213
|
+
* @param left 左侧贴图列表
|
|
214
|
+
* @param right 右侧贴图列表
|
|
215
|
+
* @returns 是否包含相同贴图 ID
|
|
216
|
+
*/
|
|
217
|
+
var HaveSameTextureIds = (left, right) => {
|
|
218
|
+
if (left.length !== right.length) return false;
|
|
219
|
+
const rightIds = new Set(right.map((texture) => texture.id));
|
|
220
|
+
return left.every((texture) => rightIds.has(texture.id));
|
|
221
|
+
};
|
|
222
|
+
//#endregion
|
|
223
|
+
export { Scene as default };
|
|
224
|
+
|
|
225
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/scripts/Scene/index.ts"],"sourcesContent":["import type { AddObject, Geometry2d, Material2d } from \"../global-types\";\nimport Group from \"../Group\";\nimport type { GroupLike } from \"../Group\";\nimport Mesh from \"../Mesh\";\nimport type { MeshLike } from \"../Mesh\";\nimport type { TextureResource } from \"../Texture/Layers\";\n\ntype DrawList = MeshLike;\ntype GeometryList = Geometry2d;\ntype MaterialList = Material2d;\ntype TextureList = TextureResource;\n\ninterface SceneLike extends GroupLike {\n drawList: DrawList[];\n geometryList: GeometryList[];\n materialList: MaterialList[];\n textureList: TextureList[];\n ensureLists(): DrawList[];\n addToLists(child: AddObject): void;\n removeFromLists(child: AddObject): void;\n updateLists(): DrawList[];\n updateResourceLists(): void;\n updateDrawList(): DrawList[];\n updateTextureList(): TextureList[];\n getMaterialGeometryTypes(materialId: number): ReadonlySet<string>;\n updateDrawOrder(): void;\n}\n\n/**\n * 场景对象\n * 作为场景树的根级容器使用\n * @class\n */\nclass Scene extends Group implements SceneLike {\n /**\n * 对象类型\n */\n public readonly type: string = \"Scene\";\n\n /** CPU 四个列表与贴图列表分别处理到的版本快照,不是额外版本源。 */\n private _listsSnapshot: number = -1;\n private _textureSnapshot: number = -1;\n\n /**\n * 当前 Scene 中材质实际搭配的几何类型,不使用材质历史类型创建闲置模板。\n */\n private readonly _materialGeometryTypes = new Map<number, Set<string>>();\n\n\n /**\n * 当前绘制列表\n */\n drawList: DrawList[] = [];\n\n /**\n * 当前场景使用的去重 Geometry 列表。\n * 多个 Mesh 共用同一 Geometry 时只保留一个对象引用。\n */\n geometryList: GeometryList[] = [];\n\n /**\n * 当前场景使用的去重 Material 列表。\n * Material 对象同时提供 id 和 key,分别用于资源销毁与 Pipeline 复用。\n */\n materialList: MaterialList[] = [];\n\n /**\n * 当前场景使用的去重 Texture 列表。\n */\n textureList: TextureList[] = [];\n\n /**\n * 创建场景对象\n */\n public constructor() {\n super(0, 0);\n }\n\n /** 版本变化后统一重建四个列表;一个 Render 处理后不影响其他 Render 的缓存快照。 */\n public ensureLists(): DrawList[] {\n if (this._listsSnapshot !== this.version) this.updateLists();\n return this.drawList;\n }\n\n /**\n * 将新加入场景的节点及其后代增量写入四个列表。\n * 该方法只负责补充引用;删除节点时由 removeFromLists 处理共享资源校准。\n * @param child 新加入场景树的节点\n * @returns 无返回值\n */\n public addToLists(child: AddObject): void {\n const collect = (node: AddObject): void => {\n if (node instanceof Mesh && node.data !== undefined && node.material !== undefined) {\n if (!this.drawList.some((mesh: DrawList): boolean => mesh.id === node.id)) {\n this.drawList.push(node);\n }\n\n if (!this.geometryList.some((geometry: GeometryList): boolean => geometry.id === node.data?.id)) {\n this.geometryList.push(node.data);\n }\n\n if (!this.materialList.some((material: MaterialList): boolean => material.id === node.material?.id)) {\n this.materialList.push(node.material);\n }\n this.addMaterialGeometryType(node.material.id, node.data.type);\n\n for (const texture of GetMeshTextures(node)) {\n if (!this.textureList.some((item: TextureList): boolean => item.id === texture.id)) {\n this.textureList.push(texture);\n }\n }\n }\n\n if (node instanceof Group) {\n for (const nextChild of node.children) {\n collect(nextChild);\n }\n }\n };\n\n collect(child);\n this.updateDrawOrder();\n }\n\n /**\n * 从 drawList 中移除节点及其后代包含的 Mesh。\n * 资源可能仍被其他 Mesh 共用,因此只标记下一帧重建另外三个资源列表。\n * @param child 从场景树删除的节点\n * @returns 无返回值\n */\n public removeFromLists(child: AddObject): void {\n const removedMeshIds: Set<number> = new Set<number>();\n const collect = (node: AddObject): void => {\n if (node instanceof Mesh) {\n removedMeshIds.add(node.id);\n }\n\n if (node instanceof Group) {\n for (const nextChild of node.children) {\n collect(nextChild);\n }\n }\n };\n\n collect(child);\n\n if (removedMeshIds.size === 0) {\n return;\n }\n\n this.drawList = this.drawList.filter((mesh: DrawList): boolean => {\n return !removedMeshIds.has(mesh.id);\n });\n this.updateVersion();\n }\n\n /**\n * 一次递归更新场景的 Mesh、Geometry、Material 和 Texture 四个列表。\n * Geometry、Material 与 Texture 按全局 ID 去重,供 Render 创建和回收缓存。\n * @returns 更新后的绘制列表\n */\n public updateLists(): DrawList[] {\n this.updateVersion();\n const drawList: DrawList[] = [];\n const collect = (child: AddObject): void => {\n if (child instanceof Mesh && child.data !== undefined && child.material !== undefined) {\n drawList.push(child);\n }\n\n if (child instanceof Group) {\n for (const nextChild of child.children) {\n collect(nextChild);\n }\n }\n };\n\n for (const child of this.children) {\n collect(child);\n }\n this.drawList = drawList;\n this.updateResourceLists();\n this.updateDrawOrder();\n this._listsSnapshot = this.version;\n return this.drawList;\n }\n\n /**\n * 根据当前 drawList 重建 Geometry、Material 和 Texture 三个资源列表。\n * 资源按全局 ID 去重,避免删除共享资源时误伤仍在场景中的 Mesh。\n * @returns 无返回值\n */\n public updateResourceLists(): void {\n this._materialGeometryTypes.clear();\n const geometryList: GeometryList[] = [];\n const materialList: MaterialList[] = [];\n const textureList: TextureList[] = [];\n const geometryIds: Set<number> = new Set<number>();\n const materialIds: Set<number> = new Set<number>();\n const textureIds: Set<number> = new Set<number>();\n\n for (const mesh of this.drawList) {\n const geometry: GeometryList | undefined = mesh.data;\n const material: MaterialList | undefined = mesh.material;\n\n if (geometry !== undefined && !geometryIds.has(geometry.id)) {\n geometryIds.add(geometry.id);\n geometryList.push(geometry);\n }\n\n if (material === undefined) {\n continue;\n }\n\n if (!materialIds.has(material.id)) {\n materialIds.add(material.id);\n materialList.push(material);\n }\n\n for (const texture of GetMeshTextures(mesh)) {\n if (!textureIds.has(texture.id)) {\n textureIds.add(texture.id);\n textureList.push(texture);\n }\n }\n\n if (geometry !== undefined) this.addMaterialGeometryType(material.id, geometry.type);\n }\n\n this.geometryList = geometryList;\n this.materialList = materialList;\n this.textureList = textureList;\n this._textureSnapshot = this.version;\n }\n\n /**\n * 更新绘制列表及其关联资源列表。\n * 保留原方法名,现有调用会同步更新全部四个列表。\n * @returns 更新后的绘制列表\n */\n public updateDrawList(): DrawList[] {\n return this.updateLists();\n }\n\n /**\n * 根据材质列表单独刷新 Texture 列表。\n * 适用于只替换 Style 中 solid、edge、points.texture 的普通渲染帧。\n * @returns 更新后的贴图列表\n */\n public updateTextureList(): TextureList[] {\n // Material -> Mesh 通知增加 Scene 版本,静止帧不扫描材质版本。\n if (this._textureSnapshot === this.version) return this.textureList;\n\n const previousTextureList: TextureList[] = this.textureList;\n const textureList: TextureList[] = [];\n const textureIds: Set<number> = new Set<number>();\n\n for (const mesh of this.drawList) {\n for (const texture of GetMeshTextures(mesh)) {\n if (!textureIds.has(texture.id)) {\n textureIds.add(texture.id);\n textureList.push(texture);\n }\n }\n\n }\n\n this.textureList = textureList;\n if (!HaveSameTextureIds(previousTextureList, textureList)) {\n this.updateVersion();\n }\n this._textureSnapshot = this.version;\n return this.textureList;\n }\n\n /**\n * 获取当前场景中一个材质实际使用的几何类型,供 materialList 创建管线。\n * @param materialId 材质 ID\n * @returns 几何类型只读集合;不要修改返回的内部集合\n */\n public getMaterialGeometryTypes(materialId: number): ReadonlySet<string> {\n return this._materialGeometryTypes.get(materialId) ?? new Set<string>();\n }\n\n /**\n * 记录一个实际 Mesh 的材质与几何类型组合。\n * @param materialId 材质 ID\n * @param geometryType 几何类型\n */\n private addMaterialGeometryType(materialId: number, geometryType: string): void {\n let types = this._materialGeometryTypes.get(materialId);\n if (types === undefined) {\n types = new Set<string>();\n this._materialGeometryTypes.set(materialId, types);\n }\n types.add(geometryType);\n }\n\n /**\n * 更新场景绘制顺序。\n * 仅按照 Mesh 的 order 从小到大重新排列 drawList,不重建其他资源列表。\n * @returns 无返回值\n */\n public updateDrawOrder(): void {\n this.drawList.sort((left: DrawList, right: DrawList): number => {\n return left.order - right.order;\n });\n\n }\n\n}\n\n/**\n * 获取网格使用的单层图片或实例层表;列表由调用者按 ID 去重。\n * @param mesh 普通或实例网格\n * @returns 材质引用的贴图列表\n */\nconst GetMeshTextures = (mesh: MeshLike): TextureResource[] => {\n return mesh.textures.filter((texture): texture is TextureResource => texture !== undefined);\n};\n\n/**\n * 比较两个贴图列表是否包含相同 ID。\n * @param left 左侧贴图列表\n * @param right 右侧贴图列表\n * @returns 是否包含相同贴图 ID\n */\nconst HaveSameTextureIds = (left: readonly TextureResource[], right: readonly TextureResource[]): boolean => {\n if (left.length !== right.length) {\n return false;\n }\n\n const rightIds: Set<number> = new Set<number>(right.map((texture: TextureResource): number => texture.id));\n\n return left.every((texture: TextureResource): boolean => rightIds.has(texture.id));\n};\n\nexport default Scene;\nexport type { DrawList, GeometryList, MaterialList, SceneLike, TextureList };\n"],"mappings":"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"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import TexturedStyle from "./TexturedStyle";
|
|
2
|
+
import type { BorderAlign, PixelAligned } from "./types";
|
|
3
|
+
/** 有宽度的实体三角面边框样式。 */
|
|
4
|
+
declare class EdgeStyle extends TexturedStyle {
|
|
5
|
+
/** 创建关闭的实体边框,顺向重复、横向固定。 */
|
|
6
|
+
constructor();
|
|
7
|
+
private _width;
|
|
8
|
+
/** 实体边框宽度,0 不生成边框。 */
|
|
9
|
+
get width(): number;
|
|
10
|
+
/** @param value 实体边框宽度,0 不生成边框。 */
|
|
11
|
+
set width(value: number);
|
|
12
|
+
private _borderAlign;
|
|
13
|
+
/** 边框对齐:inset / normal / outset。 */
|
|
14
|
+
get borderAlign(): BorderAlign;
|
|
15
|
+
/** @param value 边框对齐:inset / normal / outset。 */
|
|
16
|
+
set borderAlign(value: BorderAlign);
|
|
17
|
+
private _pixelAligned;
|
|
18
|
+
/** px 固定像素,zoom 随相机缩放。 */
|
|
19
|
+
get pixelAligned(): PixelAligned;
|
|
20
|
+
/** @param value px 固定像素,zoom 随相机缩放。 */
|
|
21
|
+
set pixelAligned(value: PixelAligned);
|
|
22
|
+
private _uvRepeat;
|
|
23
|
+
/** 沿完整轮廓的 UV 重复次数。 */
|
|
24
|
+
get uvRepeat(): number;
|
|
25
|
+
/** @param value 沿完整轮廓的 UV 重复次数。 */
|
|
26
|
+
set uvRepeat(value: number);
|
|
27
|
+
}
|
|
28
|
+
export default EdgeStyle;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { NormalizeSize } from "./PartStyle.js";
|
|
2
|
+
import TexturedStyle from "./TexturedStyle.js";
|
|
3
|
+
//#region src/scripts/Style/EdgeStyle.ts
|
|
4
|
+
/** 有宽度的实体三角面边框样式。 */
|
|
5
|
+
var EdgeStyle = class extends TexturedStyle {
|
|
6
|
+
/** 创建关闭的实体边框,顺向重复、横向固定。 */
|
|
7
|
+
constructor() {
|
|
8
|
+
super("edge");
|
|
9
|
+
this.addressModeV = "clamp-to-edge";
|
|
10
|
+
}
|
|
11
|
+
_width = 1;
|
|
12
|
+
/** 实体边框宽度,0 不生成边框。 */
|
|
13
|
+
get width() {
|
|
14
|
+
return this._width;
|
|
15
|
+
}
|
|
16
|
+
/** @param value 实体边框宽度,0 不生成边框。 */
|
|
17
|
+
set width(value) {
|
|
18
|
+
value = NormalizeSize(value);
|
|
19
|
+
if (this._width === value) return;
|
|
20
|
+
this._width = value;
|
|
21
|
+
this.notify("width");
|
|
22
|
+
}
|
|
23
|
+
_borderAlign = "normal";
|
|
24
|
+
/** 边框对齐:inset / normal / outset。 */
|
|
25
|
+
get borderAlign() {
|
|
26
|
+
return this._borderAlign;
|
|
27
|
+
}
|
|
28
|
+
/** @param value 边框对齐:inset / normal / outset。 */
|
|
29
|
+
set borderAlign(value) {
|
|
30
|
+
if (![
|
|
31
|
+
"inset",
|
|
32
|
+
"normal",
|
|
33
|
+
"outset"
|
|
34
|
+
].includes(value)) throw new TypeError("Invalid border alignment.");
|
|
35
|
+
if (this._borderAlign === value) return;
|
|
36
|
+
this._borderAlign = value;
|
|
37
|
+
this.notify("borderAlign");
|
|
38
|
+
}
|
|
39
|
+
_pixelAligned = "px";
|
|
40
|
+
/** px 固定像素,zoom 随相机缩放。 */
|
|
41
|
+
get pixelAligned() {
|
|
42
|
+
return this._pixelAligned;
|
|
43
|
+
}
|
|
44
|
+
/** @param value px 固定像素,zoom 随相机缩放。 */
|
|
45
|
+
set pixelAligned(value) {
|
|
46
|
+
if (!["px", "zoom"].includes(value)) throw new TypeError("Invalid pixel alignment.");
|
|
47
|
+
if (this._pixelAligned === value) return;
|
|
48
|
+
this._pixelAligned = value;
|
|
49
|
+
this.notify("pixelAligned");
|
|
50
|
+
}
|
|
51
|
+
_uvRepeat = 1;
|
|
52
|
+
/** 沿完整轮廓的 UV 重复次数。 */
|
|
53
|
+
get uvRepeat() {
|
|
54
|
+
return this._uvRepeat;
|
|
55
|
+
}
|
|
56
|
+
/** @param value 沿完整轮廓的 UV 重复次数。 */
|
|
57
|
+
set uvRepeat(value) {
|
|
58
|
+
value = NormalizeSize(value);
|
|
59
|
+
if (this._uvRepeat === value) return;
|
|
60
|
+
this._uvRepeat = value;
|
|
61
|
+
this.notify("uvRepeat");
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
export { EdgeStyle as default };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=EdgeStyle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EdgeStyle.js","names":[],"sources":["../../src/scripts/Style/EdgeStyle.ts"],"sourcesContent":["import TexturedStyle from \"./TexturedStyle\";\nimport { NormalizeSize } from \"./PartStyle\";\nimport type { BorderAlign, PixelAligned } from \"./types\";\n\n/** 有宽度的实体三角面边框样式。 */\nclass EdgeStyle extends TexturedStyle {\n /** 创建关闭的实体边框,顺向重复、横向固定。 */\n public constructor() {\n super(\"edge\");\n this.addressModeV = \"clamp-to-edge\";\n }\n\n private _width: number = 1;\n /** 实体边框宽度,0 不生成边框。 */\n public get width(): number { return this._width; }\n /** @param value 实体边框宽度,0 不生成边框。 */\n public set width(value: number) {\n value = NormalizeSize(value);\n if (this._width === value) return;\n this._width = value;\n this.notify(\"width\");\n }\n\n private _borderAlign: BorderAlign = \"normal\";\n /** 边框对齐:inset / normal / outset。 */\n public get borderAlign(): BorderAlign { return this._borderAlign; }\n /** @param value 边框对齐:inset / normal / outset。 */\n public set borderAlign(value: BorderAlign) {\n if (![\"inset\", \"normal\", \"outset\"].includes(value)) throw new TypeError(\"Invalid border alignment.\");\n if (this._borderAlign === value) return;\n this._borderAlign = value;\n this.notify(\"borderAlign\");\n }\n\n private _pixelAligned: PixelAligned = \"px\";\n /** px 固定像素,zoom 随相机缩放。 */\n public get pixelAligned(): PixelAligned { return this._pixelAligned; }\n /** @param value px 固定像素,zoom 随相机缩放。 */\n public set pixelAligned(value: PixelAligned) {\n if (![\"px\", \"zoom\"].includes(value)) throw new TypeError(\"Invalid pixel alignment.\");\n if (this._pixelAligned === value) return;\n this._pixelAligned = value;\n this.notify(\"pixelAligned\");\n }\n\n\n private _uvRepeat: number = 1;\n /** 沿完整轮廓的 UV 重复次数。 */\n public get uvRepeat(): number { return this._uvRepeat; }\n /** @param value 沿完整轮廓的 UV 重复次数。 */\n public set uvRepeat(value: number) {\n value = NormalizeSize(value);\n if (this._uvRepeat === value) return;\n this._uvRepeat = value;\n this.notify(\"uvRepeat\");\n }\n\n}\nexport default EdgeStyle;\n"],"mappings":";;;;AAKA,IAAM,YAAN,cAAwB,cAAc;;CAElC,cAAqB;EACjB,MAAM,MAAM;EACZ,KAAK,eAAe;CACxB;CAEA,SAAyB;;CAEzB,IAAW,QAAgB;EAAE,OAAO,KAAK;CAAQ;;CAEjD,IAAW,MAAM,OAAe;EAC5B,QAAQ,cAAc,KAAK;EAC3B,IAAI,KAAK,WAAW,OAAO;EAC3B,KAAK,SAAS;EACd,KAAK,OAAO,OAAO;CACvB;CAEA,eAAoC;;CAEpC,IAAW,cAA2B;EAAE,OAAO,KAAK;CAAc;;CAElE,IAAW,YAAY,OAAoB;EACvC,IAAI,CAAC;GAAC;GAAS;GAAU;EAAQ,CAAC,CAAC,SAAS,KAAK,GAAG,MAAM,IAAI,UAAU,2BAA2B;EACnG,IAAI,KAAK,iBAAiB,OAAO;EACjC,KAAK,eAAe;EACpB,KAAK,OAAO,aAAa;CAC7B;CAEA,gBAAsC;;CAEtC,IAAW,eAA6B;EAAE,OAAO,KAAK;CAAe;;CAErE,IAAW,aAAa,OAAqB;EACzC,IAAI,CAAC,CAAC,MAAM,MAAM,CAAC,CAAC,SAAS,KAAK,GAAG,MAAM,IAAI,UAAU,0BAA0B;EACnF,IAAI,KAAK,kBAAkB,OAAO;EAClC,KAAK,gBAAgB;EACrB,KAAK,OAAO,cAAc;CAC9B;CAGA,YAA4B;;CAE5B,IAAW,WAAmB;EAAE,OAAO,KAAK;CAAW;;CAEvD,IAAW,SAAS,OAAe;EAC/B,QAAQ,cAAc,KAAK;EAC3B,IAAI,KAAK,cAAc,OAAO;EAC9B,KAAK,YAAY;EACjB,KAAK,OAAO,UAAU;CAC1B;AAEJ"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PartSubscriber } from "./types";
|
|
2
|
+
/** miter 尖角斜接、round 圆接、bevel 切角连接。 */
|
|
3
|
+
type JoinType = "miter" | "round" | "bevel";
|
|
4
|
+
/** 多边形节点连接样式,只控制几何拓扑,不拥有颜色、宽度或 GPU 缓存。 */
|
|
5
|
+
declare class JoinStyle {
|
|
6
|
+
private _type;
|
|
7
|
+
private _seg;
|
|
8
|
+
private readonly _subscribers;
|
|
9
|
+
/** 默认尖角;bevel 切掉尖端,但不会断开边框。 */
|
|
10
|
+
get type(): JoinType;
|
|
11
|
+
/** @param value 节点连接类型 */
|
|
12
|
+
set type(value: JoinType);
|
|
13
|
+
/** 每个圆接的细分段数,默认 8;不影响填充面或原生线框。 */
|
|
14
|
+
get seg(): number;
|
|
15
|
+
/** @param value 1 到 4096 的整数,只有 round 使用此精度 */
|
|
16
|
+
set seg(value: number);
|
|
17
|
+
/** @param subscriber 通常为所属 Style */
|
|
18
|
+
add(subscriber: PartSubscriber): void;
|
|
19
|
+
/** @param subscriber 要解绑的 Style */
|
|
20
|
+
delete(subscriber: PartSubscriber): void;
|
|
21
|
+
/** 清理订阅,不销毁其他对象。 */
|
|
22
|
+
dispose(): void;
|
|
23
|
+
/** @param field 改变的字段 */
|
|
24
|
+
private notify;
|
|
25
|
+
}
|
|
26
|
+
export default JoinStyle;
|
|
27
|
+
export type { JoinType };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region src/scripts/Style/JoinStyle.ts
|
|
2
|
+
/** 多边形节点连接样式,只控制几何拓扑,不拥有颜色、宽度或 GPU 缓存。 */
|
|
3
|
+
var JoinStyle = class {
|
|
4
|
+
_type = "miter";
|
|
5
|
+
_seg = 8;
|
|
6
|
+
_subscribers = /* @__PURE__ */ new Set();
|
|
7
|
+
/** 默认尖角;bevel 切掉尖端,但不会断开边框。 */
|
|
8
|
+
get type() {
|
|
9
|
+
return this._type;
|
|
10
|
+
}
|
|
11
|
+
/** @param value 节点连接类型 */
|
|
12
|
+
set type(value) {
|
|
13
|
+
if (![
|
|
14
|
+
"miter",
|
|
15
|
+
"round",
|
|
16
|
+
"bevel"
|
|
17
|
+
].includes(value)) throw new TypeError("Invalid join type.");
|
|
18
|
+
if (this._type === value) return;
|
|
19
|
+
this._type = value;
|
|
20
|
+
this.notify("type");
|
|
21
|
+
}
|
|
22
|
+
/** 每个圆接的细分段数,默认 8;不影响填充面或原生线框。 */
|
|
23
|
+
get seg() {
|
|
24
|
+
return this._seg;
|
|
25
|
+
}
|
|
26
|
+
/** @param value 1 到 4096 的整数,只有 round 使用此精度 */
|
|
27
|
+
set seg(value) {
|
|
28
|
+
if (!Number.isInteger(value) || value < 1 || value > 4096) throw new RangeError("Join seg must be an integer in [1, 4096].");
|
|
29
|
+
if (this._seg === value) return;
|
|
30
|
+
this._seg = value;
|
|
31
|
+
this.notify("seg");
|
|
32
|
+
}
|
|
33
|
+
/** @param subscriber 通常为所属 Style */
|
|
34
|
+
add(subscriber) {
|
|
35
|
+
this._subscribers.add(subscriber);
|
|
36
|
+
}
|
|
37
|
+
/** @param subscriber 要解绑的 Style */
|
|
38
|
+
delete(subscriber) {
|
|
39
|
+
this._subscribers.delete(subscriber);
|
|
40
|
+
}
|
|
41
|
+
/** 清理订阅,不销毁其他对象。 */
|
|
42
|
+
dispose() {
|
|
43
|
+
this._subscribers.clear();
|
|
44
|
+
}
|
|
45
|
+
/** @param field 改变的字段 */
|
|
46
|
+
notify(field) {
|
|
47
|
+
for (const subscriber of [...this._subscribers]) subscriber.onPartChange("join", field);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { JoinStyle as default };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=JoinStyle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JoinStyle.js","names":[],"sources":["../../src/scripts/Style/JoinStyle.ts"],"sourcesContent":["import type { PartSubscriber } from \"./types\";\n\n/** miter 尖角斜接、round 圆接、bevel 切角连接。 */\ntype JoinType = \"miter\" | \"round\" | \"bevel\";\n\n/** 多边形节点连接样式,只控制几何拓扑,不拥有颜色、宽度或 GPU 缓存。 */\nclass JoinStyle {\n private _type: JoinType = \"miter\";\n private _seg: number = 8;\n private readonly _subscribers = new Set<PartSubscriber>();\n\n /** 默认尖角;bevel 切掉尖端,但不会断开边框。 */\n public get type(): JoinType { return this._type; }\n /** @param value 节点连接类型 */\n public set type(value: JoinType) {\n if (![\"miter\", \"round\", \"bevel\"].includes(value)) throw new TypeError(\"Invalid join type.\");\n if (this._type === value) return;\n this._type = value;\n this.notify(\"type\");\n }\n /** 每个圆接的细分段数,默认 8;不影响填充面或原生线框。 */\n public get seg(): number { return this._seg; }\n /** @param value 1 到 4096 的整数,只有 round 使用此精度 */\n public set seg(value: number) {\n if (!Number.isInteger(value) || value < 1 || value > 4096) throw new RangeError(\"Join seg must be an integer in [1, 4096].\");\n if (this._seg === value) return;\n this._seg = value;\n this.notify(\"seg\");\n }\n /** @param subscriber 通常为所属 Style */\n public add(subscriber: PartSubscriber): void { this._subscribers.add(subscriber); }\n /** @param subscriber 要解绑的 Style */\n public delete(subscriber: PartSubscriber): void { this._subscribers.delete(subscriber); }\n /** 清理订阅,不销毁其他对象。 */\n public dispose(): void { this._subscribers.clear(); }\n /** @param field 改变的字段 */\n private notify(field: string): void {\n for (const subscriber of [...this._subscribers]) subscriber.onPartChange(\"join\", field);\n }\n}\n\nexport default JoinStyle;\nexport type { JoinType };\n"],"mappings":";;AAMA,IAAM,YAAN,MAAgB;CACZ,QAA0B;CAC1B,OAAuB;CACvB,+BAAgC,IAAI,IAAoB;;CAGxD,IAAW,OAAiB;EAAE,OAAO,KAAK;CAAO;;CAEjD,IAAW,KAAK,OAAiB;EAC7B,IAAI,CAAC;GAAC;GAAS;GAAS;EAAO,CAAC,CAAC,SAAS,KAAK,GAAG,MAAM,IAAI,UAAU,oBAAoB;EAC1F,IAAI,KAAK,UAAU,OAAO;EAC1B,KAAK,QAAQ;EACb,KAAK,OAAO,MAAM;CACtB;;CAEA,IAAW,MAAc;EAAE,OAAO,KAAK;CAAM;;CAE7C,IAAW,IAAI,OAAe;EAC1B,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,QAAQ,KAAK,QAAQ,MAAM,MAAM,IAAI,WAAW,2CAA2C;EAC3H,IAAI,KAAK,SAAS,OAAO;EACzB,KAAK,OAAO;EACZ,KAAK,OAAO,KAAK;CACrB;;CAEA,IAAW,YAAkC;EAAE,KAAK,aAAa,IAAI,UAAU;CAAG;;CAElF,OAAc,YAAkC;EAAE,KAAK,aAAa,OAAO,UAAU;CAAG;;CAExF,UAAuB;EAAE,KAAK,aAAa,MAAM;CAAG;;CAEpD,OAAe,OAAqB;EAChC,KAAK,MAAM,cAAc,CAAC,GAAG,KAAK,YAAY,GAAG,WAAW,aAAa,QAAQ,KAAK;CAC1F;AACJ"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import Color from "../Color";
|
|
2
|
+
import type { ColorSubscriber } from "../Color";
|
|
3
|
+
import type { PartSubscriber, StyleArea } from "./types";
|
|
4
|
+
/** 四个样式分区的共同基础,仅管理显示、颜色、透明度和订阅。 */
|
|
5
|
+
declare class PartStyle implements ColorSubscriber {
|
|
6
|
+
/** 分区身份。 */
|
|
7
|
+
readonly area: Exclude<StyleArea, "whole">;
|
|
8
|
+
private readonly _subscribers;
|
|
9
|
+
private _enabled;
|
|
10
|
+
private _color;
|
|
11
|
+
private _opacity;
|
|
12
|
+
/**
|
|
13
|
+
* 创建分区并订阅默认颜色。
|
|
14
|
+
* @param area 分区身份
|
|
15
|
+
*/
|
|
16
|
+
constructor(area: Exclude<StyleArea, "whole">);
|
|
17
|
+
/** 是否生成并显示该分区,默认关闭。 */
|
|
18
|
+
get enabled(): boolean;
|
|
19
|
+
/** @param value 是否启用该分区 */
|
|
20
|
+
set enabled(value: boolean);
|
|
21
|
+
/** 该分区独立颜色,默认不透明白色。 */
|
|
22
|
+
get color(): Color;
|
|
23
|
+
/** @param value 新颜色引用;先解绑旧颜色,再订阅新颜色 */
|
|
24
|
+
set color(value: Color);
|
|
25
|
+
/** 该分区独立透明度,作用于最终输出 alpha。 */
|
|
26
|
+
get opacity(): number;
|
|
27
|
+
/** @param value 透明度,钳制到 0 到 1 */
|
|
28
|
+
set opacity(value: number);
|
|
29
|
+
/** @param subscriber 分区变化接收者 */
|
|
30
|
+
add(subscriber: PartSubscriber): void;
|
|
31
|
+
/** @param subscriber 要解除的接收者;不销毁对象或 GPU 缓存 */
|
|
32
|
+
delete(subscriber: PartSubscriber): void;
|
|
33
|
+
/** 最终停止使用时解除颜色订阅及分区订阅;不销毁共享 Color。 */
|
|
34
|
+
dispose(): void;
|
|
35
|
+
/**
|
|
36
|
+
* 接收颜色的字段级通知。
|
|
37
|
+
* @param color 来源颜色
|
|
38
|
+
* @param field 颜色属性名
|
|
39
|
+
*/
|
|
40
|
+
onColorChange(color: Color, field: string): void;
|
|
41
|
+
/** @param field 实际变化的字段名 */
|
|
42
|
+
protected notify(field: string): void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 验证尺寸参数并钳制负值;拒绝非有限值,避免污染几何和 GPU 数据。
|
|
46
|
+
* @param value 待验证数值
|
|
47
|
+
* @returns 非负有限值
|
|
48
|
+
*/
|
|
49
|
+
export declare const NormalizeSize: (value: number) => number;
|
|
50
|
+
export default PartStyle;
|