From ae0aa7962db76e370f5126b4dec4e8b017c6c1b4 Mon Sep 17 00:00:00 2001 From: ChenMo Date: Tue, 5 Nov 2024 16:07:59 +0800 Subject: [PATCH 01/15] fix(particle): texture sheet and gravity bug (#2422) --- packages/core/src/particle/ParticleGenerator.ts | 16 ++++++++++++---- packages/core/src/particle/modules/MainModule.ts | 10 ++-------- .../core/src/shaderlib/extra/particle.vs.glsl | 2 +- .../particle/texture_sheet_animation_module.glsl | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/core/src/particle/ParticleGenerator.ts b/packages/core/src/particle/ParticleGenerator.ts index f7e74dad42..744dde9bc9 100644 --- a/packages/core/src/particle/ParticleGenerator.ts +++ b/packages/core/src/particle/ParticleGenerator.ts @@ -14,6 +14,7 @@ import { SetDataOptions } from "../graphic/enums/SetDataOptions"; import { VertexAttribute } from "../mesh"; import { ShaderData } from "../shader"; import { Buffer } from "./../graphic/Buffer"; +import { ParticleBufferUtils } from "./ParticleBufferUtils"; import { ParticleRenderer, ParticleUpdateFlags } from "./ParticleRenderer"; import { ParticleCurveMode } from "./enums/ParticleCurveMode"; import { ParticleGradientMode } from "./enums/ParticleGradientMode"; @@ -23,12 +24,11 @@ import { ParticleStopMode } from "./enums/ParticleStopMode"; import { ColorOverLifetimeModule } from "./modules/ColorOverLifetimeModule"; import { EmissionModule } from "./modules/EmissionModule"; import { MainModule } from "./modules/MainModule"; +import { ParticleCompositeCurve } from "./modules/ParticleCompositeCurve"; import { RotationOverLifetimeModule } from "./modules/RotationOverLifetimeModule"; import { SizeOverLifetimeModule } from "./modules/SizeOverLifetimeModule"; import { TextureSheetAnimationModule } from "./modules/TextureSheetAnimationModule"; import { VelocityOverLifetimeModule } from "./modules/VelocityOverLifetimeModule"; -import { ParticleBufferUtils } from "./ParticleBufferUtils"; -import { ParticleCompositeCurve } from "./modules/ParticleCompositeCurve"; /** * Particle Generator. @@ -758,8 +758,16 @@ export class ParticleGenerator { // Start speed instanceVertices[offset + 18] = startSpeed; - // Unused, Color, size, rotation, - // instanceVertices[offset + 19] = rand.random(); + // Gravity, unused, size, rotation + switch (main.gravityModifier.mode) { + case ParticleCurveMode.Constant: + instanceVertices[offset + 19] = main.gravityModifier.constant; + break; + case ParticleCurveMode.TwoConstants: + instanceVertices[offset + 19] = main.gravityModifier.evaluate(undefined, main._gravityModifierRand.random()); + break; + } + const colorOverLifetime = this.colorOverLifetime; if (colorOverLifetime.enabled && colorOverLifetime.color.mode === ParticleGradientMode.TwoGradients) { instanceVertices[offset + 20] = colorOverLifetime._colorGradientRand.random(); diff --git a/packages/core/src/particle/modules/MainModule.ts b/packages/core/src/particle/modules/MainModule.ts index 0349aec31b..0dd474e0f7 100644 --- a/packages/core/src/particle/modules/MainModule.ts +++ b/packages/core/src/particle/modules/MainModule.ts @@ -1,4 +1,5 @@ import { Color, Rand, Vector3, Vector4 } from "@galacean/engine-math"; +import { TransformModifyFlags } from "../../Transform"; import { deepClone, ignoreClone } from "../../clone/CloneManager"; import { ICustomClone } from "../../clone/ComponentCloner"; import { ShaderData } from "../../shader/ShaderData"; @@ -9,7 +10,6 @@ import { ParticleScaleMode } from "../enums/ParticleScaleMode"; import { ParticleSimulationSpace } from "../enums/ParticleSimulationSpace"; import { ParticleCompositeCurve } from "./ParticleCompositeCurve"; import { ParticleCompositeGradient } from "./ParticleCompositeGradient"; -import { TransformModifyFlags } from "../../Transform"; export class MainModule implements ICustomClone { private static _tempVector40 = new Vector4(); @@ -96,8 +96,6 @@ export class MainModule implements ICustomClone { private _simulationSpace = ParticleSimulationSpace.Local; @ignoreClone private _generator: ParticleGenerator; - @ignoreClone - private _gravity = new Vector3(); /** * The initial lifetime of particles when emitted. @@ -322,11 +320,7 @@ export class MainModule implements ICustomClone { break; } - const particleGravity = this._gravity; - const gravityModifierValue = this.gravityModifier.evaluate(undefined, this._gravityModifierRand.random()); - Vector3.scale(renderer.scene.physics.gravity, gravityModifierValue, particleGravity); - - shaderData.setVector3(MainModule._gravity, particleGravity); + shaderData.setVector3(MainModule._gravity, renderer.scene.physics.gravity); shaderData.setInt(MainModule._simulationSpace, this.simulationSpace); shaderData.setFloat(MainModule._startRotation3D, +this.startRotation3D); shaderData.setInt(MainModule._scaleMode, this.scalingMode); diff --git a/packages/core/src/shaderlib/extra/particle.vs.glsl b/packages/core/src/shaderlib/extra/particle.vs.glsl index e41918c787..dfdf5723f9 100644 --- a/packages/core/src/shaderlib/extra/particle.vs.glsl +++ b/packages/core/src/shaderlib/extra/particle.vs.glsl @@ -74,7 +74,7 @@ void main() { lifeVelocity = computeParticleLifeVelocity(normalizedAge); #endif - vec3 gravityVelocity = renderer_Gravity * age; + vec3 gravityVelocity = renderer_Gravity * a_Random0.x * age; vec4 worldRotation; if (renderer_SimulationSpace == 0) { diff --git a/packages/core/src/shaderlib/particle/texture_sheet_animation_module.glsl b/packages/core/src/shaderlib/particle/texture_sheet_animation_module.glsl index 42fb287d73..7187dfcb2f 100644 --- a/packages/core/src/shaderlib/particle/texture_sheet_animation_module.glsl +++ b/packages/core/src/shaderlib/particle/texture_sheet_animation_module.glsl @@ -20,7 +20,7 @@ vec2 computeParticleUV(in vec2 uv, in float normalizedAge) { float frame = floor(normalizedFrame * renderer_TSATillingParams.z); float tileRow = frame * renderer_TSATillingParams.x; - float floorTotalULength = floor(tileRow); + float tileRowIndex = floor(tileRow); uv.x += tileRow - tileRowIndex; uv.y += tileRowIndex * renderer_TSATillingParams.y; #endif From 781855d041215586e83bc725a8355aa90003dc77 Mon Sep 17 00:00:00 2001 From: ChenMo Date: Tue, 5 Nov 2024 21:20:37 +0800 Subject: [PATCH 02/15] Fix particle rotation bug (#2423) * fix: roation bug --- packages/core/src/particle/modules/MainModule.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/core/src/particle/modules/MainModule.ts b/packages/core/src/particle/modules/MainModule.ts index 0dd474e0f7..7778ae27cb 100644 --- a/packages/core/src/particle/modules/MainModule.ts +++ b/packages/core/src/particle/modules/MainModule.ts @@ -12,7 +12,7 @@ import { ParticleCompositeCurve } from "./ParticleCompositeCurve"; import { ParticleCompositeGradient } from "./ParticleCompositeGradient"; export class MainModule implements ICustomClone { - private static _tempVector40 = new Vector4(); + private _tempVector40 = new Vector4(); private static _vector3One = new Vector3(1, 1, 1); private static readonly _positionScale = ShaderProperty.getByName("renderer_PositionScale"); @@ -293,8 +293,7 @@ export class MainModule implements ICustomClone { case ParticleSimulationSpace.Local: shaderData.setVector3(MainModule._worldPosition, transform.worldPosition); const worldRotation = transform.worldRotationQuaternion; - const worldRotationV4 = MainModule._tempVector40; - worldRotationV4.copyFrom(worldRotation); + const worldRotationV4 = this._tempVector40.copyFrom(worldRotation); // Maybe shaderData should support Quaternion shaderData.setVector4(MainModule._worldRotation, worldRotationV4); break; case ParticleSimulationSpace.World: From 808b60367dc36a651e42667af803e3faade9b366 Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Tue, 5 Nov 2024 21:22:23 +0800 Subject: [PATCH 03/15] chore: release v1.3.16 --- e2e/package.json | 2 +- package.json | 2 +- packages/core/package.json | 2 +- packages/design/package.json | 2 +- packages/galacean/package.json | 2 +- packages/loader/package.json | 2 +- packages/math/package.json | 2 +- packages/physics-lite/package.json | 2 +- packages/physics-physx/package.json | 2 +- packages/rhi-webgl/package.json | 2 +- packages/shader-lab/package.json | 2 +- packages/xr-webxr/package.json | 2 +- packages/xr/package.json | 2 +- tests/package.json | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/e2e/package.json b/e2e/package.json index 6839be85cf..4e44d8d23b 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -1,7 +1,7 @@ { "name": "@galacean/engine-e2e", "private": true, - "version": "1.3.15", + "version": "1.3.16", "license": "MIT", "scripts": { "case": "vite serve .dev --config .dev/vite.config.js", diff --git a/package.json b/package.json index d605722015..1dff6bd63e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-root", - "version": "1.3.15", + "version": "1.3.16", "packageManager": "pnpm@9.3.0", "private": true, "scripts": { diff --git a/packages/core/package.json b/packages/core/package.json index 6cfee070bc..cf2c3ee3e9 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-core", - "version": "1.3.15", + "version": "1.3.16", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/design/package.json b/packages/design/package.json index 49791f9f52..4f82b2b99b 100644 --- a/packages/design/package.json +++ b/packages/design/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-design", - "version": "1.3.15", + "version": "1.3.16", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/galacean/package.json b/packages/galacean/package.json index 51ec81fdab..d63f585afe 100644 --- a/packages/galacean/package.json +++ b/packages/galacean/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine", - "version": "1.3.15", + "version": "1.3.16", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/loader/package.json b/packages/loader/package.json index 51675522b9..e2b5ed4b00 100644 --- a/packages/loader/package.json +++ b/packages/loader/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-loader", - "version": "1.3.15", + "version": "1.3.16", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/math/package.json b/packages/math/package.json index 7c75ab4757..c47e1379dc 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-math", - "version": "1.3.15", + "version": "1.3.16", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/physics-lite/package.json b/packages/physics-lite/package.json index 8613b8fca5..16c484c7b8 100644 --- a/packages/physics-lite/package.json +++ b/packages/physics-lite/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-physics-lite", - "version": "1.3.15", + "version": "1.3.16", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/physics-physx/package.json b/packages/physics-physx/package.json index b8d0d617e7..adbdb890b0 100644 --- a/packages/physics-physx/package.json +++ b/packages/physics-physx/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-physics-physx", - "version": "1.3.15", + "version": "1.3.16", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/rhi-webgl/package.json b/packages/rhi-webgl/package.json index 92d28df54b..6ba5fb6b9b 100644 --- a/packages/rhi-webgl/package.json +++ b/packages/rhi-webgl/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-rhi-webgl", - "version": "1.3.15", + "version": "1.3.16", "repository": { "url": "https://github.com/galacean/engine.git" }, diff --git a/packages/shader-lab/package.json b/packages/shader-lab/package.json index 0350dafdfa..109d789976 100644 --- a/packages/shader-lab/package.json +++ b/packages/shader-lab/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-shader-lab", - "version": "1.3.15", + "version": "1.3.16", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/xr-webxr/package.json b/packages/xr-webxr/package.json index 29f3404db3..374dc9b47e 100644 --- a/packages/xr-webxr/package.json +++ b/packages/xr-webxr/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-xr-webxr", - "version": "1.3.15", + "version": "1.3.16", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/xr/package.json b/packages/xr/package.json index b4866c635d..cc6fbcefce 100644 --- a/packages/xr/package.json +++ b/packages/xr/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-xr", - "version": "1.3.15", + "version": "1.3.16", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/tests/package.json b/tests/package.json index 5559435b0b..a1ca75686b 100644 --- a/tests/package.json +++ b/tests/package.json @@ -1,7 +1,7 @@ { "name": "@galacean/engine-tests", "private": true, - "version": "1.3.15", + "version": "1.3.16", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", From a831b41cd4514703afe7ed0e53c5b7f91c996ad0 Mon Sep 17 00:00:00 2001 From: SwayYan Date: Wed, 6 Nov 2024 23:20:07 +0800 Subject: [PATCH 04/15] Add loader for `Shader` and `ShaderChunk` asset (#2027) * feat: add loader for shader asset --- packages/core/src/Utils.ts | 6 + packages/core/src/asset/AssetType.ts | 2 + packages/core/src/asset/Loader.ts | 5 +- packages/core/src/asset/ResourceManager.ts | 80 +++++---- packages/loader/src/AnimationClipLoader.ts | 2 +- .../loader/src/AnimatorControllerLoader.ts | 2 +- packages/loader/src/BufferLoader.ts | 6 +- packages/loader/src/EnvLoader.ts | 2 +- packages/loader/src/FontLoader.ts | 2 +- packages/loader/src/GLTFLoader.ts | 3 +- packages/loader/src/HDRLoader.ts | 2 +- packages/loader/src/JSONLoader.ts | 6 +- packages/loader/src/KTXCubeLoader.ts | 2 +- packages/loader/src/KTXLoader.ts | 2 +- packages/loader/src/MaterialLoader.ts | 155 ++++++++++-------- packages/loader/src/MeshLoader.ts | 29 ---- packages/loader/src/PrefabLoader.ts | 2 +- packages/loader/src/PrimitiveMeshLoader.ts | 6 +- packages/loader/src/ProjectLoader.ts | 2 +- packages/loader/src/SceneLoader.ts | 2 +- packages/loader/src/ShaderChunkLoader.ts | 49 ++++++ packages/loader/src/ShaderLoader.ts | 38 +++++ packages/loader/src/SourceFontLoader.ts | 3 +- packages/loader/src/SpriteAtlasLoader.ts | 2 +- packages/loader/src/SpriteLoader.ts | 2 +- packages/loader/src/TextLoader.ts | 6 +- packages/loader/src/Texture2DLoader.ts | 2 +- packages/loader/src/TextureCubeLoader.ts | 2 +- .../src/gltf/parser/GLTFBufferParser.ts | 4 +- .../src/gltf/parser/GLTFSchemaParser.ts | 6 +- packages/loader/src/index.ts | 3 +- packages/loader/src/ktx2/KTX2Loader.ts | 2 +- .../loader/src/resource-deserialize/index.ts | 1 - .../resources/scene/EditorTextureLoader.ts | 2 +- .../resources/scene/MeshLoader.ts | 17 -- .../resources/schema/MaterialSchema.ts | 14 +- .../xr/src/loader/XRReferenceImageLoader.ts | 2 +- 37 files changed, 292 insertions(+), 181 deletions(-) delete mode 100644 packages/loader/src/MeshLoader.ts create mode 100644 packages/loader/src/ShaderChunkLoader.ts create mode 100644 packages/loader/src/ShaderLoader.ts delete mode 100644 packages/loader/src/resource-deserialize/resources/scene/MeshLoader.ts diff --git a/packages/core/src/Utils.ts b/packages/core/src/Utils.ts index 8c2c8b03bf..f312853312 100644 --- a/packages/core/src/Utils.ts +++ b/packages/core/src/Utils.ts @@ -78,6 +78,12 @@ export class Utils { return relativeUrl; } + if (!/^https?:/.test(baseUrl)) { + const fileSchema = "files://"; + baseUrl = fileSchema + baseUrl; + return new URL(relativeUrl, baseUrl).href.substring(fileSchema.length); + } + return relativeUrl ? new URL(relativeUrl, baseUrl).href : baseUrl; } diff --git a/packages/core/src/asset/AssetType.ts b/packages/core/src/asset/AssetType.ts index e5d6fef91f..4f8ddab140 100644 --- a/packages/core/src/asset/AssetType.ts +++ b/packages/core/src/asset/AssetType.ts @@ -23,6 +23,8 @@ export enum AssetType { TextureCube = "TextureCube", /** Material. */ Material = "Material", + /** Shader. */ + Shader = "Shader", /** Mesh. */ Mesh = "Mesh", /** AnimationClip. */ diff --git a/packages/core/src/asset/Loader.ts b/packages/core/src/asset/Loader.ts index efe38d5311..a3bf73817b 100644 --- a/packages/core/src/asset/Loader.ts +++ b/packages/core/src/asset/Loader.ts @@ -41,5 +41,8 @@ export abstract class Loader { constructor(public readonly useCache: boolean) {} initialize?(engine: Engine, configuration: EngineConfiguration): Promise; abstract load(item: LoadItem, resourceManager: ResourceManager): AssetPromise; - request: (url: string, config: RequestConfig) => AssetPromise = request; + request(url: string, resourceManager: ResourceManager, config: RequestConfig): AssetPromise { + const remoteUrl = resourceManager._virtualPathMap[url] ?? url; + return request(remoteUrl, config); + } } diff --git a/packages/core/src/asset/ResourceManager.ts b/packages/core/src/asset/ResourceManager.ts index c3bedf1177..19550684be 100644 --- a/packages/core/src/asset/ResourceManager.ts +++ b/packages/core/src/asset/ResourceManager.ts @@ -183,12 +183,14 @@ export class ResourceManager { * @internal */ _onSubAssetSuccess(assetBaseURL: string, assetSubPath: string, value: T): void { - const subPromiseCallback = this._subAssetPromiseCallbacks[assetBaseURL]?.[assetSubPath]; + const remoteAssetBaseURL = this._virtualPathMap[assetBaseURL] ?? assetBaseURL; + + const subPromiseCallback = this._subAssetPromiseCallbacks[remoteAssetBaseURL]?.[assetSubPath]; if (subPromiseCallback) { subPromiseCallback.resolve(value); } else { // Pending - (this._subAssetPromiseCallbacks[assetBaseURL] ||= {})[assetSubPath] = { + (this._subAssetPromiseCallbacks[remoteAssetBaseURL] ||= {})[assetSubPath] = { resolvedValue: value }; } @@ -326,10 +328,7 @@ export class ResourceManager { private _loadSingleItem(itemOrURL: LoadItem | string): AssetPromise { const item = this._assignDefaultOptions(typeof itemOrURL === "string" ? { url: itemOrURL } : itemOrURL); - - // Check url mapping - const itemURL = item.url; - let url = this._virtualPathMap[itemURL] ? this._virtualPathMap[itemURL] : itemURL; + let { url } = item; // Not absolute and base url is set if (!Utils.isAbsoluteUrl(url) && this.baseUrl) url = Utils.resolveAbsoluteUrl(this.baseUrl, url); @@ -338,8 +337,11 @@ export class ResourceManager { const { assetBaseURL, queryPath } = this._parseURL(url); const paths = queryPath ? this._parseQueryPath(queryPath) : []; + // Get remote asset base url + const remoteAssetBaseURL = this._virtualPathMap[assetBaseURL] ?? assetBaseURL; + // Check cache - const cacheObject = this._assetUrlPool[assetBaseURL]; + const cacheObject = this._assetUrlPool[remoteAssetBaseURL]; if (cacheObject) { return new AssetPromise((resolve) => { resolve(this._getResolveResource(cacheObject, paths) as T); @@ -347,18 +349,18 @@ export class ResourceManager { } // Get asset url - let assetURL = assetBaseURL; + let remoteAssetURL = remoteAssetBaseURL; if (queryPath) { - assetURL += "?q=" + paths.shift(); + remoteAssetURL += "?q=" + paths.shift(); let index: string; while ((index = paths.shift())) { - assetURL += `[${index}]`; + remoteAssetURL += `[${index}]`; } } // Check is loading const loadingPromises = this._loadingPromises; - const loadingPromise = loadingPromises[assetURL]; + const loadingPromise = loadingPromises[remoteAssetURL]; if (loadingPromise) { return new AssetPromise((resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) => { loadingPromise @@ -381,34 +383,40 @@ export class ResourceManager { // Check sub asset if (queryPath) { // Check whether load main asset - const mainPromise = loadingPromises[assetBaseURL] || this._loadMainAsset(loader, item, assetBaseURL); + const mainPromise = + loadingPromises[remoteAssetBaseURL] || this._loadMainAsset(loader, item, remoteAssetBaseURL, assetBaseURL); mainPromise.catch((e) => { - this._onSubAssetFail(assetBaseURL, queryPath, e); + this._onSubAssetFail(remoteAssetBaseURL, queryPath, e); }); - return this._createSubAssetPromiseCallback(assetBaseURL, assetURL, queryPath); + return this._createSubAssetPromiseCallback(remoteAssetBaseURL, remoteAssetURL, queryPath); } - return this._loadMainAsset(loader, item, assetBaseURL); + return this._loadMainAsset(loader, item, remoteAssetBaseURL, assetBaseURL); } - private _loadMainAsset(loader: Loader, item: LoadItem, assetBaseURL: string): AssetPromise { + private _loadMainAsset( + loader: Loader, + item: LoadItem, + remoteAssetBaseURL: string, + assetBaseURL: string + ): AssetPromise { item.url = assetBaseURL; const loadingPromises = this._loadingPromises; const promise = loader.load(item, this); - loadingPromises[assetBaseURL] = promise; + loadingPromises[remoteAssetBaseURL] = promise; promise.then( (resource: T) => { if (loader.useCache) { - this._addAsset(assetBaseURL, resource as EngineObject); + this._addAsset(remoteAssetBaseURL, resource as EngineObject); } - delete loadingPromises[assetBaseURL]; - this._releaseSubAssetPromiseCallback(assetBaseURL); + delete loadingPromises[remoteAssetBaseURL]; + this._releaseSubAssetPromiseCallback(remoteAssetBaseURL); }, () => { - delete loadingPromises[assetBaseURL]; - this._releaseSubAssetPromiseCallback(assetBaseURL); + delete loadingPromises[remoteAssetBaseURL]; + this._releaseSubAssetPromiseCallback(remoteAssetBaseURL); } ); @@ -416,12 +424,12 @@ export class ResourceManager { } private _createSubAssetPromiseCallback( - assetBaseURL: string, - assetURL: string, + remoteAssetBaseURL: string, + remoteAssetURL: string, assetSubPath: string ): AssetPromise { const loadingPromises = this._loadingPromises; - const subPromiseCallback = this._subAssetPromiseCallbacks[assetBaseURL]?.[assetSubPath]; + const subPromiseCallback = this._subAssetPromiseCallbacks[remoteAssetBaseURL]?.[assetSubPath]; const resolvedValue = subPromiseCallback?.resolvedValue; const rejectedValue = subPromiseCallback?.rejectedValue; @@ -438,19 +446,19 @@ export class ResourceManager { // Pending const promise = new AssetPromise((resolve, reject) => { - (this._subAssetPromiseCallbacks[assetBaseURL] ||= {})[assetSubPath] = { + (this._subAssetPromiseCallbacks[remoteAssetBaseURL] ||= {})[assetSubPath] = { resolve, reject }; }); - loadingPromises[assetURL] = promise; + loadingPromises[remoteAssetURL] = promise; promise.then( () => { - delete loadingPromises[assetURL]; + delete loadingPromises[remoteAssetURL]; }, - () => delete loadingPromises[assetURL] + () => delete loadingPromises[remoteAssetURL] ); return promise; @@ -537,15 +545,21 @@ export class ResourceManager { if (obj) { promise = Promise.resolve(obj); } else { - let url = this._editorResourceConfig[refId]?.path; - if (!url) { + const resourceConfig = this._editorResourceConfig[refId]; + if (!resourceConfig) { Logger.warn(`refId:${refId} is not find in this._editorResourceConfig.`); return Promise.resolve(null); } - url = key ? `${url}${url.indexOf("?") > -1 ? "&" : "?"}q=${key}` : url; + const remoteUrl = resourceConfig.path; + const queryPath = new URL(remoteUrl).search; + let url = resourceConfig.virtualPath + queryPath; + if (key) { + url += (url.indexOf("?") > -1 ? "&" : "?") + "q=" + key; + } + promise = this.load({ url, - type: this._editorResourceConfig[refId].type + type: resourceConfig.type }); } return promise.then((item) => (isClone ? item.clone() : item)); diff --git a/packages/loader/src/AnimationClipLoader.ts b/packages/loader/src/AnimationClipLoader.ts index b6352a3dd5..0c5cfa4521 100644 --- a/packages/loader/src/AnimationClipLoader.ts +++ b/packages/loader/src/AnimationClipLoader.ts @@ -14,7 +14,7 @@ import { decode } from "./resource-deserialize"; class AnimationClipLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, { + this.request(item.url, resourceManager, { ...item, type: "arraybuffer" }) diff --git a/packages/loader/src/AnimatorControllerLoader.ts b/packages/loader/src/AnimatorControllerLoader.ts index 06728a6f7a..e420ff72e8 100644 --- a/packages/loader/src/AnimatorControllerLoader.ts +++ b/packages/loader/src/AnimatorControllerLoader.ts @@ -19,7 +19,7 @@ import { class AnimatorControllerLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, { + this.request(item.url, resourceManager, { ...item, type: "json" }) diff --git a/packages/loader/src/BufferLoader.ts b/packages/loader/src/BufferLoader.ts index c4bc38e9fe..564cd8bbc1 100644 --- a/packages/loader/src/BufferLoader.ts +++ b/packages/loader/src/BufferLoader.ts @@ -1,11 +1,11 @@ -import { resourceLoader, Loader, AssetPromise, AssetType, LoadItem } from "@galacean/engine-core"; +import { resourceLoader, Loader, AssetPromise, AssetType, LoadItem, ResourceManager } from "@galacean/engine-core"; function isBase64(url) { return /^data:(.+?);base64,/.test(url); } @resourceLoader(AssetType.Buffer, ["bin", "r3bin"], false) class BufferLoader extends Loader { - load(item: LoadItem): AssetPromise { + load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { const url = item.url; if (isBase64(url)) { return new AssetPromise((resolve) => { @@ -14,7 +14,7 @@ class BufferLoader extends Loader { resolve(result.buffer); }); } - return this.request(url, { + return this.request(url, resourceManager, { ...item, type: "arraybuffer" }); diff --git a/packages/loader/src/EnvLoader.ts b/packages/loader/src/EnvLoader.ts index d7c9ca7290..99ca9f7ee9 100644 --- a/packages/loader/src/EnvLoader.ts +++ b/packages/loader/src/EnvLoader.ts @@ -17,7 +17,7 @@ import { SphericalHarmonics3 } from "@galacean/engine-math"; class EnvLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, { ...item, type: "arraybuffer" }) + this.request(item.url, resourceManager, { ...item, type: "arraybuffer" }) .then((arraybuffer) => { const shArray = new Float32Array(arraybuffer, 0, 27); const shByteLength = 27 * 4; diff --git a/packages/loader/src/FontLoader.ts b/packages/loader/src/FontLoader.ts index 2357ada08a..4441e80ba5 100644 --- a/packages/loader/src/FontLoader.ts +++ b/packages/loader/src/FontLoader.ts @@ -12,7 +12,7 @@ import { class FontLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, { ...item, type: "json" }) + this.request(item.url, resourceManager, { ...item, type: "json" }) .then((data) => { const { fontName, fontUrl } = data; diff --git a/packages/loader/src/GLTFLoader.ts b/packages/loader/src/GLTFLoader.ts index 0707d17aac..cff590de7f 100644 --- a/packages/loader/src/GLTFLoader.ts +++ b/packages/loader/src/GLTFLoader.ts @@ -37,9 +37,8 @@ export class GLTFLoader extends Loader { } override load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { - const url = item.url; const params = item.params; - const glTFResource = new GLTFResource(resourceManager.engine, url); + const glTFResource = new GLTFResource(resourceManager.engine, item.url); const context = new GLTFParserContext(glTFResource, resourceManager, { keepMeshData: false, ...params diff --git a/packages/loader/src/HDRLoader.ts b/packages/loader/src/HDRLoader.ts index 3f72080728..d9504d5ac3 100644 --- a/packages/loader/src/HDRLoader.ts +++ b/packages/loader/src/HDRLoader.ts @@ -381,7 +381,7 @@ class HDRLoader extends Loader { return new AssetPromise((resolve, reject) => { const engine = resourceManager.engine; - this.request(item.url, { ...item, type: "arraybuffer" }) + this.request(item.url, resourceManager, { ...item, type: "arraybuffer" }) .then((buffer) => { const uint8Array = new Uint8Array(buffer); const { width, height, dataPosition } = HDRLoader._parseHeader(uint8Array); diff --git a/packages/loader/src/JSONLoader.ts b/packages/loader/src/JSONLoader.ts index 364b1159b4..7942f15210 100644 --- a/packages/loader/src/JSONLoader.ts +++ b/packages/loader/src/JSONLoader.ts @@ -1,9 +1,9 @@ -import { resourceLoader, Loader, AssetPromise, AssetType, LoadItem } from "@galacean/engine-core"; +import { resourceLoader, Loader, AssetPromise, AssetType, LoadItem, ResourceManager } from "@galacean/engine-core"; @resourceLoader(AssetType.JSON, ["json"], false) class JSONLoader extends Loader { - load(item: LoadItem): AssetPromise { - return this.request(item.url, { + load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { + return this.request(item.url, resourceManager, { ...item, type: "json" }); diff --git a/packages/loader/src/KTXCubeLoader.ts b/packages/loader/src/KTXCubeLoader.ts index 8e459c50a4..4a9607a776 100644 --- a/packages/loader/src/KTXCubeLoader.ts +++ b/packages/loader/src/KTXCubeLoader.ts @@ -16,7 +16,7 @@ class KTXCubeLoader extends Loader { return new AssetPromise((resolve, reject) => { Promise.all( item.urls.map((url) => - this.request(url, { + this.request(url, resourceManager, { ...item, type: "arraybuffer" }) diff --git a/packages/loader/src/KTXLoader.ts b/packages/loader/src/KTXLoader.ts index cdfa175a22..191d6c20be 100644 --- a/packages/loader/src/KTXLoader.ts +++ b/packages/loader/src/KTXLoader.ts @@ -13,7 +13,7 @@ import { parseSingleKTX } from "./compressed-texture"; export class KTXLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, { + this.request(item.url, resourceManager, { ...item, type: "arraybuffer" }) diff --git a/packages/loader/src/MaterialLoader.ts b/packages/loader/src/MaterialLoader.ts index 6048f24301..c58cba8d12 100644 --- a/packages/loader/src/MaterialLoader.ts +++ b/packages/loader/src/MaterialLoader.ts @@ -1,6 +1,7 @@ import { AssetPromise, AssetType, + Engine, LoadItem, Loader, Material, @@ -10,7 +11,15 @@ import { resourceLoader } from "@galacean/engine-core"; import { Color, Vector2, Vector3, Vector4 } from "@galacean/engine-math"; -import type { IAssetRef, IColor, IMaterialSchema, IVector2, IVector3, IVector4 } from "./resource-deserialize"; +import { + MaterialLoaderType, + type IAssetRef, + type IColor, + type IMaterialSchema, + type IVector2, + type IVector3, + type IVector4 +} from "./resource-deserialize"; function parseProperty(object: Object, key: string, value: any) { if (typeof value === "object") { @@ -26,79 +35,97 @@ function parseProperty(object: Object, key: string, value: any) { class MaterialLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, { + this.request(item.url, resourceManager, { ...item, type: "json" }) .then((materialSchema: IMaterialSchema) => { const engine = resourceManager.engine; - const { name, shader, shaderData, macros, renderState } = materialSchema; - const material = new Material(engine, Shader.find(shader)); - material.name = name; - - const texturePromises = new Array>(); - const materialShaderData = material.shaderData; - for (let key in shaderData) { - const { type, value } = shaderData[key]; + const { shaderRef, shader: shaderName } = materialSchema; - switch (type) { - case "Vector2": - materialShaderData.setVector2(key, new Vector2((value).x, (value).y)); - break; - case "Vector3": - materialShaderData.setVector3( - key, - new Vector3((value).x, (value).y, (value).z) - ); - break; - case "Vector4": - materialShaderData.setVector4( - key, - new Vector4((value).x, (value).y, (value).z, (value).w) - ); - break; - case "Color": - materialShaderData.setColor( - key, - new Color((value).r, (value).g, (value).b, (value).a) - ); - break; - case "Float": - materialShaderData.setFloat(key, value); - break; - case "Texture": - texturePromises.push( - // @ts-ignore - resourceManager.getResourceByRef(value).then((texture) => { - materialShaderData.setTexture(key, texture); - }) - ); - break; - case "Boolean": - materialShaderData.setInt(key, value ? 1 : 0); - break; - case "Integer": - materialShaderData.setInt(key, Number(value)); - break; - } + if (shaderRef) { + resolve( + resourceManager + // @ts-ignore + .getResourceByRef(shaderRef) + .then((shader) => this.getMaterialByShader(materialSchema, shader, engine)) + ); + } else { + // compatible with 1.2-pre version material schema + const shader = Shader.find(shaderName); + resolve(this.getMaterialByShader(materialSchema, shader, engine)); } + }) + .catch(reject); + }); + } - for (let i = 0, length = macros.length; i < length; i++) { - const { name, value } = macros[i]; - if (value == undefined) { - materialShaderData.enableMacro(name); - } else { - materialShaderData.enableMacro(name, value); - } - } + private getMaterialByShader(materialSchema: IMaterialSchema, shader: Shader, engine: Engine): Promise { + const { name, shaderData, macros, renderState } = materialSchema; - parseProperty(material, "renderState", renderState); + const material = new Material(engine, shader); + material.name = name; - return Promise.all(texturePromises).then(() => { - resolve(material); - }); - }) - .catch(reject); + const texturePromises = new Array>(); + const materialShaderData = material.shaderData; + for (let key in shaderData) { + const { type, value } = shaderData[key]; + + switch (type) { + case MaterialLoaderType.Vector2: + materialShaderData.setVector2(key, new Vector2((value).x, (value).y)); + break; + case MaterialLoaderType.Vector3: + materialShaderData.setVector3( + key, + new Vector3((value).x, (value).y, (value).z) + ); + break; + case MaterialLoaderType.Vector4: + materialShaderData.setVector4( + key, + new Vector4((value).x, (value).y, (value).z, (value).w) + ); + break; + case MaterialLoaderType.Color: + materialShaderData.setColor( + key, + new Color((value).r, (value).g, (value).b, (value).a) + ); + break; + case MaterialLoaderType.Float: + materialShaderData.setFloat(key, value); + break; + case MaterialLoaderType.Texture: + texturePromises.push( + // @ts-ignore + engine.resourceManager.getResourceByRef(value).then((texture) => { + materialShaderData.setTexture(key, texture); + }) + ); + break; + case MaterialLoaderType.Boolean: + materialShaderData.setInt(key, value ? 1 : 0); + break; + case MaterialLoaderType.Integer: + materialShaderData.setInt(key, Number(value)); + break; + } + } + + for (let i = 0, length = macros.length; i < length; i++) { + const { name, value } = macros[i]; + if (value == undefined) { + materialShaderData.enableMacro(name); + } else { + materialShaderData.enableMacro(name, value); + } + } + + parseProperty(material, "renderState", renderState); + + return Promise.all(texturePromises).then(() => { + return material; }); } } diff --git a/packages/loader/src/MeshLoader.ts b/packages/loader/src/MeshLoader.ts deleted file mode 100644 index 73ff264273..0000000000 --- a/packages/loader/src/MeshLoader.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { - resourceLoader, - Loader, - AssetPromise, - AssetType, - LoadItem, - ResourceManager, - ModelMesh -} from "@galacean/engine-core"; -import { decode } from "./resource-deserialize"; - -@resourceLoader(AssetType.Mesh, ["mesh"]) -class MeshLoader extends Loader { - load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { - return new AssetPromise((resolve, reject) => { - this.request(item.url, { - ...item, - type: "arraybuffer" - }) - .then((data) => { - return decode(data, resourceManager.engine); - }) - .then((mesh) => { - resolve(mesh); - }) - .catch(reject); - }); - } -} diff --git a/packages/loader/src/PrefabLoader.ts b/packages/loader/src/PrefabLoader.ts index 8eaeb792ef..d536502092 100644 --- a/packages/loader/src/PrefabLoader.ts +++ b/packages/loader/src/PrefabLoader.ts @@ -9,7 +9,7 @@ export class PrefabLoader extends Loader { const engine = resourceManager.engine; return new AssetPromise((resolve, reject) => { - this.request(item.url, { + this.request(item.url, resourceManager, { ...item, type: "json" }).then((data) => { diff --git a/packages/loader/src/PrimitiveMeshLoader.ts b/packages/loader/src/PrimitiveMeshLoader.ts index 59d4e58863..cc85be7cf2 100644 --- a/packages/loader/src/PrimitiveMeshLoader.ts +++ b/packages/loader/src/PrimitiveMeshLoader.ts @@ -5,13 +5,15 @@ import { Loader, ModelMesh, PrimitiveMesh, + ResourceManager, resourceLoader } from "@galacean/engine-core"; @resourceLoader(AssetType.PrimitiveMesh, ["mesh"], false) class PrimitiveMeshLoader extends Loader { - load(item: LoadItem, { engine }): AssetPromise { - return this.request(item.url, { + load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { + const { engine } = resourceManager; + return this.request(item.url, resourceManager, { ...item, type: "json" }).then((data) => { diff --git a/packages/loader/src/ProjectLoader.ts b/packages/loader/src/ProjectLoader.ts index 9c9c54ff12..82441d2260 100644 --- a/packages/loader/src/ProjectLoader.ts +++ b/packages/loader/src/ProjectLoader.ts @@ -14,7 +14,7 @@ class ProjectLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { const { engine } = resourceManager; return new AssetPromise((resolve, reject) => { - this.request(item.url, { ...item, type: "json" }) + this.request(item.url, resourceManager, { ...item, type: "json" }) .then((data) => { // @ts-ignore engine.resourceManager.initVirtualResources(data.files); diff --git a/packages/loader/src/SceneLoader.ts b/packages/loader/src/SceneLoader.ts index 70c851a8e6..9fab686d79 100644 --- a/packages/loader/src/SceneLoader.ts +++ b/packages/loader/src/SceneLoader.ts @@ -21,7 +21,7 @@ class SceneLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { const { engine } = resourceManager; return new AssetPromise((resolve, reject) => { - this.request(item.url, { ...item, type: "json" }) + this.request(item.url, resourceManager, { ...item, type: "json" }) .then((data) => { return SceneParser.parse(engine, data).then((scene) => { const promises = []; diff --git a/packages/loader/src/ShaderChunkLoader.ts b/packages/loader/src/ShaderChunkLoader.ts new file mode 100644 index 0000000000..aaaea4d3a4 --- /dev/null +++ b/packages/loader/src/ShaderChunkLoader.ts @@ -0,0 +1,49 @@ +import { + AssetPromise, + LoadItem, + Loader, + ResourceManager, + ShaderFactory, + resourceLoader, + // @ts-ignore + ShaderLib, + Utils +} from "@galacean/engine-core"; + +@resourceLoader("ShaderChunk", ["glsl"]) +export class ShaderChunkLoader extends Loader { + private static _shaderIncludeRegex = /\s#include\s+"([./][^\\"]+)"/gm; + + /** + * @internal + */ + static _loadChunksInCode(code: string, basePath: string, resourceManager: ResourceManager): Promise { + const shaderChunkPaths = new Array(); + const matches = code.matchAll(ShaderChunkLoader._shaderIncludeRegex); + for (const match of matches) { + const chunkPath = Utils.resolveAbsoluteUrl(basePath, match[1]); + if (!ShaderLib[chunkPath.substring(1)]) { + shaderChunkPaths.push(chunkPath); + } + } + + return Promise.all( + shaderChunkPaths.map((chunkPath) => { + return resourceManager.load({ + type: "ShaderChunk", + url: chunkPath + }); + }) + ); + } + + load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { + const { url } = item; + + return this.request(url, resourceManager, { ...item, type: "text" }).then((code) => { + ShaderFactory.registerInclude(url.substring(1), code); + + return ShaderChunkLoader._loadChunksInCode(code, url, resourceManager); + }); + } +} diff --git a/packages/loader/src/ShaderLoader.ts b/packages/loader/src/ShaderLoader.ts new file mode 100644 index 0000000000..00795eec6e --- /dev/null +++ b/packages/loader/src/ShaderLoader.ts @@ -0,0 +1,38 @@ +import { + AssetPromise, + AssetType, + LoadItem, + Loader, + ResourceManager, + Shader, + resourceLoader +} from "@galacean/engine-core"; +import { ShaderChunkLoader } from "./ShaderChunkLoader"; + +@resourceLoader(AssetType.Shader, ["gs", "gsl"]) +class ShaderLoader extends Loader { + private static _builtinRegex = /^\s*\/\/\s*@builtin\s+(\w+)/; + + load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { + const { url } = item; + + return this.request(url, resourceManager, { ...item, type: "text" }).then((code: string) => { + const builtinShader = this._getBuiltinShader(code); + if (builtinShader) { + return Shader.find(builtinShader); + } + + return ShaderChunkLoader._loadChunksInCode(code, url, resourceManager).then(() => { + const shader = Shader.create(code); + // @ts-ignore + shader._registerPath(url); + return shader; + }); + }); + } + + private _getBuiltinShader(code: string) { + const match = code.match(ShaderLoader._builtinRegex); + if (match && match[1]) return match[1]; + } +} diff --git a/packages/loader/src/SourceFontLoader.ts b/packages/loader/src/SourceFontLoader.ts index ee8549560b..5a86000000 100644 --- a/packages/loader/src/SourceFontLoader.ts +++ b/packages/loader/src/SourceFontLoader.ts @@ -12,7 +12,8 @@ import { class SourceFontLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - const { url } = item; + // @ts-ignore + const url = resourceManager._virtualPathMap[item.url] ?? item.url; this._registerFont(url, url) .then(() => { const font = new Font(resourceManager.engine, url); diff --git a/packages/loader/src/SpriteAtlasLoader.ts b/packages/loader/src/SpriteAtlasLoader.ts index 270773143b..34424d6991 100644 --- a/packages/loader/src/SpriteAtlasLoader.ts +++ b/packages/loader/src/SpriteAtlasLoader.ts @@ -27,7 +27,7 @@ class SpriteAtlasLoader extends Loader { chainPromises[i].cancel(); } }); - const configPromise = this.request(item.url, { + const configPromise = this.request(item.url, resourceManager, { ...item, type: "json" }); diff --git a/packages/loader/src/SpriteLoader.ts b/packages/loader/src/SpriteLoader.ts index f1aae8e423..ebeca92d16 100644 --- a/packages/loader/src/SpriteLoader.ts +++ b/packages/loader/src/SpriteLoader.ts @@ -13,7 +13,7 @@ import { @resourceLoader(AssetType.Sprite, ["sprite"], false) class SpriteLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { - return this.request(item.url, { + return this.request(item.url, resourceManager, { ...item, type: "json" }).then((data) => { diff --git a/packages/loader/src/TextLoader.ts b/packages/loader/src/TextLoader.ts index 1ea1b87feb..9483042a76 100644 --- a/packages/loader/src/TextLoader.ts +++ b/packages/loader/src/TextLoader.ts @@ -1,9 +1,9 @@ -import { resourceLoader, Loader, AssetPromise, AssetType, LoadItem } from "@galacean/engine-core"; +import { resourceLoader, Loader, AssetPromise, AssetType, LoadItem, ResourceManager } from "@galacean/engine-core"; @resourceLoader(AssetType.Text, ["txt"], false) class TextLoader extends Loader { - load(item: LoadItem): AssetPromise { - return this.request(item.url, { + load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { + return this.request(item.url, resourceManager, { ...item, type: "text" }); diff --git a/packages/loader/src/Texture2DLoader.ts b/packages/loader/src/Texture2DLoader.ts index 71425b9a32..9041d85f35 100644 --- a/packages/loader/src/Texture2DLoader.ts +++ b/packages/loader/src/Texture2DLoader.ts @@ -22,7 +22,7 @@ class Texture2DLoader extends Loader { ...item, type: "image" }; - this.request(url, requestConfig) + this.request(url, resourceManager, requestConfig) .onProgress(setTaskCompleteProgress, setTaskDetailProgress) .then((image) => { const { format, mipmap, anisoLevel, wrapModeU, wrapModeV, filterMode } = diff --git a/packages/loader/src/TextureCubeLoader.ts b/packages/loader/src/TextureCubeLoader.ts index 2977a2f93e..a20188b648 100644 --- a/packages/loader/src/TextureCubeLoader.ts +++ b/packages/loader/src/TextureCubeLoader.ts @@ -21,7 +21,7 @@ class TextureCubeLoader extends Loader { type: "image" }; - Promise.all(urls.map((url) => this.request(url, requestConfig))) + Promise.all(urls.map((url) => this.request(url, resourceManager, requestConfig))) .then((images) => { const { width, height } = images[0]; diff --git a/packages/loader/src/gltf/parser/GLTFBufferParser.ts b/packages/loader/src/gltf/parser/GLTFBufferParser.ts index 92222e836c..a5576df29f 100644 --- a/packages/loader/src/gltf/parser/GLTFBufferParser.ts +++ b/packages/loader/src/gltf/parser/GLTFBufferParser.ts @@ -16,9 +16,11 @@ export class GLTFBufferParser extends GLTFParser { private _parseSingleBuffer(context: GLTFParserContext, bufferInfo: IBuffer): Promise { const { glTFResource, contentRestorer } = context; const url = glTFResource.url; + // @ts-ignore + const remoteUrl = context.resourceManager._virtualPathMap[url] ?? url; const restoreBufferRequests = contentRestorer.bufferRequests; const requestConfig = { type: "arraybuffer" }; - const absoluteUrl = Utils.resolveAbsoluteUrl(url, bufferInfo.uri); + const absoluteUrl = Utils.resolveAbsoluteUrl(remoteUrl, bufferInfo.uri); restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig)); const promise = request(absoluteUrl, requestConfig).onProgress(undefined, context._onTaskDetail); diff --git a/packages/loader/src/gltf/parser/GLTFSchemaParser.ts b/packages/loader/src/gltf/parser/GLTFSchemaParser.ts index 919b3f9921..8b43e975c0 100644 --- a/packages/loader/src/gltf/parser/GLTFSchemaParser.ts +++ b/packages/loader/src/gltf/parser/GLTFSchemaParser.ts @@ -13,10 +13,12 @@ export class GLTFSchemaParser extends GLTFParser { const url = glTFResource.url; const restoreBufferRequests = contentRestorer.bufferRequests; const requestConfig = { type: "arraybuffer" }; - return request(url, requestConfig) + // @ts-ignore + const remoteUrl = context.resourceManager._virtualPathMap[url] ?? url; + return request(remoteUrl, requestConfig) .onProgress(undefined, context._onTaskDetail) .then((buffer) => { - restoreBufferRequests.push(new BufferRequestInfo(url, requestConfig)); + restoreBufferRequests.push(new BufferRequestInfo(remoteUrl, requestConfig)); return GLTFUtils.parseGLB(context, buffer); }) .then((result) => { diff --git a/packages/loader/src/index.ts b/packages/loader/src/index.ts index b1da2b95ee..8c937a6e75 100644 --- a/packages/loader/src/index.ts +++ b/packages/loader/src/index.ts @@ -10,7 +10,6 @@ import "./JSONLoader"; import "./KTXCubeLoader"; import "./KTXLoader"; import "./MaterialLoader"; -import "./MeshLoader"; import "./PrimitiveMeshLoader"; import "./ProjectLoader"; import "./SourceFontLoader"; @@ -19,6 +18,8 @@ import "./SpriteLoader"; import "./Texture2DLoader"; import "./TextureCubeLoader"; import "./ktx2/KTX2Loader"; +import "./ShaderLoader"; +import "./ShaderChunkLoader"; export { GLTFLoader } from "./GLTFLoader"; export type { GLTFParams } from "./GLTFLoader"; diff --git a/packages/loader/src/ktx2/KTX2Loader.ts b/packages/loader/src/ktx2/KTX2Loader.ts index 511851d4bf..bd867b2027 100644 --- a/packages/loader/src/ktx2/KTX2Loader.ts +++ b/packages/loader/src/ktx2/KTX2Loader.ts @@ -221,7 +221,7 @@ export class KTX2Loader extends Loader { resourceManager: ResourceManager ): AssetPromise { return new AssetPromise((resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) => { - this.request(item.url, { type: "arraybuffer" }) + this.request(item.url, resourceManager, { type: "arraybuffer" }) .onProgress(setTaskCompleteProgress, setTaskDetailProgress) .then((buffer) => KTX2Loader._parseBuffer(new Uint8Array(buffer), resourceManager.engine, item.params).then( diff --git a/packages/loader/src/resource-deserialize/index.ts b/packages/loader/src/resource-deserialize/index.ts index 67531f3e90..b739322030 100644 --- a/packages/loader/src/resource-deserialize/index.ts +++ b/packages/loader/src/resource-deserialize/index.ts @@ -26,7 +26,6 @@ export function decode(arrayBuffer: ArrayBuffer, engine: Engine): Promise export * from "./resources/schema"; export * from "./resources/scene/SceneParser"; -export * from "./resources/scene/MeshLoader"; export * from "./resources/scene/EditorTextureLoader"; export * from "./resources/parser/ParserContext"; diff --git a/packages/loader/src/resource-deserialize/resources/scene/EditorTextureLoader.ts b/packages/loader/src/resource-deserialize/resources/scene/EditorTextureLoader.ts index 5a4d2ad197..09403013a7 100644 --- a/packages/loader/src/resource-deserialize/resources/scene/EditorTextureLoader.ts +++ b/packages/loader/src/resource-deserialize/resources/scene/EditorTextureLoader.ts @@ -5,7 +5,7 @@ import { decode } from "../.."; export class EditorTextureLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, { ...item, type: "arraybuffer" }) + this.request(item.url, resourceManager, { ...item, type: "arraybuffer" }) .then((data) => { decode(data, resourceManager.engine).then((texture) => { resolve(texture); diff --git a/packages/loader/src/resource-deserialize/resources/scene/MeshLoader.ts b/packages/loader/src/resource-deserialize/resources/scene/MeshLoader.ts deleted file mode 100644 index 6618847eb9..0000000000 --- a/packages/loader/src/resource-deserialize/resources/scene/MeshLoader.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { AssetPromise, Loader, LoadItem, ModelMesh, resourceLoader, ResourceManager } from "@galacean/engine-core"; -import { decode } from "../.."; - -@resourceLoader("Mesh", ["prefab"], true) -export class MeshLoader extends Loader { - load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { - return new AssetPromise((resolve, reject) => { - this.request(item.url, { ...item, type: "arraybuffer" }) - .then((data) => { - decode(data, resourceManager.engine).then((mesh) => { - resolve(mesh); - }); - }) - .catch(reject); - }); - } -} diff --git a/packages/loader/src/resource-deserialize/resources/schema/MaterialSchema.ts b/packages/loader/src/resource-deserialize/resources/schema/MaterialSchema.ts index 377ea86126..f2f6012918 100644 --- a/packages/loader/src/resource-deserialize/resources/schema/MaterialSchema.ts +++ b/packages/loader/src/resource-deserialize/resources/schema/MaterialSchema.ts @@ -90,10 +90,22 @@ export interface IMaterialSchema { shader: string; shaderData: { [key: string]: { - type: "Vector2" | "Vector3" | "Vector4" | "Color" | "Float" | "Texture" | "Boolean" | "Integer"; + type: MaterialLoaderType; value: IVector3 | IVector2 | IColor | number | IAssetRef; }; }; macros: Array<{ name: string; value?: string }>; renderState: IRenderState; + shaderRef: IAssetRef; +} + +export enum MaterialLoaderType { + Vector2 = "Vector2", + Vector3 = "Vector3", + Vector4 = "Vector4", + Color = "Color", + Float = "Float", + Texture = "Texture", + Boolean = "Boolean", + Integer = "Integer" } diff --git a/packages/xr/src/loader/XRReferenceImageLoader.ts b/packages/xr/src/loader/XRReferenceImageLoader.ts index 91f39db554..a6681b8cbb 100644 --- a/packages/xr/src/loader/XRReferenceImageLoader.ts +++ b/packages/xr/src/loader/XRReferenceImageLoader.ts @@ -5,7 +5,7 @@ import { XRReferenceImage } from "../feature/trackable/image/XRReferenceImage"; export class XRReferenceImageLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, { ...item, type: "arraybuffer" }) + this.request(item.url, resourceManager, { ...item, type: "arraybuffer" }) .then((data) => { decode(data, resourceManager.engine).then((referenceImage) => { resolve(referenceImage); From 88501aa84d46811d836b9ceb6af5889cbeb5f7dc Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Wed, 6 Nov 2024 23:21:03 +0800 Subject: [PATCH 05/15] chore: release v1.3.17 --- e2e/package.json | 2 +- package.json | 2 +- packages/core/package.json | 2 +- packages/design/package.json | 2 +- packages/galacean/package.json | 2 +- packages/loader/package.json | 2 +- packages/math/package.json | 2 +- packages/physics-lite/package.json | 2 +- packages/physics-physx/package.json | 2 +- packages/rhi-webgl/package.json | 2 +- packages/shader-lab/package.json | 2 +- packages/xr-webxr/package.json | 2 +- packages/xr/package.json | 2 +- tests/package.json | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/e2e/package.json b/e2e/package.json index 4e44d8d23b..0c96180e1c 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -1,7 +1,7 @@ { "name": "@galacean/engine-e2e", "private": true, - "version": "1.3.16", + "version": "1.3.17", "license": "MIT", "scripts": { "case": "vite serve .dev --config .dev/vite.config.js", diff --git a/package.json b/package.json index 1dff6bd63e..c071484d45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-root", - "version": "1.3.16", + "version": "1.3.17", "packageManager": "pnpm@9.3.0", "private": true, "scripts": { diff --git a/packages/core/package.json b/packages/core/package.json index cf2c3ee3e9..4d9588b99b 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-core", - "version": "1.3.16", + "version": "1.3.17", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/design/package.json b/packages/design/package.json index 4f82b2b99b..5334da2bb0 100644 --- a/packages/design/package.json +++ b/packages/design/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-design", - "version": "1.3.16", + "version": "1.3.17", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/galacean/package.json b/packages/galacean/package.json index d63f585afe..9fa23772da 100644 --- a/packages/galacean/package.json +++ b/packages/galacean/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine", - "version": "1.3.16", + "version": "1.3.17", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/loader/package.json b/packages/loader/package.json index e2b5ed4b00..40fef0772a 100644 --- a/packages/loader/package.json +++ b/packages/loader/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-loader", - "version": "1.3.16", + "version": "1.3.17", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/math/package.json b/packages/math/package.json index c47e1379dc..61fce3811b 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-math", - "version": "1.3.16", + "version": "1.3.17", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/physics-lite/package.json b/packages/physics-lite/package.json index 16c484c7b8..3c842c4d60 100644 --- a/packages/physics-lite/package.json +++ b/packages/physics-lite/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-physics-lite", - "version": "1.3.16", + "version": "1.3.17", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/physics-physx/package.json b/packages/physics-physx/package.json index adbdb890b0..739568a12b 100644 --- a/packages/physics-physx/package.json +++ b/packages/physics-physx/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-physics-physx", - "version": "1.3.16", + "version": "1.3.17", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/rhi-webgl/package.json b/packages/rhi-webgl/package.json index 6ba5fb6b9b..bf8c1d2d5d 100644 --- a/packages/rhi-webgl/package.json +++ b/packages/rhi-webgl/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-rhi-webgl", - "version": "1.3.16", + "version": "1.3.17", "repository": { "url": "https://github.com/galacean/engine.git" }, diff --git a/packages/shader-lab/package.json b/packages/shader-lab/package.json index 109d789976..a4615529da 100644 --- a/packages/shader-lab/package.json +++ b/packages/shader-lab/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-shader-lab", - "version": "1.3.16", + "version": "1.3.17", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/xr-webxr/package.json b/packages/xr-webxr/package.json index 374dc9b47e..d5c3592b2e 100644 --- a/packages/xr-webxr/package.json +++ b/packages/xr-webxr/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-xr-webxr", - "version": "1.3.16", + "version": "1.3.17", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/xr/package.json b/packages/xr/package.json index cc6fbcefce..5bc3644bbe 100644 --- a/packages/xr/package.json +++ b/packages/xr/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-xr", - "version": "1.3.16", + "version": "1.3.17", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/tests/package.json b/tests/package.json index a1ca75686b..ff440490c4 100644 --- a/tests/package.json +++ b/tests/package.json @@ -1,7 +1,7 @@ { "name": "@galacean/engine-tests", "private": true, - "version": "1.3.16", + "version": "1.3.17", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", From 85a44eb800529e4f91602348bba3b09d922ab4b8 Mon Sep 17 00:00:00 2001 From: SwayYan Date: Thu, 7 Nov 2024 12:03:32 +0800 Subject: [PATCH 06/15] Add mesh loader (#2426) * feat: add mesh loader --- packages/loader/src/MeshLoader.ts | 29 +++++++++++++++++++++++++++++ packages/loader/src/index.ts | 1 + 2 files changed, 30 insertions(+) create mode 100644 packages/loader/src/MeshLoader.ts diff --git a/packages/loader/src/MeshLoader.ts b/packages/loader/src/MeshLoader.ts new file mode 100644 index 0000000000..357e55b4a6 --- /dev/null +++ b/packages/loader/src/MeshLoader.ts @@ -0,0 +1,29 @@ +import { + resourceLoader, + Loader, + AssetPromise, + AssetType, + LoadItem, + ResourceManager, + ModelMesh +} from "@galacean/engine-core"; +import { decode } from "./resource-deserialize"; + +@resourceLoader(AssetType.Mesh, ["mesh"]) +class MeshLoader extends Loader { + load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { + return new AssetPromise((resolve, reject) => { + this.request(item.url, resourceManager, { + ...item, + type: "arraybuffer" + }) + .then((data) => { + return decode(data, resourceManager.engine); + }) + .then((mesh) => { + resolve(mesh); + }) + .catch(reject); + }); + } +} diff --git a/packages/loader/src/index.ts b/packages/loader/src/index.ts index 8c937a6e75..a91a14ff7a 100644 --- a/packages/loader/src/index.ts +++ b/packages/loader/src/index.ts @@ -10,6 +10,7 @@ import "./JSONLoader"; import "./KTXCubeLoader"; import "./KTXLoader"; import "./MaterialLoader"; +import "./MeshLoader"; import "./PrimitiveMeshLoader"; import "./ProjectLoader"; import "./SourceFontLoader"; From 4c0cfd05c306152e40a7c3c04502f55a2ed1eae9 Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Thu, 7 Nov 2024 12:04:04 +0800 Subject: [PATCH 07/15] chore: release v1.3.18 --- e2e/package.json | 2 +- package.json | 2 +- packages/core/package.json | 2 +- packages/design/package.json | 2 +- packages/galacean/package.json | 2 +- packages/loader/package.json | 2 +- packages/math/package.json | 2 +- packages/physics-lite/package.json | 2 +- packages/physics-physx/package.json | 2 +- packages/rhi-webgl/package.json | 2 +- packages/shader-lab/package.json | 2 +- packages/xr-webxr/package.json | 2 +- packages/xr/package.json | 2 +- tests/package.json | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/e2e/package.json b/e2e/package.json index 0c96180e1c..c927742131 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -1,7 +1,7 @@ { "name": "@galacean/engine-e2e", "private": true, - "version": "1.3.17", + "version": "1.3.18", "license": "MIT", "scripts": { "case": "vite serve .dev --config .dev/vite.config.js", diff --git a/package.json b/package.json index c071484d45..3a617722a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-root", - "version": "1.3.17", + "version": "1.3.18", "packageManager": "pnpm@9.3.0", "private": true, "scripts": { diff --git a/packages/core/package.json b/packages/core/package.json index 4d9588b99b..2dd471f6f9 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-core", - "version": "1.3.17", + "version": "1.3.18", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/design/package.json b/packages/design/package.json index 5334da2bb0..e4ef17159d 100644 --- a/packages/design/package.json +++ b/packages/design/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-design", - "version": "1.3.17", + "version": "1.3.18", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/galacean/package.json b/packages/galacean/package.json index 9fa23772da..913707b6a3 100644 --- a/packages/galacean/package.json +++ b/packages/galacean/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine", - "version": "1.3.17", + "version": "1.3.18", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/loader/package.json b/packages/loader/package.json index 40fef0772a..1469055bd5 100644 --- a/packages/loader/package.json +++ b/packages/loader/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-loader", - "version": "1.3.17", + "version": "1.3.18", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/math/package.json b/packages/math/package.json index 61fce3811b..aec943e673 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-math", - "version": "1.3.17", + "version": "1.3.18", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/physics-lite/package.json b/packages/physics-lite/package.json index 3c842c4d60..a9d892d336 100644 --- a/packages/physics-lite/package.json +++ b/packages/physics-lite/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-physics-lite", - "version": "1.3.17", + "version": "1.3.18", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/physics-physx/package.json b/packages/physics-physx/package.json index 739568a12b..6f667c70eb 100644 --- a/packages/physics-physx/package.json +++ b/packages/physics-physx/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-physics-physx", - "version": "1.3.17", + "version": "1.3.18", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/rhi-webgl/package.json b/packages/rhi-webgl/package.json index bf8c1d2d5d..317fdfd58b 100644 --- a/packages/rhi-webgl/package.json +++ b/packages/rhi-webgl/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-rhi-webgl", - "version": "1.3.17", + "version": "1.3.18", "repository": { "url": "https://github.com/galacean/engine.git" }, diff --git a/packages/shader-lab/package.json b/packages/shader-lab/package.json index a4615529da..a1059b1225 100644 --- a/packages/shader-lab/package.json +++ b/packages/shader-lab/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-shader-lab", - "version": "1.3.17", + "version": "1.3.18", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/xr-webxr/package.json b/packages/xr-webxr/package.json index d5c3592b2e..0374fd238a 100644 --- a/packages/xr-webxr/package.json +++ b/packages/xr-webxr/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-xr-webxr", - "version": "1.3.17", + "version": "1.3.18", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/xr/package.json b/packages/xr/package.json index 5bc3644bbe..4579a9f7e2 100644 --- a/packages/xr/package.json +++ b/packages/xr/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-xr", - "version": "1.3.17", + "version": "1.3.18", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/tests/package.json b/tests/package.json index ff440490c4..64a59a417b 100644 --- a/tests/package.json +++ b/tests/package.json @@ -1,7 +1,7 @@ { "name": "@galacean/engine-tests", "private": true, - "version": "1.3.17", + "version": "1.3.18", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", From 65594f017720c833db022cd2fd28a67f1238e32b Mon Sep 17 00:00:00 2001 From: SwayYan Date: Thu, 7 Nov 2024 15:22:05 +0800 Subject: [PATCH 08/15] Fix shaderlab loader in NPM mode (#2427) * fix: npm package loader shader bug --- packages/loader/src/MaterialLoader.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/loader/src/MaterialLoader.ts b/packages/loader/src/MaterialLoader.ts index c58cba8d12..fe496eedf6 100644 --- a/packages/loader/src/MaterialLoader.ts +++ b/packages/loader/src/MaterialLoader.ts @@ -42,25 +42,23 @@ class MaterialLoader extends Loader { .then((materialSchema: IMaterialSchema) => { const engine = resourceManager.engine; const { shaderRef, shader: shaderName } = materialSchema; - - if (shaderRef) { + const shader = Shader.find(shaderName); + if (shader) { + resolve(this._getMaterialByShader(materialSchema, shader, engine)); + } else if (shaderRef) { resolve( resourceManager // @ts-ignore .getResourceByRef(shaderRef) - .then((shader) => this.getMaterialByShader(materialSchema, shader, engine)) + .then((shader) => this._getMaterialByShader(materialSchema, shader, engine)) ); - } else { - // compatible with 1.2-pre version material schema - const shader = Shader.find(shaderName); - resolve(this.getMaterialByShader(materialSchema, shader, engine)); } }) .catch(reject); }); } - private getMaterialByShader(materialSchema: IMaterialSchema, shader: Shader, engine: Engine): Promise { + private _getMaterialByShader(materialSchema: IMaterialSchema, shader: Shader, engine: Engine): Promise { const { name, shaderData, macros, renderState } = materialSchema; const material = new Material(engine, shader); From bfebffd41b1f93b903fa17715b70e14b392b4a84 Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Thu, 7 Nov 2024 15:25:18 +0800 Subject: [PATCH 09/15] chore: release v1.3.19 --- e2e/package.json | 2 +- package.json | 2 +- packages/core/package.json | 2 +- packages/design/package.json | 2 +- packages/galacean/package.json | 2 +- packages/loader/package.json | 2 +- packages/math/package.json | 2 +- packages/physics-lite/package.json | 2 +- packages/physics-physx/package.json | 2 +- packages/rhi-webgl/package.json | 2 +- packages/shader-lab/package.json | 2 +- packages/xr-webxr/package.json | 2 +- packages/xr/package.json | 2 +- tests/package.json | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/e2e/package.json b/e2e/package.json index c927742131..0f3e5540b0 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -1,7 +1,7 @@ { "name": "@galacean/engine-e2e", "private": true, - "version": "1.3.18", + "version": "1.3.19", "license": "MIT", "scripts": { "case": "vite serve .dev --config .dev/vite.config.js", diff --git a/package.json b/package.json index 3a617722a6..a31b984e28 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-root", - "version": "1.3.18", + "version": "1.3.19", "packageManager": "pnpm@9.3.0", "private": true, "scripts": { diff --git a/packages/core/package.json b/packages/core/package.json index 2dd471f6f9..13697c8736 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-core", - "version": "1.3.18", + "version": "1.3.19", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/design/package.json b/packages/design/package.json index e4ef17159d..c76bdb6944 100644 --- a/packages/design/package.json +++ b/packages/design/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-design", - "version": "1.3.18", + "version": "1.3.19", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/galacean/package.json b/packages/galacean/package.json index 913707b6a3..bbd2c05316 100644 --- a/packages/galacean/package.json +++ b/packages/galacean/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine", - "version": "1.3.18", + "version": "1.3.19", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/loader/package.json b/packages/loader/package.json index 1469055bd5..94140e32e0 100644 --- a/packages/loader/package.json +++ b/packages/loader/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-loader", - "version": "1.3.18", + "version": "1.3.19", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/math/package.json b/packages/math/package.json index aec943e673..77b7ae8a03 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-math", - "version": "1.3.18", + "version": "1.3.19", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/physics-lite/package.json b/packages/physics-lite/package.json index a9d892d336..8b158572a6 100644 --- a/packages/physics-lite/package.json +++ b/packages/physics-lite/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-physics-lite", - "version": "1.3.18", + "version": "1.3.19", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/physics-physx/package.json b/packages/physics-physx/package.json index 6f667c70eb..bdc9c0b443 100644 --- a/packages/physics-physx/package.json +++ b/packages/physics-physx/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-physics-physx", - "version": "1.3.18", + "version": "1.3.19", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/rhi-webgl/package.json b/packages/rhi-webgl/package.json index 317fdfd58b..3ee2ad6f82 100644 --- a/packages/rhi-webgl/package.json +++ b/packages/rhi-webgl/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-rhi-webgl", - "version": "1.3.18", + "version": "1.3.19", "repository": { "url": "https://github.com/galacean/engine.git" }, diff --git a/packages/shader-lab/package.json b/packages/shader-lab/package.json index a1059b1225..de4f5b658e 100644 --- a/packages/shader-lab/package.json +++ b/packages/shader-lab/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-shader-lab", - "version": "1.3.18", + "version": "1.3.19", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/xr-webxr/package.json b/packages/xr-webxr/package.json index 0374fd238a..e551d487ec 100644 --- a/packages/xr-webxr/package.json +++ b/packages/xr-webxr/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-xr-webxr", - "version": "1.3.18", + "version": "1.3.19", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/xr/package.json b/packages/xr/package.json index 4579a9f7e2..dc202444be 100644 --- a/packages/xr/package.json +++ b/packages/xr/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-xr", - "version": "1.3.18", + "version": "1.3.19", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/tests/package.json b/tests/package.json index 64a59a417b..2a3471e40c 100644 --- a/tests/package.json +++ b/tests/package.json @@ -1,7 +1,7 @@ { "name": "@galacean/engine-tests", "private": true, - "version": "1.3.18", + "version": "1.3.19", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js", From fc35b0243b244ff83f1dea9a6df0b7830d9efc7b Mon Sep 17 00:00:00 2001 From: singlecoder Date: Thu, 7 Nov 2024 16:16:50 +0800 Subject: [PATCH 10/15] Add function copy to vector link object for vector (#2428) * feat(math): add copy to vector link object for vector --- packages/math/src/Color.ts | 13 +++++++++++++ packages/math/src/ICopy.ts | 6 ++++++ packages/math/src/Quaternion.ts | 13 +++++++++++++ packages/math/src/Vector2.ts | 11 +++++++++++ packages/math/src/Vector3.ts | 12 ++++++++++++ packages/math/src/Vector4.ts | 13 +++++++++++++ tests/src/math/Color.test.ts | 8 ++++++++ tests/src/math/Quaternion.test.ts | 7 +++++++ tests/src/math/Vector2.test.ts | 7 +++++++ tests/src/math/Vector3.test.ts | 7 +++++++ tests/src/math/Vector4.test.ts | 7 +++++++ 11 files changed, 104 insertions(+) diff --git a/packages/math/src/Color.ts b/packages/math/src/Color.ts index 018ff3ad85..cb67fa1c26 100644 --- a/packages/math/src/Color.ts +++ b/packages/math/src/Color.ts @@ -258,6 +258,19 @@ export class Color implements IClone, ICopy { return this; } + /** + * Copy to color like object. + * @param target - Color like object. + * @returns This Color like object + */ + copyTo(target: ColorLike): ColorLike { + target.r = this._r; + target.g = this._g; + target.b = this._b; + target.a = this._a; + return target; + } + /** * Copy from array like object. * @param source - Array like object diff --git a/packages/math/src/ICopy.ts b/packages/math/src/ICopy.ts index ac0f210c5e..0bf4d12122 100644 --- a/packages/math/src/ICopy.ts +++ b/packages/math/src/ICopy.ts @@ -7,4 +7,10 @@ export interface ICopy { * @returns This object */ copyFrom(source: S): T; + + /** + * Copy to target object. + * @returns This target object + */ + copyTo?(target: S): S; } diff --git a/packages/math/src/Quaternion.ts b/packages/math/src/Quaternion.ts index 0b396ae89a..112dcc12db 100644 --- a/packages/math/src/Quaternion.ts +++ b/packages/math/src/Quaternion.ts @@ -730,6 +730,19 @@ export class Quaternion implements IClone, ICopy, ICopy { return this; } + /** + * Copy to vector2 like object. + * @param target - Vector2 like object + * @returns This Vector2 like object + */ + copyTo(target: Vector2Like): Vector2Like { + target.x = this._x; + target.y = this._y; + return target; + } + /** * Copy the value of this vector from an array. * @param array - The array diff --git a/packages/math/src/Vector3.ts b/packages/math/src/Vector3.ts index a5eec72e9b..db6f2cb9f5 100644 --- a/packages/math/src/Vector3.ts +++ b/packages/math/src/Vector3.ts @@ -561,6 +561,18 @@ export class Vector3 implements IClone, ICopy { return this; } + /** + * Copy to vector3 like object. + * @param target - Vector3 like object + * @returns This Vector3 like object + */ + copyTo(target: Vector3Like): Vector3Like { + target.x = this._x; + target.y = this._y; + target.z = this._z; + return target; + } + /** * Copy the value of this vector from an array. * @param array - The array diff --git a/packages/math/src/Vector4.ts b/packages/math/src/Vector4.ts index 7328b3b09f..7884f8330d 100644 --- a/packages/math/src/Vector4.ts +++ b/packages/math/src/Vector4.ts @@ -477,6 +477,19 @@ export class Vector4 implements IClone, ICopy { return this; } + /** + * Copy to vector4 like object. + * @param target - Vector4 like object + * @returns This Vector4 like object + */ + copyTo(target: Vector4Like): Vector4Like { + target.x = this._x; + target.y = this._y; + target.z = this._z; + target.w = this._w; + return target; + } + /** * Copy the value of this vector by an array. * @param array - The array diff --git a/tests/src/math/Color.test.ts b/tests/src/math/Color.test.ts index 8fb93561ba..9c961b091d 100644 --- a/tests/src/math/Color.test.ts +++ b/tests/src/math/Color.test.ts @@ -58,6 +58,14 @@ describe("Color test", () => { expect(Color.equals(a, out)).to.eq(true); }); + it("copyTo", () => { + const a = new Color(1, 0, 0, 1); + const out = new Color(); + + a.copyTo(out); + expect(Color.equals(a, out)).to.eq(true); + }); + it("copyFromArray", () => { const a = new Color(); const b = new Color(0, 0, 1, 1); diff --git a/tests/src/math/Quaternion.test.ts b/tests/src/math/Quaternion.test.ts index 49e81e8ff2..a2b2bdec3a 100644 --- a/tests/src/math/Quaternion.test.ts +++ b/tests/src/math/Quaternion.test.ts @@ -261,6 +261,13 @@ describe("Quaternion test", () => { expect(toString(a)).to.eq(toString(out)); }); + it("copyTo", () => { + const a = new Quaternion(3, 4, 5, 0); + const out = new Quaternion(); + a.copyTo(out); + expect(toString(a)).to.eq(toString(out)); + }); + it("conjugate", () => { const a = new Quaternion(1, 1, 1, 1); expect(toString(a.conjugate())).to.eq("quat(-1, -1, -1, 1)"); diff --git a/tests/src/math/Vector2.test.ts b/tests/src/math/Vector2.test.ts index a51779a8d7..fdcf0dda3b 100644 --- a/tests/src/math/Vector2.test.ts +++ b/tests/src/math/Vector2.test.ts @@ -148,6 +148,13 @@ describe("Vector2 test", () => { expect(toString(a)).to.eq(toString(out)); }); + it("copyTo", () => { + const a = new Vector2(3, 4); + const out = new Vector2(); + a.copyTo(out); + expect(toString(a)).to.eq(toString(out)); + }); + it("add", () => { const a = new Vector2(3, 4); const ret = new Vector2(1, 2); diff --git a/tests/src/math/Vector3.test.ts b/tests/src/math/Vector3.test.ts index 60640f8f9a..9a9c0d6b57 100644 --- a/tests/src/math/Vector3.test.ts +++ b/tests/src/math/Vector3.test.ts @@ -176,6 +176,13 @@ describe("Vector3 test", () => { expect(toString(a)).to.eq(toString(out)); }); + it("copyTo", () => { + const a = new Vector3(3, 4, 5); + const out = new Vector3(); + a.copyTo(out); + expect(toString(a)).to.eq(toString(out)); + }); + it("add", () => { const a = new Vector3(3, 4, 5); const ret = new Vector3(1, 2, 4); diff --git a/tests/src/math/Vector4.test.ts b/tests/src/math/Vector4.test.ts index 8163141924..0f41d34739 100644 --- a/tests/src/math/Vector4.test.ts +++ b/tests/src/math/Vector4.test.ts @@ -158,6 +158,13 @@ describe("Vector4 test", () => { expect(toString(a)).to.eq(toString(out)); }); + it("copyTo", () => { + const a = new Vector4(3, 4, 5, 0); + const out = new Vector4(); + a.copyTo(out); + expect(toString(a)).to.eq(toString(out)); + }); + it("add", () => { const a = new Vector4(3, 4, 5, 1); const ret = new Vector4(1, 2, 4, 1); From 4fe788f97a6eeff41f40fefd71f9bada2c4e7c2b Mon Sep 17 00:00:00 2001 From: "JTabibito(Ji Lin)" <34726874+jtabibito@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:28:41 +0800 Subject: [PATCH 11/15] Add unit test case of `ParticleRenderer` and fix particle destroy bug (#2285) * test: add unit test case of `ParticleRenderer` * fix: particle renderer destroy bug --------- Co-authored-by: GuoLei1990 --- .../core/src/particle/ParticleRenderer.ts | 2 +- .../core/particle/ParticleRenderer.test.ts | 94 +++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 tests/src/core/particle/ParticleRenderer.test.ts diff --git a/packages/core/src/particle/ParticleRenderer.ts b/packages/core/src/particle/ParticleRenderer.ts index a03b357191..5bb7b51da4 100644 --- a/packages/core/src/particle/ParticleRenderer.ts +++ b/packages/core/src/particle/ParticleRenderer.ts @@ -233,11 +233,11 @@ export class ParticleRenderer extends Renderer { } protected override _onDestroy(): void { - super._onDestroy(); const mesh = this._mesh; if (mesh) { mesh.destroyed || this._addResourceReferCount(mesh, -1); } + super._onDestroy(); this.generator._destroy(); } diff --git a/tests/src/core/particle/ParticleRenderer.test.ts b/tests/src/core/particle/ParticleRenderer.test.ts new file mode 100644 index 0000000000..fd26b7270f --- /dev/null +++ b/tests/src/core/particle/ParticleRenderer.test.ts @@ -0,0 +1,94 @@ +import { WebGLEngine } from "@galacean/engine-rhi-webgl"; +import { Camera, ParticleRenderer, ModelMesh, Scene, ParticleRenderMode } from "@galacean/engine-core"; +import { beforeAll, describe, expect, it } from "vitest"; + +describe("ParticleRenderer", () => { + let engine: WebGLEngine; + let scene: Scene; + + beforeAll(async function () { + engine = await WebGLEngine.create({ + canvas: document.createElement("canvas") + }); + engine.canvas.resizeByClientSize(); + + scene = engine.sceneManager.activeScene; + const rootEntity = scene.createRootEntity("root"); + + const cameraEntity = rootEntity.createChild("Camera"); + cameraEntity.addComponent(Camera); + cameraEntity.transform.setPosition(0, 0, 10); + + engine.run(); + }); + + it("ParticleRenderer lengthScale", () => { + const renderer = scene.createRootEntity("Renderer").addComponent(ParticleRenderer); + renderer.lengthScale = 1; + expect(renderer.lengthScale).to.eq(1); + renderer.lengthScale = -0.333333; + expect(renderer.lengthScale).to.eq(-0.333333); + renderer.lengthScale = 0; + expect(renderer.lengthScale).to.eq(0); + }); + + it("ParticleRenderer velocityScale", () => { + const renderer = scene.createRootEntity("Renderer").addComponent(ParticleRenderer); + renderer.velocityScale = 1.333393; + expect(renderer.velocityScale).to.eq(1.333393); + renderer.velocityScale = -0.333333; + expect(renderer.velocityScale).to.eq(-0.333333); + renderer.velocityScale = 0; + expect(renderer.velocityScale).to.eq(0); + }); + + it("ParticleRenderer renderMode", () => { + const renderer = scene.createRootEntity("Renderer").addComponent(ParticleRenderer); + renderer.renderMode = ParticleRenderMode.None; + expect(renderer.renderMode).to.eq(ParticleRenderMode.None); + renderer.renderMode = ParticleRenderMode.Billboard; + expect(renderer.renderMode).to.eq(ParticleRenderMode.Billboard); + renderer.renderMode = ParticleRenderMode.StretchBillboard; + expect(renderer.renderMode).to.eq(ParticleRenderMode.StretchBillboard); + expect(() => { + renderer.renderMode = ParticleRenderMode.HorizontalBillboard; + }).to.throw("Not implemented"); + expect(() => { + renderer.renderMode = ParticleRenderMode.Mesh; + }).to.throw("Not implemented"); + expect(() => { + renderer.renderMode = ParticleRenderMode.VerticalBillboard; + }).to.throw("Not implemented"); + }); + + it("refCount", () => { + const renderer1 = scene.createRootEntity("Renderer").addComponent(ParticleRenderer); + const mesh = new ModelMesh(engine, "mesh"); + renderer1.mesh = mesh; + expect(mesh.refCount).to.eq(1); + renderer1.mesh = null; + expect(mesh.refCount).to.eq(0); + renderer1.mesh = mesh; + expect(mesh.refCount).to.eq(1); + renderer1.mesh = undefined; + expect(mesh.refCount).to.eq(0); + renderer1.mesh = mesh; + expect(mesh.refCount).to.eq(1); + renderer1.destroy(); + expect(mesh.refCount).to.eq(0); + + const entity2 = scene.createRootEntity("entity2"); + entity2.addComponent(ParticleRenderer).mesh = mesh; + entity2.destroy(); + expect(mesh.refCount).to.eq(0); + + const renderer2 = scene.createRootEntity("Renderer").addComponent(ParticleRenderer); + renderer2.mesh = mesh; + + mesh.destroy(); + expect(mesh.refCount).to.eq(1); + + mesh.destroy(true); + expect(mesh.refCount).to.eq(0); + }); +}); From 976e60fa9d2b6b65651153151c7a32b66f5a9bf6 Mon Sep 17 00:00:00 2001 From: AZhan Date: Fri, 8 Nov 2024 17:44:09 +0800 Subject: [PATCH 12/15] Fix the mesh was not restored after context lost. (#2418) * fix: mesh restorer dont work --- packages/core/src/Background.ts | 17 ++++- packages/core/src/BasicResources.ts | 13 +++- packages/loader/src/HDRLoader.ts | 70 ++++++++++++++----- packages/loader/src/gltf/GLTFUtils.ts | 11 +-- .../src/gltf/parser/GLTFSchemaParser.ts | 8 ++- 5 files changed, 91 insertions(+), 28 deletions(-) diff --git a/packages/core/src/Background.ts b/packages/core/src/Background.ts index a94d66fe68..38e71a5276 100644 --- a/packages/core/src/Background.ts +++ b/packages/core/src/Background.ts @@ -1,5 +1,5 @@ import { Color, Vector2, Vector3 } from "@galacean/engine-math"; -import { CompareFunction, Material, ModelMesh, Shader } from "."; +import { CompareFunction, ContentRestorer, Material, ModelMesh, Shader } from "."; import { Engine } from "./Engine"; import { BackgroundMode } from "./enums/BackgroundMode"; import { BackgroundTextureFillMode } from "./enums/BackgroundTextureFillMode"; @@ -134,7 +134,20 @@ export class Background { } private _initMesh(engine: Engine): void { - this._mesh = this._createPlane(engine); + const mesh = (this._mesh = this._createPlane(engine)); + engine.resourceManager.addContentRestorer( + new (class extends ContentRestorer { + constructor() { + super(mesh); + } + restoreContent() { + mesh.setPositions(mesh.getPositions()); + mesh.setUVs(mesh.getUVs()); + mesh.setIndices(mesh.getIndices()); + mesh.uploadData(false); + } + })() + ); this._mesh._addReferCount(1); } diff --git a/packages/core/src/BasicResources.ts b/packages/core/src/BasicResources.ts index d4d11b5907..6b00f88d36 100644 --- a/packages/core/src/BasicResources.ts +++ b/packages/core/src/BasicResources.ts @@ -80,8 +80,19 @@ export class BasicResources { const mesh = new ModelMesh(engine); mesh._addReferCount(1); mesh.setVertexElements([new VertexElement("POSITION_UV", 0, VertexElementFormat.Vector4, 0)]); - mesh.setVertexBufferBinding(new Buffer(engine, BufferBindFlag.VertexBuffer, vertices, BufferUsage.Static), 16); + const buffer = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices, BufferUsage.Static, true); + mesh.setVertexBufferBinding(buffer, 16); mesh.addSubMesh(0, 3, MeshTopology.Triangles); + engine.resourceManager.addContentRestorer( + new (class extends ContentRestorer { + constructor() { + super(mesh); + } + restoreContent() { + buffer.setData(buffer.data); + } + })() + ); return mesh; } diff --git a/packages/loader/src/HDRLoader.ts b/packages/loader/src/HDRLoader.ts index d9504d5ac3..f81712f39f 100644 --- a/packages/loader/src/HDRLoader.ts +++ b/packages/loader/src/HDRLoader.ts @@ -1,13 +1,17 @@ import { AssetPromise, AssetType, - Loader, + ContentRestorer, + Engine, LoadItem, - resourceLoader, + Loader, ResourceManager, TextureCube, - TextureCubeFace + TextureCubeFace, + request, + resourceLoader } from "@galacean/engine-core"; +import { RequestConfig } from "@galacean/engine-core/types/asset/request"; import { Color, Vector3 } from "@galacean/engine-math"; const PI = Math.PI; @@ -82,6 +86,23 @@ class HDRLoader extends Loader { private static _temp4Vector3 = new Vector3(); private static _temp5Vector3 = new Vector3(); + /** + * @internal + */ + static _setTextureByBuffer(engine: Engine, buffer: ArrayBuffer, texture?: TextureCube) { + const bufferArray = new Uint8Array(buffer); + const { width, height, dataPosition } = HDRLoader._parseHeader(bufferArray); + const cubeSize = height >> 1; + texture ||= new TextureCube(engine, cubeSize); + const pixels = HDRLoader._readPixels(bufferArray.subarray(dataPosition), width, height); + const cubeMapData = HDRLoader._convertToCubemap(pixels, width, height, cubeSize); + for (let faceIndex = 0; faceIndex < 6; faceIndex++) { + texture.setPixelBuffer(TextureCubeFace.PositiveX + faceIndex, cubeMapData[faceIndex], 0); + } + texture.generateMipmaps(); + return texture; + } + private static _convertToCubemap( pixels: Uint8Array, inputWidth: number, @@ -376,28 +397,41 @@ class HDRLoader extends Loader { color.b *= scaleFactor; color.a *= M; } - load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { const engine = resourceManager.engine; - - this.request(item.url, resourceManager, { ...item, type: "arraybuffer" }) + const requestConfig = { ...item, type: "arraybuffer" } as RequestConfig; + this.request(item.url, resourceManager, requestConfig) .then((buffer) => { - const uint8Array = new Uint8Array(buffer); - const { width, height, dataPosition } = HDRLoader._parseHeader(uint8Array); - const pixels = HDRLoader._readPixels(uint8Array.subarray(dataPosition), width, height); - const cubeSize = height >> 1; - - const cubeMapData = HDRLoader._convertToCubemap(pixels, width, height, cubeSize); - const texture = new TextureCube(engine, cubeSize); - - for (let faceIndex = 0; faceIndex < 6; faceIndex++) { - texture.setPixelBuffer(TextureCubeFace.PositiveX + faceIndex, cubeMapData[faceIndex], 0); - } - texture.generateMipmaps(); + const texture = HDRLoader._setTextureByBuffer(engine, buffer); + engine.resourceManager.addContentRestorer(new HDRContentRestorer(texture, item.url, requestConfig)); resolve(texture); }) .catch(reject); }); } } + +/** + * @internal + */ +class HDRContentRestorer extends ContentRestorer { + constructor( + resource: TextureCube, + public url: string, + public requestConfig: RequestConfig + ) { + super(resource); + } + + override restoreContent(): AssetPromise { + return new AssetPromise((resolve, reject) => { + request(this.url, this.requestConfig) + .then((buffer) => { + HDRLoader._setTextureByBuffer(this.resource.engine, buffer, this.resource); + resolve(this.resource); + }) + .catch(reject); + }); + } +} diff --git a/packages/loader/src/gltf/GLTFUtils.ts b/packages/loader/src/gltf/GLTFUtils.ts index f6aa01e207..e186b6f0a3 100644 --- a/packages/loader/src/gltf/GLTFUtils.ts +++ b/packages/loader/src/gltf/GLTFUtils.ts @@ -389,31 +389,32 @@ export class GLTFUtils { const dataView = new DataView(originBuffer); - // read header + // Read header const header = { magic: dataView.getUint32(0, true), version: dataView.getUint32(UINT32_LENGTH, true), length: dataView.getUint32(2 * UINT32_LENGTH, true) }; + // Return the original buffer if it is not a glb if (header.magic !== GLB_HEADER_MAGIC) { return { originBuffer }; } - // read main data + // Read main data let chunkLength = dataView.getUint32(GLB_HEADER_LENGTH, true); let chunkType = dataView.getUint32(GLB_HEADER_LENGTH + UINT32_LENGTH, true); - // read glTF json + // Read glTF json if (chunkType !== GLB_CHUNK_TYPES.JSON) { console.error("Invalid glb chunk type. Expected 0x4E4F534A, found 0x" + chunkType.toString(16)); return null; } const glTFData = new Uint8Array(originBuffer, GLB_HEADER_LENGTH + 2 * UINT32_LENGTH, chunkLength); - const glTF: IGLTF = JSON.parse(Utils.decodeText(glTFData)); + const glTF = JSON.parse(Utils.decodeText(glTFData)); - // read all buffers + // Read all buffers const buffers: ArrayBuffer[] = []; let byteOffset = GLB_HEADER_LENGTH + 2 * UINT32_LENGTH + chunkLength; diff --git a/packages/loader/src/gltf/parser/GLTFSchemaParser.ts b/packages/loader/src/gltf/parser/GLTFSchemaParser.ts index 8b43e975c0..728b570ed3 100644 --- a/packages/loader/src/gltf/parser/GLTFSchemaParser.ts +++ b/packages/loader/src/gltf/parser/GLTFSchemaParser.ts @@ -18,8 +18,12 @@ export class GLTFSchemaParser extends GLTFParser { return request(remoteUrl, requestConfig) .onProgress(undefined, context._onTaskDetail) .then((buffer) => { - restoreBufferRequests.push(new BufferRequestInfo(remoteUrl, requestConfig)); - return GLTFUtils.parseGLB(context, buffer); + const parseResult = GLTFUtils.parseGLB(context, buffer); + // If the buffer is a GLB file, we need to restore the buffer data + if (parseResult?.glTF) { + restoreBufferRequests.push(new BufferRequestInfo(remoteUrl, requestConfig)); + } + return parseResult; }) .then((result) => { if (result?.glTF) { From 9b39b66986621bfbbb36c9b9c2bb2e4683264289 Mon Sep 17 00:00:00 2001 From: SwayYan Date: Mon, 11 Nov 2024 17:32:30 +0800 Subject: [PATCH 13/15] Refactor request in `ResourceManager` and `Loader` (#2429) * feat: refactor request in `ResourceManager` and `Loader` --- e2e/README.md | 43 ++++++ e2e/case/project-loader.ts | 29 ++++ e2e/config.ts | 9 +- .../originImage/Advance_project-loader.jpg | 3 + e2e/package.json | 2 +- packages/core/src/asset/Loader.ts | 4 - packages/core/src/asset/ResourceManager.ts | 23 +++ packages/loader/src/AnimationClipLoader.ts | 10 +- .../loader/src/AnimatorControllerLoader.ts | 10 +- packages/loader/src/BufferLoader.ts | 3 +- packages/loader/src/EnvLoader.ts | 4 +- packages/loader/src/FontLoader.ts | 4 +- packages/loader/src/HDRLoader.ts | 4 +- packages/loader/src/JSONLoader.ts | 3 +- packages/loader/src/KTXCubeLoader.ts | 3 +- packages/loader/src/KTXLoader.ts | 10 +- packages/loader/src/MaterialLoader.ts | 10 +- packages/loader/src/MeshLoader.ts | 10 +- packages/loader/src/PrefabLoader.ts | 15 +- packages/loader/src/PrimitiveMeshLoader.ts | 111 +++++++------- packages/loader/src/ProjectLoader.ts | 4 +- packages/loader/src/SceneLoader.ts | 4 +- packages/loader/src/ShaderChunkLoader.ts | 3 +- packages/loader/src/ShaderLoader.ts | 3 +- packages/loader/src/SourceFontLoader.ts | 2 +- packages/loader/src/SpriteAtlasLoader.ts | 3 +- packages/loader/src/SpriteLoader.ts | 21 ++- packages/loader/src/TextLoader.ts | 3 +- packages/loader/src/Texture2DLoader.ts | 4 +- packages/loader/src/TextureCubeLoader.ts | 3 +- .../src/gltf/parser/GLTFBufferParser.ts | 9 +- .../src/gltf/parser/GLTFSchemaParser.ts | 48 +++--- packages/loader/src/ktx2/KTX2Loader.ts | 4 +- .../resources/scene/EditorTextureLoader.ts | 4 +- .../xr/src/loader/XRReferenceImageLoader.ts | 4 +- pnpm-lock.yaml | 142 ++++++++++-------- 36 files changed, 369 insertions(+), 202 deletions(-) create mode 100644 e2e/README.md create mode 100644 e2e/case/project-loader.ts create mode 100644 e2e/fixtures/originImage/Advance_project-loader.jpg diff --git a/e2e/README.md b/e2e/README.md new file mode 100644 index 0000000000..43f73bef3e --- /dev/null +++ b/e2e/README.md @@ -0,0 +1,43 @@ +### Note: Require install git-lfs +We use [git-lfs](https://git-lfs.com/) (Install by official website) to manage baseline images for e2e tests, so it's necessary to install it, ignore if already installed. +### 1. Create a case page in the e2e/case directory +You can refer to e2e/case/animator-play.ts. +### 2. Configure your e2e test in e2e/config.ts +The threshold is color difference threshold (from 0 to 1). Less more precise. +### 3. Debug your test cases: +#### Launch the Case page: + +``` +npm run e2e:case +``` + +After successfully launching the case page, run: + +``` +git lfs pull +``` +Pull image from github, then run + +``` +npm run e2e:debug +``` + +Open the Cypress client for debugging. +Cypress will capture screenshots of your case pages. +Review the screenshots in e2e/downloads folder, store them in the e2e/fixtures/originImage directory if there are no issues, then rerun the test cases. If the test cases pass, the debugging is complete. + +### 4. Run the complete e2e tests: +``` +npm run e2e +``` +Note: The e2e testing framework for this project is Cypress. For detailed usage instructions, please refer to https://www.cypress.io/. + + +### Add new e2e case + +1. modify `config.ts` based on the new test case. +2. run `npm run e2e:debug` + +the new image of test case for comparison will be present under directory `e2e/downloads`, you need to copy it into directory `e2e/fixtures/originImage`. + + diff --git a/e2e/case/project-loader.ts b/e2e/case/project-loader.ts new file mode 100644 index 0000000000..bd61cb1d02 --- /dev/null +++ b/e2e/case/project-loader.ts @@ -0,0 +1,29 @@ +/** + * @title Project loader + * @category Advance + */ +import { Logger, WebGLEngine, AssetType, Camera } from "@galacean/engine"; +import { ShaderLab } from "@galacean/engine-shader-lab"; +import { registerIncludes } from "@galacean/engine-toolkit"; +import { initScreenshot, updateForE2E } from './.mockForE2E'; + +// Create ShaderLab +const shaderLab = new ShaderLab(); +registerIncludes(); + +Logger.enable(); +WebGLEngine.create({ canvas: "canvas", shaderLab }).then( (engine) => { + engine.canvas.resizeByClientSize(2); + engine.resourceManager + .load({ + type: AssetType.Project, + url: "https://mdn.alipayobjects.com/oasis_be/afts/file/A*o15SSopTBh0AAAAAAAAAAAAADkp5AQ/project.json" + }).then(() => { + updateForE2E(engine); + + const cameraEntity = + engine.sceneManager.activeScene.findEntityByName('Camera'); + const camera = cameraEntity.getComponent(Camera) + initScreenshot(engine, camera) + }) +}); diff --git a/e2e/config.ts b/e2e/config.ts index 67a1095ec3..924f149a77 100644 --- a/e2e/config.ts +++ b/e2e/config.ts @@ -219,5 +219,12 @@ export const E2E_CONFIG = { caseFileName: "text-typed", threshold: 0.4 } - } + }, + Other: { + ProjectLoader: { + category: "Advance", + caseFileName: "project-loader", + threshold: 0.4 + } + }, }; diff --git a/e2e/fixtures/originImage/Advance_project-loader.jpg b/e2e/fixtures/originImage/Advance_project-loader.jpg new file mode 100644 index 0000000000..8f32a54ef7 --- /dev/null +++ b/e2e/fixtures/originImage/Advance_project-loader.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:12af410f9c34b96e3e7e8f0ae56478da524bd8ada15af7c2fcef0fd0bca3e5ab +size 571023 diff --git a/e2e/package.json b/e2e/package.json index 0f3e5540b0..7ce79e484c 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -9,7 +9,7 @@ }, "files": [], "dependencies": { - "@galacean/engine-toolkit": "^1.0.0-beta.1", + "@galacean/engine-toolkit": "^1.3.9", "@galacean/engine-shader-lab": "workspace:*", "@galacean/engine": "workspace:*", "@galacean/engine-core": "workspace:*", diff --git a/packages/core/src/asset/Loader.ts b/packages/core/src/asset/Loader.ts index a3bf73817b..47a046657f 100644 --- a/packages/core/src/asset/Loader.ts +++ b/packages/core/src/asset/Loader.ts @@ -41,8 +41,4 @@ export abstract class Loader { constructor(public readonly useCache: boolean) {} initialize?(engine: Engine, configuration: EngineConfiguration): Promise; abstract load(item: LoadItem, resourceManager: ResourceManager): AssetPromise; - request(url: string, resourceManager: ResourceManager, config: RequestConfig): AssetPromise { - const remoteUrl = resourceManager._virtualPathMap[url] ?? url; - return request(remoteUrl, config); - } } diff --git a/packages/core/src/asset/ResourceManager.ts b/packages/core/src/asset/ResourceManager.ts index 19550684be..b76de6f79b 100644 --- a/packages/core/src/asset/ResourceManager.ts +++ b/packages/core/src/asset/ResourceManager.ts @@ -4,6 +4,7 @@ import { GraphicsResource } from "./GraphicsResource"; import { Loader } from "./Loader"; import { LoadItem } from "./LoadItem"; import { ReferResource } from "./ReferResource"; +import { request, RequestConfig } from "./request"; /** * ResourceManager @@ -179,6 +180,28 @@ export class ResourceManager { this._contentRestorerPool[restorer.resource.instanceId] = restorer; } + /** + * @internal + */ + _getRemoteUrl(url: string): string { + return this._virtualPathMap[url] ?? url; + } + + /** + * @internal + */ + _requestByRemoteUrl(url: string, config: RequestConfig): AssetPromise { + return request(url, config); + } + + /** + * @internal + */ + _request(url: string, config: RequestConfig): AssetPromise { + const remoteUrl = this._getRemoteUrl(url); + return this._requestByRemoteUrl(remoteUrl, config); + } + /** * @internal */ diff --git a/packages/loader/src/AnimationClipLoader.ts b/packages/loader/src/AnimationClipLoader.ts index 0c5cfa4521..58227e65fc 100644 --- a/packages/loader/src/AnimationClipLoader.ts +++ b/packages/loader/src/AnimationClipLoader.ts @@ -14,10 +14,12 @@ import { decode } from "./resource-deserialize"; class AnimationClipLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, resourceManager, { - ...item, - type: "arraybuffer" - }) + resourceManager + // @ts-ignore + ._request(item.url, { + ...item, + type: "arraybuffer" + }) .then((data) => { return decode(data, resourceManager.engine) .then((clip) => { diff --git a/packages/loader/src/AnimatorControllerLoader.ts b/packages/loader/src/AnimatorControllerLoader.ts index e420ff72e8..6d2f20f610 100644 --- a/packages/loader/src/AnimatorControllerLoader.ts +++ b/packages/loader/src/AnimatorControllerLoader.ts @@ -19,10 +19,12 @@ import { class AnimatorControllerLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, resourceManager, { - ...item, - type: "json" - }) + resourceManager + // @ts-ignore + ._request(item.url, { + ...item, + type: "json" + }) .then((data) => { const animatorController = new AnimatorController(resourceManager.engine); const { layers, parameters } = data; diff --git a/packages/loader/src/BufferLoader.ts b/packages/loader/src/BufferLoader.ts index 564cd8bbc1..6d427cdd29 100644 --- a/packages/loader/src/BufferLoader.ts +++ b/packages/loader/src/BufferLoader.ts @@ -14,7 +14,8 @@ class BufferLoader extends Loader { resolve(result.buffer); }); } - return this.request(url, resourceManager, { + // @ts-ignore + return resourceManager._request(url, { ...item, type: "arraybuffer" }); diff --git a/packages/loader/src/EnvLoader.ts b/packages/loader/src/EnvLoader.ts index 99ca9f7ee9..6b04a4c563 100644 --- a/packages/loader/src/EnvLoader.ts +++ b/packages/loader/src/EnvLoader.ts @@ -17,7 +17,9 @@ import { SphericalHarmonics3 } from "@galacean/engine-math"; class EnvLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, resourceManager, { ...item, type: "arraybuffer" }) + resourceManager + // @ts-ignore + ._request(item.url, { ...item, type: "arraybuffer" }) .then((arraybuffer) => { const shArray = new Float32Array(arraybuffer, 0, 27); const shByteLength = 27 * 4; diff --git a/packages/loader/src/FontLoader.ts b/packages/loader/src/FontLoader.ts index 4441e80ba5..aabc04c396 100644 --- a/packages/loader/src/FontLoader.ts +++ b/packages/loader/src/FontLoader.ts @@ -12,7 +12,9 @@ import { class FontLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, resourceManager, { ...item, type: "json" }) + resourceManager + // @ts-ignore + ._request(item.url, { ...item, type: "json" }) .then((data) => { const { fontName, fontUrl } = data; diff --git a/packages/loader/src/HDRLoader.ts b/packages/loader/src/HDRLoader.ts index f81712f39f..b31099b98a 100644 --- a/packages/loader/src/HDRLoader.ts +++ b/packages/loader/src/HDRLoader.ts @@ -401,7 +401,9 @@ class HDRLoader extends Loader { return new AssetPromise((resolve, reject) => { const engine = resourceManager.engine; const requestConfig = { ...item, type: "arraybuffer" } as RequestConfig; - this.request(item.url, resourceManager, requestConfig) + resourceManager + // @ts-ignore + ._request(item.url, requestConfig) .then((buffer) => { const texture = HDRLoader._setTextureByBuffer(engine, buffer); engine.resourceManager.addContentRestorer(new HDRContentRestorer(texture, item.url, requestConfig)); diff --git a/packages/loader/src/JSONLoader.ts b/packages/loader/src/JSONLoader.ts index 7942f15210..ec96834331 100644 --- a/packages/loader/src/JSONLoader.ts +++ b/packages/loader/src/JSONLoader.ts @@ -3,7 +3,8 @@ import { resourceLoader, Loader, AssetPromise, AssetType, LoadItem, ResourceMana @resourceLoader(AssetType.JSON, ["json"], false) class JSONLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { - return this.request(item.url, resourceManager, { + // @ts-ignore + return resourceManager._request(item.url, { ...item, type: "json" }); diff --git a/packages/loader/src/KTXCubeLoader.ts b/packages/loader/src/KTXCubeLoader.ts index 4a9607a776..023d338357 100644 --- a/packages/loader/src/KTXCubeLoader.ts +++ b/packages/loader/src/KTXCubeLoader.ts @@ -16,7 +16,8 @@ class KTXCubeLoader extends Loader { return new AssetPromise((resolve, reject) => { Promise.all( item.urls.map((url) => - this.request(url, resourceManager, { + // @ts-ignore + resourceManager._request(url, { ...item, type: "arraybuffer" }) diff --git a/packages/loader/src/KTXLoader.ts b/packages/loader/src/KTXLoader.ts index 191d6c20be..b25af122ed 100644 --- a/packages/loader/src/KTXLoader.ts +++ b/packages/loader/src/KTXLoader.ts @@ -13,10 +13,12 @@ import { parseSingleKTX } from "./compressed-texture"; export class KTXLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, resourceManager, { - ...item, - type: "arraybuffer" - }) + resourceManager + // @ts-ignore + ._request(item.url, { + ...item, + type: "arraybuffer" + }) .then((bin) => { const parsedData = parseSingleKTX(bin); const { width, height, mipmaps, engineFormat } = parsedData; diff --git a/packages/loader/src/MaterialLoader.ts b/packages/loader/src/MaterialLoader.ts index fe496eedf6..162d2e0c87 100644 --- a/packages/loader/src/MaterialLoader.ts +++ b/packages/loader/src/MaterialLoader.ts @@ -35,10 +35,12 @@ function parseProperty(object: Object, key: string, value: any) { class MaterialLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, resourceManager, { - ...item, - type: "json" - }) + resourceManager + // @ts-ignore + ._request(item.url, { + ...item, + type: "json" + }) .then((materialSchema: IMaterialSchema) => { const engine = resourceManager.engine; const { shaderRef, shader: shaderName } = materialSchema; diff --git a/packages/loader/src/MeshLoader.ts b/packages/loader/src/MeshLoader.ts index 357e55b4a6..e183057a3e 100644 --- a/packages/loader/src/MeshLoader.ts +++ b/packages/loader/src/MeshLoader.ts @@ -13,10 +13,12 @@ import { decode } from "./resource-deserialize"; class MeshLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, resourceManager, { - ...item, - type: "arraybuffer" - }) + resourceManager + // @ts-ignore + ._request(item.url, { + ...item, + type: "arraybuffer" + }) .then((data) => { return decode(data, resourceManager.engine); }) diff --git a/packages/loader/src/PrefabLoader.ts b/packages/loader/src/PrefabLoader.ts index d536502092..f2009b8f0c 100644 --- a/packages/loader/src/PrefabLoader.ts +++ b/packages/loader/src/PrefabLoader.ts @@ -9,12 +9,15 @@ export class PrefabLoader extends Loader { const engine = resourceManager.engine; return new AssetPromise((resolve, reject) => { - this.request(item.url, resourceManager, { - ...item, - type: "json" - }).then((data) => { - PrefabParser.parse(engine, item.url, data).then(resolve).catch(reject); - }); + resourceManager + // @ts-ignore + ._request(item.url, { + ...item, + type: "json" + }) + .then((data) => { + PrefabParser.parse(engine, item.url, data).then(resolve).catch(reject); + }); }); } } diff --git a/packages/loader/src/PrimitiveMeshLoader.ts b/packages/loader/src/PrimitiveMeshLoader.ts index cc85be7cf2..91c2ad2c84 100644 --- a/packages/loader/src/PrimitiveMeshLoader.ts +++ b/packages/loader/src/PrimitiveMeshLoader.ts @@ -13,59 +13,64 @@ import { class PrimitiveMeshLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { const { engine } = resourceManager; - return this.request(item.url, resourceManager, { - ...item, - type: "json" - }).then((data) => { - switch (data.type) { - case PrimitiveMeshType.Sphere: - return PrimitiveMesh.createSubdivisionSurfaceSphere(engine, data.sphereRadius, data.sphereStep); - case PrimitiveMeshType.Capsule: - return PrimitiveMesh.createCapsule( - engine, - data.capsuleRadius, - data.capsuleHeight, - data.capsuleRadialSegments, - data.capsuleHeightSegments - ); - case PrimitiveMeshType.Cone: - return PrimitiveMesh.createCone( - engine, - data.coneRadius, - data.coneHeight, - data.coneRadialSegment, - data.coneHeightSegment - ); - case PrimitiveMeshType.Cuboid: - return PrimitiveMesh.createCuboid(engine, data.cuboidWidth, data.cuboidHeight, data.cuboidDepth); - case PrimitiveMeshType.Cylinder: - return PrimitiveMesh.createCylinder( - engine, - data.cylinderRadiusTop, - data.cylinderRadiusBottom, - data.cylinderHeight, - data.cylinderRadialSegment, - data.cylinderHeightSegment - ); - case PrimitiveMeshType.Plane: - return PrimitiveMesh.createPlane( - engine, - data.planeWidth, - data.planeHeight, - data.planeHorizontalSegments, - data.planeVerticalSegments - ); - case PrimitiveMeshType.Torus: - return PrimitiveMesh.createTorus( - engine, - data.torusRadius, - data.torusTubeRadius, - data.torusRadialSegments, - data.torusTubularSegments, - data.torusArc - ); - } - }); + return ( + resourceManager + // @ts-ignore + ._request(item.url, { + ...item, + type: "json" + }) + .then((data) => { + switch (data.type) { + case PrimitiveMeshType.Sphere: + return PrimitiveMesh.createSubdivisionSurfaceSphere(engine, data.sphereRadius, data.sphereStep); + case PrimitiveMeshType.Capsule: + return PrimitiveMesh.createCapsule( + engine, + data.capsuleRadius, + data.capsuleHeight, + data.capsuleRadialSegments, + data.capsuleHeightSegments + ); + case PrimitiveMeshType.Cone: + return PrimitiveMesh.createCone( + engine, + data.coneRadius, + data.coneHeight, + data.coneRadialSegment, + data.coneHeightSegment + ); + case PrimitiveMeshType.Cuboid: + return PrimitiveMesh.createCuboid(engine, data.cuboidWidth, data.cuboidHeight, data.cuboidDepth); + case PrimitiveMeshType.Cylinder: + return PrimitiveMesh.createCylinder( + engine, + data.cylinderRadiusTop, + data.cylinderRadiusBottom, + data.cylinderHeight, + data.cylinderRadialSegment, + data.cylinderHeightSegment + ); + case PrimitiveMeshType.Plane: + return PrimitiveMesh.createPlane( + engine, + data.planeWidth, + data.planeHeight, + data.planeHorizontalSegments, + data.planeVerticalSegments + ); + case PrimitiveMeshType.Torus: + return PrimitiveMesh.createTorus( + engine, + data.torusRadius, + data.torusTubeRadius, + data.torusRadialSegments, + data.torusTubularSegments, + data.torusArc + ); + } + }) + ); } } diff --git a/packages/loader/src/ProjectLoader.ts b/packages/loader/src/ProjectLoader.ts index 82441d2260..392ea0b179 100644 --- a/packages/loader/src/ProjectLoader.ts +++ b/packages/loader/src/ProjectLoader.ts @@ -14,7 +14,9 @@ class ProjectLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { const { engine } = resourceManager; return new AssetPromise((resolve, reject) => { - this.request(item.url, resourceManager, { ...item, type: "json" }) + resourceManager + // @ts-ignore + ._request(item.url, { ...item, type: "json" }) .then((data) => { // @ts-ignore engine.resourceManager.initVirtualResources(data.files); diff --git a/packages/loader/src/SceneLoader.ts b/packages/loader/src/SceneLoader.ts index 9fab686d79..7d191991d3 100644 --- a/packages/loader/src/SceneLoader.ts +++ b/packages/loader/src/SceneLoader.ts @@ -21,7 +21,9 @@ class SceneLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { const { engine } = resourceManager; return new AssetPromise((resolve, reject) => { - this.request(item.url, resourceManager, { ...item, type: "json" }) + resourceManager + // @ts-ignore + ._request(item.url, { ...item, type: "json" }) .then((data) => { return SceneParser.parse(engine, data).then((scene) => { const promises = []; diff --git a/packages/loader/src/ShaderChunkLoader.ts b/packages/loader/src/ShaderChunkLoader.ts index aaaea4d3a4..6ebfc418c9 100644 --- a/packages/loader/src/ShaderChunkLoader.ts +++ b/packages/loader/src/ShaderChunkLoader.ts @@ -40,7 +40,8 @@ export class ShaderChunkLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { const { url } = item; - return this.request(url, resourceManager, { ...item, type: "text" }).then((code) => { + // @ts-ignore + return resourceManager._request(url, { ...item, type: "text" }).then((code) => { ShaderFactory.registerInclude(url.substring(1), code); return ShaderChunkLoader._loadChunksInCode(code, url, resourceManager); diff --git a/packages/loader/src/ShaderLoader.ts b/packages/loader/src/ShaderLoader.ts index 00795eec6e..e1cafbf9ff 100644 --- a/packages/loader/src/ShaderLoader.ts +++ b/packages/loader/src/ShaderLoader.ts @@ -16,7 +16,8 @@ class ShaderLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { const { url } = item; - return this.request(url, resourceManager, { ...item, type: "text" }).then((code: string) => { + // @ts-ignore + return resourceManager._request(url, { ...item, type: "text" }).then((code: string) => { const builtinShader = this._getBuiltinShader(code); if (builtinShader) { return Shader.find(builtinShader); diff --git a/packages/loader/src/SourceFontLoader.ts b/packages/loader/src/SourceFontLoader.ts index 5a86000000..aa10cdd96a 100644 --- a/packages/loader/src/SourceFontLoader.ts +++ b/packages/loader/src/SourceFontLoader.ts @@ -13,7 +13,7 @@ class SourceFontLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { // @ts-ignore - const url = resourceManager._virtualPathMap[item.url] ?? item.url; + const url = resourceManager._getRemoteUrl(item.url); this._registerFont(url, url) .then(() => { const font = new Font(resourceManager.engine, url); diff --git a/packages/loader/src/SpriteAtlasLoader.ts b/packages/loader/src/SpriteAtlasLoader.ts index 34424d6991..f627255dd1 100644 --- a/packages/loader/src/SpriteAtlasLoader.ts +++ b/packages/loader/src/SpriteAtlasLoader.ts @@ -27,7 +27,8 @@ class SpriteAtlasLoader extends Loader { chainPromises[i].cancel(); } }); - const configPromise = this.request(item.url, resourceManager, { + // @ts-ignore + const configPromise = resourceManager._request(item.url, { ...item, type: "json" }); diff --git a/packages/loader/src/SpriteLoader.ts b/packages/loader/src/SpriteLoader.ts index ebeca92d16..9d075fe806 100644 --- a/packages/loader/src/SpriteLoader.ts +++ b/packages/loader/src/SpriteLoader.ts @@ -13,14 +13,19 @@ import { @resourceLoader(AssetType.Sprite, ["sprite"], false) class SpriteLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { - return this.request(item.url, resourceManager, { - ...item, - type: "json" - }).then((data) => { - return data.belongToAtlas - ? this._loadFromAtlas(resourceManager, data) - : this._loadFromTexture(resourceManager, data); - }); + return ( + resourceManager + // @ts-ignore + ._request(item.url, { + ...item, + type: "json" + }) + .then((data) => { + return data.belongToAtlas + ? this._loadFromAtlas(resourceManager, data) + : this._loadFromTexture(resourceManager, data); + }) + ); } private _loadFromAtlas(resourceManager: ResourceManager, data: any): AssetPromise { diff --git a/packages/loader/src/TextLoader.ts b/packages/loader/src/TextLoader.ts index 9483042a76..a13c1feec0 100644 --- a/packages/loader/src/TextLoader.ts +++ b/packages/loader/src/TextLoader.ts @@ -3,7 +3,8 @@ import { resourceLoader, Loader, AssetPromise, AssetType, LoadItem, ResourceMana @resourceLoader(AssetType.Text, ["txt"], false) class TextLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { - return this.request(item.url, resourceManager, { + // @ts-ignore + return resourceManager._request(item.url, { ...item, type: "text" }); diff --git a/packages/loader/src/Texture2DLoader.ts b/packages/loader/src/Texture2DLoader.ts index 9041d85f35..0c8af7dd54 100644 --- a/packages/loader/src/Texture2DLoader.ts +++ b/packages/loader/src/Texture2DLoader.ts @@ -22,7 +22,9 @@ class Texture2DLoader extends Loader { ...item, type: "image" }; - this.request(url, resourceManager, requestConfig) + resourceManager + // @ts-ignore + ._request(url, requestConfig) .onProgress(setTaskCompleteProgress, setTaskDetailProgress) .then((image) => { const { format, mipmap, anisoLevel, wrapModeU, wrapModeV, filterMode } = diff --git a/packages/loader/src/TextureCubeLoader.ts b/packages/loader/src/TextureCubeLoader.ts index a20188b648..d90559d507 100644 --- a/packages/loader/src/TextureCubeLoader.ts +++ b/packages/loader/src/TextureCubeLoader.ts @@ -21,7 +21,8 @@ class TextureCubeLoader extends Loader { type: "image" }; - Promise.all(urls.map((url) => this.request(url, resourceManager, requestConfig))) + // @ts-ignore + Promise.all(urls.map((url) => resourceManager._request(url, requestConfig))) .then((images) => { const { width, height } = images[0]; diff --git a/packages/loader/src/gltf/parser/GLTFBufferParser.ts b/packages/loader/src/gltf/parser/GLTFBufferParser.ts index a5576df29f..84a4f81b0d 100644 --- a/packages/loader/src/gltf/parser/GLTFBufferParser.ts +++ b/packages/loader/src/gltf/parser/GLTFBufferParser.ts @@ -14,16 +14,19 @@ export class GLTFBufferParser extends GLTFParser { } private _parseSingleBuffer(context: GLTFParserContext, bufferInfo: IBuffer): Promise { - const { glTFResource, contentRestorer } = context; + const { glTFResource, contentRestorer, resourceManager } = context; const url = glTFResource.url; // @ts-ignore - const remoteUrl = context.resourceManager._virtualPathMap[url] ?? url; + const remoteUrl = resourceManager._getRemoteUrl(url); const restoreBufferRequests = contentRestorer.bufferRequests; const requestConfig = { type: "arraybuffer" }; const absoluteUrl = Utils.resolveAbsoluteUrl(remoteUrl, bufferInfo.uri); restoreBufferRequests.push(new BufferRequestInfo(absoluteUrl, requestConfig)); - const promise = request(absoluteUrl, requestConfig).onProgress(undefined, context._onTaskDetail); + const promise = resourceManager + // @ts-ignore + ._requestByRemoteUrl(absoluteUrl, requestConfig) + .onProgress(undefined, context._onTaskDetail); context._addTaskCompletePromise(promise); return promise; diff --git a/packages/loader/src/gltf/parser/GLTFSchemaParser.ts b/packages/loader/src/gltf/parser/GLTFSchemaParser.ts index 728b570ed3..ffc716702b 100644 --- a/packages/loader/src/gltf/parser/GLTFSchemaParser.ts +++ b/packages/loader/src/gltf/parser/GLTFSchemaParser.ts @@ -9,31 +9,35 @@ import { GLTFParserContext, GLTFParserType, registerGLTFParser } from "./GLTFPar @registerGLTFParser(GLTFParserType.Schema) export class GLTFSchemaParser extends GLTFParser { parse(context: GLTFParserContext): Promise { - const { glTFResource, contentRestorer } = context; + const { glTFResource, contentRestorer, resourceManager } = context; const url = glTFResource.url; const restoreBufferRequests = contentRestorer.bufferRequests; const requestConfig = { type: "arraybuffer" }; // @ts-ignore - const remoteUrl = context.resourceManager._virtualPathMap[url] ?? url; - return request(remoteUrl, requestConfig) - .onProgress(undefined, context._onTaskDetail) - .then((buffer) => { - const parseResult = GLTFUtils.parseGLB(context, buffer); - // If the buffer is a GLB file, we need to restore the buffer data - if (parseResult?.glTF) { - restoreBufferRequests.push(new BufferRequestInfo(remoteUrl, requestConfig)); - } - return parseResult; - }) - .then((result) => { - if (result?.glTF) { - contentRestorer.isGLB = true; - context.buffers = result.buffers; - return result.glTF; - } else { - contentRestorer.isGLB = false; - return JSON.parse(Utils.decodeText(new Uint8Array(result.originBuffer))); - } - }); + const remoteUrl = resourceManager._getRemoteUrl(url); + return ( + resourceManager + // @ts-ignore + ._requestByRemoteUrl(remoteUrl, requestConfig) + .onProgress(undefined, context._onTaskDetail) + .then((buffer) => { + const parseResult = GLTFUtils.parseGLB(context, buffer); + // If the buffer is a GLB file, we need to restore the buffer data + if (parseResult?.glTF) { + restoreBufferRequests.push(new BufferRequestInfo(remoteUrl, requestConfig)); + } + return parseResult; + }) + .then((result) => { + if (result?.glTF) { + contentRestorer.isGLB = true; + context.buffers = result.buffers; + return result.glTF; + } else { + contentRestorer.isGLB = false; + return JSON.parse(Utils.decodeText(new Uint8Array(result.originBuffer))); + } + }) + ); } } diff --git a/packages/loader/src/ktx2/KTX2Loader.ts b/packages/loader/src/ktx2/KTX2Loader.ts index bd867b2027..1d853e6239 100644 --- a/packages/loader/src/ktx2/KTX2Loader.ts +++ b/packages/loader/src/ktx2/KTX2Loader.ts @@ -221,7 +221,9 @@ export class KTX2Loader extends Loader { resourceManager: ResourceManager ): AssetPromise { return new AssetPromise((resolve, reject, setTaskCompleteProgress, setTaskDetailProgress) => { - this.request(item.url, resourceManager, { type: "arraybuffer" }) + resourceManager + // @ts-ignore + ._request(item.url, { type: "arraybuffer" }) .onProgress(setTaskCompleteProgress, setTaskDetailProgress) .then((buffer) => KTX2Loader._parseBuffer(new Uint8Array(buffer), resourceManager.engine, item.params).then( diff --git a/packages/loader/src/resource-deserialize/resources/scene/EditorTextureLoader.ts b/packages/loader/src/resource-deserialize/resources/scene/EditorTextureLoader.ts index 09403013a7..793fc3e3f9 100644 --- a/packages/loader/src/resource-deserialize/resources/scene/EditorTextureLoader.ts +++ b/packages/loader/src/resource-deserialize/resources/scene/EditorTextureLoader.ts @@ -5,7 +5,9 @@ import { decode } from "../.."; export class EditorTextureLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, resourceManager, { ...item, type: "arraybuffer" }) + resourceManager + // @ts-ignore + ._request(item.url, { ...item, type: "arraybuffer" }) .then((data) => { decode(data, resourceManager.engine).then((texture) => { resolve(texture); diff --git a/packages/xr/src/loader/XRReferenceImageLoader.ts b/packages/xr/src/loader/XRReferenceImageLoader.ts index a6681b8cbb..8476382721 100644 --- a/packages/xr/src/loader/XRReferenceImageLoader.ts +++ b/packages/xr/src/loader/XRReferenceImageLoader.ts @@ -5,7 +5,9 @@ import { XRReferenceImage } from "../feature/trackable/image/XRReferenceImage"; export class XRReferenceImageLoader extends Loader { load(item: LoadItem, resourceManager: ResourceManager): AssetPromise { return new AssetPromise((resolve, reject) => { - this.request(item.url, resourceManager, { ...item, type: "arraybuffer" }) + resourceManager + // @ts-ignore + ._request(item.url, { ...item, type: "arraybuffer" }) .then((data) => { decode(data, resourceManager.engine).then((referenceImage) => { resolve(referenceImage); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 53f203f2fd..87f849986a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -159,8 +159,8 @@ importers: specifier: workspace:* version: link:../packages/shader-lab '@galacean/engine-toolkit': - specifier: ^1.0.0-beta.1 - version: 1.0.0-beta.1(@galacean/engine@packages+galacean) + specifier: ^1.3.9 + version: 1.3.9(@galacean/engine@packages+galacean) dat.gui: specifier: ^0.7.9 version: 0.7.9 @@ -529,63 +529,68 @@ packages: '@fastify/deepmerge@1.3.0': resolution: {integrity: sha512-J8TOSBq3SoZbDhM9+R/u77hP93gz/rajSA+K2kGyijPpORPWUXHUpTaleoj+92As0S9uPRP7Oi8IqMf0u+ro6A==} - '@galacean/engine-toolkit-auxiliary-lines@1.0.0-beta.1': - resolution: {integrity: sha512-EvRBQc0gOhPeJUteyCyxOOqVB/Ls/lcp1CDbicH7Pxfv1Eyww+NFMNVN8RbvxPwcjMuZtzSvaaKgMx8KZK6WnQ==} + '@galacean/engine-toolkit-auxiliary-lines@1.3.9': + resolution: {integrity: sha512-UZFS/A2DoHphG1Rq1qulswZnNykZ+3jHtMkpBpqNLCjqtiKG6zlFrYktUFQkTzVdaIs1Z74UdHHAneGiFx/Xig==} peerDependencies: - '@galacean/engine': ^1.0.0-alpha + '@galacean/engine': ^1.3.0-beta.6 - '@galacean/engine-toolkit-controls@1.0.0-beta.1': - resolution: {integrity: sha512-q5yqPYfJlvGBXWUVt88dQUsEGDzg1VwUmp2mxOoJCcSDFBLE3ZdWUwnNOneIkkSTX/kNujOdBOPFbLMRDbMzNg==} + '@galacean/engine-toolkit-controls@1.3.9': + resolution: {integrity: sha512-4vmOoo6++jZAAywiJNoSOEhxN1XJ+mEOO8RjOsBHMJi88copSarhI1UloDhh4Phybx0gyIMxfW+Pf+rURkFIEw==} peerDependencies: - '@galacean/engine': ^1.0.0-alpha + '@galacean/engine': ^1.3.0-beta.6 - '@galacean/engine-toolkit-custom-material@1.0.0-beta.1': - resolution: {integrity: sha512-FqEacCNVUHo55CSKON+4LfMJgjRYmsBe4/ywFSNXQ9t+x0po8p4ztCyJwCSph1YdGzrk1hIbMGpFmlU6tCosrA==} + '@galacean/engine-toolkit-custom-material@1.3.9': + resolution: {integrity: sha512-+YJFcY8vJrzhgxJuABT5IehXWULIZhIrYqvqZaCVCYwOwONW+snHaJ668hQofdafVMQemJaoshsapuG6L/2Ifg==} peerDependencies: - '@galacean/engine': ^1.0.0-alpha + '@galacean/engine': ^1.3.0-beta.6 - '@galacean/engine-toolkit-framebuffer-picker@1.0.0-beta.1': - resolution: {integrity: sha512-e/ZLiaIGJeuHcZUFPPLjdxxBF1WfScF1XJBwt3iMW6lRONYVlJbaq8up0Pcu74N6i4aytaEVTeAonf778SQyrg==} + '@galacean/engine-toolkit-framebuffer-picker@1.3.9': + resolution: {integrity: sha512-uncOV18yagh1oe9JboRnp6QmkHqyfC+xaLD40+sXc+M8xKPchM41E1ygy3mNQvkBRQfbUA6ZkqIGsne5V45tAg==} peerDependencies: - '@galacean/engine': ^1.0.0-alpha + '@galacean/engine': ^1.3.0-beta.6 - '@galacean/engine-toolkit-geometry-sketch@1.0.0-beta.1': - resolution: {integrity: sha512-FyPkAOn/s/sLwrxKb1xQbE+DEmoT9jnCxYnPGRAawhEoypVDnvqQZoopELjsmQGecSmhCqvXuEO0yNQSdiW4lQ==} + '@galacean/engine-toolkit-geometry-sketch@1.3.9': + resolution: {integrity: sha512-2G4wjKT4ilFhqy2KED5wuoqiau/gCVgXFyBeHIUq633rzixSKsSVd56pxQItsD1WdifWRfp1o/XqordIGGkViA==} peerDependencies: - '@galacean/engine': ^1.0.0-alpha + '@galacean/engine': ^1.3.0-beta.6 - '@galacean/engine-toolkit-gizmo@1.0.0-beta.1': - resolution: {integrity: sha512-9F5PXr5dYSjRXpq8FgZUmE4ziYOR0hJGmBY7y1nlrK/Zug8IMyza4epHyIIlbJAO3qIWI9A7PccrNZamg+79cw==} + '@galacean/engine-toolkit-gizmo@1.3.9': + resolution: {integrity: sha512-Qg5yVeZfUJZTOqrM/Kr1CUxVpZZ6v2xeqywT1xRxHCBLaoJnyNcYdM1NHLozhpmnv89Sxlb0XCQFVz2KqecrJQ==} peerDependencies: - '@galacean/engine': ^1.0.0-alpha + '@galacean/engine': ^1.3.0-beta.6 - '@galacean/engine-toolkit-lines@1.0.0-beta.1': - resolution: {integrity: sha512-Y9Pa5kXgQFFnI81a6hYGXhMvupUw2uMFMpcyUKKG9KJjEyJKwlh/rOAsMIVb23djlK1jD6n3SwEm4febiZhu1A==} + '@galacean/engine-toolkit-lines@1.3.9': + resolution: {integrity: sha512-htXfz2a/4HouKI0wmd8HjTfq5PnMt21uIQD3X6D7kE11VmosRbq+YSB/LYoNLWvyHCG8AcjodIn4UL1Lgxt6bw==} peerDependencies: - '@galacean/engine': ^1.0.0-alpha + '@galacean/engine': ^1.3.0-beta.6 - '@galacean/engine-toolkit-navigation-gizmo@1.0.0-beta.1': - resolution: {integrity: sha512-5/1k7uayO+5Wh51Pkvs5ipxT0WfCcZR5Iavzz8tHyPUMbbQrQcZZIwsOuTj57m9rUs5oDIyXKPl4t3QWTPXI3g==} + '@galacean/engine-toolkit-navigation-gizmo@1.3.9': + resolution: {integrity: sha512-v/iDh/qATqGYARCLwGuiZymuhDo7LvfStmDIJtZ94Cd2dh9fV0mT8kKVN1yvuW8X2/375Cc+d9OHRlYGz7hmRw==} peerDependencies: - '@galacean/engine': ^1.0.0-alpha + '@galacean/engine': ^1.3.0-beta.6 - '@galacean/engine-toolkit-outline@1.0.0-beta.1': - resolution: {integrity: sha512-0mAHxMBYAWKo3OSHwCrl1w3GEYzfm1mYoG11Q/70feTSNNS+YkePJY2wvvvStflGmnqffDU3q+3sK6w6hxUH5w==} + '@galacean/engine-toolkit-outline@1.3.9': + resolution: {integrity: sha512-WnyVZ7hRQPYdj0RzKC/yPrwGeXWJ3da1Ztonrofyv1F00CSTFyzXY1RapscJDQQtaOdRX5bV/5vkBBzBOYuKlA==} peerDependencies: - '@galacean/engine': ^1.0.0-alpha + '@galacean/engine': ^1.3.0-beta.6 - '@galacean/engine-toolkit-skeleton-viewer@1.0.0-beta.1': - resolution: {integrity: sha512-Ni6nQ0GijPUYtMnWR5UUjIx9WitY48vB+FfO+QqEw17Yp+KfvuW9On2NKTxICKG/NTC/lg30L0xCYVgb+r7fNw==} + '@galacean/engine-toolkit-shader-lab@1.3.9': + resolution: {integrity: sha512-XvXvVHdU9Ic69oF5tkgRIjAxsOq/7L7b6UCYMggDvoWV7RO3JXB8CbvfEDnG/qUztFBfIc10h69gXizcu2xJJg==} peerDependencies: - '@galacean/engine': ^1.0.0-alpha + '@galacean/engine': ^1.3.0-beta.6 - '@galacean/engine-toolkit-stats@1.0.0-beta.1': - resolution: {integrity: sha512-28RskztCxAfR7qHQU5c8zJzuok39pLC/5/0YgNXyIcCZtdBCOb2d+3fo3p17OMcT1JSquKipO3Ze7JoqI/EgfA==} + '@galacean/engine-toolkit-skeleton-viewer@1.3.9': + resolution: {integrity: sha512-DmKrnzYLqv1IZgirE11dCE57qS9ShbsCLf1T9lqO5ExbGwzA/3GLPACSOTPAMLWc6n+peZFOkhRMr597fb9HHQ==} peerDependencies: - '@galacean/engine': ^1.0.0-alpha + '@galacean/engine': ^1.3.0-beta.6 - '@galacean/engine-toolkit@1.0.0-beta.1': - resolution: {integrity: sha512-TRB6NS5hXDNiAgsiEsymxGFzTHW70c6FNoESw/87G/BpMgZ1cGcA0yAIlSzeuAPkXO2w30/4CZSZTRpYsRpzpA==} + '@galacean/engine-toolkit-stats@1.3.9': + resolution: {integrity: sha512-5EfsVwg1YzICLzJsek9U++jcqOUK6SCakwQmSVIEFvVxn5cLN9cphNorcmOPsju3crcrfP45aLjZEEPgoYcAqw==} + peerDependencies: + '@galacean/engine': ^1.3.0-beta.6 + + '@galacean/engine-toolkit@1.3.9': + resolution: {integrity: sha512-sxE7QfzH61O9Q1wtwnjIEjcg3n0ZZVz9B6CyqBLOWyWgWsZmefcjZLnnH4HIkvc5ZLNA+gMuJ1ekmwJgfkck+g==} '@humanwhocodes/config-array@0.11.10': resolution: {integrity: sha512-KVVjQmNUepDVGXNuoRRdmmEjruj0KfiGSbS8LVc12LMsWDQzRXJ0qdhN8L8uUigKpfEHRhlaQFY0ib1tnUbNeQ==} @@ -4004,68 +4009,73 @@ snapshots: '@fastify/deepmerge@1.3.0': {} - '@galacean/engine-toolkit-auxiliary-lines@1.0.0-beta.1(@galacean/engine@packages+galacean)': + '@galacean/engine-toolkit-auxiliary-lines@1.3.9(@galacean/engine@packages+galacean)': + dependencies: + '@galacean/engine': link:packages/galacean + '@galacean/engine-toolkit-custom-material': 1.3.9(@galacean/engine@packages+galacean) + + '@galacean/engine-toolkit-controls@1.3.9(@galacean/engine@packages+galacean)': dependencies: '@galacean/engine': link:packages/galacean - '@galacean/engine-toolkit-custom-material': 1.0.0-beta.1(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-controls@1.0.0-beta.1(@galacean/engine@packages+galacean)': + '@galacean/engine-toolkit-custom-material@1.3.9(@galacean/engine@packages+galacean)': dependencies: '@galacean/engine': link:packages/galacean - '@galacean/engine-toolkit-custom-material@1.0.0-beta.1(@galacean/engine@packages+galacean)': + '@galacean/engine-toolkit-framebuffer-picker@1.3.9(@galacean/engine@packages+galacean)': dependencies: '@galacean/engine': link:packages/galacean - '@galacean/engine-toolkit-framebuffer-picker@1.0.0-beta.1(@galacean/engine@packages+galacean)': + '@galacean/engine-toolkit-geometry-sketch@1.3.9(@galacean/engine@packages+galacean)': dependencies: '@galacean/engine': link:packages/galacean - '@galacean/engine-toolkit-geometry-sketch@1.0.0-beta.1(@galacean/engine@packages+galacean)': + '@galacean/engine-toolkit-gizmo@1.3.9(@galacean/engine@packages+galacean)': dependencies: '@galacean/engine': link:packages/galacean + '@galacean/engine-toolkit-custom-material': 1.3.9(@galacean/engine@packages+galacean) + '@galacean/engine-toolkit-framebuffer-picker': 1.3.9(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-gizmo@1.0.0-beta.1(@galacean/engine@packages+galacean)': + '@galacean/engine-toolkit-lines@1.3.9(@galacean/engine@packages+galacean)': dependencies: '@galacean/engine': link:packages/galacean - '@galacean/engine-toolkit-custom-material': 1.0.0-beta.1(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-framebuffer-picker': 1.0.0-beta.1(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-lines@1.0.0-beta.1(@galacean/engine@packages+galacean)': + '@galacean/engine-toolkit-navigation-gizmo@1.3.9(@galacean/engine@packages+galacean)': dependencies: '@galacean/engine': link:packages/galacean + '@galacean/engine-toolkit-controls': 1.3.9(@galacean/engine@packages+galacean) + '@galacean/engine-toolkit-custom-material': 1.3.9(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-navigation-gizmo@1.0.0-beta.1(@galacean/engine@packages+galacean)': + '@galacean/engine-toolkit-outline@1.3.9(@galacean/engine@packages+galacean)': dependencies: '@galacean/engine': link:packages/galacean - '@galacean/engine-toolkit-controls': 1.0.0-beta.1(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-custom-material': 1.0.0-beta.1(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-outline@1.0.0-beta.1(@galacean/engine@packages+galacean)': + '@galacean/engine-toolkit-shader-lab@1.3.9(@galacean/engine@packages+galacean)': dependencies: '@galacean/engine': link:packages/galacean - '@galacean/engine-toolkit-skeleton-viewer@1.0.0-beta.1(@galacean/engine@packages+galacean)': + '@galacean/engine-toolkit-skeleton-viewer@1.3.9(@galacean/engine@packages+galacean)': dependencies: '@galacean/engine': link:packages/galacean - '@galacean/engine-toolkit-stats@1.0.0-beta.1(@galacean/engine@packages+galacean)': + '@galacean/engine-toolkit-stats@1.3.9(@galacean/engine@packages+galacean)': dependencies: '@galacean/engine': link:packages/galacean - '@galacean/engine-toolkit@1.0.0-beta.1(@galacean/engine@packages+galacean)': - dependencies: - '@galacean/engine-toolkit-auxiliary-lines': 1.0.0-beta.1(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-controls': 1.0.0-beta.1(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-custom-material': 1.0.0-beta.1(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-framebuffer-picker': 1.0.0-beta.1(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-geometry-sketch': 1.0.0-beta.1(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-gizmo': 1.0.0-beta.1(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-lines': 1.0.0-beta.1(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-navigation-gizmo': 1.0.0-beta.1(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-outline': 1.0.0-beta.1(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-skeleton-viewer': 1.0.0-beta.1(@galacean/engine@packages+galacean) - '@galacean/engine-toolkit-stats': 1.0.0-beta.1(@galacean/engine@packages+galacean) + '@galacean/engine-toolkit@1.3.9(@galacean/engine@packages+galacean)': + dependencies: + '@galacean/engine-toolkit-auxiliary-lines': 1.3.9(@galacean/engine@packages+galacean) + '@galacean/engine-toolkit-controls': 1.3.9(@galacean/engine@packages+galacean) + '@galacean/engine-toolkit-custom-material': 1.3.9(@galacean/engine@packages+galacean) + '@galacean/engine-toolkit-framebuffer-picker': 1.3.9(@galacean/engine@packages+galacean) + '@galacean/engine-toolkit-geometry-sketch': 1.3.9(@galacean/engine@packages+galacean) + '@galacean/engine-toolkit-gizmo': 1.3.9(@galacean/engine@packages+galacean) + '@galacean/engine-toolkit-lines': 1.3.9(@galacean/engine@packages+galacean) + '@galacean/engine-toolkit-navigation-gizmo': 1.3.9(@galacean/engine@packages+galacean) + '@galacean/engine-toolkit-outline': 1.3.9(@galacean/engine@packages+galacean) + '@galacean/engine-toolkit-shader-lab': 1.3.9(@galacean/engine@packages+galacean) + '@galacean/engine-toolkit-skeleton-viewer': 1.3.9(@galacean/engine@packages+galacean) + '@galacean/engine-toolkit-stats': 1.3.9(@galacean/engine@packages+galacean) transitivePeerDependencies: - '@galacean/engine' From a1599259a97aa136eb97226058dfbafc1a0abd78 Mon Sep 17 00:00:00 2001 From: ChenMo Date: Mon, 11 Nov 2024 21:36:16 +0800 Subject: [PATCH 14/15] Support particle start delay time (#2431) * feat: support particle start delay time --- .../core/src/particle/ParticleGenerator.ts | 18 +++++++++++++++++- .../core/src/particle/modules/MainModule.ts | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/core/src/particle/ParticleGenerator.ts b/packages/core/src/particle/ParticleGenerator.ts index 744dde9bc9..1f3baa89c0 100644 --- a/packages/core/src/particle/ParticleGenerator.ts +++ b/packages/core/src/particle/ParticleGenerator.ts @@ -121,6 +121,8 @@ export class ParticleGenerator { private _firstActiveTransformedBoundingBox = 0; @ignoreClone private _firstFreeTransformedBoundingBox = 0; + @ignoreClone + private _playStartDelay = 0; /** * Whether the particle generator is contain alive or is still creating particles. @@ -187,6 +189,8 @@ export class ParticleGenerator { if (this.useAutoRandomSeed) { this._resetGlobalRandSeed(Math.floor(Math.random() * 0xffffffff)); // 2^32 - 1 } + + this._playStartDelay = this.main.startDelay.evaluate(undefined, this.main._startDelayRand.random()); } } @@ -266,8 +270,20 @@ export class ParticleGenerator { const { main, emission } = this; const duration = main.duration; const lastPlayTime = this._playTime; + const deltaTime = elapsedTime * main.simulationSpeed; + + // Process start delay time + if (this._playStartDelay > 0) { + const remainingDelay = (this._playStartDelay -= deltaTime); + if (remainingDelay < 0) { + this._playTime -= remainingDelay; + this._playStartDelay = 0; + } else { + return; + } + } - this._playTime += elapsedTime * main.simulationSpeed; + this._playTime += deltaTime; this._retireActiveParticles(); this._freeRetiredParticles(); diff --git a/packages/core/src/particle/modules/MainModule.ts b/packages/core/src/particle/modules/MainModule.ts index 7778ae27cb..94a73610e8 100644 --- a/packages/core/src/particle/modules/MainModule.ts +++ b/packages/core/src/particle/modules/MainModule.ts @@ -63,6 +63,9 @@ export class MainModule implements ICustomClone { _maxParticleBuffer = 1000; /** @internal */ @ignoreClone + readonly _startDelayRand = new Rand(0, ParticleRandomSubSeeds.StartDelay); + /** @internal */ + @ignoreClone readonly _startSpeedRand = new Rand(0, ParticleRandomSubSeeds.StartSpeed); /** @internal */ @ignoreClone From 2b891977ea93128056ca9133cf44a17200602c30 Mon Sep 17 00:00:00 2001 From: GuoLei1990 Date: Mon, 11 Nov 2024 21:36:48 +0800 Subject: [PATCH 15/15] chore: release v1.3.20 --- e2e/package.json | 2 +- package.json | 2 +- packages/core/package.json | 2 +- packages/design/package.json | 2 +- packages/galacean/package.json | 2 +- packages/loader/package.json | 2 +- packages/math/package.json | 2 +- packages/physics-lite/package.json | 2 +- packages/physics-physx/package.json | 2 +- packages/rhi-webgl/package.json | 2 +- packages/shader-lab/package.json | 2 +- packages/xr-webxr/package.json | 2 +- packages/xr/package.json | 2 +- tests/package.json | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/e2e/package.json b/e2e/package.json index 7ce79e484c..7ecd4c6920 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -1,7 +1,7 @@ { "name": "@galacean/engine-e2e", "private": true, - "version": "1.3.19", + "version": "1.3.20", "license": "MIT", "scripts": { "case": "vite serve .dev --config .dev/vite.config.js", diff --git a/package.json b/package.json index a31b984e28..e1862706a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-root", - "version": "1.3.19", + "version": "1.3.20", "packageManager": "pnpm@9.3.0", "private": true, "scripts": { diff --git a/packages/core/package.json b/packages/core/package.json index 13697c8736..470a3a9d55 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-core", - "version": "1.3.19", + "version": "1.3.20", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/design/package.json b/packages/design/package.json index c76bdb6944..e23c7c29e8 100644 --- a/packages/design/package.json +++ b/packages/design/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-design", - "version": "1.3.19", + "version": "1.3.20", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/galacean/package.json b/packages/galacean/package.json index bbd2c05316..7aeec98b99 100644 --- a/packages/galacean/package.json +++ b/packages/galacean/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine", - "version": "1.3.19", + "version": "1.3.20", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/loader/package.json b/packages/loader/package.json index 94140e32e0..d2572af034 100644 --- a/packages/loader/package.json +++ b/packages/loader/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-loader", - "version": "1.3.19", + "version": "1.3.20", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/math/package.json b/packages/math/package.json index 77b7ae8a03..7b67a5d553 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-math", - "version": "1.3.19", + "version": "1.3.20", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/physics-lite/package.json b/packages/physics-lite/package.json index 8b158572a6..19a7821eb8 100644 --- a/packages/physics-lite/package.json +++ b/packages/physics-lite/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-physics-lite", - "version": "1.3.19", + "version": "1.3.20", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/physics-physx/package.json b/packages/physics-physx/package.json index bdc9c0b443..9790dc826d 100644 --- a/packages/physics-physx/package.json +++ b/packages/physics-physx/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-physics-physx", - "version": "1.3.19", + "version": "1.3.20", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/rhi-webgl/package.json b/packages/rhi-webgl/package.json index 3ee2ad6f82..f0ef3a3fe7 100644 --- a/packages/rhi-webgl/package.json +++ b/packages/rhi-webgl/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-rhi-webgl", - "version": "1.3.19", + "version": "1.3.20", "repository": { "url": "https://github.com/galacean/engine.git" }, diff --git a/packages/shader-lab/package.json b/packages/shader-lab/package.json index de4f5b658e..c1d39d960b 100644 --- a/packages/shader-lab/package.json +++ b/packages/shader-lab/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-shader-lab", - "version": "1.3.19", + "version": "1.3.20", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/xr-webxr/package.json b/packages/xr-webxr/package.json index e551d487ec..2744932ddb 100644 --- a/packages/xr-webxr/package.json +++ b/packages/xr-webxr/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-xr-webxr", - "version": "1.3.19", + "version": "1.3.20", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/packages/xr/package.json b/packages/xr/package.json index dc202444be..dd353da751 100644 --- a/packages/xr/package.json +++ b/packages/xr/package.json @@ -1,6 +1,6 @@ { "name": "@galacean/engine-xr", - "version": "1.3.19", + "version": "1.3.20", "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" diff --git a/tests/package.json b/tests/package.json index 2a3471e40c..7db1e6425e 100644 --- a/tests/package.json +++ b/tests/package.json @@ -1,7 +1,7 @@ { "name": "@galacean/engine-tests", "private": true, - "version": "1.3.19", + "version": "1.3.20", "license": "MIT", "main": "dist/main.js", "module": "dist/module.js",