function generateAsteroidSurfaces(props) {
    const surfaces = {
        geometry: undefined,
        instances: [],
    };

    const asteroidsGeom = new THREE.Geometry();

    function _generateAsteroidCentroids({ beltRadius, numAsteroids, distBetweenRings, closestRingRadius }) {
        const centroids = [];
        let curRingRadius = closestRingRadius;
        const satelliteSlots = 20; // potential locations on ring for satellite
        while (centroids.length < numAsteroids) {
            curRingRadius += distBetweenRings;
            const orbitRing = new THREE.CircleGeometry(curRingRadius, satelliteSlots);
            const orbitPoint = randomArrayVal(orbitRing.vertices.slice(1, orbitRing.vertices.length));
            orbitPoint.z = [-1, 1][THREE.Math.randInt(0, 1)] * closestRingRadius + beltRadius * (Math.random() - 0.5);
            centroids.push(orbitPoint);
        }
        return centroids;
    }

    function _generateAsteroidNoiseSphere({ centroid, radius }) {
        const noiseSphere = new NoiseSphereGeometry(
            radius,
            10, // sides
            10,//Math.floor(Math.max(radius * Math.random(), radius * 2)), // tiers
            {
                centroid: centroid,
                seed: Math.floor(Math.random() * 1000),
                noiseWidth: 1,
                noiseHeight: 1,
                scale: { x: Math.random() * 1.5, y: 1, z: 1 }
            })
        noiseSphere.verticesNeedUpdate = true;
        noiseSphere.computeBoundingSphere();
        noiseSphere.computeBoundingBox();
        noiseSphere.computeFaceNormals();
        return noiseSphere;
    }

    function _generateAsteroidInstance({ centroid, beltRadius, maxAsteroidRadius }) {
        const radius = THREE.Math.randInt(maxAsteroidRadius * .75, maxAsteroidRadius);
        const asteroidGeom = _generateAsteroidNoiseSphere({ centroid: centroid, radius: radius })
        return {
            geometry: asteroidGeom,
            faces: asteroidGeom.faces,
            vertices: asteroidGeom.vertices,
            centroid: centroid,
            radius: radius,
        }
    }

    surfaces.instances = _generateAsteroidCentroids({ ...props }).map(centroid => {
        const instance = _generateAsteroidInstance({ centroid: centroid, ...props });
        asteroidsGeom.merge(instance.geometry);
        return instance;
    });
    surfaces.geometry = new THREE.BufferGeometry().fromGeometry(asteroidsGeom);
    return surfaces;
}
// then this can become a component again
then this can become a component again
then this can become a component again
function generateAsteroidSurfaces(props) {
    const surfaces = {
        geometry: undefined,
        instances: [],
    };
    const asteroidsGeom = new THREE.Geometry();
    function _generateAsteroidCentroids({ beltRadius, numAsteroids, distBetweenRings, closestRingRadius }) {
        const centroids = [];
        let curRingRadius = closestRingRadius;
        const satelliteSlots = 20; 
        while (centroids.length < numAsteroids) {
            curRingRadius += distBetweenRings;
            const orbitRing = new THREE.CircleGeometry(curRingRadius, satelliteSlots);
            const orbitPoint = randomArrayVal(orbitRing.vertices.slice(1, orbitRing.vertices.length));
            orbitPoint.z = [-1, 1][THREE.Math.randInt(0, 1)] * closestRingRadius + beltRadius * (Math.random() - 0.5);
            centroids.push(orbitPoint);
        }
        return centroids;
    }
    function _generateAsteroidNoiseSphere({ centroid, radius }) {
        const noiseSphere = new NoiseSphereGeometry(
            radius,
            10, 
            10,
            {
                centroid: centroid,
                seed: Math.floor(Math.random() * 1000),
                noiseWidth: 1,
                noiseHeight: 1,
                scale: { x: Math.random() * 1.5, y: 1, z: 1 }
            })
        noiseSphere.verticesNeedUpdate = true;
        noiseSphere.computeBoundingSphere();
        noiseSphere.computeBoundingBox();
        noiseSphere.computeFaceNormals();
        return noiseSphere;
    }
    function _generateAsteroidInstance({ centroid, beltRadius, maxAsteroidRadius }) {
        const radius = THREE.Math.randInt(maxAsteroidRadius * .75, maxAsteroidRadius);
        const asteroidGeom = _generateAsteroidNoiseSphere({ centroid: centroid, radius: radius })
        return {
            geometry: asteroidGeom,
            faces: asteroidGeom.faces,
            vertices: asteroidGeom.vertices,
            centroid: centroid,
            radius: radius,
        }
    }
    surfaces.instances = _generateAsteroidCentroids({ ...props }).map(centroid => {
        const instance = _generateAsteroidInstance({ centroid: centroid, ...props });
        asteroidsGeom.merge(instance.geometry);
        return instance;
    });
    surfaces.geometry = new THREE.BufferGeometry().fromGeometry(asteroidsGeom);
    return surfaces;
}
function generateAsteroidSurfaces ( props ) { const surfaces = { geometry : undefined , instances : [ ] , } ; const asteroidsGeom = new THREE . Geometry ( ) ; function _generateAsteroidCentroids ( { beltRadius , numAsteroids , distBetweenRings , closestRingRadius } ) { const centroids = [ ] ; let curRingRadius = closestRingRadius ; const satelliteSlots = 20 ; while ( centroids . length < numAsteroids ) { curRingRadius += distBetweenRings ; const orbitRing = new THREE . CircleGeometry ( curRingRadius , satelliteSlots ) ; const orbitPoint = randomArrayVal ( orbitRing . vertices . slice ( 1 , orbitRing . vertices . length ) ) ; orbitPoint . z = [ - 1 , 1 ] [ THREE . Math . randInt ( 0 , 1 ) ] * closestRingRadius + beltRadius * ( Math . random ( ) - 0.5 ) ; centroids . push ( orbitPoint ) ; } return centroids ; } function _generateAsteroidNoiseSphere ( { centroid , radius } ) { const noiseSphere = new NoiseSphereGeometry ( radius , 10 , 10 , { centroid : centroid , seed : Math . floor ( Math . random ( ) * 1000 ) , noiseWidth : 1 , noiseHeight : 1 , scale : { x : Math . random ( ) * 1.5 , y : 1 , z : 1 } } ) noiseSphere . verticesNeedUpdate = true ; noiseSphere . computeBoundingSphere ( ) ; noiseSphere . computeBoundingBox ( ) ; noiseSphere . computeFaceNormals ( ) ; return noiseSphere ; } function _generateAsteroidInstance ( { centroid , beltRadius , maxAsteroidRadius } ) { const radius = THREE . Math . randInt ( maxAsteroidRadius * .75 , maxAsteroidRadius ) ; const asteroidGeom = _generateAsteroidNoiseSphere ( { centroid : centroid , radius : radius } ) return { geometry : asteroidGeom , faces : asteroidGeom . faces , vertices : asteroidGeom . vertices , centroid : centroid , radius : radius , } } surfaces . instances = _generateAsteroidCentroids ( { ... props } ) . map ( centroid => { const instance = _generateAsteroidInstance ( { centroid : centroid , ... props } ) ; asteroidsGeom . merge ( instance . geometry ) ; return instance ; } ) ; surfaces . geometry = new THREE . BufferGeometry ( ) . fromGeometry ( asteroidsGeom ) ; return surfaces ; }
then this can become a component again
then this can become a component again
// potential locations on ring for satellite // sides //Math.floor(Math.max(radius * Math.random(), radius * 2)), // tiers