Skip to content

Commit

Permalink
Fix shaderlab loader in NPM mode (#2427)
Browse files Browse the repository at this point in the history
* fix: npm package loader shader bug
  • Loading branch information
Sway007 authored Nov 7, 2024
1 parent 4c0cfd0 commit 65594f0
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/loader/src/MaterialLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,23 @@ class MaterialLoader extends Loader<Material> {
.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<Shader>(<IAssetRef>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<Material> {
private _getMaterialByShader(materialSchema: IMaterialSchema, shader: Shader, engine: Engine): Promise<Material> {
const { name, shaderData, macros, renderState } = materialSchema;

const material = new Material(engine, shader);
Expand Down

0 comments on commit 65594f0

Please sign in to comment.