Divide volume depending on chosen amount.

Hi,
I’m a bit stuck and could do with some help please, I’ve put together a script to find the bounds of a prefab that helps me place light probes but what I’d like to do is if I ask for 2, 3 or 4 light probe volumes I’d like to divide the bounds up like in the pictures below, any ideas on how to efficiently do this, thanks.

function findBounds ()
{
    ClearBounds();
    probePositions.Clear();

    var allChildren = transform.root.gameObject.GetComponentsInChildren(Transform);

    for ( var child : Transform in allChildren)
    {
        if(child.gameObject.GetComponent.<Renderer>() != null)
            meshRenererArray.Add(child.gameObject.GetComponent.<Renderer>());
    }
     for (var i: int = 0; i < meshRenererArray.Count; i++)
     {
         boundsArray.Add(meshRenererArray[i].bounds);
         _center += meshRenererArray[i].bounds.center;
     }
//center is average center of children
     _center /= transform.root.childCount;
     totalBound = new Bounds(_center, Vector3.zero);

     for (var ii: int = 0; ii < boundsArray.Count; ii++)
     {
         b = new Bounds(boundsArray[ii].center, boundsArray[ii].size);
         totalBound.Encapsulate(boundsArray[ii]); 
    }
    transform.position = totalBound.center;

    for ( var area: LightProbeArea in LightProbeVolumes)
    {
        area.ProbeVolume.extents = totalBound.size;
        area.ProbeVolume.center = totalBound.center;
    }
}

2868659--210150--Cubes_00.jpg

Divide the bounds by the required slices and fill up the space with so many items?

1 Like

Yeah think I was just being idle, thanks for the prod … Added this …

    var outerBounds : float = (totalBound.center.x - (totalBound.size.x/2));
    var _newCenters : float = (totalBound.extents.x / LightProbeVolumes.Length);
    var newPosX : float = (outerBounds + _newCenters);

    totalBound.size.x /= LightProbeVolumes.Length;

    var newCenter : float = (totalBound.center.x - (totalBound.size.x/2));

    for ( var area: LightProbeArea in LightProbeVolumes)
    {
        area.ProbeVolume.extents = totalBound.size;

        area.ProbeVolume.center.x = (outerBounds + _newCenters);
        area.ProbeVolume.center.y = totalBound.center.y;
        area.ProbeVolume.center.z = totalBound.center.z;
        _newCenters += area.ProbeVolume.extents.x;
    }

And it divides it up into strips, might change it again so it does squares to.

2869048--210188--Screen Shot_00.jpg