public override bool Stroke(Ray ray, BrickTree tree, VoxelMaterial voxelMaterial, VoxelMaterialAtlas materialAtlas, List <byte> blackList, Queue <OctreeEntry <Brick> > outChangedBricks, Bounds bounds)
    {
        // Find the brick intersected
        OctreeEntry <Brick> brickEntry = FirstBrickIntersected(ray, tree, blackList);

        // If we can't find one return
        if (brickEntry == null)
        {
            return(false);
        }

        Brick brick = brickEntry.entry;

        Vector3 brickPosition = brickEntry.bounds.min;

        dummyVector3.Set(brickEntry.cell.x, brickEntry.cell.y, brickEntry.cell.z);
        // Make sure the brick is within the legal paining bounds
        if (!bounds.Contains(dummyVector3))
        {
            // return false;
        }
        // Clear the resused found queue
        found.Clear();
        // Find which cells are intersected within the grid
        selector.Select(ray, brick, brickPosition, blackList, found);

        if (found.Count == 0)
        {
            return(false);
        }

        Vector3i firstIntersection = found.Dequeue();

        Ray offsetRay = new Ray(new Vector3(ray.origin.x - brickPosition.x, ray.origin.y - brickPosition.y, ray.origin.z - brickPosition.z), ray.direction);

        float distance;

        RayEntersCellFromCell(offsetRay, firstIntersection, dummyVector3i, out distance);

        Vector3i adjacentLocal = dummyVector3i;
        Vector3i adjacentWorld = adjacentLocal + brickEntry.bounds.min;

        dummyVector3.Set(adjacentWorld.x, adjacentWorld.y, adjacentWorld.z);
        if (!bounds.Contains(dummyVector3))
        {
            return(false);
        }

        tree.SetVoxelAt(adjacentWorld.x, adjacentWorld.y, adjacentWorld.z, materialAtlas.GetMaterialId(voxelMaterial));

        Vector3i cellModified = new Vector3i(adjacentWorld.x / tree.BrickDimensionX, adjacentWorld.y / tree.BrickDimensionY, adjacentWorld.z / tree.BrickDimensionZ);

        OctreeEntry <Brick> modified = tree.GetAt(cellModified.x, cellModified.y, cellModified.z);

        outChangedBricks.Enqueue(modified);

        if (adjacentLocal.x == 0)
        {
            modified = tree.GetAt(cellModified.x - 1, cellModified.y, cellModified.z);

            outChangedBricks.Enqueue(modified);
        }
        if (adjacentLocal.y == 0)
        {
            modified = tree.GetAt(cellModified.x, cellModified.y - 1, cellModified.z);

            outChangedBricks.Enqueue(modified);
        }
        if (adjacentLocal.z == 0)
        {
            modified = tree.GetAt(cellModified.x, cellModified.y, cellModified.z - 1);

            outChangedBricks.Enqueue(modified);
        }

        return(true);
    }
Example #2
0
 public abstract bool Stroke(Ray ray, BrickTree tree, VoxelMaterial voxelMaterial, VoxelMaterialAtlas materialAtlas, List <byte> blackList, Queue <OctreeEntry <Brick> > outChangedBricks, Bounds bounds);
 public CubicChunkExtractor(VoxelMaterialAtlas materialAtlas)
 {
     this.materialAtlas = materialAtlas;
 }
Example #4
0
    public override bool Stroke(Ray ray, BrickTree tree, VoxelMaterial voxelMaterial, VoxelMaterialAtlas materialAtlas, List <byte> blackList, Queue <OctreeEntry <Brick> > outChangedBricks, Bounds bounds)
    {
        OctreeEntry <Brick> brickEntry = FirstBrickIntersected(ray, tree, blackList);

        Brick brick = brickEntry.entry;

        Vector3 brickPosition = brickEntry.bounds.min;

        found.Clear();

        selector.Select(ray, brick, brickPosition, blackList, found);

        if (found.Count == 0)
        {
            return(false);
        }

        Vector3i cell = found.Dequeue();

        brick.SetValue(cell.x, cell.y, cell.z, materialAtlas.GetMaterialId(voxelMaterial));

        outChangedBricks.Enqueue(brickEntry);

        if (cell.x == 0)
        {
            OctreeEntry <Brick> modified = tree.GetAt(brickEntry.cell.x - 1, brickEntry.cell.y, brickEntry.cell.z);

            outChangedBricks.Enqueue(modified);
        }
        if (cell.y == 0)
        {
            OctreeEntry <Brick> modified = tree.GetAt(brickEntry.cell.x, brickEntry.cell.y - 1, brickEntry.cell.z);

            outChangedBricks.Enqueue(modified);
        }
        if (cell.z == 0)
        {
            OctreeEntry <Brick> modified = tree.GetAt(brickEntry.cell.x, brickEntry.cell.y, brickEntry.cell.z - 1);

            outChangedBricks.Enqueue(modified);
        }

        return(true);
    }