import { useMemo } from "react";
import * as THREE from "three";

export function AsteroidMesh({ scale = 1, color = "#4b3a5f" }: { scale?: number; color?: string }) {
  const geometry = useMemo(() => {
    const geo = new THREE.IcosahedronGeometry(scale, 1);
    const pos = geo.attributes.position;
    for (let i = 0; i < pos.count; i += 1) {
      const n = 0.75 + Math.random() * 0.55;
      pos.setXYZ(i, pos.getX(i) * n, pos.getY(i) * n, pos.getZ(i) * n);
    }
    geo.computeVertexNormals();
    return geo;
  }, [scale]);

  return (
    <mesh geometry={geometry}>
      <meshStandardMaterial color={color} roughness={0.85} metalness={0.08} flatShading />
    </mesh>
  );
}
