Skip to content

Commit

Permalink
Fix breaking issue with ScriptBaseUrl (#14472)
Browse files Browse the repository at this point in the history
* Fix breaking issue with ScriptBaseUrl

* formatting
  • Loading branch information
RaananW committed Oct 30, 2023
1 parent 3c073f2 commit ac5bb82
Show file tree
Hide file tree
Showing 22 changed files with 45 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/dev/core/src/Debug/debugLayer.ts
Expand Up @@ -222,7 +222,7 @@ export class DebugLayer {
* By default it uses the babylonjs CDN.
* @ignoreNaming
*/
public static InspectorURL = `v${Engine.Version}/inspector/babylon.inspector.bundle.js`;
public static InspectorURL = `https://cdn.babylonjs.com/v${Engine.Version}/inspector/babylon.inspector.bundle.js`;

private _scene: Scene;

Expand Down
4 changes: 2 additions & 2 deletions packages/dev/core/src/Engines/WebGPU/webgpuTintWASM.ts
Expand Up @@ -22,8 +22,8 @@ export interface TwgslOptions {
export class WebGPUTintWASM {
// Default twgsl options.
private static readonly _TWgslDefaultOptions: TwgslOptions = {
jsPath: "twgsl/twgsl.js",
wasmPath: "twgsl/twgsl.wasm",
jsPath: "https://cdn.babylonjs.com/twgsl/twgsl.js",
wasmPath: "https://cdn.babylonjs.com/twgsl/twgsl.wasm",
};

public static ShowWGSLShaderCode = false;
Expand Down
4 changes: 2 additions & 2 deletions packages/dev/core/src/Engines/webgpuEngine.ts
Expand Up @@ -165,8 +165,8 @@ export interface WebGPUEngineOptions extends ThinEngineOptions, GPURequestAdapte
export class WebGPUEngine extends Engine {
// Default glslang options.
private static readonly _GLSLslangDefaultOptions: GlslangOptions = {
jsPath: "glslang/glslang.js",
wasmPath: "glslang/glslang.wasm",
jsPath: "https://cdn.babylonjs.com/glslang/glslang.js",
wasmPath: "https://cdn.babylonjs.com/glslang/glslang.wasm",
};

/** true to enable using TintWASM to convert Spir-V to WGSL */
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/core/src/Materials/Node/nodeMaterial.ts
Expand Up @@ -201,7 +201,7 @@ export class NodeMaterial extends PushMaterial {
private _animationFrame = -1;

/** Define the Url to load node editor script */
public static EditorURL = `v${Engine.Version}/nodeEditor/babylon.nodeEditor.js`;
public static EditorURL = `https://cdn.babylonjs.com/v${Engine.Version}/nodeEditor/babylon.nodeEditor.js`;

/** Define the Url to load snippets */
public static SnippetUrl = Constants.SnippetUrl;
Expand Down
12 changes: 6 additions & 6 deletions packages/dev/core/src/Meshes/Compression/dracoCompression.ts
Expand Up @@ -302,15 +302,15 @@ export class DracoCompression implements IDisposable {

/**
* The configuration. Defaults to the following urls:
* - wasmUrl: "https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js"
* - wasmBinaryUrl: "https://preview.babylonjs.com/draco_decoder_gltf.wasm"
* - fallbackUrl: "https://preview.babylonjs.com/draco_decoder_gltf.js"
* - wasmUrl: "https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js"
* - wasmBinaryUrl: "https://cdn.babylonjs.com/draco_decoder_gltf.wasm"
* - fallbackUrl: "https://cdn.babylonjs.com/draco_decoder_gltf.js"
*/
public static Configuration: IDracoCompressionConfiguration = {
decoder: {
wasmUrl: "draco_wasm_wrapper_gltf.js",
wasmBinaryUrl: "draco_decoder_gltf.wasm",
fallbackUrl: "draco_decoder_gltf.js",
wasmUrl: "https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js",
wasmBinaryUrl: "https://cdn.babylonjs.com/draco_decoder_gltf.wasm",
fallbackUrl: "https://cdn.babylonjs.com/draco_decoder_gltf.js",
},
};

Expand Down
Expand Up @@ -49,13 +49,13 @@ export class MeshoptCompression implements IDisposable {
* The configuration. Defaults to the following:
* ```javascript
* decoder: {
* url: "https://preview.babylonjs.com/meshopt_decoder.js"
* url: "https://cdn.babylonjs.com/meshopt_decoder.js"
* }
* ```
*/
public static Configuration: IMeshoptCompressionConfiguration = {
decoder: {
url: "meshopt_decoder.js",
url: "https://cdn.babylonjs.com/meshopt_decoder.js",
},
};

Expand Down
2 changes: 1 addition & 1 deletion packages/dev/core/src/Meshes/Node/nodeGeometry.ts
Expand Up @@ -49,7 +49,7 @@ export class NodeGeometry {
private _buildExecutionTime: number = 0;

/** Define the Url to load node editor script */
public static EditorURL = `v${Engine.Version}/nodeGeometryEditor/babylon.nodeGeometryEditor.js`;
public static EditorURL = `https://cdn.babylonjs.com/v${Engine.Version}/nodeGeometryEditor/babylon.nodeGeometryEditor.js`;

/** Define the Url to load snippets */
public static SnippetUrl = Constants.SnippetUrl;
Expand Down
4 changes: 2 additions & 2 deletions packages/dev/core/src/Misc/basis.ts
Expand Up @@ -114,11 +114,11 @@ export const BasisToolsOptions = {
/**
* URL to use when loading the basis transcoder
*/
JSModuleURL: "basisTranscoder/1/basis_transcoder.js",
JSModuleURL: "https://cdn.babylonjs.com/basisTranscoder/1/basis_transcoder.js",
/**
* URL to use when loading the wasm module for the transcoder
*/
WasmModuleURL: "basisTranscoder/1/basis_transcoder.wasm",
WasmModuleURL: "https://cdn.babylonjs.com/basisTranscoder/1/basis_transcoder.wasm",
};

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/core/src/Misc/fileTools.ts
Expand Up @@ -114,7 +114,7 @@ export const FileToolsOptions: {
* Gets or sets the base URL to use to load scripts
* Used for both JS and WASM
*/
ScriptBaseUrl: "https://cdn.babylonjs.com/",
ScriptBaseUrl: "",
/**
* Gets or sets a function used to pre-process script url before using them to load.
* Used for both JS and WASM
Expand Down
2 changes: 1 addition & 1 deletion packages/dev/core/src/Misc/khronosTextureContainer2.ts
Expand Up @@ -241,7 +241,7 @@ export class KhronosTextureContainer2 {
wasmMSCTranscoder: Nullable<string>;
wasmZSTDDecoder: Nullable<string>;
} = {
jsDecoderModule: "babylon.ktx2Decoder.js",
jsDecoderModule: "https://cdn.babylonjs.com/babylon.ktx2Decoder.js",
wasmUASTCToASTC: null,
wasmUASTCToBC7: null,
wasmUASTCToRGBA_UNORM: null,
Expand Down
12 changes: 9 additions & 3 deletions packages/dev/core/src/Misc/tools.ts
Expand Up @@ -485,6 +485,11 @@ export class Tools {
});
}

/**
* @internal
*/
public static _DefaultCdnUrl = "https://cdn.babylonjs.com/";

/**
* Get a script URL including preprocessing
* @param scriptUrl the script Url to process
Expand All @@ -494,10 +499,11 @@ export class Tools {
if (!scriptUrl) {
return "";
}
// check if the URL is absolute or relative. Otherwise, append the base URL
if (!Tools.IsAbsoluteUrl(scriptUrl)) {
// if the base URL was set, and the script Url is an absolute path change the default path
if (Tools.ScriptBaseUrl && scriptUrl.startsWith(Tools._DefaultCdnUrl)) {
// change the default host, which is https://cdn.babylonjs.com with the one defined
const baseUrl = Tools.ScriptBaseUrl[Tools.ScriptBaseUrl.length - 1] === "/" ? Tools.ScriptBaseUrl : Tools.ScriptBaseUrl + "/";
scriptUrl = baseUrl + (scriptUrl[0] === "/" ? scriptUrl.substring(1) : scriptUrl);
scriptUrl = scriptUrl.replace(Tools._DefaultCdnUrl, baseUrl);
}

// run the preprocessor
Expand Down
Expand Up @@ -5,7 +5,7 @@ import { GUIEditor } from "gui-editor/guiEditor";

declare let BABYLON: any;

let editorUrl = `v${Engine.Version}/guiEditor/babylon.guiEditor.js`;
let editorUrl = `https://cdn.babylonjs.com/v${Engine.Version}/guiEditor/babylon.guiEditor.js`;
// eslint-disable-next-line @typescript-eslint/naming-convention
let guiEditorContainer: { GUIEditor: typeof GUIEditor };
/** Get the inspector from bundle or global */
Expand Down
4 changes: 2 additions & 2 deletions packages/dev/loaders/src/glTF/glTFValidation.ts
Expand Up @@ -86,10 +86,10 @@ export interface IGLTFValidationConfiguration {
*/
export class GLTFValidation {
/**
* The configuration. Defaults to `{ url: "https://preview.babylonjs.com/gltf_validator.js" }`.
* The configuration. Defaults to `{ url: "https://cdn.babylonjs.com/gltf_validator.js" }`.
*/
public static Configuration: IGLTFValidationConfiguration = {
url: "gltf_validator.js",
url: "https://cdn.babylonjs.com/gltf_validator.js",
};

private static _LoadScriptPromise: Promise<void>;
Expand Down
Expand Up @@ -10,7 +10,7 @@ export class LiteTranscoder_UASTC_ASTC extends LiteTranscoder {
/**
* URL to use when loading the wasm module for the transcoder
*/
public static WasmModuleURL = "ktx2Transcoders/1/uastc_astc.wasm";
public static WasmModuleURL = "https://cdn.babylonjs.com/ktx2Transcoders/1/uastc_astc.wasm";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public static CanTranscode(src: KTX2.SourceTextureFormat, dst: KTX2.TranscodeTarget, isInGammaSpace: boolean): boolean {
Expand Down
Expand Up @@ -10,7 +10,7 @@ export class LiteTranscoder_UASTC_BC7 extends LiteTranscoder {
/**
* URL to use when loading the wasm module for the transcoder
*/
public static WasmModuleURL = "ktx2Transcoders/1/uastc_bc7.wasm";
public static WasmModuleURL = "https://cdn.babylonjs.com/ktx2Transcoders/1/uastc_bc7.wasm";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public static CanTranscode(src: KTX2.SourceTextureFormat, dst: KTX2.TranscodeTarget, isInGammaSpace: boolean): boolean {
Expand Down
Expand Up @@ -11,7 +11,7 @@ export class LiteTranscoder_UASTC_R8_UNORM extends LiteTranscoder {
/**
* URL to use when loading the wasm module for the transcoder (unorm)
*/
public static WasmModuleURL = "ktx2Transcoders/1/uastc_r8_unorm.wasm";
public static WasmModuleURL = "https://cdn.babylonjs.com/ktx2Transcoders/1/uastc_r8_unorm.wasm";

public static CanTranscode(src: KTX2.SourceTextureFormat, dst: KTX2.TranscodeTarget, isInGammaSpace: boolean): boolean {
return src === KTX2.SourceTextureFormat.UASTC4x4 && dst === KTX2.TranscodeTarget.R8;
Expand Down
Expand Up @@ -11,7 +11,7 @@ export class LiteTranscoder_UASTC_RG8_UNORM extends LiteTranscoder {
/**
* URL to use when loading the wasm module for the transcoder (unorm)
*/
public static WasmModuleURL = "ktx2Transcoders/1/uastc_rg8_unorm.wasm";
public static WasmModuleURL = "https://cdn.babylonjs.com/ktx2Transcoders/1/uastc_rg8_unorm.wasm";

public static CanTranscode(src: KTX2.SourceTextureFormat, dst: KTX2.TranscodeTarget, isInGammaSpace: boolean): boolean {
return src === KTX2.SourceTextureFormat.UASTC4x4 && dst === KTX2.TranscodeTarget.RG8;
Expand Down
Expand Up @@ -11,7 +11,7 @@ export class LiteTranscoder_UASTC_RGBA_SRGB extends LiteTranscoder {
/**
* URL to use when loading the wasm module for the transcoder (srgb)
*/
public static WasmModuleURL = "ktx2Transcoders/1/uastc_rgba8_srgb_v2.wasm";
public static WasmModuleURL = "https://cdn.babylonjs.com/ktx2Transcoders/1/uastc_rgba8_srgb_v2.wasm";

public static CanTranscode(src: KTX2.SourceTextureFormat, dst: KTX2.TranscodeTarget, isInGammaSpace: boolean): boolean {
return src === KTX2.SourceTextureFormat.UASTC4x4 && dst === KTX2.TranscodeTarget.RGBA32 && isInGammaSpace;
Expand Down
Expand Up @@ -11,7 +11,7 @@ export class LiteTranscoder_UASTC_RGBA_UNORM extends LiteTranscoder {
/**
* URL to use when loading the wasm module for the transcoder (unorm)
*/
public static WasmModuleURL = "ktx2Transcoders/1/uastc_rgba8_unorm_v2.wasm";
public static WasmModuleURL = "https://cdn.babylonjs.com/ktx2Transcoders/1/uastc_rgba8_unorm_v2.wasm";

public static CanTranscode(src: KTX2.SourceTextureFormat, dst: KTX2.TranscodeTarget, isInGammaSpace: boolean): boolean {
return src === KTX2.SourceTextureFormat.UASTC4x4 && dst === KTX2.TranscodeTarget.RGBA32 && !isInGammaSpace;
Expand Down
4 changes: 2 additions & 2 deletions packages/tools/ktx2Decoder/src/Transcoders/mscTranscoder.ts
Expand Up @@ -15,11 +15,11 @@ export class MSCTranscoder extends Transcoder {
/**
* URL to use when loading the MSC transcoder
*/
public static JSModuleURL = "ktx2Transcoders/1/msc_basis_transcoder.js";
public static JSModuleURL = "https://cdn.babylonjs.com/ktx2Transcoders/1/msc_basis_transcoder.js";
/**
* URL to use when loading the wasm module for the transcoder
*/
public static WasmModuleURL = "ktx2Transcoders/1/msc_basis_transcoder.wasm";
public static WasmModuleURL = "https://cdn.babylonjs.com/ktx2Transcoders/1/msc_basis_transcoder.wasm";

public static UseFromWorkerThread = true;

Expand Down
7 changes: 5 additions & 2 deletions packages/tools/ktx2Decoder/src/transcoder.ts
Expand Up @@ -15,10 +15,13 @@ export class Transcoder {

public static Name = "Transcoder";

public static WasmBaseUrl = "https://preview.babylonjs.com/";
public static WasmBaseUrl = "";

public static GetWasmUrl(wasmUrl: string) {
return `${Transcoder.WasmBaseUrl}${wasmUrl}`;
if (Transcoder.WasmBaseUrl && wasmUrl.startsWith("https://cdn.babylonjs.com/")) {
wasmUrl = wasmUrl.replace("https://cdn.babylonjs.com/", Transcoder.WasmBaseUrl);
}
return wasmUrl;
}

public getName(): string {
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/ktx2Decoder/src/zstddec.ts
Expand Up @@ -30,7 +30,7 @@ const IMPORT_OBJECT = {
* ZSTD (Zstandard) decoder.
*/
export class ZSTDDecoder {
public static WasmModuleURL = "zstddec.wasm";
public static WasmModuleURL = "https://cdn.babylonjs.com/zstddec.wasm";

init(): Promise<void> {
if (init) {
Expand Down

0 comments on commit ac5bb82

Please sign in to comment.