@needle-tools/engine 2.35.0-pre → 2.35.1-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 +5 -0
- package/dist/needle-engine.d.ts +199 -179
- package/dist/needle-engine.js +337 -337
- package/dist/needle-engine.js.map +4 -4
- package/dist/needle-engine.min.js +35 -35
- package/dist/needle-engine.min.js.map +4 -4
- package/lib/engine/engine_components.d.ts +12 -11
- package/lib/engine/engine_components.js +41 -24
- package/lib/engine/engine_components.js.map +1 -1
- package/lib/engine/engine_element.js +2 -1
- package/lib/engine/engine_element.js.map +1 -1
- package/lib/engine/engine_element_loading.js +4 -1
- package/lib/engine/engine_element_loading.js.map +1 -1
- package/lib/engine/engine_networking.d.ts +5 -0
- package/lib/engine/engine_networking.js +6 -4
- package/lib/engine/engine_networking.js.map +1 -1
- package/lib/engine/engine_physics.d.ts +6 -1
- package/lib/engine/engine_physics.js +12 -2
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_types.d.ts +7 -2
- package/lib/engine/engine_types.js +6 -5
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine-components/Collider.d.ts +3 -1
- package/lib/engine-components/Collider.js +11 -0
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Component.d.ts +7 -7
- package/lib/engine-components/Component.js +8 -8
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/Networking.d.ts +3 -1
- package/lib/engine-components/Networking.js +3 -0
- package/lib/engine-components/Networking.js.map +1 -1
- package/lib/engine-components/js-extensions/Object3D.js +13 -11
- package/lib/engine-components/js-extensions/Object3D.js.map +1 -1
- package/lib/engine-components/ui/EventSystem.js +2 -2
- package/lib/engine-components/ui/EventSystem.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/engine_components.ts +42 -27
- package/src/engine/engine_element.ts +2 -1
- package/src/engine/engine_element_loading.ts +5 -1
- package/src/engine/engine_networking.ts +12 -4
- package/src/engine/engine_physics.ts +34 -4
- package/src/engine/engine_types.ts +14 -6
- package/src/engine-components/Collider.ts +17 -2
- package/src/engine-components/Component.ts +21 -22
- package/src/engine-components/Networking.ts +6 -1
- package/src/engine-components/js-extensions/Object3D.ts +17 -15
- package/src/engine-components/ui/EventSystem.ts +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Object3D } from "three";
|
|
1
|
+
import { Object3D, Scene } from "three";
|
|
2
2
|
import { Constructor, ConstructorConcrete, IComponent as Component, IComponent, IGameObject } from "./engine_types";
|
|
3
3
|
import { Context, registerComponent } from "./engine_setup";
|
|
4
4
|
import { getParam } from "./engine_utils";
|
|
@@ -28,7 +28,7 @@ export function removeComponent(go: Object3D, componentInstance: IComponent) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export function getOrAddComponent<T extends IComponent>(go: Object3D, typeName: ConstructorConcrete<T>): T {
|
|
31
|
-
const comp = getComponent(
|
|
31
|
+
const comp = getComponent(go, typeName);
|
|
32
32
|
if (comp) return comp;
|
|
33
33
|
const newInstance = new typeName();
|
|
34
34
|
return addNewComponentInstance(go, newInstance) as unknown as T;
|
|
@@ -53,7 +53,7 @@ export function addNewComponentInstance<T extends IComponent>(obj: Object3D, com
|
|
|
53
53
|
return componentInstance;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
export function moveComponentInstance(
|
|
56
|
+
export function moveComponentInstance(obj: Object3D, componentInstance: IComponent) {
|
|
57
57
|
if (componentInstance.gameObject === obj) return;
|
|
58
58
|
// TODO: update raycast array
|
|
59
59
|
if (componentInstance.gameObject && componentInstance.gameObject.userData.components) {
|
|
@@ -85,13 +85,19 @@ export function destroyComponentInstance(componentInstance: IComponent) {
|
|
|
85
85
|
// console.log("destroyed", index, componentInstance);
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
function onGetComponent<T>(obj: Object3D | null | undefined, componentType: Constructor<T>, arr?: T[]) {
|
|
89
|
+
if (obj === null || obj === undefined) return;
|
|
90
|
+
if (!obj.isObject3D) {
|
|
91
|
+
console.error("Object is not object3D");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
89
94
|
if (!(obj?.userData?.components)) return null;
|
|
90
95
|
if (debug)
|
|
91
96
|
console.log("FIND", componentType);
|
|
97
|
+
if (componentType === undefined || componentType === null) return;
|
|
92
98
|
for (let i = 0; i < obj.userData.components.length; i++) {
|
|
93
99
|
const component = obj.userData.components[i];
|
|
94
|
-
if (componentType === null || component.constructor.name === componentType
|
|
100
|
+
if (componentType === null || component.constructor.name === componentType["name"] || component.constructor.name === componentType) {
|
|
95
101
|
if (debug)
|
|
96
102
|
console.log("MATCH BY NAME", component)
|
|
97
103
|
if (arr) arr.push(component);
|
|
@@ -116,59 +122,63 @@ export function onGetComponent<T>(componentType: Constructor<T>, obj: Object3D,
|
|
|
116
122
|
return arr;
|
|
117
123
|
}
|
|
118
124
|
|
|
119
|
-
export function getComponent<T>(componentType: Constructor<T
|
|
120
|
-
return onGetComponent(
|
|
125
|
+
export function getComponent<T>(obj: Object3D, componentType: Constructor<T>) {
|
|
126
|
+
return onGetComponent(obj, componentType);
|
|
121
127
|
}
|
|
122
128
|
|
|
123
|
-
export function getComponents(
|
|
129
|
+
export function getComponents<T>(obj: Object3D, componentType: Constructor<T>, arr?: T[] | null): T[] {
|
|
124
130
|
if (!arr) arr = [];
|
|
125
|
-
return onGetComponent(
|
|
131
|
+
return onGetComponent(obj, componentType, arr);
|
|
126
132
|
}
|
|
127
133
|
|
|
128
|
-
export function getComponentInChildren(
|
|
129
|
-
const res = getComponent(
|
|
134
|
+
export function getComponentInChildren<T>(obj: Object3D, componentType: Constructor<T>, includeInactive?: boolean) {
|
|
135
|
+
const res = getComponent(obj, componentType);
|
|
130
136
|
if (includeInactive === false && res.enabled === false) return null;
|
|
131
137
|
if (res) return res;
|
|
132
138
|
for (let i = 0; i < obj?.children?.length; i++) {
|
|
133
|
-
const res = getComponentInChildren(
|
|
139
|
+
const res = getComponentInChildren(obj.children[i], componentType);
|
|
134
140
|
if (res) return res;
|
|
135
141
|
}
|
|
136
142
|
return null;
|
|
137
143
|
}
|
|
138
144
|
|
|
139
|
-
export function getComponentsInChildren<T
|
|
145
|
+
export function getComponentsInChildren<T>(obj: Object3D, componentType: Constructor<T>, arr?: T[]) {
|
|
140
146
|
if (!arr) arr = [];
|
|
141
|
-
getComponents(
|
|
147
|
+
getComponents(obj, componentType, arr);
|
|
142
148
|
for (let i = 0; i < obj?.children?.length; i++) {
|
|
143
|
-
getComponentsInChildren(
|
|
149
|
+
getComponentsInChildren(obj.children[i], componentType, arr);
|
|
144
150
|
}
|
|
145
151
|
return arr;
|
|
146
152
|
}
|
|
147
153
|
|
|
148
|
-
export function getComponentInParent(
|
|
154
|
+
export function getComponentInParent<T>(obj: Object3D, componentType: Constructor<T>) {
|
|
149
155
|
if (!obj) return null;
|
|
150
156
|
if (Array.isArray(obj)) {
|
|
151
157
|
for (let i = 0; i < obj.length; i++) {
|
|
152
158
|
const o = tryGetObject(obj[i]);
|
|
153
|
-
const res = getComponentInParent(
|
|
159
|
+
const res = getComponentInParent(o, componentType);
|
|
154
160
|
if (res) return res;
|
|
155
161
|
}
|
|
156
162
|
return null;
|
|
157
163
|
}
|
|
158
164
|
// console.log(obj);
|
|
159
|
-
const res = getComponent(
|
|
165
|
+
const res = getComponent(obj, componentType);
|
|
160
166
|
if (res) return res;
|
|
161
|
-
|
|
167
|
+
if (obj.parent)
|
|
168
|
+
return getComponentInParent(obj.parent, componentType);
|
|
169
|
+
return null;
|
|
162
170
|
}
|
|
163
171
|
|
|
164
|
-
export function getComponentsInParent(
|
|
172
|
+
export function getComponentsInParent<T>(obj: Object3D, componentType: Constructor<T>, arr?: T[] | null): T[] {
|
|
165
173
|
if (!arr) arr = [];
|
|
166
174
|
if (!obj) return arr;
|
|
167
|
-
getComponents(
|
|
168
|
-
|
|
175
|
+
getComponents(obj, componentType, arr);
|
|
176
|
+
if (obj.parent)
|
|
177
|
+
return getComponentsInParent(obj.parent, componentType, arr);
|
|
178
|
+
return arr;
|
|
169
179
|
}
|
|
170
180
|
|
|
171
|
-
export function findObjectOfType(type
|
|
181
|
+
export function findObjectOfType<T>(type: Constructor<T>, contextOrScene: Object3D | { scene: Scene }, includeInactive) {
|
|
172
182
|
if (!type) return null;
|
|
173
183
|
if (!contextOrScene) {
|
|
174
184
|
contextOrScene = Context.Current;
|
|
@@ -177,18 +187,23 @@ export function findObjectOfType(type, contextOrScene, includeInactive) {
|
|
|
177
187
|
return null;
|
|
178
188
|
}
|
|
179
189
|
}
|
|
180
|
-
|
|
190
|
+
|
|
191
|
+
let scene = contextOrScene as Scene;
|
|
192
|
+
if (!scene.isScene) scene = (contextOrScene as { scene: Scene })?.scene;
|
|
193
|
+
if (!scene) return null;
|
|
194
|
+
|
|
195
|
+
// const scene = contextOrScene.isScene === true || contextOrScene.isObject3D === true ? contextOrScene : contextOrScene?.scene;
|
|
181
196
|
for (const i in scene.children) {
|
|
182
197
|
const child = scene.children[i];
|
|
183
198
|
if (includeInactive === false && child[activeInHierarchyFieldName] === false) continue;
|
|
184
199
|
if (child.constructor == type) return child;
|
|
185
|
-
const res = getComponentInChildren(
|
|
200
|
+
const res = getComponentInChildren(child, type);
|
|
186
201
|
if (res) return res;
|
|
187
202
|
}
|
|
188
203
|
return null;
|
|
189
204
|
}
|
|
190
205
|
|
|
191
|
-
export function findObjectsOfType(type
|
|
206
|
+
export function findObjectsOfType<T>(type: Constructor<T>, array: T[], contextOrScene) : T[] {
|
|
192
207
|
if (!type) return array;
|
|
193
208
|
if (!contextOrScene) {
|
|
194
209
|
contextOrScene = Context.Current;
|
|
@@ -202,7 +217,7 @@ export function findObjectsOfType(type, array, contextOrScene) {
|
|
|
202
217
|
for (const i in scene.children) {
|
|
203
218
|
const child = scene.children[i];
|
|
204
219
|
if (child.constructor == type) return child;
|
|
205
|
-
getComponentsInChildren(
|
|
220
|
+
getComponentsInChildren(child, type, array);
|
|
206
221
|
}
|
|
207
222
|
return array;
|
|
208
223
|
}
|
|
@@ -162,13 +162,14 @@ export class EngineElement extends HTMLElement {
|
|
|
162
162
|
if (fn) {
|
|
163
163
|
this.classList.add("loading");
|
|
164
164
|
console.log("Needle Engine: Begin loading", alias ?? "");
|
|
165
|
+
const allowOverridingDefaultLoading = false;
|
|
165
166
|
// default loading can be overriden by calling preventDefault in the onload start event
|
|
166
167
|
const useDefaultLoading = this.dispatchEvent(new CustomEvent("loadstart", {
|
|
167
168
|
detail: {
|
|
168
169
|
context: this._context,
|
|
169
170
|
alias: alias
|
|
170
171
|
},
|
|
171
|
-
cancelable:
|
|
172
|
+
cancelable: allowOverridingDefaultLoading
|
|
172
173
|
}));
|
|
173
174
|
if (!this._loadingView && useDefaultLoading)
|
|
174
175
|
this._loadingView = new EngineLoadingView(this);
|
|
@@ -127,6 +127,8 @@ export class EngineLoadingView implements ILoadingViewHandler {
|
|
|
127
127
|
|
|
128
128
|
private createLoadingElement(existing?: HTMLElement): HTMLElement {
|
|
129
129
|
this._loadingElement = existing || document.createElement("div");
|
|
130
|
+
this._loadingElement.style.width = "100%";
|
|
131
|
+
|
|
130
132
|
const className = this._loadingElementOptions?.className ?? "loading";
|
|
131
133
|
this._loadingElement.classList.add(className);
|
|
132
134
|
if (this._loadingElementOptions?.additionalClasses) {
|
|
@@ -141,7 +143,7 @@ export class EngineLoadingView implements ILoadingViewHandler {
|
|
|
141
143
|
}
|
|
142
144
|
|
|
143
145
|
const loadingBarContainer = document.createElement("div");
|
|
144
|
-
const maxWidth =
|
|
146
|
+
const maxWidth = 30;
|
|
145
147
|
loadingBarContainer.style.display = "flex";
|
|
146
148
|
loadingBarContainer.style.width = maxWidth + "%";
|
|
147
149
|
loadingBarContainer.style.height = "2px";
|
|
@@ -171,6 +173,8 @@ export class EngineLoadingView implements ILoadingViewHandler {
|
|
|
171
173
|
messageContainer.style.fontSize = ".8em";
|
|
172
174
|
messageContainer.style.paddingTop = ".5em";
|
|
173
175
|
messageContainer.style.color = "rgba(255,255,255,.5)";
|
|
176
|
+
// messageContainer.style.border = "1px solid rgba(255,255,255,.1)";
|
|
177
|
+
messageContainer.style.justifyContent = "center";
|
|
174
178
|
this._loadingElement.appendChild(messageContainer);
|
|
175
179
|
|
|
176
180
|
return this._loadingElement;
|
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
let serverUrl = 'wss://needle-tiny-starter.glitch.me/socket';
|
|
5
5
|
|
|
6
6
|
import { Websocket, WebsocketBuilder } from 'websocket-ts';
|
|
7
|
-
import {
|
|
8
|
-
import { Networking } from '../engine-components/Networking';
|
|
7
|
+
// import { Networking } from '../engine-components/Networking';
|
|
9
8
|
import { Context } from './engine_setup';
|
|
10
9
|
import * as utils from "./engine_utils";
|
|
11
10
|
import * as flatbuffers from 'flatbuffers';
|
|
@@ -16,6 +15,9 @@ import { IModel, INetworkConnection, SendQueue } from './engine_networking_types
|
|
|
16
15
|
export const debugNet = utils.getParam("debugnet") ? true : false;
|
|
17
16
|
export const debugOwner = debugNet || utils.getParam("debugowner") ? true : false;
|
|
18
17
|
|
|
18
|
+
export interface INetworkingWebsocketUrlProvider {
|
|
19
|
+
getWebsocketUrl() : string | null;
|
|
20
|
+
}
|
|
19
21
|
|
|
20
22
|
export declare interface IConnectionData {
|
|
21
23
|
id: string;
|
|
@@ -384,14 +386,20 @@ export class NetworkConnection implements INetworkConnection {
|
|
|
384
386
|
}
|
|
385
387
|
}
|
|
386
388
|
|
|
389
|
+
private netWebSocketUrlProvider? : INetworkingWebsocketUrlProvider;
|
|
390
|
+
|
|
391
|
+
public registerProvider(prov : INetworkingWebsocketUrlProvider){
|
|
392
|
+
this.netWebSocketUrlProvider = prov;
|
|
393
|
+
}
|
|
394
|
+
|
|
387
395
|
public connect() {
|
|
388
396
|
if (this.connected) return;
|
|
389
397
|
if (debugNet)
|
|
390
398
|
console.log("connecting");
|
|
391
399
|
// this.channel = geckos({ port: 9208, url: 'http://127.0.0.1' });
|
|
392
400
|
// this.channel.onConnect(this.onConnectGeckosIo.bind(this));
|
|
393
|
-
const networking = GameObject.findObjectOfType(Networking, this.context, false);
|
|
394
|
-
const overrideUrl =
|
|
401
|
+
// const networking = GameObject.findObjectOfType(Networking, this.context, false);
|
|
402
|
+
const overrideUrl = this.netWebSocketUrlProvider?.getWebsocketUrl();
|
|
395
403
|
if (overrideUrl) {
|
|
396
404
|
serverUrl = overrideUrl;
|
|
397
405
|
}
|
|
@@ -4,10 +4,21 @@ import { Context } from './engine_setup';
|
|
|
4
4
|
import cannonDebugger from 'cannon-es-debugger'
|
|
5
5
|
import * as utils from "./engine_utils"
|
|
6
6
|
import * as threeutils from "./engine_three_utils"
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
IComponent as Component,
|
|
9
|
+
IGameObject as GameObject,
|
|
10
|
+
ICollider,
|
|
11
|
+
IRigidbody as Rigidbody, $physicsKey,
|
|
12
|
+
Collision, CannonCollision,
|
|
13
|
+
ICollisionContext,
|
|
14
|
+
IComponent
|
|
15
|
+
}
|
|
16
|
+
from './engine_types';
|
|
8
17
|
import { Shape } from 'cannon-es';
|
|
9
18
|
import { InstancingUtil } from './engine_instancing';
|
|
10
19
|
import { foreachComponent } from './engine_gameobject';
|
|
20
|
+
import { getComponentInChildren } from './engine_components';
|
|
21
|
+
|
|
11
22
|
|
|
12
23
|
const debugPhysics = utils.getParam("debugphysics");
|
|
13
24
|
const debugCollisions = utils.getParam("debugcollisions");
|
|
@@ -635,8 +646,10 @@ export class Physics {
|
|
|
635
646
|
// console.log("START");
|
|
636
647
|
}
|
|
637
648
|
|
|
649
|
+
private readonly collisionContext: ICollisionContext = new CollisionContext();
|
|
650
|
+
|
|
638
651
|
private raiseCollisionEvents(obj: THREE.Object3D, event: CannonCollision) {
|
|
639
|
-
const collision = new Collision(obj, event);
|
|
652
|
+
const collision = new Collision(obj, event, this.collisionContext);
|
|
640
653
|
if (debugCollisions)
|
|
641
654
|
console.log("collision between", event.contact.bi, event.contact.bj, obj, event);
|
|
642
655
|
foreachComponent(obj, (c: Component) => {
|
|
@@ -645,7 +658,7 @@ export class Physics {
|
|
|
645
658
|
|
|
646
659
|
// handle triggers
|
|
647
660
|
if (collision.collider && !collision.collider.attachedRigidbody && collision.collider.isTrigger) {
|
|
648
|
-
const collision2 = new Collision(collision.gameObject, event, true);
|
|
661
|
+
const collision2 = new Collision(collision.gameObject, event, this.collisionContext, true);
|
|
649
662
|
foreachComponent(collision.gameObject, (c: Component) => {
|
|
650
663
|
c.__internalHandleCollision(collision2, true);
|
|
651
664
|
});
|
|
@@ -659,7 +672,6 @@ export class Physics {
|
|
|
659
672
|
const obj2 = args.bodyB[$physicsKey];
|
|
660
673
|
// console.log(obj2);
|
|
661
674
|
|
|
662
|
-
|
|
663
675
|
foreachComponent(obj2, (c: Component) => {
|
|
664
676
|
c.__internalHandleExitCollisionEvent(obj1, false);
|
|
665
677
|
});
|
|
@@ -676,3 +688,21 @@ export class Physics {
|
|
|
676
688
|
}
|
|
677
689
|
|
|
678
690
|
}
|
|
691
|
+
|
|
692
|
+
export interface IColliderProvider {
|
|
693
|
+
getCollider(obj: THREE.Object3D): ICollider;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
let colliderProvider: IColliderProvider | null = null;
|
|
697
|
+
export function registerColliderProvider(prov: IColliderProvider) {
|
|
698
|
+
colliderProvider = prov;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
class CollisionContext implements ICollisionContext {
|
|
702
|
+
|
|
703
|
+
getCollider(obj: THREE.Object3D<THREE.Event>): ICollider {
|
|
704
|
+
return colliderProvider!.getCollider(obj);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
}
|
|
708
|
+
|
|
@@ -27,6 +27,7 @@ export declare interface IGameObject extends Object3D {
|
|
|
27
27
|
export interface IComponent {
|
|
28
28
|
get isComponent(): boolean;
|
|
29
29
|
|
|
30
|
+
|
|
30
31
|
gameObject: IGameObject;
|
|
31
32
|
guid: string;
|
|
32
33
|
enabled: boolean;
|
|
@@ -73,6 +74,8 @@ export interface IComponent {
|
|
|
73
74
|
|
|
74
75
|
__internalHandleCollision(col: Collision, isTriggerCollision: boolean);
|
|
75
76
|
__internalHandleExitCollisionEvent(obj: Object3D, isTriggerCollision: boolean);
|
|
77
|
+
|
|
78
|
+
get forward() : Vector3;
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
|
|
@@ -99,7 +102,7 @@ export declare interface IRenderer extends IComponent {
|
|
|
99
102
|
|
|
100
103
|
export declare interface ICollider extends IComponent {
|
|
101
104
|
get isCollider();
|
|
102
|
-
attachedRigidbody: IRigidbody;
|
|
105
|
+
attachedRigidbody: IRigidbody | null;
|
|
103
106
|
isTrigger: boolean;
|
|
104
107
|
}
|
|
105
108
|
|
|
@@ -123,6 +126,10 @@ export declare type CannonCollision = {
|
|
|
123
126
|
type: string;
|
|
124
127
|
}
|
|
125
128
|
|
|
129
|
+
export declare type ICollisionContext = {
|
|
130
|
+
getCollider(obj : Object3D) : ICollider;
|
|
131
|
+
}
|
|
132
|
+
|
|
126
133
|
export class Collision {
|
|
127
134
|
|
|
128
135
|
get __internalCollision(): CannonCollision {
|
|
@@ -136,6 +143,7 @@ export class Collision {
|
|
|
136
143
|
private readonly invert: boolean;
|
|
137
144
|
private readonly collision: CannonCollision;
|
|
138
145
|
private readonly targetBody: Body;
|
|
146
|
+
private readonly context : ICollisionContext;
|
|
139
147
|
|
|
140
148
|
readonly me: Object3D;
|
|
141
149
|
|
|
@@ -151,8 +159,7 @@ export class Collision {
|
|
|
151
159
|
private _collider?: ICollider;
|
|
152
160
|
get collider(): ICollider {
|
|
153
161
|
if (!this._collider) {
|
|
154
|
-
|
|
155
|
-
this._collider = getComponentInChildren(this.gameObject, Collider) as ICollider;
|
|
162
|
+
this._collider = this.context.getCollider(this.gameObject);
|
|
156
163
|
}
|
|
157
164
|
return this._collider;
|
|
158
165
|
}
|
|
@@ -171,10 +178,11 @@ export class Collision {
|
|
|
171
178
|
// return this._point;
|
|
172
179
|
// }
|
|
173
180
|
|
|
174
|
-
constructor(obj: Object3D, collision: CannonCollision, invert: boolean = false) {
|
|
175
|
-
this.invert = invert;
|
|
181
|
+
constructor(obj: Object3D, collision: CannonCollision, context : ICollisionContext, invert: boolean = false) {
|
|
176
182
|
this.me = obj;
|
|
177
183
|
this.collision = collision;
|
|
178
|
-
this.
|
|
184
|
+
this.context = context;
|
|
185
|
+
this.targetBody = invert ? collision.target : collision.body;
|
|
186
|
+
this.invert = invert;
|
|
179
187
|
}
|
|
180
188
|
}
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import { Behaviour } from "./Component";
|
|
2
2
|
import { Rigidbody } from "./RigidBody";
|
|
3
3
|
import { serializeable } from "../engine/engine_serialization_decorator";
|
|
4
|
-
import { Vector3 } from "three"
|
|
4
|
+
import { Event, Object3D, Vector3 } from "three"
|
|
5
5
|
import { Shape } from "cannon-es";
|
|
6
|
+
import { IColliderProvider, registerColliderProvider } from "../engine/engine_physics";
|
|
7
|
+
import { ICollider } from "../engine/engine_types";
|
|
8
|
+
import { getComponentInChildren } from "../engine/engine_components";
|
|
9
|
+
|
|
10
|
+
class ColliderProvider implements IColliderProvider {
|
|
11
|
+
getCollider(obj: Object3D): ICollider {
|
|
12
|
+
return getComponentInChildren<Collider>(obj, Collider);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
registerColliderProvider(new ColliderProvider());
|
|
16
|
+
|
|
17
|
+
export class Collider extends Behaviour implements ICollider {
|
|
18
|
+
|
|
19
|
+
get isCollider(): any {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
6
22
|
|
|
7
|
-
export class Collider extends Behaviour {
|
|
8
23
|
@serializeable(Rigidbody)
|
|
9
24
|
attachedRigidbody: Rigidbody | null = null;
|
|
10
25
|
@serializeable()
|
|
@@ -40,13 +40,13 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
public static markAsInstancedRendered(go: THREE.Object3D, instanced: boolean) {
|
|
43
|
-
markAsInstancedRendered(go, instanced);
|
|
43
|
+
markAsInstancedRendered(go, instanced);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
public static isUsingInstancing(instance: THREE.Object3D): boolean { return isUsingInstancing(instance); }
|
|
47
47
|
|
|
48
48
|
public static foreachComponent(instance: THREE.Object3D, cb: (comp: Component) => any, recursive: boolean = true): any {
|
|
49
|
-
return foreachComponent(instance, cb as (comp
|
|
49
|
+
return foreachComponent(instance, cb as (comp: IComponent) => any, recursive);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
public static instantiateSynced(instance: GameObject | Object3D | null, opts: InstantiateOptions): GameObject | null {
|
|
@@ -124,7 +124,7 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
124
124
|
}, children);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
public static addNewComponent<T
|
|
127
|
+
public static addNewComponent<T>(go: GameObject | THREE.Object3D, type: ConstructorConcrete<T>, callAwake: boolean = true): T {
|
|
128
128
|
const instance = new type();
|
|
129
129
|
//@ts-ignore
|
|
130
130
|
addNewComponentInstance(go, instance, callAwake);
|
|
@@ -135,7 +135,7 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
135
135
|
if (instance.gameObject == null) {
|
|
136
136
|
throw new Error("Did you mean to create a new component? Use addNewComponent");
|
|
137
137
|
}
|
|
138
|
-
moveComponentInstance(instance as any
|
|
138
|
+
moveComponentInstance(go, instance as any);
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
public static removeComponent(instance: Component): Component {
|
|
@@ -143,7 +143,7 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
143
143
|
return instance;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
public static getOrAddComponent<T
|
|
146
|
+
public static getOrAddComponent<T>(go: GameObject | THREE.Object3D, typeName: ConstructorConcrete<T>): T {
|
|
147
147
|
return getOrAddComponent<any>(go, typeName);
|
|
148
148
|
}
|
|
149
149
|
|
|
@@ -153,12 +153,12 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
153
153
|
// not ideal, but I dont know a good/sane way to do this otherwise
|
|
154
154
|
// const res = TypeStore.get(typeName);
|
|
155
155
|
// if(res) typeName = res;
|
|
156
|
-
return getComponent(typeName as any
|
|
156
|
+
return getComponent(go, typeName as any);
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
public static getComponents<T>(go: GameObject | THREE.Object3D | null, typeName: Constructor<T
|
|
159
|
+
public static getComponents<T>(go: GameObject | THREE.Object3D | null, typeName: Constructor<T>, arr: T[] | null = null): T[] {
|
|
160
160
|
if (go === null) return arr ?? [];
|
|
161
|
-
return getComponents(
|
|
161
|
+
return getComponents(go, typeName, arr);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
public static findByGuid(guid: string, hierarchy: THREE.Object3D): GameObject | Component | null | undefined {
|
|
@@ -166,8 +166,8 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
166
166
|
return res as GameObject | Component | null | undefined;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
public static findObjectOfType<T>(typeName: Constructor<T
|
|
170
|
-
return findObjectOfType(typeName, context, includeInactive);
|
|
169
|
+
public static findObjectOfType<T>(typeName: Constructor<T>, context?: Context | THREE.Object3D, includeInactive: boolean = true): T | null {
|
|
170
|
+
return findObjectOfType(typeName, context ?? Context.Current, includeInactive);
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
public static findObjectsOfType<T>(typeName: Constructor<T>, context?: Context | THREE.Object3D): Array<T> {
|
|
@@ -176,20 +176,20 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
176
176
|
return arr;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
public static getComponentInChildren<T>(go: GameObject | THREE.Object3D, typeName: Constructor<T>
|
|
180
|
-
return getComponentInChildren(
|
|
179
|
+
public static getComponentInChildren<T>(go: GameObject | THREE.Object3D, typeName: Constructor<T>): T | null {
|
|
180
|
+
return getComponentInChildren(go, typeName);
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
public static getComponentsInChildren<T
|
|
184
|
-
return getComponentsInChildren<T>(
|
|
183
|
+
public static getComponentsInChildren<T>(go: GameObject | THREE.Object3D, typeName: Constructor<T>, arr: T[] | null = null): Array<T> {
|
|
184
|
+
return getComponentsInChildren<T>(go, typeName, arr ?? undefined) as T[]
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
public static getComponentInParent<T>(go: GameObject | THREE.Object3D
|
|
188
|
-
return getComponentInParent(
|
|
187
|
+
public static getComponentInParent<T>(go: GameObject | THREE.Object3D, typeName: Constructor<T>): T | null {
|
|
188
|
+
return getComponentInParent(go, typeName);
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
public static getComponentsInParent<T>(go: GameObject | THREE.Object3D, typeName: Constructor<T>, arr: Array<T> | null = null): Array<T> {
|
|
192
|
-
return getComponentsInParent(
|
|
192
|
+
return getComponentsInParent(go, typeName, arr);
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
public static getAllComponents(go: GameObject | THREE.Object3D): Behaviour[] {
|
|
@@ -291,8 +291,7 @@ class Component implements IComponent, EventTarget {
|
|
|
291
291
|
return res;
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
-
private set __isActiveInHierarchy(val: boolean)
|
|
295
|
-
{
|
|
294
|
+
private set __isActiveInHierarchy(val: boolean) {
|
|
296
295
|
if (!this.gameObject) return;
|
|
297
296
|
this.gameObject[activeInHierarchyFieldName] = val;
|
|
298
297
|
}
|
|
@@ -339,7 +338,7 @@ class Component implements IComponent, EventTarget {
|
|
|
339
338
|
this.context.unregisterCoroutineUpdate(routine, evt);
|
|
340
339
|
}
|
|
341
340
|
|
|
342
|
-
public get destroyed()
|
|
341
|
+
public get destroyed(): boolean {
|
|
343
342
|
return this.__destroyed;
|
|
344
343
|
}
|
|
345
344
|
|
|
@@ -378,7 +377,7 @@ class Component implements IComponent, EventTarget {
|
|
|
378
377
|
if (this.start) this.start();
|
|
379
378
|
}
|
|
380
379
|
|
|
381
|
-
__internalEnable()
|
|
380
|
+
__internalEnable(): boolean {
|
|
382
381
|
if (this.__didEnable) return false;
|
|
383
382
|
// console.trace("INTERNAL ENABLE");
|
|
384
383
|
this.__didEnable = true;
|
|
@@ -401,7 +400,7 @@ class Component implements IComponent, EventTarget {
|
|
|
401
400
|
// console.log("destroy", this);
|
|
402
401
|
destroyComponentInstance(this as any);
|
|
403
402
|
}
|
|
404
|
-
|
|
403
|
+
|
|
405
404
|
// isActiveAndEnabled: boolean = false;
|
|
406
405
|
|
|
407
406
|
get enabled(): boolean {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { INetworkingWebsocketUrlProvider } from "../engine/engine_networking";
|
|
1
2
|
import { isLocalNetwork } from "../engine/engine_networking_utils";
|
|
2
3
|
import { getParam } from "../engine/engine_utils";
|
|
3
4
|
import { Behaviour } from "./Component";
|
|
4
5
|
|
|
5
|
-
export class Networking extends Behaviour {
|
|
6
|
+
export class Networking extends Behaviour implements INetworkingWebsocketUrlProvider {
|
|
6
7
|
|
|
7
8
|
url: string | null = null;
|
|
8
9
|
urlParameterName: string | null = null;
|
|
@@ -10,6 +11,10 @@ export class Networking extends Behaviour {
|
|
|
10
11
|
// used when local host is detected
|
|
11
12
|
localhost: string | null = null;
|
|
12
13
|
|
|
14
|
+
awake(){
|
|
15
|
+
this.context.connection.registerProvider(this);
|
|
16
|
+
}
|
|
17
|
+
|
|
13
18
|
getWebsocketUrl(): string | null {
|
|
14
19
|
|
|
15
20
|
let socketurl = this.url ? Networking.GetUrl(this.url, this.localhost) : null;
|
|
@@ -12,15 +12,17 @@ export function apply(object: Object3D) {
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
// this is a fix to allow gameObject active animation be applied to a three object
|
|
15
|
-
Object.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
15
|
+
if (!Object.getOwnPropertyDescriptor(Object3D.prototype, "activeSelf")) {
|
|
16
|
+
Object.defineProperty(Object3D.prototype, "activeSelf", {
|
|
17
|
+
get: function () {
|
|
18
|
+
return this.visible;
|
|
19
|
+
},
|
|
20
|
+
set: function (val: boolean | number) {
|
|
21
|
+
const state = typeof val === "number" ? val > 0.5 : val;
|
|
22
|
+
this.visible = state;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
24
26
|
|
|
25
27
|
|
|
26
28
|
// do we still need this?
|
|
@@ -40,23 +42,23 @@ Object3D.prototype["getOrAddComponent"] = function <T extends IComponent>(typeNa
|
|
|
40
42
|
return getOrAddComponent<T>(this, typeName);
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
Object3D.prototype["getComponent"] = function <T>(type: Constructor<T>) {
|
|
44
|
-
return getComponent(
|
|
45
|
+
Object3D.prototype["getComponent"] = function <T extends IComponent>(type: Constructor<T>) {
|
|
46
|
+
return getComponent(this, type);
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
Object3D.prototype["getComponents"] = function <T>(type: Constructor<T>, arr?: []) {
|
|
49
|
+
Object3D.prototype["getComponents"] = function <T extends IComponent>(type: Constructor<T>, arr?: []) {
|
|
48
50
|
return getComponents(this, type, arr);
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
Object3D.prototype["getComponentInChildren"] = function <T>(type: Constructor<T>) {
|
|
53
|
+
Object3D.prototype["getComponentInChildren"] = function <T extends IComponent>(type: Constructor<T>) {
|
|
52
54
|
return getComponentInChildren(this, type);
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
Object3D.prototype["getComponentsInChildren"] = function <T extends IComponent>(type: Constructor<T>, arr?: []) {
|
|
56
|
-
return getComponentsInChildren(
|
|
58
|
+
return getComponentsInChildren(this, type, arr);
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
Object3D.prototype["getComponentInParent"] = function <T>(type: Constructor<T>) {
|
|
61
|
+
Object3D.prototype["getComponentInParent"] = function <T extends IComponent>(type: Constructor<T>) {
|
|
60
62
|
return getComponentInParent(this, type);
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -344,8 +344,8 @@ export class EventSystem extends Behaviour {
|
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
-
if (clicked)
|
|
348
|
-
|
|
347
|
+
// if (clicked)
|
|
348
|
+
// console.log(this.context.time.frame, object);
|
|
349
349
|
this.objectsHoveredThisFrame.push(object);
|
|
350
350
|
|
|
351
351
|
if (canvasGroup === null || canvasGroup.interactable) {
|