From da8f2137575a9f0af203f358ca534bf6c48797b6 Mon Sep 17 00:00:00 2001 From: Gugustinette Date: Tue, 3 Sep 2024 17:35:27 +0200 Subject: [PATCH] feat: improve 3d model texture loading --- packages/3d/src/model/FModel.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/3d/src/model/FModel.ts b/packages/3d/src/model/FModel.ts index 0441f5fc..cceeb088 100644 --- a/packages/3d/src/model/FModel.ts +++ b/packages/3d/src/model/FModel.ts @@ -164,8 +164,12 @@ 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) => { @@ -173,7 +177,7 @@ export abstract class FModel extends FComponent { // 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) }) }