@needle-tools/engine 4.10.5-next.a5d5bf4 → 4.11.0-beta
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 +10 -0
- package/components.needle.json +1 -1
- package/dist/{needle-engine.bundle-D56E0HeK.min.js → needle-engine.bundle-BJ2hrLWW.min.js} +130 -130
- package/dist/{needle-engine.bundle-B2qX4saI.js → needle-engine.bundle-DZS0TuER.js} +5974 -5826
- package/dist/{needle-engine.bundle-DPHrCUDs.umd.cjs → needle-engine.bundle-JCl0_y_J.umd.cjs} +133 -133
- package/dist/needle-engine.d.ts +14 -0
- package/dist/needle-engine.js +321 -320
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine/codegen/register_types.js +2 -0
- package/lib/engine/codegen/register_types.js.map +1 -1
- package/lib/engine/engine_gizmos.js +2 -2
- package/lib/engine/engine_gizmos.js.map +1 -1
- package/lib/engine/engine_physics.js +19 -12
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/js-extensions/Object3D.d.ts +14 -0
- package/lib/engine/js-extensions/Object3D.js +13 -0
- package/lib/engine/js-extensions/Object3D.js.map +1 -1
- package/lib/engine-components/Renderer.js +33 -32
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/RendererLightmap.d.ts +7 -5
- package/lib/engine-components/RendererLightmap.js +29 -30
- package/lib/engine-components/RendererLightmap.js.map +1 -1
- package/lib/engine-components/SeeThrough.d.ts +70 -0
- package/lib/engine-components/SeeThrough.js +223 -0
- package/lib/engine-components/SeeThrough.js.map +1 -0
- package/lib/engine-components/codegen/components.d.ts +1 -0
- package/lib/engine-components/codegen/components.js +1 -0
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/ui/Graphic.js +13 -1
- package/lib/engine-components/ui/Graphic.js.map +1 -1
- package/lib/engine-components/ui/RaycastUtils.js +5 -3
- package/lib/engine-components/ui/RaycastUtils.js.map +1 -1
- package/lib/engine-components/utils/LookAt.js +4 -2
- package/lib/engine-components/utils/LookAt.js.map +1 -1
- package/lib/engine-components/web/Clickthrough.d.ts +2 -1
- package/lib/engine-components/web/Clickthrough.js +2 -1
- package/lib/engine-components/web/Clickthrough.js.map +1 -1
- package/lib/engine-components/web/CursorFollow.d.ts +7 -1
- package/lib/engine-components/web/CursorFollow.js +35 -2
- package/lib/engine-components/web/CursorFollow.js.map +1 -1
- package/package.json +2 -2
- package/src/engine/codegen/register_types.ts +2 -0
- package/src/engine/engine_gizmos.ts +3 -3
- package/src/engine/engine_physics.ts +24 -12
- package/src/engine/js-extensions/Object3D.ts +32 -0
- package/src/engine-components/Renderer.ts +38 -37
- package/src/engine-components/RendererLightmap.ts +31 -33
- package/src/engine-components/SeeThrough.ts +256 -0
- package/src/engine-components/codegen/components.ts +1 -0
- package/src/engine-components/ui/Graphic.ts +13 -1
- package/src/engine-components/ui/RaycastUtils.ts +9 -8
- package/src/engine-components/utils/LookAt.ts +4 -1
- package/src/engine-components/web/Clickthrough.ts +2 -1
- package/src/engine-components/web/CursorFollow.ts +48 -7
|
@@ -11,9 +11,8 @@ export class UIRaycastUtils {
|
|
|
11
11
|
/** returns the real object when dealing with shadow UI */
|
|
12
12
|
static getObject(obj: Object3D): Object3D {
|
|
13
13
|
const shadowOwner = obj[$shadowDomOwner];
|
|
14
|
-
if(shadowOwner)
|
|
15
|
-
|
|
16
|
-
if((shadowOwner as IComponent).isComponent === true) obj = (shadowOwner as IComponent).gameObject;
|
|
14
|
+
if (shadowOwner) {
|
|
15
|
+
if ((shadowOwner as IComponent).isComponent === true) obj = (shadowOwner as IComponent).gameObject;
|
|
17
16
|
else obj = shadowOwner;
|
|
18
17
|
}
|
|
19
18
|
return obj;
|
|
@@ -29,8 +28,8 @@ export class UIRaycastUtils {
|
|
|
29
28
|
|
|
30
29
|
obj = this.getObject(obj);
|
|
31
30
|
|
|
32
|
-
if(!obj.visible) return false;
|
|
33
|
-
|
|
31
|
+
if (!obj.visible) return false;
|
|
32
|
+
|
|
34
33
|
const canvasGroup = this.tryFindCanvasGroup(obj);
|
|
35
34
|
if (canvasGroup?.isCanvasGroup === true) {
|
|
36
35
|
if (out) out.canvasGroup = canvasGroup as ICanvasGroup;
|
|
@@ -38,7 +37,7 @@ export class UIRaycastUtils {
|
|
|
38
37
|
if (canvasGroup.interactable === false) return false;
|
|
39
38
|
}
|
|
40
39
|
// handle Graphic Raycast target
|
|
41
|
-
const graphic
|
|
40
|
+
const graphic: IGraphic | undefined = foreachComponent(obj, c => {
|
|
42
41
|
if ((c as unknown as IGraphic).isGraphic === true) return c;
|
|
43
42
|
return undefined;
|
|
44
43
|
}, false);
|
|
@@ -58,8 +57,10 @@ export class UIRaycastUtils {
|
|
|
58
57
|
if (!obj) return null;
|
|
59
58
|
// test for canvas groups
|
|
60
59
|
const res = foreachComponent(obj, c => {
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
if (c.activeAndEnabled) {
|
|
61
|
+
const gr = c as unknown as ICanvasGroup;
|
|
62
|
+
if (gr.blocksRaycasts !== undefined && gr.interactable !== undefined) return gr;
|
|
63
|
+
}
|
|
63
64
|
return undefined;
|
|
64
65
|
}, false);
|
|
65
66
|
if (res !== undefined) return res;
|
|
@@ -45,7 +45,10 @@ export class LookAt extends Behaviour implements UsdzBehaviour {
|
|
|
45
45
|
let target: Object3D | null | undefined = this.target;
|
|
46
46
|
if (!target) {
|
|
47
47
|
target = this.context.mainCamera;
|
|
48
|
-
if (isDevEnvironment()
|
|
48
|
+
if (isDevEnvironment() && !this["__did_warn"]) {
|
|
49
|
+
this["__did_warn"] = true;
|
|
50
|
+
console.debug(`[LookAt] No target set on ${this.name}, using main camera as target.`);
|
|
51
|
+
}
|
|
49
52
|
}
|
|
50
53
|
if (!target) return;
|
|
51
54
|
|
|
@@ -29,7 +29,8 @@ onStart(ctx => {
|
|
|
29
29
|
* - Add the ClickThrough component to any GameObject in your scene.
|
|
30
30
|
* - Alternatively, add the `clickthrough` attribute to the `<needle-engine>` HTML element (e.g. `<needle-engine clickthrough></needle-engine>`).
|
|
31
31
|
*
|
|
32
|
-
*
|
|
32
|
+
* - Example https://stackblitz.com/~/github.com/needle-engine/sample-3d-over-html
|
|
33
|
+
*
|
|
33
34
|
* @category Web
|
|
34
35
|
* @group Components
|
|
35
36
|
* @component
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import { Ray } from "three";
|
|
2
|
+
|
|
3
|
+
import { Gizmos } from "../../engine/engine_gizmos.js";
|
|
1
4
|
import { serializable } from "../../engine/engine_serialization_decorator.js";
|
|
2
5
|
import { getTempVector } from "../../engine/engine_three_utils.js";
|
|
6
|
+
import { getParam } from "../../engine/engine_utils.js";
|
|
3
7
|
import { Behaviour } from "../Component.js";
|
|
4
8
|
|
|
9
|
+
|
|
10
|
+
const debug = getParam("debugcursor");
|
|
11
|
+
|
|
5
12
|
/**
|
|
6
13
|
* The CursorFollow component makes the object follow the cursor (or touch) position on screen.
|
|
7
14
|
*
|
|
@@ -34,9 +41,15 @@ export class CursorFollow extends Behaviour {
|
|
|
34
41
|
@serializable()
|
|
35
42
|
keepDistance: boolean = true;
|
|
36
43
|
|
|
37
|
-
|
|
44
|
+
/**
|
|
45
|
+
* If true, the object will attempt to snap to the surface of other objects in the scene using a raycast.
|
|
46
|
+
*/
|
|
47
|
+
@serializable()
|
|
48
|
+
snapToSurface: boolean = false;
|
|
49
|
+
|
|
50
|
+
|
|
38
51
|
private _distance: number = -1;
|
|
39
|
-
updateDistance(force:boolean = false) {
|
|
52
|
+
updateDistance(force: boolean = false) {
|
|
40
53
|
if (!force && (this.keepDistance && this._distance !== -1)) {
|
|
41
54
|
return;
|
|
42
55
|
}
|
|
@@ -48,10 +61,12 @@ export class CursorFollow extends Behaviour {
|
|
|
48
61
|
this._distance = -1;
|
|
49
62
|
}
|
|
50
63
|
|
|
64
|
+
/** @internal */
|
|
51
65
|
onEnable(): void {
|
|
52
66
|
this._distance = -1;
|
|
53
67
|
window.addEventListener('pointermove', this._onPointerMove);
|
|
54
68
|
}
|
|
69
|
+
/** @internal */
|
|
55
70
|
onDisable(): void {
|
|
56
71
|
window.removeEventListener('pointermove', this._onPointerMove);
|
|
57
72
|
}
|
|
@@ -59,8 +74,8 @@ export class CursorFollow extends Behaviour {
|
|
|
59
74
|
private _ndc_x = 0;
|
|
60
75
|
private _ndc_y = 0;
|
|
61
76
|
|
|
62
|
-
private _onPointerMove = (e:PointerEvent) => {
|
|
63
|
-
if(!this.useFullPage) return;
|
|
77
|
+
private _onPointerMove = (e: PointerEvent) => {
|
|
78
|
+
if (!this.useFullPage) return;
|
|
64
79
|
const x = e.clientX;
|
|
65
80
|
const y = e.clientY;
|
|
66
81
|
const domx = this.context.domX;
|
|
@@ -73,7 +88,7 @@ export class CursorFollow extends Behaviour {
|
|
|
73
88
|
|
|
74
89
|
|
|
75
90
|
/** @internal */
|
|
76
|
-
|
|
91
|
+
lateUpdate() {
|
|
77
92
|
// continuously update distance in case camera or object moves
|
|
78
93
|
this.updateDistance();
|
|
79
94
|
|
|
@@ -89,16 +104,42 @@ export class CursorFollow extends Behaviour {
|
|
|
89
104
|
rayDirection.sub(cameraPosition).normalize();
|
|
90
105
|
|
|
91
106
|
// position object at initial distance along the ray
|
|
92
|
-
const newPosition = rayDirection.multiplyScalar(this._distance).add(cameraPosition);
|
|
107
|
+
const newPosition = getTempVector(rayDirection).multiplyScalar(this._distance).add(cameraPosition);
|
|
108
|
+
let _position = newPosition;
|
|
109
|
+
|
|
110
|
+
|
|
93
111
|
if (this.damping > 0) {
|
|
94
112
|
const pos = this.gameObject.worldPosition;
|
|
95
113
|
pos.lerp(newPosition, this.context.time.deltaTime / this.damping);
|
|
96
114
|
this.gameObject.worldPosition = pos;
|
|
115
|
+
_position = pos;
|
|
97
116
|
}
|
|
98
117
|
else {
|
|
99
118
|
this.gameObject.worldPosition = newPosition;
|
|
100
119
|
}
|
|
101
120
|
|
|
121
|
+
|
|
122
|
+
if (this.snapToSurface) {
|
|
123
|
+
ray.origin = _position;
|
|
124
|
+
ray.direction = rayDirection.multiplyScalar(-1);
|
|
125
|
+
const hits = this.context.physics.raycastFromRay(ray);
|
|
126
|
+
if (hits?.length) {
|
|
127
|
+
const hit = hits[0];
|
|
128
|
+
if (this.damping > 0) {
|
|
129
|
+
this.gameObject.worldPosition = _position.lerp(hit.point, this.context.time.deltaTime / this.damping);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
this.gameObject.worldPosition = hit.point;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if(debug) {
|
|
136
|
+
Gizmos.DrawLine(hit.point, hit.normal!.add(hit.point), 0x00FF00);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
102
141
|
}
|
|
103
142
|
|
|
104
|
-
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const ray = new Ray();
|