import '../../globals.js';
// Copyright 2021-2024, University of Colorado Boulder
/**
 * Helps writing buffer-array style triangles into buffers.
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import Vector3 from '../../dot/js/Vector3.js';
import mobius from './mobius.js';
export default class TriangleArrayWriter {
    /**
     * @param positionArray
     * @param normalArray
     * @param uvArray
     * @param offset - How many vertices have been specified so far?
     * @param offsetPosition - How to transform all of the points
     */
    constructor(positionArray, normalArray, uvArray, offset = 0, offsetPosition = Vector3.ZERO) {
        this.positionArray = positionArray;
        this.normalArray = normalArray;
        this.uvArray = uvArray;
        this.positionIndex = offset * 3;
        this.normalIndex = offset * 3;
        this.uvIndex = offset * 2;
        this.offset = offset;
        this.offsetPosition = offsetPosition;
    }
    /**
     * Writes a position into the (optional) positionArray, and increments the offset.
     */
    position(x, y, z) {
        if (this.positionArray) {
            this.positionArray[this.positionIndex++] = x + this.offsetPosition.x;
            this.positionArray[this.positionIndex++] = y + this.offsetPosition.y;
            this.positionArray[this.positionIndex++] = z + this.offsetPosition.z;
        }
        this.offset++;
    }
    /**
     * Writes a normal into the (optional) normalArray
     */
    normal(x, y, z) {
        if (this.normalArray) {
            this.normalArray[this.normalIndex++] = x;
            this.normalArray[this.normalIndex++] = y;
            this.normalArray[this.normalIndex++] = z;
        }
    }
    /**
     * Writes a UV into the (optional) uvArray
     */
    uv(u, v) {
        if (this.uvArray) {
            this.uvArray[this.uvIndex++] = u;
            this.uvArray[this.uvIndex++] = v;
        }
    }
    /**
     * Returns the offset (previous offset + number of triangles added, counted from the positionArray)
     */
    getOffset() {
        return this.offset;
    }
}
mobius.register('TriangleArrayWriter', TriangleArrayWriter);
//# sourceMappingURL=TriangleArrayWriter.js.map