Exemplo n.º 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(x, y, z);

                    chunkData[x, y, z] = new Cube(this, x, y, z, cubePosition, chunkMaterial);

                    // Add the cube to a CSGCombiner node, so that we can delete the chunk's meshes in one go (not sure is this will be doable as this stage)
                    planetChunk.AddChild(chunkData[x, y, z].cube);

                    // create new cube
                    if (IsOuterLayer(cubePosition))
                    {
                        CubeIsSolid[x, y, z] = true;
                    }
                    else // set cube to SPACE
                    {
                        CubeIsSolid[x, y, z] = false;
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    public void CreateQuad(Vector3 vertex0, Vector3 vertex1, Vector3 vertex2, Vector3 vertex3)
    {
        // Generate quad mesh (2 triangles)

        Vector3[] vertices = { vertex0,   //top-left
                               vertex1,   //top-right
                               vertex2,   //bottom-left
                               vertex3 }; //bottom-right

        int[] index = new int[6] {
            0, 1, 2, 3, 2, 1
        };

        // UVs
        Vector2[] uvs = { new Vector2(0f, 1f),   //top-left
                          new Vector2(1f, 1f),   //top-right
                          new Vector2(0f, 0f),   //bottom-left
                          new Vector2(1f, 0f) }; //bottom-right

        // Normals
        Vector3[] normals = new Vector3[4]
        {
            Vector3.Up, Vector3.Up, Vector3.Up, Vector3.Up
        };

        Godot.Collections.Array arrays = new Godot.Collections.Array();
        arrays.Resize(9);
        // see
        arrays[0] = vertices;
        arrays[1] = normals;
        arrays[4] = uvs;
        arrays[8] = index;

        // Create the Mesh.

        // Initialize the ArrayMesh.
        ArrayMesh arr_mesh = new ArrayMesh();

        arr_mesh.AddSurfaceFromArrays(Mesh.PrimitiveType.Triangles, arrays);
        MeshInstance quad = new MeshInstance();

        quad.Mesh = arr_mesh;

        quad.MaterialOverride = cubeMaterial; // apply texture - rock, dirt, grass, etc.
        quad.MaterialOverride = cubeMaterial; // apply texture - rock, dirt, grass, etc.

        cube.AddChild(quad);                  // add quad to the cube node
    }