Esempio n. 1
0
        protected void traverse(VoxelUpdateInfo info, byte detailLevel)
        {
            int  factor = 1 << (detailLevel - VoxelBlock.CHILD_COUNT_POWER);
            byte xiMin  = (byte)Mathf.Max(minX / factor - info.x * VoxelBlock.CHILD_DIMENSION, 0f);
            byte xiMax  = (byte)Mathf.Min((maxX + 1) / factor - info.x * VoxelBlock.CHILD_DIMENSION, VoxelBlock.CHILD_DIMENSION - 1f);
            byte yiMin  = (byte)Mathf.Max(minY / factor - info.y * VoxelBlock.CHILD_DIMENSION, 0f);
            byte yiMax  = (byte)Mathf.Min((maxY + 1) / factor - info.y * VoxelBlock.CHILD_DIMENSION, VoxelBlock.CHILD_DIMENSION - 1f);
            byte ziMin  = (byte)Mathf.Max(minZ / factor - info.z * VoxelBlock.CHILD_DIMENSION, 0f);
            byte ziMax  = (byte)Mathf.Min((maxZ + 1) / factor - info.z * VoxelBlock.CHILD_DIMENSION, VoxelBlock.CHILD_DIMENSION - 1f);

            VoxelBlock block = (VoxelBlock)info.blocks[1, 1, 1];

            uint scale = (uint)(1 << (VoxelBlock.CHILD_COUNT_POWER * (detailLevel - 1)));

            for (byte yi = yiMin; yi <= yiMax; ++yi)
            {
                if ((info.y * VoxelBlock.CHILD_DIMENSION + yi) < maskMinY / scale ||
                    (info.y * VoxelBlock.CHILD_DIMENSION + yi) > maskMaxY / scale + 1)
                {
                    continue;
                }

                for (byte xi = xiMin; xi <= xiMax; ++xi)
                {
                    for (byte zi = ziMin; zi <= ziMax; ++zi)
                    {
                        if (detailLevel <= VoxelBlock.CHILD_COUNT_POWER)
                        {
                            block.children[xi, yi, zi] = modifyVoxel(block.children[xi, yi, zi], info.x * VoxelBlock.CHILD_DIMENSION + xi, info.y * VoxelBlock.CHILD_DIMENSION + yi, info.z * VoxelBlock.CHILD_DIMENSION + zi);
                        }
                        else
                        {
                            if (block.children[xi, yi, zi].GetType() == typeof(Voxel))
                            {
                                block.children[xi, yi, zi] = new VoxelBlock((Voxel)block.children[xi, yi, zi]);
                            }
                            traverse(new VoxelUpdateInfo(info, xi, yi, zi), (byte)(detailLevel - VoxelBlock.CHILD_COUNT_POWER));
                        }
                    }
                }
            }

            if (updateMesh && info != null && (VoxelBlock.isRenderSize(info.size, control) || VoxelBlock.isRenderLod(info.x, info.y, info.z, info.size, control)))
            {
                //block.clearSubRenderers(control);
                block.updateAll(info.x, info.y, info.z, info.detailLevel, control, true);
            }
        }
Esempio n. 2
0
        public override void execute()
        {
            //MonoBehaviour.print("APPLYING!");
            Vector3 pos = rend.position / rend.size;

            if (VoxelBlock.isRenderLod(pos.x, pos.y, pos.z, rend.size, rend.control) || VoxelBlock.isRenderSize(rend.size, rend.control))
            {
                rend.applyMesh(detailLevel, x, y, z);
            }
        }