Пример #1
0
    public void Start()
    {
        setBrush         = new SetVoxelBrush();
        setAdjacentBrush = new SetVoxelAdjacentBrush();

        materialAtlas.LoadFromFile("VoxelAtlas1");

        extractor = new CubicChunkExtractor(materialAtlas);

        Noise2D noise = new PerlinHeightmap(scale, magnitude, 1);

        brickTree = new BrickTree(brickDimensions, noise);

        createAll();
    }
Пример #2
0
    public Chunk ReInitialize(BrickTree brickTree, CubicChunkExtractor extractor, Material material, int brickX, int brickY, int brickZ, Pool <Chunk> chunkPool, Pool <ChunkFromOctreeRequest> parentPool)
    {
        this.brickTree = brickTree;
        this.extractor = extractor;
        this.material  = material;

        this.chunkPool  = chunkPool;
        this.parentPool = parentPool;

        this.chunk = chunkPool.Catch();

        brickCell = new Vector3i(brickX, brickY, brickZ);

        return(chunk);
    }
Пример #3
0
    public void Start()
    {
        foreach (Transform child in this.gameObject.transform)
        {
            chunkPool.Release(new Chunk(child.gameObject));
        }

        Noise2D noise = new FlatNoise(2);

        materialAtlas.LoadFromFile(voxelAtlasFile);

        voxelTree = new BrickTree(brickResolution, noise);

        extractor = new CubicChunkExtractor(materialAtlas);

        createAll();
    }
Пример #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);
    }
Пример #5
0
    public void Extract(BrickTree brickTree, Vector3i brickWorld, List <Color> colors, List <Vector3> vertices, List <Vector3> normals, List <Vector2> uv, List <int> indices, Pool <Color> colorPool, Pool <Vector2> vector2Pool, Pool <Vector3> vector3Pool)
    {
        int       xOffset   = brickTree.BrickDimensionX * brickWorld.x;
        int       yOffset   = brickTree.BrickDimensionY * brickWorld.y;
        int       zOffset   = brickTree.BrickDimensionZ * brickWorld.z;
        ColorUtil colorUtil = new ColorUtil();
        int       normalDirection;

        for (int x = 0; x < brickTree.BrickDimensionX; ++x)
        {
            for (int y = 0; y < brickTree.BrickDimensionY; ++y)
            {
                for (int z = 0; z < brickTree.BrickDimensionZ; ++z)
                {
                    int trueX = x + xOffset;
                    int trueY = y + yOffset;
                    int trueZ = z + zOffset;

                    VoxelMaterial voxel      = materialAtlas.GetVoxelMaterial(brickTree.GetVoxelAt(trueX, trueY, trueZ));
                    VoxelMaterial voxelPlusX = materialAtlas.GetVoxelMaterial(brickTree.GetVoxelAt(trueX + 1, trueY, trueZ));
                    VoxelMaterial voxelPlusY = materialAtlas.GetVoxelMaterial(brickTree.GetVoxelAt(trueX, trueY + 1, trueZ));
                    VoxelMaterial voxelPlusZ = materialAtlas.GetVoxelMaterial(brickTree.GetVoxelAt(trueX, trueY, trueZ + 1));

                    if (CheckForTransition(voxel, voxelPlusX, out normalDirection))
                    {
                        AddQuadX(voxel, x, y, z, normalDirection, colors, vertices, normals, uv, indices, colorPool, vector2Pool, vector3Pool, colorUtil);
                    }

                    if (CheckForTransition(voxel, voxelPlusY, out normalDirection))
                    {
                        AddQuadY(voxel, x, y, z, normalDirection, colors, vertices, normals, uv, indices, colorPool, vector2Pool, vector3Pool, colorUtil);
                    }

                    if (CheckForTransition(voxel, voxelPlusZ, out normalDirection))
                    {
                        AddQuadZ(voxel, x, y, z, normalDirection, colors, vertices, normals, uv, indices, colorPool, vector2Pool, vector3Pool, colorUtil);
                    }
                }
            }
        }
    }
Пример #6
0
    protected OctreeEntry <Brick> FirstBrickIntersected(Ray ray, BrickTree tree, List <byte> blackList)
    {
        entryPrioirityQueue.Clear();

        tree.RaycastFind(ray, entryPrioirityQueue);

        while (!entryPrioirityQueue.IsEmpty())
        {
            cellPriorityQueue.Clear();

            OctreeEntry <Brick> entry = entryPrioirityQueue.Dequeue();

            blackListSelector.Select(ray, entry.entry, entry.bounds.min, blackList, cellPriorityQueue);

            if (cellPriorityQueue.Count > 0)
            {
                return(entry);
            }
        }

        return(null);
    }
Пример #7
0
    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);
    }
Пример #8
0
 public abstract bool Stroke(Ray ray, BrickTree tree, VoxelMaterial voxelMaterial, VoxelMaterialAtlas materialAtlas, List <byte> blackList, Queue <OctreeEntry <Brick> > outChangedBricks, Bounds bounds);