import { BoxGeometry } from '../../../scene/geometry/box-geometry.js';
import { Mesh } from '../../../scene/mesh.js';
import { TriData } from '../tri-data.js';
import { Shape } from './shape.js';

class BoxShape extends Shape {
		constructor(device, args = {}){
				super(device, 'boxCenter', args), this._size = 0.12, this._tolerance = 0.05;
				this._size = args.size ?? this._size;
				this._tolerance = args.tolerance ?? this._tolerance;
				this.triData = [
						new TriData(new BoxGeometry(), 2)
				];
				this._createRenderComponent(this.entity, [
						Mesh.fromGeometry(this.device, new BoxGeometry())
				]);
				this._update();
		}
		set size(value) {
				this._size = value ?? this._size;
				this._update();
		}
		get size() {
				return this._size;
		}
		set tolerance(value) {
				this._tolerance = value ?? this._tolerance;
				this._update();
		}
		get tolerance() {
				return this._tolerance;
		}
		_update() {
				this.entity.setLocalScale(this._size, this._size, this._size);
		}
}

export { BoxShape };
