From 65594f017720c833db022cd2fd28a67f1238e32b Mon Sep 17 00:00:00 2001 From: SwayYan Date: Thu, 7 Nov 2024 15:22:05 +0800 Subject: [PATCH] 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);