I am attempting to replace the texture on models displayed in Cesium during runtime. Here’s the code I’m using:
// Replace the texture with the correct one for this airline
// New texture must be the same size as the original texture
var textureIndexToReplace = 0;
var textures = model._rendererResources.textures;
var texture = textures[textureIndexToReplace];
url : “resources/liveries/” + model[‘ModelId’] + “_” + model[‘Airline’] + “.jpg”
texture.generateMipmap(); // Also replaces textures in mipmap
I am successfully updating the texture on the models. However, it appears that when the fetchImage URL points to a location that doesn’t exist (an image doesn’t exist for the model/airline combination being requested) the last image successfully fetched is applied to the model.
I have attempted to add .otherwise to the fetchImage function/promise, but the incorrect image is still applied to the model when the URL points to an invalid image. I’ve also tried wrapping the fetchImage function/promise in a try/catch but I get the same result. I do end up in the .otherwise or catch code when the image is not found (indicating an error or response of some sort is happening, but the incorrect image is still applied to the model.
If someone could help point me in the right direction to resolve this I’d really appreciate it!