@needle-tools/engine 3.2.3-alpha → 3.2.4-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 +6 -0
- package/dist/needle-engine.js +23769 -22904
- package/dist/needle-engine.min.js +361 -361
- package/dist/needle-engine.umd.cjs +356 -356
- package/lib/engine/api.d.ts +4 -0
- package/lib/engine/api.js +4 -0
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/engine_addressables.d.ts +3 -3
- package/lib/engine/engine_addressables.js +0 -1
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_context.d.ts +11 -12
- package/lib/engine/engine_context.js +16 -17
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_fileloader.d.ts +2 -2
- package/lib/engine/engine_fileloader.js +2 -2
- package/lib/engine/engine_fileloader.js.map +1 -1
- package/lib/engine/engine_gameobject.d.ts +8 -8
- package/lib/engine/engine_gameobject.js +1 -1
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_gizmos.d.ts +2 -3
- package/lib/engine/engine_gizmos.js +3 -3
- package/lib/engine/engine_gizmos.js.map +1 -1
- package/lib/engine/engine_gltf_builtin_components.js +4 -5
- package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
- package/lib/engine/engine_input.d.ts +7 -7
- package/lib/engine/engine_input.js +12 -12
- package/lib/engine/engine_input.js.map +1 -1
- package/lib/engine/engine_license.js +2 -2
- package/lib/engine/engine_license.js.map +1 -1
- package/lib/engine/engine_mainloop_utils.d.ts +1 -1
- package/lib/engine/engine_mainloop_utils.js +1 -1
- package/lib/engine/engine_mainloop_utils.js.map +1 -1
- package/lib/engine/engine_networking_auto.d.ts +1 -1
- package/lib/engine/engine_networking_auto.js.map +1 -1
- package/lib/engine/engine_networking_files.d.ts +4 -4
- package/lib/engine/engine_networking_files.js +4 -5
- package/lib/engine/engine_networking_files.js.map +1 -1
- package/lib/engine/engine_three_utils.d.ts +19 -19
- package/lib/engine/engine_three_utils.js +17 -18
- package/lib/engine/engine_three_utils.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_components.d.ts +6 -5
- package/lib/engine/extensions/NEEDLE_components.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_lighting_settings.js +14 -6
- package/lib/engine/extensions/NEEDLE_lighting_settings.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_techniques_webgl.d.ts +3 -4
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js +25 -26
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js.map +1 -1
- package/lib/engine-components/Animation.d.ts +6 -7
- package/lib/engine-components/Animation.js +5 -6
- package/lib/engine-components/Animation.js.map +1 -1
- package/lib/engine-components/Animator.d.ts +3 -4
- package/lib/engine-components/Animator.js.map +1 -1
- package/lib/engine-components/AnimatorController.js +3 -4
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/AudioListener.d.ts +2 -2
- package/lib/engine-components/AudioListener.js +2 -2
- package/lib/engine-components/AudioListener.js.map +1 -1
- package/lib/engine-components/AudioSource.d.ts +2 -2
- package/lib/engine-components/AudioSource.js +4 -4
- package/lib/engine-components/AudioSource.js.map +1 -1
- package/lib/engine-components/AvatarLoader.d.ts +7 -7
- package/lib/engine-components/AvatarLoader.js +3 -4
- package/lib/engine-components/AvatarLoader.js.map +1 -1
- package/lib/engine-components/AxesHelper.js.map +1 -1
- package/lib/engine-components/BasicIKConstraint.js +2 -2
- package/lib/engine-components/BasicIKConstraint.js.map +1 -1
- package/lib/engine-components/BoxHelperComponent.d.ts +5 -5
- package/lib/engine-components/BoxHelperComponent.js +6 -6
- package/lib/engine-components/BoxHelperComponent.js.map +1 -1
- package/lib/engine-components/Component.d.ts +43 -44
- package/lib/engine-components/Component.js +14 -14
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/DragControls.d.ts +3 -3
- package/lib/engine-components/DragControls.js +22 -24
- package/lib/engine-components/DragControls.js.map +1 -1
- package/lib/engine-components/api.d.ts +2 -0
- package/lib/engine-components/api.js +2 -0
- package/lib/engine-components/api.js.map +1 -1
- package/lib/engine-components/ui/Utils.d.ts +4 -3
- package/lib/engine-components/ui/Utils.js.map +1 -1
- package/lib/engine-components-experimental/api.d.ts +1 -0
- package/lib/engine-components-experimental/api.js +2 -0
- package/lib/engine-components-experimental/api.js.map +1 -0
- package/lib/engine-components-experimental/networking/PlayerSync.d.ts +2 -1
- package/lib/engine-components-experimental/networking/PlayerSync.js +18 -1
- package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
- package/lib/needle-engine.d.ts +1 -5
- package/lib/needle-engine.js +4 -5
- package/lib/needle-engine.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/plugins/vite/license.js +2 -2
- package/src/engine/api.ts +5 -1
- package/src/engine/codegen/register_types.js +2 -2
- package/src/engine/engine_addressables.ts +6 -7
- package/src/engine/engine_context.ts +31 -28
- package/src/engine/engine_fileloader.js +2 -2
- package/src/engine/engine_gameobject.ts +21 -21
- package/src/engine/engine_gizmos.ts +5 -6
- package/src/engine/engine_gltf_builtin_components.ts +9 -10
- package/src/engine/engine_input.ts +17 -18
- package/src/engine/engine_license.ts +2 -2
- package/src/engine/engine_mainloop_utils.ts +5 -5
- package/src/engine/engine_networking_auto.ts +1 -1
- package/src/engine/engine_networking_files.ts +10 -11
- package/src/engine/engine_three_utils.ts +37 -37
- package/src/engine/extensions/NEEDLE_components.ts +7 -6
- package/src/engine/extensions/NEEDLE_lighting_settings.ts +15 -6
- package/src/engine/extensions/NEEDLE_techniques_webgl.ts +29 -30
- package/src/engine-components/Animation.ts +17 -19
- package/src/engine-components/Animator.ts +4 -5
- package/src/engine-components/AnimatorController.ts +16 -17
- package/src/engine-components/AudioListener.ts +4 -4
- package/src/engine-components/AudioSource.ts +8 -8
- package/src/engine-components/AvatarLoader.ts +15 -16
- package/src/engine-components/AxesHelper.ts +1 -1
- package/src/engine-components/BasicIKConstraint.ts +2 -2
- package/src/engine-components/BoxHelperComponent.ts +13 -13
- package/src/engine-components/Component.ts +63 -64
- package/src/engine-components/DragControls.ts +42 -43
- package/src/engine-components/ParticleSystemModules.ts +1483 -1483
- package/src/engine-components/api.ts +2 -0
- package/src/engine-components/ui/Utils.ts +4 -4
- package/src/engine-components-experimental/api.ts +1 -0
- package/src/engine-components-experimental/networking/PlayerSync.ts +17 -4
- package/src/needle-engine.ts +5 -8
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import * as THREE from "three";
|
|
2
1
|
import { Mathf } from "../engine/engine_math";
|
|
3
2
|
import * as threeutils from "../engine/engine_three_utils";
|
|
4
3
|
import { activeInHierarchyFieldName } from "../engine/engine_constants";
|
|
5
4
|
import { Context, FrameEvent } from "../engine/engine_setup";
|
|
6
5
|
import * as main from "../engine/engine_mainloop_utils";
|
|
7
|
-
import { Object3D } from "three";
|
|
8
6
|
import { syncDestroy, syncInstantiate } from "../engine/engine_networking_instantiate";
|
|
9
|
-
import { ConstructorConcrete, SourceIdentifier, IComponent, IGameObject, Constructor, GuidsMap,
|
|
7
|
+
import { ConstructorConcrete, SourceIdentifier, IComponent, IGameObject, Constructor, GuidsMap, Collision, ICollider } from "../engine/engine_types";
|
|
10
8
|
import { addNewComponent, destroyComponentInstance, findObjectOfType, findObjectsOfType, getComponent, getComponentInChildren, getComponentInParent, getComponents, getComponentsInChildren, getComponentsInParent, getOrAddComponent, moveComponentInstance, removeComponent } from "../engine/engine_components";
|
|
11
9
|
import { findByGuid, destroy, InstantiateOptions, instantiate, HideFlags, foreachComponent, markAsInstancedRendered, isActiveInHierarchy, isActiveSelf, isUsingInstancing, setActive, isDestroyed } from "../engine/engine_gameobject";
|
|
12
10
|
|
|
11
|
+
import { Euler, Object3D, Quaternion, Scene, Vector3 } from "three";
|
|
13
12
|
|
|
14
13
|
// export interface ISerializationCallbackReceiver {
|
|
15
14
|
// onBeforeSerialize?(): object | void;
|
|
@@ -19,7 +18,7 @@ import { findByGuid, destroy, InstantiateOptions, instantiate, HideFlags, foreac
|
|
|
19
18
|
// onDeserialize?(key: string, value: any): any | void;
|
|
20
19
|
// }
|
|
21
20
|
|
|
22
|
-
abstract class GameObject extends
|
|
21
|
+
abstract class GameObject extends Object3D implements Object3D, IGameObject {
|
|
23
22
|
|
|
24
23
|
guid: string | undefined;
|
|
25
24
|
|
|
@@ -27,13 +26,13 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
27
26
|
abstract destroy();
|
|
28
27
|
|
|
29
28
|
// The actual implementation / prototype of threejs is modified in js-extensions/Object3D
|
|
30
|
-
abstract get transform():
|
|
29
|
+
abstract get transform(): Object3D;
|
|
31
30
|
|
|
32
|
-
public static isDestroyed(go:
|
|
31
|
+
public static isDestroyed(go: Object3D): boolean {
|
|
33
32
|
return isDestroyed(go);
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
public static setActive(go:
|
|
35
|
+
public static setActive(go: Object3D, active: boolean, processStart: boolean = true) {
|
|
37
36
|
if (!go) return;
|
|
38
37
|
setActive(go, active);
|
|
39
38
|
|
|
@@ -44,29 +43,29 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
/** If the object is active (same as go.visible) */
|
|
47
|
-
public static isActiveSelf(go:
|
|
46
|
+
public static isActiveSelf(go: Object3D): boolean {
|
|
48
47
|
return isActiveSelf(go);
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
/** If the object is active in the hierarchy (e.g. if any parent is invisible or not in the scene it will be false)
|
|
52
51
|
* @param go object to check
|
|
53
52
|
*/
|
|
54
|
-
public static isActiveInHierarchy(go:
|
|
53
|
+
public static isActiveInHierarchy(go: Object3D): boolean {
|
|
55
54
|
return isActiveInHierarchy(go);
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
public static markAsInstancedRendered(go:
|
|
57
|
+
public static markAsInstancedRendered(go: Object3D, instanced: boolean) {
|
|
59
58
|
markAsInstancedRendered(go, instanced);
|
|
60
59
|
}
|
|
61
60
|
|
|
62
|
-
public static isUsingInstancing(instance:
|
|
61
|
+
public static isUsingInstancing(instance: Object3D): boolean { return isUsingInstancing(instance); }
|
|
63
62
|
|
|
64
63
|
/** Run a callback for all components of the provided type on the provided object and its children (if recursive is true)
|
|
65
64
|
* @param instance object to run the method on
|
|
66
65
|
* @param cb callback to run on each component
|
|
67
66
|
* @param recursive if true, the method will be run on all children as well
|
|
68
67
|
*/
|
|
69
|
-
public static foreachComponent(instance:
|
|
68
|
+
public static foreachComponent(instance: Object3D, cb: (comp: Component) => any, recursive: boolean = true): any {
|
|
70
69
|
return foreachComponent(instance, cb as (comp: IComponent) => any, recursive);
|
|
71
70
|
}
|
|
72
71
|
|
|
@@ -90,7 +89,7 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
90
89
|
/** Destroys a object on all connected clients (if you are in a networked session)
|
|
91
90
|
* @param instance object to destroy
|
|
92
91
|
*/
|
|
93
|
-
public static destroySynced(instance:
|
|
92
|
+
public static destroySynced(instance: Object3D | Component, context?: Context, recursive: boolean = true) {
|
|
94
93
|
if (!instance) return;
|
|
95
94
|
const go = instance as GameObject;
|
|
96
95
|
context = context ?? Context.Current;
|
|
@@ -101,14 +100,14 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
101
100
|
* @param instance object to destroy
|
|
102
101
|
* @param recursive if true, all children will be destroyed as well
|
|
103
102
|
*/
|
|
104
|
-
public static destroy(instance:
|
|
103
|
+
public static destroy(instance: Object3D | Component, recursive: boolean = true, isRoot: boolean = true) {
|
|
105
104
|
return destroy(instance, recursive, isRoot);
|
|
106
105
|
}
|
|
107
106
|
|
|
108
107
|
/**
|
|
109
108
|
* Add an object to parent and also ensure all components are being registered
|
|
110
109
|
*/
|
|
111
|
-
public static add(instance:
|
|
110
|
+
public static add(instance: Object3D | null | undefined, parent: Object3D, context?: Context) {
|
|
112
111
|
if (!instance || !parent) return;
|
|
113
112
|
if (instance === parent) {
|
|
114
113
|
console.warn("Can not add object to self", instance);
|
|
@@ -137,7 +136,7 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
137
136
|
/**
|
|
138
137
|
* Removes the object from its parent and deactivates all of its components
|
|
139
138
|
*/
|
|
140
|
-
public static remove(instance:
|
|
139
|
+
public static remove(instance: Object3D | null | undefined) {
|
|
141
140
|
if (!instance) return;
|
|
142
141
|
instance.parent?.remove(instance);
|
|
143
142
|
setActive(instance, false);
|
|
@@ -148,7 +147,7 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
148
147
|
}
|
|
149
148
|
|
|
150
149
|
/** Invokes a method on all components including children (if a method with that name exists) */
|
|
151
|
-
public static invokeOnChildren(go:
|
|
150
|
+
public static invokeOnChildren(go: Object3D | null | undefined, functionName: string, ...args: any) {
|
|
152
151
|
this.invoke(go, functionName, true, args);
|
|
153
152
|
}
|
|
154
153
|
|
|
@@ -156,7 +155,7 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
156
155
|
* @param go object to invoke the method on all components
|
|
157
156
|
* @param functionName name of the method to invoke
|
|
158
157
|
*/
|
|
159
|
-
public static invoke(go:
|
|
158
|
+
public static invoke(go: Object3D | null | undefined, functionName: string, children: boolean = false, ...args: any) {
|
|
160
159
|
if (!go) return;
|
|
161
160
|
this.foreachComponent(go, c => {
|
|
162
161
|
const fn = c[functionName];
|
|
@@ -172,7 +171,7 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
172
171
|
* @param type type of the component to add
|
|
173
172
|
* @param callAwake if true, the component will be added and awake will be called immediately
|
|
174
173
|
*/
|
|
175
|
-
public static addNewComponent<T>(go:
|
|
174
|
+
public static addNewComponent<T>(go: IGameObject | Object3D, type: ConstructorConcrete<T>, callAwake: boolean = true): T {
|
|
176
175
|
const instance = new type();
|
|
177
176
|
//@ts-ignore
|
|
178
177
|
addNewComponent(go, instance, callAwake);
|
|
@@ -185,7 +184,7 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
185
184
|
* @param go component to move the component to
|
|
186
185
|
* @param instance component to move to the GO
|
|
187
186
|
*/
|
|
188
|
-
public static addComponent(go:
|
|
187
|
+
public static addComponent(go: IGameObject, instance: Component): void {
|
|
189
188
|
return this.moveComponent(go, instance);
|
|
190
189
|
}
|
|
191
190
|
|
|
@@ -194,7 +193,7 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
194
193
|
* @param go component to move the component to
|
|
195
194
|
* @param instance component to move to the GO
|
|
196
195
|
*/
|
|
197
|
-
public static moveComponent(go:
|
|
196
|
+
public static moveComponent(go: IGameObject, instance: Component): void {
|
|
198
197
|
if (instance.gameObject == null) {
|
|
199
198
|
throw new Error("Did you mean to create a new component? Use addNewComponent");
|
|
200
199
|
}
|
|
@@ -209,12 +208,12 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
209
208
|
return instance;
|
|
210
209
|
}
|
|
211
210
|
|
|
212
|
-
public static getOrAddComponent<T>(go:
|
|
211
|
+
public static getOrAddComponent<T>(go: IGameObject | Object3D, typeName: ConstructorConcrete<T>): T {
|
|
213
212
|
return getOrAddComponent<any>(go, typeName);
|
|
214
213
|
}
|
|
215
214
|
|
|
216
215
|
/** Gets a component on the provided object */
|
|
217
|
-
public static getComponent<T>(go:
|
|
216
|
+
public static getComponent<T>(go: IGameObject | Object3D | null, typeName: Constructor<T> | null): T | null {
|
|
218
217
|
if (go === null) return null;
|
|
219
218
|
// if names are minified we could also use the type store and work with strings everywhere
|
|
220
219
|
// not ideal, but I dont know a good/sane way to do this otherwise
|
|
@@ -223,49 +222,49 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
223
222
|
return getComponent(go, typeName as any);
|
|
224
223
|
}
|
|
225
224
|
|
|
226
|
-
public static getComponents<T>(go:
|
|
225
|
+
public static getComponents<T>(go: IGameObject | Object3D | null, typeName: Constructor<T>, arr: T[] | null = null): T[] {
|
|
227
226
|
if (go === null) return arr ?? [];
|
|
228
227
|
return getComponents(go, typeName, arr);
|
|
229
228
|
}
|
|
230
229
|
|
|
231
|
-
public static findByGuid(guid: string, hierarchy:
|
|
230
|
+
public static findByGuid(guid: string, hierarchy: Object3D): GameObject | Component | null | undefined {
|
|
232
231
|
const res = findByGuid(guid, hierarchy);
|
|
233
232
|
return res as GameObject | Component | null | undefined;
|
|
234
233
|
}
|
|
235
234
|
|
|
236
|
-
public static findObjectOfType<T>(typeName: Constructor<T>, context?: Context |
|
|
235
|
+
public static findObjectOfType<T>(typeName: Constructor<T>, context?: Context | Object3D, includeInactive: boolean = true): T | null {
|
|
237
236
|
return findObjectOfType(typeName, context ?? Context.Current, includeInactive);
|
|
238
237
|
}
|
|
239
238
|
|
|
240
|
-
public static findObjectsOfType<T>(typeName: Constructor<T>, context?: Context |
|
|
239
|
+
public static findObjectsOfType<T>(typeName: Constructor<T>, context?: Context | Object3D): Array<T> {
|
|
241
240
|
const arr = [];
|
|
242
241
|
findObjectsOfType(typeName, arr, context);
|
|
243
242
|
return arr;
|
|
244
243
|
}
|
|
245
244
|
|
|
246
|
-
public static getComponentInChildren<T>(go:
|
|
245
|
+
public static getComponentInChildren<T>(go: IGameObject | Object3D, typeName: Constructor<T>): T | null {
|
|
247
246
|
return getComponentInChildren(go, typeName);
|
|
248
247
|
}
|
|
249
248
|
|
|
250
|
-
public static getComponentsInChildren<T>(go:
|
|
249
|
+
public static getComponentsInChildren<T>(go: IGameObject | Object3D, typeName: Constructor<T>, arr: T[] | null = null): Array<T> {
|
|
251
250
|
return getComponentsInChildren<T>(go, typeName, arr ?? undefined) as T[]
|
|
252
251
|
}
|
|
253
252
|
|
|
254
|
-
public static getComponentInParent<T>(go:
|
|
253
|
+
public static getComponentInParent<T>(go: IGameObject | Object3D, typeName: Constructor<T>): T | null {
|
|
255
254
|
return getComponentInParent(go, typeName);
|
|
256
255
|
}
|
|
257
256
|
|
|
258
|
-
public static getComponentsInParent<T>(go:
|
|
257
|
+
public static getComponentsInParent<T>(go: IGameObject | Object3D, typeName: Constructor<T>, arr: Array<T> | null = null): Array<T> {
|
|
259
258
|
return getComponentsInParent(go, typeName, arr);
|
|
260
259
|
}
|
|
261
260
|
|
|
262
|
-
public static getAllComponents(go:
|
|
261
|
+
public static getAllComponents(go: IGameObject | Object3D): Behaviour[] {
|
|
263
262
|
const componentsList = go.userData?.components;
|
|
264
263
|
const newList = [...componentsList];
|
|
265
264
|
return newList;
|
|
266
265
|
}
|
|
267
266
|
|
|
268
|
-
public static *iterateComponents(go:
|
|
267
|
+
public static *iterateComponents(go: IGameObject | Object3D) {
|
|
269
268
|
const list = go?.userData?.components;
|
|
270
269
|
if (list && Array.isArray(list)) {
|
|
271
270
|
for (let i = 0; i < list.length; i++) {
|
|
@@ -300,7 +299,7 @@ class Component implements IComponent, EventTarget {
|
|
|
300
299
|
set context(context: Context) {
|
|
301
300
|
this.__context = context;
|
|
302
301
|
}
|
|
303
|
-
get scene():
|
|
302
|
+
get scene(): Scene { return this.context.scene; }
|
|
304
303
|
|
|
305
304
|
get layer(): number {
|
|
306
305
|
return this.gameObject?.userData?.layer;
|
|
@@ -367,7 +366,7 @@ class Component implements IComponent, EventTarget {
|
|
|
367
366
|
gameObject!: GameObject;
|
|
368
367
|
guid: string = "invalid";
|
|
369
368
|
sourceId?: SourceIdentifier;
|
|
370
|
-
// transform:
|
|
369
|
+
// transform: Object3D = nullObject;
|
|
371
370
|
|
|
372
371
|
/** called on a component with a map of old to new guids (e.g. when instantiate generated new guids and e.g. timeline track bindings needs to remape them) */
|
|
373
372
|
resolveGuids?(guidsMap: GuidsMap): void;
|
|
@@ -521,24 +520,24 @@ class Component implements IComponent, EventTarget {
|
|
|
521
520
|
|
|
522
521
|
// TODO move this to threeutils
|
|
523
522
|
// we need a copy for modifying the values to local space
|
|
524
|
-
private static _worldPositionBuffer:
|
|
525
|
-
private static _worldQuaternionBuffer:
|
|
526
|
-
private static _worldEulerBuffer:
|
|
527
|
-
|
|
528
|
-
private _worldPosition:
|
|
529
|
-
private _worldQuaternion:
|
|
530
|
-
private static _tempQuaternionBuffer2:
|
|
531
|
-
private _worldEuler:
|
|
532
|
-
private _worldRotation:
|
|
533
|
-
|
|
534
|
-
get worldPosition():
|
|
535
|
-
if (!this._worldPosition) this._worldPosition = new
|
|
523
|
+
private static _worldPositionBuffer: Vector3 = new Vector3();
|
|
524
|
+
private static _worldQuaternionBuffer: Quaternion = new Quaternion();
|
|
525
|
+
private static _worldEulerBuffer: Euler = new Euler();
|
|
526
|
+
|
|
527
|
+
private _worldPosition: Vector3 | undefined = undefined;
|
|
528
|
+
private _worldQuaternion: Quaternion | undefined = undefined;
|
|
529
|
+
private static _tempQuaternionBuffer2: Quaternion = new Quaternion();
|
|
530
|
+
private _worldEuler: Euler | undefined = undefined;
|
|
531
|
+
private _worldRotation: Vector3 | undefined = undefined;
|
|
532
|
+
|
|
533
|
+
get worldPosition(): Vector3 {
|
|
534
|
+
if (!this._worldPosition) this._worldPosition = new Vector3();
|
|
536
535
|
threeutils.getWorldPosition(this.gameObject, this._worldPosition);
|
|
537
536
|
// this.gameObject.getWorldPosition(this._worldPosition);
|
|
538
537
|
return this._worldPosition;
|
|
539
538
|
}
|
|
540
539
|
|
|
541
|
-
set worldPosition(val:
|
|
540
|
+
set worldPosition(val: Vector3) {
|
|
542
541
|
threeutils.setWorldPosition(this.gameObject, val);
|
|
543
542
|
}
|
|
544
543
|
|
|
@@ -548,11 +547,11 @@ class Component implements IComponent, EventTarget {
|
|
|
548
547
|
}
|
|
549
548
|
|
|
550
549
|
|
|
551
|
-
get worldQuaternion():
|
|
552
|
-
if (!this._worldQuaternion) this._worldQuaternion = new
|
|
550
|
+
get worldQuaternion(): Quaternion {
|
|
551
|
+
if (!this._worldQuaternion) this._worldQuaternion = new Quaternion();
|
|
553
552
|
return threeutils.getWorldQuaternion(this.gameObject, this._worldQuaternion);
|
|
554
553
|
}
|
|
555
|
-
set worldQuaternion(val:
|
|
554
|
+
set worldQuaternion(val: Quaternion) {
|
|
556
555
|
threeutils.setWorldQuaternion(this.gameObject, val);
|
|
557
556
|
}
|
|
558
557
|
setWorldQuaternion(x: number, y: number, z: number, w: number) {
|
|
@@ -562,23 +561,23 @@ class Component implements IComponent, EventTarget {
|
|
|
562
561
|
|
|
563
562
|
|
|
564
563
|
// world euler (in radians)
|
|
565
|
-
get worldEuler():
|
|
566
|
-
if (!this._worldEuler) this._worldEuler = new
|
|
564
|
+
get worldEuler(): Euler {
|
|
565
|
+
if (!this._worldEuler) this._worldEuler = new Euler();
|
|
567
566
|
this._worldEuler.setFromQuaternion(this.worldQuaternion);
|
|
568
567
|
return this._worldEuler;
|
|
569
568
|
}
|
|
570
569
|
|
|
571
570
|
// world euler (in radians)
|
|
572
|
-
set worldEuler(val:
|
|
573
|
-
if (!this._worldQuaternion) this._worldQuaternion = new
|
|
571
|
+
set worldEuler(val: Euler) {
|
|
572
|
+
if (!this._worldQuaternion) this._worldQuaternion = new Quaternion();
|
|
574
573
|
this._worldQuaternion?.setFromEuler(val);
|
|
575
574
|
this.worldQuaternion = this._worldQuaternion;
|
|
576
575
|
}
|
|
577
576
|
|
|
578
577
|
// returns rotation in degrees
|
|
579
|
-
get worldRotation():
|
|
578
|
+
get worldRotation(): Vector3 {
|
|
580
579
|
const rot = this.worldEuler;
|
|
581
|
-
if (!this._worldRotation) this._worldRotation = new
|
|
580
|
+
if (!this._worldRotation) this._worldRotation = new Vector3();
|
|
582
581
|
const wr = this._worldRotation;
|
|
583
582
|
wr.set(rot.x, rot.y, rot.z);
|
|
584
583
|
wr.x = Mathf.toDegrees(wr.x);
|
|
@@ -587,7 +586,7 @@ class Component implements IComponent, EventTarget {
|
|
|
587
586
|
return wr;
|
|
588
587
|
}
|
|
589
588
|
|
|
590
|
-
set worldRotation(val:
|
|
589
|
+
set worldRotation(val: Vector3) {
|
|
591
590
|
this.setWorldRotation(val.x, val.y, val.z, true);
|
|
592
591
|
}
|
|
593
592
|
|
|
@@ -602,16 +601,16 @@ class Component implements IComponent, EventTarget {
|
|
|
602
601
|
this.worldQuaternion = Component._worldQuaternionBuffer;
|
|
603
602
|
}
|
|
604
603
|
|
|
605
|
-
private static _forward:
|
|
606
|
-
public get forward():
|
|
604
|
+
private static _forward: Vector3 = new Vector3();
|
|
605
|
+
public get forward(): Vector3 {
|
|
607
606
|
return Component._forward.set(0, 0, -1).applyQuaternion(this.worldQuaternion);
|
|
608
607
|
}
|
|
609
|
-
private static _right:
|
|
610
|
-
public get right():
|
|
608
|
+
private static _right: Vector3 = new Vector3();
|
|
609
|
+
public get right(): Vector3 {
|
|
611
610
|
return Component._right.set(1, 0, 0).applyQuaternion(this.worldQuaternion);
|
|
612
611
|
}
|
|
613
|
-
private static _up:
|
|
614
|
-
public get up():
|
|
612
|
+
private static _up: Vector3 = new Vector3();
|
|
613
|
+
public get up(): Vector3 {
|
|
615
614
|
return Component._up.set(0, 1, 0).applyQuaternion(this.worldQuaternion);
|
|
616
615
|
}
|
|
617
616
|
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
// import { DragControls as Control } from "../include/three/DragControls";
|
|
1
|
+
import { GameObject } from "./Component";
|
|
3
2
|
import { SyncedTransform } from "./SyncedTransform";
|
|
4
|
-
import
|
|
5
|
-
import { IPointerClickHandler, IPointerDownHandler, IPointerEnterHandler, IPointerExitHandler, IPointerUpHandler, PointerEventData } from "./ui/PointerEvents";
|
|
3
|
+
import { IPointerDownHandler, IPointerEnterHandler, IPointerExitHandler, IPointerUpHandler, PointerEventData } from "./ui/PointerEvents";
|
|
6
4
|
import { Context } from "../engine/engine_setup";
|
|
7
5
|
import { Interactable, UsageMarker } from "./Interactable";
|
|
8
6
|
import { Rigidbody } from "./RigidBody";
|
|
9
7
|
import { WebXR } from "./WebXR";
|
|
10
8
|
import { Avatar_POI } from "./avatar/Avatar_Brain_LookAt";
|
|
11
9
|
import { RaycastOptions } from "../engine/engine_physics";
|
|
12
|
-
import { getWorldPosition,
|
|
10
|
+
import { getWorldPosition, setWorldPosition } from "../engine/engine_three_utils";
|
|
13
11
|
import { KeyCode } from "../engine/engine_input";
|
|
14
12
|
import { nameofFactory } from "../engine/engine_utils";
|
|
15
13
|
import { InstancingUtil } from "../engine/engine_instancing";
|
|
16
14
|
import { OrbitControls } from "./OrbitControls";
|
|
15
|
+
import { BufferGeometry, Camera, Color, Line, LineBasicMaterial, Matrix4, Mesh, MeshBasicMaterial, Object3D, Plane, Ray, Raycaster, SphereGeometry, Vector2, Vector3 } from "three";
|
|
17
16
|
|
|
18
17
|
const debug = false;
|
|
19
18
|
|
|
@@ -23,8 +22,8 @@ export enum DragEvents {
|
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
interface SelectArgs {
|
|
26
|
-
selected:
|
|
27
|
-
attached:
|
|
25
|
+
selected: Object3D;
|
|
26
|
+
attached: Object3D | GameObject | null;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
|
|
@@ -41,7 +40,7 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
41
40
|
|
|
42
41
|
public transformSelf: boolean = true;
|
|
43
42
|
// public transformGroup: boolean = true;
|
|
44
|
-
// public targets:
|
|
43
|
+
// public targets: Object3D[] | null = null;
|
|
45
44
|
|
|
46
45
|
// private controls: Control | null = null;
|
|
47
46
|
private orbit: OrbitControls | null = null;
|
|
@@ -53,7 +52,7 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
53
52
|
super();
|
|
54
53
|
this.selectStartEventListener = [];
|
|
55
54
|
this.selectEndEventListener = [];
|
|
56
|
-
this._dragDelta = new
|
|
55
|
+
this._dragDelta = new Vector2();
|
|
57
56
|
}
|
|
58
57
|
|
|
59
58
|
addDragEventListener(type: DragEvents, cb: (ctrls: DragControls, args: SelectArgs) => void | Function) {
|
|
@@ -74,10 +73,10 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
74
73
|
this.orbit = GameObject.findObjectOfType(OrbitControls, this.context);
|
|
75
74
|
}
|
|
76
75
|
|
|
77
|
-
private static lastHovered:
|
|
76
|
+
private static lastHovered: Object3D;
|
|
78
77
|
private _draggingRigidbodies: Rigidbody[] = [];
|
|
79
78
|
|
|
80
|
-
private allowEdit(_obj:
|
|
79
|
+
private allowEdit(_obj: Object3D | null = null) {
|
|
81
80
|
return this.context.connection.allowEditing;
|
|
82
81
|
}
|
|
83
82
|
|
|
@@ -160,7 +159,7 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
160
159
|
|
|
161
160
|
private _isDragging: boolean = false;
|
|
162
161
|
private _marker: UsageMarker | null = null;
|
|
163
|
-
private _dragDelta!:
|
|
162
|
+
private _dragDelta!: Vector2;
|
|
164
163
|
private _didDrag: boolean = false;
|
|
165
164
|
private _activePointerId?: number;
|
|
166
165
|
|
|
@@ -177,14 +176,14 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
177
176
|
if (!dc || dc !== this) return;
|
|
178
177
|
|
|
179
178
|
|
|
180
|
-
let object:
|
|
179
|
+
let object: Object3D = evt.object;
|
|
181
180
|
|
|
182
181
|
if (this.transformSelf) {
|
|
183
182
|
object = this.gameObject;
|
|
184
183
|
}
|
|
185
184
|
|
|
186
185
|
// raise event
|
|
187
|
-
const args: { selected:
|
|
186
|
+
const args: { selected: Object3D, attached: Object3D | null } = { selected: object, attached: object };
|
|
188
187
|
for (const listener of this.selectStartEventListener) {
|
|
189
188
|
listener(this, args);
|
|
190
189
|
}
|
|
@@ -285,54 +284,54 @@ class DragHelper {
|
|
|
285
284
|
return this._selected !== null && this._selected !== undefined;
|
|
286
285
|
}
|
|
287
286
|
|
|
288
|
-
public get selected():
|
|
287
|
+
public get selected(): Object3D | null {
|
|
289
288
|
return this._selected;
|
|
290
289
|
}
|
|
291
290
|
|
|
292
|
-
private _selected:
|
|
291
|
+
private _selected: Object3D | null = null;
|
|
293
292
|
private _context: Context | null = null;
|
|
294
|
-
private _camera:
|
|
295
|
-
private _cameraPlane:
|
|
293
|
+
private _camera: Camera;
|
|
294
|
+
private _cameraPlane: Plane = new Plane();
|
|
296
295
|
|
|
297
296
|
private _hasGroundPlane: boolean = false;
|
|
298
|
-
private _groundPlane:
|
|
299
|
-
private _groundOffset:
|
|
297
|
+
private _groundPlane: Plane = new Plane();
|
|
298
|
+
private _groundOffset: Vector3 = new Vector3();
|
|
300
299
|
private _groundOffsetFactor: number = 0;
|
|
301
300
|
private _groundDistance: number = 0;
|
|
302
|
-
private _groundPlanePoint:
|
|
301
|
+
private _groundPlanePoint: Vector3 = new Vector3();
|
|
303
302
|
|
|
304
|
-
private _raycaster = new
|
|
305
|
-
private _cameraPlaneOffset = new
|
|
306
|
-
private _intersection = new
|
|
307
|
-
private _worldPosition = new
|
|
308
|
-
private _inverseMatrix = new
|
|
303
|
+
private _raycaster = new Raycaster();
|
|
304
|
+
private _cameraPlaneOffset = new Vector3();
|
|
305
|
+
private _intersection = new Vector3();
|
|
306
|
+
private _worldPosition = new Vector3();
|
|
307
|
+
private _inverseMatrix = new Matrix4();
|
|
309
308
|
private _rbs: Rigidbody[] = [];
|
|
310
309
|
|
|
311
|
-
private _groundLine:
|
|
312
|
-
private _groundMarker:
|
|
313
|
-
private static geometry = new
|
|
310
|
+
private _groundLine: Line;
|
|
311
|
+
private _groundMarker: Object3D;
|
|
312
|
+
private static geometry = new BufferGeometry().setFromPoints([new Vector3(0, 0, 0), new Vector3(0, -1, 0)]);
|
|
314
313
|
|
|
315
|
-
constructor(camera:
|
|
314
|
+
constructor(camera: Camera) {
|
|
316
315
|
this._camera = camera;
|
|
317
316
|
|
|
318
|
-
const line = new
|
|
319
|
-
const mat = line.material as
|
|
320
|
-
mat.color = new
|
|
317
|
+
const line = new Line(DragHelper.geometry);
|
|
318
|
+
const mat = line.material as LineBasicMaterial;
|
|
319
|
+
mat.color = new Color(.4, .4, .4);
|
|
321
320
|
line.layers.set(2);
|
|
322
321
|
line.name = 'line';
|
|
323
322
|
line.scale.y = 1;
|
|
324
323
|
// line.matrixAutoUpdate = false;
|
|
325
324
|
this._groundLine = line;
|
|
326
325
|
|
|
327
|
-
const geometry = new
|
|
328
|
-
const material = new
|
|
329
|
-
const sphere = new
|
|
326
|
+
const geometry = new SphereGeometry(.5, 22, 22);
|
|
327
|
+
const material = new MeshBasicMaterial({ color: mat.color });
|
|
328
|
+
const sphere = new Mesh(geometry, material);
|
|
330
329
|
sphere.visible = false;
|
|
331
330
|
sphere.layers.set(2);
|
|
332
331
|
this._groundMarker = sphere;
|
|
333
332
|
}
|
|
334
333
|
|
|
335
|
-
setSelected(newSelected:
|
|
334
|
+
setSelected(newSelected: Object3D | null, context: Context) {
|
|
336
335
|
if (this._selected && context) {
|
|
337
336
|
for (const rb of this._rbs) {
|
|
338
337
|
rb.wakeUp();
|
|
@@ -376,7 +375,7 @@ class DragHelper {
|
|
|
376
375
|
}
|
|
377
376
|
}
|
|
378
377
|
|
|
379
|
-
private _groundOffsetVector = new
|
|
378
|
+
private _groundOffsetVector = new Vector3(0, 1, 0);
|
|
380
379
|
private _requireUpdateGroundPlane = true;
|
|
381
380
|
private _didDragOnGroundPlaneLastFrame: boolean = false;
|
|
382
381
|
|
|
@@ -429,7 +428,7 @@ class DragHelper {
|
|
|
429
428
|
this._requireUpdateGroundPlane = false;
|
|
430
429
|
if (this._hasGroundPlane) {
|
|
431
430
|
// const wp = getWorldPosition(this._selected);
|
|
432
|
-
// const ray = new
|
|
431
|
+
// const ray = new Ray(wp, new Vector3(0, -1, 0));
|
|
433
432
|
|
|
434
433
|
if (this._raycaster.ray.intersectPlane(this._groundPlane, this._intersection)) {
|
|
435
434
|
const y = this._intersection.y;
|
|
@@ -466,7 +465,7 @@ class DragHelper {
|
|
|
466
465
|
}
|
|
467
466
|
}
|
|
468
467
|
|
|
469
|
-
private onUpdateWorldPosition(wp:
|
|
468
|
+
private onUpdateWorldPosition(wp: Vector3, pointOnPlane: Vector3 | null, heightOnly: boolean) {
|
|
470
469
|
if (!this._selected) return;
|
|
471
470
|
if (heightOnly) {
|
|
472
471
|
const cur = getWorldPosition(this._selected);
|
|
@@ -503,7 +502,7 @@ class DragHelper {
|
|
|
503
502
|
private onUpdateGroundPlane() {
|
|
504
503
|
if (!this._selected || !this._context) return;
|
|
505
504
|
const wp = getWorldPosition(this._selected);
|
|
506
|
-
const ray = new
|
|
505
|
+
const ray = new Ray(new Vector3(0, .1, 0).add(wp), new Vector3(0, -1, 0));
|
|
507
506
|
const opts = new RaycastOptions();
|
|
508
507
|
opts.ignore = [this._selected];
|
|
509
508
|
const hits = this._context.physics.raycastFromRay(ray, opts);
|
|
@@ -512,7 +511,7 @@ class DragHelper {
|
|
|
512
511
|
if (!hit.face || this.contains(this._selected, hit.object)) {
|
|
513
512
|
continue;
|
|
514
513
|
}
|
|
515
|
-
const normal = new
|
|
514
|
+
const normal = new Vector3(0, 1, 0); // hit.face.normal
|
|
516
515
|
this._groundPlane.setFromNormalAndCoplanarPoint(normal, hit.point);
|
|
517
516
|
break;
|
|
518
517
|
}
|
|
@@ -536,7 +535,7 @@ class DragHelper {
|
|
|
536
535
|
}
|
|
537
536
|
}
|
|
538
537
|
|
|
539
|
-
private contains(obj:
|
|
538
|
+
private contains(obj: Object3D, toSearch: Object3D): boolean {
|
|
540
539
|
if (obj === toSearch) return true;
|
|
541
540
|
if (obj.children) {
|
|
542
541
|
for (const child of obj.children) {
|