@iwsdk/vite-plugin-dev 0.5.1 → 0.5.3
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/README.md +3 -0
- package/dist/editor/editor-workspace.d.ts +7 -0
- package/dist/editor/editor-workspace.js +64 -2
- package/dist/editor/editor-workspace.js.map +1 -1
- package/dist/index.js +2025 -199
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +8 -1
- package/dist/uikitml-preflight.d.ts +12 -0
- package/package.json +6 -4
package/dist/index.js
CHANGED
|
@@ -7,17 +7,25 @@ import { inflateSync } from 'zlib';
|
|
|
7
7
|
import { assertValidIwsdkProjectManifest, normalizeProjectSourcePath, normalizeProjectDevOptions } from '@iwsdk/core/project';
|
|
8
8
|
import { m as findNode, n as getNodeWorldBounds, o as getScenePatternRequestedCount, p as resolveScenePrefabRoot, q as getSceneNodeCollisionRadius, t as MAX_SCENE_PATTERN_INSTANCES, u as getScenePatternInstanceCount, s as sha256, c as canonicalizeJson, w as deepClone, a as assertValidSceneDocument, x as isPlainObject, y as SCENE_IMPORT_ID_PATTERN, z as validateSceneReview, v as validateSceneDocument, h as hashSceneDocument, b as hashRuntimeSceneDocument, A as getSceneCompositionSourceHashes, i as applyScenePatch, B as parseSceneDocument, j as serializeSceneDocument, D as serializeSceneReview, E as resolveSceneAuthoringTransforms, F as parseSceneReview } from './patch-BVc5fBs4.js';
|
|
9
9
|
import { getCertificate } from '@vitejs/plugin-basic-ssl';
|
|
10
|
+
import process$1 from 'node:process';
|
|
11
|
+
import { Buffer as Buffer$1 } from 'node:buffer';
|
|
12
|
+
import path$1 from 'node:path';
|
|
13
|
+
import { fileURLToPath } from 'node:url';
|
|
14
|
+
import { promisify } from 'node:util';
|
|
15
|
+
import childProcess, { execFile as execFile$1 } from 'node:child_process';
|
|
16
|
+
import fs$2, { constants, readFile as readFile$1, readdir } from 'node:fs/promises';
|
|
17
|
+
import os$1 from 'node:os';
|
|
18
|
+
import fs$1, { existsSync as existsSync$1, readFileSync, realpathSync, lstatSync } from 'node:fs';
|
|
10
19
|
import { WebSocketServer, WebSocket } from 'ws';
|
|
11
|
-
import { fileURLToPath } from 'url';
|
|
20
|
+
import { fileURLToPath as fileURLToPath$1 } from 'url';
|
|
12
21
|
import { spawn } from 'child_process';
|
|
13
22
|
import * as os from 'os';
|
|
14
23
|
import { chromium } from 'playwright';
|
|
15
24
|
import sharp from 'sharp';
|
|
16
|
-
import { createRequire } from 'module';
|
|
17
25
|
import { readFile, access, rm, mkdir, writeFile, rename } from 'fs/promises';
|
|
18
|
-
import {
|
|
19
|
-
import path$1 from 'node:path';
|
|
26
|
+
import { createRequire } from 'module';
|
|
20
27
|
import { d } from './signals-core-BRx7ThPn.js';
|
|
28
|
+
import { parse, resolveKitComponentSets } from '@drawcall/uikitml';
|
|
21
29
|
|
|
22
30
|
/**
|
|
23
31
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -3529,6 +3537,617 @@ RUNTIME_MCP_TOOLS.map((tool) => {
|
|
|
3529
3537
|
};
|
|
3530
3538
|
});
|
|
3531
3539
|
|
|
3540
|
+
let isDockerCached;
|
|
3541
|
+
|
|
3542
|
+
function hasDockerEnv() {
|
|
3543
|
+
try {
|
|
3544
|
+
fs$1.statSync('/.dockerenv');
|
|
3545
|
+
return true;
|
|
3546
|
+
} catch {
|
|
3547
|
+
return false;
|
|
3548
|
+
}
|
|
3549
|
+
}
|
|
3550
|
+
|
|
3551
|
+
function hasDockerCGroup() {
|
|
3552
|
+
try {
|
|
3553
|
+
return fs$1.readFileSync('/proc/self/cgroup', 'utf8').includes('docker');
|
|
3554
|
+
} catch {
|
|
3555
|
+
return false;
|
|
3556
|
+
}
|
|
3557
|
+
}
|
|
3558
|
+
|
|
3559
|
+
function isDocker() {
|
|
3560
|
+
// TODO: Use `??=` when targeting Node.js 16.
|
|
3561
|
+
if (isDockerCached === undefined) {
|
|
3562
|
+
isDockerCached = hasDockerEnv() || hasDockerCGroup();
|
|
3563
|
+
}
|
|
3564
|
+
|
|
3565
|
+
return isDockerCached;
|
|
3566
|
+
}
|
|
3567
|
+
|
|
3568
|
+
let cachedResult;
|
|
3569
|
+
|
|
3570
|
+
// Podman detection
|
|
3571
|
+
const hasContainerEnv = () => {
|
|
3572
|
+
try {
|
|
3573
|
+
fs$1.statSync('/run/.containerenv');
|
|
3574
|
+
return true;
|
|
3575
|
+
} catch {
|
|
3576
|
+
return false;
|
|
3577
|
+
}
|
|
3578
|
+
};
|
|
3579
|
+
|
|
3580
|
+
function isInsideContainer() {
|
|
3581
|
+
// TODO: Use `??=` when targeting Node.js 16.
|
|
3582
|
+
if (cachedResult === undefined) {
|
|
3583
|
+
cachedResult = hasContainerEnv() || isDocker();
|
|
3584
|
+
}
|
|
3585
|
+
|
|
3586
|
+
return cachedResult;
|
|
3587
|
+
}
|
|
3588
|
+
|
|
3589
|
+
const isWsl = () => {
|
|
3590
|
+
if (process$1.platform !== 'linux') {
|
|
3591
|
+
return false;
|
|
3592
|
+
}
|
|
3593
|
+
|
|
3594
|
+
if (os$1.release().toLowerCase().includes('microsoft')) {
|
|
3595
|
+
if (isInsideContainer()) {
|
|
3596
|
+
return false;
|
|
3597
|
+
}
|
|
3598
|
+
|
|
3599
|
+
return true;
|
|
3600
|
+
}
|
|
3601
|
+
|
|
3602
|
+
try {
|
|
3603
|
+
if (fs$1.readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft')) {
|
|
3604
|
+
return !isInsideContainer();
|
|
3605
|
+
}
|
|
3606
|
+
} catch {}
|
|
3607
|
+
|
|
3608
|
+
// Fallback for custom kernels: check WSL-specific paths.
|
|
3609
|
+
if (
|
|
3610
|
+
fs$1.existsSync('/proc/sys/fs/binfmt_misc/WSLInterop')
|
|
3611
|
+
|| fs$1.existsSync('/run/WSL')
|
|
3612
|
+
) {
|
|
3613
|
+
return !isInsideContainer();
|
|
3614
|
+
}
|
|
3615
|
+
|
|
3616
|
+
return false;
|
|
3617
|
+
};
|
|
3618
|
+
|
|
3619
|
+
var isWsl$1 = process$1.env.__IS_WSL_TEST__ ? isWsl : isWsl();
|
|
3620
|
+
|
|
3621
|
+
const wslDrivesMountPoint = (() => {
|
|
3622
|
+
// Default value for "root" param
|
|
3623
|
+
// according to https://docs.microsoft.com/en-us/windows/wsl/wsl-config
|
|
3624
|
+
const defaultMountPoint = '/mnt/';
|
|
3625
|
+
|
|
3626
|
+
let mountPoint;
|
|
3627
|
+
|
|
3628
|
+
return async function () {
|
|
3629
|
+
if (mountPoint) {
|
|
3630
|
+
// Return memoized mount point value
|
|
3631
|
+
return mountPoint;
|
|
3632
|
+
}
|
|
3633
|
+
|
|
3634
|
+
const configFilePath = '/etc/wsl.conf';
|
|
3635
|
+
|
|
3636
|
+
let isConfigFileExists = false;
|
|
3637
|
+
try {
|
|
3638
|
+
await fs$2.access(configFilePath, constants.F_OK);
|
|
3639
|
+
isConfigFileExists = true;
|
|
3640
|
+
} catch {}
|
|
3641
|
+
|
|
3642
|
+
if (!isConfigFileExists) {
|
|
3643
|
+
return defaultMountPoint;
|
|
3644
|
+
}
|
|
3645
|
+
|
|
3646
|
+
const configContent = await fs$2.readFile(configFilePath, {encoding: 'utf8'});
|
|
3647
|
+
const configMountPoint = /(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(configContent);
|
|
3648
|
+
|
|
3649
|
+
if (!configMountPoint) {
|
|
3650
|
+
return defaultMountPoint;
|
|
3651
|
+
}
|
|
3652
|
+
|
|
3653
|
+
mountPoint = configMountPoint.groups.mountPoint.trim();
|
|
3654
|
+
mountPoint = mountPoint.endsWith('/') ? mountPoint : `${mountPoint}/`;
|
|
3655
|
+
|
|
3656
|
+
return mountPoint;
|
|
3657
|
+
};
|
|
3658
|
+
})();
|
|
3659
|
+
|
|
3660
|
+
const powerShellPathFromWsl = async () => {
|
|
3661
|
+
const mountPoint = await wslDrivesMountPoint();
|
|
3662
|
+
return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
|
|
3663
|
+
};
|
|
3664
|
+
|
|
3665
|
+
const powerShellPath = async () => {
|
|
3666
|
+
if (isWsl$1) {
|
|
3667
|
+
return powerShellPathFromWsl();
|
|
3668
|
+
}
|
|
3669
|
+
|
|
3670
|
+
return `${process$1.env.SYSTEMROOT || process$1.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
3671
|
+
};
|
|
3672
|
+
|
|
3673
|
+
function defineLazyProperty(object, propertyName, valueGetter) {
|
|
3674
|
+
const define = value => Object.defineProperty(object, propertyName, {value, enumerable: true, writable: true});
|
|
3675
|
+
|
|
3676
|
+
Object.defineProperty(object, propertyName, {
|
|
3677
|
+
configurable: true,
|
|
3678
|
+
enumerable: true,
|
|
3679
|
+
get() {
|
|
3680
|
+
const result = valueGetter();
|
|
3681
|
+
define(result);
|
|
3682
|
+
return result;
|
|
3683
|
+
},
|
|
3684
|
+
set(value) {
|
|
3685
|
+
define(value);
|
|
3686
|
+
}
|
|
3687
|
+
});
|
|
3688
|
+
|
|
3689
|
+
return object;
|
|
3690
|
+
}
|
|
3691
|
+
|
|
3692
|
+
const execFileAsync$3 = promisify(execFile$1);
|
|
3693
|
+
|
|
3694
|
+
async function defaultBrowserId() {
|
|
3695
|
+
if (process$1.platform !== 'darwin') {
|
|
3696
|
+
throw new Error('macOS only');
|
|
3697
|
+
}
|
|
3698
|
+
|
|
3699
|
+
const {stdout} = await execFileAsync$3('defaults', ['read', 'com.apple.LaunchServices/com.apple.launchservices.secure', 'LSHandlers']);
|
|
3700
|
+
|
|
3701
|
+
// `(?!-)` is to prevent matching `LSHandlerRoleAll = "-";`.
|
|
3702
|
+
const match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout);
|
|
3703
|
+
|
|
3704
|
+
const browserId = match?.groups.id ?? 'com.apple.Safari';
|
|
3705
|
+
|
|
3706
|
+
// Correct the case for Safari's bundle identifier
|
|
3707
|
+
if (browserId === 'com.apple.safari') {
|
|
3708
|
+
return 'com.apple.Safari';
|
|
3709
|
+
}
|
|
3710
|
+
|
|
3711
|
+
return browserId;
|
|
3712
|
+
}
|
|
3713
|
+
|
|
3714
|
+
const execFileAsync$2 = promisify(execFile$1);
|
|
3715
|
+
|
|
3716
|
+
async function runAppleScript(script, {humanReadableOutput = true, signal} = {}) {
|
|
3717
|
+
if (process$1.platform !== 'darwin') {
|
|
3718
|
+
throw new Error('macOS only');
|
|
3719
|
+
}
|
|
3720
|
+
|
|
3721
|
+
const outputArguments = humanReadableOutput ? [] : ['-ss'];
|
|
3722
|
+
|
|
3723
|
+
const execOptions = {};
|
|
3724
|
+
if (signal) {
|
|
3725
|
+
execOptions.signal = signal;
|
|
3726
|
+
}
|
|
3727
|
+
|
|
3728
|
+
const {stdout} = await execFileAsync$2('osascript', ['-e', script, outputArguments], execOptions);
|
|
3729
|
+
return stdout.trim();
|
|
3730
|
+
}
|
|
3731
|
+
|
|
3732
|
+
async function bundleName(bundleId) {
|
|
3733
|
+
return runAppleScript(`tell application "Finder" to set app_path to application file id "${bundleId}" as string\ntell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`);
|
|
3734
|
+
}
|
|
3735
|
+
|
|
3736
|
+
const execFileAsync$1 = promisify(execFile$1);
|
|
3737
|
+
|
|
3738
|
+
// TODO: Fix the casing of bundle identifiers in the next major version.
|
|
3739
|
+
|
|
3740
|
+
// Windows doesn't have browser IDs in the same way macOS/Linux does so we give fake
|
|
3741
|
+
// ones that look real and match the macOS/Linux versions for cross-platform apps.
|
|
3742
|
+
const windowsBrowserProgIds = {
|
|
3743
|
+
MSEdgeHTM: {name: 'Edge', id: 'com.microsoft.edge'}, // The missing `L` is correct.
|
|
3744
|
+
MSEdgeBHTML: {name: 'Edge Beta', id: 'com.microsoft.edge.beta'},
|
|
3745
|
+
MSEdgeDHTML: {name: 'Edge Dev', id: 'com.microsoft.edge.dev'},
|
|
3746
|
+
AppXq0fevzme2pys62n3e0fbqa7peapykr8v: {name: 'Edge', id: 'com.microsoft.edge.old'},
|
|
3747
|
+
ChromeHTML: {name: 'Chrome', id: 'com.google.chrome'},
|
|
3748
|
+
ChromeBHTML: {name: 'Chrome Beta', id: 'com.google.chrome.beta'},
|
|
3749
|
+
ChromeDHTML: {name: 'Chrome Dev', id: 'com.google.chrome.dev'},
|
|
3750
|
+
ChromiumHTM: {name: 'Chromium', id: 'org.chromium.Chromium'},
|
|
3751
|
+
BraveHTML: {name: 'Brave', id: 'com.brave.Browser'},
|
|
3752
|
+
BraveBHTML: {name: 'Brave Beta', id: 'com.brave.Browser.beta'},
|
|
3753
|
+
BraveDHTML: {name: 'Brave Dev', id: 'com.brave.Browser.dev'},
|
|
3754
|
+
BraveSSHTM: {name: 'Brave Nightly', id: 'com.brave.Browser.nightly'},
|
|
3755
|
+
FirefoxURL: {name: 'Firefox', id: 'org.mozilla.firefox'},
|
|
3756
|
+
OperaStable: {name: 'Opera', id: 'com.operasoftware.Opera'},
|
|
3757
|
+
VivaldiHTM: {name: 'Vivaldi', id: 'com.vivaldi.Vivaldi'},
|
|
3758
|
+
'IE.HTTP': {name: 'Internet Explorer', id: 'com.microsoft.ie'},
|
|
3759
|
+
};
|
|
3760
|
+
|
|
3761
|
+
new Map(Object.entries(windowsBrowserProgIds));
|
|
3762
|
+
|
|
3763
|
+
class UnknownBrowserError extends Error {}
|
|
3764
|
+
|
|
3765
|
+
async function defaultBrowser$1(_execFileAsync = execFileAsync$1) {
|
|
3766
|
+
const {stdout} = await _execFileAsync('reg', [
|
|
3767
|
+
'QUERY',
|
|
3768
|
+
' HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice',
|
|
3769
|
+
'/v',
|
|
3770
|
+
'ProgId',
|
|
3771
|
+
]);
|
|
3772
|
+
|
|
3773
|
+
const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
|
|
3774
|
+
if (!match) {
|
|
3775
|
+
throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
|
|
3776
|
+
}
|
|
3777
|
+
|
|
3778
|
+
const {id} = match.groups;
|
|
3779
|
+
|
|
3780
|
+
// Windows can append a hash suffix to ProgIds using a dot or hyphen
|
|
3781
|
+
// (e.g., `ChromeHTML.ABC123`, `FirefoxURL-6F193CCC56814779`).
|
|
3782
|
+
// Try exact match first, then try without the suffix.
|
|
3783
|
+
const dotIndex = id.lastIndexOf('.');
|
|
3784
|
+
const hyphenIndex = id.lastIndexOf('-');
|
|
3785
|
+
const baseIdByDot = dotIndex === -1 ? undefined : id.slice(0, dotIndex);
|
|
3786
|
+
const baseIdByHyphen = hyphenIndex === -1 ? undefined : id.slice(0, hyphenIndex);
|
|
3787
|
+
|
|
3788
|
+
return windowsBrowserProgIds[id] ?? windowsBrowserProgIds[baseIdByDot] ?? windowsBrowserProgIds[baseIdByHyphen] ?? {name: id, id};
|
|
3789
|
+
}
|
|
3790
|
+
|
|
3791
|
+
const execFileAsync = promisify(execFile$1);
|
|
3792
|
+
|
|
3793
|
+
// Inlined: https://github.com/sindresorhus/titleize/blob/main/index.js
|
|
3794
|
+
const titleize = string => string.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, x => x.toUpperCase());
|
|
3795
|
+
|
|
3796
|
+
async function defaultBrowser() {
|
|
3797
|
+
if (process$1.platform === 'darwin') {
|
|
3798
|
+
const id = await defaultBrowserId();
|
|
3799
|
+
const name = await bundleName(id);
|
|
3800
|
+
return {name, id};
|
|
3801
|
+
}
|
|
3802
|
+
|
|
3803
|
+
if (process$1.platform === 'linux') {
|
|
3804
|
+
const {stdout} = await execFileAsync('xdg-mime', ['query', 'default', 'x-scheme-handler/http']);
|
|
3805
|
+
const id = stdout.trim();
|
|
3806
|
+
const name = titleize(id.replace(/.desktop$/, '').replace('-', ' '));
|
|
3807
|
+
return {name, id};
|
|
3808
|
+
}
|
|
3809
|
+
|
|
3810
|
+
if (process$1.platform === 'win32') {
|
|
3811
|
+
return defaultBrowser$1();
|
|
3812
|
+
}
|
|
3813
|
+
|
|
3814
|
+
throw new Error('Only macOS, Linux, and Windows are supported');
|
|
3815
|
+
}
|
|
3816
|
+
|
|
3817
|
+
const execFile = promisify(childProcess.execFile);
|
|
3818
|
+
|
|
3819
|
+
// Path to included `xdg-open`.
|
|
3820
|
+
const __dirname$2 = path$1.dirname(fileURLToPath(import.meta.url));
|
|
3821
|
+
const localXdgOpenPath = path$1.join(__dirname$2, 'xdg-open');
|
|
3822
|
+
|
|
3823
|
+
const {platform, arch} = process$1;
|
|
3824
|
+
|
|
3825
|
+
/**
|
|
3826
|
+
Get the default browser name in Windows from WSL.
|
|
3827
|
+
|
|
3828
|
+
@returns {Promise<string>} Browser name.
|
|
3829
|
+
*/
|
|
3830
|
+
async function getWindowsDefaultBrowserFromWsl() {
|
|
3831
|
+
const powershellPath = await powerShellPath();
|
|
3832
|
+
const rawCommand = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
|
|
3833
|
+
const encodedCommand = Buffer$1.from(rawCommand, 'utf16le').toString('base64');
|
|
3834
|
+
|
|
3835
|
+
const {stdout} = await execFile(
|
|
3836
|
+
powershellPath,
|
|
3837
|
+
[
|
|
3838
|
+
'-NoProfile',
|
|
3839
|
+
'-NonInteractive',
|
|
3840
|
+
'-ExecutionPolicy',
|
|
3841
|
+
'Bypass',
|
|
3842
|
+
'-EncodedCommand',
|
|
3843
|
+
encodedCommand,
|
|
3844
|
+
],
|
|
3845
|
+
{encoding: 'utf8'},
|
|
3846
|
+
);
|
|
3847
|
+
|
|
3848
|
+
const progId = stdout.trim();
|
|
3849
|
+
|
|
3850
|
+
// Map ProgId to browser IDs
|
|
3851
|
+
const browserMap = {
|
|
3852
|
+
ChromeHTML: 'com.google.chrome',
|
|
3853
|
+
BraveHTML: 'com.brave.Browser',
|
|
3854
|
+
MSEdgeHTM: 'com.microsoft.edge',
|
|
3855
|
+
FirefoxURL: 'org.mozilla.firefox',
|
|
3856
|
+
};
|
|
3857
|
+
|
|
3858
|
+
return browserMap[progId] ? {id: browserMap[progId]} : {};
|
|
3859
|
+
}
|
|
3860
|
+
|
|
3861
|
+
const pTryEach = async (array, mapper) => {
|
|
3862
|
+
let latestError;
|
|
3863
|
+
|
|
3864
|
+
for (const item of array) {
|
|
3865
|
+
try {
|
|
3866
|
+
return await mapper(item); // eslint-disable-line no-await-in-loop
|
|
3867
|
+
} catch (error) {
|
|
3868
|
+
latestError = error;
|
|
3869
|
+
}
|
|
3870
|
+
}
|
|
3871
|
+
|
|
3872
|
+
throw latestError;
|
|
3873
|
+
};
|
|
3874
|
+
|
|
3875
|
+
// eslint-disable-next-line complexity
|
|
3876
|
+
const baseOpen = async options => {
|
|
3877
|
+
options = {
|
|
3878
|
+
wait: false,
|
|
3879
|
+
background: false,
|
|
3880
|
+
newInstance: false,
|
|
3881
|
+
allowNonzeroExitCode: false,
|
|
3882
|
+
...options,
|
|
3883
|
+
};
|
|
3884
|
+
|
|
3885
|
+
if (Array.isArray(options.app)) {
|
|
3886
|
+
return pTryEach(options.app, singleApp => baseOpen({
|
|
3887
|
+
...options,
|
|
3888
|
+
app: singleApp,
|
|
3889
|
+
}));
|
|
3890
|
+
}
|
|
3891
|
+
|
|
3892
|
+
let {name: app, arguments: appArguments = []} = options.app ?? {};
|
|
3893
|
+
appArguments = [...appArguments];
|
|
3894
|
+
|
|
3895
|
+
if (Array.isArray(app)) {
|
|
3896
|
+
return pTryEach(app, appName => baseOpen({
|
|
3897
|
+
...options,
|
|
3898
|
+
app: {
|
|
3899
|
+
name: appName,
|
|
3900
|
+
arguments: appArguments,
|
|
3901
|
+
},
|
|
3902
|
+
}));
|
|
3903
|
+
}
|
|
3904
|
+
|
|
3905
|
+
if (app === 'browser' || app === 'browserPrivate') {
|
|
3906
|
+
// IDs from default-browser for macOS and windows are the same
|
|
3907
|
+
const ids = {
|
|
3908
|
+
'com.google.chrome': 'chrome',
|
|
3909
|
+
'google-chrome.desktop': 'chrome',
|
|
3910
|
+
'com.brave.Browser': 'brave',
|
|
3911
|
+
'org.mozilla.firefox': 'firefox',
|
|
3912
|
+
'firefox.desktop': 'firefox',
|
|
3913
|
+
'com.microsoft.msedge': 'edge',
|
|
3914
|
+
'com.microsoft.edge': 'edge',
|
|
3915
|
+
'com.microsoft.edgemac': 'edge',
|
|
3916
|
+
'microsoft-edge.desktop': 'edge',
|
|
3917
|
+
};
|
|
3918
|
+
|
|
3919
|
+
// Incognito flags for each browser in `apps`.
|
|
3920
|
+
const flags = {
|
|
3921
|
+
chrome: '--incognito',
|
|
3922
|
+
brave: '--incognito',
|
|
3923
|
+
firefox: '--private-window',
|
|
3924
|
+
edge: '--inPrivate',
|
|
3925
|
+
};
|
|
3926
|
+
|
|
3927
|
+
const browser = isWsl$1 ? await getWindowsDefaultBrowserFromWsl() : await defaultBrowser();
|
|
3928
|
+
if (browser.id in ids) {
|
|
3929
|
+
const browserName = ids[browser.id];
|
|
3930
|
+
|
|
3931
|
+
if (app === 'browserPrivate') {
|
|
3932
|
+
appArguments.push(flags[browserName]);
|
|
3933
|
+
}
|
|
3934
|
+
|
|
3935
|
+
return baseOpen({
|
|
3936
|
+
...options,
|
|
3937
|
+
app: {
|
|
3938
|
+
name: apps[browserName],
|
|
3939
|
+
arguments: appArguments,
|
|
3940
|
+
},
|
|
3941
|
+
});
|
|
3942
|
+
}
|
|
3943
|
+
|
|
3944
|
+
throw new Error(`${browser.name} is not supported as a default browser`);
|
|
3945
|
+
}
|
|
3946
|
+
|
|
3947
|
+
let command;
|
|
3948
|
+
const cliArguments = [];
|
|
3949
|
+
const childProcessOptions = {};
|
|
3950
|
+
|
|
3951
|
+
if (platform === 'darwin') {
|
|
3952
|
+
command = 'open';
|
|
3953
|
+
|
|
3954
|
+
if (options.wait) {
|
|
3955
|
+
cliArguments.push('--wait-apps');
|
|
3956
|
+
}
|
|
3957
|
+
|
|
3958
|
+
if (options.background) {
|
|
3959
|
+
cliArguments.push('--background');
|
|
3960
|
+
}
|
|
3961
|
+
|
|
3962
|
+
if (options.newInstance) {
|
|
3963
|
+
cliArguments.push('--new');
|
|
3964
|
+
}
|
|
3965
|
+
|
|
3966
|
+
if (app) {
|
|
3967
|
+
cliArguments.push('-a', app);
|
|
3968
|
+
}
|
|
3969
|
+
} else if (platform === 'win32' || (isWsl$1 && !isInsideContainer() && !app)) {
|
|
3970
|
+
command = await powerShellPath();
|
|
3971
|
+
|
|
3972
|
+
cliArguments.push(
|
|
3973
|
+
'-NoProfile',
|
|
3974
|
+
'-NonInteractive',
|
|
3975
|
+
'-ExecutionPolicy',
|
|
3976
|
+
'Bypass',
|
|
3977
|
+
'-EncodedCommand',
|
|
3978
|
+
);
|
|
3979
|
+
|
|
3980
|
+
if (!isWsl$1) {
|
|
3981
|
+
childProcessOptions.windowsVerbatimArguments = true;
|
|
3982
|
+
}
|
|
3983
|
+
|
|
3984
|
+
const encodedArguments = ['Start'];
|
|
3985
|
+
|
|
3986
|
+
if (options.wait) {
|
|
3987
|
+
encodedArguments.push('-Wait');
|
|
3988
|
+
}
|
|
3989
|
+
|
|
3990
|
+
if (app) {
|
|
3991
|
+
// Double quote with double quotes to ensure the inner quotes are passed through.
|
|
3992
|
+
// Inner quotes are delimited for PowerShell interpretation with backticks.
|
|
3993
|
+
encodedArguments.push(`"\`"${app}\`""`);
|
|
3994
|
+
if (options.target) {
|
|
3995
|
+
appArguments.push(options.target);
|
|
3996
|
+
}
|
|
3997
|
+
} else if (options.target) {
|
|
3998
|
+
encodedArguments.push(`"${options.target}"`);
|
|
3999
|
+
}
|
|
4000
|
+
|
|
4001
|
+
if (appArguments.length > 0) {
|
|
4002
|
+
appArguments = appArguments.map(argument => `"\`"${argument}\`""`);
|
|
4003
|
+
encodedArguments.push('-ArgumentList', appArguments.join(','));
|
|
4004
|
+
}
|
|
4005
|
+
|
|
4006
|
+
// Using Base64-encoded command, accepted by PowerShell, to allow special characters.
|
|
4007
|
+
options.target = Buffer$1.from(encodedArguments.join(' '), 'utf16le').toString('base64');
|
|
4008
|
+
} else {
|
|
4009
|
+
if (app) {
|
|
4010
|
+
command = app;
|
|
4011
|
+
} else {
|
|
4012
|
+
// When bundled by Webpack, there's no actual package file path and no local `xdg-open`.
|
|
4013
|
+
const isBundled = !__dirname$2 || __dirname$2 === '/';
|
|
4014
|
+
|
|
4015
|
+
// Check if local `xdg-open` exists and is executable.
|
|
4016
|
+
let exeLocalXdgOpen = false;
|
|
4017
|
+
try {
|
|
4018
|
+
await fs$2.access(localXdgOpenPath, constants.X_OK);
|
|
4019
|
+
exeLocalXdgOpen = true;
|
|
4020
|
+
} catch {}
|
|
4021
|
+
|
|
4022
|
+
const useSystemXdgOpen = process$1.versions.electron
|
|
4023
|
+
?? (platform === 'android' || isBundled || !exeLocalXdgOpen);
|
|
4024
|
+
command = useSystemXdgOpen ? 'xdg-open' : localXdgOpenPath;
|
|
4025
|
+
}
|
|
4026
|
+
|
|
4027
|
+
if (appArguments.length > 0) {
|
|
4028
|
+
cliArguments.push(...appArguments);
|
|
4029
|
+
}
|
|
4030
|
+
|
|
4031
|
+
if (!options.wait) {
|
|
4032
|
+
// `xdg-open` will block the process unless stdio is ignored
|
|
4033
|
+
// and it's detached from the parent even if it's unref'd.
|
|
4034
|
+
childProcessOptions.stdio = 'ignore';
|
|
4035
|
+
childProcessOptions.detached = true;
|
|
4036
|
+
}
|
|
4037
|
+
}
|
|
4038
|
+
|
|
4039
|
+
if (platform === 'darwin' && appArguments.length > 0) {
|
|
4040
|
+
cliArguments.push('--args', ...appArguments);
|
|
4041
|
+
}
|
|
4042
|
+
|
|
4043
|
+
// This has to come after `--args`.
|
|
4044
|
+
if (options.target) {
|
|
4045
|
+
cliArguments.push(options.target);
|
|
4046
|
+
}
|
|
4047
|
+
|
|
4048
|
+
const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);
|
|
4049
|
+
|
|
4050
|
+
if (options.wait) {
|
|
4051
|
+
return new Promise((resolve, reject) => {
|
|
4052
|
+
subprocess.once('error', reject);
|
|
4053
|
+
|
|
4054
|
+
subprocess.once('close', exitCode => {
|
|
4055
|
+
if (!options.allowNonzeroExitCode && exitCode > 0) {
|
|
4056
|
+
reject(new Error(`Exited with code ${exitCode}`));
|
|
4057
|
+
return;
|
|
4058
|
+
}
|
|
4059
|
+
|
|
4060
|
+
resolve(subprocess);
|
|
4061
|
+
});
|
|
4062
|
+
});
|
|
4063
|
+
}
|
|
4064
|
+
|
|
4065
|
+
subprocess.unref();
|
|
4066
|
+
|
|
4067
|
+
return subprocess;
|
|
4068
|
+
};
|
|
4069
|
+
|
|
4070
|
+
const open = (target, options) => {
|
|
4071
|
+
if (typeof target !== 'string') {
|
|
4072
|
+
throw new TypeError('Expected a `target`');
|
|
4073
|
+
}
|
|
4074
|
+
|
|
4075
|
+
return baseOpen({
|
|
4076
|
+
...options,
|
|
4077
|
+
target,
|
|
4078
|
+
});
|
|
4079
|
+
};
|
|
4080
|
+
|
|
4081
|
+
function detectArchBinary(binary) {
|
|
4082
|
+
if (typeof binary === 'string' || Array.isArray(binary)) {
|
|
4083
|
+
return binary;
|
|
4084
|
+
}
|
|
4085
|
+
|
|
4086
|
+
const {[arch]: archBinary} = binary;
|
|
4087
|
+
|
|
4088
|
+
if (!archBinary) {
|
|
4089
|
+
throw new Error(`${arch} is not supported`);
|
|
4090
|
+
}
|
|
4091
|
+
|
|
4092
|
+
return archBinary;
|
|
4093
|
+
}
|
|
4094
|
+
|
|
4095
|
+
function detectPlatformBinary({[platform]: platformBinary}, {wsl}) {
|
|
4096
|
+
if (wsl && isWsl$1) {
|
|
4097
|
+
return detectArchBinary(wsl);
|
|
4098
|
+
}
|
|
4099
|
+
|
|
4100
|
+
if (!platformBinary) {
|
|
4101
|
+
throw new Error(`${platform} is not supported`);
|
|
4102
|
+
}
|
|
4103
|
+
|
|
4104
|
+
return detectArchBinary(platformBinary);
|
|
4105
|
+
}
|
|
4106
|
+
|
|
4107
|
+
const apps = {};
|
|
4108
|
+
|
|
4109
|
+
defineLazyProperty(apps, 'chrome', () => detectPlatformBinary({
|
|
4110
|
+
darwin: 'google chrome',
|
|
4111
|
+
win32: 'chrome',
|
|
4112
|
+
linux: ['google-chrome', 'google-chrome-stable', 'chromium'],
|
|
4113
|
+
}, {
|
|
4114
|
+
wsl: {
|
|
4115
|
+
ia32: '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe',
|
|
4116
|
+
x64: ['/mnt/c/Program Files/Google/Chrome/Application/chrome.exe', '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'],
|
|
4117
|
+
},
|
|
4118
|
+
}));
|
|
4119
|
+
|
|
4120
|
+
defineLazyProperty(apps, 'brave', () => detectPlatformBinary({
|
|
4121
|
+
darwin: 'brave browser',
|
|
4122
|
+
win32: 'brave',
|
|
4123
|
+
linux: ['brave-browser', 'brave'],
|
|
4124
|
+
}, {
|
|
4125
|
+
wsl: {
|
|
4126
|
+
ia32: '/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe',
|
|
4127
|
+
x64: ['/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe', '/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe'],
|
|
4128
|
+
},
|
|
4129
|
+
}));
|
|
4130
|
+
|
|
4131
|
+
defineLazyProperty(apps, 'firefox', () => detectPlatformBinary({
|
|
4132
|
+
darwin: 'firefox',
|
|
4133
|
+
win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,
|
|
4134
|
+
linux: 'firefox',
|
|
4135
|
+
}, {
|
|
4136
|
+
wsl: '/mnt/c/Program Files/Mozilla Firefox/firefox.exe',
|
|
4137
|
+
}));
|
|
4138
|
+
|
|
4139
|
+
defineLazyProperty(apps, 'edge', () => detectPlatformBinary({
|
|
4140
|
+
darwin: 'microsoft edge',
|
|
4141
|
+
win32: 'msedge',
|
|
4142
|
+
linux: ['microsoft-edge', 'microsoft-edge-dev'],
|
|
4143
|
+
}, {
|
|
4144
|
+
wsl: '/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe',
|
|
4145
|
+
}));
|
|
4146
|
+
|
|
4147
|
+
defineLazyProperty(apps, 'browser', () => 'browser');
|
|
4148
|
+
|
|
4149
|
+
defineLazyProperty(apps, 'browserPrivate', () => 'browserPrivate');
|
|
4150
|
+
|
|
3532
4151
|
/**
|
|
3533
4152
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3534
4153
|
*
|
|
@@ -3589,12 +4208,12 @@ function getEditorSessionModuleImport() {
|
|
|
3589
4208
|
'./editor/scene-editor-session.ts',
|
|
3590
4209
|
];
|
|
3591
4210
|
for (const candidate of candidates) {
|
|
3592
|
-
const modulePath = fileURLToPath(new URL(candidate, import.meta.url));
|
|
4211
|
+
const modulePath = fileURLToPath$1(new URL(candidate, import.meta.url));
|
|
3593
4212
|
if (existsSync(modulePath)) {
|
|
3594
4213
|
return `/@fs/${modulePath}`;
|
|
3595
4214
|
}
|
|
3596
4215
|
}
|
|
3597
|
-
return `/@fs/${fileURLToPath(new URL('./scene-editor-session.ts', import.meta.url))}`;
|
|
4216
|
+
return `/@fs/${fileURLToPath$1(new URL('./scene-editor-session.ts', import.meta.url))}`;
|
|
3598
4217
|
}
|
|
3599
4218
|
function getEditorWorkspaceModuleImport() {
|
|
3600
4219
|
const candidates = [
|
|
@@ -3604,7 +4223,7 @@ function getEditorWorkspaceModuleImport() {
|
|
|
3604
4223
|
'./editor/editor-workspace.tsx',
|
|
3605
4224
|
];
|
|
3606
4225
|
for (const candidate of candidates) {
|
|
3607
|
-
const modulePath = fileURLToPath(new URL(candidate, import.meta.url));
|
|
4226
|
+
const modulePath = fileURLToPath$1(new URL(candidate, import.meta.url));
|
|
3608
4227
|
if (existsSync(modulePath)) {
|
|
3609
4228
|
return `/@fs/${modulePath}`;
|
|
3610
4229
|
}
|
|
@@ -3614,7 +4233,7 @@ function getEditorWorkspaceModuleImport() {
|
|
|
3614
4233
|
function getCoreModuleImport() {
|
|
3615
4234
|
const candidates = ['../../../core/src/index.ts', '../../core/src/index.ts'];
|
|
3616
4235
|
for (const candidate of candidates) {
|
|
3617
|
-
const sourceModulePath = fileURLToPath(new URL(candidate, import.meta.url));
|
|
4236
|
+
const sourceModulePath = fileURLToPath$1(new URL(candidate, import.meta.url));
|
|
3618
4237
|
if (existsSync(sourceModulePath)) {
|
|
3619
4238
|
return `/@fs/${sourceModulePath}`;
|
|
3620
4239
|
}
|
|
@@ -3627,7 +4246,7 @@ function getSceneCompositionModuleImport() {
|
|
|
3627
4246
|
'../../scene-composition/src/index.ts',
|
|
3628
4247
|
];
|
|
3629
4248
|
for (const candidate of candidates) {
|
|
3630
|
-
const sourceModulePath = fileURLToPath(new URL(candidate, import.meta.url));
|
|
4249
|
+
const sourceModulePath = fileURLToPath$1(new URL(candidate, import.meta.url));
|
|
3631
4250
|
if (existsSync(sourceModulePath)) {
|
|
3632
4251
|
return `/@fs/${sourceModulePath}`;
|
|
3633
4252
|
}
|
|
@@ -3640,7 +4259,7 @@ function getOrbitControlsModuleImport() {
|
|
|
3640
4259
|
'../../core/node_modules/three/examples/jsm/controls/OrbitControls.js',
|
|
3641
4260
|
];
|
|
3642
4261
|
for (const candidate of candidates) {
|
|
3643
|
-
const sourceModulePath = fileURLToPath(new URL(candidate, import.meta.url));
|
|
4262
|
+
const sourceModulePath = fileURLToPath$1(new URL(candidate, import.meta.url));
|
|
3644
4263
|
if (existsSync(sourceModulePath)) {
|
|
3645
4264
|
return `/@fs/${sourceModulePath}`;
|
|
3646
4265
|
}
|
|
@@ -3653,7 +4272,7 @@ function getTransformControlsModuleImport() {
|
|
|
3653
4272
|
'../../core/node_modules/three/examples/jsm/controls/TransformControls.js',
|
|
3654
4273
|
];
|
|
3655
4274
|
for (const candidate of candidates) {
|
|
3656
|
-
const sourceModulePath = fileURLToPath(new URL(candidate, import.meta.url));
|
|
4275
|
+
const sourceModulePath = fileURLToPath$1(new URL(candidate, import.meta.url));
|
|
3657
4276
|
if (existsSync(sourceModulePath)) {
|
|
3658
4277
|
return `/@fs/${sourceModulePath}`;
|
|
3659
4278
|
}
|
|
@@ -3666,7 +4285,7 @@ function getViewportGizmoModuleImport() {
|
|
|
3666
4285
|
'../../node_modules/three-viewport-gizmo/dist/three-viewport-gizmo.js',
|
|
3667
4286
|
];
|
|
3668
4287
|
for (const candidate of candidates) {
|
|
3669
|
-
const sourceModulePath = fileURLToPath(new URL(candidate, import.meta.url));
|
|
4288
|
+
const sourceModulePath = fileURLToPath$1(new URL(candidate, import.meta.url));
|
|
3670
4289
|
if (existsSync(sourceModulePath)) {
|
|
3671
4290
|
return `/@fs/${sourceModulePath}`;
|
|
3672
4291
|
}
|
|
@@ -3972,6 +4591,7 @@ let applyScenePatch;
|
|
|
3972
4591
|
let Box3;
|
|
3973
4592
|
let Box3Helper;
|
|
3974
4593
|
let BoxGeometry;
|
|
4594
|
+
let BufferGeometry;
|
|
3975
4595
|
let CanvasTexture;
|
|
3976
4596
|
let Color;
|
|
3977
4597
|
let ComponentRegistry;
|
|
@@ -3981,13 +4601,15 @@ let disposeLoweredSceneNodes;
|
|
|
3981
4601
|
let ConeGeometry;
|
|
3982
4602
|
let CylinderGeometry;
|
|
3983
4603
|
let DirectionalLight;
|
|
4604
|
+
let Float32BufferAttribute;
|
|
3984
4605
|
let Frustum;
|
|
3985
4606
|
let finalizeSceneReviewDraft;
|
|
3986
|
-
let GridHelper;
|
|
3987
4607
|
let Group;
|
|
3988
4608
|
let hashSceneDocument;
|
|
3989
4609
|
let hashRuntimeSceneDocument;
|
|
3990
4610
|
let LevelComponentApplier;
|
|
4611
|
+
let LineBasicMaterial;
|
|
4612
|
+
let LineSegments;
|
|
3991
4613
|
let LightBinding;
|
|
3992
4614
|
let lightSpecFromComponentValue;
|
|
3993
4615
|
let lowerSceneDocumentObjects;
|
|
@@ -3999,9 +4621,11 @@ let MeshStandardMaterial;
|
|
|
3999
4621
|
let OrthographicCamera;
|
|
4000
4622
|
let PerspectiveCamera;
|
|
4001
4623
|
let PlaneGeometry;
|
|
4624
|
+
let Quaternion;
|
|
4002
4625
|
let Raycaster;
|
|
4003
4626
|
let restoreSceneEnvironment;
|
|
4004
4627
|
let Scene;
|
|
4628
|
+
let ShaderMaterial;
|
|
4005
4629
|
let SphereGeometry;
|
|
4006
4630
|
let SRGBColorSpace;
|
|
4007
4631
|
let Types;
|
|
@@ -4021,6 +4645,22 @@ let editorPanelPreviewRendererState = null;
|
|
|
4021
4645
|
let editorPanelPreviewRendererCreatedCount = 0;
|
|
4022
4646
|
let editorPanelPreviewRenderQueue = Promise.resolve();
|
|
4023
4647
|
const editorPanelFrameSchedulers = new WeakMap();
|
|
4648
|
+
const DEFAULT_EDITOR_DRAW_DISTANCE = 5000;
|
|
4649
|
+
const MIN_EDITOR_DRAW_DISTANCE = 50;
|
|
4650
|
+
const MAX_EDITOR_DRAW_DISTANCE = 100000;
|
|
4651
|
+
const MIN_EDITOR_GRID_SPACING = 0.5;
|
|
4652
|
+
const EDITOR_DRAW_DISTANCE_STORAGE_KEY = 'iwsdk-editor-view-distance';
|
|
4653
|
+
const DEFAULT_EDITOR_TRANSFORM_SNAP = Object.freeze({
|
|
4654
|
+
rotationDeg: 15,
|
|
4655
|
+
scale: 0.1,
|
|
4656
|
+
translation: 0.25,
|
|
4657
|
+
});
|
|
4658
|
+
const EDITOR_TRANSFORM_SNAP_LIMITS = Object.freeze({
|
|
4659
|
+
rotationDeg: { max: 180, min: 0.1 },
|
|
4660
|
+
scale: { max: 10, min: 0.001 },
|
|
4661
|
+
translation: { max: 10000, min: 0.001 },
|
|
4662
|
+
});
|
|
4663
|
+
const EDITOR_TRANSFORM_SNAP_STORAGE_KEY = 'iwsdk-editor-transform-snap';
|
|
4024
4664
|
|
|
4025
4665
|
async function loadEditorRuntimeDependencies() {
|
|
4026
4666
|
const [
|
|
@@ -4063,6 +4703,7 @@ async function loadEditorRuntimeDependencies() {
|
|
|
4063
4703
|
Box3,
|
|
4064
4704
|
Box3Helper,
|
|
4065
4705
|
BoxGeometry,
|
|
4706
|
+
BufferGeometry,
|
|
4066
4707
|
CanvasTexture,
|
|
4067
4708
|
Color,
|
|
4068
4709
|
ComponentRegistry,
|
|
@@ -4072,10 +4713,12 @@ async function loadEditorRuntimeDependencies() {
|
|
|
4072
4713
|
ConeGeometry,
|
|
4073
4714
|
CylinderGeometry,
|
|
4074
4715
|
DirectionalLight,
|
|
4716
|
+
Float32BufferAttribute,
|
|
4075
4717
|
Frustum,
|
|
4076
|
-
GridHelper,
|
|
4077
4718
|
Group,
|
|
4078
4719
|
LevelComponentApplier,
|
|
4720
|
+
LineBasicMaterial,
|
|
4721
|
+
LineSegments,
|
|
4079
4722
|
LightBinding,
|
|
4080
4723
|
lightSpecFromComponentValue,
|
|
4081
4724
|
lowerSceneDocumentObjects,
|
|
@@ -4087,9 +4730,11 @@ async function loadEditorRuntimeDependencies() {
|
|
|
4087
4730
|
OrthographicCamera,
|
|
4088
4731
|
PerspectiveCamera,
|
|
4089
4732
|
PlaneGeometry,
|
|
4733
|
+
Quaternion,
|
|
4090
4734
|
Raycaster,
|
|
4091
4735
|
restoreSceneEnvironment,
|
|
4092
4736
|
Scene,
|
|
4737
|
+
ShaderMaterial,
|
|
4093
4738
|
SphereGeometry,
|
|
4094
4739
|
SRGBColorSpace,
|
|
4095
4740
|
Types,
|
|
@@ -4165,6 +4810,7 @@ let runtimeDispatch = async () => {
|
|
|
4165
4810
|
};
|
|
4166
4811
|
let runtimeHandles = (method) =>
|
|
4167
4812
|
String(method).startsWith('scene_') ||
|
|
4813
|
+
String(method).startsWith('ui_') ||
|
|
4168
4814
|
String(method).startsWith('workspace_');
|
|
4169
4815
|
const collapsedOutlinerNodeIds = new Set();
|
|
4170
4816
|
const hiddenOutlinerNodeIds = new Set();
|
|
@@ -4242,6 +4888,29 @@ function handlesWorkspaceMethod(method) {
|
|
|
4242
4888
|
].includes(method);
|
|
4243
4889
|
}
|
|
4244
4890
|
|
|
4891
|
+
function handlesEditorMethodWithoutSession(method) {
|
|
4892
|
+
const value = String(method);
|
|
4893
|
+
return (
|
|
4894
|
+
handlesWorkspaceMethod(value) ||
|
|
4895
|
+
value.startsWith('scene_') ||
|
|
4896
|
+
value.startsWith('ui_')
|
|
4897
|
+
);
|
|
4898
|
+
}
|
|
4899
|
+
|
|
4900
|
+
function dispatchEditorMethodWithoutSession(
|
|
4901
|
+
method,
|
|
4902
|
+
params = {},
|
|
4903
|
+
unavailableMessage =
|
|
4904
|
+
'No scene is open in the IWSDK editor. Open the Editor view and select a scene, or run npx iwsdk scene open --input-json with the scene path.',
|
|
4905
|
+
) {
|
|
4906
|
+
if (handlesWorkspaceMethod(method)) {
|
|
4907
|
+
return dispatchWorkspaceCommand(null, method, params);
|
|
4908
|
+
}
|
|
4909
|
+
throw new Error(
|
|
4910
|
+
unavailableMessage + \` Then retry "\${String(method)}".\`,
|
|
4911
|
+
);
|
|
4912
|
+
}
|
|
4913
|
+
|
|
4245
4914
|
function readStoredWorkspaceScenePath() {
|
|
4246
4915
|
try {
|
|
4247
4916
|
const value = sessionStorage.getItem(WORKSPACE_SCENE_PATH_KEY);
|
|
@@ -6351,6 +7020,25 @@ function editorWorkspaceController() {
|
|
|
6351
7020
|
reloadPage() {
|
|
6352
7021
|
window.location.reload();
|
|
6353
7022
|
},
|
|
7023
|
+
openRuntimeInBrowser() {
|
|
7024
|
+
void fetch('/__iwsdk/workspace/open-runtime', {
|
|
7025
|
+
method: 'POST',
|
|
7026
|
+
})
|
|
7027
|
+
.then((response) => {
|
|
7028
|
+
if (!response.ok) {
|
|
7029
|
+
console.error(
|
|
7030
|
+
'[IWSDK] Failed to open runtime in default browser:',
|
|
7031
|
+
response.status,
|
|
7032
|
+
);
|
|
7033
|
+
}
|
|
7034
|
+
})
|
|
7035
|
+
.catch((error) => {
|
|
7036
|
+
console.error(
|
|
7037
|
+
'[IWSDK] Failed to open runtime in default browser:',
|
|
7038
|
+
error,
|
|
7039
|
+
);
|
|
7040
|
+
});
|
|
7041
|
+
},
|
|
6354
7042
|
selectNode(nodeId, modifiers) {
|
|
6355
7043
|
const session = activeEditorSession();
|
|
6356
7044
|
if (!session) {
|
|
@@ -6385,7 +7073,14 @@ function editorWorkspaceController() {
|
|
|
6385
7073
|
.then(refreshActiveEditor);
|
|
6386
7074
|
},
|
|
6387
7075
|
setTransformMode,
|
|
7076
|
+
setTransformSnap(mode, value) {
|
|
7077
|
+
setTransformSnapValue(mode, value);
|
|
7078
|
+
refreshActiveEditor();
|
|
7079
|
+
},
|
|
6388
7080
|
setTransformSpace,
|
|
7081
|
+
setViewportDrawDistance(distance) {
|
|
7082
|
+
setEditorDrawDistance(distance);
|
|
7083
|
+
},
|
|
6389
7084
|
setView(view) {
|
|
6390
7085
|
void setWorkspaceView(view);
|
|
6391
7086
|
},
|
|
@@ -7341,6 +8036,13 @@ function snapVector(values, increment) {
|
|
|
7341
8036
|
return values.map((value) => snapNumber(value, increment));
|
|
7342
8037
|
}
|
|
7343
8038
|
|
|
8039
|
+
function snapScaleVector(values, increment) {
|
|
8040
|
+
return values.map((value) => {
|
|
8041
|
+
const snapped = snapNumber(value, increment);
|
|
8042
|
+
return snapped === 0 ? (Math.sign(value) || 1) * increment : snapped;
|
|
8043
|
+
});
|
|
8044
|
+
}
|
|
8045
|
+
|
|
7344
8046
|
function scaleVectorFromTransform(transform = {}) {
|
|
7345
8047
|
return typeof transform.scale === 'number'
|
|
7346
8048
|
? [transform.scale, transform.scale, transform.scale]
|
|
@@ -7380,7 +8082,9 @@ function snapTransformForCurrentMode(transform) {
|
|
|
7380
8082
|
if (mode === 'scale') {
|
|
7381
8083
|
return {
|
|
7382
8084
|
...transform,
|
|
7383
|
-
scale: compactScaleValue(
|
|
8085
|
+
scale: compactScaleValue(
|
|
8086
|
+
snapScaleVector(scaleVectorFromTransform(transform), snap.scale),
|
|
8087
|
+
),
|
|
7384
8088
|
};
|
|
7385
8089
|
}
|
|
7386
8090
|
return transform;
|
|
@@ -7693,23 +8397,302 @@ function markOwnedEditorHelper(mesh, nodeId, helperType) {
|
|
|
7693
8397
|
return mesh;
|
|
7694
8398
|
}
|
|
7695
8399
|
|
|
8400
|
+
function markLightEditorHelper(mesh, nodeId, helperType, role) {
|
|
8401
|
+
markOwnedEditorHelper(mesh, nodeId, helperType);
|
|
8402
|
+
mesh.userData.iwsdkEditorLightRole = role;
|
|
8403
|
+
mesh.userData.iwsdkEditorPickable = role === 'handle';
|
|
8404
|
+
return mesh;
|
|
8405
|
+
}
|
|
8406
|
+
|
|
8407
|
+
function createLightPickHandle(nodeId, helperType, color) {
|
|
8408
|
+
return markLightEditorHelper(
|
|
8409
|
+
new Mesh(
|
|
8410
|
+
new SphereGeometry(0.09, 16, 10),
|
|
8411
|
+
new MeshBasicMaterial({
|
|
8412
|
+
color,
|
|
8413
|
+
colorWrite: false,
|
|
8414
|
+
depthWrite: false,
|
|
8415
|
+
}),
|
|
8416
|
+
),
|
|
8417
|
+
nodeId,
|
|
8418
|
+
helperType,
|
|
8419
|
+
'handle',
|
|
8420
|
+
);
|
|
8421
|
+
}
|
|
8422
|
+
|
|
8423
|
+
function createLightCenterDot(nodeId, helperType, color) {
|
|
8424
|
+
return markLightEditorHelper(
|
|
8425
|
+
new Mesh(
|
|
8426
|
+
new SphereGeometry(0.025, 12, 8),
|
|
8427
|
+
new MeshBasicMaterial({ color, depthTest: false, depthWrite: false }),
|
|
8428
|
+
),
|
|
8429
|
+
nodeId,
|
|
8430
|
+
helperType,
|
|
8431
|
+
'visual',
|
|
8432
|
+
);
|
|
8433
|
+
}
|
|
8434
|
+
|
|
8435
|
+
function appendLightOutlineSegment(points, start, end) {
|
|
8436
|
+
points.push(new Vector3(...start), new Vector3(...end));
|
|
8437
|
+
}
|
|
8438
|
+
|
|
8439
|
+
function appendLightOutlineCircle(
|
|
8440
|
+
points,
|
|
8441
|
+
radius,
|
|
8442
|
+
plane = 'xy',
|
|
8443
|
+
center = [0, 0, 0],
|
|
8444
|
+
segments = 24,
|
|
8445
|
+
) {
|
|
8446
|
+
const pointAt = (angle) => {
|
|
8447
|
+
const cosine = Math.cos(angle) * radius;
|
|
8448
|
+
const sine = Math.sin(angle) * radius;
|
|
8449
|
+
if (plane === 'yz') {
|
|
8450
|
+
return [center[0], center[1] + cosine, center[2] + sine];
|
|
8451
|
+
}
|
|
8452
|
+
if (plane === 'xz') {
|
|
8453
|
+
return [center[0] + cosine, center[1], center[2] + sine];
|
|
8454
|
+
}
|
|
8455
|
+
return [center[0] + cosine, center[1] + sine, center[2]];
|
|
8456
|
+
};
|
|
8457
|
+
for (let index = 0; index < segments; index += 1) {
|
|
8458
|
+
appendLightOutlineSegment(
|
|
8459
|
+
points,
|
|
8460
|
+
pointAt((index / segments) * Math.PI * 2),
|
|
8461
|
+
pointAt(((index + 1) / segments) * Math.PI * 2),
|
|
8462
|
+
);
|
|
8463
|
+
}
|
|
8464
|
+
}
|
|
8465
|
+
|
|
8466
|
+
function appendDashedLightOutlineCircle(points, radius, segments) {
|
|
8467
|
+
const ring = Array.from({ length: segments }, (_, index) => {
|
|
8468
|
+
const angle = (index / segments) * Math.PI * 2;
|
|
8469
|
+
return [Math.cos(angle) * radius, Math.sin(angle) * radius, 0];
|
|
8470
|
+
});
|
|
8471
|
+
for (let index = 0; index < segments; index += 2) {
|
|
8472
|
+
appendLightOutlineSegment(points, ring[index], ring[index + 1]);
|
|
8473
|
+
}
|
|
8474
|
+
}
|
|
8475
|
+
|
|
8476
|
+
function appendLightOutlineDiamond(points, radius) {
|
|
8477
|
+
const diamond = [
|
|
8478
|
+
[radius, 0, 0],
|
|
8479
|
+
[0, radius, 0],
|
|
8480
|
+
[-radius, 0, 0],
|
|
8481
|
+
[0, -radius, 0],
|
|
8482
|
+
];
|
|
8483
|
+
for (let index = 0; index < diamond.length; index += 1) {
|
|
8484
|
+
appendLightOutlineSegment(
|
|
8485
|
+
points,
|
|
8486
|
+
diamond[index],
|
|
8487
|
+
diamond[(index + 1) % diamond.length],
|
|
8488
|
+
);
|
|
8489
|
+
}
|
|
8490
|
+
}
|
|
8491
|
+
|
|
8492
|
+
function createLightOutline(
|
|
8493
|
+
nodeId,
|
|
8494
|
+
helperType,
|
|
8495
|
+
color,
|
|
8496
|
+
points,
|
|
8497
|
+
alignment = 'object',
|
|
8498
|
+
) {
|
|
8499
|
+
let material;
|
|
8500
|
+
if (alignment === 'object') {
|
|
8501
|
+
material = new LineBasicMaterial({
|
|
8502
|
+
color,
|
|
8503
|
+
depthTest: false,
|
|
8504
|
+
depthWrite: false,
|
|
8505
|
+
opacity: 0.9,
|
|
8506
|
+
transparent: true,
|
|
8507
|
+
});
|
|
8508
|
+
} else {
|
|
8509
|
+
const screenSpace = alignment === 'screen-space';
|
|
8510
|
+
material = new ShaderMaterial({
|
|
8511
|
+
depthTest: false,
|
|
8512
|
+
depthWrite: false,
|
|
8513
|
+
fragmentShader: \`uniform vec3 outlineColor;
|
|
8514
|
+
void main() { gl_FragColor = vec4(outlineColor, 0.9); }\`,
|
|
8515
|
+
transparent: true,
|
|
8516
|
+
uniforms: {
|
|
8517
|
+
outlineColor: { value: color },
|
|
8518
|
+
viewportSize: { value: new Vector2(1, 1) },
|
|
8519
|
+
},
|
|
8520
|
+
vertexShader: screenSpace
|
|
8521
|
+
? \`uniform vec2 viewportSize;
|
|
8522
|
+
void main() {
|
|
8523
|
+
vec4 center = projectionMatrix * viewMatrix * modelMatrix * vec4(0.0, 0.0, 0.0, 1.0);
|
|
8524
|
+
center.xy += position.xy * 200.0 / viewportSize * center.w;
|
|
8525
|
+
gl_Position = center;
|
|
8526
|
+
}\`
|
|
8527
|
+
: \`void main() {
|
|
8528
|
+
vec3 center = (modelMatrix * vec4(0.0, 0.0, 0.0, 1.0)).xyz;
|
|
8529
|
+
vec3 right = vec3(viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0]);
|
|
8530
|
+
vec3 up = vec3(viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1]);
|
|
8531
|
+
vec3 worldPosition = center + right * position.x + up * position.y;
|
|
8532
|
+
gl_Position = projectionMatrix * viewMatrix * vec4(worldPosition, 1.0);
|
|
8533
|
+
}\`,
|
|
8534
|
+
});
|
|
8535
|
+
}
|
|
8536
|
+
const outline = new LineSegments(
|
|
8537
|
+
new BufferGeometry().setFromPoints(points),
|
|
8538
|
+
material,
|
|
8539
|
+
);
|
|
8540
|
+
if (alignment === 'screen-space') {
|
|
8541
|
+
const viewportSize = material.uniforms.viewportSize.value;
|
|
8542
|
+
outline.onBeforeRender = (renderer) => {
|
|
8543
|
+
renderer.getDrawingBufferSize(viewportSize);
|
|
8544
|
+
};
|
|
8545
|
+
}
|
|
8546
|
+
return markLightEditorHelper(
|
|
8547
|
+
outline,
|
|
8548
|
+
nodeId,
|
|
8549
|
+
helperType,
|
|
8550
|
+
'visual',
|
|
8551
|
+
);
|
|
8552
|
+
}
|
|
8553
|
+
|
|
8554
|
+
function createBlenderLightIcon(nodeId, helperType, color, sunRays = false) {
|
|
8555
|
+
const points = [];
|
|
8556
|
+
appendLightOutlineDiamond(points, 0.027);
|
|
8557
|
+
appendDashedLightOutlineCircle(points, 0.09, 16);
|
|
8558
|
+
appendDashedLightOutlineCircle(points, 0.1197, 20);
|
|
8559
|
+
if (sunRays) {
|
|
8560
|
+
for (let index = 0; index < 8; index += 1) {
|
|
8561
|
+
const angle = (index / 8) * Math.PI * 2;
|
|
8562
|
+
const direction = [Math.cos(angle), Math.sin(angle)];
|
|
8563
|
+
for (const [startScale, endScale] of [
|
|
8564
|
+
[0.144, 0.171],
|
|
8565
|
+
[0.198, 0.225],
|
|
8566
|
+
]) {
|
|
8567
|
+
appendLightOutlineSegment(
|
|
8568
|
+
points,
|
|
8569
|
+
[direction[0] * startScale, direction[1] * startScale, 0],
|
|
8570
|
+
[direction[0] * endScale, direction[1] * endScale, 0],
|
|
8571
|
+
);
|
|
8572
|
+
}
|
|
8573
|
+
}
|
|
8574
|
+
}
|
|
8575
|
+
return createLightOutline(
|
|
8576
|
+
nodeId,
|
|
8577
|
+
helperType,
|
|
8578
|
+
color,
|
|
8579
|
+
points,
|
|
8580
|
+
'screen-space',
|
|
8581
|
+
);
|
|
8582
|
+
}
|
|
8583
|
+
|
|
8584
|
+
function createSpotSilhouette(
|
|
8585
|
+
nodeId,
|
|
8586
|
+
helperType,
|
|
8587
|
+
color,
|
|
8588
|
+
radius,
|
|
8589
|
+
length,
|
|
8590
|
+
segments = 32,
|
|
8591
|
+
) {
|
|
8592
|
+
const positions = [];
|
|
8593
|
+
const adjacentNormalsA = [];
|
|
8594
|
+
const adjacentNormalsB = [];
|
|
8595
|
+
const edgeCenters = [];
|
|
8596
|
+
const angularStep = (Math.PI * 2) / segments;
|
|
8597
|
+
const appendVectorTwice = (target, value) => {
|
|
8598
|
+
target.push(...value, ...value);
|
|
8599
|
+
};
|
|
8600
|
+
const faceNormal = (angle) =>
|
|
8601
|
+
new Vector3(
|
|
8602
|
+
length * Math.cos(angle),
|
|
8603
|
+
length * Math.sin(angle),
|
|
8604
|
+
radius,
|
|
8605
|
+
)
|
|
8606
|
+
.normalize()
|
|
8607
|
+
.toArray();
|
|
8608
|
+
for (let index = 0; index < segments; index += 1) {
|
|
8609
|
+
const angle = index * angularStep;
|
|
8610
|
+
const base = [
|
|
8611
|
+
radius * Math.cos(angle),
|
|
8612
|
+
radius * Math.sin(angle),
|
|
8613
|
+
-length,
|
|
8614
|
+
];
|
|
8615
|
+
positions.push(0, 0, 0, ...base);
|
|
8616
|
+
appendVectorTwice(
|
|
8617
|
+
adjacentNormalsA,
|
|
8618
|
+
faceNormal(angle - angularStep / 2),
|
|
8619
|
+
);
|
|
8620
|
+
appendVectorTwice(
|
|
8621
|
+
adjacentNormalsB,
|
|
8622
|
+
faceNormal(angle + angularStep / 2),
|
|
8623
|
+
);
|
|
8624
|
+
appendVectorTwice(edgeCenters, [base[0] / 2, base[1] / 2, -length / 2]);
|
|
8625
|
+
}
|
|
8626
|
+
const geometry = new BufferGeometry();
|
|
8627
|
+
geometry.setAttribute(
|
|
8628
|
+
'position',
|
|
8629
|
+
new Float32BufferAttribute(positions, 3),
|
|
8630
|
+
);
|
|
8631
|
+
geometry.setAttribute(
|
|
8632
|
+
'adjacentNormalA',
|
|
8633
|
+
new Float32BufferAttribute(adjacentNormalsA, 3),
|
|
8634
|
+
);
|
|
8635
|
+
geometry.setAttribute(
|
|
8636
|
+
'adjacentNormalB',
|
|
8637
|
+
new Float32BufferAttribute(adjacentNormalsB, 3),
|
|
8638
|
+
);
|
|
8639
|
+
geometry.setAttribute(
|
|
8640
|
+
'edgeCenter',
|
|
8641
|
+
new Float32BufferAttribute(edgeCenters, 3),
|
|
8642
|
+
);
|
|
8643
|
+
return markLightEditorHelper(
|
|
8644
|
+
new LineSegments(
|
|
8645
|
+
geometry,
|
|
8646
|
+
new ShaderMaterial({
|
|
8647
|
+
depthTest: false,
|
|
8648
|
+
depthWrite: false,
|
|
8649
|
+
fragmentShader: \`uniform vec3 outlineColor;
|
|
8650
|
+
void main() {
|
|
8651
|
+
gl_FragColor = vec4(outlineColor, 0.9);
|
|
8652
|
+
}\`,
|
|
8653
|
+
transparent: true,
|
|
8654
|
+
uniforms: { outlineColor: { value: color } },
|
|
8655
|
+
vertexShader: \`attribute vec3 adjacentNormalA;
|
|
8656
|
+
attribute vec3 adjacentNormalB;
|
|
8657
|
+
attribute vec3 edgeCenter;
|
|
8658
|
+
void main() {
|
|
8659
|
+
vec3 centerInView = (modelViewMatrix * vec4(edgeCenter, 1.0)).xyz;
|
|
8660
|
+
bool perspective = projectionMatrix[2][3] == -1.0;
|
|
8661
|
+
vec3 viewDirection = perspective ? normalize(-centerInView) : vec3(0.0, 0.0, 1.0);
|
|
8662
|
+
float facingA = dot(normalize(normalMatrix * adjacentNormalA), viewDirection);
|
|
8663
|
+
float facingB = dot(normalize(normalMatrix * adjacentNormalB), viewDirection);
|
|
8664
|
+
vec3 visiblePosition = facingA * facingB <= 0.0 ? position : vec3(0.0);
|
|
8665
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(visiblePosition, 1.0);
|
|
8666
|
+
}\`,
|
|
8667
|
+
}),
|
|
8668
|
+
),
|
|
8669
|
+
nodeId,
|
|
8670
|
+
helperType,
|
|
8671
|
+
'visual',
|
|
8672
|
+
);
|
|
8673
|
+
}
|
|
8674
|
+
|
|
7696
8675
|
function createComponentHelperDecoration(node, helperType) {
|
|
7697
8676
|
const group = new Group();
|
|
7698
8677
|
group.name = node.id + '-' + helperType + '-helper';
|
|
7699
8678
|
group.userData.iwsdkEditorHelper = true;
|
|
7700
8679
|
group.userData.iwsdkEditorHelperType = helperType;
|
|
7701
8680
|
group.userData.iwsdkSceneNodeId = node.id;
|
|
8681
|
+
if (isLightEditorHelperType(helperType)) {
|
|
8682
|
+
group.matrixAutoUpdate = false;
|
|
8683
|
+
group.matrixWorldAutoUpdate = false;
|
|
8684
|
+
group.userData.iwsdkEditorScaleInvariant = true;
|
|
8685
|
+
group.userData.iwsdkEditorWorldPosition = new Vector3();
|
|
8686
|
+
group.userData.iwsdkEditorWorldQuaternion = new Quaternion();
|
|
8687
|
+
group.userData.iwsdkEditorWorldScale = new Vector3(1, 1, 1);
|
|
8688
|
+
}
|
|
7702
8689
|
|
|
7703
8690
|
const lightSpec = Object.entries(node.components || {})
|
|
7704
8691
|
.map(([componentName, value]) =>
|
|
7705
8692
|
lightSpecFromComponentValue(componentName, value),
|
|
7706
8693
|
)
|
|
7707
8694
|
.find(Boolean);
|
|
7708
|
-
const lightColor = new Color(
|
|
7709
|
-
const authoredColor = lightSpec?.color || lightSpec?.skyColor;
|
|
7710
|
-
if (authoredColor) {
|
|
7711
|
-
lightColor.setRGB(authoredColor[0], authoredColor[1], authoredColor[2]);
|
|
7712
|
-
}
|
|
8695
|
+
const lightColor = new Color(0xffa62b);
|
|
7713
8696
|
|
|
7714
8697
|
if (helperType === 'audio-source') {
|
|
7715
8698
|
const body = markOwnedEditorHelper(
|
|
@@ -7737,140 +8720,238 @@ function createComponentHelperDecoration(node, helperType) {
|
|
|
7737
8720
|
wave.position.x = 0.18;
|
|
7738
8721
|
group.add(body, wave);
|
|
7739
8722
|
} else if (helperType === 'camera-source') {
|
|
7740
|
-
const
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
|
|
8723
|
+
const cameraColor = new Color(0xffa62b);
|
|
8724
|
+
const handle = createLightPickHandle(node.id, helperType, cameraColor);
|
|
8725
|
+
const center = createLightCenterDot(node.id, helperType, cameraColor);
|
|
8726
|
+
const points = [];
|
|
8727
|
+
const planeZ = -0.44;
|
|
8728
|
+
const corners = [
|
|
8729
|
+
[-0.22, -0.14, planeZ],
|
|
8730
|
+
[0.22, -0.14, planeZ],
|
|
8731
|
+
[0.22, 0.14, planeZ],
|
|
8732
|
+
[-0.22, 0.14, planeZ],
|
|
8733
|
+
];
|
|
8734
|
+
for (const corner of corners) {
|
|
8735
|
+
appendLightOutlineSegment(points, [0, 0, 0], corner);
|
|
8736
|
+
}
|
|
8737
|
+
for (let index = 0; index < corners.length; index += 1) {
|
|
8738
|
+
appendLightOutlineSegment(
|
|
8739
|
+
points,
|
|
8740
|
+
corners[index],
|
|
8741
|
+
corners[(index + 1) % corners.length],
|
|
8742
|
+
);
|
|
8743
|
+
}
|
|
8744
|
+
const frustum = createLightOutline(
|
|
7745
8745
|
node.id,
|
|
7746
8746
|
helperType,
|
|
8747
|
+
cameraColor,
|
|
8748
|
+
points,
|
|
7747
8749
|
);
|
|
7748
|
-
const
|
|
8750
|
+
const upMarker = markLightEditorHelper(
|
|
7749
8751
|
new Mesh(
|
|
7750
|
-
new
|
|
8752
|
+
new BufferGeometry().setFromPoints([
|
|
8753
|
+
new Vector3(-0.08, 0.16, planeZ),
|
|
8754
|
+
new Vector3(0.08, 0.16, planeZ),
|
|
8755
|
+
new Vector3(0, 0.29, planeZ),
|
|
8756
|
+
new Vector3(0, 0.29, planeZ),
|
|
8757
|
+
new Vector3(0.08, 0.16, planeZ),
|
|
8758
|
+
new Vector3(-0.08, 0.16, planeZ),
|
|
8759
|
+
]),
|
|
7751
8760
|
new MeshBasicMaterial({
|
|
7752
|
-
color:
|
|
7753
|
-
|
|
7754
|
-
|
|
7755
|
-
wireframe: true,
|
|
8761
|
+
color: cameraColor,
|
|
8762
|
+
depthTest: false,
|
|
8763
|
+
depthWrite: false,
|
|
7756
8764
|
}),
|
|
7757
8765
|
),
|
|
7758
8766
|
node.id,
|
|
7759
8767
|
helperType,
|
|
8768
|
+
'visual',
|
|
7760
8769
|
);
|
|
7761
|
-
|
|
7762
|
-
frustum.position.z = -0.24;
|
|
7763
|
-
group.add(body, frustum);
|
|
8770
|
+
group.add(handle, center, frustum, upMarker);
|
|
7764
8771
|
} else if (helperType === 'point-light') {
|
|
7765
|
-
const
|
|
7766
|
-
const
|
|
7767
|
-
const
|
|
7768
|
-
|
|
7769
|
-
|
|
7770
|
-
|
|
7771
|
-
color: lightColor,
|
|
7772
|
-
opacity: distance > 0 ? 0.22 : 0.68,
|
|
7773
|
-
transparent: true,
|
|
7774
|
-
wireframe: true,
|
|
7775
|
-
}),
|
|
7776
|
-
),
|
|
8772
|
+
const handle = createLightPickHandle(node.id, helperType, lightColor);
|
|
8773
|
+
const center = createLightCenterDot(node.id, helperType, lightColor);
|
|
8774
|
+
const icon = createBlenderLightIcon(node.id, helperType, lightColor);
|
|
8775
|
+
const points = [];
|
|
8776
|
+
appendLightOutlineCircle(points, 0.13, 'xy', [0, 0, 0], 32);
|
|
8777
|
+
const symbol = createLightOutline(
|
|
7777
8778
|
node.id,
|
|
7778
8779
|
helperType,
|
|
8780
|
+
lightColor,
|
|
8781
|
+
points,
|
|
8782
|
+
'screen-aligned',
|
|
7779
8783
|
);
|
|
7780
|
-
group.add(
|
|
8784
|
+
group.add(handle, center, icon, symbol);
|
|
7781
8785
|
} else if (helperType === 'spot-light') {
|
|
7782
|
-
const
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
8786
|
+
const handle = createLightPickHandle(node.id, helperType, lightColor);
|
|
8787
|
+
const center = createLightCenterDot(node.id, helperType, lightColor);
|
|
8788
|
+
const icon = createBlenderLightIcon(node.id, helperType, lightColor);
|
|
8789
|
+
const emitterPoints = [];
|
|
8790
|
+
appendLightOutlineCircle(emitterPoints, 0.07, 'xy', [0, 0, 0], 32);
|
|
8791
|
+
const emitter = createLightOutline(
|
|
8792
|
+
node.id,
|
|
8793
|
+
helperType,
|
|
8794
|
+
lightColor,
|
|
8795
|
+
emitterPoints,
|
|
8796
|
+
'screen-aligned',
|
|
8797
|
+
);
|
|
8798
|
+
const length = 0.5;
|
|
7786
8799
|
const angleDeg = lightSpec?.kind === 'spot' ? lightSpec.angleDeg : 60;
|
|
7787
|
-
const radius =
|
|
7788
|
-
|
|
7789
|
-
|
|
8800
|
+
const radius = MathUtils.clamp(
|
|
8801
|
+
Math.tan(MathUtils.degToRad(MathUtils.clamp(angleDeg, 5, 70))) * length,
|
|
8802
|
+
0.08,
|
|
8803
|
+
0.26,
|
|
7790
8804
|
);
|
|
7791
|
-
const
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
|
|
7797
|
-
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
|
|
8805
|
+
const points = [];
|
|
8806
|
+
appendLightOutlineCircle(points, radius, 'xy', [0, 0, -length], 24);
|
|
8807
|
+
appendLightOutlineCircle(
|
|
8808
|
+
points,
|
|
8809
|
+
radius * 0.86,
|
|
8810
|
+
'xy',
|
|
8811
|
+
[0, 0, -length],
|
|
8812
|
+
24,
|
|
8813
|
+
);
|
|
8814
|
+
appendLightOutlineSegment(points, [0, 0, 0], [0, 0, -length]);
|
|
8815
|
+
const coneOutline = createLightOutline(
|
|
7801
8816
|
node.id,
|
|
7802
8817
|
helperType,
|
|
8818
|
+
lightColor,
|
|
8819
|
+
points,
|
|
7803
8820
|
);
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
|
|
8821
|
+
const coneSilhouette = createSpotSilhouette(
|
|
8822
|
+
node.id,
|
|
8823
|
+
helperType,
|
|
8824
|
+
lightColor,
|
|
8825
|
+
radius,
|
|
8826
|
+
length,
|
|
8827
|
+
);
|
|
8828
|
+
group.add(handle, center, icon, emitter, coneOutline, coneSilhouette);
|
|
7807
8829
|
} else if (helperType === 'directional-light') {
|
|
7808
|
-
const
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
|
|
8830
|
+
const handle = createLightPickHandle(node.id, helperType, lightColor);
|
|
8831
|
+
const center = createLightCenterDot(node.id, helperType, lightColor);
|
|
8832
|
+
const icon = createBlenderLightIcon(node.id, helperType, lightColor, true);
|
|
8833
|
+
const points = [];
|
|
8834
|
+
appendLightOutlineSegment(points, [0, 0, 0], [0, 0, -0.46]);
|
|
8835
|
+
const direction = createLightOutline(
|
|
7813
8836
|
node.id,
|
|
7814
8837
|
helperType,
|
|
8838
|
+
lightColor,
|
|
8839
|
+
points,
|
|
7815
8840
|
);
|
|
7816
|
-
|
|
7817
|
-
|
|
7818
|
-
const
|
|
7819
|
-
new Mesh(
|
|
7820
|
-
new ConeGeometry(0.1, 0.2, 16),
|
|
7821
|
-
new MeshBasicMaterial({ color: lightColor }),
|
|
7822
|
-
),
|
|
8841
|
+
const endpointPoints = [];
|
|
8842
|
+
appendLightOutlineDiamond(endpointPoints, 0.022);
|
|
8843
|
+
const endpoint = createLightOutline(
|
|
7823
8844
|
node.id,
|
|
7824
8845
|
helperType,
|
|
8846
|
+
lightColor,
|
|
8847
|
+
endpointPoints,
|
|
8848
|
+
'screen-space',
|
|
7825
8849
|
);
|
|
7826
|
-
|
|
7827
|
-
|
|
7828
|
-
group.add(shaft, head);
|
|
8850
|
+
endpoint.position.z = -0.46;
|
|
8851
|
+
group.add(handle, center, icon, direction, endpoint);
|
|
7829
8852
|
} else if (helperType === 'rect-area-light') {
|
|
7830
|
-
const
|
|
7831
|
-
const
|
|
7832
|
-
const
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
|
|
7838
|
-
|
|
7839
|
-
|
|
7840
|
-
|
|
7841
|
-
|
|
8853
|
+
const authoredWidth = lightSpec?.kind === 'rect-area' ? lightSpec.width : 0.48;
|
|
8854
|
+
const authoredHeight = lightSpec?.kind === 'rect-area' ? lightSpec.height : 0.32;
|
|
8855
|
+
const fitScale = Math.min(
|
|
8856
|
+
1,
|
|
8857
|
+
0.42 / Math.max(Math.abs(authoredWidth), Math.abs(authoredHeight), 0.01),
|
|
8858
|
+
);
|
|
8859
|
+
const width = Math.max(0.12, Math.abs(authoredWidth) * fitScale);
|
|
8860
|
+
const height = Math.max(0.08, Math.abs(authoredHeight) * fitScale);
|
|
8861
|
+
const handle = createLightPickHandle(node.id, helperType, lightColor);
|
|
8862
|
+
const center = createLightCenterDot(node.id, helperType, lightColor);
|
|
8863
|
+
const icon = createBlenderLightIcon(node.id, helperType, lightColor);
|
|
8864
|
+
const points = [];
|
|
8865
|
+
const corners = [
|
|
8866
|
+
[-width / 2, -height / 2, 0],
|
|
8867
|
+
[width / 2, -height / 2, 0],
|
|
8868
|
+
[width / 2, height / 2, 0],
|
|
8869
|
+
[-width / 2, height / 2, 0],
|
|
8870
|
+
];
|
|
8871
|
+
for (let index = 0; index < corners.length; index += 1) {
|
|
8872
|
+
appendLightOutlineSegment(
|
|
8873
|
+
points,
|
|
8874
|
+
corners[index],
|
|
8875
|
+
corners[(index + 1) % corners.length],
|
|
8876
|
+
);
|
|
8877
|
+
}
|
|
8878
|
+
appendLightOutlineSegment(points, [0, 0, 0], [0, 0, -0.44]);
|
|
8879
|
+
const panel = createLightOutline(
|
|
7842
8880
|
node.id,
|
|
7843
8881
|
helperType,
|
|
8882
|
+
lightColor,
|
|
8883
|
+
points,
|
|
7844
8884
|
);
|
|
7845
|
-
|
|
7846
|
-
|
|
7847
|
-
const
|
|
7848
|
-
new Mesh(
|
|
7849
|
-
new CylinderGeometry(0.14, 0.14, 0.06, 24),
|
|
7850
|
-
new MeshBasicMaterial({ color: 0xa8ff78, opacity: 0.85, transparent: true }),
|
|
7851
|
-
),
|
|
8885
|
+
const endpointPoints = [];
|
|
8886
|
+
appendLightOutlineDiamond(endpointPoints, 0.022);
|
|
8887
|
+
const endpoint = createLightOutline(
|
|
7852
8888
|
node.id,
|
|
7853
8889
|
helperType,
|
|
8890
|
+
lightColor,
|
|
8891
|
+
endpointPoints,
|
|
8892
|
+
'screen-space',
|
|
7854
8893
|
);
|
|
7855
|
-
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7863
|
-
|
|
7864
|
-
),
|
|
8894
|
+
endpoint.position.z = -0.44;
|
|
8895
|
+
group.add(handle, center, icon, panel, endpoint);
|
|
8896
|
+
} else {
|
|
8897
|
+
const handle = createLightPickHandle(node.id, helperType, lightColor);
|
|
8898
|
+
const center = createLightCenterDot(node.id, helperType, lightColor);
|
|
8899
|
+
const points = [];
|
|
8900
|
+
appendLightOutlineCircle(points, 0.17, 'xy', [0, 0, 0], 24);
|
|
8901
|
+
appendLightOutlineCircle(points, 0.17, 'xz', [0, 0, 0], 24);
|
|
8902
|
+
const halo = createLightOutline(
|
|
7865
8903
|
node.id,
|
|
7866
8904
|
helperType,
|
|
8905
|
+
lightColor,
|
|
8906
|
+
points,
|
|
7867
8907
|
);
|
|
7868
|
-
|
|
7869
|
-
group.add(core, halo);
|
|
8908
|
+
group.add(handle, center, halo);
|
|
7870
8909
|
}
|
|
7871
8910
|
return group;
|
|
7872
8911
|
}
|
|
7873
8912
|
|
|
8913
|
+
function componentHelperProof(nodeId) {
|
|
8914
|
+
syncEditorLightHelperTransforms();
|
|
8915
|
+
const object = editorWorldState?.objectMap.get(nodeId);
|
|
8916
|
+
const helper = object?.children.find(
|
|
8917
|
+
(child) =>
|
|
8918
|
+
child.userData?.iwsdkEditorHelper === true &&
|
|
8919
|
+
typeof child.userData?.iwsdkEditorHelperType === 'string',
|
|
8920
|
+
);
|
|
8921
|
+
if (!helper) {
|
|
8922
|
+
return null;
|
|
8923
|
+
}
|
|
8924
|
+
helper.updateMatrixWorld(true);
|
|
8925
|
+
const bounds = new Box3().setFromObject(helper);
|
|
8926
|
+
const size = new Vector3();
|
|
8927
|
+
if (!bounds.isEmpty()) {
|
|
8928
|
+
bounds.getSize(size);
|
|
8929
|
+
}
|
|
8930
|
+
const meshes = [];
|
|
8931
|
+
helper.traverse((entry) => {
|
|
8932
|
+
if (!entry.isMesh && !entry.isLine) {
|
|
8933
|
+
return;
|
|
8934
|
+
}
|
|
8935
|
+
meshes.push({
|
|
8936
|
+
color:
|
|
8937
|
+
entry.material?.color?.getHexString?.() ||
|
|
8938
|
+
entry.material?.uniforms?.outlineColor?.value?.getHexString?.() ||
|
|
8939
|
+
null,
|
|
8940
|
+
geometry: entry.geometry?.type || null,
|
|
8941
|
+
kind: entry.isLine ? 'line' : 'mesh',
|
|
8942
|
+
material: entry.material?.type || null,
|
|
8943
|
+
pickable: entry.userData?.iwsdkEditorPickable !== false,
|
|
8944
|
+
role: entry.userData?.iwsdkEditorLightRole || null,
|
|
8945
|
+
vertexCount: entry.geometry?.attributes?.position?.count || 0,
|
|
8946
|
+
});
|
|
8947
|
+
});
|
|
8948
|
+
return {
|
|
8949
|
+
helperType: helper.userData.iwsdkEditorHelperType,
|
|
8950
|
+
meshes,
|
|
8951
|
+
size: roundVec3(size.toArray()),
|
|
8952
|
+
};
|
|
8953
|
+
}
|
|
8954
|
+
|
|
7874
8955
|
async function waitForAssetLoads() {
|
|
7875
8956
|
if (!editorWorldState) {
|
|
7876
8957
|
return;
|
|
@@ -8180,6 +9261,25 @@ function syncEditorLightBindings() {
|
|
|
8180
9261
|
}
|
|
8181
9262
|
}
|
|
8182
9263
|
|
|
9264
|
+
function syncEditorLightHelperTransforms() {
|
|
9265
|
+
if (!editorWorldState?.objectMap) return;
|
|
9266
|
+
for (const object of editorWorldState.objectMap.values()) {
|
|
9267
|
+
const helper = object.children.find(
|
|
9268
|
+
(child) => child.userData?.iwsdkEditorScaleInvariant === true,
|
|
9269
|
+
);
|
|
9270
|
+
if (!helper) continue;
|
|
9271
|
+
object.updateWorldMatrix(true, false);
|
|
9272
|
+
const position = helper.userData.iwsdkEditorWorldPosition;
|
|
9273
|
+
const quaternion = helper.userData.iwsdkEditorWorldQuaternion;
|
|
9274
|
+
const scale = helper.userData.iwsdkEditorWorldScale;
|
|
9275
|
+
object.getWorldPosition(position);
|
|
9276
|
+
object.getWorldQuaternion(quaternion);
|
|
9277
|
+
helper.matrixWorld.compose(position, quaternion, scale);
|
|
9278
|
+
helper.matrixWorldNeedsUpdate = false;
|
|
9279
|
+
helper.updateWorldMatrix(false, true);
|
|
9280
|
+
}
|
|
9281
|
+
}
|
|
9282
|
+
|
|
8183
9283
|
function runtimeComponentForSceneName(componentName) {
|
|
8184
9284
|
const componentId = stripComponentPrefix(componentName);
|
|
8185
9285
|
const targetId = componentId === 'Interactable' ? 'RayInteractable' : componentId;
|
|
@@ -8721,7 +9821,20 @@ function boundsForObjectWithoutEditorHelpers(object) {
|
|
|
8721
9821
|
return fallbackBounds.isEmpty() ? null : fallbackBounds;
|
|
8722
9822
|
}
|
|
8723
9823
|
|
|
9824
|
+
function isLightEditorHelperType(helperType) {
|
|
9825
|
+
return (
|
|
9826
|
+
helperType === 'directional-light' ||
|
|
9827
|
+
helperType === 'environment-light' ||
|
|
9828
|
+
helperType === 'point-light' ||
|
|
9829
|
+
helperType === 'rect-area-light' ||
|
|
9830
|
+
helperType === 'spot-light'
|
|
9831
|
+
);
|
|
9832
|
+
}
|
|
9833
|
+
|
|
8724
9834
|
function createEditorBoundsHelper(object, color) {
|
|
9835
|
+
if (isLightEditorHelperType(object.userData?.iwsdkEditorHelperType)) {
|
|
9836
|
+
return null;
|
|
9837
|
+
}
|
|
8725
9838
|
const bounds = boundsForObjectWithoutEditorHelpers(object);
|
|
8726
9839
|
if (!bounds) {
|
|
8727
9840
|
return null;
|
|
@@ -8971,6 +10084,8 @@ function renderEditorWorld() {
|
|
|
8971
10084
|
}
|
|
8972
10085
|
hideCurrentEditorHelpersForRenderOnlyCapture();
|
|
8973
10086
|
syncEditorLightBindings();
|
|
10087
|
+
syncEditorLightHelperTransforms();
|
|
10088
|
+
syncInfiniteEditorGrid();
|
|
8974
10089
|
const startedAt = performance.now();
|
|
8975
10090
|
editorWorldState.world.renderer.render(
|
|
8976
10091
|
editorWorldState.world.scene,
|
|
@@ -9649,6 +10764,42 @@ function selectedBuiltinTarget() {
|
|
|
9649
10764
|
return target === 'player' ? target : null;
|
|
9650
10765
|
}
|
|
9651
10766
|
|
|
10767
|
+
function lightScaleTarget(node) {
|
|
10768
|
+
if (!node || node.content != null) {
|
|
10769
|
+
return null;
|
|
10770
|
+
}
|
|
10771
|
+
for (const [component, value] of Object.entries(node.components || {})) {
|
|
10772
|
+
const spec = lightSpecFromComponentValue(component, value);
|
|
10773
|
+
if (spec) {
|
|
10774
|
+
return { component, spec, value };
|
|
10775
|
+
}
|
|
10776
|
+
}
|
|
10777
|
+
return null;
|
|
10778
|
+
}
|
|
10779
|
+
|
|
10780
|
+
function lightScaleAxisPolicy(node) {
|
|
10781
|
+
const target = lightScaleTarget(node);
|
|
10782
|
+
if (!target) return null;
|
|
10783
|
+
switch (target.spec.kind) {
|
|
10784
|
+
case 'point':
|
|
10785
|
+
return {
|
|
10786
|
+
x: target.spec.distance > 0,
|
|
10787
|
+
y: target.spec.distance > 0,
|
|
10788
|
+
z: target.spec.distance > 0,
|
|
10789
|
+
};
|
|
10790
|
+
case 'spot':
|
|
10791
|
+
return {
|
|
10792
|
+
x: true,
|
|
10793
|
+
y: true,
|
|
10794
|
+
z: target.spec.distance > 0,
|
|
10795
|
+
};
|
|
10796
|
+
case 'rect-area':
|
|
10797
|
+
return { x: true, y: true, z: false };
|
|
10798
|
+
default:
|
|
10799
|
+
return { x: false, y: false, z: false };
|
|
10800
|
+
}
|
|
10801
|
+
}
|
|
10802
|
+
|
|
9652
10803
|
function selectionForNodeClick(nodeId, event) {
|
|
9653
10804
|
const currentSelection = Array.isArray(window.__IWSDK_EDITOR_SELECTION)
|
|
9654
10805
|
? window.__IWSDK_EDITOR_SELECTION
|
|
@@ -9671,6 +10822,14 @@ function applyTransformControlSettings() {
|
|
|
9671
10822
|
const transformControls = editorWorldState.transformControls;
|
|
9672
10823
|
transformControls.setMode(mode);
|
|
9673
10824
|
transformControls.setSpace(space);
|
|
10825
|
+
const nodeId = selectedNodeId();
|
|
10826
|
+
const node = nodeId
|
|
10827
|
+
? findNodeById(editorWorldState.currentSession?.document, nodeId)
|
|
10828
|
+
: null;
|
|
10829
|
+
const lightPolicy = mode === 'scale' ? lightScaleAxisPolicy(node) : null;
|
|
10830
|
+
transformControls.showX = lightPolicy?.x ?? true;
|
|
10831
|
+
transformControls.showY = lightPolicy?.y ?? true;
|
|
10832
|
+
transformControls.showZ = lightPolicy?.z ?? true;
|
|
9674
10833
|
const snap = editorWorldState.transformSnapEnabled
|
|
9675
10834
|
? editorWorldState.transformSnap
|
|
9676
10835
|
: null;
|
|
@@ -9713,6 +10872,119 @@ function setTransformControlSnap(transformControls, method, property, value) {
|
|
|
9713
10872
|
}
|
|
9714
10873
|
}
|
|
9715
10874
|
|
|
10875
|
+
function scaleRatio(startTransform, nextTransform) {
|
|
10876
|
+
const start = scaleVectorFromTransform(startTransform);
|
|
10877
|
+
const next = scaleVectorFromTransform(nextTransform);
|
|
10878
|
+
return start.map((value, index) =>
|
|
10879
|
+
Math.max(
|
|
10880
|
+
0.001,
|
|
10881
|
+
Math.abs(value) > 1e-6 ? Math.abs(next[index] / value) : 1,
|
|
10882
|
+
),
|
|
10883
|
+
);
|
|
10884
|
+
}
|
|
10885
|
+
|
|
10886
|
+
function inferredScaleAxis(ratio) {
|
|
10887
|
+
const changed = ['X', 'Y', 'Z'].filter(
|
|
10888
|
+
(_axis, index) => Math.abs(ratio[index] - 1) > 1e-4,
|
|
10889
|
+
);
|
|
10890
|
+
if (
|
|
10891
|
+
changed.length === 3 &&
|
|
10892
|
+
Math.abs(ratio[0] - ratio[1]) < 1e-4 &&
|
|
10893
|
+
Math.abs(ratio[1] - ratio[2]) < 1e-4
|
|
10894
|
+
) {
|
|
10895
|
+
return 'XYZ';
|
|
10896
|
+
}
|
|
10897
|
+
return changed.join('');
|
|
10898
|
+
}
|
|
10899
|
+
|
|
10900
|
+
function combinedScaleFactor(ratio, axis) {
|
|
10901
|
+
const indices = ['X', 'Y', 'Z']
|
|
10902
|
+
.map((name, index) => (axis.includes(name) ? index : -1))
|
|
10903
|
+
.filter((index) => index >= 0);
|
|
10904
|
+
if (indices.length === 0) return 1;
|
|
10905
|
+
return Math.pow(
|
|
10906
|
+
indices.reduce((product, index) => product * ratio[index], 1),
|
|
10907
|
+
1 / indices.length,
|
|
10908
|
+
);
|
|
10909
|
+
}
|
|
10910
|
+
|
|
10911
|
+
function roundedLightProperty(value) {
|
|
10912
|
+
return Number(value.toFixed(4));
|
|
10913
|
+
}
|
|
10914
|
+
|
|
10915
|
+
function lightPropertyScaleEdit(node, startTransform, nextTransform, scaleAxis) {
|
|
10916
|
+
const target = lightScaleTarget(node);
|
|
10917
|
+
if (!target) return null;
|
|
10918
|
+
const ratio = scaleRatio(startTransform, nextTransform);
|
|
10919
|
+
const axis = scaleAxis || inferredScaleAxis(ratio);
|
|
10920
|
+
const value = { ...target.value };
|
|
10921
|
+
let changed = false;
|
|
10922
|
+
switch (target.spec.kind) {
|
|
10923
|
+
case 'point': {
|
|
10924
|
+
if (target.spec.distance <= 0) break;
|
|
10925
|
+
const factor = combinedScaleFactor(ratio, axis || 'XYZ');
|
|
10926
|
+
value.distance = roundedLightProperty(
|
|
10927
|
+
Math.max(0.001, target.spec.distance * factor),
|
|
10928
|
+
);
|
|
10929
|
+
changed = value.distance !== target.spec.distance;
|
|
10930
|
+
break;
|
|
10931
|
+
}
|
|
10932
|
+
case 'spot': {
|
|
10933
|
+
if (axis !== 'XYZ' && (axis.includes('X') || axis.includes('Y'))) {
|
|
10934
|
+
const radialAxis = ['X', 'Y'].filter((name) => axis.includes(name)).join('');
|
|
10935
|
+
const radialFactor = combinedScaleFactor(ratio, radialAxis);
|
|
10936
|
+
value.angleDeg = roundedLightProperty(
|
|
10937
|
+
MathUtils.clamp(
|
|
10938
|
+
MathUtils.radToDeg(
|
|
10939
|
+
Math.atan(
|
|
10940
|
+
Math.tan(MathUtils.degToRad(target.spec.angleDeg)) *
|
|
10941
|
+
radialFactor,
|
|
10942
|
+
),
|
|
10943
|
+
),
|
|
10944
|
+
0.1,
|
|
10945
|
+
90,
|
|
10946
|
+
),
|
|
10947
|
+
);
|
|
10948
|
+
changed = value.angleDeg !== target.spec.angleDeg;
|
|
10949
|
+
}
|
|
10950
|
+
if (axis.includes('Z') && target.spec.distance > 0) {
|
|
10951
|
+
value.distance = roundedLightProperty(
|
|
10952
|
+
Math.max(0.001, target.spec.distance * ratio[2]),
|
|
10953
|
+
);
|
|
10954
|
+
changed = changed || value.distance !== target.spec.distance;
|
|
10955
|
+
}
|
|
10956
|
+
break;
|
|
10957
|
+
}
|
|
10958
|
+
case 'rect-area': {
|
|
10959
|
+
if (axis.includes('X')) {
|
|
10960
|
+
value.width = roundedLightProperty(
|
|
10961
|
+
Math.max(0.001, target.spec.width * ratio[0]),
|
|
10962
|
+
);
|
|
10963
|
+
changed = value.width !== target.spec.width;
|
|
10964
|
+
}
|
|
10965
|
+
if (axis.includes('Y')) {
|
|
10966
|
+
value.height = roundedLightProperty(
|
|
10967
|
+
Math.max(0.001, target.spec.height * ratio[1]),
|
|
10968
|
+
);
|
|
10969
|
+
changed = changed || value.height !== target.spec.height;
|
|
10970
|
+
}
|
|
10971
|
+
break;
|
|
10972
|
+
}
|
|
10973
|
+
}
|
|
10974
|
+
return {
|
|
10975
|
+
changed,
|
|
10976
|
+
patch: changed
|
|
10977
|
+
? {
|
|
10978
|
+
component: target.component,
|
|
10979
|
+
nodeId: node.id,
|
|
10980
|
+
op: 'updateComponent',
|
|
10981
|
+
value,
|
|
10982
|
+
}
|
|
10983
|
+
: null,
|
|
10984
|
+
policy: target.spec.kind,
|
|
10985
|
+
};
|
|
10986
|
+
}
|
|
10987
|
+
|
|
9716
10988
|
function renderTransformToolbar() {
|
|
9717
10989
|
const mode = editorWorldState?.transformMode || 'translate';
|
|
9718
10990
|
const space = editorWorldState?.transformSpace || 'local';
|
|
@@ -9741,6 +11013,7 @@ function setTransformMode(mode) {
|
|
|
9741
11013
|
if (editorWorldState) {
|
|
9742
11014
|
editorWorldState.transformMode = mode;
|
|
9743
11015
|
applyTransformControlSettings();
|
|
11016
|
+
workspaceUi?.update({ transformMode: mode });
|
|
9744
11017
|
renderEditorWorld();
|
|
9745
11018
|
}
|
|
9746
11019
|
renderTransformToolbar();
|
|
@@ -9758,6 +11031,46 @@ function setTransformSpace(space) {
|
|
|
9758
11031
|
renderTransformToolbar();
|
|
9759
11032
|
}
|
|
9760
11033
|
|
|
11034
|
+
function transformSnapPropertyForMode(mode) {
|
|
11035
|
+
if (mode === 'rotate') {
|
|
11036
|
+
return 'rotationDeg';
|
|
11037
|
+
}
|
|
11038
|
+
if (mode === 'scale') {
|
|
11039
|
+
return 'scale';
|
|
11040
|
+
}
|
|
11041
|
+
return 'translation';
|
|
11042
|
+
}
|
|
11043
|
+
|
|
11044
|
+
function setTransformSnapValue(mode, value, persist = true) {
|
|
11045
|
+
if (!editorWorldState) {
|
|
11046
|
+
return null;
|
|
11047
|
+
}
|
|
11048
|
+
const property = transformSnapPropertyForMode(mode);
|
|
11049
|
+
const nextValue = normalizeEditorTransformSnapValue(property, value);
|
|
11050
|
+
editorWorldState.transformSnap = {
|
|
11051
|
+
...editorWorldState.transformSnap,
|
|
11052
|
+
[property]: nextValue,
|
|
11053
|
+
};
|
|
11054
|
+
applyTransformControlSettings();
|
|
11055
|
+
if (persist && typeof localStorage !== 'undefined') {
|
|
11056
|
+
try {
|
|
11057
|
+
localStorage.setItem(
|
|
11058
|
+
EDITOR_TRANSFORM_SNAP_STORAGE_KEY,
|
|
11059
|
+
JSON.stringify(editorWorldState.transformSnap),
|
|
11060
|
+
);
|
|
11061
|
+
} catch {
|
|
11062
|
+
// The snap settings still apply when browser storage is unavailable.
|
|
11063
|
+
}
|
|
11064
|
+
}
|
|
11065
|
+
workspaceUi?.update({
|
|
11066
|
+
transformSnapRotationDeg: editorWorldState.transformSnap.rotationDeg,
|
|
11067
|
+
transformSnapScale: editorWorldState.transformSnap.scale,
|
|
11068
|
+
transformSnapTranslation: editorWorldState.transformSnap.translation,
|
|
11069
|
+
});
|
|
11070
|
+
renderEditorWorld();
|
|
11071
|
+
return nextValue;
|
|
11072
|
+
}
|
|
11073
|
+
|
|
9761
11074
|
function setTransformSnapEnabled(enabled) {
|
|
9762
11075
|
if (editorWorldState) {
|
|
9763
11076
|
editorWorldState.transformSnapEnabled = Boolean(enabled);
|
|
@@ -9845,6 +11158,28 @@ async function commitTransformControlDrag(session, rerender) {
|
|
|
9845
11158
|
const nextTransform = snapTransformForCurrentMode(
|
|
9846
11159
|
transformFromObject(object, node.transform || {}),
|
|
9847
11160
|
);
|
|
11161
|
+
const lightScaleEdit =
|
|
11162
|
+
dragState.mode === 'scale'
|
|
11163
|
+
? lightPropertyScaleEdit(
|
|
11164
|
+
node,
|
|
11165
|
+
dragState.startTransform,
|
|
11166
|
+
nextTransform,
|
|
11167
|
+
dragState.scaleAxis,
|
|
11168
|
+
)
|
|
11169
|
+
: null;
|
|
11170
|
+
if (lightScaleEdit) {
|
|
11171
|
+
applyNodeTransform(object, dragState.startTransform);
|
|
11172
|
+
updateSelectionHelpers();
|
|
11173
|
+
renderEditorWorld();
|
|
11174
|
+
if (lightScaleEdit.patch) {
|
|
11175
|
+
await session.dispatch('scene_apply_patch', {
|
|
11176
|
+
patch: lightScaleEdit.patch,
|
|
11177
|
+
});
|
|
11178
|
+
clearValidationResult();
|
|
11179
|
+
}
|
|
11180
|
+
rerender();
|
|
11181
|
+
return;
|
|
11182
|
+
}
|
|
9848
11183
|
applyNodeTransform(object, nextTransform);
|
|
9849
11184
|
updateSelectionHelpers();
|
|
9850
11185
|
renderEditorWorld();
|
|
@@ -9988,6 +11323,193 @@ function syncEditorWorld(session, camera, size = {}) {
|
|
|
9988
11323
|
updateProjectedHitTargets(session);
|
|
9989
11324
|
}
|
|
9990
11325
|
|
|
11326
|
+
function normalizeEditorDrawDistance(value) {
|
|
11327
|
+
if (value == null || value === '') {
|
|
11328
|
+
return DEFAULT_EDITOR_DRAW_DISTANCE;
|
|
11329
|
+
}
|
|
11330
|
+
const numeric = Number(value);
|
|
11331
|
+
if (!Number.isFinite(numeric)) {
|
|
11332
|
+
return DEFAULT_EDITOR_DRAW_DISTANCE;
|
|
11333
|
+
}
|
|
11334
|
+
return Math.round(
|
|
11335
|
+
MathUtils.clamp(
|
|
11336
|
+
numeric,
|
|
11337
|
+
MIN_EDITOR_DRAW_DISTANCE,
|
|
11338
|
+
MAX_EDITOR_DRAW_DISTANCE,
|
|
11339
|
+
),
|
|
11340
|
+
);
|
|
11341
|
+
}
|
|
11342
|
+
|
|
11343
|
+
function loadEditorDrawDistance() {
|
|
11344
|
+
if (typeof localStorage === 'undefined') {
|
|
11345
|
+
return DEFAULT_EDITOR_DRAW_DISTANCE;
|
|
11346
|
+
}
|
|
11347
|
+
try {
|
|
11348
|
+
return normalizeEditorDrawDistance(
|
|
11349
|
+
localStorage.getItem(EDITOR_DRAW_DISTANCE_STORAGE_KEY),
|
|
11350
|
+
);
|
|
11351
|
+
} catch {
|
|
11352
|
+
return DEFAULT_EDITOR_DRAW_DISTANCE;
|
|
11353
|
+
}
|
|
11354
|
+
}
|
|
11355
|
+
|
|
11356
|
+
function normalizeEditorTransformSnapValue(property, value) {
|
|
11357
|
+
const fallback = DEFAULT_EDITOR_TRANSFORM_SNAP[property];
|
|
11358
|
+
const limits = EDITOR_TRANSFORM_SNAP_LIMITS[property];
|
|
11359
|
+
const numeric = Number(value);
|
|
11360
|
+
if (!limits || !Number.isFinite(numeric)) {
|
|
11361
|
+
return fallback;
|
|
11362
|
+
}
|
|
11363
|
+
return Number(
|
|
11364
|
+
MathUtils.clamp(numeric, limits.min, limits.max).toFixed(6),
|
|
11365
|
+
);
|
|
11366
|
+
}
|
|
11367
|
+
|
|
11368
|
+
function normalizeEditorTransformSnap(value) {
|
|
11369
|
+
const candidate = value && typeof value === 'object' ? value : {};
|
|
11370
|
+
return {
|
|
11371
|
+
rotationDeg: normalizeEditorTransformSnapValue(
|
|
11372
|
+
'rotationDeg',
|
|
11373
|
+
candidate.rotationDeg,
|
|
11374
|
+
),
|
|
11375
|
+
scale: normalizeEditorTransformSnapValue('scale', candidate.scale),
|
|
11376
|
+
translation: normalizeEditorTransformSnapValue(
|
|
11377
|
+
'translation',
|
|
11378
|
+
candidate.translation,
|
|
11379
|
+
),
|
|
11380
|
+
};
|
|
11381
|
+
}
|
|
11382
|
+
|
|
11383
|
+
function loadEditorTransformSnap() {
|
|
11384
|
+
if (typeof localStorage === 'undefined') {
|
|
11385
|
+
return { ...DEFAULT_EDITOR_TRANSFORM_SNAP };
|
|
11386
|
+
}
|
|
11387
|
+
try {
|
|
11388
|
+
const stored = localStorage.getItem(EDITOR_TRANSFORM_SNAP_STORAGE_KEY);
|
|
11389
|
+
return normalizeEditorTransformSnap(stored ? JSON.parse(stored) : null);
|
|
11390
|
+
} catch {
|
|
11391
|
+
return { ...DEFAULT_EDITOR_TRANSFORM_SNAP };
|
|
11392
|
+
}
|
|
11393
|
+
}
|
|
11394
|
+
|
|
11395
|
+
function createInfiniteEditorGrid(drawDistance) {
|
|
11396
|
+
const material = new ShaderMaterial({
|
|
11397
|
+
depthTest: true,
|
|
11398
|
+
depthWrite: false,
|
|
11399
|
+
extensions: { derivatives: true },
|
|
11400
|
+
fragmentShader:
|
|
11401
|
+
'varying vec3 gridWorldPosition; ' +
|
|
11402
|
+
'uniform float drawDistance; ' +
|
|
11403
|
+
'uniform float minimumGridSpacing; ' +
|
|
11404
|
+
'uniform bool perspectiveView; ' +
|
|
11405
|
+
'float gridLine(vec2 position, float scale) { ' +
|
|
11406
|
+
' vec2 coordinate = position / scale; ' +
|
|
11407
|
+
' vec2 width = max(fwidth(coordinate), vec2(0.0001)); ' +
|
|
11408
|
+
' vec2 lineDistance = abs(fract(coordinate - 0.5) - 0.5) / width; ' +
|
|
11409
|
+
' return 1.0 - min(min(lineDistance.x, lineDistance.y), 1.0); ' +
|
|
11410
|
+
'} ' +
|
|
11411
|
+
'void main() { ' +
|
|
11412
|
+
' vec2 gridPosition = gridWorldPosition.xz; ' +
|
|
11413
|
+
' float pixelWorldSize = max(length(fwidth(gridPosition)), 0.0001); ' +
|
|
11414
|
+
' float level = log(max((pixelWorldSize * 10.0) / minimumGridSpacing, 1.0)) / log(10.0); ' +
|
|
11415
|
+
' float gridScale = minimumGridSpacing * pow(10.0, floor(level)); ' +
|
|
11416
|
+
' float levelBlend = fract(level); ' +
|
|
11417
|
+
' float fineLine = gridLine(gridPosition, gridScale); ' +
|
|
11418
|
+
' float middleLine = gridLine(gridPosition, gridScale * 10.0); ' +
|
|
11419
|
+
' float coarseLine = gridLine(gridPosition, gridScale * 100.0); ' +
|
|
11420
|
+
' float fineAlpha = fineLine * (1.0 - levelBlend) * 0.22; ' +
|
|
11421
|
+
' float middleAlpha = middleLine * mix(0.48, 0.22, levelBlend); ' +
|
|
11422
|
+
' float coarseAlpha = coarseLine * levelBlend * 0.48; ' +
|
|
11423
|
+
' float gridAlpha = max(fineAlpha, max(middleAlpha, coarseAlpha)); ' +
|
|
11424
|
+
' float xAxis = 1.0 - smoothstep(0.0, max(fwidth(gridWorldPosition.z) * 1.5, 0.0001), abs(gridWorldPosition.z)); ' +
|
|
11425
|
+
' float zAxis = 1.0 - smoothstep(0.0, max(fwidth(gridWorldPosition.x) * 1.5, 0.0001), abs(gridWorldPosition.x)); ' +
|
|
11426
|
+
' vec3 color = vec3(0.24, 0.29, 0.32); ' +
|
|
11427
|
+
' color = mix(color, vec3(0.63, 0.20, 0.19), xAxis); ' +
|
|
11428
|
+
' color = mix(color, vec3(0.28, 0.53, 0.16), zAxis); ' +
|
|
11429
|
+
' float alpha = max(gridAlpha, max(xAxis, zAxis) * 0.78); ' +
|
|
11430
|
+
' float cameraDistance = length(cameraPosition - gridWorldPosition); ' +
|
|
11431
|
+
' float distanceFade = 1.0 - smoothstep(drawDistance * 0.5, drawDistance, cameraDistance); ' +
|
|
11432
|
+
' if (perspectiveView) { ' +
|
|
11433
|
+
' vec3 viewDirection = normalize(cameraPosition - gridWorldPosition); ' +
|
|
11434
|
+
' float angleFade = 1.0 - pow(1.0 - abs(viewDirection.y), 3.0); ' +
|
|
11435
|
+
' distanceFade *= angleFade; ' +
|
|
11436
|
+
' } ' +
|
|
11437
|
+
' alpha *= distanceFade; ' +
|
|
11438
|
+
' if (alpha < 0.003) discard; ' +
|
|
11439
|
+
' gl_FragColor = vec4(color, alpha); ' +
|
|
11440
|
+
'}',
|
|
11441
|
+
polygonOffset: true,
|
|
11442
|
+
polygonOffsetFactor: -1,
|
|
11443
|
+
polygonOffsetUnits: -1,
|
|
11444
|
+
transparent: true,
|
|
11445
|
+
uniforms: {
|
|
11446
|
+
drawDistance: { value: drawDistance },
|
|
11447
|
+
minimumGridSpacing: { value: MIN_EDITOR_GRID_SPACING },
|
|
11448
|
+
perspectiveView: { value: true },
|
|
11449
|
+
},
|
|
11450
|
+
vertexShader:
|
|
11451
|
+
'varying vec3 gridWorldPosition; ' +
|
|
11452
|
+
'void main() { ' +
|
|
11453
|
+
' vec4 worldPosition = modelMatrix * vec4(position, 1.0); ' +
|
|
11454
|
+
' gridWorldPosition = worldPosition.xyz; ' +
|
|
11455
|
+
' gl_Position = projectionMatrix * viewMatrix * worldPosition; ' +
|
|
11456
|
+
'}',
|
|
11457
|
+
});
|
|
11458
|
+
const grid = new Mesh(new PlaneGeometry(2, 2), material);
|
|
11459
|
+
grid.name = 'IWSDKSceneEditorGrid';
|
|
11460
|
+
grid.rotation.x = -Math.PI / 2;
|
|
11461
|
+
grid.scale.set(drawDistance, drawDistance, 1);
|
|
11462
|
+
grid.frustumCulled = false;
|
|
11463
|
+
grid.renderOrder = -1;
|
|
11464
|
+
grid.userData.iwsdkEditorHelper = true;
|
|
11465
|
+
grid.userData.iwsdkEditorInfiniteGrid = true;
|
|
11466
|
+
return grid;
|
|
11467
|
+
}
|
|
11468
|
+
|
|
11469
|
+
function syncInfiniteEditorGrid() {
|
|
11470
|
+
if (!editorWorldState?.editorGrid) {
|
|
11471
|
+
return;
|
|
11472
|
+
}
|
|
11473
|
+
const camera = editorWorldState.world.camera;
|
|
11474
|
+
const grid = editorWorldState.editorGrid;
|
|
11475
|
+
const drawDistance = editorWorldState.drawDistance;
|
|
11476
|
+
grid.position.set(camera.position.x, 0, camera.position.z);
|
|
11477
|
+
grid.scale.set(drawDistance, drawDistance, 1);
|
|
11478
|
+
grid.material.uniforms.drawDistance.value = drawDistance;
|
|
11479
|
+
grid.material.uniforms.perspectiveView.value =
|
|
11480
|
+
camera.isPerspectiveCamera === true;
|
|
11481
|
+
grid.updateMatrixWorld(true);
|
|
11482
|
+
}
|
|
11483
|
+
|
|
11484
|
+
function setEditorDrawDistance(value, persist = true) {
|
|
11485
|
+
const drawDistance = normalizeEditorDrawDistance(value);
|
|
11486
|
+
if (!editorWorldState) {
|
|
11487
|
+
return drawDistance;
|
|
11488
|
+
}
|
|
11489
|
+
editorWorldState.drawDistance = drawDistance;
|
|
11490
|
+
for (const camera of [
|
|
11491
|
+
editorWorldState.perspectiveCamera,
|
|
11492
|
+
editorWorldState.orthographicCamera,
|
|
11493
|
+
]) {
|
|
11494
|
+
camera.far = drawDistance;
|
|
11495
|
+
camera.updateProjectionMatrix();
|
|
11496
|
+
}
|
|
11497
|
+
if (persist && typeof localStorage !== 'undefined') {
|
|
11498
|
+
try {
|
|
11499
|
+
localStorage.setItem(
|
|
11500
|
+
EDITOR_DRAW_DISTANCE_STORAGE_KEY,
|
|
11501
|
+
String(drawDistance),
|
|
11502
|
+
);
|
|
11503
|
+
} catch {
|
|
11504
|
+
// The viewport setting still applies when browser storage is unavailable.
|
|
11505
|
+
}
|
|
11506
|
+
}
|
|
11507
|
+
syncInfiniteEditorGrid();
|
|
11508
|
+
workspaceUi?.update({ viewportDrawDistance: drawDistance });
|
|
11509
|
+
renderEditorWorld();
|
|
11510
|
+
return drawDistance;
|
|
11511
|
+
}
|
|
11512
|
+
|
|
9991
11513
|
async function createEditorWorld(session, camera) {
|
|
9992
11514
|
const host = getViewportHost();
|
|
9993
11515
|
const editorRuntime = window.FRAMEWORK_MCP_RUNTIME;
|
|
@@ -10025,7 +11547,11 @@ async function createEditorWorld(session, camera) {
|
|
|
10025
11547
|
canvas.setAttribute('aria-label', 'IWSDK 3D scene viewport');
|
|
10026
11548
|
world.renderer.setClearColor(0x101418, 1);
|
|
10027
11549
|
|
|
11550
|
+
const drawDistance = loadEditorDrawDistance();
|
|
11551
|
+
const transformSnap = loadEditorTransformSnap();
|
|
10028
11552
|
const perspectiveCamera = world.camera;
|
|
11553
|
+
perspectiveCamera.far = drawDistance;
|
|
11554
|
+
perspectiveCamera.updateProjectionMatrix();
|
|
10029
11555
|
const orthographicCamera = new OrthographicCamera(
|
|
10030
11556
|
-1,
|
|
10031
11557
|
1,
|
|
@@ -10065,9 +11591,7 @@ async function createEditorWorld(session, camera) {
|
|
|
10065
11591
|
const { builtInObjectMap, levelRootProxy } =
|
|
10066
11592
|
createEditorBuiltinRig(proxyRoot);
|
|
10067
11593
|
|
|
10068
|
-
const grid =
|
|
10069
|
-
grid.name = 'IWSDKSceneEditorGrid';
|
|
10070
|
-
grid.userData.iwsdkEditorHelper = true;
|
|
11594
|
+
const grid = createInfiniteEditorGrid(drawDistance);
|
|
10071
11595
|
world.scene.add(grid);
|
|
10072
11596
|
const ambient = new AmbientLight(0xffffff, 0.65);
|
|
10073
11597
|
ambient.name = 'IWSDKSceneEditorAmbientLight';
|
|
@@ -10086,6 +11610,7 @@ async function createEditorWorld(session, camera) {
|
|
|
10086
11610
|
currentCamera: camera,
|
|
10087
11611
|
currentDocumentValue: null,
|
|
10088
11612
|
currentSession: session,
|
|
11613
|
+
drawDistance,
|
|
10089
11614
|
editorAmbient: ambient,
|
|
10090
11615
|
editorDirectional: directional,
|
|
10091
11616
|
editorGrid: grid,
|
|
@@ -10135,11 +11660,7 @@ async function createEditorWorld(session, camera) {
|
|
|
10135
11660
|
transformDragState: null,
|
|
10136
11661
|
transformHelper,
|
|
10137
11662
|
transformMode: 'translate',
|
|
10138
|
-
transformSnap
|
|
10139
|
-
rotationDeg: 15,
|
|
10140
|
-
scale: 0.1,
|
|
10141
|
-
translation: 0.25,
|
|
10142
|
-
},
|
|
11663
|
+
transformSnap,
|
|
10143
11664
|
transformSnapApplied: {
|
|
10144
11665
|
rotationSnapDeg: null,
|
|
10145
11666
|
scaleSnap: null,
|
|
@@ -10165,6 +11686,8 @@ async function createEditorWorld(session, camera) {
|
|
|
10165
11686
|
: nodeId && node
|
|
10166
11687
|
? {
|
|
10167
11688
|
nodeId,
|
|
11689
|
+
mode: editorWorldState.transformMode,
|
|
11690
|
+
scaleAxis: transformControls.axis,
|
|
10168
11691
|
startTransform: cloneTransform(node.transform || {}),
|
|
10169
11692
|
}
|
|
10170
11693
|
: null;
|
|
@@ -10430,6 +11953,34 @@ function createViewportProof() {
|
|
|
10430
11953
|
layout: createLayoutProof(),
|
|
10431
11954
|
materialCount,
|
|
10432
11955
|
meshCount,
|
|
11956
|
+
editorGrid: {
|
|
11957
|
+
cameraAnchored:
|
|
11958
|
+
editorWorldState.editorGrid.position.x ===
|
|
11959
|
+
editorWorldState.world.camera.position.x &&
|
|
11960
|
+
editorWorldState.editorGrid.position.z ===
|
|
11961
|
+
editorWorldState.world.camera.position.z,
|
|
11962
|
+
drawDistance: editorWorldState.drawDistance,
|
|
11963
|
+
fadeEnd: editorWorldState.drawDistance,
|
|
11964
|
+
fadeStart: editorWorldState.drawDistance * 0.5,
|
|
11965
|
+
followsCamera: true,
|
|
11966
|
+
geometry: editorWorldState.editorGrid.geometry.type,
|
|
11967
|
+
material: editorWorldState.editorGrid.material.type,
|
|
11968
|
+
minimumSpacing:
|
|
11969
|
+
editorWorldState.editorGrid.material.uniforms.minimumGridSpacing.value,
|
|
11970
|
+
planeSize: editorWorldState.drawDistance * 2,
|
|
11971
|
+
position: roundCameraVec3(editorWorldState.editorGrid.position),
|
|
11972
|
+
seamlessLod:
|
|
11973
|
+
editorWorldState.editorGrid.material.fragmentShader.includes(
|
|
11974
|
+
'middleLine * mix(0.48, 0.22, levelBlend)',
|
|
11975
|
+
) &&
|
|
11976
|
+
editorWorldState.editorGrid.material.fragmentShader.includes(
|
|
11977
|
+
'coarseLine * levelBlend * 0.48',
|
|
11978
|
+
),
|
|
11979
|
+
shaderFade:
|
|
11980
|
+
editorWorldState.editorGrid.material.fragmentShader.includes(
|
|
11981
|
+
'smoothstep(drawDistance * 0.5, drawDistance, cameraDistance)',
|
|
11982
|
+
),
|
|
11983
|
+
},
|
|
10433
11984
|
nodeObjectCount: editorWorldState.objectMap.size,
|
|
10434
11985
|
objectHierarchy: objectHierarchyProof(),
|
|
10435
11986
|
orbitControls: Boolean(editorWorldState.orbitControls),
|
|
@@ -10450,10 +12001,12 @@ function createViewportProof() {
|
|
|
10450
12001
|
: null,
|
|
10451
12002
|
renderer: canvas.dataset.renderer || 'unknown',
|
|
10452
12003
|
rendererCamera: {
|
|
12004
|
+
far: editorWorldState.world.camera.far,
|
|
10453
12005
|
isOrthographicCamera:
|
|
10454
12006
|
editorWorldState.world.camera.isOrthographicCamera === true,
|
|
10455
12007
|
isPerspectiveCamera:
|
|
10456
12008
|
editorWorldState.world.camera.isPerspectiveCamera === true,
|
|
12009
|
+
near: editorWorldState.world.camera.near,
|
|
10457
12010
|
type: editorWorldState.world.camera.type,
|
|
10458
12011
|
},
|
|
10459
12012
|
renderStats: currentEditorRenderStats(),
|
|
@@ -13804,6 +15357,9 @@ function pickCanvasNode(session, camera, canvas, event) {
|
|
|
13804
15357
|
true,
|
|
13805
15358
|
);
|
|
13806
15359
|
for (const intersection of intersections) {
|
|
15360
|
+
if (intersection.object.userData?.iwsdkEditorPickable === false) {
|
|
15361
|
+
continue;
|
|
15362
|
+
}
|
|
13807
15363
|
let current = intersection.object;
|
|
13808
15364
|
while (current) {
|
|
13809
15365
|
const nodeId = current.userData?.iwsdkSceneNodeId;
|
|
@@ -13833,6 +15389,36 @@ function pickCanvasNode(session, camera, canvas, event) {
|
|
|
13833
15389
|
return null;
|
|
13834
15390
|
}
|
|
13835
15391
|
|
|
15392
|
+
function pickNodeAtObjectCenter(session, nodeId) {
|
|
15393
|
+
if (!editorWorldState) {
|
|
15394
|
+
return null;
|
|
15395
|
+
}
|
|
15396
|
+
const object = editorWorldState.objectMap.get(nodeId);
|
|
15397
|
+
if (!object) {
|
|
15398
|
+
return { builtinTarget: null, nodeId: null };
|
|
15399
|
+
}
|
|
15400
|
+
const bounds = boundsForObjectWithoutEditorHelpers(object);
|
|
15401
|
+
if (!bounds) {
|
|
15402
|
+
return { builtinTarget: null, nodeId: null };
|
|
15403
|
+
}
|
|
15404
|
+
const projected = new Vector3();
|
|
15405
|
+
bounds.getCenter(projected);
|
|
15406
|
+
projected.project(editorWorldState.world.camera);
|
|
15407
|
+
if (!Number.isFinite(projected.z) || projected.z < -1 || projected.z > 1) {
|
|
15408
|
+
return { builtinTarget: null, nodeId: null };
|
|
15409
|
+
}
|
|
15410
|
+
const canvas = getCanvas();
|
|
15411
|
+
const rect = canvas.getBoundingClientRect();
|
|
15412
|
+
const hit = pickCanvasNode(session, editorWorldState.currentCamera, canvas, {
|
|
15413
|
+
clientX: rect.left + ((projected.x + 1) / 2) * rect.width,
|
|
15414
|
+
clientY: rect.top + ((1 - projected.y) / 2) * rect.height,
|
|
15415
|
+
});
|
|
15416
|
+
return {
|
|
15417
|
+
builtinTarget: hit?.builtinTarget || null,
|
|
15418
|
+
nodeId: hit?.node?.id || null,
|
|
15419
|
+
};
|
|
15420
|
+
}
|
|
15421
|
+
|
|
13836
15422
|
function renderCanvas(session, camera, size = {}) {
|
|
13837
15423
|
if (!editorWorldState) {
|
|
13838
15424
|
return;
|
|
@@ -13905,9 +15491,20 @@ function renderUi(session, camera) {
|
|
|
13905
15491
|
soloNodeId: soloOutlinerNodeId,
|
|
13906
15492
|
statusStrip: editorStatusStripText(session, nodes.length),
|
|
13907
15493
|
transformMode: editorWorldState?.transformMode || 'translate',
|
|
15494
|
+
transformSnapRotationDeg:
|
|
15495
|
+
editorWorldState?.transformSnap?.rotationDeg ??
|
|
15496
|
+
DEFAULT_EDITOR_TRANSFORM_SNAP.rotationDeg,
|
|
15497
|
+
transformSnapScale:
|
|
15498
|
+
editorWorldState?.transformSnap?.scale ??
|
|
15499
|
+
DEFAULT_EDITOR_TRANSFORM_SNAP.scale,
|
|
15500
|
+
transformSnapTranslation:
|
|
15501
|
+
editorWorldState?.transformSnap?.translation ??
|
|
15502
|
+
DEFAULT_EDITOR_TRANSFORM_SNAP.translation,
|
|
13908
15503
|
transformSnapEnabled:
|
|
13909
15504
|
editorWorldState?.transformSnapEnabled === true,
|
|
13910
15505
|
transformSpace: editorWorldState?.transformSpace || 'local',
|
|
15506
|
+
viewportDrawDistance:
|
|
15507
|
+
editorWorldState?.drawDistance ?? DEFAULT_EDITOR_DRAW_DISTANCE,
|
|
13911
15508
|
view: window.__IWSDK_WORKSPACE_VIEW || 'runtime',
|
|
13912
15509
|
});
|
|
13913
15510
|
|
|
@@ -14178,9 +15775,9 @@ async function init() {
|
|
|
14178
15775
|
syncWorkspaceLocation('editor', currentScenePath(), { replace: true });
|
|
14179
15776
|
}
|
|
14180
15777
|
} else {
|
|
14181
|
-
runtimeHandles = (method) =>
|
|
15778
|
+
runtimeHandles = (method) => handlesEditorMethodWithoutSession(method);
|
|
14182
15779
|
runtimeDispatch = (method, params = {}) =>
|
|
14183
|
-
|
|
15780
|
+
dispatchEditorMethodWithoutSession(method, params);
|
|
14184
15781
|
window.IWSDK_SCENE_EDITOR = {
|
|
14185
15782
|
listContributions: () => [],
|
|
14186
15783
|
registerContribution: registerEditorContribution,
|
|
@@ -14197,9 +15794,13 @@ async function init() {
|
|
|
14197
15794
|
updateEditorStartupProgress('Loading scene…', 48);
|
|
14198
15795
|
const loadedScene = await fetchComposedSceneDocument(currentScenePath());
|
|
14199
15796
|
if ((loadedScene.sourceDocument?.imports?.length || 0) > 0) {
|
|
14200
|
-
runtimeHandles = (method) =>
|
|
15797
|
+
runtimeHandles = (method) => handlesEditorMethodWithoutSession(method);
|
|
14201
15798
|
runtimeDispatch = (method, params = {}) =>
|
|
14202
|
-
|
|
15799
|
+
dispatchEditorMethodWithoutSession(
|
|
15800
|
+
method,
|
|
15801
|
+
params,
|
|
15802
|
+
'The selected scene uses imports and cannot be edited directly. Flatten it first, then open the flattened scene.',
|
|
15803
|
+
);
|
|
14203
15804
|
window.IWSDK_SCENE_EDITOR = {
|
|
14204
15805
|
listContributions: () => [],
|
|
14205
15806
|
registerContribution: registerEditorContribution,
|
|
@@ -14477,10 +16078,13 @@ async function init() {
|
|
|
14477
16078
|
};
|
|
14478
16079
|
},
|
|
14479
16080
|
getCamera: () => activeCamera,
|
|
16081
|
+
getComponentHelperState: (nodeId) => componentHelperProof(nodeId),
|
|
14480
16082
|
getObjectSummary: () => ({
|
|
14481
16083
|
ids: editorWorldState ? [...editorWorldState.objectMap.keys()] : [],
|
|
14482
16084
|
objectCount: editorWorldState?.objectMap.size ?? 0,
|
|
14483
16085
|
}),
|
|
16086
|
+
pickNodeAtObjectCenter: (nodeId) =>
|
|
16087
|
+
pickNodeAtObjectCenter(session, nodeId),
|
|
14484
16088
|
getPanelPreviewState: (nodeId) => {
|
|
14485
16089
|
const object = editorWorldState?.objectMap.get(nodeId);
|
|
14486
16090
|
const preview = object?.children.find(
|
|
@@ -14624,6 +16228,11 @@ async function init() {
|
|
|
14624
16228
|
getRendererGlobals: () => rendererGlobalsProof(),
|
|
14625
16229
|
getTransformControlObjectTransform: () =>
|
|
14626
16230
|
objectTransformProof(editorWorldState?.transformControls?.object),
|
|
16231
|
+
getTransformControlAxisVisibility: () => ({
|
|
16232
|
+
x: editorWorldState?.transformControls?.showX ?? null,
|
|
16233
|
+
y: editorWorldState?.transformControls?.showY ?? null,
|
|
16234
|
+
z: editorWorldState?.transformControls?.showZ ?? null,
|
|
16235
|
+
}),
|
|
14627
16236
|
findTransformControlPointerTarget: (axis = 'X') =>
|
|
14628
16237
|
findTransformControlPointerTarget(axis),
|
|
14629
16238
|
beginTransformControlDrag: (transform) => {
|
|
@@ -14672,6 +16281,7 @@ async function init() {
|
|
|
14672
16281
|
return activeCamera;
|
|
14673
16282
|
},
|
|
14674
16283
|
setTransformMode: (mode) => setTransformMode(mode),
|
|
16284
|
+
setTransformSnap: (mode, value) => setTransformSnapValue(mode, value),
|
|
14675
16285
|
setSurfacePlacementEnabled: (enabled) =>
|
|
14676
16286
|
setSurfacePlacementEnabled(enabled),
|
|
14677
16287
|
setTransformSnapEnabled: (enabled) => setTransformSnapEnabled(enabled),
|
|
@@ -14686,7 +16296,7 @@ async function init() {
|
|
|
14686
16296
|
};
|
|
14687
16297
|
},
|
|
14688
16298
|
hasSharedAsset: (key) => editorWorldState?.world.assets.has(String(key)) === true,
|
|
14689
|
-
simulateTransformControlCommit: async (transform) => {
|
|
16299
|
+
simulateTransformControlCommit: async (transform, scaleAxis = null) => {
|
|
14690
16300
|
const nodeId = selectedNodeId();
|
|
14691
16301
|
if (!nodeId || !editorWorldState?.transformControls?.object) {
|
|
14692
16302
|
throw new Error('A selected node with attached transform controls is required');
|
|
@@ -14697,6 +16307,8 @@ async function init() {
|
|
|
14697
16307
|
}
|
|
14698
16308
|
editorWorldState.transformDragState = {
|
|
14699
16309
|
nodeId,
|
|
16310
|
+
mode: editorWorldState.transformMode,
|
|
16311
|
+
scaleAxis,
|
|
14700
16312
|
startTransform: cloneTransform(node.transform || {}),
|
|
14701
16313
|
};
|
|
14702
16314
|
applyNodeTransform(editorWorldState.transformControls.object, transform);
|
|
@@ -15021,16 +16633,19 @@ const EDITOR_SHELL_CSS = String.raw ` html,
|
|
|
15021
16633
|
color: #ffffff;
|
|
15022
16634
|
}
|
|
15023
16635
|
|
|
15024
|
-
.workspace-view-switcher .workspace-
|
|
16636
|
+
.workspace-view-switcher .workspace-icon-button {
|
|
15025
16637
|
align-items: center;
|
|
15026
16638
|
display: flex;
|
|
15027
16639
|
justify-content: center;
|
|
15028
|
-
margin-left: 2px;
|
|
15029
16640
|
padding: 0;
|
|
15030
16641
|
width: 24px;
|
|
15031
16642
|
}
|
|
15032
16643
|
|
|
15033
|
-
.workspace-view-switcher .workspace-reload-button
|
|
16644
|
+
.workspace-view-switcher .workspace-reload-button {
|
|
16645
|
+
margin-left: 2px;
|
|
16646
|
+
}
|
|
16647
|
+
|
|
16648
|
+
.workspace-view-switcher .workspace-icon-button .lucide-icon {
|
|
15034
16649
|
height: 13px;
|
|
15035
16650
|
stroke-width: 1.8;
|
|
15036
16651
|
width: 13px;
|
|
@@ -15315,6 +16930,35 @@ const EDITOR_SHELL_CSS = String.raw ` html,
|
|
|
15315
16930
|
padding-left: 0;
|
|
15316
16931
|
}
|
|
15317
16932
|
|
|
16933
|
+
.transform-snap-control,
|
|
16934
|
+
.viewport-distance-control {
|
|
16935
|
+
align-items: center;
|
|
16936
|
+
display: flex;
|
|
16937
|
+
gap: 4px;
|
|
16938
|
+
white-space: nowrap;
|
|
16939
|
+
}
|
|
16940
|
+
|
|
16941
|
+
.transform-snap-control > span,
|
|
16942
|
+
.viewport-distance-control > span {
|
|
16943
|
+
color: #8d8d94;
|
|
16944
|
+
font-size: 10px;
|
|
16945
|
+
}
|
|
16946
|
+
|
|
16947
|
+
.transform-snap-control input,
|
|
16948
|
+
.viewport-distance-control input {
|
|
16949
|
+
height: 24px;
|
|
16950
|
+
min-height: 24px;
|
|
16951
|
+
text-align: right;
|
|
16952
|
+
}
|
|
16953
|
+
|
|
16954
|
+
.transform-snap-control input {
|
|
16955
|
+
width: 54px;
|
|
16956
|
+
}
|
|
16957
|
+
|
|
16958
|
+
.viewport-distance-control input {
|
|
16959
|
+
width: 68px;
|
|
16960
|
+
}
|
|
16961
|
+
|
|
15318
16962
|
.editor-slot:empty {
|
|
15319
16963
|
display: none !important;
|
|
15320
16964
|
}
|
|
@@ -17786,6 +19430,9 @@ async function launchManagedBrowser(url, headless, verbose, viewport = null, scr
|
|
|
17786
19430
|
: `🖥️ IWSDK: Using hardware GPU (${backend.useAngle})`);
|
|
17787
19431
|
const browserArgs = [
|
|
17788
19432
|
'--enable-webgl',
|
|
19433
|
+
// This dedicated browser only visits the local managed workspace. Keep
|
|
19434
|
+
// HTTPS enabled while accepting IWSDK's intentionally untrusted dev cert.
|
|
19435
|
+
'--ignore-certificate-errors',
|
|
17789
19436
|
`--use-gl=${backend.useGl}`,
|
|
17790
19437
|
`--use-angle=${backend.useAngle}`,
|
|
17791
19438
|
'--disable-background-timer-throttling',
|
|
@@ -17971,72 +19618,6 @@ async function launchManagedBrowser(url, headless, verbose, viewport = null, scr
|
|
|
17971
19618
|
};
|
|
17972
19619
|
}
|
|
17973
19620
|
|
|
17974
|
-
/**
|
|
17975
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
17976
|
-
*
|
|
17977
|
-
* This source code is licensed under the MIT license found in the
|
|
17978
|
-
* LICENSE file in the root directory of this source tree.
|
|
17979
|
-
*/
|
|
17980
|
-
/**
|
|
17981
|
-
* MetaVR telemetry integration for IWSDK.
|
|
17982
|
-
*
|
|
17983
|
-
* Reports MCP tool calls, session lifecycle, and errors through MetaVR's
|
|
17984
|
-
* DeveloperTelemetry pipeline via the `metavr xxiwsdk` subcommand.
|
|
17985
|
-
* All calls are fire-and-forget — telemetry never blocks or breaks the tool.
|
|
17986
|
-
*
|
|
17987
|
-
* Executes MetaVR's JavaScript entrypoint with the current Node executable.
|
|
17988
|
-
* This avoids platform shell shims and works the same way on Windows and Unix.
|
|
17989
|
-
* If MetaVR is not installed in the workspace, telemetry is silently skipped.
|
|
17990
|
-
*/
|
|
17991
|
-
function resolveMetaVrEntrypoint() {
|
|
17992
|
-
try {
|
|
17993
|
-
const requireFromWorkspace = createRequire(path__default.join(process.cwd(), 'package.json'));
|
|
17994
|
-
return requireFromWorkspace.resolve('@meta-quest/metavr/bin.js');
|
|
17995
|
-
}
|
|
17996
|
-
catch {
|
|
17997
|
-
return null;
|
|
17998
|
-
}
|
|
17999
|
-
}
|
|
18000
|
-
function metaVrTelemetry(args, clientVersion) {
|
|
18001
|
-
const entrypoint = resolveMetaVrEntrypoint();
|
|
18002
|
-
if (entrypoint == null) {
|
|
18003
|
-
return;
|
|
18004
|
-
}
|
|
18005
|
-
const globalArgs = ['xxiwsdk'];
|
|
18006
|
-
if (clientVersion) {
|
|
18007
|
-
globalArgs.push('--client-version', clientVersion);
|
|
18008
|
-
}
|
|
18009
|
-
const child = spawn(process.execPath, [entrypoint, ...globalArgs, ...args], {
|
|
18010
|
-
stdio: 'ignore',
|
|
18011
|
-
windowsHide: true,
|
|
18012
|
-
});
|
|
18013
|
-
child.on('error', () => { });
|
|
18014
|
-
child.unref();
|
|
18015
|
-
}
|
|
18016
|
-
function reportSessionStart(sessionId, opts) {
|
|
18017
|
-
const args = ['session-start', '--session-id', sessionId];
|
|
18018
|
-
if (opts?.iwsdkVersion) {
|
|
18019
|
-
args.push('--iwsdk-version', opts.iwsdkVersion);
|
|
18020
|
-
}
|
|
18021
|
-
if (opts?.device) {
|
|
18022
|
-
args.push('--device', opts.device);
|
|
18023
|
-
}
|
|
18024
|
-
if (opts?.port) {
|
|
18025
|
-
args.push('--port', String(opts.port));
|
|
18026
|
-
}
|
|
18027
|
-
metaVrTelemetry(args, opts?.clientVersion);
|
|
18028
|
-
}
|
|
18029
|
-
function reportSessionEnd(sessionId, opts) {
|
|
18030
|
-
const args = ['session-end', '--session-id', sessionId];
|
|
18031
|
-
if (opts?.durationMs != null) {
|
|
18032
|
-
args.push('--duration-ms', String(Math.round(opts.durationMs)));
|
|
18033
|
-
}
|
|
18034
|
-
if (opts?.reason) {
|
|
18035
|
-
args.push('--reason', opts.reason);
|
|
18036
|
-
}
|
|
18037
|
-
metaVrTelemetry(args, opts?.clientVersion);
|
|
18038
|
-
}
|
|
18039
|
-
|
|
18040
19621
|
/**
|
|
18041
19622
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
18042
19623
|
*
|
|
@@ -18044,7 +19625,7 @@ function reportSessionEnd(sessionId, opts) {
|
|
|
18044
19625
|
* LICENSE file in the root directory of this source tree.
|
|
18045
19626
|
*/
|
|
18046
19627
|
// Get __dirname equivalent for ES modules
|
|
18047
|
-
const __filename$1 = fileURLToPath(import.meta.url);
|
|
19628
|
+
const __filename$1 = fileURLToPath$1(import.meta.url);
|
|
18048
19629
|
const __dirname$1 = path.dirname(__filename$1);
|
|
18049
19630
|
/**
|
|
18050
19631
|
* Load and customize the pre-built injection bundle
|
|
@@ -18406,6 +19987,72 @@ function isRelayPageTarget(value) {
|
|
|
18406
19987
|
typeof target.sceneSessionId === 'string');
|
|
18407
19988
|
}
|
|
18408
19989
|
|
|
19990
|
+
/**
|
|
19991
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
19992
|
+
*
|
|
19993
|
+
* This source code is licensed under the MIT license found in the
|
|
19994
|
+
* LICENSE file in the root directory of this source tree.
|
|
19995
|
+
*/
|
|
19996
|
+
/**
|
|
19997
|
+
* MetaVR telemetry integration for IWSDK.
|
|
19998
|
+
*
|
|
19999
|
+
* Reports MCP tool calls, session lifecycle, and errors through MetaVR's
|
|
20000
|
+
* DeveloperTelemetry pipeline via the `metavr xxiwsdk` subcommand.
|
|
20001
|
+
* All calls are fire-and-forget — telemetry never blocks or breaks the tool.
|
|
20002
|
+
*
|
|
20003
|
+
* Executes MetaVR's JavaScript entrypoint with the current Node executable.
|
|
20004
|
+
* This avoids platform shell shims and works the same way on Windows and Unix.
|
|
20005
|
+
* If MetaVR is not installed in the workspace, telemetry is silently skipped.
|
|
20006
|
+
*/
|
|
20007
|
+
function resolveMetaVrEntrypoint() {
|
|
20008
|
+
try {
|
|
20009
|
+
const requireFromWorkspace = createRequire(path__default.join(process.cwd(), 'package.json'));
|
|
20010
|
+
return requireFromWorkspace.resolve('@meta-quest/metavr/bin.js');
|
|
20011
|
+
}
|
|
20012
|
+
catch {
|
|
20013
|
+
return null;
|
|
20014
|
+
}
|
|
20015
|
+
}
|
|
20016
|
+
function metaVrTelemetry(args, clientVersion) {
|
|
20017
|
+
const entrypoint = resolveMetaVrEntrypoint();
|
|
20018
|
+
if (entrypoint == null) {
|
|
20019
|
+
return;
|
|
20020
|
+
}
|
|
20021
|
+
const globalArgs = ['xxiwsdk'];
|
|
20022
|
+
if (clientVersion) {
|
|
20023
|
+
globalArgs.push('--client-version', clientVersion);
|
|
20024
|
+
}
|
|
20025
|
+
const child = spawn(process.execPath, [entrypoint, ...globalArgs, ...args], {
|
|
20026
|
+
stdio: 'ignore',
|
|
20027
|
+
windowsHide: true,
|
|
20028
|
+
});
|
|
20029
|
+
child.on('error', () => { });
|
|
20030
|
+
child.unref();
|
|
20031
|
+
}
|
|
20032
|
+
function reportSessionStart(sessionId, opts) {
|
|
20033
|
+
const args = ['session-start', '--session-id', sessionId];
|
|
20034
|
+
if (opts?.iwsdkVersion) {
|
|
20035
|
+
args.push('--iwsdk-version', opts.iwsdkVersion);
|
|
20036
|
+
}
|
|
20037
|
+
if (opts?.device) {
|
|
20038
|
+
args.push('--device', opts.device);
|
|
20039
|
+
}
|
|
20040
|
+
if (opts?.port) {
|
|
20041
|
+
args.push('--port', String(opts.port));
|
|
20042
|
+
}
|
|
20043
|
+
metaVrTelemetry(args, opts?.clientVersion);
|
|
20044
|
+
}
|
|
20045
|
+
function reportSessionEnd(sessionId, opts) {
|
|
20046
|
+
const args = ['session-end', '--session-id', sessionId];
|
|
20047
|
+
if (opts?.durationMs != null) {
|
|
20048
|
+
args.push('--duration-ms', String(Math.round(opts.durationMs)));
|
|
20049
|
+
}
|
|
20050
|
+
if (opts?.reason) {
|
|
20051
|
+
args.push('--reason', opts.reason);
|
|
20052
|
+
}
|
|
20053
|
+
metaVrTelemetry(args, opts?.clientVersion);
|
|
20054
|
+
}
|
|
20055
|
+
|
|
18409
20056
|
/**
|
|
18410
20057
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
18411
20058
|
*
|
|
@@ -49025,6 +50672,16 @@ const RectAreaLightComponent = createComponent('RectAreaLight', {
|
|
|
49025
50672
|
*/
|
|
49026
50673
|
function createSystem(queries = {}, schema = {}) {
|
|
49027
50674
|
var _a;
|
|
50675
|
+
if (typeof queries === 'function') {
|
|
50676
|
+
throw new TypeError('createSystem() received a lifecycle function as its query map. ' +
|
|
50677
|
+
'Pass only named query descriptors in createSystem({...}); define init(), update(), and destroy() in the subclass body.');
|
|
50678
|
+
}
|
|
50679
|
+
for (const [name, query] of Object.entries(queries)) {
|
|
50680
|
+
if (typeof query === 'function') {
|
|
50681
|
+
throw new TypeError(`createSystem() received lifecycle method "${name}" inside its query map. ` +
|
|
50682
|
+
`Move ${name}() into the subclass body; each createSystem() entry must be a query descriptor such as { required: [Component] }.`);
|
|
50683
|
+
}
|
|
50684
|
+
}
|
|
49028
50685
|
return _a = class {
|
|
49029
50686
|
constructor(world, queryManager, priority) {
|
|
49030
50687
|
this.world = world;
|
|
@@ -49902,6 +51559,119 @@ async function unregisterRuntimeSession(workspaceRoot) {
|
|
|
49902
51559
|
});
|
|
49903
51560
|
}
|
|
49904
51561
|
|
|
51562
|
+
/**
|
|
51563
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
51564
|
+
*
|
|
51565
|
+
* This source code is licensed under the MIT license found in the
|
|
51566
|
+
* LICENSE file in the root directory of this source tree.
|
|
51567
|
+
*/
|
|
51568
|
+
const BUNDLED_FONT_CHARACTERS = new Set(`${Array.from({ length: 95 }, (_, index) => String.fromCodePoint(0x20 + index)).join('')}°ÄÖÜäöüß§`);
|
|
51569
|
+
function formatParseError(error) {
|
|
51570
|
+
const position = error.range?.start;
|
|
51571
|
+
return `${error.message}${position ? ` at ${position.line}:${position.column}` : ''}`;
|
|
51572
|
+
}
|
|
51573
|
+
function describeElement(element) {
|
|
51574
|
+
if (!element) {
|
|
51575
|
+
return '<text>';
|
|
51576
|
+
}
|
|
51577
|
+
const id = typeof element.props.id === 'string' ? `#${element.props.id}` : '';
|
|
51578
|
+
return `<${element.tagName}${id}>`;
|
|
51579
|
+
}
|
|
51580
|
+
function collectUnsupportedGlyphs(node, glyphs, parent) {
|
|
51581
|
+
if (node.kind === 'text') {
|
|
51582
|
+
for (const character of node.value) {
|
|
51583
|
+
if (/\s/u.test(character) || BUNDLED_FONT_CHARACTERS.has(character)) {
|
|
51584
|
+
continue;
|
|
51585
|
+
}
|
|
51586
|
+
if (!glyphs.has(character)) {
|
|
51587
|
+
const position = node.meta.text?.start ?? node.meta.element.start;
|
|
51588
|
+
glyphs.set(character, `${describeElement(parent)} ${position.line + 1}:${position.column + 1}`);
|
|
51589
|
+
}
|
|
51590
|
+
}
|
|
51591
|
+
return;
|
|
51592
|
+
}
|
|
51593
|
+
if (node.kind === 'element') {
|
|
51594
|
+
for (const child of node.children) {
|
|
51595
|
+
collectUnsupportedGlyphs(child, glyphs, node);
|
|
51596
|
+
}
|
|
51597
|
+
}
|
|
51598
|
+
}
|
|
51599
|
+
function fontCoverageWarning(ast, filePath) {
|
|
51600
|
+
const glyphs = new Map();
|
|
51601
|
+
collectUnsupportedGlyphs(ast.root, glyphs);
|
|
51602
|
+
if (glyphs.size === 0) {
|
|
51603
|
+
return undefined;
|
|
51604
|
+
}
|
|
51605
|
+
const details = [...glyphs].map(([character, location]) => {
|
|
51606
|
+
const codePoint = character.codePointAt(0);
|
|
51607
|
+
return `${JSON.stringify(character)} (U+${codePoint
|
|
51608
|
+
.toString(16)
|
|
51609
|
+
.toUpperCase()
|
|
51610
|
+
.padStart(4, '0')}) at ${location}`;
|
|
51611
|
+
});
|
|
51612
|
+
const customFontNote = ast.fontFaces?.length
|
|
51613
|
+
? ' A custom @font-face is declared; confirm that it is applied to these elements and contains these glyphs.'
|
|
51614
|
+
: ' Define and apply a custom @font-face containing these glyphs; UIKitML does not automatically fall back to a system font.';
|
|
51615
|
+
return `[IWSDK] UIKitML font coverage warning in ${filePath}: the bundled font atlas does not contain ${details.join(', ')}.${customFontNote}`;
|
|
51616
|
+
}
|
|
51617
|
+
function parseUIKitMLSource(source, filePath) {
|
|
51618
|
+
if (/^\s*(?:<!doctype\s+html\b|<html(?:\s|>))/i.test(source)) {
|
|
51619
|
+
throw new Error(`[IWSDK] Invalid UIKitML ${filePath}: file contains an HTML document instead of UIKitML.`);
|
|
51620
|
+
}
|
|
51621
|
+
const result = parse(source, {
|
|
51622
|
+
componentSets: resolveKitComponentSets('horizon'),
|
|
51623
|
+
});
|
|
51624
|
+
if (!result.success) {
|
|
51625
|
+
throw new Error(`[IWSDK] Invalid UIKitML ${filePath}:\n${result.errors
|
|
51626
|
+
.map(formatParseError)
|
|
51627
|
+
.join('\n')}`);
|
|
51628
|
+
}
|
|
51629
|
+
return result.ast;
|
|
51630
|
+
}
|
|
51631
|
+
async function collectUIKitMLFiles(directory) {
|
|
51632
|
+
let entries;
|
|
51633
|
+
try {
|
|
51634
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
51635
|
+
}
|
|
51636
|
+
catch (error) {
|
|
51637
|
+
if (error.code === 'ENOENT') {
|
|
51638
|
+
return [];
|
|
51639
|
+
}
|
|
51640
|
+
throw error;
|
|
51641
|
+
}
|
|
51642
|
+
const files = await Promise.all(entries.map(async (entry) => {
|
|
51643
|
+
const entryPath = path$1.join(directory, entry.name);
|
|
51644
|
+
if (entry.isDirectory()) {
|
|
51645
|
+
return collectUIKitMLFiles(entryPath);
|
|
51646
|
+
}
|
|
51647
|
+
return entry.isFile() && entry.name.endsWith('.uikitml')
|
|
51648
|
+
? [entryPath]
|
|
51649
|
+
: [];
|
|
51650
|
+
}));
|
|
51651
|
+
return files.flat().sort();
|
|
51652
|
+
}
|
|
51653
|
+
async function validateUIKitMLDirectory(publicDirectory) {
|
|
51654
|
+
const files = await collectUIKitMLFiles(publicDirectory);
|
|
51655
|
+
const failures = [];
|
|
51656
|
+
const warnings = [];
|
|
51657
|
+
for (const file of files) {
|
|
51658
|
+
try {
|
|
51659
|
+
const ast = parseUIKitMLSource(await readFile$1(file, 'utf8'), file);
|
|
51660
|
+
const warning = fontCoverageWarning(ast, file);
|
|
51661
|
+
if (warning) {
|
|
51662
|
+
warnings.push(warning);
|
|
51663
|
+
}
|
|
51664
|
+
}
|
|
51665
|
+
catch (error) {
|
|
51666
|
+
failures.push(error instanceof Error ? error.message : String(error));
|
|
51667
|
+
}
|
|
51668
|
+
}
|
|
51669
|
+
if (failures.length > 0) {
|
|
51670
|
+
throw new Error(failures.join('\n\n'));
|
|
51671
|
+
}
|
|
51672
|
+
return { files, warnings };
|
|
51673
|
+
}
|
|
51674
|
+
|
|
49905
51675
|
/**
|
|
49906
51676
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
49907
51677
|
*
|
|
@@ -49935,6 +51705,7 @@ const WORKSPACE_REVIEWS_ROUTE = `${WORKSPACE_ROUTE}/reviews`;
|
|
|
49935
51705
|
const WORKSPACE_REVIEW_CAPTURES_ROUTE = `${WORKSPACE_REVIEWS_ROUTE}/captures`;
|
|
49936
51706
|
const WORKSPACE_REVIEW_TRANSITIONS_ROUTE = `${WORKSPACE_REVIEWS_ROUTE}/transitions`;
|
|
49937
51707
|
const WORKSPACE_PUBLISH_ROUTE = `${WORKSPACE_ROUTE}/publish`;
|
|
51708
|
+
const WORKSPACE_OPEN_RUNTIME_ROUTE = `${WORKSPACE_ROUTE}/open-runtime`;
|
|
49938
51709
|
const WORKSPACE_RUNTIME_PREFLIGHT_ROUTE = `${WORKSPACE_ROUTE}/runtime-preflight`;
|
|
49939
51710
|
const OPTIMIZER_EXCLUSIONS = [
|
|
49940
51711
|
'@zappar/msdf-generator',
|
|
@@ -49968,6 +51739,11 @@ const MAX_ISSUED_REVIEW_TRANSITIONS = 64;
|
|
|
49968
51739
|
* Process and normalize plugin options with defaults
|
|
49969
51740
|
*/
|
|
49970
51741
|
function processOptions(options = {}) {
|
|
51742
|
+
const bridgeReadyTimeoutMs = options.bridgeReadyTimeoutMs ?? 5000;
|
|
51743
|
+
if (!Number.isSafeInteger(bridgeReadyTimeoutMs) ||
|
|
51744
|
+
bridgeReadyTimeoutMs <= 0) {
|
|
51745
|
+
throw new Error('iwsdkDev().bridgeReadyTimeoutMs must be a positive integer');
|
|
51746
|
+
}
|
|
49971
51747
|
const emulator = options.emulator ?? {};
|
|
49972
51748
|
const processed = {
|
|
49973
51749
|
...(options.assetManifest == null
|
|
@@ -49982,6 +51758,7 @@ function processOptions(options = {}) {
|
|
|
49982
51758
|
verbose: options.verbose || false,
|
|
49983
51759
|
userAgentException: emulator.userAgentException || new RegExp('OculusBrowser'),
|
|
49984
51760
|
iwer: emulator.iwer ?? true,
|
|
51761
|
+
bridgeReadyTimeoutMs,
|
|
49985
51762
|
};
|
|
49986
51763
|
// Process SEM options from emulator.environment
|
|
49987
51764
|
if (emulator.environment) {
|
|
@@ -50127,6 +51904,9 @@ function projectManifestPluginOptions(options, manifest, projectRoot, command) {
|
|
|
50127
51904
|
...(workspace == null ? {} : { workspace }),
|
|
50128
51905
|
...(options.https == null ? {} : { https: options.https }),
|
|
50129
51906
|
...(options.verbose == null ? {} : { verbose: options.verbose }),
|
|
51907
|
+
...(options.bridgeReadyTimeoutMs == null
|
|
51908
|
+
? {}
|
|
51909
|
+
: { bridgeReadyTimeoutMs: options.bridgeReadyTimeoutMs }),
|
|
50130
51910
|
};
|
|
50131
51911
|
}
|
|
50132
51912
|
function optionalAiMode(value) {
|
|
@@ -50237,12 +52017,18 @@ function iwsdkDev(options = {}) {
|
|
|
50237
52017
|
options.https !== false &&
|
|
50238
52018
|
userConfig.server?.https === undefined) {
|
|
50239
52019
|
const httpsOptions = typeof options.https === 'object' ? options.https : {};
|
|
50240
|
-
const configuredCacheDir = httpsOptions.certDir ??
|
|
50241
|
-
path.join(userConfig.cacheDir ?? 'node_modules/.vite', 'iwsdk-https');
|
|
52020
|
+
const configuredCacheDir = httpsOptions.certDir ?? path.join('.iwsdk', 'https');
|
|
50242
52021
|
const certDir = path.isAbsolute(configuredCacheDir)
|
|
50243
52022
|
? configuredCacheDir
|
|
50244
52023
|
: path.resolve(projectRoot, configuredCacheDir);
|
|
50245
52024
|
const certificate = await getCertificate(certDir, httpsOptions.name ?? 'IWSDK Development', httpsOptions.domains, httpsOptions.ttlDays ?? 365);
|
|
52025
|
+
// @vitejs/plugin-basic-ssl writes its cache asynchronously after
|
|
52026
|
+
// returning. Complete the write before Vite starts so a rapid restart
|
|
52027
|
+
// cannot generate a second certificate for the same project.
|
|
52028
|
+
mkdirSync(certDir, { recursive: true });
|
|
52029
|
+
writeFileSync(path.join(certDir, '_cert.pem'), certificate, {
|
|
52030
|
+
mode: 0o600,
|
|
52031
|
+
});
|
|
50246
52032
|
userConfig.server ?? (userConfig.server = {});
|
|
50247
52033
|
userConfig.server.https = {
|
|
50248
52034
|
cert: certificate,
|
|
@@ -50400,6 +52186,14 @@ function iwsdkDev(options = {}) {
|
|
|
50400
52186
|
handleScenePublishRequest(request, response, config.root, managedBrowser);
|
|
50401
52187
|
return;
|
|
50402
52188
|
}
|
|
52189
|
+
if (pathname === WORKSPACE_OPEN_RUNTIME_ROUTE) {
|
|
52190
|
+
if (!isManagedWorkspaceRequest) {
|
|
52191
|
+
sendJsonError(response, 403, 'Opening the runtime in the default browser is only available from the managed workspace browser.');
|
|
52192
|
+
return;
|
|
52193
|
+
}
|
|
52194
|
+
handleOpenRuntimeRequest(request, response, server);
|
|
52195
|
+
return;
|
|
52196
|
+
}
|
|
50403
52197
|
if (pathname === WORKSPACE_RUNTIME_PREFLIGHT_ROUTE) {
|
|
50404
52198
|
if (!isManagedWorkspaceRequest) {
|
|
50405
52199
|
sendJsonError(response, 403, 'IWSDK runtime preflight is only available in the managed workspace browser.');
|
|
@@ -50440,7 +52234,7 @@ function iwsdkDev(options = {}) {
|
|
|
50440
52234
|
let consecutiveFailures = 0;
|
|
50441
52235
|
let currentBrowserState = null;
|
|
50442
52236
|
const MAX_LAUNCH_FAILURES = 3;
|
|
50443
|
-
const BRIDGE_READY_TIMEOUT_MS =
|
|
52237
|
+
const BRIDGE_READY_TIMEOUT_MS = pluginOptions.bridgeReadyTimeoutMs;
|
|
50444
52238
|
const traceEnabled = process.env.IWSDK_RUNTIME_TRACE === '1';
|
|
50445
52239
|
const wsConnectionIds = new WeakMap();
|
|
50446
52240
|
const wsConnectionKinds = new WeakMap();
|
|
@@ -50553,6 +52347,7 @@ function iwsdkDev(options = {}) {
|
|
|
50553
52347
|
WORKSPACE_REVIEW_CAPTURES_ROUTE,
|
|
50554
52348
|
WORKSPACE_REVIEW_TRANSITIONS_ROUTE,
|
|
50555
52349
|
WORKSPACE_PUBLISH_ROUTE,
|
|
52350
|
+
WORKSPACE_OPEN_RUNTIME_ROUTE,
|
|
50556
52351
|
WORKSPACE_RUNTIME_PREFLIGHT_ROUTE,
|
|
50557
52352
|
`${EDITOR_ROUTE}/document`,
|
|
50558
52353
|
],
|
|
@@ -51309,6 +53104,15 @@ function iwsdkDev(options = {}) {
|
|
|
51309
53104
|
if (loadedProject != null) {
|
|
51310
53105
|
this.addWatchFile(loadedProject.configPath);
|
|
51311
53106
|
}
|
|
53107
|
+
if (config.command === 'build') {
|
|
53108
|
+
const validation = await validateUIKitMLDirectory(config.publicDir || path.resolve(config.root, 'public'));
|
|
53109
|
+
for (const file of validation.files) {
|
|
53110
|
+
this.addWatchFile(file);
|
|
53111
|
+
}
|
|
53112
|
+
for (const warning of validation.warnings) {
|
|
53113
|
+
this.warn(warning);
|
|
53114
|
+
}
|
|
53115
|
+
}
|
|
51312
53116
|
// Development always builds the managed-workspace bridge, even when
|
|
51313
53117
|
// IWER is disabled. Production builds include only explicitly enabled
|
|
51314
53118
|
// IWER emulation; the editor bridge is never a production side effect.
|
|
@@ -51499,6 +53303,28 @@ function sendJsonError(response, statusCode, message, extra = {}) {
|
|
|
51499
53303
|
response.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
51500
53304
|
response.end(JSON.stringify({ error: message, ...extra }));
|
|
51501
53305
|
}
|
|
53306
|
+
async function handleOpenRuntimeRequest(request, response, server) {
|
|
53307
|
+
if (request.method !== 'POST') {
|
|
53308
|
+
response.statusCode = 405;
|
|
53309
|
+
response.setHeader('Allow', 'POST');
|
|
53310
|
+
response.end('Method not allowed');
|
|
53311
|
+
return;
|
|
53312
|
+
}
|
|
53313
|
+
const localUrl = server.resolvedUrls?.local?.[0];
|
|
53314
|
+
if (localUrl == null) {
|
|
53315
|
+
sendJsonError(response, 503, 'The local runtime URL is not available yet.');
|
|
53316
|
+
return;
|
|
53317
|
+
}
|
|
53318
|
+
try {
|
|
53319
|
+
await open(new URL('/', localUrl).toString(), { wait: false });
|
|
53320
|
+
response.statusCode = 204;
|
|
53321
|
+
response.end();
|
|
53322
|
+
}
|
|
53323
|
+
catch (error) {
|
|
53324
|
+
console.error('[IWSDK] Failed to open the default browser:', error);
|
|
53325
|
+
sendJsonError(response, 500, 'Failed to open the default browser.');
|
|
53326
|
+
}
|
|
53327
|
+
}
|
|
51502
53328
|
function normalizePageRole(role) {
|
|
51503
53329
|
return role === 'editor' || role === 'preview' ? role : 'app';
|
|
51504
53330
|
}
|