Skip to content

Commit

Permalink
fix: load gltf has no material (#408)
Browse files Browse the repository at this point in the history
* fix: load gltf has no material
  • Loading branch information
czizzy authored Jul 30, 2021
1 parent 8585af9 commit 731a74d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
52 changes: 27 additions & 25 deletions packages/loader/src/scene-loader/resources/GLTFResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,35 @@ export class GLTFResource extends SchemaResource {
}
}
};
for (let i = 0; i < materials.length; i++) {
const material = materials[i];
let materialResource = null;
let type = "";
if (materials?.length) {
for (let i = 0; i < materials.length; i++) {
const material = materials[i];
let materialResource = null;
let type = "";

if (material instanceof PBRMaterial) {
materialResource = new PBRMaterialResource(this.resourceManager);
type = "PBRMaterial";
} else if (material instanceof UnlitMaterial) {
materialResource = new UnlitMaterialResource(this.resourceManager);
type = "UnlitMaterial";
} else if (material instanceof PBRSpecularMaterial) {
materialResource = new PBRSpecularMaterialResource(this.resourceManager);
type = "PBRSpecularMaterial";
} else {
materialResource = new BlinnPhongMaterialResource(this.resourceManager);
type = "BlinnPhongMaterial";
}
if (material instanceof PBRMaterial) {
materialResource = new PBRMaterialResource(this.resourceManager);
type = "PBRMaterial";
} else if (material instanceof UnlitMaterial) {
materialResource = new UnlitMaterialResource(this.resourceManager);
type = "UnlitMaterial";
} else if (material instanceof PBRSpecularMaterial) {
materialResource = new PBRSpecularMaterialResource(this.resourceManager);
type = "PBRSpecularMaterial";
} else {
materialResource = new BlinnPhongMaterialResource(this.resourceManager);
type = "BlinnPhongMaterial";
}

this._attachedResources.push(materialResource);
loadPromises.push(
materialResource.loadWithAttachedResources(resourceManager, {
type,
name: material.name,
resource: material
})
);
this._attachedResources.push(materialResource);
loadPromises.push(
materialResource.loadWithAttachedResources(resourceManager, {
type,
name: material.name,
resource: material
})
);
}
}
Promise.all(loadPromises).then((res) => {
const newMaterial = result.structure.props.newMaterial;
Expand Down
3 changes: 0 additions & 3 deletions packages/loader/src/scene-loader/resources/TextureResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ export class TextureResource extends SchemaResource {
setMeta() {
if (this.resource) {
this._meta.name = this.resource.name;
if (this.resource.image) {
this._meta.url = this.resource.image.src;
}
}
}
}

0 comments on commit 731a74d

Please sign in to comment.