@needle-tools/engine 4.8.8-next.c758977 → 4.8.8-next.e80f4d7
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 +6 -2
- package/dist/{needle-engine.bundle-CGGDUMtw.umd.cjs → needle-engine.bundle-DK1r3WiC.umd.cjs} +53 -53
- package/dist/{needle-engine.bundle-NtRy1Q8c.js → needle-engine.bundle-DfWoUjQM.js} +27 -11
- package/dist/{needle-engine.bundle-rHPLwL4P.min.js → needle-engine.bundle-IGziSts0.min.js} +5 -5
- package/dist/needle-engine.js +2 -2
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine/engine_camera.d.ts +15 -2
- package/lib/engine/engine_camera.js +9 -2
- package/lib/engine/engine_camera.js.map +1 -1
- package/lib/engine/engine_context.d.ts +8 -2
- package/lib/engine/engine_context.js +21 -3
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_create_objects.d.ts +3 -3
- package/lib/engine/engine_create_objects.js +5 -4
- package/lib/engine/engine_create_objects.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_lighting_settings.js +5 -2
- package/lib/engine/extensions/NEEDLE_lighting_settings.js.map +1 -1
- package/lib/engine-components/OrbitControls.js +2 -4
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/package.json +2 -2
- package/src/engine/engine_camera.ts +15 -3
- package/src/engine/engine_context.ts +22 -4
- package/src/engine/engine_create_objects.ts +8 -7
- package/src/engine/extensions/NEEDLE_lighting_settings.ts +5 -2
- package/src/engine-components/OrbitControls.ts +2 -6
|
@@ -25,7 +25,11 @@ export function setCameraController(cam: Camera, cameraController: ICameraContro
|
|
|
25
25
|
|
|
26
26
|
const autofit = "needle:autofit";
|
|
27
27
|
|
|
28
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Used by e.g. getBoundingBox via ContactShadows or OrbitControls when fitting the camera or shadow planes. Objects can be marked to be excluded from bounding box calculations via `setAutoFitEnabled(obj, <bool>)`
|
|
30
|
+
* @see setAutoFitEnabled
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
29
33
|
export function useForAutoFit(obj: Object3D): boolean {
|
|
30
34
|
// if autofit is not defined we assume it may be included
|
|
31
35
|
if (obj[autofit] === undefined) return true;
|
|
@@ -34,7 +38,9 @@ export function useForAutoFit(obj: Object3D): boolean {
|
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
/**
|
|
37
|
-
* Enable or disable autofitting for the given object
|
|
41
|
+
* Enable or disable autofitting for the given object. Objects that are 'disabled' will be excluded in getBoundingBox calculations.
|
|
42
|
+
* This is used by ContactShadows or OrbitControls when fitting the shadow plane or camera to the given objects or scene.
|
|
43
|
+
* @see useForAutoFit
|
|
38
44
|
*/
|
|
39
45
|
export function setAutoFitEnabled(obj: Object3D, enabled: boolean): void {
|
|
40
46
|
obj[autofit] = enabled;
|
|
@@ -42,12 +48,18 @@ export function setAutoFitEnabled(obj: Object3D, enabled: boolean): void {
|
|
|
42
48
|
|
|
43
49
|
|
|
44
50
|
|
|
45
|
-
|
|
51
|
+
export type FocusRectSettings = {
|
|
52
|
+
/** Lower values will result in faster alignment with the rect (value ~= seconds to reach target)
|
|
53
|
+
* Minimum value is 0.
|
|
54
|
+
*/
|
|
55
|
+
damping: number
|
|
56
|
+
}
|
|
46
57
|
export type FocusRect = DOMRect | Element | { x: number, y: number, width: number, height: number };
|
|
47
58
|
|
|
48
59
|
let rendererRect: DOMRect | undefined = undefined;
|
|
49
60
|
const overlapRect = { x: 0, y: 0, width: 0, height: 0 };
|
|
50
61
|
|
|
62
|
+
/** Used internally by the Needle Engine context via 'setFocusRect(<rect>)' */
|
|
51
63
|
export function updateCameraFocusRect(focusRect: FocusRect, dt: number, camera: PerspectiveCamera, renderer: WebGLRenderer) {
|
|
52
64
|
|
|
53
65
|
if (focusRect instanceof Element) {
|
|
@@ -18,7 +18,7 @@ import { Addressables } from './engine_addressables.js';
|
|
|
18
18
|
import { AnimationsRegistry } from './engine_animation.js';
|
|
19
19
|
import { Application } from './engine_application.js';
|
|
20
20
|
import { AssetDatabase } from './engine_assetdatabase.js';
|
|
21
|
-
import { FocusRect, updateCameraFocusRect } from './engine_camera.js';
|
|
21
|
+
import { FocusRect, FocusRectSettings, updateCameraFocusRect } from './engine_camera.js';
|
|
22
22
|
import { VERSION } from './engine_constants.js';
|
|
23
23
|
import { ContextEvent, ContextRegistry } from './engine_context_registry.js';
|
|
24
24
|
import { WaitForPromise } from './engine_coroutine.js';
|
|
@@ -1378,11 +1378,26 @@ export class Context implements IContext {
|
|
|
1378
1378
|
* Set a rect or dom element. The camera center will be moved to the center of the rect.
|
|
1379
1379
|
* This is useful if you have Needle Engine embedded in a HTML layout and while you want the webgl background to fill e.g. the whole screen you want to move the camera center to free space.
|
|
1380
1380
|
* For that you can simply pass in the rect or HMTL div that you want the camera to center on.
|
|
1381
|
+
* @param rect The focus rect or null to disable
|
|
1382
|
+
* @param settings Optional settings for the focus rect. These will override the `focusRectSettings` property
|
|
1381
1383
|
*/
|
|
1382
|
-
public setCameraFocusRect(rect: FocusRect | null) {
|
|
1384
|
+
public setCameraFocusRect(rect: FocusRect | null, settings?: Partial<FocusRectSettings>) {
|
|
1383
1385
|
this._focusRect = rect;
|
|
1386
|
+
if (settings) {
|
|
1387
|
+
Object.assign(this.focusRectSettings, settings);
|
|
1388
|
+
}
|
|
1384
1389
|
}
|
|
1385
1390
|
get focusRect() { return this._focusRect; }
|
|
1391
|
+
/** Settings when a focus rect is set. Use `setCameraFocusRect(...)` to do so.
|
|
1392
|
+
* This can be used to offset the renderer center e.g. to a specific DOM element.
|
|
1393
|
+
*/
|
|
1394
|
+
readonly focusRectSettings: FocusRectSettings = {
|
|
1395
|
+
/** Controls how fast the rect is centered. Smaller values mean the rect is centered faster.
|
|
1396
|
+
* A minimum value of 0 means the rect is centered instantly.
|
|
1397
|
+
* @default .05
|
|
1398
|
+
*/
|
|
1399
|
+
damping: .05
|
|
1400
|
+
};
|
|
1386
1401
|
private _focusRect: FocusRect | null = null;
|
|
1387
1402
|
|
|
1388
1403
|
|
|
@@ -1514,8 +1529,11 @@ export class Context implements IContext {
|
|
|
1514
1529
|
if (this.isVisibleToUser || this.runInBackground) {
|
|
1515
1530
|
|
|
1516
1531
|
if (this._focusRect) {
|
|
1517
|
-
if (this.mainCamera instanceof PerspectiveCamera)
|
|
1518
|
-
|
|
1532
|
+
if (this.mainCamera instanceof PerspectiveCamera) {
|
|
1533
|
+
const settings = this.focusRectSettings;
|
|
1534
|
+
const dt = settings.damping > 0 ? this.time.deltaTime / settings.damping : 1;
|
|
1535
|
+
updateCameraFocusRect(this._focusRect, dt, this.mainCamera, this.renderer);
|
|
1536
|
+
}
|
|
1519
1537
|
}
|
|
1520
1538
|
|
|
1521
1539
|
this._currentFrameEvent = FrameEvent.OnBeforeRender;
|
|
@@ -42,13 +42,13 @@ export type ObjectOptions = {
|
|
|
42
42
|
/**
|
|
43
43
|
* The position of the object in local space
|
|
44
44
|
*/
|
|
45
|
-
position?: Vec3 | [number, number, number],
|
|
45
|
+
position?: Partial<Vec3> | [number, number, number],
|
|
46
46
|
/** The rotation of the object in local space */
|
|
47
|
-
rotation?: Vec3 | [number, number, number],
|
|
47
|
+
rotation?: Partial<Vec3> | [number, number, number],
|
|
48
48
|
/**
|
|
49
49
|
* The scale of the object in local space
|
|
50
50
|
*/
|
|
51
|
-
scale?: Vec3 | number | [number, number, number],
|
|
51
|
+
scale?: Partial<Vec3> | number | [number, number, number],
|
|
52
52
|
/**
|
|
53
53
|
* If the object should receive shadows
|
|
54
54
|
* @default true
|
|
@@ -251,14 +251,15 @@ export class ObjectUtils {
|
|
|
251
251
|
if (opts?.position) {
|
|
252
252
|
if (Array.isArray(opts.position))
|
|
253
253
|
obj.position.set(opts.position[0], opts.position[1], opts.position[2]);
|
|
254
|
-
else
|
|
255
|
-
obj.position.set(opts.position.x, opts.position.y, opts.position.z);
|
|
254
|
+
else {
|
|
255
|
+
obj.position.set(opts.position.x || 0, opts.position.y || 0, opts.position.z || 0);
|
|
256
|
+
}
|
|
256
257
|
}
|
|
257
258
|
if (opts?.rotation) {
|
|
258
259
|
if (Array.isArray(opts.rotation))
|
|
259
260
|
obj.rotation.set(opts.rotation[0], opts.rotation[1], opts.rotation[2]);
|
|
260
261
|
else
|
|
261
|
-
obj.rotation.set(opts.rotation.x, opts.rotation.y, opts.rotation.z);
|
|
262
|
+
obj.rotation.set(opts.rotation.x || 0, opts.rotation.y || 0, opts.rotation.z || 0);
|
|
262
263
|
}
|
|
263
264
|
if (opts?.scale) {
|
|
264
265
|
if (typeof opts.scale === "number")
|
|
@@ -267,7 +268,7 @@ export class ObjectUtils {
|
|
|
267
268
|
obj.scale.set(opts.scale[0], opts.scale[1], opts.scale[2]);
|
|
268
269
|
}
|
|
269
270
|
else {
|
|
270
|
-
obj.scale.set(opts.scale.x, opts.scale.y, opts.scale.z);
|
|
271
|
+
obj.scale.set(opts.scale.x || 1, opts.scale.y || 1, opts.scale.z || 1);
|
|
271
272
|
|
|
272
273
|
}
|
|
273
274
|
}
|
|
@@ -169,8 +169,11 @@ export class SceneLightSettings extends Behaviour {
|
|
|
169
169
|
this._hemisphereLightObj.removeFromParent();
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
if (this.sourceId)
|
|
173
|
-
this.context.
|
|
172
|
+
if (this.sourceId) {
|
|
173
|
+
if (!this.context.domElement.getAttribute("environment-image")) {
|
|
174
|
+
this.context.sceneLighting.internalEnableReflection(this.sourceId);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
174
177
|
}
|
|
175
178
|
|
|
176
179
|
onDisable() {
|
|
@@ -1044,15 +1044,13 @@ export class OrbitControls extends Behaviour implements ICameraController {
|
|
|
1044
1044
|
// and thus we're just getting some maximum that will work for sure.
|
|
1045
1045
|
const box = getBoundingBox(objects, undefined, this._camera?.threeCamera?.layers);
|
|
1046
1046
|
const boxCopy = box.clone();
|
|
1047
|
-
|
|
1048
|
-
camera.updateMatrixWorld();
|
|
1049
|
-
camera.updateProjectionMatrix();
|
|
1050
1047
|
box.getCenter(center);
|
|
1051
1048
|
|
|
1052
1049
|
const box_size = new Vector3();
|
|
1053
1050
|
box.getSize(box_size);
|
|
1054
1051
|
|
|
1055
1052
|
// project this box into camera space
|
|
1053
|
+
camera.updateMatrixWorld();
|
|
1056
1054
|
box.applyMatrix4(camera.matrixWorldInverse);
|
|
1057
1055
|
|
|
1058
1056
|
box.getSize(size);
|
|
@@ -1104,6 +1102,7 @@ export class OrbitControls extends Behaviour implements ICameraController {
|
|
|
1104
1102
|
// TODO: this doesnt take the Camera component nearClipPlane into account
|
|
1105
1103
|
camera.near = (distance / 100);
|
|
1106
1104
|
camera.far = boundsMax + distance * 10;
|
|
1105
|
+
camera.updateProjectionMatrix();
|
|
1107
1106
|
|
|
1108
1107
|
// adjust maxZoom so that the ground projection radius is always inside
|
|
1109
1108
|
if (groundprojection) {
|
|
@@ -1116,9 +1115,6 @@ export class OrbitControls extends Behaviour implements ICameraController {
|
|
|
1116
1115
|
if (currentZoom < this.minZoom) this.minZoom = currentZoom * 0.9;
|
|
1117
1116
|
if (currentZoom > this.maxZoom) this.maxZoom = currentZoom * 1.1;
|
|
1118
1117
|
|
|
1119
|
-
camera.updateMatrixWorld();
|
|
1120
|
-
camera.updateProjectionMatrix();
|
|
1121
|
-
|
|
1122
1118
|
const direction = center.clone();
|
|
1123
1119
|
if (options.fitDirection) {
|
|
1124
1120
|
direction.sub(new Vector3().copy(options.fitDirection).multiplyScalar(1_000_000));
|