@needle-tools/engine 3.2.12-alpha → 3.2.14-alpha
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 +11 -0
- package/dist/needle-engine.js +10130 -9995
- package/dist/needle-engine.min.js +279 -279
- package/dist/needle-engine.umd.cjs +273 -273
- package/lib/engine/codegen/register_types.js +4 -0
- package/lib/engine/codegen/register_types.js.map +1 -1
- package/lib/engine/engine_serialization_core.js +2 -0
- package/lib/engine/engine_serialization_core.js.map +1 -1
- package/lib/engine/engine_utils.d.ts +2 -2
- package/lib/engine/engine_utils.js +4 -4
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine-components/SceneSwitcher.d.ts +5 -0
- package/lib/engine-components/SceneSwitcher.js +32 -4
- package/lib/engine-components/SceneSwitcher.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +2 -0
- package/lib/engine-components/codegen/components.js +2 -0
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/export/usdz/USDZExporter.d.ts +9 -5
- package/lib/engine-components/export/usdz/USDZExporter.js +79 -28
- package/lib/engine-components/export/usdz/USDZExporter.js.map +1 -1
- package/lib/engine-components/ui/EventSystem.js +11 -4
- package/lib/engine-components/ui/EventSystem.js.map +1 -1
- package/lib/engine-components/utils/OpenURL.d.ts +21 -0
- package/lib/engine-components/utils/OpenURL.js +125 -0
- package/lib/engine-components/utils/OpenURL.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/plugins/vite/alias.js +1 -4
- package/plugins/vite/copyfiles.js +46 -40
- package/plugins/vite/index.js +2 -0
- package/plugins/vite/meta.js +5 -2
- package/plugins/vite/peer.js +28 -0
- package/plugins/vite/reload.js +17 -13
- package/src/engine/codegen/register_types.js +4 -0
- package/src/engine/engine_serialization_core.ts +1 -1
- package/src/engine/engine_utils.ts +7 -7
- package/src/engine-components/SceneSwitcher.ts +38 -5
- package/src/engine-components/codegen/components.ts +2 -0
- package/src/engine-components/export/usdz/USDZExporter.ts +75 -31
- package/src/engine-components/ui/EventSystem.ts +11 -5
- package/src/engine-components/utils/OpenURL.ts +119 -0
|
@@ -6,14 +6,14 @@ import * as ThreeMeshUI from 'three-mesh-ui'
|
|
|
6
6
|
import { Context } from "../../engine/engine_setup";
|
|
7
7
|
import { OrbitControls } from "../OrbitControls";
|
|
8
8
|
import { IPointerEventHandler, PointerEventData } from "./PointerEvents";
|
|
9
|
-
import { Raycaster } from "./Raycaster";
|
|
9
|
+
import { ObjectRaycaster, Raycaster } from "./Raycaster";
|
|
10
10
|
import { InputEvents } from "../../engine/engine_input";
|
|
11
11
|
import { Object3D } from "three";
|
|
12
12
|
import { ICanvasGroup, IGraphic } from "./Interfaces";
|
|
13
13
|
import { getParam } from "../../engine/engine_utils";
|
|
14
14
|
import { UIRaycastUtils } from "./RaycastUtils";
|
|
15
15
|
import { $shadowDomOwner } from "./BaseUIComponent";
|
|
16
|
-
import { showBalloonMessage, showBalloonWarning } from "../../engine/debug";
|
|
16
|
+
import { isDevEnvironment, showBalloonMessage, showBalloonWarning } from "../../engine/debug";
|
|
17
17
|
|
|
18
18
|
const debug = getParam("debugeventsystem");
|
|
19
19
|
|
|
@@ -86,9 +86,15 @@ export class EventSystem extends Behaviour {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
start() {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
if (this.raycaster.length <= 0) {
|
|
90
|
+
const res = GameObject.findObjectOfType(Raycaster, this.context);
|
|
91
|
+
if (!res) {
|
|
92
|
+
const rc = GameObject.addNewComponent(this.context.scene, ObjectRaycaster);
|
|
93
|
+
this.raycaster.push(rc);
|
|
94
|
+
if (isDevEnvironment())
|
|
95
|
+
console.warn("Added an ObjectRaycaster to the scene because no raycaster was found", this);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
92
98
|
}
|
|
93
99
|
|
|
94
100
|
register(rc: Raycaster) {
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
|
|
2
|
+
import { IPointerClickHandler, PointerEventData } from "../ui";
|
|
3
|
+
import { Behaviour } from "../Component";
|
|
4
|
+
import { serializable } from "../../engine/engine_serialization";
|
|
5
|
+
import { isDevEnvironment, showBalloonMessage } from "../../engine/debug";
|
|
6
|
+
import { isSafari } from "../../engine/engine_utils";
|
|
7
|
+
import { ObjectRaycaster, Raycaster } from "../ui/Raycaster";
|
|
8
|
+
import { tryGetUIComponent } from "../ui/Utils";
|
|
9
|
+
|
|
10
|
+
export enum OpenURLMode {
|
|
11
|
+
NewTab = 0,
|
|
12
|
+
SameTab = 1,
|
|
13
|
+
NewWindow = 2
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class OpenURL extends Behaviour implements IPointerClickHandler {
|
|
17
|
+
|
|
18
|
+
@serializable()
|
|
19
|
+
clickable: boolean = true;
|
|
20
|
+
|
|
21
|
+
@serializable()
|
|
22
|
+
url?: string;
|
|
23
|
+
|
|
24
|
+
@serializable()
|
|
25
|
+
mode: OpenURLMode = OpenURLMode.NewTab;
|
|
26
|
+
|
|
27
|
+
async open() {
|
|
28
|
+
if (!this.url) {
|
|
29
|
+
console.error("URL is not set", this);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
this._validateUrl();
|
|
34
|
+
|
|
35
|
+
if (isDevEnvironment()) showBalloonMessage("Open URL: " + this.url)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
switch (this.mode) {
|
|
39
|
+
case OpenURLMode.NewTab:
|
|
40
|
+
if (isSafari()) {
|
|
41
|
+
globalThis.open(this.url, "_blank");
|
|
42
|
+
}
|
|
43
|
+
else
|
|
44
|
+
globalThis.open(this.url, "_blank");
|
|
45
|
+
break;
|
|
46
|
+
case OpenURLMode.SameTab:
|
|
47
|
+
if (isSafari()) {
|
|
48
|
+
globalThis.open(this.url, "_top");
|
|
49
|
+
}
|
|
50
|
+
else globalThis.open(this.url, "_self");
|
|
51
|
+
break;
|
|
52
|
+
case OpenURLMode.NewWindow:
|
|
53
|
+
if (isSafari()) {
|
|
54
|
+
globalThis.open(this.url, "_top");
|
|
55
|
+
}
|
|
56
|
+
else globalThis.open(this.url, "_new");
|
|
57
|
+
break;
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
start(): void {
|
|
63
|
+
const raycaster = this.gameObject.getComponentInParent(ObjectRaycaster);
|
|
64
|
+
if (!raycaster) this.gameObject.addNewComponent(ObjectRaycaster);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
onEnable(): void {
|
|
68
|
+
if (isSafari()) window.addEventListener("touchend", this._safariNewTabWorkaround);
|
|
69
|
+
}
|
|
70
|
+
onDisable(): void {
|
|
71
|
+
if (isSafari()) window.removeEventListener("touchend", this._safariNewTabWorkaround);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
onPointerEnter(args) {
|
|
75
|
+
if (!args.used && this.clickable)
|
|
76
|
+
this.context.input.setCursorPointer();
|
|
77
|
+
}
|
|
78
|
+
onPointerExit() {
|
|
79
|
+
if (this.clickable)
|
|
80
|
+
this.context.input.setCursorNormal();
|
|
81
|
+
}
|
|
82
|
+
onPointerClick(args: PointerEventData) {
|
|
83
|
+
if (this.clickable && !args.used && this.url?.length)
|
|
84
|
+
this.open();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private _safariNewTabWorkaround = () => {
|
|
88
|
+
if (!this.clickable || !this.url?.length) return;
|
|
89
|
+
// we only need this workaround for opening a new tab
|
|
90
|
+
if (this.mode === OpenURLMode.SameTab) return;
|
|
91
|
+
// When we process the click directly in the browser event we can open a new tab
|
|
92
|
+
// by emitting a link attribute and calling onClick
|
|
93
|
+
const raycaster = this.gameObject.getComponentInParent(Raycaster);
|
|
94
|
+
if (raycaster) {
|
|
95
|
+
const hits = raycaster.performRaycast();
|
|
96
|
+
if (!hits) return;
|
|
97
|
+
for (const hit of hits) {
|
|
98
|
+
if (hit.object === this.gameObject || tryGetUIComponent(hit.object)?.gameObject === this.gameObject) {
|
|
99
|
+
this._validateUrl();
|
|
100
|
+
var a = document.createElement('a') as HTMLAnchorElement;
|
|
101
|
+
a.setAttribute("target", "_blank");
|
|
102
|
+
a.setAttribute("href", this.url);
|
|
103
|
+
a.click();
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private _validateUrl() {
|
|
111
|
+
if (!this.url) return;
|
|
112
|
+
if (this.url.startsWith("www.")) {
|
|
113
|
+
if (isDevEnvironment()) {
|
|
114
|
+
console.warn("URL is not valid, adding https:// to the start of the URL", this.url);
|
|
115
|
+
}
|
|
116
|
+
this.url = "https://" + this.url;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|