private byte ParseShape(OreTypes ore, MarchingSquaresGrid marchingGrid, OreGrid oreGrid, int x, int y)
    {
        byte shape = 0;

        for (int i = 0; i < 7; i += 2)
        {
            if (GetNode(i, x, y, marchingGrid) > 0.5f && oreGrid.GetTileByIndex(i, x, y) == (int)ore)
            {
                shape |= (byte)(1 << i);
                int nextIndex        = Mod(i + 2, 8);
                int prevIndex        = Mod(i - 2, 8);
                int nextIntermediate = Mod(i + 1, 8);
                int prevIntermediate = Mod(i - 1, 8);

                //If the next node is a different type, or below the rendering threshold, add the intermediate node
                if (GetNode(nextIndex, x, y, marchingGrid) < 0.5f || oreGrid.GetTileByIndex(nextIndex, x, y) != (int)ore)
                {
                    shape |= (byte)(1 << (nextIntermediate));
                }
                if (GetNode(prevIndex, x, y, marchingGrid) < 0.5f || oreGrid.GetTileByIndex(prevIndex, x, y) != (int)ore)
                {
                    shape |= (byte)(1 << (prevIntermediate));
                }
            }
        }
        return(shape);
        //	return (byte) 1 +( 1<< 1) + (1 << 7);
    }
    public void ApplyStamp(MarchingSquaresGrid marchingGrid, OreGrid oreGrid)
    {
        TransformToCircle();

        new MarchingSquaresCutTools(marchingGrid).DigCircleFromWorld(position, radius, isSolid);
        //	Topography topography = (Topography)FindObjectOfType (typeof(Topography));
        //	topography.DigCircle (this.transform.position, radius, isSolid);
        Destroy(this.gameObject);
    }
Exemplo n.º 3
0
    public void ApplyStamp(MarchingSquaresGrid marchingGrid, OreGrid oreGrid)
    {
        TransformToRect();
        //	Vector2 position2d = new Vector2 (this.transform.position.x, this.transform.position.y);
        //	QuadToHulls quad = new QuadToHulls(position2d, 0f, 20f, 20f);

        QuadToHulls quad = new QuadToHulls(position, angle, width, height);

        new MarchingSquaresCutTools(marchingGrid).DigConvexHullFromWorld(quad.GetUpperHull(), quad.GetLowerHull(), isSolid);
        Destroy(this.gameObject);
    }
Exemplo n.º 4
0
 public void ApplyStamp(MarchingSquaresGrid marchingGrid, OreGrid oreGrid)
 {
     IStampable[] stampables = this.transform.GetComponentsInChildren <IStampable> ();
     foreach (IStampable stampable in stampables)
     {
         if (!stampable.Equals(this))
         {
             stampable.ApplyStamp(marchingGrid, oreGrid);
         }
     }
 }
 public void BuildMesh(MarchingSquaresGrid marchingGrid, OreGrid oreGrid)
 {
     //Loop through marchingGrid starting from your own coordinate
     for (int i = chunkCoord.X * chunkSize; i < chunkCoord.X * chunkSize + chunkSize; i++)
     {
         for (int j = chunkCoord.Y * chunkSize; j < chunkCoord.Y * chunkSize + chunkSize; j++)
         {
             BuildSquare(i, j, marchingGrid, oreGrid);
         }
     }
     UpdateMesh();
 }
Exemplo n.º 6
0
    public void ApplyStamp(MarchingSquaresGrid marchingGrid, OreGrid oreGrid)
    {
        TransformToRect();
        //	Vector2 position2d = new Vector2 (this.transform.position.x, this.transform.position.y);
        //	QuadToHulls quad = new QuadToHulls(position2d, 0f, 20f, 20f);

        QuadToHulls quad = new QuadToHulls(position, angle, width, height);

        new MarchingSquaresCutTools(marchingGrid).DigAxisAlignedRectFromWorld(position, width, height, isSolid, sharpCorners);

        Destroy(this.gameObject);
    }
    private Color32 GetNodeColor(int index, int anchorX, int anchorY, OreGrid oreGrid)
    {
        switch (index)
        {
        case 0:
        {
            return(oreGrid.GetColorOfTile(anchorX, anchorY));
        }

        case 1:
        {
            return(Color32.Lerp(oreGrid.GetColorOfTile(anchorX, anchorY), oreGrid.GetColorOfTile(anchorX, anchorY + 1), 0.5f));

            ;
        }

        case 2:
        {
            return(oreGrid.GetColorOfTile(anchorX, anchorY + 1));
        }

        case 3:
        {
            return(Color32.Lerp(oreGrid.GetColorOfTile(anchorX + 1, anchorY + 1), oreGrid.GetColorOfTile(anchorX, anchorY + 1), 0.5f));
        }

        case 4:
        {
            return(oreGrid.GetColorOfTile(anchorX + 1, anchorY + 1));
        }

        case 5:
        {
            return(Color32.Lerp(oreGrid.GetColorOfTile(anchorX + 1, anchorY + 1), oreGrid.GetColorOfTile(anchorX + 1, anchorY), 0.5f));
        }

        case 6:
        {
            return(oreGrid.GetColorOfTile(anchorX + 1, anchorY));
        }

        case 7:
        {
            return(Color32.Lerp(oreGrid.GetColorOfTile(anchorX, anchorY), oreGrid.GetColorOfTile(anchorX + 1, anchorY), 0.5f));
        }

        default:
            return(new Color32(0, 255, 255, 255));
        }
    }
Exemplo n.º 8
0
    public void Initialise(float vesselSize)
    {
        this.vesselRadius = vesselSize / 2f;

        //Ensure enough chunks to contain vessel. Could add a buffer to build above this level.
        numChunks    = (int)Mathf.Ceil(vesselSize / chunkSize);
        worldSizeX   = numChunks * chunkSize;
        worldSizeY   = numChunks * chunkSize;
        vesselCenter = new Vector3((float)worldSizeX / 2f, (float)worldSizeY / 2f, 0f);

        GameObject marchingGridGO = Instantiate(marchingGridPrefab, this.transform.position, Quaternion.identity) as GameObject;

        marchingGrid = marchingGridGO.GetComponent <MarchingSquaresGrid> () as MarchingSquaresGrid;
        marchingGrid.Initialise(worldSizeX, worldSizeY, isSolid);

        oreGrid = new OreGrid();
        oreGrid.GenerateMap(worldSizeX, worldSizeY);

        destructableArray = oreGrid.GetDestructableArray();

        LabyrinthBuilder labyrinthBuilder = GetComponentInChildren <LabyrinthBuilder> () as LabyrinthBuilder;

        if (labyrinthBuilder != null)
        {
            labyrinthBuilder.GenerateLabyrinth();
        }

        rootStampCollection = this.transform.GetComponentInChildren <StampCollection> () as StampCollection;
        ApplyStampCollection(rootStampCollection);

        renderChunkPool                = new Stack <RenderChunk> ();
        renderChunkUpdateQueue         = new Queue <RenderChunk> ();
        renderChunkPriorityUpdateQueue = new Queue <RenderChunk> ();
        renderChunkArray               = new RenderChunk[numChunks, numChunks];

        collisionChunkPool                = new Stack <CollisionChunk> ();
        collisionChunkUpdateQueue         = new Queue <CollisionChunk> ();
        collisionChunkPriorityUpdateQueue = new Queue <CollisionChunk> ();
        collisionChunkArray               = new CollisionChunk[numChunks, numChunks];

        this.faceGO = Instantiate(facePrefab, new Vector3(0f, 0f, 0f), Quaternion.identity) as GameObject;

        this.interiorGO = Instantiate(interiorPrefab, new Vector3(0f, 0f, 0f), Quaternion.identity) as GameObject;

        renderFoci = new List <GameObject> ();
    }
Exemplo n.º 9
0
    private void Start()
    {
        outPointsDefined = false;

        grid = FindObjectOfType <OreGrid>();

        upVec    = new Vector3(0, 2f, 0);
        downVec  = new Vector3(0, -2f, 0);
        leftVec  = new Vector3(-2f, 0, 0);
        rightVec = new Vector3(2f, 0, 0);

        forwardVec = new Vector3(0, 0, -1.0f);

        upIn    = up.position;
        downIn  = down.position;
        leftIn  = left.position;
        rightIn = right.position;

        DropTarget();
    }
Exemplo n.º 10
0
    void BuildWorld()
    {
        surface    = Instantiate(prefab, transform.position + surfaceOffset, transform.rotation, transform);
        topLayer   = Instantiate(prefab, transform.position + topOffset, transform.rotation, transform);
        midLayer   = Instantiate(prefab, transform.position + midOffset, transform.rotation, transform);
        lowerLayer = Instantiate(prefab, transform.position + lowOffset, transform.rotation, transform);
        deepLayer  = Instantiate(prefab, transform.position + deepOffset, transform.rotation, transform);

        BuildSurface();
        BuildTopLayer();
        BuildMidLayer();
        BuildLowLayer();
        BuildDeepLayer();

        /*
         * Top layer - 10x10
         * Middle - 14x5x3
         * Lower - 14x7x5
         * Deepest - 10x5x10
         *
         */
        //Debug.Log("Finish");
        FinishWorld();
    }
Exemplo n.º 11
0
 // Start is called before the first frame update
 void Start()
 {
     grid = transform.parent.GetComponent <OreGrid>();
 }
Exemplo n.º 12
0
 public void ApplyStamp(MarchingSquaresGrid marchingGrid, OreGrid oreGrid)
 {
     new MarchingSquaresCutTools(marchingGrid).DigPerlinTunnels(0.02f);
     Destroy(this.gameObject);
 }
Exemplo n.º 13
0
    private void BuildSquare(int x, int y, MarchingSquaresGrid marchingGrid, OreGrid oreGrid)
    {
        float   xOffset   = (float)x;
        float   yOffset   = (float)y;
        Vector3 vecOffset = new Vector3(xOffset, yOffset, 0f);

        Color32 borderColor = new Color32(230, 230, 230, 255);
        Color32 mainColor   = new Color32(200, 200, 200, 255);

        //Build an individual square by going clockwise around the nodes and interpolations in that tile space
        int numCornerNodes  = 0;
        int numAllTypeNodes = 0;
        int i          = 0;
        int anchorVert = numVerts;

        int numShapes = 0;              //One shape per unique OreType.

        for (i = 0; i < 8; i++)
        {
            if (i == 0 || i == 2 || i == 4 || i == 6)
            {
                if (GetNode(i, x, y, marchingGrid) >= 0.5f)
                {
                    numCornerNodes++;
                }
            }
        }

        if (numCornerNodes > 0)
        {
            //Parse up to 4 shapes.

            //Look at each corner.
            //If the Corner is rendered, set its bit to true.
            //If the the adjacent corners are different or not rendered, set the adjacent edge bits to true.
            byte botLeft  = 0;
            byte topRight = 0;
            byte topLeft  = 0;
            byte botRight = 0;

            OreTypes ore0 = (OreTypes)oreGrid.GetTile(x, y);
            OreTypes ore1 = (OreTypes)oreGrid.GetTile(x, y + 1);
            OreTypes ore2 = (OreTypes)oreGrid.GetTile(x + 1, y + 1);
            OreTypes ore3 = (OreTypes)oreGrid.GetTile(x + 1, y);

            bool unique0 = true;
            bool unique1 = true;
            bool unique2 = true;
            bool unique3 = true;

            int shape0Nodes = 0;
            int shape1Nodes = 0;
            int shape2Nodes = 0;
            int shape3Nodes = 0;

            //Identify the ore types that appear.
            if (ore0 == ore1)
            {
                unique1 = false;
            }
            if (ore0 == ore2)
            {
                unique2 = false;
            }
            if (ore0 == ore3)
            {
                unique3 = false;
            }

            if (ore1 == ore2)
            {
                unique2 = false;
            }
            if (ore1 == ore3)
            {
                unique3 = false;
            }

            if (ore2 == ore3)
            {
                unique3 = false;
            }

            //Render the first ore across the entire tile, to prevent gaps
            bool baseColorRendered = false;
            //For each unique ore type, loop around the perimeter, flagging raised corners of that type, and edge nodes where the ore is different or the elevation changes.
            //If a corner is the first instance of an ore type, parse its shape. Redundant ore type corners will be flagged in the first instance as part of this loop.
            if (unique0)
            {
                botLeft           = ParseBaseShape(ore0, marchingGrid, oreGrid, x, y);
                baseColorRendered = true;
                //	botLeft = ParseShape (ore0, marchingGrid, oreGrid, x, y);
            }
            if (unique1)
            {
                if (baseColorRendered)
                {
                    topLeft = ParseShape(ore1, marchingGrid, oreGrid, x, y);
                }
                else
                {
                    baseColorRendered = true;
                    topLeft           = ParseBaseShape(ore1, marchingGrid, oreGrid, x, y);
                }
            }
            if (unique2)
            {
                if (baseColorRendered)
                {
                    topRight = ParseShape(ore2, marchingGrid, oreGrid, x, y);
                }
                else
                {
                    baseColorRendered = true;
                    topRight          = ParseBaseShape(ore2, marchingGrid, oreGrid, x, y);
                }
            }
            if (unique3)
            {
                if (baseColorRendered)
                {
                    botRight = ParseShape(ore3, marchingGrid, oreGrid, x, y);
                }
                else
                {
                    botRight = ParseBaseShape(ore3, marchingGrid, oreGrid, x, y);
                }
            }

            //If a corner is the origin of a shape, render it.
            if (botLeft > 0)               //if bot left needs to be rendered
            {
                mainColor = oreGrid.GetOreColor(ore0);
                for (i = 0; i < 8; i++)
                {
                    if ((botLeft & ((byte)1 << i)) > 0)
                    {
                        AddFaceVert(GetTileVertPosition(i, x, y, marchingGrid) + vecOffset + new Vector3(0f, 0f, -0.1f), mainColor);
                        shape0Nodes++;
                    }
                }

                for (i = 1; i < shape0Nodes - 1; i++)
                {
                    faceTris.Add(anchorVert);
                    faceTris.Add(anchorVert + i);
                    faceTris.Add(anchorVert + i + 1);
                    numTris++;
                }
                anchorVert = numVerts;
            }

            if (topLeft > 0)
            {
                mainColor = oreGrid.GetOreColor(ore1);
                for (i = 0; i < 8; i++)
                {
                    if ((topLeft & ((byte)1 << i)) > 0)
                    {
                        AddFaceVert(GetTileVertPosition(i, x, y, marchingGrid) + vecOffset + new Vector3(0f, 0f, -0.2f), mainColor);
                        shape1Nodes++;
                    }
                }

                for (i = 1; i < shape1Nodes - 1; i++)
                {
                    faceTris.Add(anchorVert);
                    faceTris.Add(anchorVert + i);
                    faceTris.Add(anchorVert + i + 1);
                    numTris++;
                }
                anchorVert = numVerts;
            }

            if (topRight > 0)
            {
                mainColor = oreGrid.GetOreColor(ore2);
                for (i = 0; i < 8; i++)
                {
                    if ((topRight & ((byte)1 << i)) > 0)
                    {
                        AddFaceVert(GetTileVertPosition(i, x, y, marchingGrid) + vecOffset + new Vector3(0f, 0f, -0.3f), mainColor);
                        shape2Nodes++;
                    }
                }

                for (i = 1; i < shape2Nodes - 1; i++)
                {
                    faceTris.Add(anchorVert);
                    faceTris.Add(anchorVert + i);
                    faceTris.Add(anchorVert + i + 1);
                    numTris++;
                }
                anchorVert = numVerts;
            }

            if (botRight > 0)
            {
                mainColor = oreGrid.GetOreColor(ore3);
                for (i = 0; i < 8; i++)
                {
                    if ((botRight & ((byte)1 << i)) > 0)
                    {
                        AddFaceVert(GetTileVertPosition(i, x, y, marchingGrid) + vecOffset + new Vector3(0f, 0f, -0.4f), mainColor);
                        shape3Nodes++;
                    }
                }

                for (i = 1; i < shape3Nodes - 1; i++)
                {
                    faceTris.Add(anchorVert);
                    faceTris.Add(anchorVert + i);
                    faceTris.Add(anchorVert + i + 1);
                    numTris++;
                }
                anchorVert = numVerts;
            }

            //Add a lighter colour to the edge of the tile
            BuildOutline(x, y, marchingGrid, borderColor);
        }
    }
Exemplo n.º 14
0
 public void UpdateRenderChunk(MarchingSquaresGrid marchingGrid, OreGrid oreGrid)
 {
     BuildMesh(marchingGrid, oreGrid);
 }
 public OreStampTools(OreGrid oreGrid)
 {
     terrainMap = (oreGrid).GetTerrainMap();
     tileXSize  = terrainMap.GetLength(0);
     tileYSize  = terrainMap.GetLength(1);
 }