@needle-tools/engine 3.2.3-alpha → 3.2.4-alpha.1
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 +9 -0
- package/dist/needle-engine.js +24012 -22890
- package/dist/needle-engine.min.js +363 -363
- package/dist/needle-engine.umd.cjs +369 -369
- package/lib/engine/api.d.ts +33 -11
- package/lib/engine/api.js +33 -11
- 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 +45 -47
- package/lib/engine-components/Component.js +16 -17
- 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 +3 -0
- package/lib/engine-components/api.js +3 -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 +39 -20
- 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 +65 -68
- package/src/engine-components/DragControls.ts +42 -43
- package/src/engine-components/ParticleSystemModules.ts +1483 -1483
- package/src/engine-components/api.ts +3 -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 -9
|
@@ -7,10 +7,10 @@ const debug = getParam("debuglicense");
|
|
|
7
7
|
|
|
8
8
|
// This is modified by a bundler (e.g. vite)
|
|
9
9
|
// Do not edit manually
|
|
10
|
-
const
|
|
10
|
+
const NEEDLE_ENGINE_COMMERCIAL_USE_LICENSE = false;
|
|
11
11
|
|
|
12
12
|
export function hasProLicense() {
|
|
13
|
-
return
|
|
13
|
+
return NEEDLE_ENGINE_COMMERCIAL_USE_LICENSE;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
|
|
@@ -230,7 +230,7 @@ export function updateIsActive(obj?: Object3D) {
|
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
-
function updateIsActiveInHierarchyRecursiveRuntime(go:
|
|
233
|
+
function updateIsActiveInHierarchyRecursiveRuntime(go: Object3D, activeInHierarchy: boolean, allowEventCall: boolean, level: number = 0) {
|
|
234
234
|
if (level > 1000) {
|
|
235
235
|
console.warn("Hierarchy is too deep (> 1000 level) - will abort updating active state");
|
|
236
236
|
return false;
|
|
@@ -307,7 +307,7 @@ function updateIsActiveInHierarchyRecursiveRuntime(go: THREE.Object3D, activeInH
|
|
|
307
307
|
|
|
308
308
|
// let isRunning = false;
|
|
309
309
|
// // Prevent: https://github.com/needle-tools/needle-tiny/issues/641
|
|
310
|
-
// const temporyChildArrayBuffer: Array<Array<
|
|
310
|
+
// const temporyChildArrayBuffer: Array<Array<Object3D>> = [];
|
|
311
311
|
// export function* iterateChildrenSafe(obj: Object3D) {
|
|
312
312
|
// if (!obj || !obj.children) yield null;
|
|
313
313
|
// // if(isRunning) return;
|
|
@@ -322,9 +322,9 @@ function updateIsActiveInHierarchyRecursiveRuntime(go: THREE.Object3D, activeInH
|
|
|
322
322
|
// temporyChildArrayBuffer.push(arr);
|
|
323
323
|
// }
|
|
324
324
|
|
|
325
|
-
export function updateActiveInHierarchyWithoutEventCall(go:
|
|
325
|
+
export function updateActiveInHierarchyWithoutEventCall(go: Object3D) {
|
|
326
326
|
let activeInHierarchy = true;
|
|
327
|
-
let current:
|
|
327
|
+
let current: Object3D | null = go;
|
|
328
328
|
let foundScene: boolean = false;
|
|
329
329
|
while (current) {
|
|
330
330
|
if (!current) break;
|
|
@@ -342,7 +342,7 @@ export function updateActiveInHierarchyWithoutEventCall(go: THREE.Object3D) {
|
|
|
342
342
|
go[constants.activeInHierarchyFieldName] = activeInHierarchy && foundScene;
|
|
343
343
|
}
|
|
344
344
|
|
|
345
|
-
function perComponent(go:
|
|
345
|
+
function perComponent(go: Object3D, evt: (comp: IComponent) => void) {
|
|
346
346
|
if (go.userData?.components) {
|
|
347
347
|
for (const comp of go.userData.components) {
|
|
348
348
|
evt(comp);
|
|
@@ -210,7 +210,7 @@ export declare type FieldChangedCallbackFn = (newValue: any, previousValue: any)
|
|
|
210
210
|
* (for example a networked color is sent as a number and may be converted to a color in the receiver again)
|
|
211
211
|
* Parameters: (newValue, previousValue)
|
|
212
212
|
*/
|
|
213
|
-
export const syncField = function(onFieldChanged
|
|
213
|
+
export const syncField = function(onFieldChanged?: string | FieldChangedCallbackFn) {
|
|
214
214
|
|
|
215
215
|
return function (target: any, propertyKey: string) {
|
|
216
216
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { Context } from "../engine/engine_setup";
|
|
2
|
-
// import { loadSync, parseSync } from "../engine/engine_scenetools";
|
|
3
|
-
import * as THREE from "three";
|
|
4
2
|
import * as web from "../engine/engine_web_api";
|
|
5
3
|
import { NetworkConnection } from "../engine/engine_networking";
|
|
6
4
|
import { generateSeed, InstantiateIdProvider } from "../engine/engine_networking_instantiate";
|
|
@@ -11,6 +9,7 @@ import { IModel } from "./engine_networking_types";
|
|
|
11
9
|
import { IGameObject } from "./engine_types";
|
|
12
10
|
import { findByGuid } from "./engine_gameobject";
|
|
13
11
|
import { ContextEvent, ContextRegistry } from "./engine_context_registry";
|
|
12
|
+
import { BoxGeometry, BoxHelper, Mesh, MeshBasicMaterial, Object3D, Vector3 } from "three";
|
|
14
13
|
|
|
15
14
|
export enum File_Event {
|
|
16
15
|
File_Spawned = "file-spawned",
|
|
@@ -21,15 +20,15 @@ export class FileSpawnModel implements IModel {
|
|
|
21
20
|
file_name: string;
|
|
22
21
|
file_hash: string;
|
|
23
22
|
file_size: number;
|
|
24
|
-
position:
|
|
23
|
+
position: Vector3 | null;
|
|
25
24
|
seed: number;
|
|
26
25
|
sender: string;
|
|
27
26
|
serverUrl: string;
|
|
28
27
|
parentGuid?: string;
|
|
29
28
|
|
|
30
|
-
boundsSize?:
|
|
29
|
+
boundsSize?: Vector3;
|
|
31
30
|
|
|
32
|
-
constructor(connectionId: string, seed: number, guid: string, name: string, hash: string, size: number, position:
|
|
31
|
+
constructor(connectionId: string, seed: number, guid: string, name: string, hash: string, size: number, position: Vector3 | null, serverUrl: string) {
|
|
33
32
|
this.seed = seed;
|
|
34
33
|
this.guid = guid;
|
|
35
34
|
this.file_name = name;
|
|
@@ -129,7 +128,7 @@ export function beginListenFileSpawn(context: Context) {
|
|
|
129
128
|
|
|
130
129
|
// add object to proper parent
|
|
131
130
|
if (evt.parentGuid) {
|
|
132
|
-
const parent = findByGuid(evt.parentGuid, context.scene) as
|
|
131
|
+
const parent = findByGuid(evt.parentGuid, context.scene) as Object3D;
|
|
133
132
|
if ("add" in parent) parent.add(obj);
|
|
134
133
|
}
|
|
135
134
|
if (!obj.parent)
|
|
@@ -182,16 +181,16 @@ async function handleUpload(connection: NetworkConnection, file: File, seed: num
|
|
|
182
181
|
}
|
|
183
182
|
|
|
184
183
|
|
|
185
|
-
const previews: { [key: string]:
|
|
184
|
+
const previews: { [key: string]: Object3D } = {};
|
|
186
185
|
|
|
187
186
|
function addPreview(evt: FileSpawnModel, context: Context) {
|
|
188
|
-
const sphere = new
|
|
189
|
-
const object = new
|
|
190
|
-
const box = new
|
|
187
|
+
const sphere = new BoxGeometry();
|
|
188
|
+
const object = new Mesh(sphere, new MeshBasicMaterial({ color: 0x00ff00 }));
|
|
189
|
+
const box = new BoxHelper(object, 0x555555);
|
|
191
190
|
previews[evt.guid] = box;
|
|
192
191
|
context.scene.add(box);
|
|
193
192
|
if (evt.parentGuid) {
|
|
194
|
-
const parent = findByGuid(evt.parentGuid, context.scene) as
|
|
193
|
+
const parent = findByGuid(evt.parentGuid, context.scene) as Object3D;
|
|
195
194
|
if (parent)
|
|
196
195
|
parent.add(box);
|
|
197
196
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as THREE from "three";
|
|
2
2
|
import { Mathf } from "./engine_math"
|
|
3
|
-
import { WebGLRenderer, Vector3, Quaternion, Uniform, Texture, Material, ShaderMaterial, CanvasTexture, AnimationAction, Camera, PerspectiveCamera } from "three";
|
|
3
|
+
import { WebGLRenderer, Vector3, Quaternion, Uniform, Texture, Material, ShaderMaterial, CanvasTexture, AnimationAction, Camera, PerspectiveCamera, Object3D, Euler, PlaneGeometry, Scene, Mesh } from "three";
|
|
4
4
|
import { CircularBuffer } from "./engine_utils";
|
|
5
5
|
|
|
6
6
|
|
|
@@ -12,16 +12,16 @@ export function slerp(vec: Vector3, end: Vector3, t: number) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const flipYQuat: Quaternion = new Quaternion().setFromAxisAngle(new Vector3(0, 1, 0), Math.PI);
|
|
15
|
-
export function lookAtInverse(obj:
|
|
15
|
+
export function lookAtInverse(obj: Object3D, target: Vector3) {
|
|
16
16
|
|
|
17
17
|
obj.lookAt(target);
|
|
18
18
|
obj.quaternion.multiply(flipYQuat);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
const _worldPositions = new CircularBuffer(() => new
|
|
22
|
+
const _worldPositions = new CircularBuffer(() => new Vector3(), 100);
|
|
23
23
|
|
|
24
|
-
export function getWorldPosition(obj:
|
|
24
|
+
export function getWorldPosition(obj: Object3D, vec: Vector3 | null = null, updateParents: boolean = true): Vector3 {
|
|
25
25
|
const wp = vec ?? _worldPositions.get();
|
|
26
26
|
if (!obj) return wp.set(0, 0, 0);
|
|
27
27
|
if (!obj.parent) return wp.copy(obj.position);
|
|
@@ -33,7 +33,7 @@ export function getWorldPosition(obj: THREE.Object3D, vec: THREE.Vector3 | null
|
|
|
33
33
|
return wp;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export function setWorldPosition(obj:
|
|
36
|
+
export function setWorldPosition(obj: Object3D, val: Vector3) {
|
|
37
37
|
if (!obj) return;
|
|
38
38
|
const wp = _worldPositions.get();
|
|
39
39
|
if (val !== wp)
|
|
@@ -43,25 +43,25 @@ export function setWorldPosition(obj: THREE.Object3D, val: THREE.Vector3) {
|
|
|
43
43
|
obj.position.set(wp.x, wp.y, wp.z);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
export function setWorldPositionXYZ(obj:
|
|
46
|
+
export function setWorldPositionXYZ(obj: Object3D, x: number, y: number, z: number) {
|
|
47
47
|
const wp = _worldPositions.get();
|
|
48
48
|
wp.set(x, y, z);
|
|
49
49
|
setWorldPosition(obj, wp);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
|
|
53
|
-
const _worldQuaternionBuffer:
|
|
54
|
-
const _worldQuaternion:
|
|
55
|
-
const _tempQuaternionBuffer2:
|
|
53
|
+
const _worldQuaternionBuffer: Quaternion = new Quaternion();
|
|
54
|
+
const _worldQuaternion: Quaternion = new Quaternion();
|
|
55
|
+
const _tempQuaternionBuffer2: Quaternion = new Quaternion();
|
|
56
56
|
|
|
57
|
-
export function getWorldQuaternion(obj:
|
|
57
|
+
export function getWorldQuaternion(obj: Object3D, target: Quaternion | null = null): Quaternion {
|
|
58
58
|
if (!obj) return _worldQuaternion.set(0, 0, 0, 1);
|
|
59
59
|
const quat = target ?? _worldQuaternion;
|
|
60
60
|
if (!obj.parent) return quat.copy(obj.quaternion);
|
|
61
61
|
obj.getWorldQuaternion(quat);
|
|
62
62
|
return quat;
|
|
63
63
|
}
|
|
64
|
-
export function setWorldQuaternion(obj:
|
|
64
|
+
export function setWorldQuaternion(obj: Object3D, val: Quaternion) {
|
|
65
65
|
if (!obj) return;
|
|
66
66
|
if (val !== _worldQuaternionBuffer)
|
|
67
67
|
_worldQuaternionBuffer.copy(val);
|
|
@@ -74,22 +74,22 @@ export function setWorldQuaternion(obj: THREE.Object3D, val: THREE.Quaternion) {
|
|
|
74
74
|
obj.quaternion.set(q.x, q.y, q.z, q.w);
|
|
75
75
|
// console.error("quaternion world to local is not yet implemented");
|
|
76
76
|
}
|
|
77
|
-
export function setWorldQuaternionXYZW(obj:
|
|
77
|
+
export function setWorldQuaternionXYZW(obj: Object3D, x: number, y: number, z: number, w: number) {
|
|
78
78
|
_worldQuaternionBuffer.set(x, y, z, w);
|
|
79
79
|
setWorldQuaternion(obj, _worldQuaternionBuffer);
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
const _worldScale:
|
|
83
|
-
const _worldScale2:
|
|
82
|
+
const _worldScale: Vector3 = new Vector3();
|
|
83
|
+
const _worldScale2: Vector3 = new Vector3();
|
|
84
84
|
|
|
85
|
-
export function getWorldScale(obj:
|
|
85
|
+
export function getWorldScale(obj: Object3D, vec: Vector3 | null = null): Vector3 {
|
|
86
86
|
if (!obj) return _worldScale.set(0, 0, 0);
|
|
87
87
|
if (!obj.parent) return _worldScale.copy(obj.scale);
|
|
88
88
|
obj.getWorldScale(vec ?? _worldScale);
|
|
89
89
|
return vec ?? _worldScale;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
export function setWorldScale(obj:
|
|
92
|
+
export function setWorldScale(obj: Object3D, vec: Vector3) {
|
|
93
93
|
if (!obj) return;
|
|
94
94
|
if (!obj.parent) {
|
|
95
95
|
obj.scale.copy(vec);
|
|
@@ -102,35 +102,35 @@ export function setWorldScale(obj: THREE.Object3D, vec: THREE.Vector3) {
|
|
|
102
102
|
obj.scale.copy(tempVec);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
const _forward = new
|
|
106
|
-
const _forwardQuat = new
|
|
107
|
-
export function forward(obj:
|
|
105
|
+
const _forward = new Vector3();
|
|
106
|
+
const _forwardQuat = new Quaternion();
|
|
107
|
+
export function forward(obj: Object3D): Vector3 {
|
|
108
108
|
getWorldQuaternion(obj, _forwardQuat);
|
|
109
109
|
return _forward.set(0, 0, 1).applyQuaternion(_forwardQuat);
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
|
|
113
113
|
|
|
114
|
-
const _worldEulerBuffer:
|
|
115
|
-
const _worldEuler:
|
|
116
|
-
const _worldRotation:
|
|
114
|
+
const _worldEulerBuffer: Euler = new Euler();
|
|
115
|
+
const _worldEuler: Euler = new Euler();
|
|
116
|
+
const _worldRotation: Vector3 = new Vector3();
|
|
117
117
|
|
|
118
118
|
|
|
119
119
|
|
|
120
120
|
// world euler (in radians)
|
|
121
|
-
export function getWorldEuler(obj:
|
|
121
|
+
export function getWorldEuler(obj: Object3D): Euler {
|
|
122
122
|
obj.getWorldQuaternion(_worldQuaternion);
|
|
123
123
|
_worldEuler.setFromQuaternion(_worldQuaternion);
|
|
124
124
|
return _worldEuler;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
// world euler (in radians)
|
|
128
|
-
export function setWorldEuler(obj:
|
|
128
|
+
export function setWorldEuler(obj: Object3D, val: Euler) {
|
|
129
129
|
setWorldQuaternion(obj, _worldQuaternion.setFromEuler(val));;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
// returns rotation in degrees
|
|
133
|
-
export function getWorldRotation(obj:
|
|
133
|
+
export function getWorldRotation(obj: Object3D): Vector3 {
|
|
134
134
|
const rot = getWorldEuler(obj);
|
|
135
135
|
const wr = _worldRotation;
|
|
136
136
|
wr.set(rot.x, rot.y, rot.z);
|
|
@@ -140,11 +140,11 @@ export function getWorldRotation(obj: THREE.Object3D): THREE.Vector3 {
|
|
|
140
140
|
return wr;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
export function setWorldRotation(obj:
|
|
143
|
+
export function setWorldRotation(obj: Object3D, val: Vector3) {
|
|
144
144
|
setWorldRotationXYZ(obj, val.x, val.y, val.z, true);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
export function setWorldRotationXYZ(obj:
|
|
147
|
+
export function setWorldRotationXYZ(obj: Object3D, x: number, y: number, z: number, degrees: boolean = true) {
|
|
148
148
|
if (degrees) {
|
|
149
149
|
x = Mathf.toRadians(x);
|
|
150
150
|
y = Mathf.toRadians(y);
|
|
@@ -159,18 +159,18 @@ export function setWorldRotationXYZ(obj: THREE.Object3D, x: number, y: number, z
|
|
|
159
159
|
|
|
160
160
|
|
|
161
161
|
|
|
162
|
-
// from https://github.com/mrdoob/
|
|
163
|
-
export function logHierarchy(root:
|
|
162
|
+
// from https://github.com/mrdoob/js/pull/10995#issuecomment-287614722
|
|
163
|
+
export function logHierarchy(root: Object3D | null | undefined, collapsible: boolean = true) {
|
|
164
164
|
if (!root) return;
|
|
165
165
|
if (collapsible) {
|
|
166
|
-
(function printGraph(obj:
|
|
166
|
+
(function printGraph(obj: Object3D) {
|
|
167
167
|
console.groupCollapsed((obj.name ? obj.name : '(no name : ' + obj.type + ')') + ' %o', obj);
|
|
168
168
|
obj.children.forEach(printGraph);
|
|
169
169
|
console.groupEnd();
|
|
170
170
|
}(root));
|
|
171
171
|
|
|
172
172
|
} else {
|
|
173
|
-
root.traverse(function (obj:
|
|
173
|
+
root.traverse(function (obj: Object3D) {
|
|
174
174
|
var s = '|___';
|
|
175
175
|
var obj2 = obj;
|
|
176
176
|
while (obj2.parent !== null) {
|
|
@@ -198,10 +198,10 @@ export function isAnimationAction(obj: object) {
|
|
|
198
198
|
|
|
199
199
|
|
|
200
200
|
export class Graphics {
|
|
201
|
-
private static planeGeometry = new
|
|
201
|
+
private static planeGeometry = new PlaneGeometry(2, 2, 1, 1);
|
|
202
202
|
private static renderer = new WebGLRenderer({ antialias: false });
|
|
203
|
-
private static perspectiveCam = new
|
|
204
|
-
private static scene = new
|
|
203
|
+
private static perspectiveCam = new PerspectiveCamera();
|
|
204
|
+
private static scene = new Scene();
|
|
205
205
|
private static readonly vertex = `
|
|
206
206
|
varying vec2 vUv;
|
|
207
207
|
void main(){
|
|
@@ -230,7 +230,7 @@ export class Graphics {
|
|
|
230
230
|
fragmentShader: fragment
|
|
231
231
|
});
|
|
232
232
|
}
|
|
233
|
-
private static readonly mesh = new
|
|
233
|
+
private static readonly mesh = new Mesh(this.planeGeometry, this.blipMaterial);
|
|
234
234
|
|
|
235
235
|
static copyTexture(texture: Texture, blitMaterial?: ShaderMaterial) {
|
|
236
236
|
const material = blitMaterial ?? this.blipMaterial;
|
|
@@ -292,12 +292,12 @@ export class Graphics {
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
/**@obsolete use Graphics.copyTexture */
|
|
295
|
-
export function copyTexture(texture:
|
|
295
|
+
export function copyTexture(texture: Texture): Texture {
|
|
296
296
|
return Graphics.copyTexture(texture);
|
|
297
297
|
}
|
|
298
298
|
|
|
299
299
|
/**@obsolete use Graphics.textureToCanvas */
|
|
300
|
-
export function textureToCanvas(texture:
|
|
300
|
+
export function textureToCanvas(texture: Texture, force: boolean = false): HTMLCanvasElement | null {
|
|
301
301
|
return Graphics.textureToCanvas(texture, force);
|
|
302
302
|
}
|
|
303
303
|
|
|
@@ -6,6 +6,7 @@ import { builtinComponentKeyName } from "../engine_constants";
|
|
|
6
6
|
import { resolveReferences } from "./extension_utils";
|
|
7
7
|
import { apply } from "../../engine-components/js-extensions/Object3D";
|
|
8
8
|
import { getLoader } from "../engine_gltf";
|
|
9
|
+
import { Object3D } from "three";
|
|
9
10
|
|
|
10
11
|
export const debug = debugExtension
|
|
11
12
|
const componentsArrayExportKey = "$___Export_Components";
|
|
@@ -17,11 +18,11 @@ class ExtensionData {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
class ExportData {
|
|
20
|
-
node:
|
|
21
|
+
node: Object3D;
|
|
21
22
|
nodeIndex: number;
|
|
22
23
|
nodeDef: any;
|
|
23
24
|
|
|
24
|
-
constructor(node:
|
|
25
|
+
constructor(node: Object3D, nodeIndex: number, nodeDef: any) {
|
|
25
26
|
this.node = node;
|
|
26
27
|
this.nodeIndex = nodeIndex;
|
|
27
28
|
this.nodeDef = nodeDef;
|
|
@@ -78,7 +79,7 @@ export class NEEDLE_components implements GLTFLoaderPlugin {
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
// https://github.com/mrdoob/three.js/blob/efbfc67edc7f65cfcc61a389ffc5fd43ea702bc6/examples/jsm/exporters/GLTFExporter.js#L532
|
|
81
|
-
serializeUserData(node:
|
|
82
|
+
serializeUserData(node: Object3D, _nodeDef: any) {
|
|
82
83
|
const components = node.userData?.components;
|
|
83
84
|
if (!components || components.length <= 0) return;
|
|
84
85
|
// delete components before serializing user data to avoid circular references
|
|
@@ -86,7 +87,7 @@ export class NEEDLE_components implements GLTFLoaderPlugin {
|
|
|
86
87
|
node[componentsArrayExportKey] = components;
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
afterSerializeUserData(node:
|
|
90
|
+
afterSerializeUserData(node: Object3D, _nodeDef) {
|
|
90
91
|
if (node.type === "Scene") {
|
|
91
92
|
if (debug)
|
|
92
93
|
console.log("DONE", JSON.stringify(_nodeDef));
|
|
@@ -102,7 +103,7 @@ export class NEEDLE_components implements GLTFLoaderPlugin {
|
|
|
102
103
|
// console.log(_nodeDef, _nodeDef.mesh);
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
writeNode(node:
|
|
106
|
+
writeNode(node: Object3D, nodeDef) {
|
|
106
107
|
let nodeIndex = this.writer.json.nodes.length;
|
|
107
108
|
console.log(node.name, nodeIndex, node.uuid);
|
|
108
109
|
const context = new ExportData(node, nodeIndex, nodeDef);
|
|
@@ -198,7 +199,7 @@ export class NEEDLE_components implements GLTFLoaderPlugin {
|
|
|
198
199
|
await Promise.all(loadComponents);
|
|
199
200
|
}
|
|
200
201
|
|
|
201
|
-
private async createComponents(obj:
|
|
202
|
+
private async createComponents(obj: Object3D, data: ExtensionData) {
|
|
202
203
|
if (!data) return;
|
|
203
204
|
const componentData = data[builtinComponentKeyName];
|
|
204
205
|
if (componentData) {
|
|
@@ -43,11 +43,20 @@ export class NEEDLE_lighting_settings implements GLTFLoaderPlugin {
|
|
|
43
43
|
if (ext) {
|
|
44
44
|
if (debug)
|
|
45
45
|
console.log("Apply \"" + this.name + "\", src: \"" + this.sourceId + "\"", ext);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
let settings: SceneLightSettings | undefined = undefined;
|
|
47
|
+
// If the result scene has only one child we add the LightingSettingsComponent to that child
|
|
48
|
+
if (_result.scene.children.length === 1) {
|
|
49
|
+
// add a component to the root of the scene
|
|
50
|
+
settings = GameObject.addNewComponent(_result.scene.children[0], SceneLightSettings, false);
|
|
51
|
+
}
|
|
52
|
+
// if the scene already has multiple children we add it as a new object
|
|
53
|
+
else
|
|
54
|
+
{
|
|
55
|
+
const lightSettings = new Object3D();
|
|
56
|
+
lightSettings.name = "Needle LightSettings";
|
|
57
|
+
_result.scene.add(lightSettings);
|
|
58
|
+
settings = GameObject.addNewComponent(lightSettings, SceneLightSettings, false);
|
|
59
|
+
}
|
|
51
60
|
settings.sourceId = this.sourceId;
|
|
52
61
|
settings.ambientIntensity = ext.ambientIntensity;
|
|
53
62
|
settings.ambientLight = new Color().fromArray(ext.ambientLight);
|
|
@@ -109,7 +118,7 @@ export class SceneLightSettings extends Behaviour {
|
|
|
109
118
|
}
|
|
110
119
|
if (this.ambientMode == AmbientMode.Flat) {
|
|
111
120
|
if (this.ambientLight && !this._ambientLightObj) {
|
|
112
|
-
this._ambientLightObj = new AmbientLight(this.ambientLight,
|
|
121
|
+
this._ambientLightObj = new AmbientLight(this.ambientLight, this.ambientIntensity);
|
|
113
122
|
}
|
|
114
123
|
if (this._ambientLightObj) {
|
|
115
124
|
this.gameObject.add(this._ambientLightObj)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader";
|
|
2
|
-
import * as THREE from 'three';
|
|
3
2
|
import { FindShaderTechniques, whiteDefaultTexture, ToUnityMatrixArray, SetUnitySphericalHarmonics } from '../engine_shaders';
|
|
4
|
-
import { IUniform, RawShaderMaterial, Vector4 } from 'three';
|
|
3
|
+
import { AlwaysDepth, BackSide, Camera, DoubleSide, EqualDepth, FrontSide, GreaterDepth, GreaterEqualDepth, IUniform, LessDepth, LessEqualDepth, LinearEncoding, Material, Matrix4, NotEqualDepth, Object3D, RawShaderMaterial, Vector3, Vector4 } from 'three';
|
|
5
4
|
import { Context } from '../engine_setup';
|
|
6
5
|
import { getParam } from "../engine_utils";
|
|
7
6
|
import * as SHADERDATA from "../shaders/shaderData"
|
|
@@ -37,13 +36,13 @@ enum UniformType {
|
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
class ObjectRendererData {
|
|
40
|
-
objectToWorldMatrix:
|
|
41
|
-
worldToObjectMatrix:
|
|
39
|
+
objectToWorldMatrix: Matrix4 = new Matrix4();
|
|
40
|
+
worldToObjectMatrix: Matrix4 = new Matrix4();
|
|
42
41
|
|
|
43
42
|
objectToWorld: Array<Vector4> = new Array<Vector4>();
|
|
44
43
|
worldToObject: Array<Vector4> = new Array<Vector4>();
|
|
45
44
|
|
|
46
|
-
updateFrom(obj:
|
|
45
|
+
updateFrom(obj: Object3D) {
|
|
47
46
|
this.objectToWorldMatrix.copy(obj.matrixWorld);
|
|
48
47
|
ToUnityMatrixArray(this.objectToWorldMatrix, this.objectToWorld);
|
|
49
48
|
|
|
@@ -132,7 +131,7 @@ export class CustomShader extends RawShaderMaterial {
|
|
|
132
131
|
this.uniforms["unity_SpecCube0"] = { value: envTexture };
|
|
133
132
|
SetUnitySphericalHarmonics(this.uniforms, array);
|
|
134
133
|
const hdr = Math.sqrt(Math.PI * .5);
|
|
135
|
-
this.uniforms["unity_SpecCube0_HDR"] = { value: new
|
|
134
|
+
this.uniforms["unity_SpecCube0_HDR"] = { value: new Vector4(hdr, hdr, hdr, hdr) };
|
|
136
135
|
// this.needsUpdate = true;
|
|
137
136
|
// this.uniformsNeedUpdate = true;
|
|
138
137
|
if (debug) console.log("Set environment lighting", this.uniforms);
|
|
@@ -143,20 +142,20 @@ export class CustomShader extends RawShaderMaterial {
|
|
|
143
142
|
private _objToWorldName = "hlslcc_mtx4x4unity_ObjectToWorld";
|
|
144
143
|
private _worldToObjectName = "hlslcc_mtx4x4unity_WorldToObject";
|
|
145
144
|
|
|
146
|
-
private static viewProjection:
|
|
145
|
+
private static viewProjection: Matrix4 = new Matrix4();
|
|
147
146
|
private static _viewProjectionValues: Array<Vector4> = [];
|
|
148
147
|
private _viewProjectionName = "hlslcc_mtx4x4unity_MatrixVP";
|
|
149
148
|
|
|
150
|
-
private static viewMatrix:
|
|
149
|
+
private static viewMatrix: Matrix4 = new Matrix4();
|
|
151
150
|
private static _viewMatrixValues: Array<Vector4> = [];
|
|
152
151
|
private _viewMatrixName = "hlslcc_mtx4x4unity_MatrixV";
|
|
153
152
|
|
|
154
153
|
private static _worldSpaceCameraPosName = "_WorldSpaceCameraPos";
|
|
155
|
-
private static _worldSpaceCameraPos:
|
|
154
|
+
private static _worldSpaceCameraPos: Vector3 = new Vector3();
|
|
156
155
|
|
|
157
|
-
private static _mainLightColor:
|
|
158
|
-
private static _mainLightPosition:
|
|
159
|
-
private static _lightData:
|
|
156
|
+
private static _mainLightColor: Vector4 = new Vector4();
|
|
157
|
+
private static _mainLightPosition: Vector3 = new Vector3();
|
|
158
|
+
private static _lightData: Vector4 = new Vector4();
|
|
160
159
|
|
|
161
160
|
private _rendererData = new ObjectRendererData();
|
|
162
161
|
|
|
@@ -184,7 +183,7 @@ export class CustomShader extends RawShaderMaterial {
|
|
|
184
183
|
this.onUpdateUniforms(camera, obj);
|
|
185
184
|
}
|
|
186
185
|
|
|
187
|
-
onUpdateUniforms(camera?:
|
|
186
|
+
onUpdateUniforms(camera?: Camera, obj?: any) {
|
|
188
187
|
|
|
189
188
|
const context = Context.Current;
|
|
190
189
|
|
|
@@ -309,7 +308,7 @@ export class NEEDLE_techniques_webgl implements GLTFLoaderPlugin {
|
|
|
309
308
|
this.identifier = identifier;
|
|
310
309
|
}
|
|
311
310
|
|
|
312
|
-
loadMaterial(index: number): Promise<
|
|
311
|
+
loadMaterial(index: number): Promise<Material> | null {
|
|
313
312
|
|
|
314
313
|
const mat = this.parser.json.materials[index];
|
|
315
314
|
if (!mat) {
|
|
@@ -328,7 +327,7 @@ export class NEEDLE_techniques_webgl implements GLTFLoaderPlugin {
|
|
|
328
327
|
const technique: SHADERDATA.Technique = shaders.techniques[techniqueIndex];
|
|
329
328
|
if (!technique) return null;
|
|
330
329
|
|
|
331
|
-
return new Promise<
|
|
330
|
+
return new Promise<Material>(async (resolve, reject) => {
|
|
332
331
|
const bundle = await FindShaderTechniques(shaders, technique.program!);
|
|
333
332
|
const frag = bundle?.fragmentShader;
|
|
334
333
|
const vert = bundle?.vertexShader;
|
|
@@ -342,7 +341,7 @@ export class NEEDLE_techniques_webgl implements GLTFLoaderPlugin {
|
|
|
342
341
|
const techniqueUniforms = technique.uniforms;
|
|
343
342
|
|
|
344
343
|
if (vert.includes("_Time"))
|
|
345
|
-
uniforms["_Time"] = { value: new
|
|
344
|
+
uniforms["_Time"] = { value: new Vector4(0, 0, 0, 0) };
|
|
346
345
|
|
|
347
346
|
for (const u in techniqueUniforms) {
|
|
348
347
|
const uniformName = u;
|
|
@@ -350,7 +349,7 @@ export class NEEDLE_techniques_webgl implements GLTFLoaderPlugin {
|
|
|
350
349
|
// const typeName = UniformType[uniformValues.type];
|
|
351
350
|
switch (uniformName) {
|
|
352
351
|
case "_TimeParameters":
|
|
353
|
-
const timeUniform = new
|
|
352
|
+
const timeUniform = new Vector4();
|
|
354
353
|
uniforms[uniformName] = { value: timeUniform };
|
|
355
354
|
break;
|
|
356
355
|
|
|
@@ -422,7 +421,7 @@ export class NEEDLE_techniques_webgl implements GLTFLoaderPlugin {
|
|
|
422
421
|
if (texIndex >= 0) {
|
|
423
422
|
const tex = await this.parser.getDependency("texture", texIndex);
|
|
424
423
|
if (tex) {
|
|
425
|
-
tex.encoding =
|
|
424
|
+
tex.encoding = LinearEncoding;
|
|
426
425
|
tex.needsUpdate = true;
|
|
427
426
|
}
|
|
428
427
|
uniforms[key] = { value: tex };
|
|
@@ -436,7 +435,7 @@ export class NEEDLE_techniques_webgl implements GLTFLoaderPlugin {
|
|
|
436
435
|
}
|
|
437
436
|
}
|
|
438
437
|
if (Array.isArray(val) && val.length === 4) {
|
|
439
|
-
uniforms[key] = { value: new
|
|
438
|
+
uniforms[key] = { value: new Vector4(val[0], val[1], val[2], val[3]) };
|
|
440
439
|
continue;
|
|
441
440
|
}
|
|
442
441
|
uniforms[key] = { value: val };
|
|
@@ -460,16 +459,16 @@ export class NEEDLE_techniques_webgl implements GLTFLoaderPlugin {
|
|
|
460
459
|
const culling = uniforms["_Cull"]?.value;
|
|
461
460
|
switch (culling) {
|
|
462
461
|
case CullMode.Off:
|
|
463
|
-
material.side =
|
|
462
|
+
material.side = DoubleSide;
|
|
464
463
|
break;
|
|
465
464
|
case CullMode.Front:
|
|
466
|
-
material.side =
|
|
465
|
+
material.side = BackSide;
|
|
467
466
|
break;
|
|
468
467
|
case CullMode.Back:
|
|
469
|
-
material.side =
|
|
468
|
+
material.side = FrontSide;
|
|
470
469
|
break;
|
|
471
470
|
default:
|
|
472
|
-
material.side =
|
|
471
|
+
material.side = FrontSide;
|
|
473
472
|
break;
|
|
474
473
|
}
|
|
475
474
|
|
|
@@ -477,31 +476,31 @@ export class NEEDLE_techniques_webgl implements GLTFLoaderPlugin {
|
|
|
477
476
|
switch (zTest) {
|
|
478
477
|
case ZTestMode.Equal:
|
|
479
478
|
material.depthTest = true;
|
|
480
|
-
material.depthFunc =
|
|
479
|
+
material.depthFunc = EqualDepth;
|
|
481
480
|
break;
|
|
482
481
|
case ZTestMode.NotEqual:
|
|
483
482
|
material.depthTest = true;
|
|
484
|
-
material.depthFunc =
|
|
483
|
+
material.depthFunc = NotEqualDepth;
|
|
485
484
|
break;
|
|
486
485
|
case ZTestMode.Less:
|
|
487
486
|
material.depthTest = true;
|
|
488
|
-
material.depthFunc =
|
|
487
|
+
material.depthFunc = LessDepth;
|
|
489
488
|
break;
|
|
490
489
|
case ZTestMode.LEqual:
|
|
491
490
|
material.depthTest = true;
|
|
492
|
-
material.depthFunc =
|
|
491
|
+
material.depthFunc = LessEqualDepth;
|
|
493
492
|
break;
|
|
494
493
|
case ZTestMode.Greater:
|
|
495
494
|
material.depthTest = true;
|
|
496
|
-
material.depthFunc =
|
|
495
|
+
material.depthFunc = GreaterDepth;
|
|
497
496
|
break;
|
|
498
497
|
case ZTestMode.GEqual:
|
|
499
498
|
material.depthTest = true;
|
|
500
|
-
material.depthFunc =
|
|
499
|
+
material.depthFunc = GreaterEqualDepth;
|
|
501
500
|
break;
|
|
502
501
|
case ZTestMode.Always:
|
|
503
502
|
material.depthTest = false;
|
|
504
|
-
material.depthFunc =
|
|
503
|
+
material.depthFunc = AlwaysDepth;
|
|
505
504
|
break;
|
|
506
505
|
}
|
|
507
506
|
|