Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .build/flags.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"errorThreshold": 1.2
"errorThreshold": 1.1
}
14 changes: 0 additions & 14 deletions packages/dev/core/src/Buffers/buffer.pure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,17 +999,3 @@ export function RegisterVertexBuffer(): void {
VertexBuffer.ForEach = VertexBufferForEach;
VertexBuffer.GetFloatData = VertexBufferGetFloatData;
}

// #region GENERATED_SIDE_EFFECT_STUBS — do not edit, regenerate with `npm run generate:side-effect-stubs`
import { _MissingSideEffectProperty } from "../Misc/devTools";

if (!Object.getOwnPropertyDescriptor(VertexBuffer.prototype, "effectiveByteStride")) {
Object.defineProperty(VertexBuffer.prototype, "effectiveByteStride", _MissingSideEffectProperty("VertexBuffer", "effectiveByteStride"));
}
if (!Object.getOwnPropertyDescriptor(VertexBuffer.prototype, "effectiveByteOffset")) {
Object.defineProperty(VertexBuffer.prototype, "effectiveByteOffset", _MissingSideEffectProperty("VertexBuffer", "effectiveByteOffset"));
}
if (!Object.getOwnPropertyDescriptor(VertexBuffer.prototype, "effectiveBuffer")) {
Object.defineProperty(VertexBuffer.prototype, "effectiveBuffer", _MissingSideEffectProperty("VertexBuffer", "effectiveBuffer"));
}
// #endregion GENERATED_SIDE_EFFECT_STUBS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { type IOfflineProvider } from "../../Offline/IOfflineProvider";
import { AbstractEngine } from "../../Engines/abstractEngine.pure";
import { RegisterFileTools } from "../../Misc/fileTools.pure";

let _Registered = false;
/**
Expand All @@ -14,6 +15,14 @@ export function RegisterAbstractEngineLoadFile(): void {
}
_Registered = true;

// File loading requires the fileTools implementation (LoadFile / LoadImage).
// These are injected lazily through EngineFunctionContext so that engines
// that never load files (e.g. the minimal thin engine) do not force-link
// fileTools. Any consumer of the loadFile extension — the full Engine
// side-effect wrapper and RegisterStandardEngineExtensions — reaches this
// registration, which wires the fileTools loaders in.
RegisterFileTools();

AbstractEngine.prototype._loadFileAsync = async function (url: string, offlineProvider?: IOfflineProvider, useArrayBuffer?: boolean): Promise<any> {
return await new Promise<string | ArrayBuffer>((resolve, reject) => {
this._loadFile(
Expand Down
10 changes: 6 additions & 4 deletions packages/dev/core/src/Engines/Processors/shaderProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { type WebRequest } from "../../Misc/webRequest";
import { type LoadFileError } from "../../Misc/fileTools";
import { type IOfflineProvider } from "../../Offline/IOfflineProvider";
import { type IFileRequest } from "../../Misc/fileRequest";
import { LoadFile } from "../../Misc/fileTools.pure";
import { _WarnImport } from "../../Misc/devTools";
import { _GetGlobalDefines } from "../abstractEngine.functions";
import { type AbstractEngine } from "../abstractEngine";

Expand Down Expand Up @@ -499,7 +499,7 @@ export function ProcessIncludes(sourceCode: string, options: _IProcessingOptions
} else {
const includeShaderUrl = options.shadersRepository + "ShadersInclude/" + includeFile + ".fx";

LoadFile(includeShaderUrl, (fileContent) => {
_FunctionContainer.loadFile(includeShaderUrl, (fileContent) => {
options.includesShadersStore[includeFile] = fileContent as string;
ProcessIncludes(parts.join(""), options, callback);
});
Expand All @@ -522,12 +522,14 @@ export function ProcessIncludes(sourceCode: string, options: _IProcessingOptions
* @internal
*/
export const _FunctionContainer = {
loadFile: LoadFile as (
loadFile: (
url: string,
onSuccess: (data: string | ArrayBuffer, responseURL?: string) => void,
onProgress?: (ev: ProgressEvent) => void,
offlineProvider?: IOfflineProvider,
useArrayBuffer?: boolean,
onError?: (request?: WebRequest, exception?: LoadFileError) => void
) => IFileRequest,
): IFileRequest => {
throw _WarnImport("FileTools");
},
};
26 changes: 22 additions & 4 deletions packages/dev/core/src/Engines/abstractEngine.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import { type IWebRequest } from "core/Misc/interfaces/iWebRequest";
import { type WebRequest } from "core/Misc/webRequest";
import { type IOfflineProvider } from "core/Offline/IOfflineProvider";
import { type Nullable } from "core/types";
import { LoadFile } from "core/Misc/fileTools.pure";
import { _WarnImport } from "core/Misc/devTools";
import { Constants } from "./constants";
import { type AbstractEngine } from "./abstractEngine";

/**
* @deprecated Use direct imports from fileTools.pure instead.
* Kept for backwards compatibility — will be removed in a future version.
* Injection seam for file/image loading. The implementations live in
* `fileTools.pure` and are registered here as a side effect by `fileTools.ts`
* (via `RegisterFileTools`). Keeping them behind this mutable context object —
* instead of importing them directly into the always-loaded engine classes —
* lets bundlers tree-shake all file-loading code out of builds that never
* import the `fileTools` side effect (e.g. a minimal thin-engine build).
* @internal
*/
export const EngineFunctionContext: {
Expand All @@ -22,6 +27,15 @@ export const EngineFunctionContext: {
useArrayBuffer?: boolean,
onError?: (request?: WebRequest, exception?: LoadFileError) => void
) => IFileRequest;
loadImage?: (
input: string | ArrayBuffer | ArrayBufferView | Blob,
onLoad: (img: HTMLImageElement | ImageBitmap) => void,
onError: (message?: string, exception?: any) => void,
offlineProvider: Nullable<IOfflineProvider>,
mimeType?: string,
imageBitmapOptions?: ImageBitmapOptions,
engine?: Nullable<AbstractEngine>
) => Nullable<HTMLImageElement>;
} = {};

/**
Expand Down Expand Up @@ -50,7 +64,11 @@ export function _LoadFile(
onError?: (request?: WebRequest, exception?: LoadFileError) => void
) => IFileRequest
): IFileRequest {
const loadFileFn = injectedLoadFile || EngineFunctionContext.loadFile || LoadFile;
const loadFileFn = injectedLoadFile || EngineFunctionContext.loadFile;
if (!loadFileFn) {
// The fileTools side effect was never imported, so no loader is registered.
throw _WarnImport("FileTools");
}
const request = loadFileFn(url, onSuccess, onProgress, offlineProvider, useArrayBuffer, onError);
return request;
}
Expand Down
Loading