@needle-tools/engine 4.1.0-beta.3 → 4.1.0-beta.4
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/CHANGELOG.md +5 -1
- package/dist/gltf-progressive.js +59 -59
- package/dist/gltf-progressive.light.js +59 -59
- package/dist/gltf-progressive.light.min.js +6 -6
- package/dist/gltf-progressive.light.umd.cjs +5 -5
- package/dist/gltf-progressive.min.js +6 -6
- package/dist/gltf-progressive.umd.cjs +5 -5
- package/dist/needle-engine.bundle.js +85 -76
- package/dist/needle-engine.bundle.light.js +85 -76
- package/dist/needle-engine.bundle.light.min.js +38 -38
- package/dist/needle-engine.bundle.light.umd.cjs +3 -3
- package/dist/needle-engine.bundle.min.js +38 -38
- package/dist/needle-engine.bundle.umd.cjs +3 -3
- package/lib/engine/engine_context.d.ts +2 -2
- package/lib/engine/engine_context.js +25 -4
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine-components/Camera.d.ts +7 -4
- package/lib/engine-components/Camera.js +13 -10
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/OrbitControls.js +1 -1
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/package.json +2 -2
- package/src/engine/engine_context.ts +29 -8
- package/src/engine-components/Camera.ts +14 -11
- package/src/engine-components/OrbitControls.ts +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EffectComposer } from "postprocessing";
|
|
2
2
|
import {
|
|
3
3
|
BufferGeometry, Camera, Color, DepthTexture, Group,
|
|
4
|
-
Material, NearestFilter, NoToneMapping, Object3D, PCFSoftShadowMap,
|
|
4
|
+
Material, NearestFilter, NoToneMapping, Object3D, OrthographicCamera, PCFSoftShadowMap,
|
|
5
5
|
PerspectiveCamera, RGBAFormat, Scene, SRGBColorSpace,
|
|
6
6
|
Texture, WebGLRenderer, type WebGLRendererParameters, WebGLRenderTarget, type WebXRArrayCamera
|
|
7
7
|
} from 'three';
|
|
@@ -485,7 +485,7 @@ export class Context implements IContext {
|
|
|
485
485
|
this.renderer.shadowMap.type = PCFSoftShadowMap;
|
|
486
486
|
this.renderer.setSize(this.domWidth, this.domHeight);
|
|
487
487
|
this.renderer.outputColorSpace = SRGBColorSpace;
|
|
488
|
-
|
|
488
|
+
|
|
489
489
|
// Injecting the core nodes library here, like WebGPURenderer backends do
|
|
490
490
|
//@ts-ignore
|
|
491
491
|
this.renderer.nodes = {
|
|
@@ -545,16 +545,37 @@ export class Context implements IContext {
|
|
|
545
545
|
}
|
|
546
546
|
}
|
|
547
547
|
|
|
548
|
-
updateAspect(camera: PerspectiveCamera, width?: number, height?: number) {
|
|
548
|
+
updateAspect(camera: PerspectiveCamera | OrthographicCamera, width?: number, height?: number) {
|
|
549
549
|
if (!camera) return;
|
|
550
550
|
if (width === undefined)
|
|
551
551
|
width = this.domWidth;
|
|
552
552
|
if (height === undefined)
|
|
553
553
|
height = this.domHeight;
|
|
554
|
-
const
|
|
555
|
-
camera
|
|
556
|
-
|
|
557
|
-
|
|
554
|
+
const aspectRatio = width / height;
|
|
555
|
+
if ((camera as PerspectiveCamera).isPerspectiveCamera) {
|
|
556
|
+
const cam = camera as PerspectiveCamera;
|
|
557
|
+
const pa = cam.aspect;
|
|
558
|
+
cam.aspect = aspectRatio;
|
|
559
|
+
if (pa !== cam.aspect)
|
|
560
|
+
camera.updateProjectionMatrix();
|
|
561
|
+
}
|
|
562
|
+
else if ((camera as OrthographicCamera).isOrthographicCamera) {
|
|
563
|
+
const cam = camera as OrthographicCamera;
|
|
564
|
+
// Maintain the camera's current vertical size (top - bottom)
|
|
565
|
+
const verticalSize = cam.top - cam.bottom;
|
|
566
|
+
// Calculate new horizontal size based on aspect ratio
|
|
567
|
+
const horizontalSize = verticalSize * aspectRatio;
|
|
568
|
+
// Update camera bounds while maintaining center position
|
|
569
|
+
const halfWidth = horizontalSize / 2;
|
|
570
|
+
const halfHeight = verticalSize / 2;
|
|
571
|
+
if (cam.left != -halfWidth || cam.top != halfHeight) {
|
|
572
|
+
cam.left = -halfWidth;
|
|
573
|
+
cam.right = halfWidth;
|
|
574
|
+
cam.top = halfHeight;
|
|
575
|
+
cam.bottom = -halfHeight;
|
|
576
|
+
camera.updateProjectionMatrix();
|
|
577
|
+
}
|
|
578
|
+
}
|
|
558
579
|
}
|
|
559
580
|
|
|
560
581
|
/** This will recreate the whole needle engine context and dispose the whole scene content
|
|
@@ -1078,7 +1099,7 @@ export class Context implements IContext {
|
|
|
1078
1099
|
// if the id was changed while still loading
|
|
1079
1100
|
// then we want to cleanup/destroy previously loaded files
|
|
1080
1101
|
if (createId !== this._createId || args.abortSignal?.aborted) {
|
|
1081
|
-
if(debug) console.log("Aborting loading because create id changed or abort signal was set", createId, this._createId);
|
|
1102
|
+
if (debug) console.log("Aborting loading because create id changed or abort signal was set", createId, this._createId);
|
|
1082
1103
|
for (const res of results) {
|
|
1083
1104
|
if (res && res.file) {
|
|
1084
1105
|
for (const scene of res.file.scenes)
|
|
@@ -51,7 +51,7 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
/** The camera's field of view in degrees if it is a perspective camera */
|
|
54
|
+
/** The camera's field of view in degrees if it is a perspective camera. Calls updateProjectionMatrix when set */
|
|
55
55
|
get fieldOfView(): number | undefined {
|
|
56
56
|
if (this._cam instanceof PerspectiveCamera) {
|
|
57
57
|
return this._cam.fov;
|
|
@@ -74,7 +74,7 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
/** The camera's near clipping plane */
|
|
77
|
+
/** The camera's near clipping plane. Calls updateProjectionMatrix when set */
|
|
78
78
|
get nearClipPlane(): number { return this._nearClipPlane; }
|
|
79
79
|
@serializable()
|
|
80
80
|
set nearClipPlane(val) {
|
|
@@ -87,15 +87,7 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
87
87
|
}
|
|
88
88
|
private _nearClipPlane: number = 0.1;
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
if (this._cam) {
|
|
92
|
-
this._cam.near = this._nearClipPlane;
|
|
93
|
-
this._cam.far = this._farClipPlane;
|
|
94
|
-
this._cam.updateProjectionMatrix();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** The camera's far clipping plane */
|
|
90
|
+
/** The camera's far clipping plane. Calls updateProjectionMatrix when set */
|
|
99
91
|
get farClipPlane(): number { return this._farClipPlane; }
|
|
100
92
|
@serializable()
|
|
101
93
|
set farClipPlane(val) {
|
|
@@ -108,6 +100,17 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
108
100
|
}
|
|
109
101
|
private _farClipPlane: number = 1000;
|
|
110
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Applys both the camera's near and far plane and calls updateProjectionMatrix on the camera.
|
|
105
|
+
*/
|
|
106
|
+
applyClippingPlane() {
|
|
107
|
+
if (this._cam) {
|
|
108
|
+
this._cam.near = this._nearClipPlane;
|
|
109
|
+
this._cam.far = this._farClipPlane;
|
|
110
|
+
this._cam.updateProjectionMatrix();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
111
114
|
/** The camera's clear flags - determines if the background is a skybox or a solid color or transparent */
|
|
112
115
|
@serializable()
|
|
113
116
|
public get clearFlags(): ClearFlags {
|
|
@@ -287,7 +287,7 @@ export class OrbitControls extends Behaviour implements ICameraController {
|
|
|
287
287
|
cam = this.gameObject;
|
|
288
288
|
}
|
|
289
289
|
if (cam) setCameraController(cam, this, true);
|
|
290
|
-
if (!this._controls && cam instanceof
|
|
290
|
+
if (!this._controls && cam instanceof Object3D) {
|
|
291
291
|
this._cameraObject = cam;
|
|
292
292
|
// Using the parent if possible to make it possible to disable input on the canvas
|
|
293
293
|
// for having HTML content behind it and still receive input
|