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,212 @@
|
|
|
1
|
+
import { GETID } from "../ID.js";
|
|
2
|
+
import { Vec2 } from "bpmatrixjs/Math/Vec2";
|
|
3
|
+
import { Mat3 } from "bpmatrixjs/Math/Mat3";
|
|
4
|
+
//#region src/scripts/Object/index.ts
|
|
5
|
+
/** 场景节点变换基类:参数持有一个版本,计算结果和每个消费者各存处理快照。 */
|
|
6
|
+
var ObjectNode = class {
|
|
7
|
+
/** 全局节点 ID。 */
|
|
8
|
+
id = GETID();
|
|
9
|
+
/** 节点类型。 */
|
|
10
|
+
type = "ObjectNode";
|
|
11
|
+
_version = 0;
|
|
12
|
+
_parent = null;
|
|
13
|
+
_position;
|
|
14
|
+
_rotation = 0;
|
|
15
|
+
_scale;
|
|
16
|
+
_matrix = new Mat3();
|
|
17
|
+
_worldMatrix = new Mat3();
|
|
18
|
+
_order = 0;
|
|
19
|
+
_localSnapshot = -1;
|
|
20
|
+
_worldSnapshot = -1;
|
|
21
|
+
_parentSnapshot = null;
|
|
22
|
+
_parentVersion = -1;
|
|
23
|
+
_writingMatrices = false;
|
|
24
|
+
_nodeDisposed = false;
|
|
25
|
+
/** @param x 初始 X 坐标 @param y 初始 Y 坐标 */
|
|
26
|
+
constructor(x, y) {
|
|
27
|
+
this._position = new Vec2(x, y);
|
|
28
|
+
this._scale = new Vec2(1, 1);
|
|
29
|
+
this._position.add(this, "position");
|
|
30
|
+
this._scale.add(this, "scale");
|
|
31
|
+
this._matrix.add(this, "matrix");
|
|
32
|
+
this._worldMatrix.add(this, "worldMatrix");
|
|
33
|
+
}
|
|
34
|
+
/** 节点输入版本;计算快照不会清除或回退它。 */
|
|
35
|
+
get version() {
|
|
36
|
+
return this._version;
|
|
37
|
+
}
|
|
38
|
+
/** 手动使变换失效;普通 position/scale/rotation 修改已自动通知。 */
|
|
39
|
+
updateVersion() {
|
|
40
|
+
this._version++;
|
|
41
|
+
}
|
|
42
|
+
/** 父节点,场景树结构请通过 Group.add/remove 修改。 */
|
|
43
|
+
get parent() {
|
|
44
|
+
return this._parent;
|
|
45
|
+
}
|
|
46
|
+
/** @param value 父引用,Group 维护 children 与 Scene 列表 */
|
|
47
|
+
set parent(value) {
|
|
48
|
+
if (this._parent === value) return;
|
|
49
|
+
this._parent = value;
|
|
50
|
+
this.updateVersion();
|
|
51
|
+
}
|
|
52
|
+
/** 位置向量,内部 set/setX/x 赋值均能通知。 */
|
|
53
|
+
get position() {
|
|
54
|
+
return this._position;
|
|
55
|
+
}
|
|
56
|
+
/** @param value 新位置向量,替换时解绑旧字段 */
|
|
57
|
+
set position(value) {
|
|
58
|
+
if (this._position === value) return;
|
|
59
|
+
this._position.delete(this, "position");
|
|
60
|
+
this._position = value;
|
|
61
|
+
value.add(this, "position");
|
|
62
|
+
this.updateVersion();
|
|
63
|
+
}
|
|
64
|
+
/** 本地旋转弧度。 */
|
|
65
|
+
get rotation() {
|
|
66
|
+
return this._rotation;
|
|
67
|
+
}
|
|
68
|
+
/** @param value 新旋转弧度 */
|
|
69
|
+
set rotation(value) {
|
|
70
|
+
if (this._rotation === value) return;
|
|
71
|
+
this._rotation = value;
|
|
72
|
+
this.updateVersion();
|
|
73
|
+
}
|
|
74
|
+
/** 缩放向量,可与其他节点共享。 */
|
|
75
|
+
get scale() {
|
|
76
|
+
return this._scale;
|
|
77
|
+
}
|
|
78
|
+
/** @param value 新缩放向量 */
|
|
79
|
+
set scale(value) {
|
|
80
|
+
if (this._scale === value) return;
|
|
81
|
+
this._scale.delete(this, "scale");
|
|
82
|
+
this._scale = value;
|
|
83
|
+
value.add(this, "scale");
|
|
84
|
+
this.updateVersion();
|
|
85
|
+
}
|
|
86
|
+
/** 本地矩阵;直接修改类方法会作为自定义矩阵保留,直到变换参数再次改变。 */
|
|
87
|
+
get matrix() {
|
|
88
|
+
return this._matrix;
|
|
89
|
+
}
|
|
90
|
+
/** @param value 新本地矩阵 */
|
|
91
|
+
set matrix(value) {
|
|
92
|
+
if (this._matrix === value) return;
|
|
93
|
+
this._matrix.delete(this, "matrix");
|
|
94
|
+
this._matrix = value;
|
|
95
|
+
value.add(this, "matrix");
|
|
96
|
+
this.onMathChange(value, "matrix");
|
|
97
|
+
}
|
|
98
|
+
/** 世界矩阵,Mat3 通知用于更新 Mesh 连续矩阵数组。 */
|
|
99
|
+
get worldMatrix() {
|
|
100
|
+
return this._worldMatrix;
|
|
101
|
+
}
|
|
102
|
+
/** @param value 新世界矩阵 */
|
|
103
|
+
set worldMatrix(value) {
|
|
104
|
+
if (this._worldMatrix === value) return;
|
|
105
|
+
this._worldMatrix.delete(this, "worldMatrix");
|
|
106
|
+
this._worldMatrix = value;
|
|
107
|
+
value.add(this, "worldMatrix");
|
|
108
|
+
this.onMathChange(value, "worldMatrix");
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 数学对象完成修改后通知节点;内部计算不反向增加输入版本。
|
|
112
|
+
* @param source 数学对象
|
|
113
|
+
* @param field position/scale/matrix/worldMatrix 关联字段
|
|
114
|
+
*/
|
|
115
|
+
onMathChange(source, field) {
|
|
116
|
+
if (this._nodeDisposed || this._writingMatrices) return;
|
|
117
|
+
if (field === "position" && source === this._position || field === "scale" && source === this._scale) this.updateVersion();
|
|
118
|
+
else if (field === "matrix" && source === this._matrix || field === "worldMatrix" && source === this._worldMatrix) {
|
|
119
|
+
this.updateVersion();
|
|
120
|
+
this._localSnapshot = this.version;
|
|
121
|
+
if (field === "worldMatrix") {
|
|
122
|
+
this._worldSnapshot = this.version;
|
|
123
|
+
this._parentSnapshot = this.parent?.worldMatrix ?? null;
|
|
124
|
+
this._parentVersion = this._parentSnapshot?.version ?? -1;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** 参数版本改变后才生成本地矩阵。 */
|
|
129
|
+
ensureMatrix() {
|
|
130
|
+
if (this._nodeDisposed) throw new Error("Disposed node cannot be updated.");
|
|
131
|
+
if (this._localSnapshot !== this.version) this.updateMatrix();
|
|
132
|
+
return this._matrix;
|
|
133
|
+
}
|
|
134
|
+
/** 强制根据 position/rotation/scale 生成本地矩阵;覆盖手动指定的本地矩阵。 */
|
|
135
|
+
updateMatrix() {
|
|
136
|
+
const cos = Math.cos(this.rotation);
|
|
137
|
+
const sin = Math.sin(this.rotation);
|
|
138
|
+
this._writingMatrices = true;
|
|
139
|
+
try {
|
|
140
|
+
this._matrix.set([
|
|
141
|
+
cos * this.scale.x,
|
|
142
|
+
sin * this.scale.x,
|
|
143
|
+
0,
|
|
144
|
+
-sin * this.scale.y,
|
|
145
|
+
cos * this.scale.y,
|
|
146
|
+
0,
|
|
147
|
+
this.position.x,
|
|
148
|
+
this.position.y,
|
|
149
|
+
1
|
|
150
|
+
]);
|
|
151
|
+
this._localSnapshot = this.version;
|
|
152
|
+
this._worldSnapshot = -1;
|
|
153
|
+
} finally {
|
|
154
|
+
this._writingMatrices = false;
|
|
155
|
+
}
|
|
156
|
+
return this._matrix;
|
|
157
|
+
}
|
|
158
|
+
/** 先更新祖先,再按自身版本、父矩阵身份和版本更新世界矩阵,不遍历兄弟节点。 */
|
|
159
|
+
ensureWorldMatrix() {
|
|
160
|
+
this.parent?.ensureWorldMatrix();
|
|
161
|
+
this.ensureMatrix();
|
|
162
|
+
const parentMatrix = this.parent?.worldMatrix ?? null;
|
|
163
|
+
const parentVersion = parentMatrix?.version ?? -1;
|
|
164
|
+
if (this._worldSnapshot !== this.version || this._parentSnapshot !== parentMatrix || this._parentVersion !== parentVersion) {
|
|
165
|
+
this._writingMatrices = true;
|
|
166
|
+
try {
|
|
167
|
+
if (parentMatrix === null) this._worldMatrix.copy(this._matrix);
|
|
168
|
+
else this._worldMatrix.mul(parentMatrix, this._matrix);
|
|
169
|
+
this._worldSnapshot = this.version;
|
|
170
|
+
this._parentSnapshot = parentMatrix;
|
|
171
|
+
this._parentVersion = parentVersion;
|
|
172
|
+
} finally {
|
|
173
|
+
this._writingMatrices = false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return this._worldMatrix;
|
|
177
|
+
}
|
|
178
|
+
/** 强制重新计算当前世界矩阵,同时保留显式修改的本地矩阵。 */
|
|
179
|
+
updateWorldMatrix() {
|
|
180
|
+
this._worldSnapshot = -1;
|
|
181
|
+
return this.ensureWorldMatrix();
|
|
182
|
+
}
|
|
183
|
+
/** 绘制排序值。 */
|
|
184
|
+
get order() {
|
|
185
|
+
return this._order;
|
|
186
|
+
}
|
|
187
|
+
/** @param value 新排序值;所属 Scene 递增版本,下一帧重排列表 */
|
|
188
|
+
set order(value) {
|
|
189
|
+
if (this._order === value) return;
|
|
190
|
+
this._order = value;
|
|
191
|
+
let current = this.parent;
|
|
192
|
+
while (current !== null) {
|
|
193
|
+
if (current.type === "Scene") {
|
|
194
|
+
current.updateVersion();
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
current = current.parent;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** 最终释放数学对象订阅,不移除场景节点,不销毁共享 Vec2/Mat3。 */
|
|
201
|
+
dispose() {
|
|
202
|
+
this._position.delete(this, "position");
|
|
203
|
+
this._scale.delete(this, "scale");
|
|
204
|
+
this._matrix.delete(this, "matrix");
|
|
205
|
+
this._worldMatrix.delete(this, "worldMatrix");
|
|
206
|
+
this._nodeDisposed = true;
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
//#endregion
|
|
210
|
+
export { ObjectNode as default };
|
|
211
|
+
|
|
212
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/scripts/Object/index.ts"],"sourcesContent":["import { Vec2 } from \"bpmatrixjs/Math/Vec2\";\nimport { Mat3 } from \"bpmatrixjs/Math/Mat3\";\nimport type { MathSubscriber, VersionedMath } from \"bpmatrixjs/Math\";\nimport { GETID } from \"../ID\";\nimport type { AddObject } from \"../global-types\";\n\ninterface ObjectNodeLike extends MathSubscriber {\n readonly id: number;\n readonly type: string;\n readonly version: number;\n parent: AddObject | null;\n position: Vec2;\n rotation: number;\n scale: Vec2;\n matrix: Mat3;\n worldMatrix: Mat3;\n order: number;\n updateVersion(): void;\n ensureMatrix(): Mat3;\n ensureWorldMatrix(): Mat3;\n updateMatrix(): Mat3;\n updateWorldMatrix(): Mat3;\n dispose(): void;\n}\n\n/** 场景节点变换基类:参数持有一个版本,计算结果和每个消费者各存处理快照。 */\nclass ObjectNode implements ObjectNodeLike {\n /** 全局节点 ID。 */\n public readonly id: number = GETID();\n /** 节点类型。 */\n public readonly type: string = \"ObjectNode\";\n private _version: number = 0;\n private _parent: AddObject | null = null;\n private _position: Vec2;\n private _rotation: number = 0;\n private _scale: Vec2;\n private _matrix: Mat3 = new Mat3();\n private _worldMatrix: Mat3 = new Mat3();\n private _order: number = 0;\n private _localSnapshot: number = -1;\n private _worldSnapshot: number = -1;\n private _parentSnapshot: Mat3 | null = null;\n private _parentVersion: number = -1;\n // 内部计算仍会通知 Mesh,但不能把计算结果误当作用户输入再次使自己失效。\n private _writingMatrices: boolean = false;\n protected _nodeDisposed: boolean = false;\n\n /** @param x 初始 X 坐标 @param y 初始 Y 坐标 */\n public constructor(x: number, y: number) {\n this._position = new Vec2(x, y);\n this._scale = new Vec2(1, 1);\n this._position.add(this, \"position\");\n this._scale.add(this, \"scale\");\n this._matrix.add(this, \"matrix\");\n this._worldMatrix.add(this, \"worldMatrix\");\n }\n\n /** 节点输入版本;计算快照不会清除或回退它。 */\n public get version(): number { return this._version; }\n /** 手动使变换失效;普通 position/scale/rotation 修改已自动通知。 */\n public updateVersion(): void { this._version++; }\n\n /** 父节点,场景树结构请通过 Group.add/remove 修改。 */\n public get parent(): AddObject | null { return this._parent; }\n /** @param value 父引用,Group 维护 children 与 Scene 列表 */\n public set parent(value: AddObject | null) {\n if (this._parent === value) return;\n this._parent = value;\n this.updateVersion();\n }\n\n /** 位置向量,内部 set/setX/x 赋值均能通知。 */\n public get position(): Vec2 { return this._position; }\n /** @param value 新位置向量,替换时解绑旧字段 */\n public set position(value: Vec2) {\n if (this._position === value) return;\n this._position.delete(this, \"position\");\n this._position = value;\n value.add(this, \"position\");\n this.updateVersion();\n }\n\n /** 本地旋转弧度。 */\n public get rotation(): number { return this._rotation; }\n /** @param value 新旋转弧度 */\n public set rotation(value: number) {\n if (this._rotation === value) return;\n this._rotation = value;\n this.updateVersion();\n }\n\n /** 缩放向量,可与其他节点共享。 */\n public get scale(): Vec2 { return this._scale; }\n /** @param value 新缩放向量 */\n public set scale(value: Vec2) {\n if (this._scale === value) return;\n this._scale.delete(this, \"scale\");\n this._scale = value;\n value.add(this, \"scale\");\n this.updateVersion();\n }\n\n /** 本地矩阵;直接修改类方法会作为自定义矩阵保留,直到变换参数再次改变。 */\n public get matrix(): Mat3 { return this._matrix; }\n /** @param value 新本地矩阵 */\n public set matrix(value: Mat3) {\n if (this._matrix === value) return;\n this._matrix.delete(this, \"matrix\");\n this._matrix = value;\n value.add(this, \"matrix\");\n this.onMathChange(value, \"matrix\");\n }\n\n /** 世界矩阵,Mat3 通知用于更新 Mesh 连续矩阵数组。 */\n public get worldMatrix(): Mat3 { return this._worldMatrix; }\n /** @param value 新世界矩阵 */\n public set worldMatrix(value: Mat3) {\n if (this._worldMatrix === value) return;\n this._worldMatrix.delete(this, \"worldMatrix\");\n this._worldMatrix = value;\n value.add(this, \"worldMatrix\");\n this.onMathChange(value, \"worldMatrix\");\n }\n\n /**\n * 数学对象完成修改后通知节点;内部计算不反向增加输入版本。\n * @param source 数学对象\n * @param field position/scale/matrix/worldMatrix 关联字段\n */\n public onMathChange(source: VersionedMath, field: string): void {\n if (this._nodeDisposed || this._writingMatrices) return;\n if ((field === \"position\" && source === this._position)\n || (field === \"scale\" && source === this._scale)) {\n this.updateVersion();\n } else if ((field === \"matrix\" && source === this._matrix)\n || (field === \"worldMatrix\" && source === this._worldMatrix)) {\n this.updateVersion();\n this._localSnapshot = this.version;\n if (field === \"worldMatrix\") {\n this._worldSnapshot = this.version;\n this._parentSnapshot = this.parent?.worldMatrix ?? null;\n this._parentVersion = this._parentSnapshot?.version ?? -1;\n }\n }\n }\n\n /** 参数版本改变后才生成本地矩阵。 */\n public ensureMatrix(): Mat3 {\n if (this._nodeDisposed) throw new Error(\"Disposed node cannot be updated.\");\n if (this._localSnapshot !== this.version) this.updateMatrix();\n return this._matrix;\n }\n\n /** 强制根据 position/rotation/scale 生成本地矩阵;覆盖手动指定的本地矩阵。 */\n public updateMatrix(): Mat3 {\n const cos: number = Math.cos(this.rotation);\n const sin: number = Math.sin(this.rotation);\n this._writingMatrices = true;\n try {\n this._matrix.set([\n cos * this.scale.x, sin * this.scale.x, 0,\n -sin * this.scale.y, cos * this.scale.y, 0,\n this.position.x, this.position.y, 1,\n ]);\n this._localSnapshot = this.version;\n this._worldSnapshot = -1;\n } finally {\n this._writingMatrices = false;\n }\n return this._matrix;\n }\n\n /** 先更新祖先,再按自身版本、父矩阵身份和版本更新世界矩阵,不遍历兄弟节点。 */\n public ensureWorldMatrix(): Mat3 {\n this.parent?.ensureWorldMatrix();\n this.ensureMatrix();\n const parentMatrix: Mat3 | null = this.parent?.worldMatrix ?? null;\n const parentVersion: number = parentMatrix?.version ?? -1;\n if (this._worldSnapshot !== this.version || this._parentSnapshot !== parentMatrix\n || this._parentVersion !== parentVersion) {\n this._writingMatrices = true;\n try {\n if (parentMatrix === null) this._worldMatrix.copy(this._matrix);\n else this._worldMatrix.mul(parentMatrix, this._matrix);\n this._worldSnapshot = this.version;\n this._parentSnapshot = parentMatrix;\n this._parentVersion = parentVersion;\n } finally {\n this._writingMatrices = false;\n }\n }\n return this._worldMatrix;\n }\n\n /** 强制重新计算当前世界矩阵,同时保留显式修改的本地矩阵。 */\n public updateWorldMatrix(): Mat3 {\n this._worldSnapshot = -1;\n return this.ensureWorldMatrix();\n }\n\n /** 绘制排序值。 */\n public get order(): number { return this._order; }\n /** @param value 新排序值;所属 Scene 递增版本,下一帧重排列表 */\n public set order(value: number) {\n if (this._order === value) return;\n this._order = value;\n let current: AddObject | null = this.parent;\n while (current !== null) {\n if (current.type === \"Scene\") {\n current.updateVersion();\n break;\n }\n current = current.parent;\n }\n }\n\n /** 最终释放数学对象订阅,不移除场景节点,不销毁共享 Vec2/Mat3。 */\n public dispose(): void {\n this._position.delete(this, \"position\");\n this._scale.delete(this, \"scale\");\n this._matrix.delete(this, \"matrix\");\n this._worldMatrix.delete(this, \"worldMatrix\");\n this._nodeDisposed = true;\n }\n}\nexport default ObjectNode;\nexport type { ObjectNodeLike };\n"],"mappings":";;;;;AA0BA,IAAM,aAAN,MAA2C;;CAEvC,KAA6B,MAAM;;CAEnC,OAA+B;CAC/B,WAA2B;CAC3B,UAAoC;CACpC;CACA,YAA4B;CAC5B;CACA,UAAwB,IAAI,KAAK;CACjC,eAA6B,IAAI,KAAK;CACtC,SAAyB;CACzB,iBAAiC;CACjC,iBAAiC;CACjC,kBAAuC;CACvC,iBAAiC;CAEjC,mBAAoC;CACpC,gBAAmC;;CAGnC,YAAmB,GAAW,GAAW;EACrC,KAAK,YAAY,IAAI,KAAK,GAAG,CAAC;EAC9B,KAAK,SAAS,IAAI,KAAK,GAAG,CAAC;EAC3B,KAAK,UAAU,IAAI,MAAM,UAAU;EACnC,KAAK,OAAO,IAAI,MAAM,OAAO;EAC7B,KAAK,QAAQ,IAAI,MAAM,QAAQ;EAC/B,KAAK,aAAa,IAAI,MAAM,aAAa;CAC7C;;CAGA,IAAW,UAAkB;EAAE,OAAO,KAAK;CAAU;;CAErD,gBAA6B;EAAE,KAAK;CAAY;;CAGhD,IAAW,SAA2B;EAAE,OAAO,KAAK;CAAS;;CAE7D,IAAW,OAAO,OAAyB;EACvC,IAAI,KAAK,YAAY,OAAO;EAC5B,KAAK,UAAU;EACf,KAAK,cAAc;CACvB;;CAGA,IAAW,WAAiB;EAAE,OAAO,KAAK;CAAW;;CAErD,IAAW,SAAS,OAAa;EAC7B,IAAI,KAAK,cAAc,OAAO;EAC9B,KAAK,UAAU,OAAO,MAAM,UAAU;EACtC,KAAK,YAA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AAO,KAAK;CAAQ;;CAEjD,IAAW,MAAM,OAAe;EAC5B,IAAI,KAAK,WAAW,OAAO;EAC3B,KAAK,SAAS;EACd,IAAI,UAA4B,KAAK;EACrC,OAAO,YAAY,MAAM;GACrB,IAAI,QAAQ,SAAS,SAAS;IAC1B,QAAQ,cAAc;IACtB;GACJ;GACA,UAAU,QAAQ;EACtB;CACJ;;CAGA,UAAuB;EACnB,KAAK,UAAU,OAAO,MAAM,UAAU;EACtC,KAAK,OAAO,OAAO,MAAM,OAAO;EAChC,KAAK,QAAQ,OAAO,MAAM,QAAQ;EAClC,KAAK,aAAa,OAAO,MAAM,aAAa;EAC5C,KAAK,gBAAgB;CACzB;AACJ"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Vec2 } from "bpmatrixjs/Math";
|
|
2
|
+
import type { MathSubscriber, VersionedMath } from "bpmatrixjs/Math";
|
|
3
|
+
import Style from "../Style";
|
|
4
|
+
import type { StyleChange, StyleSubscriber } from "../Style";
|
|
5
|
+
/** push / updateAt 使用的完整快照;省略项分别为原点、0、单位缩放和默认样式。 */
|
|
6
|
+
export interface RawOptions {
|
|
7
|
+
position?: Vec2;
|
|
8
|
+
rotation?: number;
|
|
9
|
+
scale?: Vec2;
|
|
10
|
+
style?: Style;
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** 原始值变化的影响范围,版本仍只有 Raw.version 一个。 */
|
|
14
|
+
export type RawChange = "matrix" | "style" | "texture" | "textureData" | "sampler";
|
|
15
|
+
/** 原始值管理者,不在回调内分配 GPU 资源。 */
|
|
16
|
+
export interface RawSubscriber {
|
|
17
|
+
onRawChange(raw: Raw, change: RawChange): void;
|
|
18
|
+
}
|
|
19
|
+
/** 一条实例原始记录;id 稳定,index 对应连续数组中的槽位。 */
|
|
20
|
+
export declare class Raw implements MathSubscriber, StyleSubscriber {
|
|
21
|
+
/** 全局唯一 ID,不随扩容改变。 */
|
|
22
|
+
readonly id: number;
|
|
23
|
+
/** 连续数组槽位,不是字节偏移。 */
|
|
24
|
+
readonly index: number;
|
|
25
|
+
private _position;
|
|
26
|
+
private _rotation;
|
|
27
|
+
private _scale;
|
|
28
|
+
private _style;
|
|
29
|
+
private _enabled;
|
|
30
|
+
private _version;
|
|
31
|
+
private readonly _subscribers;
|
|
32
|
+
private _disposed;
|
|
33
|
+
/**
|
|
34
|
+
* @param index 槽位
|
|
35
|
+
* @param options 原始值,不复制 Vec2 / Style,允许共享并接收通知
|
|
36
|
+
*/
|
|
37
|
+
constructor(index: number, options?: RawOptions);
|
|
38
|
+
/** 任意原始值变化时递增;打包或扩容不会改变这个版本。 */
|
|
39
|
+
get version(): number;
|
|
40
|
+
/** 相对于 IMesh 的位置。 */
|
|
41
|
+
get position(): Vec2;
|
|
42
|
+
/** @param value 位置引用,旧引用解除关联 */
|
|
43
|
+
set position(value: Vec2);
|
|
44
|
+
/** 局部旋转弧度。 */
|
|
45
|
+
get rotation(): number;
|
|
46
|
+
/** @param value 有限弧度 */
|
|
47
|
+
set rotation(value: number);
|
|
48
|
+
/** 局部缩放。 */
|
|
49
|
+
get scale(): Vec2;
|
|
50
|
+
/** @param value 缩放引用 */
|
|
51
|
+
set scale(value: Vec2);
|
|
52
|
+
/** 本条记录的独立样式,不覆盖共享 Geometry / Material.style。 */
|
|
53
|
+
get style(): Style;
|
|
54
|
+
/** @param value 新样式引用 */
|
|
55
|
+
set style(value: Style);
|
|
56
|
+
/** 是否绘制此槽位;关闭不删除记录或移动其他 index。 */
|
|
57
|
+
get enabled(): boolean;
|
|
58
|
+
/** @param value 是否绘制 */
|
|
59
|
+
set enabled(value: boolean);
|
|
60
|
+
/** @param subscriber 接收下一帧更新通知的管理者 */
|
|
61
|
+
add(subscriber: RawSubscriber): void;
|
|
62
|
+
/** @param subscriber 解除关联的管理者 */
|
|
63
|
+
delete(subscriber: RawSubscriber): void;
|
|
64
|
+
/** @param source 数学对象 @param field 关联字段 */
|
|
65
|
+
onMathChange(source: VersionedMath, field: string): void;
|
|
66
|
+
/** @param change 样式变化,图片像素变化不重打包数值 */
|
|
67
|
+
onStyleChange(change: StyleChange): void;
|
|
68
|
+
/** 解绑原始对象;不销毁共享 Vec2、Style 或 Texture。 */
|
|
69
|
+
dispose(): void;
|
|
70
|
+
/** 防止已解绑的记录重新产生部分关联。 */
|
|
71
|
+
private assertActive;
|
|
72
|
+
/** @param change 本次需要重新打包的区域 */
|
|
73
|
+
private notify;
|
|
74
|
+
}
|
|
75
|
+
/** 由 IMesh 持有的原始记录索引;外部使用 map.get(id) 后修改记录,不直接增删 Map。 */
|
|
76
|
+
declare class Raws {
|
|
77
|
+
private readonly _map;
|
|
78
|
+
/** 只读 Map,避免外部删除记录后遗留订阅或数组空洞。 */
|
|
79
|
+
get map(): ReadonlyMap<number, Raw>;
|
|
80
|
+
/** 记录数量,raw=false 时始终为 0。 */
|
|
81
|
+
get size(): number;
|
|
82
|
+
/** @param raw 由 IMesh 创建的记录 @internal */
|
|
83
|
+
add(raw: Raw): void;
|
|
84
|
+
/** 由 IMesh.clear / dispose 调用,解除全部订阅。 @internal */
|
|
85
|
+
clear(): void;
|
|
86
|
+
}
|
|
87
|
+
export default Raws;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { GETID } from "../ID.js";
|
|
2
|
+
import Style from "../Style/index.js";
|
|
3
|
+
import { Vec2 } from "bpmatrixjs/Math";
|
|
4
|
+
//#region src/scripts/Raws/index.ts
|
|
5
|
+
/** 一条实例原始记录;id 稳定,index 对应连续数组中的槽位。 */
|
|
6
|
+
var Raw = class {
|
|
7
|
+
/** 全局唯一 ID,不随扩容改变。 */
|
|
8
|
+
id = GETID();
|
|
9
|
+
/** 连续数组槽位,不是字节偏移。 */
|
|
10
|
+
index;
|
|
11
|
+
_position;
|
|
12
|
+
_rotation;
|
|
13
|
+
_scale;
|
|
14
|
+
_style;
|
|
15
|
+
_enabled;
|
|
16
|
+
_version = 0;
|
|
17
|
+
_subscribers = /* @__PURE__ */ new Set();
|
|
18
|
+
_disposed = false;
|
|
19
|
+
/**
|
|
20
|
+
* @param index 槽位
|
|
21
|
+
* @param options 原始值,不复制 Vec2 / Style,允许共享并接收通知
|
|
22
|
+
*/
|
|
23
|
+
constructor(index, options = {}) {
|
|
24
|
+
if (!Number.isSafeInteger(index) || index < 0) throw new RangeError("Invalid raw index.");
|
|
25
|
+
this.index = index;
|
|
26
|
+
this._position = options.position ?? new Vec2();
|
|
27
|
+
this._rotation = options.rotation ?? 0;
|
|
28
|
+
this._scale = options.scale ?? new Vec2(1, 1);
|
|
29
|
+
this._style = options.style ?? new Style();
|
|
30
|
+
this._enabled = options.enabled ?? true;
|
|
31
|
+
if (!Number.isFinite(this._rotation)) throw new RangeError("Rotation must be finite.");
|
|
32
|
+
this._position.add(this, "position");
|
|
33
|
+
this._scale.add(this, "scale");
|
|
34
|
+
this._style.add(this);
|
|
35
|
+
}
|
|
36
|
+
/** 任意原始值变化时递增;打包或扩容不会改变这个版本。 */
|
|
37
|
+
get version() {
|
|
38
|
+
return this._version;
|
|
39
|
+
}
|
|
40
|
+
/** 相对于 IMesh 的位置。 */
|
|
41
|
+
get position() {
|
|
42
|
+
return this._position;
|
|
43
|
+
}
|
|
44
|
+
/** @param value 位置引用,旧引用解除关联 */
|
|
45
|
+
set position(value) {
|
|
46
|
+
if (value === this._position) return;
|
|
47
|
+
this.assertActive();
|
|
48
|
+
this._position.delete(this, "position");
|
|
49
|
+
this._position = value;
|
|
50
|
+
value.add(this, "position");
|
|
51
|
+
this.notify("matrix");
|
|
52
|
+
}
|
|
53
|
+
/** 局部旋转弧度。 */
|
|
54
|
+
get rotation() {
|
|
55
|
+
return this._rotation;
|
|
56
|
+
}
|
|
57
|
+
/** @param value 有限弧度 */
|
|
58
|
+
set rotation(value) {
|
|
59
|
+
if (!Number.isFinite(value)) throw new RangeError("Rotation must be finite.");
|
|
60
|
+
if (value === this._rotation) return;
|
|
61
|
+
this.assertActive();
|
|
62
|
+
this._rotation = value;
|
|
63
|
+
this.notify("matrix");
|
|
64
|
+
}
|
|
65
|
+
/** 局部缩放。 */
|
|
66
|
+
get scale() {
|
|
67
|
+
return this._scale;
|
|
68
|
+
}
|
|
69
|
+
/** @param value 缩放引用 */
|
|
70
|
+
set scale(value) {
|
|
71
|
+
if (value === this._scale) return;
|
|
72
|
+
this.assertActive();
|
|
73
|
+
this._scale.delete(this, "scale");
|
|
74
|
+
this._scale = value;
|
|
75
|
+
value.add(this, "scale");
|
|
76
|
+
this.notify("matrix");
|
|
77
|
+
}
|
|
78
|
+
/** 本条记录的独立样式,不覆盖共享 Geometry / Material.style。 */
|
|
79
|
+
get style() {
|
|
80
|
+
return this._style;
|
|
81
|
+
}
|
|
82
|
+
/** @param value 新样式引用 */
|
|
83
|
+
set style(value) {
|
|
84
|
+
if (value === this._style) return;
|
|
85
|
+
this.assertActive();
|
|
86
|
+
this._style.delete(this);
|
|
87
|
+
this._style = value;
|
|
88
|
+
value.add(this);
|
|
89
|
+
this.notify("texture");
|
|
90
|
+
}
|
|
91
|
+
/** 是否绘制此槽位;关闭不删除记录或移动其他 index。 */
|
|
92
|
+
get enabled() {
|
|
93
|
+
return this._enabled;
|
|
94
|
+
}
|
|
95
|
+
/** @param value 是否绘制 */
|
|
96
|
+
set enabled(value) {
|
|
97
|
+
if (value === this._enabled) return;
|
|
98
|
+
this.assertActive();
|
|
99
|
+
this._enabled = value;
|
|
100
|
+
this.notify("style");
|
|
101
|
+
}
|
|
102
|
+
/** @param subscriber 接收下一帧更新通知的管理者 */
|
|
103
|
+
add(subscriber) {
|
|
104
|
+
this.assertActive();
|
|
105
|
+
this._subscribers.add(subscriber);
|
|
106
|
+
}
|
|
107
|
+
/** @param subscriber 解除关联的管理者 */
|
|
108
|
+
delete(subscriber) {
|
|
109
|
+
this._subscribers.delete(subscriber);
|
|
110
|
+
}
|
|
111
|
+
/** @param source 数学对象 @param field 关联字段 */
|
|
112
|
+
onMathChange(source, field) {
|
|
113
|
+
if (field === "position" && source === this._position || field === "scale" && source === this._scale) this.notify("matrix");
|
|
114
|
+
}
|
|
115
|
+
/** @param change 样式变化,图片像素变化不重打包数值 */
|
|
116
|
+
onStyleChange(change) {
|
|
117
|
+
if (change.source !== this._style) return;
|
|
118
|
+
const field = change.field;
|
|
119
|
+
this.notify(field === "texture" ? "texture" : field === "textureData" ? "textureData" : field === "addressModeU" || field === "addressModeV" ? "sampler" : "style");
|
|
120
|
+
}
|
|
121
|
+
/** 解绑原始对象;不销毁共享 Vec2、Style 或 Texture。 */
|
|
122
|
+
dispose() {
|
|
123
|
+
this._position.delete(this, "position");
|
|
124
|
+
this._scale.delete(this, "scale");
|
|
125
|
+
this._style.delete(this);
|
|
126
|
+
this._subscribers.clear();
|
|
127
|
+
this._disposed = true;
|
|
128
|
+
}
|
|
129
|
+
/** 防止已解绑的记录重新产生部分关联。 */
|
|
130
|
+
assertActive() {
|
|
131
|
+
if (this._disposed) throw new Error("Disposed Raw cannot be reused.");
|
|
132
|
+
}
|
|
133
|
+
/** @param change 本次需要重新打包的区域 */
|
|
134
|
+
notify(change) {
|
|
135
|
+
if (this._disposed) return;
|
|
136
|
+
this._version++;
|
|
137
|
+
for (const subscriber of this._subscribers) subscriber.onRawChange(this, change);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
/** 由 IMesh 持有的原始记录索引;外部使用 map.get(id) 后修改记录,不直接增删 Map。 */
|
|
141
|
+
var Raws = class {
|
|
142
|
+
_map = /* @__PURE__ */ new Map();
|
|
143
|
+
/** 只读 Map,避免外部删除记录后遗留订阅或数组空洞。 */
|
|
144
|
+
get map() {
|
|
145
|
+
return this._map;
|
|
146
|
+
}
|
|
147
|
+
/** 记录数量,raw=false 时始终为 0。 */
|
|
148
|
+
get size() {
|
|
149
|
+
return this._map.size;
|
|
150
|
+
}
|
|
151
|
+
/** @param raw 由 IMesh 创建的记录 @internal */
|
|
152
|
+
add(raw) {
|
|
153
|
+
this._map.set(raw.id, raw);
|
|
154
|
+
}
|
|
155
|
+
/** 由 IMesh.clear / dispose 调用,解除全部订阅。 @internal */
|
|
156
|
+
clear() {
|
|
157
|
+
for (const raw of this._map.values()) raw.dispose();
|
|
158
|
+
this._map.clear();
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
//#endregion
|
|
162
|
+
export { Raw, Raws as default };
|
|
163
|
+
|
|
164
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/scripts/Raws/index.ts"],"sourcesContent":["import { Vec2 } from \"bpmatrixjs/Math\";\nimport type { MathSubscriber, VersionedMath } from \"bpmatrixjs/Math\";\nimport { GETID } from \"../ID\";\nimport Style from \"../Style\";\nimport type { StyleChange, StyleSubscriber } from \"../Style\";\n\n/** push / updateAt 使用的完整快照;省略项分别为原点、0、单位缩放和默认样式。 */\nexport interface RawOptions {\n position?: Vec2;\n rotation?: number;\n scale?: Vec2;\n style?: Style;\n enabled?: boolean;\n}\n\n/** 原始值变化的影响范围,版本仍只有 Raw.version 一个。 */\nexport type RawChange = \"matrix\" | \"style\" | \"texture\" | \"textureData\" | \"sampler\";\n\n/** 原始值管理者,不在回调内分配 GPU 资源。 */\nexport interface RawSubscriber {\n onRawChange(raw: Raw, change: RawChange): void;\n}\n\n/** 一条实例原始记录;id 稳定,index 对应连续数组中的槽位。 */\nexport class Raw implements MathSubscriber, StyleSubscriber {\n /** 全局唯一 ID,不随扩容改变。 */\n public readonly id: number = GETID();\n /** 连续数组槽位,不是字节偏移。 */\n public readonly index: number;\n private _position: Vec2;\n private _rotation: number;\n private _scale: Vec2;\n private _style: Style;\n private _enabled: boolean;\n private _version: number = 0;\n private readonly _subscribers = new Set<RawSubscriber>();\n private _disposed: boolean = false;\n\n /**\n * @param index 槽位\n * @param options 原始值,不复制 Vec2 / Style,允许共享并接收通知\n */\n public constructor(index: number, options: RawOptions = {}) {\n if (!Number.isSafeInteger(index) || index < 0) throw new RangeError(\"Invalid raw index.\");\n this.index = index;\n this._position = options.position ?? new Vec2();\n this._rotation = options.rotation ?? 0;\n this._scale = options.scale ?? new Vec2(1, 1);\n this._style = options.style ?? new Style();\n this._enabled = options.enabled ?? true;\n if (!Number.isFinite(this._rotation)) throw new RangeError(\"Rotation must be finite.\");\n this._position.add(this, \"position\");\n this._scale.add(this, \"scale\");\n this._style.add(this);\n }\n\n /** 任意原始值变化时递增;打包或扩容不会改变这个版本。 */\n public get version(): number { return this._version; }\n /** 相对于 IMesh 的位置。 */\n public get position(): Vec2 { return this._position; }\n /** @param value 位置引用,旧引用解除关联 */\n public set position(value: Vec2) {\n if (value === this._position) return;\n this.assertActive();\n this._position.delete(this, \"position\");\n this._position = value;\n value.add(this, \"position\");\n this.notify(\"matrix\");\n }\n /** 局部旋转弧度。 */\n public get rotation(): number { return this._rotation; }\n /** @param value 有限弧度 */\n public set rotation(value: number) {\n if (!Number.isFinite(value)) throw new RangeError(\"Rotation must be finite.\");\n if (value === this._rotation) return;\n this.assertActive();\n this._rotation = value;\n this.notify(\"matrix\");\n }\n /** 局部缩放。 */\n public get scale(): Vec2 { return this._scale; }\n /** @param value 缩放引用 */\n public set scale(value: Vec2) {\n if (value === this._scale) return;\n this.assertActive();\n this._scale.delete(this, \"scale\");\n this._scale = value;\n value.add(this, \"scale\");\n this.notify(\"matrix\");\n }\n /** 本条记录的独立样式,不覆盖共享 Geometry / Material.style。 */\n public get style(): Style { return this._style; }\n /** @param value 新样式引用 */\n public set style(value: Style) {\n if (value === this._style) return;\n this.assertActive();\n this._style.delete(this);\n this._style = value;\n value.add(this);\n this.notify(\"texture\");\n }\n /** 是否绘制此槽位;关闭不删除记录或移动其他 index。 */\n public get enabled(): boolean { return this._enabled; }\n /** @param value 是否绘制 */\n public set enabled(value: boolean) {\n if (value === this._enabled) return;\n this.assertActive();\n this._enabled = value;\n this.notify(\"style\");\n }\n /** @param subscriber 接收下一帧更新通知的管理者 */\n public add(subscriber: RawSubscriber): void { this.assertActive(); this._subscribers.add(subscriber); }\n /** @param subscriber 解除关联的管理者 */\n public delete(subscriber: RawSubscriber): void { this._subscribers.delete(subscriber); }\n /** @param source 数学对象 @param field 关联字段 */\n public onMathChange(source: VersionedMath, field: string): void {\n if ((field === \"position\" && source === this._position) || (field === \"scale\" && source === this._scale)) this.notify(\"matrix\");\n }\n /** @param change 样式变化,图片像素变化不重打包数值 */\n public onStyleChange(change: StyleChange): void {\n if (change.source !== this._style) return;\n const field = change.field;\n this.notify(field === \"texture\" ? \"texture\" : field === \"textureData\" ? \"textureData\"\n : field === \"addressModeU\" || field === \"addressModeV\" ? \"sampler\" : \"style\");\n }\n /** 解绑原始对象;不销毁共享 Vec2、Style 或 Texture。 */\n public dispose(): void {\n this._position.delete(this, \"position\");\n this._scale.delete(this, \"scale\");\n this._style.delete(this);\n this._subscribers.clear();\n this._disposed = true;\n }\n /** 防止已解绑的记录重新产生部分关联。 */\n private assertActive(): void {\n if (this._disposed) throw new Error(\"Disposed Raw cannot be reused.\");\n }\n /** @param change 本次需要重新打包的区域 */\n private notify(change: RawChange): void {\n if (this._disposed) return;\n this._version++;\n for (const subscriber of this._subscribers) subscriber.onRawChange(this, change);\n }\n}\n\n/** 由 IMesh 持有的原始记录索引;外部使用 map.get(id) 后修改记录,不直接增删 Map。 */\nclass Raws {\n private readonly _map = new Map<number, Raw>();\n /** 只读 Map,避免外部删除记录后遗留订阅或数组空洞。 */\n public get map(): ReadonlyMap<number, Raw> { return this._map; }\n /** 记录数量,raw=false 时始终为 0。 */\n public get size(): number { return this._map.size; }\n /** @param raw 由 IMesh 创建的记录 @internal */\n public add(raw: Raw): void { this._map.set(raw.id, raw); }\n /** 由 IMesh.clear / dispose 调用,解除全部订阅。 @internal */\n public clear(): void {\n for (const raw of this._map.values()) raw.dispose();\n this._map.clear();\n }\n}\n\nexport default Raws;\n"],"mappings":";;;;;AAwBA,IAAa,MAAb,MAA4D;;CAExD,KAA6B,MAAM;;CAEnC;CACA;CACA;CACA;CACA;CACA;CACA,WAA2B;CAC3B,+B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;EACL,KAAK,MAAM,cAAc,KAAK,cAAc,WAAW,YAAY,MAAM,MAAM;CACnF;AACJ;;AAGA,IAAM,OAAN,MAAW;CACP,uBAAwB,IAAI,IAAiB;;CAE7C,IAAW,MAAgC;EAAE,OAAO,KAAK;CAAM;;CAE/D,IAAW,OAAe;EAAE,OAAO,KAAK,KAAK;CAAM;;CAEnD,IAAW,KAAgB;EAAE,KAAK,KAAK,IAAI,IAAI,IAAI,GAAG;CAAG;;CAEzD,QAAqB;EACjB,KAAK,MAAM,OAAO,KAAK,KAAK,OAAO,GAAG,IAAI,QAAQ;EAClD,KAAK,KAAK,MAAM;CACpB;AACJ"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type Camera from "../Camera";
|
|
2
|
+
import type Scene from "../Scene";
|
|
3
|
+
import type { PipelineLike, RenderMode } from "./types";
|
|
4
|
+
interface BufferManagerLike {
|
|
5
|
+
draw(scene: Scene, camera: Camera, dpr: number, renderMode: RenderMode): void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 管理当前 Render 对应的 Camera、Material、Mesh 和 Geometry GPUBuffer。
|
|
9
|
+
* @class
|
|
10
|
+
*/
|
|
11
|
+
declare class BufferManager implements BufferManagerLike {
|
|
12
|
+
private readonly pipeline;
|
|
13
|
+
private readonly depthManager;
|
|
14
|
+
private readonly developmentValidator;
|
|
15
|
+
private _cameraSnapshot;
|
|
16
|
+
private readonly _validatedMaterials;
|
|
17
|
+
/**
|
|
18
|
+
* 创建缓冲管理器。
|
|
19
|
+
* @param pipeline 当前 Render 的共享管线资源
|
|
20
|
+
*/
|
|
21
|
+
constructor(pipeline: PipelineLike);
|
|
22
|
+
/**
|
|
23
|
+
* 创建或更新当前场景需要的 GPUBuffer。
|
|
24
|
+
* @param scene 场景对象
|
|
25
|
+
* @param camera 相机对象
|
|
26
|
+
* @param dpr 当前设备像素比
|
|
27
|
+
* @param renderMode 当前 Render 运行模式
|
|
28
|
+
* @returns 无返回值
|
|
29
|
+
*/
|
|
30
|
+
draw(scene: Scene, camera: Camera, dpr: number, renderMode: RenderMode): void;
|
|
31
|
+
/**
|
|
32
|
+
* 按 materialList 检查材质,共享材质每个版本只检查一次。
|
|
33
|
+
* 材质显示数值的 GPU 存储属于 Mesh 实例数组,不在这里重复创建一份缓冲。
|
|
34
|
+
* @param scene 场景对象
|
|
35
|
+
* @param renderMode production 跳过开发检查
|
|
36
|
+
*/
|
|
37
|
+
private prepareMaterials;
|
|
38
|
+
/**
|
|
39
|
+
* 创建并写入基础 GPUBuffer。
|
|
40
|
+
* @param device 当前 Render 对应的 WebGPU 设备
|
|
41
|
+
* @param label GPU 调试标签
|
|
42
|
+
* @param data 首次写入的缓冲数据
|
|
43
|
+
* @param usage 缓冲用途标记
|
|
44
|
+
* @returns 已写入数据的 GPUBuffer
|
|
45
|
+
*/
|
|
46
|
+
private createBuffer;
|
|
47
|
+
/**
|
|
48
|
+
* 按当前 Render 自己的矩阵身份和版本快照上传相机数据。
|
|
49
|
+
* @param device WebGPU 设备
|
|
50
|
+
* @param camera 相机对象
|
|
51
|
+
* @param dpr 设备像素比
|
|
52
|
+
*/
|
|
53
|
+
private drawCameraBuffers;
|
|
54
|
+
/**
|
|
55
|
+
* 创建或更新每个 Mesh 的连续矩阵与样式 Storage 数组,分别对比版本。
|
|
56
|
+
* @param device 当前 WebGPU 设备
|
|
57
|
+
* @param scene 场景对象
|
|
58
|
+
* @param renderMode 当前 Render 运行模式
|
|
59
|
+
* @returns 无返回值
|
|
60
|
+
*/
|
|
61
|
+
private drawMeshBuffers;
|
|
62
|
+
/**
|
|
63
|
+
* 为去重后的 Geometry 创建顶点、二维轮廓法线、UV、索引和参数缓冲。
|
|
64
|
+
* @param device 当前 WebGPU 设备
|
|
65
|
+
* @param scene 场景对象
|
|
66
|
+
* @param renderMode 当前 Render 运行模式
|
|
67
|
+
* @returns 无返回值
|
|
68
|
+
*/
|
|
69
|
+
private drawGeometryBuffers;
|
|
70
|
+
/**
|
|
71
|
+
* 创建单种几何绘制模式的顶点、二维轮廓法线、UV 和索引缓冲。
|
|
72
|
+
* @param device 当前 WebGPU 设备
|
|
73
|
+
* @param label GPU 调试标签前缀
|
|
74
|
+
* @param data CPU 几何数据
|
|
75
|
+
* @returns 已创建的几何缓冲分区
|
|
76
|
+
*/
|
|
77
|
+
private createGeometryBufferPart;
|
|
78
|
+
/**
|
|
79
|
+
* 获取关键点索引段起点,缓存后绘制时无需重复遍历。
|
|
80
|
+
* 原生 line-list 需要插在实体面与关键点之间时,复用同一个合并缓冲分段绘制。
|
|
81
|
+
* @param data 已按面、边框、关键点顺序合并的数据
|
|
82
|
+
* @returns 关键点索引段起点;没有关键点时等于总索引数
|
|
83
|
+
*/
|
|
84
|
+
private getPointsFirstIndex;
|
|
85
|
+
/**
|
|
86
|
+
* 销毁一个 Geometry 缓存集合中的全部已创建缓冲。
|
|
87
|
+
* @param geometryBuffer Geometry GPU 缓存集合
|
|
88
|
+
* @returns 无返回值
|
|
89
|
+
*/
|
|
90
|
+
private destroyGeometryBuffer;
|
|
91
|
+
}
|
|
92
|
+
export default BufferManager;
|
|
93
|
+
export type { BufferManagerLike };
|