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

class SphereShape extends Shape {
		constructor(device, args = {}){
				super(device, 'sphereCenter', args), this._radius = 0.06, this._tolerance = 0.05;
				this._radius = args.radius ?? this._radius;
				this._tolerance = args.tolerance ?? this._tolerance;
				this.triData = [
						new TriData(new SphereGeometry(), 2)
				];
				this._createRenderComponent(this.entity, [
						Mesh.fromGeometry(this.device, new SphereGeometry({
								latitudeBands: 32,
								longitudeBands: 32
						}))
				]);
				this._update();
		}
		set radius(value) {
				this._radius = value ?? this._radius;
				this._update();
		}
		get radius() {
				return this._radius;
		}
		set tolerance(value) {
				this._tolerance = value ?? this._tolerance;
				this._update();
		}
		get tolerance() {
				return this._tolerance;
		}
		_update() {
				const scale = this._radius * 2;
				this.entity.setLocalScale(scale, scale, scale);
		}
}

export { SphereShape };
