import * as THREE from 'three';
import '../../globals.js';
// Copyright 2019-2024, University of Colorado Boulder
/**
 * Creates a quad for a given texture with a specific width and height, in the 3d space
 * with x: [0,width] and y: [0,height].
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import Disposable from '../../axon/js/Disposable.js';
import { combineOptions } from '../../phet-core/js/optionize.js';
import mobius from './mobius.js';
import Quad from './Quad.js';
export default class TextureQuad extends THREE.Mesh {
    constructor(texture, width, height, materialOptions) {
        const quadGeometry = new Quad(0, 0, 0, width, 0, 0, width, height, 0, 0, height, 0, 0, 0, 1);
        const basicMaterial = new THREE.MeshBasicMaterial(combineOptions({
            transparent: true,
            depthTest: false,
            map: texture
        }, materialOptions));
        super(quadGeometry, basicMaterial);
        this.disposable = new Disposable();
        this.quadGeometry = quadGeometry;
        this.basicMaterial = basicMaterial;
        this.textureQuadWidth = width;
        this.textureQuadHeight = height;
        this.disposeEmitter = this.disposable.disposeEmitter;
    }
    updateTexture(texture, width = this.textureQuadWidth, height = this.textureQuadHeight) {
        this.basicMaterial.map = texture;
        this.basicMaterial.needsUpdate = true;
        if (width !== this.textureQuadWidth || height !== this.textureQuadHeight) {
            this.textureQuadWidth = width;
            this.textureQuadHeight = height;
            this.quadGeometry.set(0, 0, 0, width, 0, 0, width, height, 0, 0, height, 0, 0, 0, 1);
        }
    }
    /**
     * Releases references
     */
    dispose() {
        this.quadGeometry.dispose();
        this.basicMaterial.dispose();
        this.disposable.dispose();
        // @ts-expect-error
        super.dispose && super.dispose();
    }
}
mobius.register('TextureQuad', TextureQuad);
//# sourceMappingURL=TextureQuad.js.map