@needle-tools/engine 2.35.3-pre → 2.35.5-pre
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.d.ts +58 -34
- package/dist/needle-engine.js +394 -343
- package/dist/needle-engine.js.map +4 -4
- package/dist/needle-engine.min.js +96 -45
- package/dist/needle-engine.min.js.map +4 -4
- package/lib/engine/api.d.ts +3 -0
- package/lib/engine/api.js +3 -0
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/debug/debug.d.ts +3 -0
- package/lib/engine/debug/debug.js +8 -0
- package/lib/engine/debug/debug.js.map +1 -0
- package/lib/engine/debug/debug_overlay.d.ts +7 -0
- package/lib/engine/debug/debug_overlay.js +202 -0
- package/lib/engine/debug/debug_overlay.js.map +1 -0
- package/lib/engine/engine.js +1 -1
- package/lib/engine/engine.js.map +1 -1
- package/lib/engine/engine_element_loading.js +19 -8
- package/lib/engine/engine_element_loading.js.map +1 -1
- package/lib/engine/engine_networking.js +4 -0
- package/lib/engine/engine_networking.js.map +1 -1
- package/lib/engine/engine_networking_utils.d.ts +1 -0
- package/lib/engine/engine_networking_utils.js +3 -0
- package/lib/engine/engine_networking_utils.js.map +1 -1
- package/lib/engine/engine_serialization_core.js +35 -0
- package/lib/engine/engine_serialization_core.js.map +1 -1
- package/lib/engine/engine_types.d.ts +5 -1
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_render_objects.d.ts +2 -2
- package/lib/engine/extensions/NEEDLE_render_objects.js +2 -2
- package/lib/engine/extensions/NEEDLE_render_objects.js.map +1 -1
- package/lib/engine-components/AudioSource.d.ts +1 -1
- package/lib/engine-components/AudioSource.js +2 -2
- package/lib/engine-components/AudioSource.js.map +1 -1
- package/lib/engine-components/Component.js +4 -2
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/Renderer.d.ts +8 -3
- package/lib/engine-components/Renderer.js +9 -1
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/WebXRController.js +6 -2
- package/lib/engine-components/WebXRController.js.map +1 -1
- package/lib/engine-components/js-extensions/ExtensionUtils.js +1 -1
- package/lib/engine-components/js-extensions/ExtensionUtils.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/api.ts +3 -0
- package/src/engine/debug/debug.ts +9 -0
- package/src/engine/debug/debug_overlay.ts +217 -0
- package/src/engine/engine.ts +1 -1
- package/src/engine/engine_element_loading.ts +20 -9
- package/src/engine/engine_networking.ts +7 -3
- package/src/engine/engine_networking_utils.ts +4 -0
- package/src/engine/engine_serialization_core.ts +34 -0
- package/src/engine/engine_types.ts +6 -1
- package/src/engine/extensions/NEEDLE_render_objects.ts +4 -4
- package/src/engine-components/AudioSource.ts +3 -3
- package/src/engine-components/Component.ts +4 -2
- package/src/engine-components/Renderer.ts +737 -724
- package/src/engine-components/WebXRController.ts +6 -2
- package/src/engine-components/js-extensions/ExtensionUtils.ts +1 -1
- package/lib/engine/debug/error_overlay.d.ts +0 -1
- package/lib/engine/debug/error_overlay.js +0 -114
- package/lib/engine/debug/error_overlay.js.map +0 -1
- package/src/engine/debug/error_overlay.ts +0 -126
|
@@ -13,7 +13,7 @@ import * as utils from "../engine/engine_three_utils"
|
|
|
13
13
|
import { Interactable, UsageMarker } from "./Interactable";
|
|
14
14
|
import { InstancingUtil } from "../engine/engine_instancing";
|
|
15
15
|
import { Rigidbody } from "./RigidBody";
|
|
16
|
-
import { delay, getParam } from "../engine/engine_utils";
|
|
16
|
+
import { delay, getParam, getPath } from "../engine/engine_utils";
|
|
17
17
|
import { UIRaycastUtils } from "./ui/RaycastUtils";
|
|
18
18
|
import { RaycastResult } from "cannon-es";
|
|
19
19
|
|
|
@@ -79,7 +79,9 @@ export class WebXRController extends Behaviour {
|
|
|
79
79
|
ctrl.controllerGrip.add(ctrl.controllerModel);
|
|
80
80
|
|
|
81
81
|
ctrl.hand = context.renderer.xr.getHand(index);
|
|
82
|
-
|
|
82
|
+
const hand = new OculusHandModel(ctrl.hand);
|
|
83
|
+
hand["path"] = "/" + getPath(owner.sourceId, "/assets/");
|
|
84
|
+
ctrl.hand.add(hand);
|
|
83
85
|
ctrl.hand.traverse(x => x.layers.set(2));
|
|
84
86
|
|
|
85
87
|
ctrl.handPointerModel = new OculusHandPointerModel(ctrl.hand, ctrl.controller);
|
|
@@ -800,6 +802,8 @@ export class AttachedObject {
|
|
|
800
802
|
console.warn("Prevented taking object that is not interactable", candidate);
|
|
801
803
|
return null;
|
|
802
804
|
}
|
|
805
|
+
else candidate = interactable.gameObject;
|
|
806
|
+
|
|
803
807
|
|
|
804
808
|
let objectToAttach = candidate;
|
|
805
809
|
const sync = GameObject.getComponentInParent(candidate, SyncedTransform);
|
|
@@ -20,7 +20,7 @@ export function applyPrototypeExtensions<T>(obj: any, prototype : Constructor<T>
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export function registerPrototypeExtensions<T>(type: Constructor<T>) {
|
|
23
|
-
console.log("Register", type.prototype.constructor.name);
|
|
23
|
+
// console.log("Register", type.prototype.constructor.name);
|
|
24
24
|
const handler = createPrototypeExtensionHandler(type.prototype);
|
|
25
25
|
handlers.set(type, handler);
|
|
26
26
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function makeErrorsVisibleForDevelopment(): void;
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { getParam } from "../engine_utils";
|
|
2
|
-
import { isLocalNetwork } from "../engine_networking_utils";
|
|
3
|
-
import { Context } from "../engine_setup";
|
|
4
|
-
import { arContainerClassName } from "../engine_element_overlay";
|
|
5
|
-
const debug = getParam("debugdebug");
|
|
6
|
-
const hide = getParam("noerrors");
|
|
7
|
-
const errorContainer = new Map();
|
|
8
|
-
const locationRegex = new RegExp(" at .+\/(.+?\.ts)", "g");
|
|
9
|
-
var LogType;
|
|
10
|
-
(function (LogType) {
|
|
11
|
-
LogType[LogType["Log"] = 0] = "Log";
|
|
12
|
-
LogType[LogType["Warn"] = 1] = "Warn";
|
|
13
|
-
LogType[LogType["Error"] = 2] = "Error";
|
|
14
|
-
})(LogType || (LogType = {}));
|
|
15
|
-
export function makeErrorsVisibleForDevelopment() {
|
|
16
|
-
if (hide)
|
|
17
|
-
return;
|
|
18
|
-
if (isLocalNetwork()) {
|
|
19
|
-
if (debug)
|
|
20
|
-
console.log(window.location.hostname);
|
|
21
|
-
const error = console.error;
|
|
22
|
-
console.error = (...args) => {
|
|
23
|
-
error.apply(console, args);
|
|
24
|
-
handleLog(LogType.Error, args, null, null);
|
|
25
|
-
};
|
|
26
|
-
window.addEventListener("error", (event) => {
|
|
27
|
-
if (!event)
|
|
28
|
-
return;
|
|
29
|
-
handleLog(LogType.Error, event.error, event.filename, event.lineno);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function handleLog(type, message, _file, _line) {
|
|
34
|
-
const context = Context.Current;
|
|
35
|
-
if (type === LogType.Error) {
|
|
36
|
-
const domElement = context?.domElement ?? document.querySelector("needle-engine");
|
|
37
|
-
if (!domElement)
|
|
38
|
-
return;
|
|
39
|
-
if (Array.isArray(message)) {
|
|
40
|
-
message = message.join(" ");
|
|
41
|
-
}
|
|
42
|
-
appendErrorMessageToDomElement(domElement, message);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function getLocation(err) {
|
|
46
|
-
const location = err.stack;
|
|
47
|
-
console.log(location);
|
|
48
|
-
if (location) {
|
|
49
|
-
locationRegex.exec(location);
|
|
50
|
-
const match = locationRegex.exec(location);
|
|
51
|
-
return match ? match[1] : "";
|
|
52
|
-
}
|
|
53
|
-
return "";
|
|
54
|
-
}
|
|
55
|
-
function getErrorContainer(domElement) {
|
|
56
|
-
if (errorContainer.has(domElement)) {
|
|
57
|
-
return errorContainer.get(domElement);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
const container = document.createElement("div");
|
|
61
|
-
container.classList.add(arContainerClassName);
|
|
62
|
-
container.classList.add("desktop");
|
|
63
|
-
container.style.position = "absolute";
|
|
64
|
-
container.style.top = "0";
|
|
65
|
-
container.style.left = "0";
|
|
66
|
-
container.style.margin = "5px";
|
|
67
|
-
container.style.width = "calc(100% - 10px)";
|
|
68
|
-
container.style.zIndex = "1000";
|
|
69
|
-
container.style.pointerEvents = "none";
|
|
70
|
-
container.style.display = "flex";
|
|
71
|
-
container.style.alignItems = "end";
|
|
72
|
-
container.style.flexDirection = "column";
|
|
73
|
-
container.style.color = "white";
|
|
74
|
-
container.style.overflow = "auto";
|
|
75
|
-
domElement.appendChild(container);
|
|
76
|
-
errorContainer.set(domElement, container);
|
|
77
|
-
return container;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function appendErrorMessageToDomElement(element, msg, location) {
|
|
81
|
-
const container = getErrorContainer(element);
|
|
82
|
-
if (container.childElementCount >= 5) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const errorElement = document.createElement("div");
|
|
86
|
-
container.appendChild(errorElement);
|
|
87
|
-
errorElement.style.display = "flex";
|
|
88
|
-
errorElement.style.alignItems = "start";
|
|
89
|
-
errorElement.style.flexDirection = "row";
|
|
90
|
-
// errorElement.style.justifyContent = "space-between";
|
|
91
|
-
// errorElement.style.width = "100%";
|
|
92
|
-
errorElement.style.padding = ".2em";
|
|
93
|
-
errorElement.style.backgroundColor = "rgba(0,0,0,1)";
|
|
94
|
-
errorElement.style.marginBottom = "2px";
|
|
95
|
-
errorElement.style.borderRadius = "8px";
|
|
96
|
-
errorElement.style.color = "#ff5555";
|
|
97
|
-
errorElement.style.fontWeight = "bold";
|
|
98
|
-
errorElement.title = "Open developer console to debug";
|
|
99
|
-
errorElement.style.pointerEvents = "all";
|
|
100
|
-
errorElement.style.userSelect = "text";
|
|
101
|
-
const messageElement = document.createElement("div");
|
|
102
|
-
const locationElement = document.createElement("div");
|
|
103
|
-
errorElement.appendChild(messageElement);
|
|
104
|
-
errorElement.appendChild(locationElement);
|
|
105
|
-
if (msg.length > 200) {
|
|
106
|
-
msg = msg.substring(0, 200) + "...";
|
|
107
|
-
}
|
|
108
|
-
messageElement.innerText = msg; // "Javascript error: please open the browser developer console to debug";// + msg;
|
|
109
|
-
locationElement.innerText = location || "";
|
|
110
|
-
setTimeout(() => {
|
|
111
|
-
container.removeChild(errorElement);
|
|
112
|
-
}, 10000);
|
|
113
|
-
}
|
|
114
|
-
//# sourceMappingURL=error_overlay.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error_overlay.js","sourceRoot":"","sources":["../../../../engine/debug/error_overlay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,KAAK,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;AACrC,MAAM,IAAI,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;AAElC,MAAM,cAAc,GAAkC,IAAI,GAAG,EAAE,CAAC;AAChE,MAAM,aAAa,GAAG,IAAI,MAAM,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC;AAE9D,IAAK,OAIJ;AAJD,WAAK,OAAO;IACR,mCAAG,CAAA;IACH,qCAAI,CAAA;IACJ,uCAAK,CAAA;AACT,CAAC,EAJI,OAAO,KAAP,OAAO,QAIX;AAED,MAAM,UAAU,+BAA+B;IAC3C,IAAI,IAAI;QAAE,OAAO;IACjB,IAAI,cAAc,EAAE,EAAE;QAClB,IAAI,KAAK;YACL,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC1C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC5B,OAAO,CAAC,KAAK,GAAG,CAAC,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;IAC1C,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG,EAAE;QAClB,GAAG,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC;KACvC;IACD,cAAc,CAAC,SAAS,GAAG,GAAG,CAAC,CAAA,mFAAmF;IAClH,eAAe,CAAC,SAAS,GAAG,QAAQ,IAAI,EAAE,CAAC;IAC3C,UAAU,CAAC,GAAG,EAAE;QACZ,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IACxC,CAAC,EAAE,KAAK,CAAC,CAAC;AACd,CAAC"}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { getParam } from "../engine_utils";
|
|
2
|
-
import { isLocalNetwork } from "../engine_networking_utils";
|
|
3
|
-
import { Context } from "../engine_setup";
|
|
4
|
-
import { arContainerClassName } from "../engine_element_overlay";
|
|
5
|
-
|
|
6
|
-
const debug = getParam("debugdebug");
|
|
7
|
-
const hide = getParam("noerrors");
|
|
8
|
-
|
|
9
|
-
const errorContainer: Map<HTMLElement, HTMLElement> = new Map();
|
|
10
|
-
const locationRegex = new RegExp(" at .+\/(.+?\.ts)", "g");
|
|
11
|
-
|
|
12
|
-
enum LogType {
|
|
13
|
-
Log,
|
|
14
|
-
Warn,
|
|
15
|
-
Error
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function makeErrorsVisibleForDevelopment() {
|
|
19
|
-
if (hide) return;
|
|
20
|
-
if (isLocalNetwork()) {
|
|
21
|
-
if (debug)
|
|
22
|
-
console.log(window.location.hostname);
|
|
23
|
-
const error = console.error;
|
|
24
|
-
console.error = (...args: any[]) => {
|
|
25
|
-
error.apply(console, args);
|
|
26
|
-
handleLog(LogType.Error, args, null, null);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
window.addEventListener("error", (event) => {
|
|
30
|
-
if (!event) return;
|
|
31
|
-
handleLog(LogType.Error, event.error, event.filename, event.lineno);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
function handleLog(type: LogType, message: string | any[], _file: string | null, _line: number | null) {
|
|
39
|
-
|
|
40
|
-
const context = Context.Current;
|
|
41
|
-
if (type === LogType.Error) {
|
|
42
|
-
const domElement = context?.domElement ?? document.querySelector("needle-engine");
|
|
43
|
-
if(!domElement) return;
|
|
44
|
-
if (Array.isArray(message)) {
|
|
45
|
-
message = message.join(" ");
|
|
46
|
-
}
|
|
47
|
-
appendErrorMessageToDomElement(domElement, message);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
function getLocation(err: Error): string {
|
|
54
|
-
const location = err.stack;
|
|
55
|
-
console.log(location);
|
|
56
|
-
if (location) {
|
|
57
|
-
locationRegex.exec(location);
|
|
58
|
-
const match = locationRegex.exec(location);
|
|
59
|
-
return match ? match[1] : "";
|
|
60
|
-
}
|
|
61
|
-
return "";
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
function getErrorContainer(domElement: HTMLElement): HTMLElement {
|
|
67
|
-
if (errorContainer.has(domElement)) {
|
|
68
|
-
return errorContainer.get(domElement)!;
|
|
69
|
-
} else {
|
|
70
|
-
const container = document.createElement("div");
|
|
71
|
-
container.classList.add(arContainerClassName);
|
|
72
|
-
container.classList.add("desktop");
|
|
73
|
-
container.style.position = "absolute";
|
|
74
|
-
container.style.top = "0";
|
|
75
|
-
container.style.left = "0";
|
|
76
|
-
container.style.margin = "5px";
|
|
77
|
-
container.style.width = "calc(100% - 10px)";
|
|
78
|
-
container.style.zIndex = "1000";
|
|
79
|
-
container.style.pointerEvents = "none";
|
|
80
|
-
container.style.display = "flex";
|
|
81
|
-
container.style.alignItems = "end";
|
|
82
|
-
container.style.flexDirection = "column";
|
|
83
|
-
container.style.color = "white";
|
|
84
|
-
container.style.overflow = "auto";
|
|
85
|
-
domElement.appendChild(container);
|
|
86
|
-
errorContainer.set(domElement, container);
|
|
87
|
-
return container;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
function appendErrorMessageToDomElement(element: HTMLElement, msg: string, location?: string) {
|
|
93
|
-
const container = getErrorContainer(element);
|
|
94
|
-
if (container.childElementCount >= 5) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const errorElement = document.createElement("div");
|
|
98
|
-
container.appendChild(errorElement);
|
|
99
|
-
errorElement.style.display = "flex";
|
|
100
|
-
errorElement.style.alignItems = "start";
|
|
101
|
-
errorElement.style.flexDirection = "row";
|
|
102
|
-
// errorElement.style.justifyContent = "space-between";
|
|
103
|
-
// errorElement.style.width = "100%";
|
|
104
|
-
errorElement.style.padding = ".2em";
|
|
105
|
-
errorElement.style.backgroundColor = "rgba(0,0,0,1)";
|
|
106
|
-
errorElement.style.marginBottom = "2px";
|
|
107
|
-
errorElement.style.borderRadius = "8px";
|
|
108
|
-
errorElement.style.color = "#ff5555";
|
|
109
|
-
errorElement.style.fontWeight = "bold";
|
|
110
|
-
errorElement.title = "Open developer console to debug";
|
|
111
|
-
errorElement.style.pointerEvents = "all";
|
|
112
|
-
errorElement.style.userSelect = "text";
|
|
113
|
-
|
|
114
|
-
const messageElement = document.createElement("div");
|
|
115
|
-
const locationElement = document.createElement("div");
|
|
116
|
-
errorElement.appendChild(messageElement);
|
|
117
|
-
errorElement.appendChild(locationElement);
|
|
118
|
-
if (msg.length > 200) {
|
|
119
|
-
msg = msg.substring(0, 200) + "...";
|
|
120
|
-
}
|
|
121
|
-
messageElement.innerText = msg;// "Javascript error: please open the browser developer console to debug";// + msg;
|
|
122
|
-
locationElement.innerText = location || "";
|
|
123
|
-
setTimeout(() => {
|
|
124
|
-
container.removeChild(errorElement);
|
|
125
|
-
}, 10000);
|
|
126
|
-
}
|