예제 #1
0
    /*
     * Generate the planet, but do not draw the cubes at this point.
     * We need generate first, so that we can see where quads need not be
     * drawn, due to being next to a cube that is or will be drawn during
     * the initial generation of the planet.
     */
    public void BuildTheChunk()
    {
        for (int y = 0; y < planet.chunkSize; y++)
        {
            for (int z = 0; z < planet.chunkSize; z++)
            {
                for (int x = 0; x < planet.chunkSize; x++)
                {
                    // generate cube - solid or space/air?
                    //     Vector3 cubePosition = new Vector3(planetChunk.transform.position.x + x,
                    //                                         planetChunk.transform.position.y + y,
                    //                                         planetChunk.transform.position.z + z);

                    Vector3 cubePosition = new Vector3(x, y, z);

                    //         Debug.Log(" CHUNK NAME : " + planetChunk.name);
                    chunkData[x, y, z] = new Cube(planetChunk.gameObject, this,
                                                  x, y, z,
                                                  CustomMaterials.RetrieveMaterial(CustomMaterials.rockQuad),
                                                  CustomMaterials.rockQuad, cubePosition, planetChunk.name);

                    chunkData[x, y, z].cube.transform.parent = planetChunk.transform; // make the quad a child of the cube
                    // create new cube
                    if (IsOuterLayer(cubePosition))
                    {
                        CubeIsSolid[x, y, z] = true;
                    }
                    else // set cube to SPACE
                    {
                        CubeIsSolid[x, y, z] = false;
                    }
                }
            }
        }
    }
예제 #2
0
    /*
     * This is used to give the chunks each a different material.
     * TODO: Delete this when no longer requred - when everything works
     */
    SpatialMaterial GetNextMaterial(int cubeCount)
    {
        switch (cubeCount)
        {
        case 0:
            return(customMaterials.RetrieveMaterial(CustomMaterials.sandQuad));

        case 1:
            return(customMaterials.RetrieveMaterial(CustomMaterials.rockQuad));

        case 2:
            return(customMaterials.RetrieveMaterial(CustomMaterials.dirtQuad));

        default:
            return(customMaterials.RetrieveMaterial(CustomMaterials.grassQuad));
        }
    }
예제 #3
0
    void GenerateRightQuad()
    {
        // Right quad
        rightQuadVertices[0] = new Vector3(cubeLocation.x + 1, cubeLocation.y, cubeLocation.z);
        rightQuadVertices[1] = new Vector3(cubeLocation.x + 1, cubeLocation.y + 1, cubeLocation.z);
        rightQuadVertices[2] = new Vector3(cubeLocation.x + 1, cubeLocation.y, cubeLocation.z + 1);
        rightQuadVertices[3] = new Vector3(cubeLocation.x + 1, cubeLocation.y + 1, cubeLocation.z + 1);

        DisplayQuad(rightQuadVertices, "_Right_quad", CustomMaterials.RetrieveMaterial(CustomMaterials.dirtQuad));
    }
예제 #4
0
    void GenerateLeftQuad()
    {
        // Left quad
        leftQuadVertices[0] = new Vector3(cubeLocation.x, cubeLocation.y, cubeLocation.z + 1);
        leftQuadVertices[1] = new Vector3(cubeLocation.x, cubeLocation.y + 1, cubeLocation.z + 1);
        leftQuadVertices[2] = new Vector3(cubeLocation.x, cubeLocation.y, cubeLocation.z);
        leftQuadVertices[3] = new Vector3(cubeLocation.x, cubeLocation.y + 1, cubeLocation.z);

        DisplayQuad(leftQuadVertices, "_Left_quad", CustomMaterials.RetrieveMaterial(CustomMaterials.dirtQuad));
    }
예제 #5
0
    void GenerateBackQuad()
    {
        // Back quad
        backQuadVertices[0] = new Vector3(cubeLocation.x + 1, cubeLocation.y, cubeLocation.z + 1);
        backQuadVertices[1] = new Vector3(cubeLocation.x + 1, cubeLocation.y + 1, cubeLocation.z + 1);
        backQuadVertices[2] = new Vector3(cubeLocation.x, cubeLocation.y, cubeLocation.z + 1);
        backQuadVertices[3] = new Vector3(cubeLocation.x, cubeLocation.y + 1, cubeLocation.z + 1);

        DisplayQuad(backQuadVertices, "_Back_quad", CustomMaterials.RetrieveMaterial(CustomMaterials.sandQuad));
    }
예제 #6
0
    void GenerateBottomQuad()
    {
        // Bottom quad
        bottomQuadVertices[0] = new Vector3(cubeLocation.x + 1, cubeLocation.y, cubeLocation.z);
        bottomQuadVertices[1] = new Vector3(cubeLocation.x + 1, cubeLocation.y, cubeLocation.z + 1);
        bottomQuadVertices[2] = new Vector3(cubeLocation.x, cubeLocation.y, cubeLocation.z);
        bottomQuadVertices[3] = new Vector3(cubeLocation.x, cubeLocation.y, cubeLocation.z + 1);

        DisplayQuad(bottomQuadVertices, "_Bottom_quad", CustomMaterials.RetrieveMaterial(CustomMaterials.dirtQuad));
    }
예제 #7
0
    void GenerateTopQuad()
    {
        // Top quad
        topQuadVertices[0] = new Vector3(cubeLocation.x, cubeLocation.y + 1, cubeLocation.z);
        topQuadVertices[1] = new Vector3(cubeLocation.x, cubeLocation.y + 1, cubeLocation.z + 1);
        topQuadVertices[2] = new Vector3(cubeLocation.x + 1, cubeLocation.y + 1, cubeLocation.z);
        topQuadVertices[3] = new Vector3(cubeLocation.x + 1, cubeLocation.y + 1, cubeLocation.z + 1);

        DisplayQuad(topQuadVertices, "_Top_quad", CustomMaterials.RetrieveMaterial(CustomMaterials.grassQuad));
    }
예제 #8
0
    public void GenerateFrontQuad()
    {
        // Front quad
        frontQuadVertices[0] = new Vector3(cubeLocation.x, cubeLocation.y, cubeLocation.z);
        frontQuadVertices[1] = new Vector3(cubeLocation.x, cubeLocation.y + 1, cubeLocation.z);
        frontQuadVertices[2] = new Vector3(cubeLocation.x + 1, cubeLocation.y, cubeLocation.z);
        frontQuadVertices[3] = new Vector3(cubeLocation.x + 1, cubeLocation.y + 1, cubeLocation.z);

        DisplayQuad(frontQuadVertices, "_Front_quad", CustomMaterials.RetrieveMaterial(CustomMaterials.sandQuad));
    }
예제 #9
0
 /*
  * Pick a material to add to the quad
  */
 public static Material SetMaterial(Vector3 vertex0, int maxTerrainHeight, out int terrainType)
 {
     if (vertex0.y > maxTerrainHeight * 0.70)
     {
         terrainType = CustomMaterials.rockQuad; // sent back to the quad object (out)
         return(CustomMaterials.RetrieveMaterial(terrainType));
     }
     else if (vertex0.y > maxTerrainHeight * 0.50)
     {
         terrainType = CustomMaterials.dirtQuad;
         return(CustomMaterials.RetrieveMaterial(terrainType));
     }
     terrainType = CustomMaterials.grassQuad;
     return(CustomMaterials.RetrieveMaterial(terrainType));
 }
예제 #10
0
    /*
     * This is run after the first time the world is built, when we need to
     * initialise the cubes again - e.g. when digging
     */
    public void ReBuildTheChunk()
    {
        for (int y = 0; y < planet.chunkSize; y++)
        {
            for (int z = 0; z < planet.chunkSize; z++)
            {
                for (int x = 0; x < planet.chunkSize; x++)
                {
                    //         Vector3 cubePosition = new Vector3(planetChunk.transform.position.x + x,
                    //                                             planetChunk.transform.position.y + y,
                    //                                             planetChunk.transform.position.z + z);

                    Vector3 cubePosition = new Vector3(x, y, z);
                    chunkData[x, y, z] = new Cube(planetChunk.gameObject, this,
                                                  x, y, z,
                                                  CustomMaterials.RetrieveMaterial(CustomMaterials.rockQuad),
                                                  CustomMaterials.rockQuad, cubePosition, planetChunk.name);

                    chunkData[x, y, z].cube.transform.parent = planetChunk.transform; // make the cube a child of the chunk
                }
            }
        }
    }
예제 #11
0
    // Grass to Dirt
    // Grass to rock
    // Dirt to Rock
    // Sand to Grass
    // Sand to Dirt
    // Sand to rock

    /*
     * Make the join between grass and dirt look more natural
     */
    private static void BlendGrassToDirt(Quad[,] chunkData, int x, int z)
    {
        // check for dirt Top and Bottom
        //  Vetical Test    IF Top (PosZ) and bottom (NegZ) quads are dirt
        if (z < Universe.chunkSize - 1 && z > 0 &&
            chunkData[x, z + 1].terrainType == CustomMaterials.dirtQuad &&
            chunkData[x, z - 1].terrainType == CustomMaterials.dirtQuad)
        {
            chunkData[x, z].terrainType = CustomMaterials.dirtQuad;
            chunkData[x, z].SetMaterial(CustomMaterials.RetrieveMaterial(CustomMaterials.dirtQuad));
        }
        // check for dirt Top and Bottom
        //  horiz Test    IF Left (NegX) and right (PosX) quads are dirt
        else if (x < Universe.chunkSize - 1 && x > 0 &&
                 chunkData[x - 1, z].terrainType == CustomMaterials.dirtQuad &&
                 chunkData[x + 1, z].terrainType == CustomMaterials.dirtQuad)
        {
            chunkData[x, z].terrainType = CustomMaterials.dirtQuad;
            chunkData[x, z].SetMaterial(CustomMaterials.RetrieveMaterial(CustomMaterials.dirtQuad));
        }
        //  diag gradient blend Test    IF Left (NegX) and bottom (NegZ) quads are dirt
        else if (z > 0 && x > 0 &&
                 chunkData[x - 1, z].terrainType == CustomMaterials.dirtQuad &&
                 chunkData[x, z - 1].terrainType == CustomMaterials.dirtQuad)
        {
            chunkData[x, z].terrainType = CustomMaterials.diagBlendGrassToLargeDirtBottomLeftQuad;
            chunkData[x, z].SetMaterial(CustomMaterials.RetrieveMaterial(CustomMaterials.diagBlendGrassToLargeDirtBottomLeftQuad));
        }
        //  diag gradient blend Test    IF Top (PosZ) and right (PosX) quads are dirt
        else if (x < Universe.chunkSize - 1 && z < Universe.chunkSize - 1 &&
                 chunkData[x, z + 1].terrainType == CustomMaterials.dirtQuad &&
                 chunkData[x + 1, z].terrainType == CustomMaterials.dirtQuad)
        {
            chunkData[x, z].terrainType = CustomMaterials.diagBlendGrassToLargeDirtTopRightQuad;
            chunkData[x, z].SetMaterial(CustomMaterials.RetrieveMaterial(CustomMaterials.diagBlendGrassToLargeDirtTopRightQuad));
        }
        //  diag gradient blend Test    IF Top (PosZ) and left (NegX) quads are dirt
        else if (x < Universe.chunkSize - 1 && z < Universe.chunkSize - 1 && x > 0 &&
                 chunkData[x, z + 1].terrainType == CustomMaterials.dirtQuad &&
                 chunkData[x + 1, z].terrainType == CustomMaterials.dirtQuad)
        {
            chunkData[x, z].terrainType = CustomMaterials.diagBlendGrassToLargeDirtTopLeftQuad;
            chunkData[x, z].SetMaterial(CustomMaterials.RetrieveMaterial(CustomMaterials.diagBlendGrassToLargeDirtTopLeftQuad));
        }
        //  diag gradient blend Test    IF Bottom (NegZ) and left (NegX) quads are dirt
        else if (x > 0 && z > 0 &&
                 chunkData[x, z - 1].terrainType == CustomMaterials.dirtQuad &&
                 chunkData[x - 1, z].terrainType == CustomMaterials.dirtQuad)
        {
            chunkData[x, z].terrainType = CustomMaterials.diagBlendGrassToLargeDirtBottomLeftQuad;
            chunkData[x, z].SetMaterial(CustomMaterials.RetrieveMaterial(CustomMaterials.diagBlendGrassToLargeDirtBottomLeftQuad));
        }
        //  diag gradient blend Test    IF Bottom (NegZ) and left (PosX) quads are dirt
        else if (x < Universe.chunkSize - 1 && x > 0 && z > 0 &&
                 chunkData[x, z - 1].terrainType == CustomMaterials.dirtQuad &&
                 chunkData[x + 1, z].terrainType == CustomMaterials.dirtQuad)
        {
            chunkData[x, z].terrainType = CustomMaterials.diagBlendGrassToLargeDirtBottomRightQuad;
            chunkData[x, z].SetMaterial(CustomMaterials.RetrieveMaterial(CustomMaterials.diagBlendGrassToLargeDirtBottomRightQuad));
        }
        // Vertical gradient blending
        //     IF positiveZ quad is dirt
        else if (z < Universe.chunkSize - 1 &&
                 chunkData[x, z + 1].terrainType == CustomMaterials.dirtQuad)
        {
            chunkData[x, z].terrainType = CustomMaterials.vertBlendGrassToDirtQuad;
            chunkData[x, z].SetMaterial(CustomMaterials.RetrieveMaterial(CustomMaterials.vertBlendGrassToDirtQuad));
        }
        //     IF negativeZ quad is dirt
        else if (z > 0 && chunkData[x, z - 1].terrainType == CustomMaterials.dirtQuad)
        {
            chunkData[x, z].terrainType = CustomMaterials.vertBlendDirtToGrassQuad;
            chunkData[x, z].SetMaterial(CustomMaterials.RetrieveMaterial(CustomMaterials.vertBlendDirtToGrassQuad));
        }
        // horiz gradient blending
        //     IF positiveX quad is dirt
        else if (x < Universe.chunkSize - 1 &&
                 chunkData[x + 1, z].terrainType == CustomMaterials.dirtQuad)
        {
            chunkData[x, z].terrainType = CustomMaterials.horizBlendGrassToDirtQuad;
            chunkData[x, z].SetMaterial(CustomMaterials.RetrieveMaterial(CustomMaterials.horizBlendGrassToDirtQuad));
        }
        //     IF negativeX quad is dirt
        else if (x > 0 && chunkData[x - 1, z].terrainType == CustomMaterials.dirtQuad)
        {
            chunkData[x, z].terrainType = CustomMaterials.horizBlendDirtToGrassQuad;
            chunkData[x, z].SetMaterial(CustomMaterials.RetrieveMaterial(CustomMaterials.horizBlendDirtToGrassQuad));
        }
        //  diag gradient blend Test    IF Top Right quad is dirt
        else if (x < Universe.chunkSize - 1 && z < Universe.chunkSize - 1 &&
                 chunkData[x + 1, z + 1].terrainType == CustomMaterials.dirtQuad)
        {
            chunkData[x, z].terrainType = CustomMaterials.diagBlendGrassToSmallDirtTopRightQuad;
            chunkData[x, z].SetMaterial(CustomMaterials.RetrieveMaterial(CustomMaterials.diagBlendGrassToSmallDirtTopRightQuad));
        }
        //  diag gradient blend Test    IF Top Left quad is dirt
        else if (z < Universe.chunkSize - 1 && x > 0 &&
                 chunkData[x - 1, z + 1].terrainType == CustomMaterials.dirtQuad)
        {
            chunkData[x, z].terrainType = CustomMaterials.diagBlendGrassToSmallDirtTopLeftQuad;
            chunkData[x, z].SetMaterial(CustomMaterials.RetrieveMaterial(CustomMaterials.diagBlendGrassToSmallDirtTopLeftQuad));
        }
        //  diag gradient blend Test    IF Bottom Right quad is dirt
        else if (x < Universe.chunkSize - 1 && z > 0 &&
                 chunkData[x + 1, z - 1].terrainType == CustomMaterials.dirtQuad)
        {
            chunkData[x, z].terrainType = CustomMaterials.diagBlendGrassToSmallDirtBottomRightQuad;
            chunkData[x, z].SetMaterial(CustomMaterials.RetrieveMaterial(CustomMaterials.diagBlendGrassToSmallDirtBottomRightQuad));
        }
        //  diag gradient blend Test    IF Bottom Left quad is dirt
        else if (z > 0 && x > 0 &&
                 chunkData[x - 1, z - 1].terrainType == CustomMaterials.dirtQuad)
        {
            chunkData[x, z].terrainType = CustomMaterials.diagBlendGrassToSmallDirtBottomLeftQuad;
            chunkData[x, z].SetMaterial(CustomMaterials.RetrieveMaterial(CustomMaterials.diagBlendGrassToSmallDirtBottomLeftQuad));
        }
    }