import { useMemo } from "react";
import * as THREE from "three";
import BaseMesh, { BaseMeshProps } from "../BaseMesh";

export interface ConeGeometry {
    radius: number;
    height: number;
    radialSegments?: number;
    heightSegments?: number;
    openEnded?: boolean;
    thetaStart?: number;
    thetaLength?: number;
}

interface Props extends Omit<BaseMeshProps, "geometry"> {
    geometry: ConeGeometry;
}

export default function Cone(props: Props) {
    const { geometry } = props;

    const geo = useMemo(() => {
        return new THREE.ConeGeometry(
            geometry.radius,
            geometry.height,
            geometry.radialSegments ?? 24,
            geometry.heightSegments ?? 1,
            geometry.openEnded ?? false,
            geometry.thetaStart ?? 0,
            geometry.thetaLength ?? Math.PI * 2
        );
    }, [
        geometry.radius,
        geometry.height,
        geometry.radialSegments,
        geometry.heightSegments,
        geometry.openEnded,
        geometry.thetaStart,
        geometry.thetaLength
    ]);

    return <BaseMesh {...props} geometry={geo} />;
}