@needle-tools/engine 4.1.0-experimental.13 → 4.1.0
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 +72 -10
- package/README.md +28 -17
- package/components.needle.json +1 -1
- package/dist/gltf-progressive.js +220 -221
- package/dist/gltf-progressive.light.js +220 -221
- package/dist/gltf-progressive.light.min.js +6 -6
- package/dist/gltf-progressive.light.umd.cjs +7 -7
- package/dist/gltf-progressive.min.js +6 -6
- package/dist/gltf-progressive.umd.cjs +7 -7
- package/dist/needle-engine.bundle.js +8237 -7948
- package/dist/needle-engine.bundle.light.js +8190 -7901
- package/dist/needle-engine.bundle.light.min.js +140 -141
- package/dist/needle-engine.bundle.light.umd.cjs +138 -139
- package/dist/needle-engine.bundle.min.js +140 -141
- package/dist/needle-engine.bundle.umd.cjs +134 -135
- package/dist/needle-engine.d.ts +140 -0
- package/dist/needle-engine.js +597 -590
- package/dist/needle-engine.light.d.ts +140 -0
- package/dist/needle-engine.light.js +597 -590
- package/dist/needle-engine.light.min.js +1 -1
- package/dist/needle-engine.light.umd.cjs +1 -1
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/postprocessing.js +1 -1
- package/dist/postprocessing.light.js +1 -1
- package/dist/postprocessing.light.min.js +1 -1
- package/dist/postprocessing.min.js +1 -1
- package/dist/three-examples.js +2809 -2450
- package/dist/three-examples.light.js +2809 -2450
- package/dist/three-examples.light.min.js +47 -15
- package/dist/three-examples.light.umd.cjs +47 -15
- package/dist/three-examples.min.js +47 -15
- package/dist/three-examples.umd.cjs +47 -15
- package/dist/three-mesh-ui.js +1 -1
- package/dist/three-mesh-ui.light.js +1 -1
- package/dist/three-mesh-ui.light.min.js +1 -1
- package/dist/three-mesh-ui.min.js +1 -1
- package/dist/three.js +577 -572
- package/dist/three.light.js +577 -572
- package/dist/three.light.min.js +170 -170
- package/dist/three.light.umd.cjs +170 -170
- package/dist/three.min.js +170 -170
- package/dist/three.umd.cjs +170 -170
- package/dist/vendor.js +1327 -1331
- package/dist/vendor.light.js +1327 -1331
- package/dist/vendor.light.min.js +33 -33
- package/dist/vendor.light.umd.cjs +33 -33
- package/dist/vendor.min.js +33 -33
- package/dist/vendor.umd.cjs +33 -33
- package/lib/engine/assets/index.js.map +1 -1
- package/lib/engine/engine.d.ts +4 -0
- package/lib/engine/engine.js +12 -0
- package/lib/engine/engine.js.map +1 -0
- package/lib/engine/engine_addressables.d.ts +6 -4
- package/lib/engine/engine_addressables.js +8 -1
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_context.d.ts +3 -2
- package/lib/engine/engine_context.js +28 -4
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_gameobject.d.ts +2 -12
- package/lib/engine/engine_gameobject.js +5 -15
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_gltf_builtin_components.js +5 -0
- package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
- package/lib/engine/engine_input.d.ts +19 -6
- package/lib/engine/engine_input.js +0 -10
- package/lib/engine/engine_input.js.map +1 -1
- package/lib/engine/engine_license.js +1 -1
- package/lib/engine/engine_license.js.map +1 -1
- package/lib/engine/engine_modules.d.ts +7 -0
- package/lib/engine/engine_modules.js +7 -0
- package/lib/engine/engine_modules.js.map +1 -1
- package/lib/engine/engine_networking_auto.js +6 -11
- package/lib/engine/engine_networking_auto.js.map +1 -1
- package/lib/engine/engine_networking_instantiate.d.ts +1 -1
- package/lib/engine/engine_physics_rapier.d.ts +6 -4
- package/lib/engine/engine_physics_rapier.js +38 -24
- package/lib/engine/engine_physics_rapier.js.map +1 -1
- package/lib/engine/engine_scenetools.js +6 -2
- package/lib/engine/engine_scenetools.js.map +1 -1
- package/lib/engine/engine_types.d.ts +9 -2
- package/lib/engine/engine_types.js +6 -0
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine/engine_web_api.d.ts +12 -0
- package/lib/engine/engine_web_api.js +113 -0
- package/lib/engine/engine_web_api.js.map +1 -0
- package/lib/engine/export/gltf/Writers.js.map +1 -1
- package/lib/engine/export/gltf/index.js +11 -1
- package/lib/engine/export/gltf/index.js.map +1 -1
- package/lib/engine/export/utils.d.ts +2 -0
- package/lib/engine/export/utils.js +8 -0
- package/lib/engine/export/utils.js.map +1 -0
- package/lib/engine/extensions/NEEDLE_gameobject_data.js +1 -1
- package/lib/engine/extensions/NEEDLE_gameobject_data.js.map +1 -1
- package/lib/engine/js-extensions/Object3D.d.ts +5 -1
- package/lib/engine/js-extensions/Object3D.js.map +1 -1
- package/lib/engine/webcomponents/needle menu/needle-menu.js +8 -2
- package/lib/engine/webcomponents/needle menu/needle-menu.js.map +1 -1
- package/lib/engine/xr/NeedleXRSession.js +3 -0
- package/lib/engine/xr/NeedleXRSession.js.map +1 -1
- package/lib/engine-components/AvatarLoader.js.map +1 -1
- package/lib/engine-components/Camera.d.ts +7 -4
- package/lib/engine-components/Camera.js +13 -10
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/Collider.js +4 -5
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Component.d.ts +4 -3
- package/lib/engine-components/Component.js +6 -7
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/ContactShadows.d.ts +1 -1
- package/lib/engine-components/ContactShadows.js +7 -0
- package/lib/engine-components/ContactShadows.js.map +1 -1
- package/lib/engine-components/FlyControls.d.ts +10 -0
- package/lib/engine-components/FlyControls.js +29 -0
- package/lib/engine-components/FlyControls.js.map +1 -0
- package/lib/engine-components/GroundProjection.d.ts +1 -1
- package/lib/engine-components/GroundProjection.js +39 -32
- package/lib/engine-components/GroundProjection.js.map +1 -1
- package/lib/engine-components/OrbitControls.js +9 -1
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/RigidBody.d.ts +1 -0
- package/lib/engine-components/RigidBody.js +11 -4
- package/lib/engine-components/RigidBody.js.map +1 -1
- package/lib/engine-components/SceneSwitcher.d.ts +1 -1
- package/lib/engine-components/SceneSwitcher.js +1 -1
- package/lib/engine-components/SceneSwitcher.js.map +1 -1
- package/lib/engine-components/SpatialTrigger.d.ts +2 -2
- package/lib/engine-components/SpatialTrigger.js +4 -4
- package/lib/engine-components/SpatialTrigger.js.map +1 -1
- package/lib/engine-components/TransformGizmo.d.ts +7 -1
- package/lib/engine-components/TransformGizmo.js +39 -32
- package/lib/engine-components/TransformGizmo.js.map +1 -1
- package/lib/engine-components/VideoPlayer.js +0 -1
- package/lib/engine-components/VideoPlayer.js.map +1 -1
- package/lib/engine-components/export/gltf/GltfExport.js +23 -4
- package/lib/engine-components/export/gltf/GltfExport.js.map +1 -1
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.d.ts +1 -1
- package/lib/engine-components/export/usdz/ThreeUSDZExporter.js +2 -2
- package/lib/engine-components/export/usdz/index.d.ts +1 -1
- package/lib/engine-components/export/usdz/index.js +1 -1
- package/lib/engine-components/export/usdz/index.js.map +1 -1
- package/lib/engine-components/particlesystem/ParticleSystem.d.ts +5 -6
- package/lib/engine-components/particlesystem/ParticleSystem.js +23 -9
- package/lib/engine-components/particlesystem/ParticleSystem.js.map +1 -1
- package/lib/engine-components/particlesystem/ParticleSystemModules.js +8 -2
- package/lib/engine-components/particlesystem/ParticleSystemModules.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/BloomEffect.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Pixelation.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Sharpening.d.ts +2 -0
- package/lib/engine-components/postprocessing/Effects/Sharpening.js +15 -6
- package/lib/engine-components/postprocessing/Effects/Sharpening.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/TiltShiftEffect.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Vignette.js.map +1 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.js +1 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
- package/lib/engine-components/webxr/Avatar.js +3 -3
- package/lib/engine-components/webxr/Avatar.js.map +1 -1
- package/lib/engine-components/webxr/WebXR.js +22 -13
- package/lib/engine-components/webxr/WebXR.js.map +1 -1
- package/lib/engine-components/webxr/WebXRImageTracking.d.ts +4 -0
- package/lib/engine-components/webxr/WebXRImageTracking.js +14 -4
- package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
- package/lib/engine-components/webxr/WebXRRig.d.ts +11 -1
- package/lib/engine-components/webxr/WebXRRig.js +13 -1
- package/lib/engine-components/webxr/WebXRRig.js.map +1 -1
- package/lib/engine-components-experimental/networking/PlayerSync.d.ts +4 -1
- package/lib/engine-components-experimental/networking/PlayerSync.js +18 -30
- package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
- package/lib/needle-engine.js +5 -5
- package/lib/needle-engine.js.map +1 -1
- package/package.json +14 -8
- package/plugins/common/config.cjs +22 -6
- package/plugins/common/config.js +27 -11
- package/plugins/next/next.js +47 -4
- package/plugins/vite/transform.js +3 -3
- package/src/engine/assets/index.ts +1 -0
- package/src/engine/codegen/register_types.ts +2 -2
- package/src/engine/engine_addressables.ts +19 -12
- package/src/engine/engine_context.ts +33 -8
- package/src/engine/engine_gameobject.ts +12 -16
- package/src/engine/engine_gltf_builtin_components.ts +7 -1
- package/src/engine/engine_input.ts +12 -5
- package/src/engine/engine_license.ts +2 -1
- package/src/engine/engine_modules.ts +7 -0
- package/src/engine/engine_networking_auto.ts +7 -22
- package/src/engine/engine_networking_instantiate.ts +1 -1
- package/src/engine/engine_physics_rapier.ts +48 -26
- package/src/engine/engine_scenetools.ts +6 -2
- package/src/engine/engine_types.ts +10 -2
- package/src/engine/export/gltf/Writers.ts +0 -1
- package/src/engine/export/gltf/index.ts +13 -3
- package/src/engine/export/index.ts +1 -1
- package/src/engine/export/utils.ts +10 -0
- package/src/engine/extensions/NEEDLE_gameobject_data.ts +1 -2
- package/src/engine/js-extensions/Object3D.ts +6 -1
- package/src/engine/webcomponents/needle menu/needle-menu.ts +16 -10
- package/src/engine/xr/NeedleXRSession.ts +4 -1
- package/src/engine-components/AvatarLoader.ts +1 -1
- package/src/engine-components/Camera.ts +14 -11
- package/src/engine-components/Collider.ts +4 -4
- package/src/engine-components/Component.ts +13 -7
- package/src/engine-components/ContactShadows.ts +11 -2
- package/src/engine-components/GroundProjection.ts +46 -38
- package/src/engine-components/OrbitControls.ts +9 -1
- package/src/engine-components/RigidBody.ts +13 -5
- package/src/engine-components/SceneSwitcher.ts +1 -1
- package/src/engine-components/SpatialTrigger.ts +6 -6
- package/src/engine-components/TransformGizmo.ts +41 -33
- package/src/engine-components/VideoPlayer.ts +0 -1
- package/src/engine-components/export/gltf/GltfExport.ts +26 -6
- package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +2 -2
- package/src/engine-components/export/usdz/index.ts +1 -1
- package/src/engine-components/particlesystem/ParticleSystem.ts +26 -10
- package/src/engine-components/particlesystem/ParticleSystemModules.ts +10 -3
- package/src/engine-components/postprocessing/Effects/Antialiasing.ts +0 -1
- package/src/engine-components/postprocessing/Effects/BloomEffect.ts +1 -1
- package/src/engine-components/postprocessing/Effects/ChromaticAberration.ts +1 -1
- package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +1 -1
- package/src/engine-components/postprocessing/Effects/Pixelation.ts +1 -1
- package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusion.ts +1 -1
- package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.ts +1 -1
- package/src/engine-components/postprocessing/Effects/Sharpening.ts +17 -7
- package/src/engine-components/postprocessing/Effects/TiltShiftEffect.ts +0 -1
- package/src/engine-components/postprocessing/Effects/Tonemapping.ts +1 -1
- package/src/engine-components/postprocessing/Effects/Vignette.ts +1 -1
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +2 -3
- package/src/engine-components/webxr/Avatar.ts +3 -3
- package/src/engine-components/webxr/WebXR.ts +23 -14
- package/src/engine-components/webxr/WebXRImageTracking.ts +23 -8
- package/src/engine-components/webxr/WebXRRig.ts +15 -2
- package/src/engine-components-experimental/networking/PlayerSync.ts +18 -37
- package/src/needle-engine.ts +5 -5
package/plugins/common/config.js
CHANGED
|
@@ -1,19 +1,35 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "fs";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @returns {import("../types").needleConfig | null}
|
|
7
|
+
*/
|
|
8
|
+
export function getConfig() {
|
|
4
9
|
const workingDirectory = process.cwd();
|
|
5
|
-
const configPath = workingDirectory
|
|
6
|
-
if(existsSync(configPath)) {
|
|
10
|
+
const configPath = `${workingDirectory}/needle.config.json`;
|
|
11
|
+
if (existsSync(configPath)) {
|
|
7
12
|
const configStr = readFileSync(configPath, "utf8");
|
|
8
13
|
const config = JSON.parse(configStr);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
return config;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @returns {import("../types").needleMeta | null}
|
|
22
|
+
*/
|
|
23
|
+
export function getMeta() {
|
|
24
|
+
const workingDirectory = process.cwd();
|
|
25
|
+
const config = getConfig();
|
|
26
|
+
if (config && config.codegenDirectory) {
|
|
27
|
+
const dir = `${workingDirectory}/${config.codegenDirectory}/meta.json`;
|
|
28
|
+
if (existsSync(dir)) {
|
|
29
|
+
const metaStr = readFileSync(dir, "utf8");
|
|
30
|
+
/**@type {import("../types").needleMeta} */
|
|
31
|
+
const meta = JSON.parse(metaStr);
|
|
32
|
+
return meta;
|
|
17
33
|
}
|
|
18
34
|
}
|
|
19
35
|
return null;
|
package/plugins/next/next.js
CHANGED
|
@@ -2,8 +2,9 @@ import { fileURLToPath } from 'url';
|
|
|
2
2
|
import { dirname, resolve } from 'path';
|
|
3
3
|
import { tryGetNeedleEngineVersion } from '../common/version.js';
|
|
4
4
|
import { tryGetGenerator } from '../common/generator.js';
|
|
5
|
-
import { getMeta } from '../common/config.cjs';
|
|
5
|
+
import { getConfig, getMeta } from '../common/config.cjs';
|
|
6
6
|
import { alias } from './alias.cjs';
|
|
7
|
+
import { createBuildInfoFile } from '../common/buildinfo.js';
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -24,12 +25,37 @@ export const needleNext = (nextConfig, userSettings) => {
|
|
|
24
25
|
reactStrictMode: true,
|
|
25
26
|
};
|
|
26
27
|
|
|
28
|
+
const needleConfig = getConfig();
|
|
29
|
+
|
|
27
30
|
// add transpile packages
|
|
28
31
|
if (!nextConfig.transpilePackages) {
|
|
29
32
|
nextConfig.transpilePackages = [];
|
|
30
33
|
}
|
|
31
34
|
nextConfig.transpilePackages.push("three", "peerjs", "three-mesh-ui");
|
|
32
35
|
|
|
36
|
+
if (nextConfig.output === undefined) {
|
|
37
|
+
console.log("Set output to 'export' (see 'https://nextjs.org/docs/pages/building-your-application/deploying/static-exports#configuration' for more information)");
|
|
38
|
+
nextConfig.output = "export";
|
|
39
|
+
// we *also* need to turn OFF image optimization for static HTML files to be generated
|
|
40
|
+
// see https://github.com/vercel/next.js/issues/40240
|
|
41
|
+
if (nextConfig.images === undefined) {
|
|
42
|
+
nextConfig.images = {
|
|
43
|
+
unoptimized: true
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (nextConfig.distDir == undefined) {
|
|
48
|
+
console.log("Export to 'dist'");
|
|
49
|
+
if (needleConfig?.buildDirectory) {
|
|
50
|
+
console.log(`Using build directory from needle config: ${needleConfig.buildDirectory}`);
|
|
51
|
+
nextConfig.distDir = needleConfig.buildDirectory;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
console.log("Using default build directory 'dist'. You can override the output directory via the needle config or by setting nextConfig.distDir");
|
|
55
|
+
nextConfig.distDir = "dist";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
33
59
|
// add webpack config
|
|
34
60
|
if (!nextConfig.webpack) nextConfig.webpack = nextWebPack;
|
|
35
61
|
else {
|
|
@@ -43,11 +69,11 @@ export const needleNext = (nextConfig, userSettings) => {
|
|
|
43
69
|
function nextWebPack(config, { buildId, dev, isServer, defaultLoaders, webpack }) {
|
|
44
70
|
|
|
45
71
|
// TODO: get public identifier key from license server
|
|
46
|
-
|
|
72
|
+
|
|
47
73
|
const meta = getMeta();
|
|
48
74
|
let useRapier = true;
|
|
49
75
|
if (userSettings.useRapier === false) useRapier = false;
|
|
50
|
-
else if (meta.useRapier === false) useRapier = false;
|
|
76
|
+
else if (meta && meta.useRapier === false) useRapier = false;
|
|
51
77
|
// add defines
|
|
52
78
|
const webpackModule = userSettings.modules?.webpack;
|
|
53
79
|
const definePlugin = webpackModule && new webpackModule.DefinePlugin({
|
|
@@ -68,7 +94,6 @@ export const needleNext = (nextConfig, userSettings) => {
|
|
|
68
94
|
test: /engine_license\.(ts|js)$/,
|
|
69
95
|
loader: resolve(__dirname, 'license.cjs')
|
|
70
96
|
});
|
|
71
|
-
|
|
72
97
|
// add mesh bvh worker transform
|
|
73
98
|
config.module.rules.push({
|
|
74
99
|
test: /generateMeshBVH.worker\.js$/,
|
|
@@ -77,6 +102,24 @@ export const needleNext = (nextConfig, userSettings) => {
|
|
|
77
102
|
|
|
78
103
|
alias(config);
|
|
79
104
|
|
|
105
|
+
// these hooks are invoked but nextjs deletes the files again:
|
|
106
|
+
// add webpack done plugin https://webpack.js.org/api/compiler-hooks/
|
|
107
|
+
// config.plugins.push({
|
|
108
|
+
// apply(compiler) {
|
|
109
|
+
// compiler.hooks.shutdown.tap('NeedleDonePlugin', (stats) => {
|
|
110
|
+
// return createBuildInfoFile(nextConfig.distDir);
|
|
111
|
+
// });
|
|
112
|
+
// }
|
|
113
|
+
// });
|
|
114
|
+
// so as a workaround for above's problem:
|
|
115
|
+
// hook into process quit event since there doesn't seem to be a next hook for "after emit"
|
|
116
|
+
// node's beforeExit event is not called :(
|
|
117
|
+
process.on('exit', (code) => {
|
|
118
|
+
if (code === 0)
|
|
119
|
+
return createBuildInfoFile(nextConfig.distDir);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
|
|
80
123
|
return config;
|
|
81
124
|
}
|
|
82
125
|
|
|
@@ -15,9 +15,9 @@ export const needleTransformCode = (command, config, userSettings) => {
|
|
|
15
15
|
*/
|
|
16
16
|
transform(src, id) {
|
|
17
17
|
if (id.includes("three__quarks.js") || id.includes("three.quarks")) {
|
|
18
|
-
const line1 = `console.log('%c Particle system powered by three.quarks. https://quarks.art/', 'font-size:
|
|
19
|
-
const line2 = `console.log("%c Particle system powered by three.quarks. https://quarks.art/", "font-size:
|
|
20
|
-
const replacement = `setTimeout(()=> console.
|
|
18
|
+
const line1 = `console.log('%c Particle system powered by three.quarks. https://quarks.art/', 'font-size: 14px; font-weight: bold;');`
|
|
19
|
+
const line2 = `console.log("%c Particle system powered by three.quarks. https://quarks.art/", "font-size: 14px; font-weight: bold;");`;
|
|
20
|
+
const replacement = `setTimeout(()=> console.debug("Particle system powered by three.quarks. https://quarks.art/"), 100);`
|
|
21
21
|
const content = src
|
|
22
22
|
.replace(line1, replacement)
|
|
23
23
|
.replace(line2, replacement);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
import { TypeStore } from "./../engine_typestore.js"
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
// Import types
|
|
5
5
|
import { AlignmentConstraint } from "../../engine-components/AlignmentConstraint.js";
|
|
6
6
|
import { Animation } from "../../engine-components/Animation.js";
|
|
@@ -220,7 +220,7 @@ import { XRFlag } from "../../engine-components/webxr/XRFlag.js";
|
|
|
220
220
|
import { PlayerSync } from "../../engine-components-experimental/networking/PlayerSync.js";
|
|
221
221
|
import { PlayerState } from "../../engine-components-experimental/networking/PlayerSync.js";
|
|
222
222
|
import { PresentationMode } from "../../engine-components-experimental/Presentation.js";
|
|
223
|
-
|
|
223
|
+
|
|
224
224
|
// Register types
|
|
225
225
|
TypeStore.add("AlignmentConstraint", AlignmentConstraint);
|
|
226
226
|
TypeStore.add("Animation", Animation);
|
|
@@ -5,10 +5,10 @@ import { destroy, type IInstantiateOptions, instantiate, InstantiateOptions, isD
|
|
|
5
5
|
import { getLoader } from "./engine_gltf.js";
|
|
6
6
|
import { processNewScripts } from "./engine_mainloop_utils.js";
|
|
7
7
|
import { BlobStorage } from "./engine_networking_blob.js";
|
|
8
|
-
import { registerPrefabProvider, syncInstantiate,SyncInstantiateOptions } from "./engine_networking_instantiate.js";
|
|
8
|
+
import { registerPrefabProvider, syncInstantiate, SyncInstantiateOptions } from "./engine_networking_instantiate.js";
|
|
9
9
|
import { SerializationContext, TypeSerializer } from "./engine_serialization_core.js";
|
|
10
10
|
import { Context } from "./engine_setup.js";
|
|
11
|
-
import type { IComponent, IGameObject, SourceIdentifier } from "./engine_types.js";
|
|
11
|
+
import type { GLTF, IComponent, IGameObject, SourceIdentifier } from "./engine_types.js";
|
|
12
12
|
|
|
13
13
|
const debug = getParam("debugaddressables");
|
|
14
14
|
|
|
@@ -140,8 +140,11 @@ export class AssetReference {
|
|
|
140
140
|
|
|
141
141
|
private static currentlyInstantiating: Map<string, number> = new Map<string, number>();
|
|
142
142
|
|
|
143
|
+
/** @returns true if this is an AssetReference instance */
|
|
144
|
+
get isAssetReference() { return true; }
|
|
145
|
+
|
|
143
146
|
/** The loaded asset */
|
|
144
|
-
get asset():
|
|
147
|
+
get asset(): Object3D | null {
|
|
145
148
|
return this._glbRoot ?? this._asset;
|
|
146
149
|
}
|
|
147
150
|
|
|
@@ -183,7 +186,7 @@ export class AssetReference {
|
|
|
183
186
|
private _hashedUri: string;
|
|
184
187
|
|
|
185
188
|
private _isLoadingRawBinary: boolean = false;
|
|
186
|
-
private _rawBinary?:
|
|
189
|
+
private _rawBinary?: ArrayBufferLike | null;
|
|
187
190
|
|
|
188
191
|
/** @internal */
|
|
189
192
|
constructor(uri: string, hash?: string, asset: any = null) {
|
|
@@ -197,7 +200,7 @@ export class AssetReference {
|
|
|
197
200
|
registerPrefabProvider(this._url, this.onResolvePrefab.bind(this));
|
|
198
201
|
}
|
|
199
202
|
|
|
200
|
-
private async onResolvePrefab(url: string): Promise<
|
|
203
|
+
private async onResolvePrefab(url: string): Promise<Object3D | null> {
|
|
201
204
|
if (url === this.url) {
|
|
202
205
|
if (this.mustLoad) await this.loadAssetAsync();
|
|
203
206
|
if (this.asset) {
|
|
@@ -208,7 +211,7 @@ export class AssetReference {
|
|
|
208
211
|
}
|
|
209
212
|
|
|
210
213
|
private get mustLoad() {
|
|
211
|
-
return !this.asset || this.asset.__destroyed === true || isDestroyed(this.asset) === true;
|
|
214
|
+
return !this.asset || (this.asset as any).__destroyed === true || isDestroyed(this.asset) === true;
|
|
212
215
|
}
|
|
213
216
|
|
|
214
217
|
/**
|
|
@@ -220,8 +223,8 @@ export class AssetReference {
|
|
|
220
223
|
if (this.asset) {
|
|
221
224
|
if (debug) console.log("Unload", this.asset);
|
|
222
225
|
// TODO: we need a way to remove objects from the context (including components) without actually "destroying" them
|
|
223
|
-
if (this.asset.scene)
|
|
224
|
-
destroy(this.asset.scene, true, true);
|
|
226
|
+
if ("scene" in this.asset && this.asset.scene)
|
|
227
|
+
destroy(this.asset.scene as Object3D, true, true);
|
|
225
228
|
destroy(this.asset, true, true);
|
|
226
229
|
}
|
|
227
230
|
this.asset = null;
|
|
@@ -234,7 +237,7 @@ export class AssetReference {
|
|
|
234
237
|
}
|
|
235
238
|
|
|
236
239
|
/** loads the asset binary without creating an instance */
|
|
237
|
-
async preload(): Promise<
|
|
240
|
+
async preload(): Promise<ArrayBufferLike | null> {
|
|
238
241
|
if (!this.mustLoad) return null;
|
|
239
242
|
if (this._isLoadingRawBinary) return null;
|
|
240
243
|
if (this._rawBinary !== undefined) return this._rawBinary;
|
|
@@ -268,6 +271,10 @@ export class AssetReference {
|
|
|
268
271
|
// we should "address" (LUL) this
|
|
269
272
|
// console.log("START LOADING");
|
|
270
273
|
if (this._rawBinary) {
|
|
274
|
+
if (!(this._rawBinary instanceof ArrayBuffer)) {
|
|
275
|
+
console.error("Invalid raw binary data", this._rawBinary);
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
271
278
|
this._loading = getLoader().parseSync(context, this._rawBinary, this.url, null);
|
|
272
279
|
this.raiseProgressEvent(new ProgressEvent("progress", { loaded: this._rawBinary.byteLength, total: this._rawBinary.byteLength }));
|
|
273
280
|
}
|
|
@@ -283,7 +290,6 @@ export class AssetReference {
|
|
|
283
290
|
this._glbRoot = this.tryGetActualGameObjectRoot(res);
|
|
284
291
|
this._loading = undefined;
|
|
285
292
|
if (res) {
|
|
286
|
-
|
|
287
293
|
// Make sure the loaded roots all have a reference to this AssetReference
|
|
288
294
|
// that was originally loading it.
|
|
289
295
|
// We need this when the loaded asset is being disposed
|
|
@@ -302,10 +308,11 @@ export class AssetReference {
|
|
|
302
308
|
}
|
|
303
309
|
return this.asset;
|
|
304
310
|
}
|
|
311
|
+
return null;
|
|
305
312
|
}
|
|
306
313
|
|
|
307
314
|
/** loads and returns a new instance of `asset` */
|
|
308
|
-
async instantiate(parent?: Object3D | IInstantiateOptions) {
|
|
315
|
+
async instantiate(parent?: Object3D | IInstantiateOptions | null) {
|
|
309
316
|
return this.onInstantiate(parent, false);
|
|
310
317
|
}
|
|
311
318
|
|
|
@@ -332,7 +339,7 @@ export class AssetReference {
|
|
|
332
339
|
}
|
|
333
340
|
}
|
|
334
341
|
|
|
335
|
-
private async onInstantiate(opts?: Object3D | IInstantiateOptions | SyncInstantiateOptions, networked: boolean = false, saveOnServer?: boolean)
|
|
342
|
+
private async onInstantiate(opts?: Object3D | IInstantiateOptions | SyncInstantiateOptions | null, networked: boolean = false, saveOnServer?: boolean): Promise<Object3D | null> {
|
|
336
343
|
const context = Context.Current;
|
|
337
344
|
|
|
338
345
|
// clone the instantiate options immediately
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import 'three/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js';
|
|
2
|
+
|
|
1
3
|
import type { EffectComposer } from "postprocessing";
|
|
2
4
|
import {
|
|
3
5
|
BufferGeometry, Camera, Color, DepthTexture, Group,
|
|
4
|
-
Material, NearestFilter, NoToneMapping, Object3D, PCFSoftShadowMap,
|
|
6
|
+
Material, NearestFilter, NoToneMapping, Object3D, OrthographicCamera, PCFSoftShadowMap,
|
|
5
7
|
PerspectiveCamera, RGBAFormat, Scene, SRGBColorSpace,
|
|
6
8
|
Texture, WebGLRenderer, type WebGLRendererParameters, WebGLRenderTarget, type WebXRArrayCamera
|
|
7
9
|
} from 'three';
|
|
@@ -156,6 +158,8 @@ export class Context implements IContext {
|
|
|
156
158
|
// Note: this is due to a bug on OSX devices. See NE-5370
|
|
157
159
|
powerPreference: (DeviceUtilities.isiOS() || DeviceUtilities.isMacOS()) ? "default" : "high-performance",
|
|
158
160
|
stencil: true,
|
|
161
|
+
// logarithmicDepthBuffer: true,
|
|
162
|
+
// reverseDepthBuffer: true, // https://github.com/mrdoob/three.js/issues/29770
|
|
159
163
|
};
|
|
160
164
|
/** The default parameters that will be used when creating a new WebGLRenderer.
|
|
161
165
|
* Modify in global context to change the default parameters for all new contexts.
|
|
@@ -485,7 +489,7 @@ export class Context implements IContext {
|
|
|
485
489
|
this.renderer.shadowMap.type = PCFSoftShadowMap;
|
|
486
490
|
this.renderer.setSize(this.domWidth, this.domHeight);
|
|
487
491
|
this.renderer.outputColorSpace = SRGBColorSpace;
|
|
488
|
-
|
|
492
|
+
|
|
489
493
|
// Injecting the core nodes library here, like WebGPURenderer backends do
|
|
490
494
|
//@ts-ignore
|
|
491
495
|
this.renderer.nodes = {
|
|
@@ -545,16 +549,37 @@ export class Context implements IContext {
|
|
|
545
549
|
}
|
|
546
550
|
}
|
|
547
551
|
|
|
548
|
-
updateAspect(camera: PerspectiveCamera, width?: number, height?: number) {
|
|
552
|
+
updateAspect(camera: PerspectiveCamera | OrthographicCamera, width?: number, height?: number) {
|
|
549
553
|
if (!camera) return;
|
|
550
554
|
if (width === undefined)
|
|
551
555
|
width = this.domWidth;
|
|
552
556
|
if (height === undefined)
|
|
553
557
|
height = this.domHeight;
|
|
554
|
-
const
|
|
555
|
-
camera
|
|
556
|
-
|
|
557
|
-
|
|
558
|
+
const aspectRatio = width / height;
|
|
559
|
+
if ((camera as PerspectiveCamera).isPerspectiveCamera) {
|
|
560
|
+
const cam = camera as PerspectiveCamera;
|
|
561
|
+
const pa = cam.aspect;
|
|
562
|
+
cam.aspect = aspectRatio;
|
|
563
|
+
if (pa !== cam.aspect)
|
|
564
|
+
camera.updateProjectionMatrix();
|
|
565
|
+
}
|
|
566
|
+
else if ((camera as OrthographicCamera).isOrthographicCamera) {
|
|
567
|
+
const cam = camera as OrthographicCamera;
|
|
568
|
+
// Maintain the camera's current vertical size (top - bottom)
|
|
569
|
+
const verticalSize = cam.top - cam.bottom;
|
|
570
|
+
// Calculate new horizontal size based on aspect ratio
|
|
571
|
+
const horizontalSize = verticalSize * aspectRatio;
|
|
572
|
+
// Update camera bounds while maintaining center position
|
|
573
|
+
const halfWidth = horizontalSize / 2;
|
|
574
|
+
const halfHeight = verticalSize / 2;
|
|
575
|
+
if (cam.left != -halfWidth || cam.top != halfHeight) {
|
|
576
|
+
cam.left = -halfWidth;
|
|
577
|
+
cam.right = halfWidth;
|
|
578
|
+
cam.top = halfHeight;
|
|
579
|
+
cam.bottom = -halfHeight;
|
|
580
|
+
camera.updateProjectionMatrix();
|
|
581
|
+
}
|
|
582
|
+
}
|
|
558
583
|
}
|
|
559
584
|
|
|
560
585
|
/** This will recreate the whole needle engine context and dispose the whole scene content
|
|
@@ -1078,7 +1103,7 @@ export class Context implements IContext {
|
|
|
1078
1103
|
// if the id was changed while still loading
|
|
1079
1104
|
// then we want to cleanup/destroy previously loaded files
|
|
1080
1105
|
if (createId !== this._createId || args.abortSignal?.aborted) {
|
|
1081
|
-
if(debug) console.log("Aborting loading because create id changed or abort signal was set", createId, this._createId);
|
|
1106
|
+
if (debug) console.log("Aborting loading because create id changed or abort signal was set", createId, this._createId);
|
|
1082
1107
|
for (const res of results) {
|
|
1083
1108
|
if (res && res.file) {
|
|
1084
1109
|
for (const scene of res.file.scenes)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Bone, Object3D, Quaternion, SkinnedMesh, Vector3 } from "three";
|
|
2
2
|
|
|
3
|
+
import { type AssetReference } from "./engine_addressables.js";
|
|
3
4
|
import { __internalNotifyObjectDestroyed as __internalRemoveReferences, disposeObjectResources } from "./engine_assetdatabase.js";
|
|
4
5
|
import { ComponentLifecycleEvents } from "./engine_components_internal.js";
|
|
5
6
|
import { activeInHierarchyFieldName } from "./engine_constants.js";
|
|
@@ -10,26 +11,13 @@ import { InstantiateIdProvider } from "./engine_networking_instantiate.js";
|
|
|
10
11
|
import { assign } from "./engine_serialization_core.js";
|
|
11
12
|
import { Context, registerComponent } from "./engine_setup.js";
|
|
12
13
|
import { logHierarchy, setWorldPosition, setWorldQuaternion } from "./engine_three_utils.js";
|
|
13
|
-
import { type Constructor, type GuidsMap, type IComponent as Component, type IComponent, IEventList,type IGameObject as GameObject, type UIDProvider } from "./engine_types.js";
|
|
14
|
+
import { type Constructor, type GuidsMap, type IComponent as Component, type IComponent, IEventList, type IGameObject as GameObject, type UIDProvider } from "./engine_types.js";
|
|
14
15
|
import { getParam, tryFindObject } from "./engine_utils.js";
|
|
15
16
|
import { apply } from "./js-extensions/index.js";
|
|
16
17
|
|
|
17
18
|
const debug = getParam("debuggetcomponent");
|
|
18
19
|
const debugInstantiate = getParam("debuginstantiate");
|
|
19
20
|
|
|
20
|
-
/** @internal */
|
|
21
|
-
export enum HideFlags {
|
|
22
|
-
None = 0,
|
|
23
|
-
HideInHierarchy = 1,
|
|
24
|
-
HideInInspector = 2,
|
|
25
|
-
DontSaveInEditor = 4,
|
|
26
|
-
NotEditable = 8,
|
|
27
|
-
DontSaveInBuild = 16, // 0x00000010
|
|
28
|
-
DontUnloadUnusedAsset = 32, // 0x00000020
|
|
29
|
-
DontSave = DontUnloadUnusedAsset | DontSaveInBuild | DontSaveInEditor, // 0x00000034
|
|
30
|
-
HideAndDontSave = DontSave | NotEditable | HideInHierarchy, // 0x0000003D
|
|
31
|
-
}
|
|
32
|
-
|
|
33
21
|
export type IInstantiateOptions = {
|
|
34
22
|
idProvider?: UIDProvider;
|
|
35
23
|
//** parent guid or object */
|
|
@@ -307,9 +295,17 @@ declare type InstantiateReferenceMap = Record<string, ObjectCloneReference>;
|
|
|
307
295
|
*/
|
|
308
296
|
export declare type InstantiateContext = Readonly<InstantiateReferenceMap>;
|
|
309
297
|
|
|
310
|
-
export function instantiate(instance:
|
|
298
|
+
export function instantiate(instance: AssetReference, opts?: IInstantiateOptions | null): Promise<Object3D | null>
|
|
299
|
+
export function instantiate(instance: GameObject | Object3D, opts?: IInstantiateOptions | null): GameObject
|
|
300
|
+
export function instantiate(instance: AssetReference | GameObject | Object3D, opts?: IInstantiateOptions | null | undefined): GameObject | Promise<Object3D | null> {
|
|
301
|
+
|
|
302
|
+
if ("isAssetReference" in instance) {
|
|
303
|
+
return instance.instantiate(opts ?? undefined);
|
|
304
|
+
}
|
|
305
|
+
|
|
311
306
|
let options: InstantiateOptions | null = null;
|
|
312
|
-
|
|
307
|
+
|
|
308
|
+
if (opts !== null && opts !== undefined) {
|
|
313
309
|
// if x is defined assume this is a vec3 - this is just to not break everything at once and stay a little bit backwards compatible
|
|
314
310
|
if (opts["x"] !== undefined) {
|
|
315
311
|
options = new InstantiateOptions();
|
|
@@ -11,7 +11,7 @@ import { isLocalNetwork } from "./engine_networking_utils.js";
|
|
|
11
11
|
import { deserializeObject, serializeObject } from "./engine_serialization.js";
|
|
12
12
|
import { assign, ImplementationInformation, type ISerializable, SerializationContext } from "./engine_serialization_core.js";
|
|
13
13
|
import { Context } from "./engine_setup.js";
|
|
14
|
-
import type { GuidsMap, ICamera, IComponent, IGameObject, SourceIdentifier, UIDProvider } from "./engine_types.js";
|
|
14
|
+
import type { GuidsMap, ICamera, ICollider, IComponent, IGameObject, IRigidbody, SourceIdentifier, UIDProvider } from "./engine_types.js";
|
|
15
15
|
import { TypeStore } from "./engine_typestore.js";
|
|
16
16
|
import { getParam } from "./engine_utils.js";
|
|
17
17
|
import { NEEDLE_components } from "./extensions/NEEDLE_components.js";
|
|
@@ -247,6 +247,12 @@ async function onCreateBuiltinComponents(context: SerializationContext, obj: Obj
|
|
|
247
247
|
if (context.context.mainCamera === null && (instance.tag === "MainCamera"))
|
|
248
248
|
context.context.setCurrentCamera(instance as ICamera);
|
|
249
249
|
}
|
|
250
|
+
|
|
251
|
+
// if the component is a rigidbody or collider and the physics engine is not initialized yet
|
|
252
|
+
// initialize the physics engine right away
|
|
253
|
+
if (context.context?.physics?.engine?.isInitialized === false && ((instance as ICollider).isCollider || (instance as IRigidbody).isRigidbody)) {
|
|
254
|
+
context.context?.physics.engine?.initialize();
|
|
255
|
+
}
|
|
250
256
|
}
|
|
251
257
|
else {
|
|
252
258
|
if (debug)
|
|
@@ -36,8 +36,15 @@ export const enum InputEvents {
|
|
|
36
36
|
KeyUp = "keyup",
|
|
37
37
|
KeyPressed = "keypress"
|
|
38
38
|
}
|
|
39
|
+
|
|
39
40
|
/** e.g. `pointerdown` */
|
|
40
|
-
|
|
41
|
+
type PointerEventNames = EnumToPrimitiveUnion<PointerEnumType>;
|
|
42
|
+
type KeyboardEventNames = EnumToPrimitiveUnion<KeyboardEnumType>;
|
|
43
|
+
export type InputEventNames = PointerEventNames | KeyboardEventNames;
|
|
44
|
+
|
|
45
|
+
declare type PointerEventListener = (evt: NEPointerEvent) => void;
|
|
46
|
+
declare type KeyboardEventListener = (evt: NEKeyboardEvent) => void;
|
|
47
|
+
declare type InputEventListener = PointerEventListener | KeyboardEventListener;
|
|
41
48
|
|
|
42
49
|
|
|
43
50
|
|
|
@@ -217,10 +224,6 @@ export class KeyEventArgs {
|
|
|
217
224
|
|
|
218
225
|
|
|
219
226
|
|
|
220
|
-
declare type PointerEventListener = (evt: NEPointerEvent) => void;
|
|
221
|
-
declare type KeyboardEventListener = (evt: NEKeyboardEvent) => void;
|
|
222
|
-
declare type InputEventListener = PointerEventListener | KeyboardEventListener;
|
|
223
|
-
|
|
224
227
|
export enum InputEventQueue {
|
|
225
228
|
Early = -100,
|
|
226
229
|
Default = 0,
|
|
@@ -254,6 +257,8 @@ export class Input implements IInput {
|
|
|
254
257
|
* @param callback The callback to call when the event is triggered
|
|
255
258
|
* @param options The options for adding the event listener
|
|
256
259
|
*/
|
|
260
|
+
addEventListener(type: PointerEventNames, callback: PointerEventListener, options?: EventListenerOptions);
|
|
261
|
+
addEventListener(type: KeyboardEventNames, callback: KeyboardEventListener, options?: EventListenerOptions);
|
|
257
262
|
addEventListener(type: InputEvents | InputEventNames, callback: InputEventListener, options?: EventListenerOptions): void {
|
|
258
263
|
if (!this._eventListeners[type]) this._eventListeners[type] = [];
|
|
259
264
|
|
|
@@ -284,6 +289,8 @@ export class Input implements IInput {
|
|
|
284
289
|
* @param callback The callback to remove
|
|
285
290
|
* @param options The options for removing the event listener
|
|
286
291
|
*/
|
|
292
|
+
removeEventListener(type: PointerEventNames, callback: PointerEventListener, options?: EventListenerOptions);
|
|
293
|
+
removeEventListener(type: KeyboardEventNames, callback: KeyboardEventListener, options?: EventListenerOptions);
|
|
287
294
|
removeEventListener(type: InputEvents | InputEventNames, callback: InputEventListener, options?: EventListenerOptions): void {
|
|
288
295
|
if (!this._eventListeners[type]) return;
|
|
289
296
|
if (!callback) return;
|
|
@@ -6,6 +6,8 @@ import { getParam } from "./engine_utils.js";
|
|
|
6
6
|
|
|
7
7
|
const debug = getParam("debuglicense");
|
|
8
8
|
|
|
9
|
+
const _licenseCheckResultChangedCallbacks: ((result: boolean) => void)[] = [];
|
|
10
|
+
|
|
9
11
|
// This is modified by a bundler (e.g. vite)
|
|
10
12
|
// Do not edit manually
|
|
11
13
|
let NEEDLE_ENGINE_LICENSE_TYPE: string = "basic";
|
|
@@ -36,7 +38,6 @@ export function hasCommercialLicense() {
|
|
|
36
38
|
return hasProLicense() || hasIndieLicense();
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
const _licenseCheckResultChangedCallbacks: ((result: boolean) => void)[] = [];
|
|
40
41
|
|
|
41
42
|
/** @internal */
|
|
42
43
|
export function onLicenseCheckResultChanged(cb: (result: boolean) => void) {
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
|
|
2
|
+
/**
|
|
3
|
+
* External dependencies that are loaded on demand either by the engine automatically when needed or they can be loaded manually by calling the `load` function.
|
|
4
|
+
*
|
|
5
|
+
* Use the `ready` function to wait for the module to be loaded if you do not wand to trigger a load.
|
|
6
|
+
*
|
|
7
|
+
* If a module is already loaded it's also available in the `MODULE` variable.
|
|
8
|
+
*/
|
|
2
9
|
export namespace MODULES {
|
|
3
10
|
|
|
4
11
|
export namespace RAPIER_PHYSICS {
|
|
@@ -32,15 +32,12 @@ class ComponentPropertiesSyncer {
|
|
|
32
32
|
comp: IComponent;
|
|
33
33
|
|
|
34
34
|
constructor(comp: IComponent) {
|
|
35
|
-
// console.log("CREATE NEW SYNC", comp.name, comp.guid);
|
|
36
35
|
this.comp = comp;
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
// private getters: { [key: string]: Function } = {};
|
|
40
39
|
private hasChanges: boolean = false;
|
|
41
40
|
private changedProperties: { [key: string]: any } = {};
|
|
42
|
-
// private data = {};
|
|
43
|
-
|
|
44
41
|
|
|
45
42
|
get networkingKey(): string {
|
|
46
43
|
return this.comp.guid;
|
|
@@ -89,27 +86,24 @@ class ComponentPropertiesSyncer {
|
|
|
89
86
|
return;
|
|
90
87
|
}
|
|
91
88
|
for (const name in this.changedProperties) {
|
|
92
|
-
const guid = this.comp.guid + "/" + name;
|
|
93
89
|
const value = this.changedProperties[name];
|
|
94
|
-
if (debug) console.log("SEND", this.comp.
|
|
95
|
-
net.send(this.networkingKey, { guid, data: value }, SendQueue.Queued);
|
|
90
|
+
if (debug) console.log("SEND", this.comp.guid, this.networkingKey);
|
|
91
|
+
net.send(this.networkingKey, { guid: this.comp.guid, property: name, data: value }, SendQueue.Queued);
|
|
92
|
+
delete this.changedProperties[name];
|
|
96
93
|
}
|
|
97
94
|
}
|
|
98
95
|
|
|
99
|
-
private onHandleReceiving = (val: { guid: string, data: any }) => {
|
|
100
|
-
if (debug)
|
|
101
|
-
console.log("RECEIVE", this.comp.name, this.comp.guid, val);
|
|
96
|
+
private onHandleReceiving = (val: { guid: string, property: string, data: any }) => {
|
|
97
|
+
if (debug) console.log("SYNCFIELD RECEIVE", this.comp.name, this.comp.guid, val);
|
|
102
98
|
if (!this._isInit) return;
|
|
103
99
|
if (!this.comp) return;
|
|
104
100
|
// check if this change belongs to this component
|
|
105
|
-
if (val.guid
|
|
101
|
+
if (val.guid !== this.comp.guid) {
|
|
106
102
|
return;
|
|
107
103
|
}
|
|
108
|
-
const [_guid, key] = val.guid.split("/");
|
|
109
|
-
if (debug) console.log("RECEIVED", this.comp.name, this.comp.guid, val);
|
|
110
104
|
try {
|
|
111
105
|
this._isReceiving = true;
|
|
112
|
-
this.comp[
|
|
106
|
+
this.comp[val.property] = val.data;
|
|
113
107
|
}
|
|
114
108
|
catch (err) {
|
|
115
109
|
console.error(err);
|
|
@@ -118,15 +112,6 @@ class ComponentPropertiesSyncer {
|
|
|
118
112
|
this._isReceiving = false;
|
|
119
113
|
}
|
|
120
114
|
}
|
|
121
|
-
|
|
122
|
-
// private _seen: Set<any> = new Set();
|
|
123
|
-
// private uniqBy(a, key) {
|
|
124
|
-
// this._seen.clear();
|
|
125
|
-
// return a.filter(item => {
|
|
126
|
-
// let k = key(item);
|
|
127
|
-
// return this._seen.has(k) ? false : this._seen.add(k);
|
|
128
|
-
// });
|
|
129
|
-
// }
|
|
130
115
|
}
|
|
131
116
|
|
|
132
117
|
function testValueChanged(newValue, previousValue): boolean {
|
|
@@ -350,7 +350,7 @@ function instantiateSeeded(obj: GameObject, opts: IInstantiateOptions | null): {
|
|
|
350
350
|
return { seed: seed, instance: instance };
|
|
351
351
|
}
|
|
352
352
|
|
|
353
|
-
export declare type PrefabProviderCallback = (guid: string) => Promise<
|
|
353
|
+
export declare type PrefabProviderCallback = (guid: string) => Promise<Object3D | null>;
|
|
354
354
|
|
|
355
355
|
const registeredPrefabProviders: { [key: string]: PrefabProviderCallback } = {};
|
|
356
356
|
|