Ejemplo n.º 1
0
    public void Init(
        string name,
        float[][] density_grids,
        int grid_width_in_voxels,
        int grid_height_in_voxels,
        int grid_depth_in_voxels,
        Vector3 voxel_size_in_meters,
        int voxel_chunk_dimesnions,
        bool generate_collision,
        float iso_level,
        float density_height_weight,
        LayeredBrush brush,
        bool cast_shadows,
        bool is_liquid,
        Material prepass_material,
        BevelTuning bevel_tuning
        )
    {
        m_voxel_chunk_dimensions = voxel_chunk_dimesnions;
        m_voxel_size_in_meters   = voxel_size_in_meters;
        m_grid_width_in_voxels   = grid_width_in_voxels;
        m_grid_height_in_voxels  = grid_height_in_voxels;
        m_grid_depth_in_voxels   = grid_depth_in_voxels;

        m_empty_sample_grid          = new byte[m_grid_width_in_voxels * m_grid_depth_in_voxels];
        m_voxel_chunk_scratch_buffer = VoxelChunk.ScratchBuffer.CreateScratchBuffer();
        m_layers           = new VoxelLayer[m_grid_height_in_voxels];
        m_brush            = brush;
        m_cast_shadows     = cast_shadows;
        m_prepass_material = prepass_material;


        for (int y = 0; y < m_grid_height_in_voxels; ++y)
        {
            float bot_y = (float)(y - 1) * m_voxel_size_in_meters.y;
            float top_y = (float)y * m_voxel_size_in_meters.y;

            var layer = new VoxelLayer(name, density_grids[y], y, m_grid_width_in_voxels, m_grid_depth_in_voxels, m_voxel_chunk_dimensions, m_voxel_size_in_meters, iso_level, bot_y, top_y, generate_collision, density_height_weight, m_vertex_attribute_descriptors, is_liquid, bevel_tuning);
            m_layers[y] = layer;
        }

        for (int y = 0; y < m_grid_height_in_voxels; ++y)
        {
            var layer_above_occlusion_grid = m_empty_sample_grid;
            var layer_below_occlusion_grid = m_empty_sample_grid;

            if (y > 0)
            {
                layer_below_occlusion_grid = m_layers[y - 1].GetSampleGrid();
            }

            if (y < m_grid_height_in_voxels - 2)
            {
                layer_above_occlusion_grid = m_layers[y + 1].GetSampleGrid();
            }

            m_layers[y].SetAboveAndBelowSampleGrids(layer_above_occlusion_grid, layer_below_occlusion_grid);
        }
    }
Ejemplo n.º 2
0
    public override bool Calculate()
    {
        if (!block1Connection.connected() || !block2Connection.connected())
        {
            return(false);
        }
        VoxelBlock <Voxel> block1 = block1Connection.GetValue <VoxelBlock <Voxel> >();
        VoxelBlock <Voxel> block2 = block2Connection.GetValue <VoxelBlock <Voxel> >();

        int overlap = block1.Overlap;
        int width   = block1.Width;
        int height  = block1.Height;
        int length  = block1.Length;

        for (int y = 0; y < height + 2 * overlap; y++)
        {
            VoxelLayer <Voxel> l1 = block1.Layers[y];
            VoxelLayer <Voxel> l2 = block2.Layers[y];
            for (int x = 0; x < width + 2 * overlap; x++)
            {
                for (int z = 0; z < length + 2 * overlap; z++)
                {
                    var v1 = l1.Layer[x, z];
                    var v2 = l2.Layer[x, z];
                    switch (mode)
                    {
                    case CombiningMode.Average:
                        v1.Data = (v1.Data + v2.Data) / 2;
                        break;

                    case CombiningMode.Add:
                        v1.Data = v1.Data + v2.Data;
                        break;

                    case CombiningMode.Subtract:
                        v1.Data = v1.Data - v2.Data;
                        break;

                    case CombiningMode.Divide:
                        if (v2.Data != 0)
                        {
                            v1.Data = v1.Data / v2.Data;
                        }
                        break;

                    case CombiningMode.Multiply:
                        v1.Data = v1.Data * v2.Data;
                        break;
                    }
                }
            }
        }
        outputConnection.SetValue(block1);

        return(true);
    }
Ejemplo n.º 3
0
 void AddToActiveLayers(VoxelLayer layerToTest)
 {
     if (layerToTest != null)
     {
         if (layerToTest.ID < currentActiveID)
         {
             activeLayer = layerToTest;
             // if (currentActiveID == layersCount)
             currentActiveID = layerToTest.ID;
         }
     }
 }
Ejemplo n.º 4
0
 protected override bool CalculateLayer(VoxelLayer <T> layer, int index)
 {
     for (int x = -layer.Overlap; x < layer.Width + layer.Overlap; x++)
     {
         for (int z = -layer.Overlap; z < layer.Length + layer.Overlap; z++)
         {
             if (!CalculateVoxel(layer[x, z], x, index, z))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Ejemplo n.º 5
0
 protected override bool CalculateLayer(VoxelLayer <T> layer, int index)
 {
     T[,] voxelLayer = layer.Layer;
     for (int x = 0; x < voxelLayer.GetLength(0); x++)
     {
         for (int z = 0; z < voxelLayer.GetLength(1); z++)
         {
             if (!CalculateVoxel(voxelLayer[x, z], x, index, z))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Ejemplo n.º 6
0
    public VoxelLayer(VoxelLayer <T> l)
    {
        this.Overlap = l.Overlap;
        int width  = l.layer.GetLength(0);
        int length = l.layer.GetLength(1);

        this.layer = new T[width, length];
        for (int x = 0; x < width; x++)
        {
            for (int z = 0; z < length; z++)
            {
                this.layer[x, z] = (T)l.layer[x, z].Clone();
            }
        }
        recalcDim();
    }
Ejemplo n.º 7
0
    VoxelLayer ExtractVoxelLayer(RaycastHit hit)
    {
        GameObject obj = hit.collider.gameObject;

        if (obj.tag == "layer")
        {
            VoxelGridSurface surf = obj.GetComponent <VoxelGridSurface>();

            VoxelLayer foundLayer = surf != null
                ? obj.transform.parent.parent.GetComponent <VoxelLayer>()
                : obj.GetComponent <VoxelLayer>();

            if (foundLayer != null)
            {
                return(foundLayer);
            }
        }
        return(null);
    }
Ejemplo n.º 8
0
    VoxelBlock <Voxel> InitBlock(Vector3Int size)
    {
        VoxelBlock <Voxel> block = new VoxelBlock <Voxel>();

        VoxelLayer <Voxel>[] layers = new VoxelLayer <Voxel> [size.y];
        for (int y = 0; y < size.y; y++)
        {
            Voxel[,] voxelLayer = new Voxel[size.x, size.z];
            for (int x = 0; x < size.x; x++)
            {
                for (int z = 0; z < size.z; z++)
                {
                    voxelLayer[x, z] = new Voxel();
                }
            }
            layers[y] = new VoxelLayer <Voxel>(voxelLayer);
        }
        block.Layers = layers;
        return(block);
    }
Ejemplo n.º 9
0
    protected override VoxelBlock <Voxel> InitBlock(VoxelBlock <Voxel> block)
    {
        int size = 64;

        VoxelLayer <Voxel>[] layers = new VoxelLayer <Voxel> [64];
        for (int y = 0; y < size; y++)
        {
            Voxel[,] voxelLayer = new Voxel[size, size];
            for (int x = 0; x < size; x++)
            {
                for (int z = 0; z < size; z++)
                {
                    voxelLayer[x, z] = new Voxel();
                    if (y < size / 2)
                    {
                        voxelLayer[x, z].Data = 1.0f;
                    }
                }
            }
            layers[y] = new VoxelLayer <Voxel>(voxelLayer);
        }
        block.Layers = layers;
        return(block);
    }
Ejemplo n.º 10
0
 protected abstract bool CalculateLayer(VoxelLayer <T> layer, int index);