Beispiel #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);
        }
    }
Beispiel #2
0
    Mesher CreateLiquidMesher(float[][] layers, LayeredBrush brush)
    {
        var liquid_mesher    = new Mesher();
        var prepass_material = Resources.Load <Material>("LiquidMaterials/LiquidPrepass");

        liquid_mesher.Init("Liquid", layers, m_grid_width_in_voxels, m_grid_height_in_voxels, m_grid_depth_in_voxels, m_voxel_size_in_meters, m_liquid_voxel_chunk_dimenions, false, m_liquid_iso_level, 1f, brush, false, true, prepass_material, m_bevel_tuning);

        return(liquid_mesher);
    }
Beispiel #3
0
    Mesher CreateSolidMesher(float[][] layers, LayeredBrush brush)
    {
        var solid_mesher = new Mesher();

        solid_mesher.Init("Solid", layers, m_grid_width_in_voxels, m_grid_height_in_voxels, m_grid_depth_in_voxels, m_voxel_size_in_meters, m_solid_voxel_chunk_dimenions, true, m_solid_iso_level, 0f, brush, true, false, null, m_bevel_tuning);

        //solid_mesher.enabled = false;

        return(solid_mesher);
    }
Beispiel #4
0
    void CreateGroundPlane(LayeredBrush brush)
    {
        m_ground_plane      = GameObject.CreatePrimitive(PrimitiveType.Plane);
        m_ground_plane.name = "GroundPlane";

        brush.GetMaterialForLayer(0, out var material);

        var ground_plane_mesh_renderer = m_ground_plane.GetComponent <MeshRenderer>();

        ground_plane_mesh_renderer.sharedMaterial = material;
        ground_plane_mesh_renderer.receiveShadows = false;
        m_ground_plane.transform.localScale       = new Vector3(m_ground_plane_size, 1, m_ground_plane_size);
        m_ground_plane.transform.localPosition    = new Vector3(0, -0.5f, 0);
    }