@zylem/game-lib 0.5.1 → 0.6.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/behaviors.d.ts +834 -88
- package/dist/behaviors.js +1166 -355
- package/dist/behaviors.js.map +1 -1
- package/dist/blueprints-Cq3Ko6_G.d.ts +26 -0
- package/dist/{camera-Dk-fOVZE.d.ts → camera-CeJPAgGg.d.ts} +20 -46
- package/dist/camera.d.ts +2 -2
- package/dist/camera.js +340 -129
- package/dist/camera.js.map +1 -1
- package/dist/{core-C2mjetAd.d.ts → core-bO8TzV7u.d.ts} +113 -44
- package/dist/core.d.ts +8 -5
- package/dist/core.js +6180 -3678
- package/dist/core.js.map +1 -1
- package/dist/entities-DvByhMGU.d.ts +306 -0
- package/dist/entities.d.ts +5 -267
- package/dist/entities.js +3239 -1893
- package/dist/entities.js.map +1 -1
- package/dist/entity-Bq_eNEDI.d.ts +28 -0
- package/dist/entity-types-DAu8sGJH.d.ts +26 -0
- package/dist/main.d.ts +147 -31
- package/dist/main.js +9364 -5479
- package/dist/main.js.map +1 -1
- package/dist/{stage-CrmY7V0i.d.ts → stage-types-Bd-KtcYT.d.ts} +149 -61
- package/dist/stage.d.ts +42 -20
- package/dist/stage.js +4103 -2027
- package/dist/stage.js.map +1 -1
- package/dist/world-C8tQ7Plj.d.ts +774 -0
- package/package.json +2 -1
- package/dist/entity-bQElAdpo.d.ts +0 -347
- package/dist/entity-spawner-DNnLYnZq.d.ts +0 -11
package/dist/camera.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// src/lib/camera/camera.ts
|
|
2
|
-
import { Vector2 as Vector23, Vector3 as
|
|
2
|
+
import { Vector2 as Vector23, Vector3 as Vector34 } from "three";
|
|
3
3
|
|
|
4
4
|
// src/lib/camera/zylem-camera.ts
|
|
5
|
-
import { PerspectiveCamera, Vector3 as
|
|
6
|
-
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
|
|
5
|
+
import { PerspectiveCamera, Vector3 as Vector33, Object3D as Object3D2, OrthographicCamera, WebGLRenderer as WebGLRenderer3 } from "three";
|
|
7
6
|
|
|
8
7
|
// src/lib/camera/perspective.ts
|
|
9
8
|
var Perspectives = {
|
|
@@ -29,11 +28,11 @@ var ThirdPersonCamera = class {
|
|
|
29
28
|
* Setup the third person camera controller
|
|
30
29
|
*/
|
|
31
30
|
setup(params) {
|
|
32
|
-
const { screenResolution, renderer, scene, camera
|
|
31
|
+
const { screenResolution, renderer, scene, camera } = params;
|
|
33
32
|
this.screenResolution = screenResolution;
|
|
34
33
|
this.renderer = renderer;
|
|
35
34
|
this.scene = scene;
|
|
36
|
-
this.cameraRef =
|
|
35
|
+
this.cameraRef = camera;
|
|
37
36
|
}
|
|
38
37
|
/**
|
|
39
38
|
* Update the third person camera
|
|
@@ -74,11 +73,11 @@ var Fixed2DCamera = class {
|
|
|
74
73
|
* Setup the fixed 2D camera controller
|
|
75
74
|
*/
|
|
76
75
|
setup(params) {
|
|
77
|
-
const { screenResolution, renderer, scene, camera
|
|
76
|
+
const { screenResolution, renderer, scene, camera } = params;
|
|
78
77
|
this.screenResolution = screenResolution;
|
|
79
78
|
this.renderer = renderer;
|
|
80
79
|
this.scene = scene;
|
|
81
|
-
this.cameraRef =
|
|
80
|
+
this.cameraRef = camera;
|
|
82
81
|
this.cameraRef.camera.position.set(0, 0, 10);
|
|
83
82
|
this.cameraRef.camera.lookAt(0, 0, 0);
|
|
84
83
|
}
|
|
@@ -104,11 +103,33 @@ import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer
|
|
|
104
103
|
// src/lib/graphics/render-pass.ts
|
|
105
104
|
import * as THREE from "three";
|
|
106
105
|
|
|
107
|
-
// src/lib/graphics/shaders/
|
|
108
|
-
var
|
|
106
|
+
// src/lib/graphics/shaders/vertex/object.shader.ts
|
|
107
|
+
var objectVertexShader = `
|
|
108
|
+
uniform vec2 uvScale;
|
|
109
|
+
varying vec2 vUv;
|
|
110
|
+
|
|
111
|
+
void main() {
|
|
112
|
+
vUv = uv;
|
|
113
|
+
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
|
|
114
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
115
|
+
}
|
|
116
|
+
`;
|
|
109
117
|
|
|
110
|
-
// src/lib/graphics/shaders/
|
|
111
|
-
var
|
|
118
|
+
// src/lib/graphics/shaders/standard.shader.ts
|
|
119
|
+
var fragment = `
|
|
120
|
+
uniform sampler2D tDiffuse;
|
|
121
|
+
varying vec2 vUv;
|
|
122
|
+
|
|
123
|
+
void main() {
|
|
124
|
+
vec4 texel = texture2D( tDiffuse, vUv );
|
|
125
|
+
|
|
126
|
+
gl_FragColor = texel;
|
|
127
|
+
}
|
|
128
|
+
`;
|
|
129
|
+
var standardShader = {
|
|
130
|
+
vertex: objectVertexShader,
|
|
131
|
+
fragment
|
|
132
|
+
};
|
|
112
133
|
|
|
113
134
|
// src/lib/graphics/render-pass.ts
|
|
114
135
|
import { WebGLRenderTarget } from "three";
|
|
@@ -121,12 +142,12 @@ var RenderPass = class extends Pass {
|
|
|
121
142
|
rgbRenderTarget;
|
|
122
143
|
normalRenderTarget;
|
|
123
144
|
normalMaterial;
|
|
124
|
-
constructor(resolution, scene,
|
|
145
|
+
constructor(resolution, scene, camera) {
|
|
125
146
|
super();
|
|
126
147
|
this.resolution = resolution;
|
|
127
148
|
this.fsQuad = new FullScreenQuad(this.material());
|
|
128
149
|
this.scene = scene;
|
|
129
|
-
this.camera =
|
|
150
|
+
this.camera = camera;
|
|
130
151
|
this.rgbRenderTarget = new WebGLRenderTarget(resolution.x * 4, resolution.y * 4);
|
|
131
152
|
this.normalRenderTarget = new WebGLRenderTarget(resolution.x * 4, resolution.y * 4);
|
|
132
153
|
this.normalMaterial = new THREE.MeshNormalMaterial();
|
|
@@ -167,8 +188,8 @@ var RenderPass = class extends Pass {
|
|
|
167
188
|
)
|
|
168
189
|
}
|
|
169
190
|
},
|
|
170
|
-
vertexShader:
|
|
171
|
-
fragmentShader:
|
|
191
|
+
vertexShader: standardShader.vertex,
|
|
192
|
+
fragmentShader: standardShader.fragment
|
|
172
193
|
});
|
|
173
194
|
}
|
|
174
195
|
dispose() {
|
|
@@ -188,25 +209,275 @@ var RenderPass = class extends Pass {
|
|
|
188
209
|
}
|
|
189
210
|
};
|
|
190
211
|
|
|
212
|
+
// src/lib/camera/camera-debug-delegate.ts
|
|
213
|
+
import { Vector3 as Vector32 } from "three";
|
|
214
|
+
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
|
|
215
|
+
var CameraOrbitController = class {
|
|
216
|
+
camera;
|
|
217
|
+
domElement;
|
|
218
|
+
cameraRig = null;
|
|
219
|
+
sceneRef = null;
|
|
220
|
+
orbitControls = null;
|
|
221
|
+
orbitTarget = null;
|
|
222
|
+
orbitTargetWorldPos = new Vector32();
|
|
223
|
+
debugDelegate = null;
|
|
224
|
+
debugUnsubscribe = null;
|
|
225
|
+
debugStateSnapshot = { enabled: false, selected: [] };
|
|
226
|
+
// Saved camera state for restoration when exiting debug mode
|
|
227
|
+
savedCameraPosition = null;
|
|
228
|
+
savedCameraQuaternion = null;
|
|
229
|
+
savedCameraZoom = null;
|
|
230
|
+
savedCameraLocalPosition = null;
|
|
231
|
+
// Saved debug camera state for restoration when re-entering debug mode
|
|
232
|
+
savedDebugCameraPosition = null;
|
|
233
|
+
savedDebugCameraQuaternion = null;
|
|
234
|
+
savedDebugCameraZoom = null;
|
|
235
|
+
savedDebugOrbitTarget = null;
|
|
236
|
+
constructor(camera, domElement, cameraRig) {
|
|
237
|
+
this.camera = camera;
|
|
238
|
+
this.domElement = domElement;
|
|
239
|
+
this.cameraRig = cameraRig ?? null;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Set the scene reference for adding/removing camera when detaching from rig.
|
|
243
|
+
*/
|
|
244
|
+
setScene(scene) {
|
|
245
|
+
this.sceneRef = scene;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Check if debug mode is currently active (orbit controls enabled).
|
|
249
|
+
*/
|
|
250
|
+
get isActive() {
|
|
251
|
+
return this.debugStateSnapshot.enabled;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Update orbit controls each frame.
|
|
255
|
+
* Should be called from the camera's update loop.
|
|
256
|
+
*/
|
|
257
|
+
update() {
|
|
258
|
+
if (this.orbitControls && this.orbitTarget) {
|
|
259
|
+
this.orbitTarget.getWorldPosition(this.orbitTargetWorldPos);
|
|
260
|
+
this.orbitControls.target.copy(this.orbitTargetWorldPos);
|
|
261
|
+
}
|
|
262
|
+
this.orbitControls?.update();
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Attach a delegate to react to debug state changes.
|
|
266
|
+
*/
|
|
267
|
+
setDebugDelegate(delegate) {
|
|
268
|
+
if (this.debugDelegate === delegate) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
this.detachDebugDelegate();
|
|
272
|
+
this.debugDelegate = delegate;
|
|
273
|
+
if (!delegate) {
|
|
274
|
+
this.applyDebugState({ enabled: false, selected: [] });
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const unsubscribe = delegate.subscribe((state) => {
|
|
278
|
+
this.applyDebugState(state);
|
|
279
|
+
});
|
|
280
|
+
this.debugUnsubscribe = () => {
|
|
281
|
+
unsubscribe?.();
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Clean up resources.
|
|
286
|
+
*/
|
|
287
|
+
dispose() {
|
|
288
|
+
this.disableOrbitControls();
|
|
289
|
+
this.detachDebugDelegate();
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Get the current debug state snapshot.
|
|
293
|
+
*/
|
|
294
|
+
get debugState() {
|
|
295
|
+
return this.debugStateSnapshot;
|
|
296
|
+
}
|
|
297
|
+
applyDebugState(state) {
|
|
298
|
+
const wasEnabled = this.debugStateSnapshot.enabled;
|
|
299
|
+
this.debugStateSnapshot = {
|
|
300
|
+
enabled: state.enabled,
|
|
301
|
+
selected: [...state.selected]
|
|
302
|
+
};
|
|
303
|
+
if (state.enabled && !wasEnabled) {
|
|
304
|
+
this.saveCameraState();
|
|
305
|
+
this.detachCameraFromRig();
|
|
306
|
+
this.enableOrbitControls();
|
|
307
|
+
this.restoreDebugCameraState();
|
|
308
|
+
this.updateOrbitTargetFromSelection(state.selected);
|
|
309
|
+
} else if (!state.enabled && wasEnabled) {
|
|
310
|
+
this.saveDebugCameraState();
|
|
311
|
+
this.orbitTarget = null;
|
|
312
|
+
this.disableOrbitControls();
|
|
313
|
+
this.reattachCameraToRig();
|
|
314
|
+
this.restoreCameraState();
|
|
315
|
+
} else if (state.enabled) {
|
|
316
|
+
this.updateOrbitTargetFromSelection(state.selected);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
enableOrbitControls() {
|
|
320
|
+
if (this.orbitControls) {
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
this.orbitControls = new OrbitControls(this.camera, this.domElement);
|
|
324
|
+
this.orbitControls.enableDamping = true;
|
|
325
|
+
this.orbitControls.dampingFactor = 0.05;
|
|
326
|
+
this.orbitControls.screenSpacePanning = false;
|
|
327
|
+
this.orbitControls.minDistance = 1;
|
|
328
|
+
this.orbitControls.maxDistance = 500;
|
|
329
|
+
this.orbitControls.maxPolarAngle = Math.PI / 2;
|
|
330
|
+
this.orbitControls.target.set(0, 0, 0);
|
|
331
|
+
}
|
|
332
|
+
disableOrbitControls() {
|
|
333
|
+
if (!this.orbitControls) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
this.orbitControls.dispose();
|
|
337
|
+
this.orbitControls = null;
|
|
338
|
+
}
|
|
339
|
+
updateOrbitTargetFromSelection(selected) {
|
|
340
|
+
if (!this.debugDelegate || selected.length === 0) {
|
|
341
|
+
this.orbitTarget = null;
|
|
342
|
+
if (this.orbitControls) {
|
|
343
|
+
this.orbitControls.target.set(0, 0, 0);
|
|
344
|
+
}
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
for (let i = selected.length - 1; i >= 0; i -= 1) {
|
|
348
|
+
const uuid = selected[i];
|
|
349
|
+
const targetObject = this.debugDelegate.resolveTarget(uuid);
|
|
350
|
+
if (targetObject) {
|
|
351
|
+
this.orbitTarget = targetObject;
|
|
352
|
+
if (this.orbitControls) {
|
|
353
|
+
targetObject.getWorldPosition(this.orbitTargetWorldPos);
|
|
354
|
+
this.orbitControls.target.copy(this.orbitTargetWorldPos);
|
|
355
|
+
}
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
this.orbitTarget = null;
|
|
360
|
+
}
|
|
361
|
+
detachDebugDelegate() {
|
|
362
|
+
if (this.debugUnsubscribe) {
|
|
363
|
+
try {
|
|
364
|
+
this.debugUnsubscribe();
|
|
365
|
+
} catch {
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
this.debugUnsubscribe = null;
|
|
369
|
+
this.debugDelegate = null;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Save camera position, rotation, and zoom before entering debug mode.
|
|
373
|
+
*/
|
|
374
|
+
saveCameraState() {
|
|
375
|
+
this.savedCameraPosition = this.camera.position.clone();
|
|
376
|
+
this.savedCameraQuaternion = this.camera.quaternion.clone();
|
|
377
|
+
if ("zoom" in this.camera) {
|
|
378
|
+
this.savedCameraZoom = this.camera.zoom;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Restore camera position, rotation, and zoom when exiting debug mode.
|
|
383
|
+
*/
|
|
384
|
+
restoreCameraState() {
|
|
385
|
+
if (this.savedCameraPosition) {
|
|
386
|
+
this.camera.position.copy(this.savedCameraPosition);
|
|
387
|
+
this.savedCameraPosition = null;
|
|
388
|
+
}
|
|
389
|
+
if (this.savedCameraQuaternion) {
|
|
390
|
+
this.camera.quaternion.copy(this.savedCameraQuaternion);
|
|
391
|
+
this.savedCameraQuaternion = null;
|
|
392
|
+
}
|
|
393
|
+
if (this.savedCameraZoom !== null && "zoom" in this.camera) {
|
|
394
|
+
this.camera.zoom = this.savedCameraZoom;
|
|
395
|
+
this.camera.updateProjectionMatrix?.();
|
|
396
|
+
this.savedCameraZoom = null;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Save debug camera state when exiting debug mode.
|
|
401
|
+
*/
|
|
402
|
+
saveDebugCameraState() {
|
|
403
|
+
this.savedDebugCameraPosition = this.camera.position.clone();
|
|
404
|
+
this.savedDebugCameraQuaternion = this.camera.quaternion.clone();
|
|
405
|
+
if ("zoom" in this.camera) {
|
|
406
|
+
this.savedDebugCameraZoom = this.camera.zoom;
|
|
407
|
+
}
|
|
408
|
+
if (this.orbitControls) {
|
|
409
|
+
this.savedDebugOrbitTarget = this.orbitControls.target.clone();
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Restore debug camera state when re-entering debug mode.
|
|
414
|
+
*/
|
|
415
|
+
restoreDebugCameraState() {
|
|
416
|
+
if (this.savedDebugCameraPosition) {
|
|
417
|
+
this.camera.position.copy(this.savedDebugCameraPosition);
|
|
418
|
+
}
|
|
419
|
+
if (this.savedDebugCameraQuaternion) {
|
|
420
|
+
this.camera.quaternion.copy(this.savedDebugCameraQuaternion);
|
|
421
|
+
}
|
|
422
|
+
if (this.savedDebugCameraZoom !== null && "zoom" in this.camera) {
|
|
423
|
+
this.camera.zoom = this.savedDebugCameraZoom;
|
|
424
|
+
this.camera.updateProjectionMatrix?.();
|
|
425
|
+
}
|
|
426
|
+
if (this.savedDebugOrbitTarget && this.orbitControls) {
|
|
427
|
+
this.orbitControls.target.copy(this.savedDebugOrbitTarget);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Detach camera from its rig to allow free orbit movement in debug mode.
|
|
432
|
+
* Preserves the camera's world position.
|
|
433
|
+
*/
|
|
434
|
+
detachCameraFromRig() {
|
|
435
|
+
if (!this.cameraRig || this.camera.parent !== this.cameraRig) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
this.savedCameraLocalPosition = this.camera.position.clone();
|
|
439
|
+
const worldPos = new Vector32();
|
|
440
|
+
this.camera.getWorldPosition(worldPos);
|
|
441
|
+
this.cameraRig.remove(this.camera);
|
|
442
|
+
if (this.sceneRef) {
|
|
443
|
+
this.sceneRef.add(this.camera);
|
|
444
|
+
}
|
|
445
|
+
this.camera.position.copy(worldPos);
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Reattach camera to its rig when exiting debug mode.
|
|
449
|
+
* Restores the camera's local position relative to the rig.
|
|
450
|
+
*/
|
|
451
|
+
reattachCameraToRig() {
|
|
452
|
+
if (!this.cameraRig || this.camera.parent === this.cameraRig) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
if (this.sceneRef && this.camera.parent === this.sceneRef) {
|
|
456
|
+
this.sceneRef.remove(this.camera);
|
|
457
|
+
}
|
|
458
|
+
this.cameraRig.add(this.camera);
|
|
459
|
+
if (this.savedCameraLocalPosition) {
|
|
460
|
+
this.camera.position.copy(this.savedCameraLocalPosition);
|
|
461
|
+
this.savedCameraLocalPosition = null;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
|
|
191
466
|
// src/lib/camera/zylem-camera.ts
|
|
192
467
|
var ZylemCamera = class {
|
|
193
|
-
cameraRig;
|
|
468
|
+
cameraRig = null;
|
|
194
469
|
camera;
|
|
195
470
|
screenResolution;
|
|
196
471
|
renderer;
|
|
197
472
|
composer;
|
|
198
473
|
_perspective;
|
|
199
|
-
orbitControls = null;
|
|
200
474
|
target = null;
|
|
201
475
|
sceneRef = null;
|
|
202
476
|
frustumSize = 10;
|
|
203
477
|
// Perspective controller delegation
|
|
204
478
|
perspectiveController = null;
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
debugStateSnapshot = { enabled: false, selected: [] };
|
|
208
|
-
orbitTarget = null;
|
|
209
|
-
orbitTargetWorldPos = new Vector32();
|
|
479
|
+
// Debug/orbit controls delegation
|
|
480
|
+
orbitController = null;
|
|
210
481
|
constructor(perspective, screenResolution, frustumSize = 10) {
|
|
211
482
|
this._perspective = perspective;
|
|
212
483
|
this.screenResolution = screenResolution;
|
|
@@ -217,26 +488,23 @@ var ZylemCamera = class {
|
|
|
217
488
|
this.composer = new EffectComposer(this.renderer);
|
|
218
489
|
const aspectRatio = screenResolution.x / screenResolution.y;
|
|
219
490
|
this.camera = this.createCameraForPerspective(aspectRatio);
|
|
220
|
-
this.
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
491
|
+
if (this.needsRig()) {
|
|
492
|
+
this.cameraRig = new Object3D2();
|
|
493
|
+
this.cameraRig.position.set(0, 3, 10);
|
|
494
|
+
this.cameraRig.add(this.camera);
|
|
495
|
+
this.camera.lookAt(new Vector33(0, 2, 0));
|
|
496
|
+
} else {
|
|
497
|
+
this.camera.position.set(0, 0, 10);
|
|
498
|
+
this.camera.lookAt(new Vector33(0, 0, 0));
|
|
499
|
+
}
|
|
224
500
|
this.initializePerspectiveController();
|
|
501
|
+
this.orbitController = new CameraOrbitController(this.camera, this.renderer.domElement, this.cameraRig);
|
|
225
502
|
}
|
|
226
503
|
/**
|
|
227
504
|
* Setup the camera with a scene
|
|
228
505
|
*/
|
|
229
506
|
async setup(scene) {
|
|
230
507
|
this.sceneRef = scene;
|
|
231
|
-
if (this.orbitControls === null) {
|
|
232
|
-
this.orbitControls = new OrbitControls(this.camera, this.renderer.domElement);
|
|
233
|
-
this.orbitControls.enableDamping = true;
|
|
234
|
-
this.orbitControls.dampingFactor = 0.05;
|
|
235
|
-
this.orbitControls.screenSpacePanning = false;
|
|
236
|
-
this.orbitControls.minDistance = 1;
|
|
237
|
-
this.orbitControls.maxDistance = 500;
|
|
238
|
-
this.orbitControls.maxPolarAngle = Math.PI / 2;
|
|
239
|
-
}
|
|
240
508
|
let renderResolution = this.screenResolution.clone().divideScalar(2);
|
|
241
509
|
renderResolution.x |= 0;
|
|
242
510
|
renderResolution.y |= 0;
|
|
@@ -250,6 +518,7 @@ var ZylemCamera = class {
|
|
|
250
518
|
camera: this
|
|
251
519
|
});
|
|
252
520
|
}
|
|
521
|
+
this.orbitController?.setScene(scene);
|
|
253
522
|
this.renderer.setAnimationLoop((delta) => {
|
|
254
523
|
this.update(delta || 0);
|
|
255
524
|
});
|
|
@@ -258,16 +527,18 @@ var ZylemCamera = class {
|
|
|
258
527
|
* Update camera and render
|
|
259
528
|
*/
|
|
260
529
|
update(delta) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
this.orbitControls.target.copy(this.orbitTargetWorldPos);
|
|
264
|
-
}
|
|
265
|
-
this.orbitControls?.update();
|
|
266
|
-
if (this.perspectiveController) {
|
|
530
|
+
this.orbitController?.update();
|
|
531
|
+
if (this.perspectiveController && !this.isDebugModeActive()) {
|
|
267
532
|
this.perspectiveController.update(delta);
|
|
268
533
|
}
|
|
269
534
|
this.composer.render(delta);
|
|
270
535
|
}
|
|
536
|
+
/**
|
|
537
|
+
* Check if debug mode is active (orbit controls taking over camera)
|
|
538
|
+
*/
|
|
539
|
+
isDebugModeActive() {
|
|
540
|
+
return this.orbitController?.isActive ?? false;
|
|
541
|
+
}
|
|
271
542
|
/**
|
|
272
543
|
* Dispose renderer, composer, controls, and detach from scene
|
|
273
544
|
*/
|
|
@@ -277,7 +548,7 @@ var ZylemCamera = class {
|
|
|
277
548
|
} catch {
|
|
278
549
|
}
|
|
279
550
|
try {
|
|
280
|
-
this.
|
|
551
|
+
this.orbitController?.dispose();
|
|
281
552
|
} catch {
|
|
282
553
|
}
|
|
283
554
|
try {
|
|
@@ -289,28 +560,13 @@ var ZylemCamera = class {
|
|
|
289
560
|
this.renderer.dispose();
|
|
290
561
|
} catch {
|
|
291
562
|
}
|
|
292
|
-
this.detachDebugDelegate();
|
|
293
563
|
this.sceneRef = null;
|
|
294
564
|
}
|
|
295
565
|
/**
|
|
296
566
|
* Attach a delegate to react to debug state changes.
|
|
297
567
|
*/
|
|
298
568
|
setDebugDelegate(delegate) {
|
|
299
|
-
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
this.detachDebugDelegate();
|
|
303
|
-
this.debugDelegate = delegate;
|
|
304
|
-
if (!delegate) {
|
|
305
|
-
this.applyDebugState({ enabled: false, selected: [] });
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
const unsubscribe = delegate.subscribe((state) => {
|
|
309
|
-
this.applyDebugState(state);
|
|
310
|
-
});
|
|
311
|
-
this.debugUnsubscribe = () => {
|
|
312
|
-
unsubscribe?.();
|
|
313
|
-
};
|
|
569
|
+
this.orbitController?.setDebugDelegate(delegate);
|
|
314
570
|
}
|
|
315
571
|
/**
|
|
316
572
|
* Resize camera and renderer
|
|
@@ -402,15 +658,31 @@ var ZylemCamera = class {
|
|
|
402
658
|
if (this._perspective === Perspectives.Flat2D || this._perspective === Perspectives.Fixed2D) {
|
|
403
659
|
this.frustumSize = position.z;
|
|
404
660
|
}
|
|
405
|
-
this.cameraRig
|
|
661
|
+
if (this.cameraRig) {
|
|
662
|
+
this.cameraRig.position.set(position.x, position.y, position.z);
|
|
663
|
+
} else {
|
|
664
|
+
this.camera.position.set(position.x, position.y, position.z);
|
|
665
|
+
}
|
|
406
666
|
}
|
|
407
667
|
move(position) {
|
|
408
668
|
this.moveCamera(position);
|
|
409
669
|
}
|
|
410
670
|
rotate(pitch, yaw, roll) {
|
|
411
|
-
this.cameraRig
|
|
412
|
-
|
|
413
|
-
|
|
671
|
+
if (this.cameraRig) {
|
|
672
|
+
this.cameraRig.rotateX(pitch);
|
|
673
|
+
this.cameraRig.rotateY(yaw);
|
|
674
|
+
this.cameraRig.rotateZ(roll);
|
|
675
|
+
} else {
|
|
676
|
+
this.camera.rotateX(pitch);
|
|
677
|
+
this.camera.rotateY(yaw);
|
|
678
|
+
this.camera.rotateZ(roll);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Check if this perspective type needs a camera rig
|
|
683
|
+
*/
|
|
684
|
+
needsRig() {
|
|
685
|
+
return this._perspective === Perspectives.ThirdPerson;
|
|
414
686
|
}
|
|
415
687
|
/**
|
|
416
688
|
* Get the DOM element for the renderer
|
|
@@ -418,89 +690,28 @@ var ZylemCamera = class {
|
|
|
418
690
|
getDomElement() {
|
|
419
691
|
return this.renderer.domElement;
|
|
420
692
|
}
|
|
421
|
-
applyDebugState(state) {
|
|
422
|
-
this.debugStateSnapshot = {
|
|
423
|
-
enabled: state.enabled,
|
|
424
|
-
selected: [...state.selected]
|
|
425
|
-
};
|
|
426
|
-
if (state.enabled) {
|
|
427
|
-
this.enableOrbitControls();
|
|
428
|
-
this.updateOrbitTargetFromSelection(state.selected);
|
|
429
|
-
} else {
|
|
430
|
-
this.orbitTarget = null;
|
|
431
|
-
this.disableOrbitControls();
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
enableOrbitControls() {
|
|
435
|
-
if (this.orbitControls) {
|
|
436
|
-
return;
|
|
437
|
-
}
|
|
438
|
-
this.orbitControls = new OrbitControls(this.camera, this.renderer.domElement);
|
|
439
|
-
this.orbitControls.enableDamping = true;
|
|
440
|
-
this.orbitControls.dampingFactor = 0.05;
|
|
441
|
-
this.orbitControls.screenSpacePanning = false;
|
|
442
|
-
this.orbitControls.minDistance = 1;
|
|
443
|
-
this.orbitControls.maxDistance = 500;
|
|
444
|
-
this.orbitControls.maxPolarAngle = Math.PI / 2;
|
|
445
|
-
}
|
|
446
|
-
disableOrbitControls() {
|
|
447
|
-
if (!this.orbitControls) {
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
this.orbitControls.dispose();
|
|
451
|
-
this.orbitControls = null;
|
|
452
|
-
}
|
|
453
|
-
updateOrbitTargetFromSelection(selected) {
|
|
454
|
-
if (!this.debugDelegate || selected.length === 0) {
|
|
455
|
-
this.orbitTarget = null;
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
for (let i = selected.length - 1; i >= 0; i -= 1) {
|
|
459
|
-
const uuid = selected[i];
|
|
460
|
-
const targetObject = this.debugDelegate.resolveTarget(uuid);
|
|
461
|
-
if (targetObject) {
|
|
462
|
-
this.orbitTarget = targetObject;
|
|
463
|
-
if (this.orbitControls) {
|
|
464
|
-
targetObject.getWorldPosition(this.orbitTargetWorldPos);
|
|
465
|
-
this.orbitControls.target.copy(this.orbitTargetWorldPos);
|
|
466
|
-
}
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
this.orbitTarget = null;
|
|
471
|
-
}
|
|
472
|
-
detachDebugDelegate() {
|
|
473
|
-
if (this.debugUnsubscribe) {
|
|
474
|
-
try {
|
|
475
|
-
this.debugUnsubscribe();
|
|
476
|
-
} catch {
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
this.debugUnsubscribe = null;
|
|
480
|
-
this.debugDelegate = null;
|
|
481
|
-
}
|
|
482
693
|
};
|
|
483
694
|
|
|
484
695
|
// src/lib/camera/camera.ts
|
|
485
696
|
var CameraWrapper = class {
|
|
486
697
|
cameraRef;
|
|
487
|
-
constructor(
|
|
488
|
-
this.cameraRef =
|
|
698
|
+
constructor(camera) {
|
|
699
|
+
this.cameraRef = camera;
|
|
489
700
|
}
|
|
490
701
|
};
|
|
491
|
-
function
|
|
702
|
+
function createCamera(options) {
|
|
492
703
|
const screenResolution = options.screenResolution || new Vector23(window.innerWidth, window.innerHeight);
|
|
493
704
|
let frustumSize = 10;
|
|
494
705
|
if (options.perspective === "fixed-2d") {
|
|
495
706
|
frustumSize = options.zoom || 10;
|
|
496
707
|
}
|
|
497
708
|
const zylemCamera = new ZylemCamera(options.perspective || "third-person", screenResolution, frustumSize);
|
|
498
|
-
zylemCamera.move(options.position || new
|
|
499
|
-
zylemCamera.camera.lookAt(options.target || new
|
|
709
|
+
zylemCamera.move(options.position || new Vector34(0, 0, 0));
|
|
710
|
+
zylemCamera.camera.lookAt(options.target || new Vector34(0, 0, 0));
|
|
500
711
|
return new CameraWrapper(zylemCamera);
|
|
501
712
|
}
|
|
502
713
|
export {
|
|
503
714
|
Perspectives,
|
|
504
|
-
|
|
715
|
+
createCamera
|
|
505
716
|
};
|
|
506
717
|
//# sourceMappingURL=camera.js.map
|