bloody-engine 1.0.0 → 1.0.2
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/dist/node/index.js +2364 -0
- package/package.json +3 -2
- package/dist/node/batch-renderer-JqZ4TYcL.js +0 -308
- package/dist/node/browser-resource-loader-D51BD3k_.js +0 -146
- package/dist/node/camera-A8EGrk7U.js +0 -271
- package/dist/node/index-node.js +0 -2117
- package/dist/node/node-resource-loader-MzkD-IGo.js +0 -166
- package/dist/node/resource-loader-factory-DQ-PAVcN.js +0 -93
- package/dist/node/resource-pipeline-Dac9qRso.js +0 -211
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
class Matrix4 {
|
|
2
|
-
/**
|
|
3
|
-
* Create an identity matrix
|
|
4
|
-
* @returns 4x4 identity matrix in column-major order
|
|
5
|
-
*/
|
|
6
|
-
static identity() {
|
|
7
|
-
return new Float32Array([
|
|
8
|
-
1,
|
|
9
|
-
0,
|
|
10
|
-
0,
|
|
11
|
-
0,
|
|
12
|
-
// column 0
|
|
13
|
-
0,
|
|
14
|
-
1,
|
|
15
|
-
0,
|
|
16
|
-
0,
|
|
17
|
-
// column 1
|
|
18
|
-
0,
|
|
19
|
-
0,
|
|
20
|
-
1,
|
|
21
|
-
0,
|
|
22
|
-
// column 2
|
|
23
|
-
0,
|
|
24
|
-
0,
|
|
25
|
-
0,
|
|
26
|
-
1
|
|
27
|
-
// column 3
|
|
28
|
-
]);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Create a translation matrix
|
|
32
|
-
* @param x Translation along X axis
|
|
33
|
-
* @param y Translation along Y axis
|
|
34
|
-
* @param z Translation along Z axis (default 0)
|
|
35
|
-
* @returns 4x4 translation matrix in column-major order
|
|
36
|
-
*/
|
|
37
|
-
static translation(x, y, z = 0) {
|
|
38
|
-
return new Float32Array([
|
|
39
|
-
1,
|
|
40
|
-
0,
|
|
41
|
-
0,
|
|
42
|
-
0,
|
|
43
|
-
// column 0
|
|
44
|
-
0,
|
|
45
|
-
1,
|
|
46
|
-
0,
|
|
47
|
-
0,
|
|
48
|
-
// column 1
|
|
49
|
-
0,
|
|
50
|
-
0,
|
|
51
|
-
1,
|
|
52
|
-
0,
|
|
53
|
-
// column 2
|
|
54
|
-
x,
|
|
55
|
-
y,
|
|
56
|
-
z,
|
|
57
|
-
1
|
|
58
|
-
// column 3
|
|
59
|
-
]);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Create a scale matrix
|
|
63
|
-
* @param x Scale factor along X axis
|
|
64
|
-
* @param y Scale factor along Y axis
|
|
65
|
-
* @param z Scale factor along Z axis (default 1)
|
|
66
|
-
* @returns 4x4 scale matrix in column-major order
|
|
67
|
-
*/
|
|
68
|
-
static scale(x, y, z = 1) {
|
|
69
|
-
return new Float32Array([
|
|
70
|
-
x,
|
|
71
|
-
0,
|
|
72
|
-
0,
|
|
73
|
-
0,
|
|
74
|
-
// column 0
|
|
75
|
-
0,
|
|
76
|
-
y,
|
|
77
|
-
0,
|
|
78
|
-
0,
|
|
79
|
-
// column 1
|
|
80
|
-
0,
|
|
81
|
-
0,
|
|
82
|
-
z,
|
|
83
|
-
0,
|
|
84
|
-
// column 2
|
|
85
|
-
0,
|
|
86
|
-
0,
|
|
87
|
-
0,
|
|
88
|
-
1
|
|
89
|
-
// column 3
|
|
90
|
-
]);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Multiply two matrices (result = a * b)
|
|
94
|
-
* @param a First matrix (left operand)
|
|
95
|
-
* @param b Second matrix (right operand)
|
|
96
|
-
* @returns Result of matrix multiplication in column-major order
|
|
97
|
-
*/
|
|
98
|
-
static multiply(a, b) {
|
|
99
|
-
const result = new Float32Array(16);
|
|
100
|
-
for (let col = 0; col < 4; col++) {
|
|
101
|
-
for (let row = 0; row < 4; row++) {
|
|
102
|
-
let sum = 0;
|
|
103
|
-
for (let k = 0; k < 4; k++) {
|
|
104
|
-
sum += a[k * 4 + row] * b[col * 4 + k];
|
|
105
|
-
}
|
|
106
|
-
result[col * 4 + row] = sum;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return result;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Create a view matrix from camera position and zoom
|
|
113
|
-
* The view matrix transforms world coordinates to camera/eye coordinates
|
|
114
|
-
*
|
|
115
|
-
* View = Translation(-cameraX, -cameraY, 0) * Scale(zoom, zoom, 1)
|
|
116
|
-
*
|
|
117
|
-
* @param x Camera X position (translation will be negative)
|
|
118
|
-
* @param y Camera Y position (translation will be negative)
|
|
119
|
-
* @param zoom Camera zoom level (1.0 = no zoom, >1 = zoom in, <1 = zoom out)
|
|
120
|
-
* @returns 4x4 view matrix in column-major order
|
|
121
|
-
*/
|
|
122
|
-
static createViewMatrix(x, y, zoom) {
|
|
123
|
-
const translation = Matrix4.translation(-x, -y, 0);
|
|
124
|
-
const scale = Matrix4.scale(zoom, zoom, 1);
|
|
125
|
-
return Matrix4.multiply(translation, scale);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
class Camera {
|
|
129
|
-
/**
|
|
130
|
-
* Create a new camera
|
|
131
|
-
* @param x Initial X position (default 0)
|
|
132
|
-
* @param y Initial Y position (default 0)
|
|
133
|
-
* @param zoom Initial zoom level (default 1.0)
|
|
134
|
-
*/
|
|
135
|
-
constructor(x = 0, y = 0, zoom = 1) {
|
|
136
|
-
this._viewMatrix = null;
|
|
137
|
-
this._viewMatrixDirty = true;
|
|
138
|
-
this._x = x;
|
|
139
|
-
this._y = y;
|
|
140
|
-
this._zoom = zoom;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Get the camera X position
|
|
144
|
-
*/
|
|
145
|
-
get x() {
|
|
146
|
-
return this._x;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Set the camera X position
|
|
150
|
-
*/
|
|
151
|
-
set x(value) {
|
|
152
|
-
this._x = value;
|
|
153
|
-
this._viewMatrixDirty = true;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Get the camera Y position
|
|
157
|
-
*/
|
|
158
|
-
get y() {
|
|
159
|
-
return this._y;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Set the camera Y position
|
|
163
|
-
*/
|
|
164
|
-
set y(value) {
|
|
165
|
-
this._y = value;
|
|
166
|
-
this._viewMatrixDirty = true;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Get the camera zoom level
|
|
170
|
-
*/
|
|
171
|
-
get zoom() {
|
|
172
|
-
return this._zoom;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Set the camera zoom level
|
|
176
|
-
* Values: 1.0 = no zoom, >1 = zoom in, <1 = zoom out
|
|
177
|
-
*/
|
|
178
|
-
set zoom(value) {
|
|
179
|
-
this._zoom = Math.max(1e-3, value);
|
|
180
|
-
this._viewMatrixDirty = true;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Set both X and Y position at once
|
|
184
|
-
* @param x New X position
|
|
185
|
-
* @param y New Y position
|
|
186
|
-
*/
|
|
187
|
-
setPosition(x, y) {
|
|
188
|
-
this._x = x;
|
|
189
|
-
this._y = y;
|
|
190
|
-
this._viewMatrixDirty = true;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Move the camera by a relative offset
|
|
194
|
-
* @param dx X offset to add to current position
|
|
195
|
-
* @param dy Y offset to add to current position
|
|
196
|
-
*/
|
|
197
|
-
move(dx, dy) {
|
|
198
|
-
this._x += dx;
|
|
199
|
-
this._y += dy;
|
|
200
|
-
this._viewMatrixDirty = true;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Scale the zoom by a factor
|
|
204
|
-
* @param factor Multiplier for current zoom (e.g., 1.1 to zoom in 10%)
|
|
205
|
-
*/
|
|
206
|
-
zoomBy(factor) {
|
|
207
|
-
this._zoom = Math.max(1e-3, this._zoom * factor);
|
|
208
|
-
this._viewMatrixDirty = true;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Reset camera to default position and zoom
|
|
212
|
-
*/
|
|
213
|
-
reset() {
|
|
214
|
-
this._x = 0;
|
|
215
|
-
this._y = 0;
|
|
216
|
-
this._zoom = 1;
|
|
217
|
-
this._viewMatrixDirty = true;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Get the view matrix for this camera
|
|
221
|
-
* The view matrix transforms world coordinates to camera space
|
|
222
|
-
* Caches the result until camera properties change
|
|
223
|
-
*
|
|
224
|
-
* @returns 4x4 view matrix in column-major order
|
|
225
|
-
*/
|
|
226
|
-
getViewMatrix() {
|
|
227
|
-
if (this._viewMatrixDirty || this._viewMatrix === null) {
|
|
228
|
-
this._viewMatrix = Matrix4.createViewMatrix(this._x, this._y, this._zoom);
|
|
229
|
-
this._viewMatrixDirty = false;
|
|
230
|
-
}
|
|
231
|
-
return this._viewMatrix;
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Convert screen coordinates to world coordinates
|
|
235
|
-
* Useful for mouse picking and interaction
|
|
236
|
-
*
|
|
237
|
-
* @param screenX Screen X coordinate (pixels)
|
|
238
|
-
* @param screenY Screen Y coordinate (pixels)
|
|
239
|
-
* @param viewportWidth Viewport width in pixels
|
|
240
|
-
* @param viewportHeight Viewport height in pixels
|
|
241
|
-
* @returns World coordinates {x, y}
|
|
242
|
-
*/
|
|
243
|
-
screenToWorld(screenX, screenY, viewportWidth, viewportHeight) {
|
|
244
|
-
const centeredX = screenX - viewportWidth / 2;
|
|
245
|
-
const centeredY = screenY - viewportHeight / 2;
|
|
246
|
-
const worldX = centeredX / this._zoom + this._x;
|
|
247
|
-
const worldY = centeredY / this._zoom + this._y;
|
|
248
|
-
return { x: worldX, y: worldY };
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Convert world coordinates to screen coordinates
|
|
252
|
-
* Useful for UI positioning and debug rendering
|
|
253
|
-
*
|
|
254
|
-
* @param worldX World X coordinate
|
|
255
|
-
* @param worldY World Y coordinate
|
|
256
|
-
* @param viewportWidth Viewport width in pixels
|
|
257
|
-
* @param viewportHeight Viewport height in pixels
|
|
258
|
-
* @returns Screen coordinates {x, y} in pixels
|
|
259
|
-
*/
|
|
260
|
-
worldToScreen(worldX, worldY, viewportWidth, viewportHeight) {
|
|
261
|
-
const centeredX = (worldX - this._x) * this._zoom;
|
|
262
|
-
const centeredY = (worldY - this._y) * this._zoom;
|
|
263
|
-
const screenX = centeredX + viewportWidth / 2;
|
|
264
|
-
const screenY = centeredY + viewportHeight / 2;
|
|
265
|
-
return { x: screenX, y: screenY };
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
export {
|
|
269
|
-
Camera,
|
|
270
|
-
Matrix4
|
|
271
|
-
};
|