-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Thin native engine #17634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Thin native engine #17634
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3635f14
Try preventing events during babylon file parsing
sebavan 27f13da
Fix entity collection issue.
sebavan 2ecd975
ThinNativeEngine
sebavan 6794e98
Merge branch 'master' of https://github.com/BabylonJS/Babylon.js into…
sebavan 1d75e50
Fix load async on thin
sebavan 03e40e1
fix
sebavan 8404e4c
Fix: init drawCalls
KevBrown-MSFT a920b1f
Merge branch 'master' into thinNativeEngine
KevBrown-MSFT 87f70d2
Move scissor functions down to ThinNativeEngine
KevBrown-MSFT 33211b6
Fixy Fixy
sebavan 32993fe
fix
sebavan c43e986
Fix of fix (put _createNativeDataStream back)
KevBrown-MSFT 889af88
Let s try smthg different
sebavan fdf0830
Merge branch 'thinNativeEngine' of https://github.com/BabylonJS/Babyl…
sebavan 6f6fdf8
Try a manual mixin way
sebavan f193820
Add doc
sebavan b4fff54
More Typings
sebavan daeaa3c
loadscript tech split
sebavan dd54624
Fix Comment
sebavan a11d88a
Fix
sebavan 64cfe03
PR Feedback
sebavan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
packages/dev/core/src/Engines/AbstractEngine/abstractEngine.loadFile.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { AbstractEngine } from "../../Engines/abstractEngine"; | ||
| import type { IOfflineProvider } from "../../Offline/IOfflineProvider"; | ||
|
|
||
| declare module "../abstractEngine" { | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| export interface AbstractEngine { | ||
| /** | ||
| * @internal | ||
| */ | ||
| _loadFileAsync(url: string, offlineProvider?: IOfflineProvider, useArrayBuffer?: false): Promise<string>; | ||
| _loadFileAsync(url: string, offlineProvider?: IOfflineProvider, useArrayBuffer?: true): Promise<ArrayBuffer>; | ||
| _loadFileAsync(url: string, offlineProvider?: IOfflineProvider, useArrayBuffer?: boolean): Promise<string | ArrayBuffer>; | ||
| } | ||
| } | ||
|
|
||
| AbstractEngine.prototype._loadFileAsync = async function (url: string, offlineProvider?: IOfflineProvider, useArrayBuffer?: boolean): Promise<any> { | ||
| return await new Promise<string | ArrayBuffer>((resolve, reject) => { | ||
| this._loadFile( | ||
| url, | ||
| (data) => { | ||
| resolve(data); | ||
| }, | ||
| undefined, | ||
| offlineProvider, | ||
| useArrayBuffer, | ||
| (request, exception) => { | ||
| // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors | ||
| reject(exception); | ||
| } | ||
| ); | ||
| }); | ||
| }; | ||
4 changes: 4 additions & 0 deletions
4
packages/dev/core/src/Engines/AbstractEngine/abstractEngine.textureLoaders.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { _GetCompatibleTextureLoader } from "core/Materials/Textures/Loaders/textureLoaderManager"; | ||
| import { AbstractEngine } from "../abstractEngine"; | ||
|
|
||
| AbstractEngine.GetCompatibleTextureLoader = _GetCompatibleTextureLoader; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from "./nativeEngine.cubeTexture"; |
184 changes: 184 additions & 0 deletions
184
packages/dev/core/src/Engines/Native/Extensions/nativeEngine.cubeTexture.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
| import { InternalTexture, InternalTextureSource } from "../../../Materials/Textures/internalTexture"; | ||
| import { Texture } from "../../../Materials/Textures/texture"; | ||
| import { CreateRadianceImageDataArrayBufferViews, GetEnvInfo, UploadEnvSpherical } from "../../../Misc/environmentTextureTools"; | ||
| import type { IWebRequest } from "../../../Misc/interfaces/iWebRequest"; | ||
| import type { Scene } from "../../../scene"; | ||
| import type { Nullable } from "../../../types"; | ||
| import { Constants } from "../../constants"; | ||
| import { ThinNativeEngine } from "../../thinNativeEngine"; | ||
|
|
||
| declare module "../../../Engines/thinNativeEngine" { | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| export interface ThinNativeEngine { | ||
| /** | ||
| * Creates a cube texture | ||
| * @param rootUrl defines the url where the files to load is located | ||
| * @param scene defines the current scene | ||
| * @param files defines the list of files to load (1 per face) | ||
| * @param noMipmap defines a boolean indicating that no mipmaps shall be generated (false by default) | ||
| * @param onLoad defines an optional callback raised when the texture is loaded | ||
| * @param onError defines an optional callback raised if there is an issue to load the texture | ||
| * @param format defines the format of the data | ||
| * @param forcedExtension defines the extension to use to pick the right loader | ||
| * @param createPolynomials if a polynomial sphere should be created for the cube texture | ||
| * @param lodScale defines the scale applied to environment texture. This manages the range of LOD level used for IBL according to the roughness | ||
| * @param lodOffset defines the offset applied to environment texture. This manages first LOD level used for IBL according to the roughness | ||
| * @param fallback defines texture to use while falling back when (compressed) texture file not found. | ||
| * @param loaderOptions options to be passed to the loader | ||
| * @param useSRGBBuffer defines if the texture must be loaded in a sRGB GPU buffer (if supported by the GPU). | ||
| * @param buffer defines the data buffer to load instead of loading the rootUrl | ||
| * @returns the cube texture as an InternalTexture | ||
| */ | ||
| createCubeTexture( | ||
| rootUrl: string, | ||
| scene: Nullable<Scene>, | ||
| files: Nullable<string[]>, | ||
| noMipmap?: boolean, | ||
| onLoad?: Nullable<(data?: any) => void>, | ||
| onError?: Nullable<(message?: string, exception?: any) => void>, | ||
| format?: number, | ||
| forcedExtension?: any, | ||
| createPolynomials?: boolean, | ||
| lodScale?: number, | ||
| lodOffset?: number, | ||
| fallback?: Nullable<InternalTexture>, | ||
| loaderOptions?: any, | ||
| useSRGBBuffer?: boolean, | ||
| buffer?: Nullable<ArrayBufferView> | ||
| ): InternalTexture; | ||
| } | ||
| } | ||
|
|
||
| ThinNativeEngine.prototype.createCubeTexture = function ( | ||
| rootUrl: string, | ||
| scene: Nullable<Scene>, | ||
| files: Nullable<string[]>, | ||
| noMipmap?: boolean, | ||
| onLoad: Nullable<(data?: any) => void> = null, | ||
| onError: Nullable<(message?: string, exception?: any) => void> = null, | ||
| format?: number, | ||
| forcedExtension: any = null, | ||
| createPolynomials = false, | ||
| lodScale: number = 0, | ||
| lodOffset: number = 0, | ||
| fallback: Nullable<InternalTexture> = null, | ||
| loaderOptions?: any, | ||
| useSRGBBuffer = false, | ||
| buffer: Nullable<ArrayBufferView> = null | ||
| ): InternalTexture { | ||
| const texture = fallback ? fallback : new InternalTexture(this, InternalTextureSource.Cube); | ||
| texture.isCube = true; | ||
| texture.url = rootUrl; | ||
| texture.generateMipMaps = !noMipmap; | ||
| texture._lodGenerationScale = lodScale; | ||
| texture._lodGenerationOffset = lodOffset; | ||
| texture._useSRGBBuffer = this._getUseSRGBBuffer(useSRGBBuffer, !!noMipmap); | ||
|
|
||
| if (!this._doNotHandleContextLost) { | ||
| texture._extension = forcedExtension; | ||
| texture._files = files; | ||
| texture._buffer = buffer; | ||
| } | ||
|
|
||
| const lastDot = rootUrl.lastIndexOf("."); | ||
| const extension = forcedExtension ? forcedExtension : lastDot > -1 ? rootUrl.substring(lastDot).toLowerCase() : ""; | ||
|
|
||
| // TODO: use texture loader to load env files? | ||
| if (extension === ".env") { | ||
| const onloaddata = (data: ArrayBufferView) => { | ||
| const info = GetEnvInfo(data)!; | ||
| texture.width = info.width; | ||
| texture.height = info.width; | ||
|
|
||
| UploadEnvSpherical(texture, info); | ||
|
|
||
| const specularInfo = info.specular; | ||
| if (!specularInfo) { | ||
| throw new Error(`Nothing else parsed so far`); | ||
| } | ||
|
|
||
| texture._lodGenerationScale = specularInfo.lodGenerationScale; | ||
| const imageData = CreateRadianceImageDataArrayBufferViews(data, info); | ||
|
|
||
| texture.format = Constants.TEXTUREFORMAT_RGBA; | ||
| texture.type = Constants.TEXTURETYPE_UNSIGNED_BYTE; | ||
| texture.generateMipMaps = true; | ||
| texture.getEngine().updateTextureSamplingMode(Texture.TRILINEAR_SAMPLINGMODE, texture); | ||
| texture._isRGBD = true; | ||
| texture.invertY = true; | ||
|
|
||
| this._engine.loadCubeTextureWithMips( | ||
| texture._hardwareTexture!.underlyingResource, | ||
| imageData, | ||
| false, | ||
| texture._useSRGBBuffer, | ||
| () => { | ||
| texture.isReady = true; | ||
| if (onLoad) { | ||
| onLoad(); | ||
| } | ||
| }, | ||
| () => { | ||
| throw new Error("Could not load a native cube texture."); | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| if (buffer) { | ||
| onloaddata(buffer); | ||
| } else if (files && files.length === 6) { | ||
| throw new Error(`Multi-file loading not allowed on env files.`); | ||
| } else { | ||
| const onInternalError = (request?: IWebRequest, exception?: any) => { | ||
| if (onError && request) { | ||
| onError(request.status + " " + request.statusText, exception); | ||
| } | ||
| }; | ||
|
|
||
| this._loadFile( | ||
| rootUrl, | ||
| (data) => { | ||
| onloaddata(new Uint8Array(data as ArrayBuffer, 0, (data as ArrayBuffer).byteLength)); | ||
| }, | ||
| undefined, | ||
| undefined, | ||
| true, | ||
| onInternalError | ||
| ); | ||
| } | ||
| } else { | ||
| if (!files || files.length !== 6) { | ||
| throw new Error("Cannot load cubemap because 6 files were not defined"); | ||
| } | ||
|
|
||
| // Reorder from [+X, +Y, +Z, -X, -Y, -Z] to [+X, -X, +Y, -Y, +Z, -Z]. | ||
| const reorderedFiles = [files[0], files[3], files[1], files[4], files[2], files[5]]; | ||
| // eslint-disable-next-line github/no-then | ||
| Promise.all(reorderedFiles.map(async (file) => await this._loadFileAsync(file, undefined, true).then((data) => new Uint8Array(data, 0, data.byteLength)))) | ||
| // eslint-disable-next-line github/no-then | ||
| .then(async (data) => { | ||
| return await new Promise<void>((resolve, reject) => { | ||
| this._engine.loadCubeTexture(texture._hardwareTexture!.underlyingResource, data, !noMipmap, true, texture._useSRGBBuffer, resolve, reject); | ||
| }); | ||
| }) | ||
| // eslint-disable-next-line github/no-then | ||
| .then( | ||
| () => { | ||
| texture.isReady = true; | ||
| if (onLoad) { | ||
| onLoad(); | ||
| } | ||
| }, | ||
| (error) => { | ||
| if (onError) { | ||
| onError(`Failed to load cubemap: ${error.message}`, error); | ||
| } | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| this._internalTexturesCache.push(texture); | ||
|
|
||
| return texture; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/dev/core/src/Engines/Native/validatedNativeDataStream.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.