Skip to content

Commit

Permalink
feat: improve 3d model texture loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Gugustinette committed Sep 3, 2024
1 parent 74b9e06 commit da8f213
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/3d/src/model/FModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,20 @@ export abstract class FModel extends FComponent {
texturePath = this.textures[mesh.material.name]
}
else {
// Otherwise, use a default path
texturePath = `assets/${this.name}/Textures/colormap.png`
// Otherwise, if a "default" texture is provided, use it
if (this.textures.default)
texturePath = this.textures.default
// Otherwise, consider the default texture path to be the colormap.png
else
texturePath = `${window.location.href}/assets/${this.name}/Textures/colormap.png`
}
// Load the texture
textureLoader.load(texturePath, (texture) => {
texture.colorSpace = THREE.SRGBColorSpace
// Apply the texture to the material
mesh.material = new THREE.MeshBasicMaterial({ map: texture })
}, undefined, (error) => {
console.error(`FibboError: An error happened while loading the texture for model: name(${this.name}) path(${this.path}) materialName(${mesh.material instanceof THREE.Mesh ? mesh.material.name : 'ERROR'}) texturePath(${texturePath})`)
console.error(`FibboError: An error happened while loading the texture for model: name(${this.name}) path(${this.path}) materialName(${mesh.material instanceof THREE.Mesh ? mesh.material.name : 'ERROR-NO-MATERIAL-NAME'}) texturePath(${texturePath})`)
console.error(error)
})
}
Expand Down

0 comments on commit da8f213

Please sign in to comment.