Пример #1
0
        private void EditVoxels(Vector3 point)
        {
            int centerX = (int)((point.x + halfSize) / voxelSize);
            int centerY = (int)((point.y + halfSize) / voxelSize);

            //int chunkX = centerX / voxelResolution;
            //int chunkY = centerY / voxelResolution;

            //centerX -= chunkX * voxelResolution;
            //centerY -= chunkY * voxelResolution;

            int xStart = (centerX - radiusIndex - 1) / voxelResolution;

            xStart = xStart < 0 ? 0 : xStart;

            int xEnd = (centerX + radiusIndex) / voxelResolution;

            xEnd = xEnd > chunkResolution - 1 ? chunkResolution - 1 : xEnd;

            int yStart = (centerY - radiusIndex - 1) / voxelResolution;

            yStart = yStart < 0 ? 0 : yStart;

            int yEnd = (centerY + radiusIndex) / voxelResolution;

            yEnd = yEnd > chunkResolution - 1 ? chunkResolution - 1 : yEnd;

            VoxelStencile activeStencile = stenciles[stencileIndex];

            activeStencile.Init(filledTypeIndex == 0, radiusIndex, voxelResolution);

            int voxelYOffset = yEnd * voxelResolution;

            for (int y = yEnd; y >= yStart; y--)
            {
                int i = y * chunkResolution + xEnd;

                int voxelXOffset = xEnd * voxelResolution;

                for (int x = xEnd; x >= xStart; x--, i--)
                {
                    activeStencile.SetCenter(centerX - voxelXOffset, centerY - voxelYOffset);
                    chunks[i].Apply(activeStencile);

                    voxelXOffset -= voxelResolution;
                }
                voxelYOffset -= voxelResolution;
            }


            //Debug.Log(voxelX + " " + voxelY + " in " + chunkX + " " + chunkY);
        }
Пример #2
0
        public void Apply(VoxelStencile stencile)
        {
            for (int y = stencile.yStart; y <= stencile.yEnd; y++)
            {
                int i = y * resolution + stencile.xStart;
                for (int x = stencile.xStart; x <= stencile.xEnd; x++, i++)
                {
                    voxels[i].state = stencile.Apply(x, y, voxels[i].state);
                }
            }

            Refresh();
        }