Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        private void DisplayStackDensity()
        {
            CellLayer[]   layers   = _manager.Layers;
            StackAnalyser analyser = _manager.Analyser;

            Index3[] neighb = Neighborhoods.Moore3Cen;

            //apply material props to each obj renderer
            for (int k = 0; k < layers.Length; k++)
            {
                CellLayer layer = layers[k];
                int       m     = layer.Rows;
                int       n     = layer.Columns;

                Cell[,] cells = layer.Cells;

                for (int i = 0; i < m; i++)
                {
                    // Note: keep the 2nd index on the inner loop for better cache locality
                    for (int j = 0; j < m; j++)
                    {
                        Cell cell = cells[i, j];

                        // skip dead cells
                        if (cell.State == 0)
                        {
                            continue;
                        }

                        // map density to color
                        int   sum   = analyser.GetNeighborSum3(i, j, k, neighb);
                        float value = Remap(sum, 0, neighb.Length, 0, 1);
                        Color color = Color.Lerp(Color.white, _stackDensityColor, value);

                        //change color of material property block
                        _materialprops.SetColor("_Color", color);
                        cell.Renderer.SetPropertyBlock(_materialprops);
                    }
                }
            }
        }