This commit is contained in:
duckietm
2025-03-18 10:46:22 +01:00
parent 00790c0789
commit 8acd0c7de4
4 changed files with 187 additions and 213 deletions
@@ -2,39 +2,47 @@ import { Texture } from 'pixi.js';
import { IsometricImageFurniVisualization } from './IsometricImageFurniVisualization';
export class FurnitureDynamicThumbnailVisualization extends IsometricImageFurniVisualization {
private _cachedUrl: string;
private _cachedUrl: string;
constructor() {
super();
this._cachedUrl = null;
this._hasOutline = true;
}
constructor() {
super();
protected updateModel(scale: number): boolean {
if (this.object) {
const thumbnailUrl = this.getThumbnailURL();
if (this._cachedUrl !== thumbnailUrl) {
this._cachedUrl = thumbnailUrl;
if (this._cachedUrl && this._cachedUrl !== '') {
const image = new Image();
image.crossOrigin = '*';
image.onload = this.onImageLoad.bind(this, image);
image.src = thumbnailUrl;
} else {
this.setThumbnailImages(null);
}
}
this._cachedUrl = null;
this._hasOutline = true;
}
return super.updateModel(scale);
}
private onImageLoad(image: HTMLImageElement): void {
const texture = Texture.from(image);
texture.source.scaleMode = 'linear';
this.setThumbnailImages(texture);
}
protected updateModel(scale: number): boolean {
if (this.object) {
const thumbnailUrl = this.getThumbnailURL();
protected getThumbnailURL(): string {
throw new Error('This method must be overridden!');
}
if (this._cachedUrl !== thumbnailUrl) {
this._cachedUrl = thumbnailUrl;
if (this._cachedUrl && this._cachedUrl !== '') {
const image = new Image();
image.src = thumbnailUrl;
image.crossOrigin = '*';
image.onload = () => {
if (image.complete && image.width > 0 && image.height > 0) {
const texture = Texture.from(image);
texture.source.scaleMode = 'linear';
this.setThumbnailImages(texture, thumbnailUrl); // Pass URL here
} else {
console.error("Image failed to load properly:", thumbnailUrl);
}
};
} else {
this.setThumbnailImages(null);
}
}
}
return super.updateModel(scale);
}
protected getThumbnailURL(): string {
throw new Error('This method must be overridden!');
}
}