@needle-tools/engine 2.65.2-pre → 2.67.0-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 +43 -0
- package/dist/needle-engine.js +34490 -26304
- package/dist/needle-engine.umd.cjs +748 -303
- package/lib/engine/api.d.ts +4 -0
- package/lib/engine/api.js +10 -0
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/codegen/register_types.js +23 -7
- package/lib/engine/codegen/register_types.js.map +1 -1
- package/lib/engine/debug/debug_overlay.js +11 -2
- package/lib/engine/debug/debug_overlay.js.map +1 -1
- package/lib/engine/engine_addressables.js +4 -4
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_assetdatabase.d.ts +17 -51
- package/lib/engine/engine_assetdatabase.js +252 -126
- package/lib/engine/engine_assetdatabase.js.map +1 -1
- package/lib/engine/engine_components.js +13 -1
- package/lib/engine/engine_components.js.map +1 -1
- package/lib/engine/engine_components_internal.d.ts +8 -0
- package/lib/engine/engine_components_internal.js +29 -0
- package/lib/engine/engine_components_internal.js.map +1 -0
- package/lib/engine/engine_constants.d.ts +1 -0
- package/lib/engine/engine_constants.js +1 -0
- package/lib/engine/engine_constants.js.map +1 -1
- package/lib/engine/engine_context_registry.d.ts +2 -0
- package/lib/engine/engine_context_registry.js +6 -0
- package/lib/engine/engine_context_registry.js.map +1 -1
- package/lib/engine/engine_editor-sync.d.ts +9 -0
- package/lib/engine/engine_editor-sync.js +8 -0
- package/lib/engine/engine_editor-sync.js.map +1 -0
- package/lib/engine/engine_element.d.ts +1 -0
- package/lib/engine/engine_element.js +4 -1
- package/lib/engine/engine_element.js.map +1 -1
- package/lib/engine/engine_element_loading.d.ts +3 -2
- package/lib/engine/engine_element_loading.js +19 -15
- package/lib/engine/engine_element_loading.js.map +1 -1
- package/lib/engine/engine_gameobject.js +21 -23
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_gizmos.js +3 -1
- package/lib/engine/engine_gizmos.js.map +1 -1
- package/lib/engine/engine_gltf_builtin_components.d.ts +2 -3
- package/lib/engine/engine_gltf_builtin_components.js +23 -6
- package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
- package/lib/engine/engine_networking.d.ts +3 -1
- package/lib/engine/engine_networking.js +10 -8
- package/lib/engine/engine_networking.js.map +1 -1
- package/lib/engine/engine_networking_auto.d.ts +1 -0
- package/lib/engine/engine_networking_auto.js +42 -9
- package/lib/engine/engine_networking_auto.js.map +1 -1
- package/lib/engine/engine_patcher.d.ts +8 -0
- package/lib/engine/engine_patcher.js +98 -0
- package/lib/engine/engine_patcher.js.map +1 -0
- package/lib/engine/engine_physics.d.ts +34 -2
- package/lib/engine/engine_physics.js +110 -11
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_scenetools.js +0 -1
- package/lib/engine/engine_scenetools.js.map +1 -1
- package/lib/engine/engine_serialization_core.js +4 -0
- package/lib/engine/engine_serialization_core.js.map +1 -1
- package/lib/engine/engine_setup.d.ts +1 -1
- package/lib/engine/engine_setup.js +12 -5
- package/lib/engine/engine_setup.js.map +1 -1
- package/lib/engine/engine_texture.d.ts +6 -1
- package/lib/engine/engine_texture.js +39 -1
- package/lib/engine/engine_texture.js.map +1 -1
- package/lib/engine/engine_types.d.ts +4 -0
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine/engine_utils.js +3 -2
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_progressive.d.ts +0 -1
- package/lib/engine/extensions/NEEDLE_progressive.js +24 -26
- package/lib/engine/extensions/NEEDLE_progressive.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_render_objects.js +9 -0
- package/lib/engine/extensions/NEEDLE_render_objects.js.map +1 -1
- package/lib/engine/extensions/extensions.d.ts +4 -1
- package/lib/engine/extensions/extensions.js +16 -0
- package/lib/engine/extensions/extensions.js.map +1 -1
- package/lib/engine/extensions/usage_tracker.d.ts +12 -0
- package/lib/engine/extensions/usage_tracker.js +59 -0
- package/lib/engine/extensions/usage_tracker.js.map +1 -0
- package/lib/engine-components/Animator.js +0 -1
- package/lib/engine-components/Animator.js.map +1 -1
- package/lib/engine-components/AnimatorController.js +4 -0
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/AudioSource.js +2 -1
- package/lib/engine-components/AudioSource.js.map +1 -1
- package/lib/engine-components/Camera.d.ts +6 -0
- package/lib/engine-components/Camera.js +70 -31
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/CharacterController.d.ts +1 -0
- package/lib/engine-components/CharacterController.js +14 -9
- package/lib/engine-components/CharacterController.js.map +1 -1
- package/lib/engine-components/Collider.js +14 -1
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Component.d.ts +52 -0
- package/lib/engine-components/Component.js +55 -14
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/Networking.js +19 -0
- package/lib/engine-components/Networking.js.map +1 -1
- package/lib/engine-components/OrbitControls.d.ts +2 -0
- package/lib/engine-components/OrbitControls.js +9 -0
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/ParticleSystem.d.ts +5 -1
- package/lib/engine-components/ParticleSystem.js +52 -7
- package/lib/engine-components/ParticleSystem.js.map +1 -1
- package/lib/engine-components/ParticleSystemModules.d.ts +2 -0
- package/lib/engine-components/ParticleSystemModules.js +26 -0
- package/lib/engine-components/ParticleSystemModules.js.map +1 -1
- package/lib/engine-components/ParticleSystemSubEmitter.js +5 -2
- package/lib/engine-components/ParticleSystemSubEmitter.js.map +1 -1
- package/lib/engine-components/ReflectionProbe.js +18 -6
- package/lib/engine-components/ReflectionProbe.js.map +1 -1
- package/lib/engine-components/Renderer.d.ts +1 -1
- package/lib/engine-components/Renderer.js +33 -11
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/ScreenCapture.js +3 -3
- package/lib/engine-components/ScreenCapture.js.map +1 -1
- package/lib/engine-components/Skybox.js +2 -0
- package/lib/engine-components/Skybox.js.map +1 -1
- package/lib/engine-components/SmoothFollow.js +1 -2
- package/lib/engine-components/SmoothFollow.js.map +1 -1
- package/lib/engine-components/SpectatorCamera.js +3 -3
- package/lib/engine-components/SpectatorCamera.js.map +1 -1
- package/lib/engine-components/SyncedCamera.js +1 -1
- package/lib/engine-components/SyncedCamera.js.map +1 -1
- package/lib/engine-components/SyncedTransform.js +2 -2
- package/lib/engine-components/SyncedTransform.js.map +1 -1
- package/lib/engine-components/TestRunner.js +1 -1
- package/lib/engine-components/TestRunner.js.map +1 -1
- package/lib/engine-components/WebARCameraBackground.d.ts +19 -0
- package/lib/engine-components/WebARCameraBackground.js +185 -0
- package/lib/engine-components/WebARCameraBackground.js.map +1 -0
- package/lib/engine-components/WebARSessionRoot.js +3 -2
- package/lib/engine-components/WebARSessionRoot.js.map +1 -1
- package/lib/engine-components/WebXR.d.ts +4 -0
- package/lib/engine-components/WebXR.js +11 -8
- package/lib/engine-components/WebXR.js.map +1 -1
- package/lib/engine-components/WebXRAvatar.js +1 -0
- package/lib/engine-components/WebXRAvatar.js.map +1 -1
- package/lib/engine-components/WebXRGrabRendering.js +2 -2
- package/lib/engine-components/WebXRGrabRendering.js.map +1 -1
- package/lib/engine-components/WebXRSync.js +2 -2
- package/lib/engine-components/WebXRSync.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +14 -6
- package/lib/engine-components/codegen/components.js +14 -6
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/js-extensions/Object3D.js +4 -1
- package/lib/engine-components/js-extensions/Object3D.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Antialiasing.d.ts +13 -0
- package/lib/engine-components/postprocessing/Effects/Antialiasing.js +46 -0
- package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/Bloom.d.ts +12 -0
- package/lib/engine-components/postprocessing/Effects/Bloom.js +76 -0
- package/lib/engine-components/postprocessing/Effects/Bloom.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/ChromaticAberration.d.ts +8 -0
- package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js +39 -0
- package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.d.ts +12 -0
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js +96 -0
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/DepthOfField.d.ts +21 -0
- package/lib/engine-components/postprocessing/Effects/DepthOfField.js +87 -0
- package/lib/engine-components/postprocessing/Effects/DepthOfField.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/Pixelation.d.ts +7 -0
- package/lib/engine-components/postprocessing/Effects/Pixelation.js +30 -0
- package/lib/engine-components/postprocessing/Effects/Pixelation.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.d.ts +11 -0
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js +70 -0
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/Tonemapping.d.ts +16 -0
- package/lib/engine-components/postprocessing/Effects/Tonemapping.js +52 -0
- package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -0
- package/lib/engine-components/postprocessing/Effects/Vignette.d.ts +11 -0
- package/lib/engine-components/postprocessing/Effects/Vignette.js +57 -0
- package/lib/engine-components/postprocessing/Effects/Vignette.js.map +1 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.d.ts +29 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.js +89 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.js.map +1 -0
- package/lib/engine-components/postprocessing/PostProcessingHandler.d.ts +13 -0
- package/lib/engine-components/postprocessing/PostProcessingHandler.js +119 -0
- package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -0
- package/lib/engine-components/postprocessing/Volume.d.ts +23 -0
- package/lib/engine-components/postprocessing/Volume.js +176 -0
- package/lib/engine-components/postprocessing/Volume.js.map +1 -0
- package/lib/engine-components/postprocessing/VolumeParameter.d.ts +21 -0
- package/lib/engine-components/postprocessing/VolumeParameter.js +75 -0
- package/lib/engine-components/postprocessing/VolumeParameter.js.map +1 -0
- package/lib/engine-components/postprocessing/VolumeProfile.d.ts +7 -0
- package/lib/engine-components/postprocessing/VolumeProfile.js +42 -0
- package/lib/engine-components/postprocessing/VolumeProfile.js.map +1 -0
- package/lib/engine-components/timeline/TimelineTracks.js +14 -15
- package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
- package/lib/engine-components/ui/Text.js +28 -170
- package/lib/engine-components/ui/Text.js.map +1 -1
- package/lib/engine-components-experimental/networking/PlayerSync.d.ts +18 -0
- package/lib/engine-components-experimental/networking/PlayerSync.js +62 -8
- package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
- package/lib/include/three/ARButton.d.ts +1 -1
- package/lib/include/three/ARButton.js +11 -19
- package/lib/include/three/ARButton.js.map +1 -1
- package/lib/include/three/VRButton.js +1 -4
- package/lib/include/three/VRButton.js.map +1 -1
- package/package.json +3 -2
- package/plugins/vite/drop-client.js +77 -0
- package/plugins/vite/drop.js +81 -0
- package/plugins/vite/editor-connection.js +121 -0
- package/plugins/vite/index.js +9 -4
- package/plugins/vite/meta.js +3 -0
- package/plugins/vite/poster-client.js +6 -4
- package/src/engine/api.ts +30 -1
- package/src/engine/codegen/register_types.js +25 -9
- package/src/engine/debug/debug_overlay.ts +11 -2
- package/src/engine/engine_addressables.ts +4 -4
- package/src/engine/engine_assetdatabase.ts +291 -184
- package/src/engine/engine_components.ts +20 -1
- package/src/engine/engine_components_internal.ts +30 -0
- package/src/engine/engine_constants.ts +4 -1
- package/src/engine/engine_context_registry.ts +7 -0
- package/src/engine/engine_editor-sync.ts +21 -0
- package/src/engine/engine_element.ts +8 -1
- package/src/engine/engine_element_loading.ts +19 -15
- package/src/engine/engine_gameobject.ts +579 -583
- package/src/engine/engine_gizmos.ts +3 -2
- package/src/engine/engine_gltf_builtin_components.ts +30 -15
- package/src/engine/engine_networking.ts +10 -8
- package/src/engine/engine_networking_auto.ts +48 -11
- package/src/engine/engine_patcher.ts +113 -0
- package/src/engine/engine_physics.ts +128 -12
- package/src/engine/engine_scenetools.ts +0 -1
- package/src/engine/engine_serialization_core.ts +6 -0
- package/src/engine/engine_setup.ts +15 -5
- package/src/engine/engine_texture.ts +54 -5
- package/src/engine/engine_types.ts +6 -1
- package/src/engine/engine_utils.ts +6 -5
- package/src/engine/extensions/NEEDLE_progressive.ts +32 -32
- package/src/engine/extensions/NEEDLE_render_objects.ts +10 -1
- package/src/engine/extensions/extensions.ts +22 -1
- package/src/engine/extensions/usage_tracker.ts +91 -0
- package/src/engine-components/Animator.ts +0 -1
- package/src/engine-components/AnimatorController.ts +2 -0
- package/src/engine-components/AudioSource.ts +1 -1
- package/src/engine-components/Camera.ts +77 -37
- package/src/engine-components/CharacterController.ts +12 -9
- package/src/engine-components/Collider.ts +16 -2
- package/src/engine-components/Component.ts +74 -30
- package/src/engine-components/Networking.ts +9 -1
- package/src/engine-components/OrbitControls.ts +11 -2
- package/src/engine-components/ParticleSystem.ts +54 -10
- package/src/engine-components/ParticleSystemModules.ts +28 -1
- package/src/engine-components/ParticleSystemSubEmitter.ts +5 -3
- package/src/engine-components/ReflectionProbe.ts +17 -7
- package/src/engine-components/Renderer.ts +36 -16
- package/src/engine-components/ScreenCapture.ts +3 -3
- package/src/engine-components/Skybox.ts +2 -0
- package/src/engine-components/SmoothFollow.ts +4 -4
- package/src/engine-components/SpectatorCamera.ts +3 -3
- package/src/engine-components/SyncedCamera.ts +1 -1
- package/src/engine-components/SyncedTransform.ts +2 -2
- package/src/engine-components/TestRunner.ts +1 -1
- package/src/engine-components/WebARCameraBackground.ts +215 -0
- package/src/engine-components/WebARSessionRoot.ts +3 -2
- package/src/engine-components/WebXR.ts +12 -8
- package/src/engine-components/WebXRAvatar.ts +1 -1
- package/src/engine-components/WebXRGrabRendering.ts +2 -2
- package/src/engine-components/WebXRSync.ts +2 -2
- package/src/engine-components/codegen/components.ts +14 -6
- package/src/engine-components/js-extensions/Object3D.ts +6 -1
- package/src/engine-components/postprocessing/Effects/Antialiasing.ts +52 -0
- package/src/engine-components/postprocessing/Effects/Bloom.ts +75 -0
- package/src/engine-components/postprocessing/Effects/ChromaticAberration.ts +36 -0
- package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +114 -0
- package/src/engine-components/postprocessing/Effects/DepthOfField.ts +90 -0
- package/src/engine-components/postprocessing/Effects/Pixelation.ts +28 -0
- package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.ts +71 -0
- package/src/engine-components/postprocessing/Effects/Tonemapping.ts +55 -0
- package/src/engine-components/postprocessing/Effects/Vignette.ts +55 -0
- package/src/engine-components/postprocessing/PostProcessingEffect.ts +112 -0
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +148 -0
- package/src/engine-components/postprocessing/Volume.ts +194 -0
- package/src/engine-components/postprocessing/VolumeParameter.ts +85 -0
- package/src/engine-components/postprocessing/VolumeProfile.ts +40 -0
- package/src/engine-components/timeline/TimelineTracks.ts +16 -17
- package/src/engine-components/ui/Text.ts +37 -174
- package/src/engine-components-experimental/networking/PlayerSync.ts +69 -8
- package/src/include/three/ARButton.js +13 -24
- package/src/include/three/VRButton.js +1 -7
- package/lib/engine-components/Volume.d.ts +0 -34
- package/lib/engine-components/Volume.js +0 -140
- package/lib/engine-components/Volume.js.map +0 -1
- package/src/engine-components/Volume.ts +0 -141
|
@@ -145,10 +145,9 @@ class Internal {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
static getSphere(radius: number, duration: number, wireframe: boolean): Mesh {
|
|
148
|
-
|
|
149
148
|
let sphere = this.spheresCache.pop();
|
|
150
149
|
if (!sphere) {
|
|
151
|
-
sphere = new Mesh(new SphereGeometry(
|
|
150
|
+
sphere = new Mesh(new SphereGeometry(1, 8, 8));
|
|
152
151
|
}
|
|
153
152
|
sphere.scale.set(radius, radius, radius);
|
|
154
153
|
sphere.material["wireframe"] = wireframe;
|
|
@@ -176,6 +175,8 @@ class Internal {
|
|
|
176
175
|
this.contextPostRenderCallbacks.set(context, cb);
|
|
177
176
|
context.post_render_callbacks.push(cb);
|
|
178
177
|
}
|
|
178
|
+
object.layers.disableAll();
|
|
179
|
+
object.layers.enable(2);
|
|
179
180
|
object[$cacheSymbol] = cache;
|
|
180
181
|
this.timedObjectsBuffer.push(object);
|
|
181
182
|
this.timesBuffer.push(Context.Current.time.time + duration);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import "./codegen/register_types";
|
|
2
2
|
import { TypeStore } from "./engine_typestore";
|
|
3
3
|
import * as THREE from "three";
|
|
4
|
-
import {
|
|
4
|
+
// import { GameObject } from "../engine-components/Component";
|
|
5
5
|
import { InstantiateIdProvider } from "./engine_networking_instantiate"
|
|
6
6
|
import { Context } from "./engine_setup";
|
|
7
7
|
import { deserializeObject, serializeObject } from "./engine_serialization";
|
|
8
8
|
import { assign, ImplementationInformation, ISerializable, SerializationContext } from "./engine_serialization_core";
|
|
9
9
|
import { NEEDLE_components } from "./extensions/NEEDLE_components";
|
|
10
10
|
import { debugExtension } from "./engine_default_parameters";
|
|
11
|
-
import { builtinComponentKeyName } from "./engine_constants";
|
|
12
|
-
import { GuidsMap, SourceIdentifier } from "./engine_types";
|
|
11
|
+
import { $originalGuid, builtinComponentKeyName } from "./engine_constants";
|
|
12
|
+
import { GuidsMap, IComponent, IGameObject, SourceIdentifier } from "./engine_types";
|
|
13
13
|
import { UIDProvider } from "./engine_types";
|
|
14
14
|
import { addNewComponent } from "./engine_components";
|
|
15
15
|
import { getParam } from "./engine_utils";
|
|
@@ -21,7 +21,7 @@ const debug = debugExtension;
|
|
|
21
21
|
const debugTypeStore = getParam("debugtypestore");
|
|
22
22
|
if (debugTypeStore) console.log(TypeStore);
|
|
23
23
|
|
|
24
|
-
export function writeBuiltinComponentData(comp:
|
|
24
|
+
export function writeBuiltinComponentData(comp: IComponent, context: SerializationContext): object | null {
|
|
25
25
|
|
|
26
26
|
// const fn = (comp as unknown as ISerializable)?.onBeforeSerialize;
|
|
27
27
|
// if (fn) {
|
|
@@ -39,6 +39,7 @@ export function writeBuiltinComponentData(comp: Component, context: Serializatio
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
const typeImplementationInformation = new ImplementationInformation();
|
|
42
|
+
const $context_deserialize_queue = Symbol("deserialize-queue");
|
|
42
43
|
|
|
43
44
|
export async function createBuiltinComponents(context: Context, gltfId: SourceIdentifier, gltf, seed: number | null | UIDProvider = null, extension?: NEEDLE_components) {
|
|
44
45
|
if (!gltf) return;
|
|
@@ -56,26 +57,34 @@ export async function createBuiltinComponents(context: Context, gltfId: SourceId
|
|
|
56
57
|
serializationContext.nodeToObject = extension?.nodeToObjectMap;
|
|
57
58
|
serializationContext.implementationInformation = typeImplementationInformation;
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
// If we're loading multiple gltf files in one scene we need to make sure we deserialize all of them in one go
|
|
61
|
+
// for that we collect them in one list per context
|
|
62
|
+
let deserializeQueue = context[$context_deserialize_queue];
|
|
63
|
+
if (!deserializeQueue) deserializeQueue = context[$context_deserialize_queue] = [];
|
|
60
64
|
|
|
61
65
|
if (gltf.scenes) {
|
|
62
66
|
for (const scene of gltf.scenes) {
|
|
63
|
-
await onCreateBuiltinComponents(serializationContext, scene,
|
|
67
|
+
await onCreateBuiltinComponents(serializationContext, scene, deserializeQueue, lateResolve);
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
if (gltf.children) {
|
|
67
71
|
for (const ch of gltf.children) {
|
|
68
|
-
await onCreateBuiltinComponents(serializationContext, ch,
|
|
72
|
+
await onCreateBuiltinComponents(serializationContext, ch, deserializeQueue, lateResolve);
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
|
|
72
|
-
|
|
73
76
|
context.new_scripts_pre_setup_callbacks.push(() => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
// First deserialize ALL components that were loaded before pre setup
|
|
78
|
+
// Down below they get new guids assigned so we have to do all of them first
|
|
79
|
+
// E.g. in cases where we load multiple glb files on startup from one scene
|
|
80
|
+
// and they might have cross-glb references
|
|
81
|
+
const queue = context[$context_deserialize_queue];
|
|
82
|
+
if (queue) {
|
|
83
|
+
for (const des of queue) {
|
|
84
|
+
handleDeserialization(des, serializationContext);
|
|
85
|
+
}
|
|
86
|
+
queue.length = 0;
|
|
77
87
|
}
|
|
78
|
-
|
|
79
88
|
// when dropping the same file multiple times we need to generate new guids
|
|
80
89
|
// e.g. SyncTransform sends its own guid to the server to know about ownership
|
|
81
90
|
// so it requires a unique guid for a new instance
|
|
@@ -95,7 +104,7 @@ export async function createBuiltinComponents(context: Context, gltfId: SourceId
|
|
|
95
104
|
// console.log("finished creating builtin components", gltf.scene?.name, gltf);
|
|
96
105
|
}
|
|
97
106
|
|
|
98
|
-
function recursiveCreateGuids(obj:
|
|
107
|
+
function recursiveCreateGuids(obj: IGameObject, idProvider: UIDProvider | null, guidsMap: GuidsMap) {
|
|
99
108
|
if (idProvider === null) return;
|
|
100
109
|
if (!obj) return;
|
|
101
110
|
const prev = obj.guid;
|
|
@@ -117,7 +126,7 @@ function recursiveCreateGuids(obj: GameObject, idProvider: UIDProvider | null, g
|
|
|
117
126
|
}
|
|
118
127
|
if (obj.children) {
|
|
119
128
|
for (const child of obj.children) {
|
|
120
|
-
recursiveCreateGuids(child as
|
|
129
|
+
recursiveCreateGuids(child as IGameObject, idProvider, guidsMap);
|
|
121
130
|
}
|
|
122
131
|
}
|
|
123
132
|
}
|
|
@@ -140,6 +149,7 @@ declare type LateResolveCallback = (gltf: THREE.Object3D) => void;
|
|
|
140
149
|
|
|
141
150
|
const unknownComponentsBuffer: Array<string> = [];
|
|
142
151
|
|
|
152
|
+
|
|
143
153
|
async function onCreateBuiltinComponents(context: SerializationContext, obj: THREE.Object3D,
|
|
144
154
|
deserialize: DeserializeData[], lateResolve: LateResolveCallback[]) {
|
|
145
155
|
if (!obj) return;
|
|
@@ -156,11 +166,16 @@ async function onCreateBuiltinComponents(context: SerializationContext, obj: THR
|
|
|
156
166
|
const type = TypeStore.get(compData.name);
|
|
157
167
|
// console.log(compData, compData.name, type, TypeStore);
|
|
158
168
|
if (type !== undefined && type !== null) {
|
|
159
|
-
const instance:
|
|
169
|
+
const instance: IComponent = new type() as IComponent;
|
|
160
170
|
instance.sourceId = context.gltfId;
|
|
161
171
|
|
|
162
172
|
// assign basic fields
|
|
163
173
|
assign(instance, compData, context.implementationInformation);
|
|
174
|
+
|
|
175
|
+
// assign the guid of the original instance
|
|
176
|
+
if("guid" in compData)
|
|
177
|
+
instance[$originalGuid] = compData.guid;
|
|
178
|
+
|
|
164
179
|
// Object.assign(instance, compData);
|
|
165
180
|
// dont call awake here because some references might not be resolved yet and components that access those fields in awake will throw
|
|
166
181
|
// for example Duplicatable reference to object might still be { node: id }
|
|
@@ -147,7 +147,7 @@ export class OwnershipModel {
|
|
|
147
147
|
// console.log(res);
|
|
148
148
|
if (res.guid === this.guid) {
|
|
149
149
|
if (this._isWaitingForOwnershipResponseCallback) {
|
|
150
|
-
this.connection.
|
|
150
|
+
this.connection.stopListen(OwnershipEvent.ResponseHasOwner, this._isWaitingForOwnershipResponseCallback);
|
|
151
151
|
this._isWaitingForOwnershipResponseCallback = null;
|
|
152
152
|
}
|
|
153
153
|
this._isOwned = res.value;
|
|
@@ -185,18 +185,18 @@ export class OwnershipModel {
|
|
|
185
185
|
// TODO: abort "requestOwnershipIfNotOwned"
|
|
186
186
|
this.connection.send(OwnershipEvent.RemoveOwnership, { guid: this.guid });
|
|
187
187
|
if (this._isWaitingForOwnershipResponseCallback) {
|
|
188
|
-
this.connection.
|
|
188
|
+
this.connection.stopListen(OwnershipEvent.ResponseHasOwner, this._isWaitingForOwnershipResponseCallback);
|
|
189
189
|
this._isWaitingForOwnershipResponseCallback = null;
|
|
190
190
|
}
|
|
191
191
|
return this;
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
public destroy() {
|
|
195
|
-
this.connection.
|
|
196
|
-
this.connection.
|
|
197
|
-
this.connection.
|
|
195
|
+
this.connection.stopListen(OwnershipEvent.GainedOwnership, this._gainSubscription);
|
|
196
|
+
this.connection.stopListen(OwnershipEvent.LostOwnership, this._lostSubscription);
|
|
197
|
+
this.connection.stopListen(OwnershipEvent.ResponseHasOwner, this._hasOwnerResponse);
|
|
198
198
|
if (this._isWaitingForOwnershipResponseCallback) {
|
|
199
|
-
this.connection.
|
|
199
|
+
this.connection.stopListen(OwnershipEvent.ResponseHasOwner, this._isWaitingForOwnershipResponseCallback);
|
|
200
200
|
this._isWaitingForOwnershipResponseCallback = null;
|
|
201
201
|
}
|
|
202
202
|
}
|
|
@@ -368,7 +368,9 @@ export class NetworkConnection implements INetworkConnection {
|
|
|
368
368
|
return callback;
|
|
369
369
|
}
|
|
370
370
|
|
|
371
|
-
|
|
371
|
+
/**@deprecated please use stopListen instead (2.65.2-pre) */
|
|
372
|
+
public stopListening(key: string | OwnershipEvent, callback: Function | null) { return this.stopListen(key, callback); }
|
|
373
|
+
public stopListen(key: string | OwnershipEvent, callback: Function | null) {
|
|
372
374
|
if (!callback) return;
|
|
373
375
|
if (!this._listeners[key]) return;
|
|
374
376
|
const index = this._listeners[key].indexOf(callback);
|
|
@@ -377,7 +379,7 @@ export class NetworkConnection implements INetworkConnection {
|
|
|
377
379
|
}
|
|
378
380
|
}
|
|
379
381
|
|
|
380
|
-
public
|
|
382
|
+
public beginListenBinary(identifier: string, callback: BinaryCallback): BinaryCallback {
|
|
381
383
|
if (!this._listenersBinary[identifier])
|
|
382
384
|
this._listenersBinary[identifier] = [];
|
|
383
385
|
this._listenersBinary[identifier].push(callback);
|
|
@@ -4,6 +4,7 @@ import { RoomEvents } from "./engine_networking";
|
|
|
4
4
|
|
|
5
5
|
const debug = getParam("debugautosync");
|
|
6
6
|
|
|
7
|
+
const $syncerId = Symbol("syncerId");
|
|
7
8
|
class ComponentsSyncerManager {
|
|
8
9
|
private _syncers: { [key: string]: ComponentPropertiesSyncer } = {};
|
|
9
10
|
|
|
@@ -11,9 +12,14 @@ class ComponentsSyncerManager {
|
|
|
11
12
|
if (!comp.guid) return null;
|
|
12
13
|
if (this._syncers[comp.guid]) return this._syncers[comp.guid];
|
|
13
14
|
const syncer = new ComponentPropertiesSyncer(comp);
|
|
14
|
-
|
|
15
|
+
syncer[$syncerId] = comp.guid;
|
|
16
|
+
this._syncers[syncer[$syncerId]] = syncer;
|
|
15
17
|
return syncer;
|
|
16
18
|
}
|
|
19
|
+
|
|
20
|
+
removeSyncer(syncer: ComponentPropertiesSyncer) {
|
|
21
|
+
delete this._syncers[syncer[$syncerId]];
|
|
22
|
+
}
|
|
17
23
|
}
|
|
18
24
|
const syncerHandler = new ComponentsSyncerManager();
|
|
19
25
|
|
|
@@ -35,6 +41,7 @@ class ComponentPropertiesSyncer {
|
|
|
35
41
|
private data = {};
|
|
36
42
|
|
|
37
43
|
private _boundEvent?: Function;
|
|
44
|
+
private _handleReceivingMethod?: Function;
|
|
38
45
|
|
|
39
46
|
get networkingKey(): string {
|
|
40
47
|
const obj = this.comp as object;
|
|
@@ -46,6 +53,7 @@ class ComponentPropertiesSyncer {
|
|
|
46
53
|
private _isReceiving: boolean = false;
|
|
47
54
|
private _isInit = false;
|
|
48
55
|
|
|
56
|
+
|
|
49
57
|
init(comp) {
|
|
50
58
|
if (this._isInit) return;
|
|
51
59
|
this._isInit = true;
|
|
@@ -53,10 +61,22 @@ class ComponentPropertiesSyncer {
|
|
|
53
61
|
// console.log("INIT", this.comp.name, this.networkingKey);
|
|
54
62
|
this._boundEvent = this.onHandleSending.bind(this);
|
|
55
63
|
this.comp.context.post_render_callbacks.push(this._boundEvent);
|
|
56
|
-
this.
|
|
64
|
+
this._handleReceivingMethod = this.onHandleReceiving.bind(this);
|
|
65
|
+
this.comp.context.connection.beginListen(this.networkingKey, this._handleReceivingMethod);
|
|
57
66
|
|
|
58
67
|
const state = this.comp.context.connection.tryGetState(this.comp.guid);
|
|
59
|
-
if(state) this.onHandleReceiving(state);
|
|
68
|
+
if (state) this.onHandleReceiving(state);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
destroy() {
|
|
72
|
+
if (!this._isInit) return;
|
|
73
|
+
if (this._boundEvent)
|
|
74
|
+
this.comp.context.post_render_callbacks.splice(this.comp.context.post_render_callbacks.indexOf(this._boundEvent), 1);
|
|
75
|
+
if (this._handleReceivingMethod)
|
|
76
|
+
this.comp.context.connection.stopListen(this.networkingKey, this._handleReceivingMethod);
|
|
77
|
+
//@ts-ignore
|
|
78
|
+
this.comp = null;
|
|
79
|
+
this._isInit = false;
|
|
60
80
|
}
|
|
61
81
|
|
|
62
82
|
notifyChanged(propertyName: string, value: any) {
|
|
@@ -156,16 +176,26 @@ function testValueChanged(newValue, previousValue): boolean {
|
|
|
156
176
|
return valueChanged;
|
|
157
177
|
}
|
|
158
178
|
|
|
179
|
+
const $syncer = Symbol("AutoSyncHandler");
|
|
159
180
|
function getSyncer(instance): ComponentPropertiesSyncer | null {
|
|
160
|
-
if (instance[
|
|
161
|
-
return instance[
|
|
181
|
+
if (instance[$syncer]) {
|
|
182
|
+
return instance[$syncer];
|
|
162
183
|
}
|
|
163
184
|
const syncer = syncerHandler.getOrCreateSyncer(instance);
|
|
164
185
|
syncer?.init(instance);
|
|
165
|
-
instance[
|
|
186
|
+
instance[$syncer] = syncer;
|
|
166
187
|
return syncer;
|
|
167
188
|
}
|
|
168
189
|
|
|
190
|
+
function destroySyncer(instance) {
|
|
191
|
+
const syncer = instance[$syncer];
|
|
192
|
+
if (syncer) {
|
|
193
|
+
syncerHandler.removeSyncer(syncer);
|
|
194
|
+
syncer.destroy();
|
|
195
|
+
delete instance[$syncer];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
169
199
|
export declare type SyncFieldOptions = {
|
|
170
200
|
onPropertyChanged: Function,
|
|
171
201
|
};
|
|
@@ -190,7 +220,7 @@ export const syncField = function (onFieldChanged?: string) {
|
|
|
190
220
|
const internalAwake = t.__internalAwake;
|
|
191
221
|
if (debug)
|
|
192
222
|
console.log(propertyKey);
|
|
193
|
-
const backingFieldName = propertyKey
|
|
223
|
+
const backingFieldName = Symbol(propertyKey);
|
|
194
224
|
|
|
195
225
|
t.__internalAwake = function () {
|
|
196
226
|
if (this[backingFieldName] !== undefined) {
|
|
@@ -221,7 +251,13 @@ export const syncField = function (onFieldChanged?: string) {
|
|
|
221
251
|
}
|
|
222
252
|
|
|
223
253
|
syncer?.init(this);
|
|
224
|
-
|
|
254
|
+
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const internalDestroy = t.__internalDestroy;
|
|
258
|
+
t.__internalDestroy = function () {
|
|
259
|
+
destroySyncer(this);
|
|
260
|
+
internalDestroy.call(this);
|
|
225
261
|
}
|
|
226
262
|
|
|
227
263
|
}
|
|
@@ -233,6 +269,7 @@ export declare type SyncOptions = {
|
|
|
233
269
|
fieldName?: string,
|
|
234
270
|
};
|
|
235
271
|
|
|
272
|
+
/** experimental - use syncField instead */
|
|
236
273
|
export const sync = function (_options?: SyncOptions) {
|
|
237
274
|
|
|
238
275
|
return function <T>(target: any, _propertyKey: string, descriptor: PropertyDescriptor) {
|
|
@@ -253,14 +290,14 @@ export const sync = function (_options?: SyncOptions) {
|
|
|
253
290
|
// inject getter and setter
|
|
254
291
|
if (!descriptor.get) {
|
|
255
292
|
const previousSetter = descriptor.set;
|
|
256
|
-
const
|
|
293
|
+
const $backingField = Symbol(_propertyKey);
|
|
257
294
|
Object.defineProperty(target, _propertyKey, {
|
|
258
295
|
set: function (value) {
|
|
259
|
-
this[
|
|
296
|
+
this[$backingField] = value;
|
|
260
297
|
previousSetter?.call(this, value);
|
|
261
298
|
},
|
|
262
299
|
get: function () {
|
|
263
|
-
return this[
|
|
300
|
+
return this[$backingField];
|
|
264
301
|
}
|
|
265
302
|
});
|
|
266
303
|
const newDescriptor = Object.getOwnPropertyDescriptor(target, _propertyKey);
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
|
|
2
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn
|
|
3
|
+
|
|
4
|
+
const _wrappedMethods = new WeakSet();
|
|
5
|
+
|
|
6
|
+
export declare type FieldPatch = (instance: object, oldValue: any, newValue: any) => any;
|
|
7
|
+
export type MethodPatch<T> = (instance: T, result: any, ...args) => any;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Use patcher for patching properties insteadof calling Object.defineProperty individually
|
|
11
|
+
* since this will cause conflicts if multiple patches need to be applied to the same property
|
|
12
|
+
*/
|
|
13
|
+
export function addPatch<TType extends object, TCallback extends (FieldPatch | MethodPatch<any>)>(prototype: TType, fieldName: string, cb: TCallback) {
|
|
14
|
+
|
|
15
|
+
// TODO: we probably want to turn this into a symbol to prevent anyone from overriding it
|
|
16
|
+
// But when we need to store the symbol per prototype to allow e.g. material disposing to iterate those and dispose all
|
|
17
|
+
const backingField = fieldName + "__needle";// Symbol(fieldName);// + " (patched)";
|
|
18
|
+
|
|
19
|
+
internalAddPatch(prototype, fieldName, cb);
|
|
20
|
+
|
|
21
|
+
const desc = Object.getOwnPropertyDescriptor(prototype, fieldName);
|
|
22
|
+
|
|
23
|
+
if (desc) {
|
|
24
|
+
// TODO: check if the property is writable
|
|
25
|
+
// the property might be a method in which case we want to wrap it
|
|
26
|
+
if (typeof desc.value === "function") {
|
|
27
|
+
const method = desc.value;
|
|
28
|
+
if (method) {
|
|
29
|
+
if (_wrappedMethods.has(method)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
_wrappedMethods.add(method);
|
|
33
|
+
prototype[fieldName] = function (this: object, ...args: any[]) {
|
|
34
|
+
// call the original method
|
|
35
|
+
const result = method.apply(this, args);
|
|
36
|
+
// call the patches
|
|
37
|
+
const patches = getPatches(prototype, fieldName);
|
|
38
|
+
if (patches) {
|
|
39
|
+
for (const patch of patches) {
|
|
40
|
+
patch(this, result, ...args);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// TODO: declare method?
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else if (prototype.hasOwnProperty(backingField)) {
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
Object.defineProperty(prototype, fieldName, {
|
|
55
|
+
set: function (this: object, value: any) {
|
|
56
|
+
const prev = this[backingField];
|
|
57
|
+
this[backingField] = value;
|
|
58
|
+
executePatches(prototype, fieldName, this, prev, value);
|
|
59
|
+
},
|
|
60
|
+
get: function (this: any) {
|
|
61
|
+
return this[backingField];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function removePatch(prototype: object, fieldName: string, cb: Function) {
|
|
68
|
+
const patches = getPatches(prototype, fieldName);
|
|
69
|
+
if (patches) {
|
|
70
|
+
for (let i = patches.length - 1; i >= 0; i--) {
|
|
71
|
+
if (patches[i] === cb) {
|
|
72
|
+
patches.splice(i, 1);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
const patches = new WeakMap<object, Map<string, Function[]>>();
|
|
82
|
+
|
|
83
|
+
function getPatches(prototype, fieldName: string) {
|
|
84
|
+
let patchesMap = patches.get(prototype);
|
|
85
|
+
if (!patchesMap) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
return patchesMap.get(fieldName);;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function internalAddPatch(prototype, fieldName: string, cb: Function) {
|
|
92
|
+
let patchesMap = patches.get(prototype);
|
|
93
|
+
if (!patchesMap) {
|
|
94
|
+
patchesMap = new Map();
|
|
95
|
+
patches.set(prototype, patchesMap);
|
|
96
|
+
}
|
|
97
|
+
let patchList = patchesMap.get(fieldName);
|
|
98
|
+
if (!patchList) {
|
|
99
|
+
patchList = [];
|
|
100
|
+
patchesMap.set(fieldName, patchList);
|
|
101
|
+
}
|
|
102
|
+
patchList.push(cb);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function executePatches(prototype, fieldName: string, instance: object, oldValue: any, newValue: any) {
|
|
106
|
+
if (!instance) return;
|
|
107
|
+
const patches = getPatches(prototype, fieldName);
|
|
108
|
+
if (patches) {
|
|
109
|
+
for (const patch of patches) {
|
|
110
|
+
patch(instance, oldValue, newValue);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|