@needle-tools/engine 4.10.4-next.f6dc9f2 → 4.10.5-next.a5d5bf4
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 +4 -0
- package/components.needle.json +1 -1
- package/dist/{gltf-progressive-DUR9TuAH.js → gltf-progressive-B63NpN_i.js} +1 -1
- package/dist/{gltf-progressive-Iy7aSAPk.umd.cjs → gltf-progressive-CHeORqEv.umd.cjs} +2 -2
- package/dist/{gltf-progressive-CoZbSfPR.min.js → gltf-progressive-D4Z_Khp3.min.js} +1 -1
- package/dist/{needle-engine.bundle-BLWB7qT-.js → needle-engine.bundle-B2qX4saI.js} +1768 -1750
- package/dist/{needle-engine.bundle-qakLfSFW.min.js → needle-engine.bundle-D56E0HeK.min.js} +101 -101
- package/dist/{needle-engine.bundle-VwU3FjT0.umd.cjs → needle-engine.bundle-DPHrCUDs.umd.cjs} +106 -106
- package/dist/needle-engine.js +3 -3
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine/debug/debug_overlay.js +1 -1
- package/lib/engine/engine_context.js +1 -0
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine-components/web/CursorFollow.d.ts +16 -2
- package/lib/engine-components/web/CursorFollow.js +41 -7
- package/lib/engine-components/web/CursorFollow.js.map +1 -1
- package/package.json +2 -2
- package/src/engine/debug/debug_overlay.ts +1 -1
- package/src/engine/engine_context.ts +1 -0
- package/src/engine-components/web/CursorFollow.ts +46 -9
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Behaviour } from "../Component.js";
|
|
2
2
|
/**
|
|
3
3
|
* The CursorFollow component makes the object follow the cursor (or touch) position on screen.
|
|
4
|
+
*
|
|
5
|
+
* - Example: [Look At Cursor sample](https://engine.needle.tools/samples/look-at-cursor-interactive-3d-header/). This sample combines the CursorFollow component with a LookAt component to create an interactive 3D header that looks at the cursor.
|
|
6
|
+
*
|
|
4
7
|
* @category Web
|
|
5
8
|
* @group Components
|
|
6
9
|
* @component
|
|
@@ -11,14 +14,25 @@ export declare class CursorFollow extends Behaviour {
|
|
|
11
14
|
* @default 0
|
|
12
15
|
*/
|
|
13
16
|
damping: number;
|
|
17
|
+
/**
|
|
18
|
+
* When enabled the object will follow the cursor even outside of the needle-engine canvas. This is useful for example for look at effects where you have a small needle-engine element on your page and you want the 3D object to keep looking at the cursor even when it's outside of the canvas.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
useFullPage: boolean;
|
|
14
22
|
/**
|
|
15
23
|
* If true, the initial distance to the camera is maintained when following the cursor.
|
|
16
24
|
* @default true
|
|
17
25
|
*/
|
|
18
26
|
keepDistance: boolean;
|
|
19
|
-
awake(): void;
|
|
20
27
|
private _distance;
|
|
21
|
-
updateDistance(): void;
|
|
28
|
+
updateDistance(force?: boolean): void;
|
|
29
|
+
/** @internal */
|
|
30
|
+
awake(): void;
|
|
31
|
+
onEnable(): void;
|
|
32
|
+
onDisable(): void;
|
|
33
|
+
private _ndc_x;
|
|
34
|
+
private _ndc_y;
|
|
35
|
+
private _onPointerMove;
|
|
22
36
|
/** @internal */
|
|
23
37
|
update(): void;
|
|
24
38
|
}
|
|
@@ -9,6 +9,9 @@ import { getTempVector } from "../../engine/engine_three_utils.js";
|
|
|
9
9
|
import { Behaviour } from "../Component.js";
|
|
10
10
|
/**
|
|
11
11
|
* The CursorFollow component makes the object follow the cursor (or touch) position on screen.
|
|
12
|
+
*
|
|
13
|
+
* - Example: [Look At Cursor sample](https://engine.needle.tools/samples/look-at-cursor-interactive-3d-header/). This sample combines the CursorFollow component with a LookAt component to create an interactive 3D header that looks at the cursor.
|
|
14
|
+
*
|
|
12
15
|
* @category Web
|
|
13
16
|
* @group Components
|
|
14
17
|
* @component
|
|
@@ -19,31 +22,59 @@ export class CursorFollow extends Behaviour {
|
|
|
19
22
|
* @default 0
|
|
20
23
|
*/
|
|
21
24
|
damping = 0;
|
|
25
|
+
/**
|
|
26
|
+
* When enabled the object will follow the cursor even outside of the needle-engine canvas. This is useful for example for look at effects where you have a small needle-engine element on your page and you want the 3D object to keep looking at the cursor even when it's outside of the canvas.
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
useFullPage = true;
|
|
22
30
|
/**
|
|
23
31
|
* If true, the initial distance to the camera is maintained when following the cursor.
|
|
24
32
|
* @default true
|
|
25
33
|
*/
|
|
26
34
|
keepDistance = true;
|
|
27
|
-
awake() {
|
|
28
|
-
this._distance = -1;
|
|
29
|
-
}
|
|
30
35
|
_distance = -1;
|
|
31
|
-
updateDistance() {
|
|
32
|
-
if (this.keepDistance && this._distance !== -1) {
|
|
36
|
+
updateDistance(force = false) {
|
|
37
|
+
if (!force && (this.keepDistance && this._distance !== -1)) {
|
|
33
38
|
return;
|
|
34
39
|
}
|
|
35
40
|
this._distance = this.gameObject.worldPosition.distanceTo(this.context.mainCamera.worldPosition);
|
|
36
41
|
}
|
|
37
42
|
/** @internal */
|
|
43
|
+
awake() {
|
|
44
|
+
this._distance = -1;
|
|
45
|
+
}
|
|
46
|
+
onEnable() {
|
|
47
|
+
this._distance = -1;
|
|
48
|
+
window.addEventListener('pointermove', this._onPointerMove);
|
|
49
|
+
}
|
|
50
|
+
onDisable() {
|
|
51
|
+
window.removeEventListener('pointermove', this._onPointerMove);
|
|
52
|
+
}
|
|
53
|
+
_ndc_x = 0;
|
|
54
|
+
_ndc_y = 0;
|
|
55
|
+
_onPointerMove = (e) => {
|
|
56
|
+
if (!this.useFullPage)
|
|
57
|
+
return;
|
|
58
|
+
const x = e.clientX;
|
|
59
|
+
const y = e.clientY;
|
|
60
|
+
const domx = this.context.domX;
|
|
61
|
+
const domy = this.context.domY;
|
|
62
|
+
const domw = this.context.domWidth;
|
|
63
|
+
const domh = this.context.domHeight;
|
|
64
|
+
this._ndc_x = (x - domx) / domw * 2 - 1;
|
|
65
|
+
this._ndc_y = -(y - domy) / domh * 2 + 1;
|
|
66
|
+
};
|
|
67
|
+
/** @internal */
|
|
38
68
|
update() {
|
|
39
69
|
// continuously update distance in case camera or object moves
|
|
40
70
|
this.updateDistance();
|
|
71
|
+
const x = this.useFullPage ? this._ndc_x : this.context.input.mousePositionRC.x;
|
|
72
|
+
const y = this.useFullPage ? this._ndc_y : this.context.input.mousePositionRC.y;
|
|
41
73
|
// follow cursor in screenspace but maintain initial distance from camera
|
|
42
|
-
const cursor = this.context.input.mousePositionRC;
|
|
43
74
|
const camera = this.context.mainCamera;
|
|
44
75
|
const cameraPosition = camera.worldPosition;
|
|
45
76
|
// create ray from camera through cursor position
|
|
46
|
-
const rayDirection = getTempVector(
|
|
77
|
+
const rayDirection = getTempVector(x, y, 1).unproject(camera);
|
|
47
78
|
rayDirection.sub(cameraPosition).normalize();
|
|
48
79
|
// position object at initial distance along the ray
|
|
49
80
|
const newPosition = rayDirection.multiplyScalar(this._distance).add(cameraPosition);
|
|
@@ -60,6 +91,9 @@ export class CursorFollow extends Behaviour {
|
|
|
60
91
|
__decorate([
|
|
61
92
|
serializable()
|
|
62
93
|
], CursorFollow.prototype, "damping", void 0);
|
|
94
|
+
__decorate([
|
|
95
|
+
serializable()
|
|
96
|
+
], CursorFollow.prototype, "useFullPage", void 0);
|
|
63
97
|
__decorate([
|
|
64
98
|
serializable()
|
|
65
99
|
], CursorFollow.prototype, "keepDistance", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CursorFollow.js","sourceRoot":"","sources":["../../../src/engine-components/web/CursorFollow.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gDAAgD,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C
|
|
1
|
+
{"version":3,"file":"CursorFollow.js","sourceRoot":"","sources":["../../../src/engine-components/web/CursorFollow.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,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AG,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACpF,IAAI,IAAI,CAAC,OAAO,GAAG,CAAC,EAAE;YAClB,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC;YAC1C,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;YAClE,IAAI,CAAC,UAAU,CAAC,aAAa,GAAG,GAAG,CAAC;SACvC;aACI;YACD,IAAI,CAAC,UAAU,CAAC,aAAa,GAAG,WAAW,CAAC;SAC/C;IAEL,CAAC;CAEJ;AAnFG;IADC,YAAY,EAAE;6CACK;AAOpB;IADC,YAAY,EAAE;iDACa;AAO5B;IADC,YAAY,EAAE;kDACc"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/engine",
|
|
3
|
-
"version": "4.10.
|
|
3
|
+
"version": "4.10.5-next.a5d5bf4",
|
|
4
4
|
"description": "Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.",
|
|
5
5
|
"main": "dist/needle-engine.min.js",
|
|
6
6
|
"exports": {
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
],
|
|
94
94
|
"dependencies": {
|
|
95
95
|
"@dimforge/rapier3d-compat": "^0.19.0",
|
|
96
|
-
"@needle-tools/gltf-progressive": "3.3.
|
|
96
|
+
"@needle-tools/gltf-progressive": "3.3.5",
|
|
97
97
|
"@needle-tools/three-animation-pointer": "1.0.4",
|
|
98
98
|
"@webxr-input-profiles/motion-controllers": "^1.0.0",
|
|
99
99
|
"flatbuffers": "2.0.4",
|
|
@@ -244,7 +244,7 @@ function getLogsContainer(domElement: HTMLElement): HTMLElement {
|
|
|
244
244
|
padding-top: 0px;
|
|
245
245
|
max-width: 70%;
|
|
246
246
|
max-height: calc(100% - 5px);
|
|
247
|
-
z-index:
|
|
247
|
+
z-index: 100000;
|
|
248
248
|
pointer-events: scroll;
|
|
249
249
|
display: flex;
|
|
250
250
|
align-items: end;
|
|
@@ -1627,6 +1627,7 @@ export class Context implements IContext {
|
|
|
1627
1627
|
// but as a fallback we still register them (if e.g. there's no camera for compile async)
|
|
1628
1628
|
looputils.runPrewarm(this);
|
|
1629
1629
|
this._currentFrameEvent = FrameEvent.Undefined;
|
|
1630
|
+
nodeFrame.camera = this.mainCamera as Camera | null;
|
|
1630
1631
|
nodeFrame.update();
|
|
1631
1632
|
this.renderNow();
|
|
1632
1633
|
this._currentFrameEvent = FrameEvent.OnAfterRender;
|
|
@@ -3,7 +3,10 @@ import { getTempVector } from "../../engine/engine_three_utils.js";
|
|
|
3
3
|
import { Behaviour } from "../Component.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* The CursorFollow component makes the object follow the cursor (or touch) position on screen.
|
|
6
|
+
* The CursorFollow component makes the object follow the cursor (or touch) position on screen.
|
|
7
|
+
*
|
|
8
|
+
* - Example: [Look At Cursor sample](https://engine.needle.tools/samples/look-at-cursor-interactive-3d-header/). This sample combines the CursorFollow component with a LookAt component to create an interactive 3D header that looks at the cursor.
|
|
9
|
+
*
|
|
7
10
|
* @category Web
|
|
8
11
|
* @group Components
|
|
9
12
|
* @component
|
|
@@ -17,6 +20,13 @@ export class CursorFollow extends Behaviour {
|
|
|
17
20
|
@serializable()
|
|
18
21
|
damping: number = 0;
|
|
19
22
|
|
|
23
|
+
/**
|
|
24
|
+
* When enabled the object will follow the cursor even outside of the needle-engine canvas. This is useful for example for look at effects where you have a small needle-engine element on your page and you want the 3D object to keep looking at the cursor even when it's outside of the canvas.
|
|
25
|
+
* @default true
|
|
26
|
+
*/
|
|
27
|
+
@serializable()
|
|
28
|
+
useFullPage: boolean = true;
|
|
29
|
+
|
|
20
30
|
/**
|
|
21
31
|
* If true, the initial distance to the camera is maintained when following the cursor.
|
|
22
32
|
* @default true
|
|
@@ -24,31 +34,58 @@ export class CursorFollow extends Behaviour {
|
|
|
24
34
|
@serializable()
|
|
25
35
|
keepDistance: boolean = true;
|
|
26
36
|
|
|
37
|
+
|
|
38
|
+
private _distance: number = -1;
|
|
39
|
+
updateDistance(force:boolean = false) {
|
|
40
|
+
if (!force && (this.keepDistance && this._distance !== -1)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
this._distance = this.gameObject.worldPosition.distanceTo(this.context.mainCamera.worldPosition);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @internal */
|
|
27
47
|
awake() {
|
|
28
48
|
this._distance = -1;
|
|
29
49
|
}
|
|
30
50
|
|
|
31
|
-
|
|
51
|
+
onEnable(): void {
|
|
52
|
+
this._distance = -1;
|
|
53
|
+
window.addEventListener('pointermove', this._onPointerMove);
|
|
54
|
+
}
|
|
55
|
+
onDisable(): void {
|
|
56
|
+
window.removeEventListener('pointermove', this._onPointerMove);
|
|
57
|
+
}
|
|
32
58
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
59
|
+
private _ndc_x = 0;
|
|
60
|
+
private _ndc_y = 0;
|
|
61
|
+
|
|
62
|
+
private _onPointerMove = (e:PointerEvent) => {
|
|
63
|
+
if(!this.useFullPage) return;
|
|
64
|
+
const x = e.clientX;
|
|
65
|
+
const y = e.clientY;
|
|
66
|
+
const domx = this.context.domX;
|
|
67
|
+
const domy = this.context.domY;
|
|
68
|
+
const domw = this.context.domWidth;
|
|
69
|
+
const domh = this.context.domHeight;
|
|
70
|
+
this._ndc_x = (x - domx) / domw * 2 - 1;
|
|
71
|
+
this._ndc_y = - (y - domy) / domh * 2 + 1;
|
|
38
72
|
}
|
|
39
73
|
|
|
74
|
+
|
|
40
75
|
/** @internal */
|
|
41
76
|
update() {
|
|
42
77
|
// continuously update distance in case camera or object moves
|
|
43
78
|
this.updateDistance();
|
|
44
79
|
|
|
80
|
+
const x = this.useFullPage ? this._ndc_x : this.context.input.mousePositionRC.x;
|
|
81
|
+
const y = this.useFullPage ? this._ndc_y : this.context.input.mousePositionRC.y;
|
|
82
|
+
|
|
45
83
|
// follow cursor in screenspace but maintain initial distance from camera
|
|
46
|
-
const cursor = this.context.input.mousePositionRC;
|
|
47
84
|
const camera = this.context.mainCamera;
|
|
48
85
|
const cameraPosition = camera.worldPosition;
|
|
49
86
|
|
|
50
87
|
// create ray from camera through cursor position
|
|
51
|
-
const rayDirection = getTempVector(
|
|
88
|
+
const rayDirection = getTempVector(x, y, 1).unproject(camera);
|
|
52
89
|
rayDirection.sub(cameraPosition).normalize();
|
|
53
90
|
|
|
54
91
|
// position object at initial distance along the ray
|