@needle-tools/engine 4.16.1 → 4.16.2
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 +7 -0
- package/components.needle.json +1 -1
- package/dist/{needle-engine.bundle-C3aSGlMn.min.js → needle-engine.bundle-BOzZVXHu.min.js} +132 -132
- package/dist/{needle-engine.bundle-CKIxz09L.js → needle-engine.bundle-VXttgVve.js} +5357 -5342
- package/dist/{needle-engine.bundle-DSHShuiJ.umd.cjs → needle-engine.bundle-nJtehyVz.umd.cjs} +131 -131
- package/dist/needle-engine.d.ts +45 -23
- package/dist/needle-engine.js +2 -2
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine-components/EventType.d.ts +1 -13
- package/lib/engine-components/EventType.js +13 -12
- package/lib/engine-components/EventType.js.map +1 -1
- package/lib/engine-components/ReflectionProbe.d.ts +31 -8
- package/lib/engine-components/ReflectionProbe.js +57 -15
- package/lib/engine-components/ReflectionProbe.js.map +1 -1
- package/package.json +15 -6
- package/plugins/next/next.d.ts +8 -0
- package/plugins/next/next.js +7 -6
- package/plugins/types/userconfig.d.ts +4 -6
- package/plugins/vite/ai.d.ts +17 -0
- package/plugins/vite/ai.js +2 -2
- package/plugins/vite/alias.d.ts +8 -0
- package/plugins/vite/alias.js +5 -2
- package/plugins/vite/asap.d.ts +7 -0
- package/plugins/vite/asap.js +3 -3
- package/plugins/vite/build-pipeline.d.ts +15 -0
- package/plugins/vite/build-pipeline.js +5 -6
- package/plugins/vite/build.d.ts +7 -0
- package/plugins/vite/build.js +5 -2
- package/plugins/vite/buildinfo.d.ts +7 -0
- package/plugins/vite/buildinfo.js +4 -2
- package/plugins/vite/config.d.ts +13 -0
- package/plugins/vite/config.js +1 -1
- package/plugins/vite/copyfiles.d.ts +7 -0
- package/plugins/vite/copyfiles.js +4 -2
- package/plugins/vite/custom-element-data.d.ts +25 -0
- package/plugins/vite/custom-element-data.js +2 -1
- package/plugins/vite/defines.d.ts +10 -0
- package/plugins/vite/defines.js +4 -3
- package/plugins/vite/dependencies.d.ts +21 -0
- package/plugins/vite/dependencies.js +3 -1
- package/plugins/vite/dependency-watcher.d.ts +11 -0
- package/plugins/vite/dependency-watcher.js +2 -1
- package/plugins/vite/drop-client.d.ts +1 -0
- package/plugins/vite/drop.d.ts +7 -0
- package/plugins/vite/drop.js +4 -4
- package/plugins/vite/editor-connection.d.ts +8 -0
- package/plugins/vite/editor-connection.js +6 -2
- package/plugins/vite/facebook-instant-games.d.ts +7 -0
- package/plugins/vite/facebook-instant-games.js +4 -2
- package/plugins/vite/gzip.d.ts +6 -0
- package/plugins/vite/gzip.js +5 -0
- package/plugins/vite/imports-logger.d.ts +13 -0
- package/plugins/vite/imports-logger.js +2 -1
- package/plugins/vite/index.d.ts +54 -0
- package/plugins/vite/index.js +16 -15
- package/plugins/vite/license.d.ts +7 -0
- package/plugins/vite/license.js +6 -6
- package/plugins/vite/local-files-analysis.d.ts +95 -0
- package/plugins/vite/local-files-analysis.js +2 -1
- package/plugins/vite/local-files-core.d.ts +51 -0
- package/plugins/vite/local-files-core.js +2 -2
- package/plugins/vite/local-files-internals.d.ts +3 -0
- package/plugins/vite/local-files-utils.d.ts +77 -0
- package/plugins/vite/local-files.d.ts +2 -0
- package/plugins/vite/logger.d.ts +8 -0
- package/plugins/vite/logger.js +1 -1
- package/plugins/vite/logging.d.ts +31 -0
- package/plugins/vite/meta.d.ts +7 -0
- package/plugins/vite/meta.js +4 -3
- package/plugins/vite/needle-app.d.ts +7 -0
- package/plugins/vite/needle-app.js +1 -1
- package/plugins/vite/npm.d.ts +4 -0
- package/plugins/vite/npm.js +1 -1
- package/plugins/vite/peer.d.ts +7 -0
- package/plugins/vite/peer.js +3 -1
- package/plugins/vite/poster-client.d.ts +1 -0
- package/plugins/vite/poster.d.ts +8 -0
- package/plugins/vite/poster.js +5 -2
- package/plugins/vite/pwa.d.ts +7 -0
- package/plugins/vite/pwa.js +4 -4
- package/plugins/vite/reload-client.d.ts +1 -0
- package/plugins/vite/reload.d.ts +7 -0
- package/plugins/vite/reload.js +7 -6
- package/plugins/vite/server.d.ts +7 -0
- package/plugins/vite/server.js +5 -5
- package/plugins/vite/transform-codegen.d.ts +8 -0
- package/plugins/vite/transform-codegen.js +6 -4
- package/plugins/vite/transform.d.ts +5 -0
- package/plugins/vite/transform.js +1 -1
- package/plugins/vite/vite-4.4-hack.d.ts +8 -0
- package/plugins/vite/vite-4.4-hack.js +1 -1
- package/src/engine-components/EventType.ts +13 -12
- package/src/engine-components/ReflectionProbe.ts +65 -20
- package/plugins/types/next.d.ts +0 -3
- package/plugins/types/vite.d.ts +0 -14
package/plugins/vite/meta.js
CHANGED
|
@@ -6,11 +6,12 @@ import { getPosterPath } from './poster.js';
|
|
|
6
6
|
import { needleGreenBold, needleLog } from './logging.js';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {import('../types').needleMeta | null} config
|
|
9
|
+
* @param {"build" | "serve"} command
|
|
10
|
+
* @param {import('../types/needleConfig').needleMeta | null} config
|
|
11
11
|
* @param {import('../types').userSettings} userSettings
|
|
12
|
+
* @returns {import('vite').Plugin}
|
|
12
13
|
*/
|
|
13
|
-
export
|
|
14
|
+
export function needleMeta(command, config, userSettings) {
|
|
14
15
|
|
|
15
16
|
// we can check if this is a build
|
|
16
17
|
const isBuild = command === 'build';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {'serve' | 'build'} command
|
|
3
|
+
* @param {{} | undefined | null} config
|
|
4
|
+
* @param {import('../types').userSettings} userSettings
|
|
5
|
+
* @returns {import('vite').Plugin[] | null}
|
|
6
|
+
*/
|
|
7
|
+
export function needleApp(command: "serve" | "build", config: {} | undefined | null, userSettings: import("../types").userSettings): import("vite").Plugin[] | null;
|
|
@@ -10,7 +10,7 @@ import { needleLog } from './logging.js';
|
|
|
10
10
|
* @param {import('../types').userSettings} userSettings
|
|
11
11
|
* @returns {import('vite').Plugin[] | null}
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export function needleApp(command, config, userSettings) {
|
|
14
14
|
|
|
15
15
|
if (command !== "build") {
|
|
16
16
|
return null;
|
package/plugins/vite/npm.js
CHANGED
|
@@ -3,6 +3,6 @@ import { ensureNpmDirectoryExists } from '../common/npm.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* @param {import('../types').userSettings} userSettings
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export function needleNPM(command, config, userSettings) {
|
|
7
7
|
ensureNpmDirectoryExists();
|
|
8
8
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {"build" | "serve"} command
|
|
3
|
+
* @param {import('../types/needleConfig').needleMeta | null | undefined} config
|
|
4
|
+
* @param {import('../types').userSettings} userSettings
|
|
5
|
+
* @returns {import("vite").Plugin | undefined}
|
|
6
|
+
*/
|
|
7
|
+
export function needlePeerjs(command: "build" | "serve", config: import("../types/needleConfig").needleMeta | null | undefined, userSettings: import("../types").userSettings): import("vite").Plugin | undefined;
|
package/plugins/vite/peer.js
CHANGED
|
@@ -2,10 +2,12 @@ const peerjsString = `/* needle: fix for peerjs */ window.global = window; var p
|
|
|
2
2
|
import { needleLog } from './logging.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
+
* @param {"build" | "serve"} command
|
|
6
|
+
* @param {import('../types/needleConfig').needleMeta | null | undefined} config
|
|
5
7
|
* @param {import('../types').userSettings} userSettings
|
|
6
8
|
* @returns {import("vite").Plugin | undefined}
|
|
7
9
|
*/
|
|
8
|
-
export
|
|
10
|
+
export function needlePeerjs(command, config, userSettings) {
|
|
9
11
|
|
|
10
12
|
if (userSettings.noPeer === true) return;
|
|
11
13
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function getPosterPath(): string;
|
|
2
|
+
/**
|
|
3
|
+
* @param {"build" | "serve"} command
|
|
4
|
+
* @param {import('../types/needleConfig').needleMeta | null | undefined} config
|
|
5
|
+
* @param {import('../types').userSettings} userSettings
|
|
6
|
+
* @returns {import('vite').Plugin | undefined}
|
|
7
|
+
*/
|
|
8
|
+
export function needlePoster(command: "build" | "serve", config: import("../types/needleConfig").needleMeta | null | undefined, userSettings: import("../types").userSettings): import("vite").Plugin | undefined;
|
package/plugins/vite/poster.js
CHANGED
|
@@ -10,9 +10,12 @@ export function getPosterPath() {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
+
* @param {"build" | "serve"} command
|
|
14
|
+
* @param {import('../types/needleConfig').needleMeta | null | undefined} config
|
|
13
15
|
* @param {import('../types').userSettings} userSettings
|
|
16
|
+
* @returns {import('vite').Plugin | undefined}
|
|
14
17
|
*/
|
|
15
|
-
export
|
|
18
|
+
export function needlePoster(command, config, userSettings) {
|
|
16
19
|
// only relevant for local development
|
|
17
20
|
if (command === 'build') return [];
|
|
18
21
|
|
|
@@ -76,4 +79,4 @@ export const needlePoster = (command, config, userSettings) => {
|
|
|
76
79
|
},
|
|
77
80
|
},
|
|
78
81
|
}
|
|
79
|
-
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Provides reasonable defaults for a PWA manifest and workbox settings.
|
|
2
|
+
* @param {"build" | "serve"} command
|
|
3
|
+
* @param {import("../types/needleConfig").needleMeta | null} config
|
|
4
|
+
* @param {import('../types').userSettings} userSettings
|
|
5
|
+
* @returns {import('vite').Plugin | undefined}
|
|
6
|
+
*/
|
|
7
|
+
export function needlePWA(command: "build" | "serve", config: import("../types/needleConfig").needleMeta | null, userSettings: import("../types").userSettings): import("vite").Plugin | undefined;
|
package/plugins/vite/pwa.js
CHANGED
|
@@ -8,12 +8,12 @@ import { needleLog } from './logging.js';
|
|
|
8
8
|
const pwaErrorWithInstructions = "It seems that you're trying to build a PWA using 'vite-plugin-pwa'!\nNeedle can manage PWA settings for you – just pass the same 'pwaOptions' to the needlePlugins and VitePWA plugins:\n\n1. Install the vite PWA plugin: npm install vite-plugin-pwa --save-dev\n\n2. Then update your vite.config.js:\n\n import { VitePWA } from 'vite-plugin-pwa';\n ...\n needlePlugins(command, needleConfig, { pwa: pwaOptions }),\n VitePWA(pwaOptions),\n\nIf you want to manage PWA building yourself and skip this check, please pass '{ pwa: false }' to needlePlugins.";
|
|
9
9
|
|
|
10
10
|
/** Provides reasonable defaults for a PWA manifest and workbox settings.
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {import('../types').userSettings} userSettings
|
|
11
|
+
* @param {"build" | "serve"} command
|
|
13
12
|
* @param {import("../types/needleConfig").needleMeta | null} config
|
|
14
|
-
* @
|
|
13
|
+
* @param {import('../types').userSettings} userSettings
|
|
14
|
+
* @returns {import('vite').Plugin | undefined}
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
16
|
+
export function needlePWA(command, config, userSettings) {
|
|
17
17
|
// @ts-ignore // TODO correctly type the userSettings.pwaOptions object
|
|
18
18
|
/** @type {import("vite-plugin-pwa").VitePWAOptions | false} */
|
|
19
19
|
const pwaOptions = userSettings.pwa === true
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {"build" | "serve"} command
|
|
3
|
+
* @param {import('../types/needleConfig').needleMeta | null} config
|
|
4
|
+
* @param {import('../types').userSettings} userSettings
|
|
5
|
+
* @returns {import('vite').Plugin | undefined}
|
|
6
|
+
*/
|
|
7
|
+
export function needleReload(command: "build" | "serve", config: import("../types/needleConfig").needleMeta | null, userSettings: import("../types").userSettings): import("vite").Plugin | undefined;
|
package/plugins/vite/reload.js
CHANGED
|
@@ -16,10 +16,11 @@ let assetsDirectory = "";
|
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @param {"build" | "serve"} command
|
|
19
|
-
* @param {import('../types').
|
|
19
|
+
* @param {import('../types/needleConfig').needleMeta | null} config
|
|
20
20
|
* @param {import('../types').userSettings} userSettings
|
|
21
|
+
* @returns {import('vite').Plugin | undefined}
|
|
21
22
|
*/
|
|
22
|
-
export
|
|
23
|
+
export function needleReload(command, config, userSettings) {
|
|
23
24
|
if (command === "build") return undefined;
|
|
24
25
|
|
|
25
26
|
if (userSettings?.noReload === true) return undefined;
|
|
@@ -31,7 +32,7 @@ export const needleReload = (command, config, userSettings) => {
|
|
|
31
32
|
isUpdatingConfig = true;
|
|
32
33
|
const res = await loadConfig();
|
|
33
34
|
isUpdatingConfig = false;
|
|
34
|
-
if (res) config = /** @type {import('../types').
|
|
35
|
+
if (res) config = /** @type {import('../types/needleConfig').needleMeta} */ (res);
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
const projectConfig = tryLoadProjectConfig();
|
|
@@ -61,7 +62,7 @@ export const needleReload = (command, config, userSettings) => {
|
|
|
61
62
|
if (userSettings?.debug === true)
|
|
62
63
|
setTimeout(() => needleLog("needle-reload", "Updated server ignore patterns: " + JSON.stringify(config.server?.watch?.ignored)), 100);
|
|
63
64
|
},
|
|
64
|
-
/** @param {
|
|
65
|
+
/** @param {import('vite').HmrContext & {buildDirectory?: string}} args */
|
|
65
66
|
handleHotUpdate(args) {
|
|
66
67
|
args.buildDirectory = buildDirectory;
|
|
67
68
|
return handleReload(args);
|
|
@@ -118,7 +119,7 @@ function notifyClientWillReload(server, file) {
|
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
/**
|
|
121
|
-
* @param {
|
|
122
|
+
* @param {import('vite').HmrContext & {buildDirectory?: string}} param0
|
|
122
123
|
* @returns {Promise<any>}
|
|
123
124
|
*/
|
|
124
125
|
async function handleReload({ file, server, modules: _modules, read, buildDirectory }) {
|
|
@@ -255,7 +256,7 @@ function getFileNameLog(file) {
|
|
|
255
256
|
const hashes = new Map();
|
|
256
257
|
const hash256 = crypto.createHash('sha256');
|
|
257
258
|
|
|
258
|
-
/** @param {string} file @param {(file?: string) => Promise<string>} read @returns {Promise<boolean>} */
|
|
259
|
+
/** @param {string} file @param {(file?: string) => string | Promise<string>} read @returns {Promise<boolean>} */
|
|
259
260
|
async function testIfFileContentChanged(file, read) {
|
|
260
261
|
let content = await read(file);
|
|
261
262
|
content = removeVersionQueryArgument(content);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Can open the network server in the browser.
|
|
2
|
+
* @param {"build" | "serve"} command
|
|
3
|
+
* @param {import('../types').needleMeta | null} config
|
|
4
|
+
* @param {import('../types').userSettings} userSettings
|
|
5
|
+
* @returns {import('vite').Plugin}
|
|
6
|
+
*/
|
|
7
|
+
export function needleServer(command: "build" | "serve", config: import("../types").needleMeta | null, userSettings: import("../types").userSettings): import("vite").Plugin;
|
package/plugins/vite/server.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @param {string} command
|
|
1
|
+
/** Can open the network server in the browser.
|
|
2
|
+
* @param {"build" | "serve"} command
|
|
4
3
|
* @param {import('../types').needleMeta | null} config
|
|
5
4
|
* @param {import('../types').userSettings} userSettings
|
|
5
|
+
* @returns {import('vite').Plugin}
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export function needleServer(command, config, userSettings) {
|
|
8
8
|
|
|
9
9
|
const shouldOpenBrowser = userSettings.openBrowser === true;
|
|
10
10
|
|
|
@@ -64,4 +64,4 @@ export const needleServer = (command, config, userSettings) => {
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
}
|
|
67
|
-
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Modify the glb load path in codegen files.
|
|
2
|
+
* This is necessary if the assets directory is not the default (changed by the user in needle.config.json).
|
|
3
|
+
* @param {"build" | "serve"} command
|
|
4
|
+
* @param {import('../types/needleConfig').needleMeta | null | undefined} config
|
|
5
|
+
* @param {import('../types').userSettings} userSettings
|
|
6
|
+
* @returns {import('vite').Plugin | undefined}
|
|
7
|
+
*/
|
|
8
|
+
export function needleTransformCodegen(command: "build" | "serve", config: import("../types/needleConfig").needleMeta | null | undefined, userSettings: import("../types").userSettings): import("vite").Plugin | undefined;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { builtAssetsDirectory, tryLoadProjectConfig } from './config.js';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
/** Modify the glb load path in codegen files.
|
|
4
|
+
* This is necessary if the assets directory is not the default (changed by the user in needle.config.json).
|
|
5
|
+
* @param {"build" | "serve"} command
|
|
6
|
+
* @param {import('../types/needleConfig').needleMeta | null | undefined} config
|
|
6
7
|
* @param {import('../types').userSettings} userSettings
|
|
8
|
+
* @returns {import('vite').Plugin | undefined}
|
|
7
9
|
*/
|
|
8
|
-
export
|
|
10
|
+
export function needleTransformCodegen(command, config, userSettings) {
|
|
9
11
|
|
|
10
12
|
if (config?.noCodegenTransform === true || userSettings?.noCodegenTransform === true) {
|
|
11
13
|
return;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make sure we dont have vite 4.4.x installed when needle engine is used locally
|
|
3
|
+
* @param {import('../types').userSettings} userSettings
|
|
4
|
+
*/
|
|
5
|
+
export function vite_4_4_hack(command: any, config: any, userSettings: import("../types").userSettings): {
|
|
6
|
+
name: string;
|
|
7
|
+
configureServer(server: any): Promise<void>;
|
|
8
|
+
};
|
|
@@ -6,7 +6,7 @@ import { execSync } from 'child_process';
|
|
|
6
6
|
* Make sure we dont have vite 4.4.x installed when needle engine is used locally
|
|
7
7
|
* @param {import('../types').userSettings} userSettings
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export function vite_4_4_hack(command, config, userSettings) {
|
|
10
10
|
if (userSettings.vite44Hack === false) return;
|
|
11
11
|
return {
|
|
12
12
|
name: "needle-vite-4.4-hack",
|
|
@@ -8,16 +8,17 @@ export enum EventType {
|
|
|
8
8
|
PointerDown = 2,
|
|
9
9
|
PointerUp = 3,
|
|
10
10
|
PointerClick = 4,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
// Unity Events, not currently supported:
|
|
12
|
+
//Drag = 5,
|
|
13
|
+
//Drop = 6,
|
|
14
|
+
//Scroll = 7,
|
|
15
|
+
//UpdateSelected = 8,
|
|
16
|
+
//Select = 9,
|
|
17
|
+
//Deselect = 10,
|
|
18
|
+
//Move = 11,
|
|
19
|
+
//InitializePotentialDrag = 12,
|
|
20
|
+
//BeginDrag = 13,
|
|
21
|
+
//EndDrag = 14,
|
|
22
|
+
//Submit = 15,
|
|
23
|
+
//Cancel = 16
|
|
23
24
|
}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { CubeTexture, EquirectangularReflectionMapping, LinearSRGBColorSpace, Material, Object3D, Texture, Vector3 } from "three";
|
|
1
|
+
import { Box3, Color, CubeTexture, EquirectangularReflectionMapping, LinearSRGBColorSpace, LineSegments, Material, Object3D, Quaternion, Texture, Vector3 } from "three";
|
|
2
2
|
|
|
3
|
+
import { CreateWireCube } from "../engine/engine_gizmos.js";
|
|
3
4
|
import { MaterialPropertyBlock } from "../engine/engine_materialpropertyblock.js";
|
|
4
5
|
import { loadPMREM } from "../engine/engine_pmrem.js";
|
|
5
6
|
import { serializable } from "../engine/engine_serialization.js";
|
|
6
7
|
import { Context } from "../engine/engine_setup.js";
|
|
8
|
+
import { getBoundingBox, getWorldPosition } from "../engine/engine_three_utils.js";
|
|
7
9
|
import { getParam, resolveUrl } from "../engine/engine_utils.js";
|
|
8
|
-
import { BoxHelperComponent } from "./BoxHelperComponent.js";
|
|
9
10
|
import { Behaviour } from "./Component.js";
|
|
10
11
|
import { EventList } from "./EventList.js";
|
|
11
12
|
|
|
12
13
|
export const debug = getParam("debugreflectionprobe");
|
|
13
14
|
const disable = getParam("noreflectionprobe");
|
|
14
15
|
|
|
16
|
+
let box: Box3 | null = null;
|
|
17
|
+
const _identityRotation = new Quaternion();
|
|
18
|
+
|
|
15
19
|
const $reflectionProbeKey = Symbol("reflectionProbeKey");
|
|
16
20
|
/**
|
|
17
21
|
* The [ReflectionProbe](https://engine.needle.tools/docs/api/ReflectionProbe) provides environment reflection data to materials within its defined area.
|
|
@@ -40,10 +44,11 @@ const $reflectionProbeKey = Symbol("reflectionProbeKey");
|
|
|
40
44
|
export class ReflectionProbe extends Behaviour {
|
|
41
45
|
|
|
42
46
|
private static _probes: Map<Context, ReflectionProbe[]> = new Map();
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
private static testBox: Box3 = new Box3();
|
|
48
|
+
|
|
45
49
|
/**
|
|
46
|
-
* Checks if the given material is currently using a reflection probe.
|
|
50
|
+
* Checks if the given material is currently using a reflection probe.
|
|
51
|
+
* This is determined by checking for an override on the material's "envMap" property, which is set by the Renderer component when applying a reflection probe.
|
|
47
52
|
*/
|
|
48
53
|
static isUsingReflectionProbe(material: Material) {
|
|
49
54
|
return !!(material as any)[$reflectionProbeKey];
|
|
@@ -101,14 +106,17 @@ export class ReflectionProbe extends Behaviour {
|
|
|
101
106
|
private _textureUrlInFlight?: string;
|
|
102
107
|
|
|
103
108
|
/**
|
|
104
|
-
* The cubemap or HDR texture used for reflections. Can be assigned directly or via a URL string.
|
|
109
|
+
* The cubemap or HDR texture used for reflections. Can be assigned directly or via a URL string.
|
|
110
|
+
* When assigning via URL, the texture will be loaded asynchronously and applied once ready.
|
|
111
|
+
* @param tex The texture or URL to assign to this reflection probe
|
|
112
|
+
* @default null
|
|
105
113
|
*/
|
|
106
114
|
@serializable([Texture, String])
|
|
107
115
|
set texture(tex: Texture | null) {
|
|
108
116
|
if (this._texture === tex) return;
|
|
109
117
|
|
|
110
118
|
if (typeof tex === "string") {
|
|
111
|
-
if(debug) console.debug(`[ReflectionProbe] Loading reflection probe texture from URL: ${tex}`);
|
|
119
|
+
if (debug) console.debug(`[ReflectionProbe] Loading reflection probe texture from URL: ${tex}`);
|
|
112
120
|
this._textureUrlInFlight = tex;
|
|
113
121
|
const textureUrl = resolveUrl(this.sourceId, tex);
|
|
114
122
|
loadPMREM(textureUrl, this.context.renderer).then(loaded => {
|
|
@@ -124,7 +132,7 @@ export class ReflectionProbe extends Behaviour {
|
|
|
124
132
|
// During deserialization / loading of the GLB the deserializer sets an empty DataTexture
|
|
125
133
|
// But if the texture is serialized as a string (via Blender Reflection Probes) then the async loading above
|
|
126
134
|
// Will abort IF textureInFlight is reset (here). That's why we do NOT reset textureInFlight during initialization (when __didAwake is false). Only after awake, when we are sure that the async loading is done, we reset the in-flight URL to allow new assignments.
|
|
127
|
-
if(this.__didAwake) this._textureUrlInFlight = undefined;
|
|
135
|
+
if (this.__didAwake) this._textureUrlInFlight = undefined;
|
|
128
136
|
|
|
129
137
|
this._texture = tex;
|
|
130
138
|
|
|
@@ -144,30 +152,49 @@ export class ReflectionProbe extends Behaviour {
|
|
|
144
152
|
return this._texture;
|
|
145
153
|
}
|
|
146
154
|
|
|
155
|
+
/**
|
|
156
|
+
* The intensity of the reflection probe's influence.
|
|
157
|
+
* Higher values will make reflections brighter, while lower values will make them dimmer.
|
|
158
|
+
* The default value is 1, which means the reflections will be applied at their original brightness. Adjust this value to achieve the desired look for your scene.
|
|
159
|
+
* @default 1
|
|
160
|
+
*/
|
|
147
161
|
@serializable()
|
|
148
162
|
intensity: number = 1;
|
|
149
163
|
|
|
150
164
|
/**
|
|
151
|
-
* Defines the center
|
|
165
|
+
* Defines the center of the reflection probe's influence area relative to the GameObject's position.
|
|
166
|
+
* The probe will affect objects within a box defined by this center and the `size` property.
|
|
167
|
+
* Note: The actual influence area is determined by both the `center` and `size` properties. The `center` defines the offset from the GameObject's position, while the `size` defines the dimensions of the box around that center. Objects within this box will be influenced by the reflection probe.
|
|
152
168
|
*/
|
|
153
169
|
@serializable(Vector3)
|
|
154
|
-
center
|
|
170
|
+
center: Vector3 = new Vector3();
|
|
155
171
|
|
|
156
172
|
/**
|
|
157
|
-
* Defines the size of the reflection probe's influence area. Objects within this box will be affected by the probe's reflections.
|
|
173
|
+
* Defines the size of the reflection probe's influence area. Objects within this box will be affected by the probe's reflections.
|
|
174
|
+
* Note: The actual influence area is determined by both the `center` and `size` properties. The `center` defines the offset from the GameObject's position, while the `size` defines the dimensions of the box around that center. Objects within this box will be influenced by the reflection probe.
|
|
158
175
|
*/
|
|
159
176
|
@serializable(Vector3)
|
|
160
|
-
size
|
|
177
|
+
size: Vector3 = new Vector3(1, 1, 1);
|
|
161
178
|
|
|
162
179
|
/**
|
|
163
180
|
* Workaround for lightmap. Compensates for the fact that lightmaps are pre-multiplied by intensity, while reflection probes are not. This means that if you use both lightmaps and reflection probes, you may need to adjust this value to get the correct balance between them. The default value of `Math.PI` is a good starting point for most cases, but you may need to tweak it based on your specific lighting setup and artistic needs.
|
|
164
181
|
*/
|
|
165
182
|
__lightmapIntensityScale: boolean = true;
|
|
166
183
|
|
|
167
|
-
private _boxHelper?: BoxHelperComponent;
|
|
168
184
|
|
|
169
185
|
private isInBox(obj: Object3D) {
|
|
170
|
-
|
|
186
|
+
|
|
187
|
+
box ??= new Box3();
|
|
188
|
+
box!.setFromCenterAndSize(this.gameObject.worldPosition.add(this.center), this.gameObject.worldScale.multiply(this.size));
|
|
189
|
+
|
|
190
|
+
getBoundingBox([obj], undefined, undefined, ReflectionProbe.testBox);
|
|
191
|
+
|
|
192
|
+
if (ReflectionProbe.testBox.isEmpty()) {
|
|
193
|
+
return box.containsPoint(obj.worldPosition);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
return box?.intersectsBox(ReflectionProbe.testBox);
|
|
197
|
+
}
|
|
171
198
|
}
|
|
172
199
|
|
|
173
200
|
constructor() {
|
|
@@ -178,12 +205,15 @@ export class ReflectionProbe extends Behaviour {
|
|
|
178
205
|
ReflectionProbe._probes.get(this.context)?.push(this);
|
|
179
206
|
}
|
|
180
207
|
|
|
208
|
+
private _gizmo: LineSegments | null = null;
|
|
209
|
+
private _color: Color | null = null;
|
|
210
|
+
|
|
181
211
|
/** @internal */
|
|
182
212
|
awake() {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
213
|
+
if (debug) {
|
|
214
|
+
this._gizmo = CreateWireCube(0x555500);
|
|
215
|
+
this.gameObject.add(this._gizmo);
|
|
216
|
+
}
|
|
187
217
|
|
|
188
218
|
if (this._texture) {
|
|
189
219
|
this._texture.mapping = EquirectangularReflectionMapping;
|
|
@@ -192,6 +222,15 @@ export class ReflectionProbe extends Behaviour {
|
|
|
192
222
|
}
|
|
193
223
|
}
|
|
194
224
|
|
|
225
|
+
/** @internal */
|
|
226
|
+
update(): void {
|
|
227
|
+
if (this._gizmo) {
|
|
228
|
+
if (this.center) this._gizmo.position.copy(this.center);
|
|
229
|
+
if (this.size) this._gizmo.scale.copy(this.size);
|
|
230
|
+
this._gizmo.worldQuaternion = _identityRotation.identity();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
195
234
|
/** @internal */
|
|
196
235
|
onEnable(): void {
|
|
197
236
|
ReflectionProbe.onEnabled?.invoke(this);
|
|
@@ -221,7 +260,10 @@ export class ReflectionProbe extends Behaviour {
|
|
|
221
260
|
}
|
|
222
261
|
|
|
223
262
|
/**
|
|
224
|
-
* Applies this reflection probe to the given object by setting material property overrides for "envMap", "envMapRotation", and "envMapIntensity".
|
|
263
|
+
* Applies this reflection probe to the given object by setting material property overrides for "envMap", "envMapRotation", and "envMapIntensity".
|
|
264
|
+
* This is typically called by the Renderer component when determining which reflection probe to use for a given object.
|
|
265
|
+
* @param object The object to apply the reflection probe to
|
|
266
|
+
* @see {@link unapply} for the corresponding method to remove the probe's influence from an object.
|
|
225
267
|
*/
|
|
226
268
|
apply(object: Object3D) {
|
|
227
269
|
if (disable) return;
|
|
@@ -240,7 +282,10 @@ export class ReflectionProbe extends Behaviour {
|
|
|
240
282
|
}
|
|
241
283
|
|
|
242
284
|
/**
|
|
243
|
-
* Removes the reflection probe overrides from the given object.
|
|
285
|
+
* Removes the reflection probe overrides from the given object.
|
|
286
|
+
* This is typically called by the Renderer component when an object is no longer influenced by this probe or when the probe is disabled.
|
|
287
|
+
* @param object The object to remove the reflection probe overrides from
|
|
288
|
+
* @see {@link apply} for the corresponding method to apply the probe's influence to an object.
|
|
244
289
|
*/
|
|
245
290
|
unapply(obj: Object3D) {
|
|
246
291
|
const block = MaterialPropertyBlock.get(obj);
|
package/plugins/types/next.d.ts
DELETED
package/plugins/types/vite.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { needleConfig, needleMeta } from "./needleConfig.d.ts";
|
|
2
|
-
import { userSettings } from "./userconfig.d.ts";
|
|
3
|
-
|
|
4
|
-
export declare function needlePlugins(command: import("vite").ConfigEnv["command"], meta?: needleMeta | null, userSettings?: userSettings): Promise<any>;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Loads the generated needle meta file
|
|
8
|
-
*/
|
|
9
|
-
export declare function loadConfig(path: string | null = null): Promise<needleMeta | null>;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Returns true if the project is configured to use gzip compression
|
|
13
|
-
*/
|
|
14
|
-
export declare function useGzip(config?: needleConfig): boolean;
|