/// <summary>
    /// Find out if this voxel already belongs to another bigger component and merge with it.
    /// </summary>
    private bool HasExistingComponent(ref Vector3I indices)
    {
        FluidComponent other = manager.GetComponent(ref indices);

        if (other != null && other != this && other.voxels.Contains(indices) && other.voxels.Count > voxels.Count && other.viscosity == viscosity)
        {
            // transfer voxels to the other component
            foreach (Vector3I myIndices in voxels)
            {
                Vector3I tmpIndices = myIndices;
                manager.AssignComponent(ref tmpIndices, other);
                other.voxels.Add(myIndices);
            }

            // transfer outlets to the other component
            foreach (Vector3I myIndices in outlets)
            {
                Vector3I tmpIndices = myIndices;
                manager.AssignComponent(ref tmpIndices, other);
                other.outlets.Add(myIndices);
            }

            other.Unsettle();

            // stop the search and this component will get removed
            voxels.Clear();
            outlets.Clear();
            manager.searchStack.Clear();

            return(true);
        }

        return(false);
    }
예제 #2
0
    public void AssignComponent(ref Vector3I indices, FluidComponent componentToAssign)
    {
        FluidComponent component;

        voxelComponents.TryGetValue(indices, out component);

        if (component != componentToAssign)
        {
            componentToAssign.Unsettle();
            voxelComponents[indices] = componentToAssign;
        }
    }