Exemplo n.º 1
0
 private void AddVertex(Vector3 vertex, Vector2 uv, Vector3 normal)
 {
     Builder.AddUv(uv);
     Builder.AddNormal(normal);
     Builder.AddVertex(vertex);
     collisionShapeFaces.Add(vertex);
 }
Exemplo n.º 2
0
        private void CreateFrontQuad(ref ChunkStruct c, int x, int y, int x2, int y2, int z)
        {
            //The Z-1 is more of a hack because the face previously was shown on the back side rather than the front
            Vector3 voxPosition1 = new Vector3((x) * VOX_SIZE, (y) * VOX_SIZE, (z - 1) * VOX_SIZE);

            voxPosition1.x = voxPosition1.x + (c.Dx * CHUNK_SIZE * VOX_SIZE);
            voxPosition1.y = voxPosition1.y + (c.Dy * CHUNK_SIZE * VOX_SIZE);
            voxPosition1.z = voxPosition1.z + (c.Dz * CHUNK_SIZE * VOX_SIZE);

            Vector3 voxPosition2 = new Vector3((x2) * VOX_SIZE, (y2) * VOX_SIZE, (z) * VOX_SIZE);

            voxPosition2.x = voxPosition2.x + (c.Dx * CHUNK_SIZE * VOX_SIZE);
            voxPosition2.y = voxPosition2.y + (c.Dy * CHUNK_SIZE * VOX_SIZE);
            voxPosition2.z = voxPosition2.z + (c.Dz * CHUNK_SIZE * VOX_SIZE);
            SurfaceTool surfaceTool = c.surfaceTool;

            surfaceTool.AddNormal(new Vector3(0.0f, 0.0f, -1.0f));

            surfaceTool.AddVertex(new Vector3(voxPosition1.x, voxPosition1.y, voxPosition1.z));
            surfaceTool.AddVertex(new Vector3(voxPosition2.x, voxPosition1.y, voxPosition1.z));
            surfaceTool.AddVertex(new Vector3(voxPosition2.x, voxPosition2.y, voxPosition1.z));

            surfaceTool.AddVertex(new Vector3(voxPosition2.x, voxPosition2.y, voxPosition1.z));
            surfaceTool.AddVertex(new Vector3(voxPosition1.x, voxPosition2.y, voxPosition1.z));
            surfaceTool.AddVertex(new Vector3(voxPosition1.x, voxPosition1.y, voxPosition1.z));
            // addQuad(ref c,
            //  new Vector3(x,y,z),
            //  new Vector3(x2,y,z),
            //  new Vector3(x2,y2,z),
            //  new Vector3(x,y2,z));
        }
Exemplo n.º 3
0
        private void CreateTopQuad(ref ChunkStruct c, int x, int z, int x2, int z2, int y)
        {
            Vector3 voxPosition1 = new Vector3((x) * VOX_SIZE, (y) * VOX_SIZE, (z) * VOX_SIZE);

            voxPosition1.x = voxPosition1.x + (c.Dx * CHUNK_SIZE * VOX_SIZE);
            voxPosition1.y = voxPosition1.y + (c.Dy * CHUNK_SIZE * VOX_SIZE);
            voxPosition1.z = voxPosition1.z + (c.Dz * CHUNK_SIZE * VOX_SIZE);

            Vector3 voxPosition2 = new Vector3((x2) * VOX_SIZE, (y) * VOX_SIZE, (z2) * VOX_SIZE);

            voxPosition2.x = voxPosition2.x + (c.Dx * CHUNK_SIZE * VOX_SIZE);
            voxPosition2.y = voxPosition2.y + (c.Dy * CHUNK_SIZE * VOX_SIZE);
            voxPosition2.z = voxPosition2.z + (c.Dz * CHUNK_SIZE * VOX_SIZE);
            SurfaceTool surfaceTool = c.surfaceTool;

            surfaceTool.AddNormal(new Vector3(0.0f, 1.0f, 0.0f));

            surfaceTool.AddVertex(new Vector3(voxPosition1.x, voxPosition2.y, voxPosition1.z));
            surfaceTool.AddVertex(new Vector3(voxPosition2.x, voxPosition2.y, voxPosition1.z));
            surfaceTool.AddVertex(new Vector3(voxPosition1.x, voxPosition2.y, voxPosition2.z));

            surfaceTool.AddVertex(new Vector3(voxPosition2.x, voxPosition2.y, voxPosition1.z));
            surfaceTool.AddVertex(new Vector3(voxPosition2.x, voxPosition2.y, voxPosition2.z));
            surfaceTool.AddVertex(new Vector3(voxPosition1.x, voxPosition2.y, voxPosition2.z));
            // this.addQuad(ref c,
            //  new Vector3(x, y, z2),
            //  new Vector3(x2, y, z2),
            //  new Vector3(x2, y, z),
            //  new Vector3(x, y, z));
        }
Exemplo n.º 4
0
        private void addTri(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, BlockState data)
        {
            // UVMap uv = UVMap.getMap("aa_test");
            UVMap uv = UVMap.getMap(data.name);

            // if (data == 2) {
            //  uv = UVMap.getMap("bedrock");
            // }
            // else if (data == 3) {
            //  uv = UVMap.getMap("jungle_planks");
            // }

            tool.AddUv(uv.uvMap[0]);
            tool.AddVertex(p4);
            tool.AddUv(uv.uvMap[2]);
            tool.AddVertex(p3);
            tool.AddUv(uv.uvMap[3]);
            tool.AddVertex(p2);

            tool.AddUv(uv.uvMap[0]);
            tool.AddVertex(p4);
            tool.AddUv(uv.uvMap[3]);
            tool.AddVertex(p2);
            tool.AddUv(uv.uvMap[1]);
            tool.AddVertex(p1);
        }
        //Adds a triangle to a surface tool.
        public static void AddTriangle(SurfaceTool surfTool, Vector3 point1, Vector3 point2, Vector3 point3, bool reverse = false)
        {
            if (reverse)
            {
                surfTool.AddUv(new Vector2(0, 0));
                surfTool.AddVertex(point1);

                surfTool.AddUv(new Vector2(0, 0));
                surfTool.AddVertex(point2);

                surfTool.AddUv(new Vector2(0, 0));
                surfTool.AddVertex(point3);
            }
            else
            {
                surfTool.AddUv(new Vector2(0, 0));
                surfTool.AddVertex(point3);

                surfTool.AddUv(new Vector2(0, 0));
                surfTool.AddVertex(point2);

                surfTool.AddUv(new Vector2(0, 0));
                surfTool.AddVertex(point1);
            }
        }
Exemplo n.º 6
0
    private void _plane(SurfaceTool st, float posX, float posY)
    {
        int xOffset = (int)posX;
        int yOffset = (int)posY;
        var z       = 0;

        GD.Print(posX, " ", posY);
        st.AddColor(get_color(xOffset, yOffset));
        st.AddUv(new Vector2(0, 1));
        st.AddVertex(new Vector3(-1 + xOffset * 2, 1 + yOffset * 2, z));

        st.AddUv(new Vector2(1, 1));
        st.AddVertex(new Vector3(1 + xOffset * 2, 1 + yOffset * 2, z));

        st.AddUv(new Vector2(1, 0));
        st.AddVertex(new Vector3(1 + xOffset * 2, -1 + yOffset * 2, z));

        st.AddUv(new Vector2(1, 0));
        st.AddVertex(new Vector3(1 + xOffset * 2, -1 + yOffset * 2, z));

        st.AddUv(new Vector2(0, 0));
        st.AddVertex(new Vector3(-1 + xOffset * 2, -1 + yOffset * 2, z));

        st.AddUv(new Vector2(0, 1));
        st.AddVertex(new Vector3(-1 + xOffset * 2, 1 + yOffset * 2, z));
    }
Exemplo n.º 7
0
        // public void SetPolygons() {
        //   this.a.AddPolygon(this)
        //   this.b.AddPolygon(this)
        //   this.c.AddPolygon(this)
        // }

        public void AddToSurfaceTool(SurfaceTool surfaceTool)
        {
            // System.Diagnostics.Debug.WriteLine("This vertex A-B-C: [" + a.x + ", " + a.y + ", " + a.z + "] - [" + b.x + ", " + b.y + ", " + b.z + "] - [" + c.x + ", " + c.y + ", " + c.z + "]");

            const float minLimit = -0.05f;
            const float maxLimit = 0.069f;

            surfaceTool.AddColor(a.determineVertexColor(minLimit, maxLimit));
            surfaceTool.AddColor(b.determineVertexColor(minLimit, maxLimit));
            surfaceTool.AddColor(c.determineVertexColor(minLimit, maxLimit));

            // Add UV coords
            surfaceTool.AddUv(
                new Vector2(
                    Mathf.Atan2(a.z, a.x) / (2f * Mathf.Pi),
                    Mathf.Asin(a.y) / Mathf.Pi + 0.5f
                    )
                );
            surfaceTool.AddUv(
                new Vector2(
                    Mathf.Atan2(b.z, b.x) / (2f * Mathf.Pi),
                    Mathf.Asin(b.y) / Mathf.Pi + 0.5f
                    )
                );
            surfaceTool.AddUv(
                new Vector2(
                    Mathf.Atan2(c.z, c.x) / (2f * Mathf.Pi),
                    Mathf.Asin(c.y) / Mathf.Pi + 0.5f
                    )
                );

            // add vertices
            surfaceTool.AddVertex(new Vector3(a.x, a.y, a.z));
            surfaceTool.AddVertex(new Vector3(b.x, b.y, b.z));
            surfaceTool.AddVertex(new Vector3(c.x, c.y, c.z));
        }
Exemplo n.º 8
0
    public override void _Ready()
    {
        MarchCube(new Vector3(1, 0, 0));
        SurfaceTool st = new SurfaceTool();

        st.Begin(Mesh.PrimitiveType.Triangles);

        foreach (Vector3 vert in vertices)
        {
            st.AddVertex(vert);
        }

        Mesh = st.Commit();

        GD.Print(vertices);
    }
 void _draw_block_face(SurfaceTool surface_tool,
                       Godot.Collections.Array <Vector3> verts,
                       Godot.Collections.Array <Vector2> uvs)
 {
     surface_tool.AddUv(uvs[1]); surface_tool.AddVertex(verts[1]);
     surface_tool.AddUv(uvs[2]); surface_tool.AddVertex(verts[2]);
     surface_tool.AddUv(uvs[3]); surface_tool.AddVertex(verts[3]);
     surface_tool.AddUv(uvs[2]); surface_tool.AddVertex(verts[2]);
     surface_tool.AddUv(uvs[1]); surface_tool.AddVertex(verts[1]);
     surface_tool.AddUv(uvs[0]); surface_tool.AddVertex(verts[0]);
 }
Exemplo n.º 10
0
    private Mesh GenerateMesh(Vector3 pos, Vector2 size, int subdivision = 0)
    {
        SurfaceTool st = new SurfaceTool();

        st.Begin(Mesh.PrimitiveType.Triangles);

        int verts = 2 + subdivision;

        Vector3[,] vertices = new Vector3[verts, verts];

        for (int i = 0; i < verts; i++)
        {
            for (int j = 0; j < verts; j++)
            {
                Vector3 p = new Vector3(
                    ((float)i / (verts - 1)),
                    0f,
                    ((float)j / (verts - 1))
                    );

                p.x *= size.x;
                p.z *= size.y;
                p.y  = GetHeight(p + pos);

                vertices[i, j] = p;
            }
        }

        for (int i = 0; i < verts - 1; i++)
        {
            for (int j = 0; j < verts - 1; j++)
            {
                st.AddVertex(vertices[i + 1, j + 0]);
                st.AddVertex(vertices[i + 1, j + 1]);
                st.AddVertex(vertices[i + 0, j + 0]);

                st.AddVertex(vertices[i + 0, j + 0]);
                st.AddVertex(vertices[i + 1, j + 1]);
                st.AddVertex(vertices[i + 0, j + 1]);
            }
        }

        st.GenerateNormals();
        //st.GenerateTangents();
        st.Index();
        return(st.Commit());
    }
Exemplo n.º 11
0
    // TODO: spend some time to actually properly refactor that (the first step is 25% done)
    public override void AddPosXFace(ref SurfaceTool surfaceTool, Vector3 origin, byte blockType)
    {
        Rect2 uvs = Game.GetBlockUV(blockType, BlockFace.Left);

        surfaceTool.AddUv(uvs.Get(1, 1));
        surfaceTool.AddVertex(origin + this[+1, -1, -1]);
        surfaceTool.AddUv(uvs.Get(0, 0));
        surfaceTool.AddVertex(origin + this[+1, +1, +1]);
        surfaceTool.AddUv(uvs.Get(1, 0));
        surfaceTool.AddVertex(origin + this[+1, +1, -1]);

        surfaceTool.AddUv(uvs.Get(1, 1));
        surfaceTool.AddVertex(origin + this[+1, -1, -1]);
        surfaceTool.AddUv(uvs.Get(0, 1));
        surfaceTool.AddVertex(origin + this[+1, -1, +1]);
        surfaceTool.AddUv(uvs.Get(0, 0));
        surfaceTool.AddVertex(origin + this[+1, +1, +1]);
    }
Exemplo n.º 12
0
    public override void AddNegXFace(ref SurfaceTool surfaceTool, Vector3 origin, byte blockType)
    {
        Rect2 uvs = Game.GetBlockUV(blockType, BlockFace.Right);

        surfaceTool.AddUv(uvs.Get(0, 1));
        surfaceTool.AddVertex(origin + this[-1, -1, -1]);
        surfaceTool.AddUv(uvs.Get(0, 0));
        surfaceTool.AddVertex(origin + this[-1, +1, -1]);
        surfaceTool.AddUv(uvs.Get(1, 0));
        surfaceTool.AddVertex(origin + this[-1, +1, +1]);

        surfaceTool.AddUv(uvs.Position + new Vector2(0, uvs.Size.y));
        surfaceTool.AddVertex(origin + SIZE * new Vector3(-0.5f, -0.5f, -0.5f));
        surfaceTool.AddUv(uvs.Position + new Vector2(uvs.Size.x, 0));
        surfaceTool.AddVertex(origin + SIZE * new Vector3(-0.5f, +0.5f, +0.5f));
        surfaceTool.AddUv(uvs.End);
        surfaceTool.AddVertex(origin + SIZE * new Vector3(-0.5f, -0.5f, +0.5f));
    }
Exemplo n.º 13
0
    public override void AddNegYFace(ref SurfaceTool surfaceTool, Vector3 origin, byte blockType)
    {
        Rect2 uvs = Game.GetBlockUV(blockType, BlockFace.Bottom);

        surfaceTool.AddUv(uvs.Position);
        surfaceTool.AddVertex(origin + SIZE * new Vector3(-0.5f, -0.5f, -0.5f));
        surfaceTool.AddUv(uvs.End);
        surfaceTool.AddVertex(origin + SIZE * new Vector3(+0.5f, -0.5f, +0.5f));
        surfaceTool.AddUv(uvs.Position + new Vector2(uvs.Size.x, 0));
        surfaceTool.AddVertex(origin + SIZE * new Vector3(+0.5f, -0.5f, -0.5f));

        surfaceTool.AddUv(uvs.Position);
        surfaceTool.AddVertex(origin + SIZE * new Vector3(-0.5f, -0.5f, -0.5f));
        surfaceTool.AddUv(uvs.Position + new Vector2(0, uvs.Size.y));
        surfaceTool.AddVertex(origin + SIZE * new Vector3(-0.5f, -0.5f, +0.5f));
        surfaceTool.AddUv(uvs.End);
        surfaceTool.AddVertex(origin + SIZE * new Vector3(+0.5f, -0.5f, +0.5f));
    }
Exemplo n.º 14
0
    private SurfaceTool createQuad(SurfaceTool st, Vector3 pos, Quat q)
    {
        //1Quad = 4 points = 2 triangles
        Vector3 v1 = new Vector3(0, q.x, -1) + pos;
        Vector3 v2 = new Vector3(1, q.y, -1) + pos;
        Vector3 v3 = new Vector3(1, q.w, 0) + pos;
        Vector3 v4 = new Vector3(0, q.z, 0) + pos;

        //tri1
        st.AddUv(new Vector2(0, 0));
        st.AddColor(heightToColor(v1.y));// active albedoVertexColors on material
        st.AddVertex(v1);


        st.AddUv(new Vector2(0, 1));
        st.AddColor(heightToColor(v2.y));
        st.AddVertex(v2);


        st.AddUv(new Vector2(1, 1));
        st.AddColor(heightToColor(v4.y));
        st.AddVertex(v4);

        //tri2
        st.AddUv(new Vector2(0, 0));
        st.AddColor(heightToColor(v2.y));
        st.AddVertex(v2);

        st.AddUv(new Vector2(0, 1));
        st.AddColor(heightToColor(v3.y));
        st.AddVertex(v3);

        st.AddUv(new Vector2(1, 1));
        st.AddColor(heightToColor(v4.y));
        st.AddVertex(v4);

        return(st);
    }
Exemplo n.º 15
0
    // Declare member variables here. Examples:
    // private int a = 2;
    // private string b = "text";

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        var orig   = GetNode <MeshInstance>("orig");
        var tights = GetNode <MeshInstance>("tights");
        var result = GetNode <MeshInstance>("result");

        var tmpMesh     = new ArrayMesh();
        var surfaceTool = new SurfaceTool();

        surfaceTool.Begin(Mesh.PrimitiveType.Triangles);

        var tool = new MeshDataTool();

        tool.CreateFromSurface((ArrayMesh)tights.Mesh, 0);

        var tool2 = new MeshDataTool();

        tool2.CreateFromSurface((ArrayMesh)orig.Mesh, 0);

        List <Vector3> vertices = new List <Vector3>();

        for (int v = 0; v < tool2.GetVertexCount(); v++)
        {
            vertices.Add(tool2.GetVertex(v));
        }

        for (int v = 0; v < tool.GetVertexCount(); v++)
        {
            //  surfaceTool.AddNormal(tool.GetVertexNormal(v));
            //  surfaceTool.AddColor(tool.GetVertexColor(v));
            // surfaceTool.AddUv(tool.GetVertexUv(v));
            //  surfaceTool.AddUv2(tool.GetVertexUv2(v));
            //  surfaceTool.AddTangent(tool.GetVertexTangent(v));

            var newVer  = tool.GetVertex(v);
            var replace = vertices.OrderBy(df => newVer.DistanceTo(df)).FirstOrDefault();

            if (replace != null && replace != Vector3.Zero && replace.DistanceTo(newVer) > 0.03f)
            {
                GD.Print("replace" + newVer + " by dist " + replace.DistanceTo(newVer));
                surfaceTool.AddVertex(replace);
            }
            else
            {
                surfaceTool.AddVertex(newVer);
            }
        }

        for (int fc = 0; fc < tool.GetFaceCount(); fc++)
        {
            for (var i = 0; i <= 2; i++)
            {
                var ind = tool.GetFaceVertex(fc, i);
                surfaceTool.AddIndex(ind);
            }
        }


        surfaceTool.Commit(tmpMesh);
        result.Mesh = tmpMesh;
    }
Exemplo n.º 16
0
        private void CreateFaces(int x, int y, int z)
        {
            Vector3 voxPosition = new Vector3((x) * VOX_SIZE, (y) * VOX_SIZE, (z) * VOX_SIZE);

            voxPosition.x = voxPosition.x + (Dx * CHUNK_SIZE * VOX_SIZE);
            voxPosition.y = voxPosition.y + (Dy * CHUNK_SIZE * VOX_SIZE);
            voxPosition.z = voxPosition.z + (Dz * CHUNK_SIZE * VOX_SIZE);
            if (canCreateFace(x, y - 1, z))
            {
                surfaceTool.AddNormal(new Vector3(0.0f, -1.0f, 0.0f));
                surfaceTool.AddVertex(vertices[1] + voxPosition);
                surfaceTool.AddVertex(vertices[3] + voxPosition);
                surfaceTool.AddVertex(vertices[2] + voxPosition);

                surfaceTool.AddVertex(vertices[1] + voxPosition);
                surfaceTool.AddVertex(vertices[0] + voxPosition);
                surfaceTool.AddVertex(vertices[3] + voxPosition);
            }
            if (canCreateFace(x, y + 1, z))
            {
                surfaceTool.AddNormal(new Vector3(0.0f, 1.0f, 0.0f));
                surfaceTool.AddVertex(vertices[4] + voxPosition);
                surfaceTool.AddVertex(vertices[5] + voxPosition);
                surfaceTool.AddVertex(vertices[7] + voxPosition);

                surfaceTool.AddVertex(vertices[5] + voxPosition);
                surfaceTool.AddVertex(vertices[6] + voxPosition);
                surfaceTool.AddVertex(vertices[7] + voxPosition);
            }
            if (canCreateFace(x + 1, y, z))
            {
                surfaceTool.AddNormal(new Vector3(1.0f, 0.0f, 0.0f));
                surfaceTool.AddVertex(vertices[2] + voxPosition);
                surfaceTool.AddVertex(vertices[5] + voxPosition);
                surfaceTool.AddVertex(vertices[1] + voxPosition);

                surfaceTool.AddVertex(vertices[2] + voxPosition);
                surfaceTool.AddVertex(vertices[6] + voxPosition);
                surfaceTool.AddVertex(vertices[5] + voxPosition);
            }
            if (canCreateFace(x - 1, y, z))
            {
                surfaceTool.AddNormal(new Vector3(-1.0f, 0.0f, 0.0f));
                surfaceTool.AddVertex(vertices[0] + voxPosition);
                surfaceTool.AddVertex(vertices[7] + voxPosition);
                surfaceTool.AddVertex(vertices[3] + voxPosition);

                surfaceTool.AddVertex(vertices[0] + voxPosition);
                surfaceTool.AddVertex(vertices[4] + voxPosition);
                surfaceTool.AddVertex(vertices[7] + voxPosition);
            }
            if (canCreateFace(x, y, z + 1))
            {
                surfaceTool.AddNormal(new Vector3(0.0f, 0.0f, 1.0f));

                surfaceTool.AddVertex(vertices[3] + voxPosition);
                surfaceTool.AddVertex(vertices[6] + voxPosition);
                surfaceTool.AddVertex(vertices[2] + voxPosition);

                surfaceTool.AddVertex(vertices[3] + voxPosition);
                surfaceTool.AddVertex(vertices[7] + voxPosition);
                surfaceTool.AddVertex(vertices[6] + voxPosition);
            }
            if (canCreateFace(x, y, z - 1))
            {
                surfaceTool.AddNormal(new Vector3(0.0f, 0.0f, -1.0f));
                surfaceTool.AddVertex(vertices[0] + voxPosition);
                surfaceTool.AddVertex(vertices[1] + voxPosition);
                surfaceTool.AddVertex(vertices[5] + voxPosition);

                surfaceTool.AddVertex(vertices[5] + voxPosition);
                surfaceTool.AddVertex(vertices[4] + voxPosition);
                surfaceTool.AddVertex(vertices[0] + voxPosition);
            }
        }
Exemplo n.º 17
0
    // Create each faces of a single voxel at pPositon in cPosition chunk.
    private void CreateVoxel(SurfaceTool pSurfaceTool, int x, int y, int z, Chunk pChunk)
    {
        // If no voxel is at position, skip
        if (!pChunk.Voxels[x, y, z].Active)
        {
            return;
        }

        // If block is next to each faces
        bool left   = x != 0 ? !pChunk.Voxels[x - 1, y, z].Active : true;
        bool right  = x != 15 ? !pChunk.Voxels[x + 1, y, z].Active : true;
        bool front  = z != 15 ? !pChunk.Voxels[x, y, z + 1].Active : true;
        bool back   = z != 0 ? !pChunk.Voxels[x, y, z - 1].Active : true;
        bool top    = y != 254 ? !pChunk.Voxels[x, y + 1, z].Active : true;
        bool bottom = y > 0 ? !pChunk.Voxels[x, y - 1, z].Active : true;

        // If voxel is completly surrounded
        if (left && right && front && back && top && bottom)
        {
            return;
        }

        // If the voxel is on the side of a chunk. Check in the neighbor chunk.
        bool left2  = (x == 0 && PreloadedChunks[new Vector2(pChunk.Offset - new Vector2(1, 0))].Voxels[15, y, z].Active);
        bool right2 = (x == 15 && PreloadedChunks[new Vector2(pChunk.Offset + new Vector2(1, 0))].Voxels[0, y, z].Active);
        bool back2  = (z == 0 && PreloadedChunks[new Vector2(pChunk.Offset - new Vector2(0, 1))].Voxels[x, y, 15].Active);
        bool front2 = (z == 15 && PreloadedChunks[new Vector2(pChunk.Offset + new Vector2(0, 1))].Voxels[x, y, 0].Active);

        // Set right type
        var type = pChunk.Voxels[x, y, z].Type;

        // Local position of the voxel.
        Vector3 vertextOffset = new Vector3(x, y, z);

        // Get colors
        var color = GetVoxelColor(pChunk, vertextOffset, type);

        pSurfaceTool.AddColor(color);

        if (top) // Above
        {
            pSurfaceTool.AddNormal(new Vector3(0, 1, 0));
            pSurfaceTool.AddVertex(Vertices[4] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[5] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[7] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[5] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[6] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[7] + vertextOffset);
        }
        if (right && !right2) // Right
        {
            pSurfaceTool.AddNormal(new Vector3(1, 0, 0));
            pSurfaceTool.AddVertex(Vertices[2] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[5] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[1] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[2] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[6] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[5] + vertextOffset);
        }
        if (left && !left2) // Left
        {
            pSurfaceTool.AddNormal(new Vector3(-1, 0, 0));
            pSurfaceTool.AddVertex(Vertices[0] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[7] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[3] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[0] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[4] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[7] + vertextOffset);
        }
        if (front && !front2) // Front
        {
            pSurfaceTool.AddNormal(new Vector3(0, 0, 1));
            pSurfaceTool.AddVertex(Vertices[3] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[6] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[2] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[3] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[7] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[6] + vertextOffset);
        }
        if (back && !back2) // Above
        {
            pSurfaceTool.AddNormal(new Vector3(0, 0, -1));
            pSurfaceTool.AddVertex(Vertices[0] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[1] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[5] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[5] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[4] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[0] + vertextOffset);
        }
        if (bottom && y != 0)
        {
            pSurfaceTool.AddNormal(new Vector3(0, 1, 0));
            pSurfaceTool.AddVertex(Vertices[1] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[3] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[2] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[1] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[0] + vertextOffset);
            pSurfaceTool.AddVertex(Vertices[3] + vertextOffset);
        }
    }
        private Godot.Collections.Array createSurfaceByBones(ArrayMesh mesh, int surface, Skin newSkin, List <UMAReciepeBindPose> origBindPoses)
        {
            var mdt = new MeshDataTool();

            mdt.CreateFromSurface(mesh, surface);

            var st = new SurfaceTool();

            st.Begin(Mesh.PrimitiveType.Triangles);

            var newBindPoses = new List <UMAReciepeBindPose>();

            if (newSkin != null)
            {
                for (int i = 0; i < newSkin.GetBindCount(); i++)
                {
                    newBindPoses.Add(new UMAReciepeBindPose
                    {
                        boneName  = newSkin.GetBindName(i),
                        transform = newSkin.GetBindPose(i),
                        boneIndex = newSkin.GetBindBone(i)
                    });
                }
            }

            var boneAmount = 0;

            for (int i = 0; i < mdt.GetVertexCount(); i++)
            {
                var oldVer  = mdt.GetVertex(i);
                var oldNorm = mdt.GetVertexNormal(i);

                var newVer  = new Vector3();
                var newNorm = new Vector3();

                var indexes = mdt.GetVertexBones(i);

                //  st.AddTangent(mdt.GetVertexTangent(i));
                st.AddBones(mdt.GetVertexBones(i));
                st.AddWeights(mdt.GetVertexWeights(i));

                int boneId = 0;
                foreach (var weight in mdt.GetVertexWeights(i))
                {
                    if (newBindPoses.Count >= indexes[boneId] && origBindPoses.Count >= indexes[boneId])
                    {
                        var restBoneNew      = newBindPoses[indexes[boneId]];
                        var restBoneTemplate = origBindPoses[indexes[boneId]];

                        var dataup    = restBoneNew.transform.Xform(Vector3.Up);
                        var dataright = restBoneNew.transform.Xform(Vector3.Right);

                        var templateup    = restBoneTemplate.transform.Xform(Vector3.Up);
                        var templateright = restBoneTemplate.transform.Xform(Vector3.Right);

                        if (Mathf.Abs(dataup.AngleTo(templateup)) > 1 || Mathf.Abs(dataright.AngleTo(templateright)) > 1)
                        {
                            Transform convertMatrix = restBoneTemplate.transform.Inverse() * restBoneNew.transform;

                            newVer  += convertMatrix.Xform(oldVer) * weight;
                            newNorm += convertMatrix.basis.Xform(oldNorm) * weight;
                        }
                        else
                        {
                            newVer  += oldVer * weight;
                            newNorm += oldNorm * weight;
                        }
                    }
                    else
                    {
                        newVer  += oldVer * weight;
                        newNorm += oldNorm * weight;
                    }

                    boneId++;
                }


                st.AddUv(mdt.GetVertexUv(i));

                if (mdt.GetVertexColor(i) != null)
                {
                    st.AddColor(mdt.GetVertexColor(i));
                }

                if (mdt.GetVertexUv2(i) != null)
                {
                    st.AddUv2(mdt.GetVertexUv2(i));
                }

                st.AddNormal(newNorm);
                st.AddVertex(newVer);

                boneAmount += mdt.GetVertexBones(i).Length;
            }

            //creating indexes
            for (int face = 0; face < mdt.GetFaceCount(); face++)
            {
                for (int faceI = 0; faceI < 3; faceI++)
                {
                    var ind = mdt.GetFaceVertex(face, faceI);
                    st.AddIndex(ind);
                }
            }

            st.GenerateTangents();
            return(st.CommitToArrays());
        }
Exemplo n.º 19
0
    public MeshInstance CreateChunkMesh(Chunk chunk)
    {
        MeshInstance instance    = new MeshInstance();
        SurfaceTool  surfacetool = new SurfaceTool();

        surfacetool.Begin(Mesh.PrimitiveType.Points);
        surfacetool.SetMaterial(chunkMaterial);
        int count = 0;

        for (int i = 0; i < Constants.CHUNK_SIZE3D / chunk.Materials; i++)
        {
            Run         run         = chunk.Voxels[i];
            int         objectID    = run.value;
            TerraObject terraObject = registry.SelectByID((int)objectID);
            var         x           = i % CHUNK_SIZE;
            var         y           = (i / CHUNK_SIZE) % CHUNK_SIZE;
            var         z           = i / (CHUNK_SIZE * CHUNK_SIZE);
            if (chunk.Voxels[i].value != 0)
            {
                int face = 0b000000;
                //Left
                if (x == 0 || chunk.Voxels[i - 1].value != objectID)
                {
                    face = 0b000001;
                }

                //Right
                else if (x == 63 || chunk.Voxels[i + 1].value != objectID)
                {
                    face = 0b000010;
                }
                //Top
                else if (y == 63 || chunk.Voxels[i + 64].value != objectID)
                {
                    face = 0b000100;
                }
                //Bottom
                else if (y == 0 || chunk.Voxels[i - 64].value != objectID)
                {
                    face = 0b001000;
                }
                //Back
                else if (z == 63 || chunk.Voxels[i + 4096].value != objectID)
                {
                    face = 0b010000;
                }
                //Front
                else if (z == 0 || chunk.Voxels[i - 4096].value != objectID)
                {
                    face = 0b100000;
                }

                if (face != 0b000000)
                {
                    int     counter   = 0;
                    Vector3 normalAvg = Vector3.Zero;
                    for (int j = 0; j < 6; j++)
                    {
                        int bitFlagN = (face >> j) & 1;
                        if (bitFlagN == 1)
                        {
                            normalAvg = normalAvg + Normals[j];
                            counter  += 1;
                        }
                    }

                    count += 1;
                    surfacetool.AddColor(new Color(1f, 1f, 1f, 1f));
                    Vector3 voxPosition = new Vector3((x) * VOX_SIZE, (y) * VOX_SIZE, (z) * VOX_SIZE);
                    voxPosition.x = voxPosition.x + (chunk.x * CHUNK_SIZE * VOX_SIZE);
                    voxPosition.y = voxPosition.y + (chunk.y * CHUNK_SIZE * VOX_SIZE);
                    voxPosition.z = voxPosition.z + (chunk.z * CHUNK_SIZE * VOX_SIZE);
                    if (counter > 0)
                    {
                        normalAvg = normalAvg / counter;
                        surfacetool.AddNormal(normalAvg);
                    }

                    surfacetool.AddVertex(voxPosition);
                }
            }
        }

        surfacetool.Index();
        instance.Mesh = surfacetool.Commit();
        surfacetool.Clear();
        instance.MaterialOverride = chunkMaterial.Duplicate() as ShaderMaterial;

        // Console.WriteLine("Mesh AABB Pos: {0} , Size: {1}, End: {2}",bb.Position,bb.Size,bb.End);
        return(instance);
    }
Exemplo n.º 20
0
        public static void CreateCube(SurfaceTool st, float size, Vector3 position, Sides sides)
        {
            if (sides.HasFlag(Sides.North) ||
                sides.HasFlag(Sides.East) ||
                sides.HasFlag(Sides.South) ||
                sides.HasFlag(Sides.West))
            {
                Color white = new Color(1f, 1f, 1f, 1f);

                Vector3[] vertices = GetVerticesForCell(size, position);

                if (sides.HasFlag(Sides.North))
                {
                    st.AddUv(new Vector2(1, 1));
                    st.AddNormal(North);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Bot_NW]);
                    st.AddUv(new Vector2(0, 0));
                    st.AddNormal(North);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Top_NE]);
                    st.AddUv(new Vector2(1, 0));
                    st.AddNormal(North);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Top_NW]);

                    st.AddUv(new Vector2(1, 1));
                    st.AddNormal(North);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Bot_NW]);
                    st.AddUv(new Vector2(0, 1));
                    st.AddNormal(North);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Bot_NE]);
                    st.AddUv(new Vector2(0, 0));
                    st.AddNormal(North);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Top_NE]);
                }

                if (sides.HasFlag(Sides.East))
                {
                    st.AddUv(new Vector2(0, 0));
                    st.AddNormal(East);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Top_SE]);
                    st.AddUv(new Vector2(1, 0));
                    st.AddNormal(East);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Top_NE]);
                    st.AddUv(new Vector2(0, 1));
                    st.AddNormal(East);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Bot_SE]);

                    st.AddUv(new Vector2(1, 0));
                    st.AddNormal(East);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Top_NE]);
                    st.AddUv(new Vector2(1, 1));
                    st.AddNormal(East);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Bot_NE]);
                    st.AddUv(new Vector2(0, 1));
                    st.AddNormal(East);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Bot_SE]);
                }

                if (sides.HasFlag(Sides.South))
                {
                    st.AddUv(new Vector2(0, 0));
                    st.AddNormal(South);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Top_SW]);
                    st.AddUv(new Vector2(1, 0));
                    st.AddNormal(South);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Top_SE]);
                    st.AddUv(new Vector2(0, 1));
                    st.AddNormal(South);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Bot_SW]);

                    st.AddUv(new Vector2(1, 0));
                    st.AddNormal(South);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Top_SE]);
                    st.AddUv(new Vector2(1, 1));
                    st.AddNormal(South);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Bot_SE]);
                    st.AddUv(new Vector2(0, 1));
                    st.AddNormal(South);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Bot_SW]);
                }

                if (sides.HasFlag(Sides.West))
                {
                    st.AddUv(new Vector2(1, 1));
                    st.AddNormal(West);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Bot_SW]);
                    st.AddUv(new Vector2(0, 0));
                    st.AddNormal(West);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Top_NW]);
                    st.AddUv(new Vector2(1, 0));
                    st.AddNormal(West);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Top_SW]);

                    st.AddUv(new Vector2(1, 1));
                    st.AddNormal(West);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Bot_SW]);
                    st.AddUv(new Vector2(0, 1));
                    st.AddNormal(West);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Bot_NW]);
                    st.AddUv(new Vector2(0, 0));
                    st.AddNormal(West);
                    st.AddColor(white);
                    st.AddVertex(vertices[(int)CellVertexIndex.Top_NW]);
                }
            }
        }
Exemplo n.º 21
0
    public void CreateMesh(Tile tile, PackedScene sphereMeshScene, PackedScene greenSphereMeshScene, int numberOfTiles, float radius)
    {
        var surfTool = new SurfaceTool();
        var mesh     = new ArrayMesh();
        var material = new SpatialMaterial();

        material.SetEmission(new Color(1.0f, 0.0f, 0.0f));
        material.SetAlbedo(new Color(1.0f, 0.0f, 0.0f));
        surfTool.SetMaterial(material);
        surfTool.Begin(Mesh.PrimitiveType.LineLoop);
        decimal tileCenterX   = 0;
        decimal tileCenterY   = 0;
        decimal tileCenterZ   = 0;
        decimal polygonRadius = 0;

        List <Point> points            = tile.boundary;
        var          lastPoint         = points[points.Count - 1];
        Vector3      lastPointVector   = new Vector3((float)lastPoint.x, (float)lastPoint.y, (float)lastPoint.z);
        decimal      polygonSideLength = 0;

        foreach (Point point in points)
        {
            surfTool.AddUv(new Vector2(0, 0));
            surfTool.AddVertex(new Vector3((float)point.x, (float)point.y, (float)point.z));

            tileCenterX += point.x / points.Count;
            tileCenterY += point.y / points.Count;
            tileCenterZ += point.z / points.Count;
            Vector3 currentVector = new Vector3((float)point.x, (float)point.y, (float)point.z);
            polygonSideLength += (decimal)currentVector.DistanceTo(lastPointVector);
            lastPointVector    = currentVector;
        }
        polygonSideLength = polygonSideLength / points.Count;

        var tileCenterPoint = new Vector3((float)tileCenterX, (float)tileCenterY, (float)tileCenterZ);
        var firstPoint      = new Vector3((float)points[0].x, (float)points[0].y, (float)points[0].z);

        foreach (Point point in points)
        {
            var vector = new Vector3((float)point.x, (float)point.y, (float)point.z);
            polygonRadius += (decimal)vector.DistanceTo(tileCenterPoint);
        }
        polygonRadius = polygonRadius / points.Count;

        var polygonRotation = firstPoint.AngleTo(tileCenterPoint);


        var sphereCenterPoint = new Vector3(0f, 0f, 0f);

        var          sphereScale = radius / numberOfTiles;
        MeshInstance sphere      = (MeshInstance)sphereMeshScene.Instance();

        sphere.SetTranslation(tileCenterPoint);
        sphere.SetScale(new Vector3(sphereScale, sphereScale, sphereScale));
        this.AddChild(sphere);

        MeshInstance sphere2 = (MeshInstance)greenSphereMeshScene.Instance();

        sphere2.SetTranslation(firstPoint);
        sphere2.SetScale(new Vector3(sphereScale, sphereScale, sphereScale));
        this.AddChild(sphere2);

        MeshInstance sphere3 = (MeshInstance)greenSphereMeshScene.Instance();

        sphere3.SetTranslation((firstPoint - tileCenterPoint) / 2 + tileCenterPoint);
        sphere3.SetScale(new Vector3(sphereScale, sphereScale, sphereScale));
        this.AddChild(sphere3);

        surfTool.GenerateNormals();
        surfTool.Index();
        surfTool.Commit(mesh);
        var meshInstance = new MeshInstance();

        meshInstance.SetMesh(mesh);
        this.AddChild(meshInstance);
    }
Exemplo n.º 22
0
        private static void BuildDoorMesh()
        {
            if (_doorMesh == null)
            {
                Color white = new Color(1f, 1f, 1f, 1f);

                using (SurfaceTool st = new SurfaceTool())
                {
                    Vector3[] cellVerts = Level.GetVerticesForCell();

                    Vector3[] verts = new Vector3[] {
                        Lerp(cellVerts[(int)Level.CellVertexIndex.Top_SW], cellVerts[(int)Level.CellVertexIndex.Top_NW], 0.5f),
                        Lerp(cellVerts[(int)Level.CellVertexIndex.Top_SE], cellVerts[(int)Level.CellVertexIndex.Top_NE], 0.5f),
                        Lerp(cellVerts[(int)Level.CellVertexIndex.Bot_SW], cellVerts[(int)Level.CellVertexIndex.Bot_NW], 0.5f),
                        Lerp(cellVerts[(int)Level.CellVertexIndex.Bot_SE], cellVerts[(int)Level.CellVertexIndex.Bot_NE], 0.5f)
                    };

                    st.Begin(Godot.Mesh.PrimitiveType.Triangles);

                    st.AddUv(new Vector2(0f, 1f));
                    st.AddColor(white);
                    st.AddNormal(Level.South);
                    st.AddVertex(verts[3]);
                    st.AddUv(new Vector2(0f, 0f));
                    st.AddColor(white);
                    st.AddNormal(Level.South);
                    st.AddVertex(verts[1]);
                    st.AddUv(new Vector2(1f, 0f));
                    st.AddColor(white);
                    st.AddNormal(Level.South);
                    st.AddVertex(verts[0]);

                    st.AddUv(new Vector2(1f, 1f));
                    st.AddColor(white);
                    st.AddNormal(Level.South);
                    st.AddVertex(verts[2]);
                    st.AddUv(new Vector2(0f, 1f));
                    st.AddColor(white);
                    st.AddNormal(Level.South);
                    st.AddVertex(verts[3]);
                    st.AddUv(new Vector2(1f, 0f));
                    st.AddColor(white);
                    st.AddNormal(Level.South);
                    st.AddVertex(verts[0]);


                    st.AddUv(new Vector2(1f, 0f));
                    st.AddColor(white);
                    st.AddNormal(Level.North);
                    st.AddVertex(verts[0]);
                    st.AddUv(new Vector2(0f, 0f));
                    st.AddColor(white);
                    st.AddNormal(Level.North);
                    st.AddVertex(verts[1]);
                    st.AddUv(new Vector2(0f, 1f));
                    st.AddColor(white);
                    st.AddNormal(Level.North);
                    st.AddVertex(verts[3]);

                    st.AddUv(new Vector2(1f, 0f));
                    st.AddColor(white);
                    st.AddNormal(Level.North);
                    st.AddVertex(verts[0]);
                    st.AddUv(new Vector2(0f, 1f));
                    st.AddColor(white);
                    st.AddNormal(Level.North);
                    st.AddVertex(verts[3]);
                    st.AddUv(new Vector2(1f, 1f));
                    st.AddColor(white);
                    st.AddNormal(Level.North);
                    st.AddVertex(verts[2]);

                    _doorMesh = st.Commit();
                }
            }
        }
Exemplo n.º 23
0
        private void createFaces(int x, int y, int z, int Dx, int Dy, int Dz,
                                 ref SurfaceTool surfaceTool, ref ChunkStruct c)
        {
            Vector3 voxPosition = new Vector3((x) * VOX_SIZE, (y) * VOX_SIZE, (z) * VOX_SIZE);

            voxPosition.x = voxPosition.x + (Dx * CHUNK_SIZE * VOX_SIZE);
            voxPosition.y = voxPosition.y + (Dy * CHUNK_SIZE * VOX_SIZE);
            voxPosition.z = voxPosition.z + (Dz * CHUNK_SIZE * VOX_SIZE);
            if (canCreateFace(x, y - 1, z, ref c))
            {
                surfaceTool.AddNormal(new Vector3(0.0f, -1.0f, 0.0f));
                surfaceTool.AddColor(new Color(1.0f, 1.0f, .7f, 1f));
                surfaceTool.AddVertex(vertices[1] + voxPosition);
                surfaceTool.AddVertex(vertices[3] + voxPosition);
                surfaceTool.AddVertex(vertices[2] + voxPosition);

                surfaceTool.AddVertex(vertices[1] + voxPosition);
                surfaceTool.AddVertex(vertices[0] + voxPosition);
                surfaceTool.AddVertex(vertices[3] + voxPosition);
            }
            if (canCreateFace(x, y + 1, z, ref c))
            {
                surfaceTool.AddNormal(new Vector3(0.0f, 1.0f, 0.0f));
                surfaceTool.AddColor(new Color(0.7f, 0.0f, .7f, 1f));
                surfaceTool.AddVertex(vertices[4] + voxPosition);
                surfaceTool.AddVertex(vertices[5] + voxPosition);
                surfaceTool.AddVertex(vertices[7] + voxPosition);

                surfaceTool.AddVertex(vertices[5] + voxPosition);
                surfaceTool.AddVertex(vertices[6] + voxPosition);
                surfaceTool.AddVertex(vertices[7] + voxPosition);
            }
            if (canCreateFace(x + 1, y, z, ref c))
            {
                surfaceTool.AddNormal(new Vector3(1.0f, 0.0f, 0.0f));
                surfaceTool.AddColor(new Color(1f, 1f, 1f, 1f));
                surfaceTool.AddVertex(vertices[2] + voxPosition);
                surfaceTool.AddVertex(vertices[5] + voxPosition);
                surfaceTool.AddVertex(vertices[1] + voxPosition);

                surfaceTool.AddVertex(vertices[2] + voxPosition);
                surfaceTool.AddVertex(vertices[6] + voxPosition);
                surfaceTool.AddVertex(vertices[5] + voxPosition);
            }
            if (canCreateFace(x - 1, y, z, ref c))
            {
                surfaceTool.AddNormal(new Vector3(-1.0f, 0.0f, 0.0f));
                surfaceTool.AddColor(new Color(1f, 1f, 1f, 1f));
                surfaceTool.AddVertex(vertices[0] + voxPosition);
                surfaceTool.AddVertex(vertices[7] + voxPosition);
                surfaceTool.AddVertex(vertices[3] + voxPosition);

                surfaceTool.AddVertex(vertices[0] + voxPosition);
                surfaceTool.AddVertex(vertices[4] + voxPosition);
                surfaceTool.AddVertex(vertices[7] + voxPosition);
            }
            if (canCreateFace(x, y, z + 1, ref c))
            {
                surfaceTool.AddNormal(new Vector3(0.0f, 0.0f, 1.0f));
                surfaceTool.AddColor(new Color(1f, 1f, 1f, 1f));
                surfaceTool.AddVertex(vertices[3] + voxPosition);
                surfaceTool.AddVertex(vertices[6] + voxPosition);
                surfaceTool.AddVertex(vertices[2] + voxPosition);

                surfaceTool.AddVertex(vertices[3] + voxPosition);
                surfaceTool.AddVertex(vertices[7] + voxPosition);
                surfaceTool.AddVertex(vertices[6] + voxPosition);
            }
            if (canCreateFace(x, y, z - 1, ref c))
            {
                surfaceTool.AddNormal(new Vector3(0.0f, 0.0f, -1.0f));
                surfaceTool.AddColor(new Color(1f, 1f, 1f, 1f));
                surfaceTool.AddVertex(vertices[0] + voxPosition);
                surfaceTool.AddVertex(vertices[1] + voxPosition);
                surfaceTool.AddVertex(vertices[5] + voxPosition);

                surfaceTool.AddVertex(vertices[5] + voxPosition);
                surfaceTool.AddVertex(vertices[4] + voxPosition);
                surfaceTool.AddVertex(vertices[0] + voxPosition);
            }
        }
Exemplo n.º 24
0
    private void CreatePerceptionPyramidMesh()
    {
        var material = new SpatialMaterial();

        material.FlagsTransparent = true;
        material.AlbedoColor      = new Color(0.0f, 1.0f, 0.0f, 0.02f);
        material.SetCullMode(SpatialMaterial.CullMode.Disabled);

        // Pyramid
        var surfaceTool = new SurfaceTool();

        surfaceTool.Begin(Mesh.PrimitiveType.Triangles);

        // Top face
        surfaceTool.AddNormal(new Vector3(0.0f, 0.5f, 0.5f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(-perceptionRadius / 2, perceptionRadius / 2, -perceptionRadius)); // top left

        surfaceTool.AddNormal(new Vector3(0.0f, 0.5f, 0.5f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(perceptionRadius / 2, perceptionRadius / 2, -perceptionRadius)); // top right

        surfaceTool.AddNormal(new Vector3(0.0f, 0.5f, 0.5f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(0, 0, 2.0f)); // home

        // Right face
        surfaceTool.AddNormal(new Vector3(0.5f, 0.0f, 0.5f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(perceptionRadius / 2, perceptionRadius / 2, -perceptionRadius)); // top right

        surfaceTool.AddNormal(new Vector3(0.5f, 0.0f, 0.5f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(perceptionRadius / 2, -perceptionRadius / 2, -perceptionRadius)); // bottom right

        surfaceTool.AddNormal(new Vector3(0.5f, 0.0f, 0.5f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(0, 0, 2.0f)); // home

        // Bottom face
        surfaceTool.AddNormal(new Vector3(0.0f, -0.5f, 0.5f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(perceptionRadius / 2, -perceptionRadius / 2, -perceptionRadius)); // bottom right

        surfaceTool.AddNormal(new Vector3(0.0f, -0.5f, 0.5f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(-perceptionRadius / 2, -perceptionRadius / 2, -perceptionRadius)); // bottom left

        surfaceTool.AddNormal(new Vector3(0.0f, -0.5f, 0.5f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(0, 0, 2.0f)); // home

        // Left face
        surfaceTool.AddNormal(new Vector3(-0.5f, 0.0f, 0.5f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(-perceptionRadius / 2, -perceptionRadius / 2, -perceptionRadius)); // bottom left

        surfaceTool.AddNormal(new Vector3(-0.5f, 0.0f, 0.5f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(-perceptionRadius / 2, perceptionRadius / 2, -perceptionRadius)); // top left

        surfaceTool.AddNormal(new Vector3(-0.5f, 0.0f, 0.5f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(0, 0, 2.0f)); // home

        // Base face1
        surfaceTool.AddNormal(new Vector3(0.0f, 0.0f, -1.0f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(perceptionRadius / 2, perceptionRadius / 2, -perceptionRadius)); // top right

        surfaceTool.AddNormal(new Vector3(0.0f, 0.0f, -1.0f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(-perceptionRadius / 2, perceptionRadius / 2, -perceptionRadius)); // top left

        surfaceTool.AddNormal(new Vector3(0.0f, 0.0f, -1.0f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(-perceptionRadius / 2, -perceptionRadius / 2, -perceptionRadius)); // bottom left

        // Base face2
        surfaceTool.AddNormal(new Vector3(0.0f, 0.0f, -1.0f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(-perceptionRadius / 2, -perceptionRadius / 2, -perceptionRadius)); // bottom left

        surfaceTool.AddNormal(new Vector3(0.0f, 0.0f, -1.0f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(perceptionRadius / 2, -perceptionRadius / 2, -perceptionRadius)); // bottom right

        surfaceTool.AddNormal(new Vector3(0.0f, 0.0f, -1.0f));
        surfaceTool.AddColor(new Color(0.0f, 1.0f, 0.0f, 0.02f));
        surfaceTool.AddVertex(new Vector3(perceptionRadius / 2, perceptionRadius / 2, -perceptionRadius)); // top right

        surfaceTool.Index();

        var mesh = surfaceTool.Commit();

        mesh.SurfaceSetMaterial(0, material);

        var meshInstance = new MeshInstance();

        meshInstance.Mesh = mesh;
        meshInstance.SetName("perceptionMesh");
        meshInstance.SetVisible(false);

        this.AddChild(meshInstance);
    }
        private void Reset()
        {
            Mesh usedMesh = mesh;

            if (usedMesh == null)
            {
                SurfaceTool st = new SurfaceTool();

                st.Begin(Mesh.PrimitiveType.Triangles);

                switch (drawMode)
                {
                case DrawMode.SingleTriangle:
                {
                    st.AddUv(new Vector2(0, 0));
                    st.AddVertex(new Vector3(-.5f, -.5f, 0));

                    st.AddUv(new Vector2(0, 2));
                    st.AddVertex(new Vector3(-.5f, 1.5f, 0));

                    st.AddUv(new Vector2(2, 0));
                    st.AddVertex(new Vector3(1.5f, -.5f, 0));
                    break;
                }

                case DrawMode.Quad:
                {
                    st.AddUv(new Vector2(0, 0));
                    st.AddVertex(new Vector3(-.5f, -.5f, 0));

                    st.AddUv(new Vector2(0, 1));
                    st.AddVertex(new Vector3(-.5f, .5f, 0));

                    st.AddUv(new Vector2(1, 0));
                    st.AddVertex(new Vector3(.5f, .51f, 0));

                    st.AddUv(new Vector2(1, 0));
                    st.AddVertex(new Vector3(.5f, -.5f, 0));

                    st.AddUv(new Vector2(0, 1));
                    st.AddVertex(new Vector3(-.5f, .5f, 0));

                    st.AddUv(new Vector2(1, 1));
                    st.AddVertex(new Vector3(.5f, .5f, 0));
                    break;
                }
                }

                //st.SetMaterial(particleSystem.testMaterial);
                st.Index();

                usedMesh = st.Commit();
            }

            multimesh = new MultiMesh();
            multimesh.TransformFormat = MultiMesh.TransformFormatEnum.Transform2d;
            multimesh.ColorFormat     = MultiMesh.ColorFormatEnum.Float;
            //multimesh.CustomDataFormat = MultiMesh.CustomDataFormatEnum.Float;
            multimesh.Mesh          = usedMesh;
            multimesh.InstanceCount = particleSystem.maxParticles;
        }
Exemplo n.º 26
0
    private void CreateVoxel(Color color, Vector3 position)
    {
        bool left   = !Voxels.ContainsKey(position - new Vector3(1, 0, 0));
        bool right  = !Voxels.ContainsKey(position + new Vector3(1, 0, 0));
        bool back   = !Voxels.ContainsKey(position - new Vector3(0, 0, 1));
        bool front  = !Voxels.ContainsKey(position + new Vector3(0, 0, 1));
        bool top    = !Voxels.ContainsKey(position + new Vector3(0, 1, 0));
        bool bottom = !Voxels.ContainsKey(position - new Vector3(0, 1, 0));

        if (left && right && front && back && top && bottom)
        {
            return;
        }

        SurfaceTool.AddColor(color);

        void addVertex(Vector3 pos) => SurfaceTool.AddVertex(pos * VoxelSize);

        Vector3 vertexOffset = position;

        if (top) // Above
        {
            SurfaceTool.AddNormal(new Vector3(0, -1, 0));
            addVertex(Vertices[4] + vertexOffset);
            addVertex(Vertices[5] + vertexOffset);
            addVertex(Vertices[7] + vertexOffset);
            addVertex(Vertices[5] + vertexOffset);
            addVertex(Vertices[6] + vertexOffset);
            addVertex(Vertices[7] + vertexOffset);
        }
        if (right) // Right
        {
            SurfaceTool.AddNormal(new Vector3(1, 0, 0));
            addVertex(Vertices[2] + vertexOffset);
            addVertex(Vertices[5] + vertexOffset);
            addVertex(Vertices[1] + vertexOffset);
            addVertex(Vertices[2] + vertexOffset);
            addVertex(Vertices[6] + vertexOffset);
            addVertex(Vertices[5] + vertexOffset);
        }
        if (left) // Left
        {
            SurfaceTool.AddNormal(new Vector3(-1, 0, 0));
            addVertex(Vertices[0] + vertexOffset);
            addVertex(Vertices[7] + vertexOffset);
            addVertex(Vertices[3] + vertexOffset);
            addVertex(Vertices[0] + vertexOffset);
            addVertex(Vertices[4] + vertexOffset);
            addVertex(Vertices[7] + vertexOffset);
        }
        if (front) // Front
        {
            SurfaceTool.AddNormal(new Vector3(0, 0, 1));
            addVertex(Vertices[3] + vertexOffset);
            addVertex(Vertices[6] + vertexOffset);
            addVertex(Vertices[2] + vertexOffset);
            addVertex(Vertices[3] + vertexOffset);
            addVertex(Vertices[7] + vertexOffset);
            addVertex(Vertices[6] + vertexOffset);
        }
        if (back) // Above
        {
            SurfaceTool.AddNormal(new Vector3(0, 0, -1));
            addVertex(Vertices[0] + vertexOffset);
            addVertex(Vertices[1] + vertexOffset);
            addVertex(Vertices[5] + vertexOffset);
            addVertex(Vertices[5] + vertexOffset);
            addVertex(Vertices[4] + vertexOffset);
            addVertex(Vertices[0] + vertexOffset);
        }
        if (bottom)
        {
            SurfaceTool.AddNormal(new Vector3(0, 1, 0));
            addVertex(Vertices[1] + vertexOffset);
            addVertex(Vertices[3] + vertexOffset);
            addVertex(Vertices[2] + vertexOffset);
            addVertex(Vertices[1] + vertexOffset);
            addVertex(Vertices[0] + vertexOffset);
            addVertex(Vertices[3] + vertexOffset);
        }
    }
Exemplo n.º 27
0
        public override void _Ready()
        {
            var surfTool = new SurfaceTool();

            surfTool.Begin(Mesh.PrimitiveType.Triangles);
            Vector3[] vertices = new Vector3[] { new Vector3(0, 0, 0),
                                                 new Vector3(length, 0, 0),
                                                 new Vector3(length, 0, width),
                                                 new Vector3(0, 0, width),

                                                 new Vector3(0, height, 0),
                                                 new Vector3(length, height, 0),
                                                 new Vector3(length, height, width),
                                                 new Vector3(0, height, width) };

            // surfTool.AddNormal(new Vector3(0.0f,0.0f,-1.0f));
            // surfTool.AddVertex(new Vector3(length, -height, -width));
            // surfTool.AddVertex(new Vector3(-length, -height, -width));
            // surfTool.AddVertex(new Vector3(-length, height, -width));
            // surfTool.AddVertex(new Vector3(length, height, -width));

            // // surfTool.AddNormal(new Vector3(0.0f, 0.0f, 1.0f));
            // surfTool.AddVertex(new Vector3(-length, -height, width));
            // surfTool.AddVertex(new Vector3(length, -height, width));
            // surfTool.AddVertex(new Vector3(length, height, width));
            // surfTool.AddVertex(new Vector3(-length, height, width));

            // // surfTool.AddNormal(new Vector3(1.0f, 0.0f, 0.0f));
            // surfTool.AddVertex(new Vector3(length, -height, width));
            // surfTool.AddVertex(new Vector3(length, -height, -width));
            // surfTool.AddVertex(new Vector3(length, height, -width));
            // surfTool.AddVertex(new Vector3(length, height, width));

            // surfTool.AddNormal(new Vector3(-1.0f, 0.0f, 0.0f));
            // surfTool.AddVertex(new Vector3(-length, -height, -width));
            // surfTool.AddVertex(new Vector3(-length, -height, width));
            // surfTool.AddVertex(new Vector3(-length, height, width));
            // surfTool.AddVertex(new Vector3(-length, height, -width));

            //Bottom Face
            surfTool.AddNormal(new Vector3(0.0f, -1.0f, 0.0f));
            surfTool.AddVertex(vertices[1]);
            surfTool.AddVertex(vertices[3]);
            surfTool.AddVertex(vertices[2]);

            surfTool.AddVertex(vertices[1]);
            surfTool.AddVertex(vertices[0]);
            surfTool.AddVertex(vertices[3]);

            surfTool.AddNormal(new Vector3(0.0f, 1.0f, 0.0f));
            surfTool.AddVertex(vertices[4]);
            surfTool.AddVertex(vertices[5]);
            surfTool.AddVertex(vertices[7]);

            surfTool.AddVertex(vertices[5]);
            surfTool.AddVertex(vertices[6]);
            surfTool.AddVertex(vertices[7]);

            surfTool.AddNormal(new Vector3(0.0f, 0.0f, 1.0f));
            surfTool.AddVertex(vertices[0]);
            surfTool.AddVertex(vertices[1]);
            surfTool.AddVertex(vertices[5]);

            surfTool.AddVertex(vertices[5]);
            surfTool.AddVertex(vertices[4]);
            surfTool.AddVertex(vertices[0]);

            surfTool.AddNormal(new Vector3(0.0f, 0.0f, -1.0f));
            surfTool.AddVertex(vertices[3]);
            surfTool.AddVertex(vertices[6]);
            surfTool.AddVertex(vertices[2]);

            surfTool.AddVertex(vertices[3]);
            surfTool.AddVertex(vertices[7]);
            surfTool.AddVertex(vertices[6]);


            surfTool.AddNormal(new Vector3(-1.0f, 0.0f, 0.0f));
            surfTool.AddVertex(vertices[0]);
            surfTool.AddVertex(vertices[7]);
            surfTool.AddVertex(vertices[3]);

            surfTool.AddVertex(vertices[0]);
            surfTool.AddVertex(vertices[4]);
            surfTool.AddVertex(vertices[7]);

            surfTool.AddNormal(new Vector3(1.0f, 0.0f, 0.0f));
            surfTool.AddVertex(vertices[2]);
            surfTool.AddVertex(vertices[5]);
            surfTool.AddVertex(vertices[1]);

            surfTool.AddVertex(vertices[2]);
            surfTool.AddVertex(vertices[6]);
            surfTool.AddVertex(vertices[5]);


            // // surfTool.AddNormal(new Vector3(0.0f, 1.0f, 0.0f));
            // surfTool.AddVertex(new Vector3(length, height, -width));
            // surfTool.AddVertex(new Vector3(-length, height, -width));
            // surfTool.AddVertex(new Vector3(-length, height, width));
            // surfTool.AddVertex(new Vector3(length, height, width));

            surfTool.Index();
            // surfTool.GenerateNormals();

            var mesh = surfTool.Commit();

            this.SetMesh(mesh);
        }
Exemplo n.º 28
0
    private static MeshInstance DebugMesh()
    {
        SurfaceTool tool = new SurfaceTool();

        tool.Begin(PrimitiveMesh.PrimitiveType.Lines);

        //Front
        tool.AddVertex(new Vector3(0, 0, 0));
        tool.AddVertex(new Vector3(1, 0, 0));
        tool.AddVertex(new Vector3(1, 0, 0));
        tool.AddVertex(new Vector3(1, 1, 0));
        tool.AddVertex(new Vector3(1, 1, 0));
        tool.AddVertex(new Vector3(0, 1, 0));
        tool.AddVertex(new Vector3(0, 1, 0));
        tool.AddVertex(new Vector3(0, 0, 0));

        //Back
        tool.AddVertex(new Vector3(0, 0, 1));
        tool.AddVertex(new Vector3(1, 0, 1));
        tool.AddVertex(new Vector3(1, 0, 1));
        tool.AddVertex(new Vector3(1, 1, 1));
        tool.AddVertex(new Vector3(1, 1, 1));
        tool.AddVertex(new Vector3(0, 1, 1));
        tool.AddVertex(new Vector3(0, 1, 1));
        tool.AddVertex(new Vector3(0, 0, 1));

        //BOTTOM
        tool.AddVertex(new Vector3(0, 0, 0));
        tool.AddVertex(new Vector3(0, 0, 1));
        tool.AddVertex(new Vector3(0, 0, 1));
        tool.AddVertex(new Vector3(1, 0, 1));
        tool.AddVertex(new Vector3(1, 0, 1));
        tool.AddVertex(new Vector3(1, 0, 0));
        tool.AddVertex(new Vector3(1, 0, 0));
        tool.AddVertex(new Vector3(0, 0, 0));

        //TOP
        tool.AddVertex(new Vector3(0, 1, 0));
        tool.AddVertex(new Vector3(0, 1, 1));
        tool.AddVertex(new Vector3(0, 1, 1));
        tool.AddVertex(new Vector3(1, 1, 1));
        tool.AddVertex(new Vector3(1, 1, 1));
        tool.AddVertex(new Vector3(1, 1, 0));
        tool.AddVertex(new Vector3(1, 1, 0));
        tool.AddVertex(new Vector3(0, 1, 0));

        MeshInstance instance = new MeshInstance();

        instance.Mesh = tool.Commit();
        return(instance);
    }
Exemplo n.º 29
0
        private void BuildFaces(bool[] freeSides, SurfaceTool tool, int x, int y, int z)
        {
            Vector3 offset = new Vector3(x, y, z);

            if (freeSides[0])
            {
                tool.AddVertex(new Vector3(BlockSize, BlockSize, -BlockSize) + offset);
                tool.AddVertex(new Vector3(BlockSize, BlockSize, BlockSize) + offset);
                tool.AddVertex(new Vector3(-BlockSize, BlockSize, BlockSize) + offset);

                tool.AddVertex(new Vector3(-BlockSize, BlockSize, BlockSize) + offset);
                tool.AddVertex(new Vector3(-BlockSize, BlockSize, -BlockSize) + offset);
                tool.AddVertex(new Vector3(BlockSize, BlockSize, -BlockSize) + offset);
            }
            if (freeSides[1])
            {
                tool.AddVertex(new Vector3(BlockSize, -BlockSize, -BlockSize) + offset);
                tool.AddVertex(new Vector3(BlockSize, -BlockSize, BlockSize) + offset);
                tool.AddVertex(new Vector3(-BlockSize, -BlockSize, BlockSize) + offset);

                tool.AddVertex(new Vector3(-BlockSize, -BlockSize, BlockSize) + offset);
                tool.AddVertex(new Vector3(-BlockSize, -BlockSize, -BlockSize) + offset);
                tool.AddVertex(new Vector3(BlockSize, -BlockSize, -BlockSize) + offset);
            }
            if (freeSides[2])
            {
                tool.AddVertex(new Vector3(BlockSize, -BlockSize, -BlockSize) + offset);
                tool.AddVertex(new Vector3(BlockSize, -BlockSize, BlockSize) + offset);
                tool.AddVertex(new Vector3(BlockSize, BlockSize, BlockSize) + offset);

                tool.AddVertex(new Vector3(BlockSize, BlockSize, BlockSize) + offset);
                tool.AddVertex(new Vector3(BlockSize, BlockSize, -BlockSize) + offset);
                tool.AddVertex(new Vector3(BlockSize, -BlockSize, -BlockSize) + offset);
            }
            if (freeSides[3])
            {
                tool.AddVertex(new Vector3(-BlockSize, -BlockSize, -BlockSize) + offset);
                tool.AddVertex(new Vector3(-BlockSize, -BlockSize, BlockSize) + offset);
                tool.AddVertex(new Vector3(-BlockSize, BlockSize, BlockSize) + offset);

                tool.AddVertex(new Vector3(-BlockSize, BlockSize, BlockSize) + offset);
                tool.AddVertex(new Vector3(-BlockSize, BlockSize, -BlockSize) + offset);
                tool.AddVertex(new Vector3(-BlockSize, -BlockSize, -BlockSize) + offset);
            }
            if (freeSides[4])
            {
                tool.AddVertex(new Vector3(BlockSize, -BlockSize, -BlockSize) + offset);
                tool.AddVertex(new Vector3(BlockSize, BlockSize, -BlockSize) + offset);
                tool.AddVertex(new Vector3(-BlockSize, BlockSize, -BlockSize) + offset);

                tool.AddVertex(new Vector3(-BlockSize, BlockSize, -BlockSize) + offset);
                tool.AddVertex(new Vector3(-BlockSize, -BlockSize, -BlockSize) + offset);
                tool.AddVertex(new Vector3(BlockSize, -BlockSize, -BlockSize) + offset);
            }
            if (freeSides[5])
            {
                tool.AddVertex(new Vector3(BlockSize, -BlockSize, BlockSize) + offset);
                tool.AddVertex(new Vector3(-BlockSize, -BlockSize, BlockSize) + offset);
                tool.AddVertex(new Vector3(-BlockSize, BlockSize, BlockSize) + offset);

                tool.AddVertex(new Vector3(-BlockSize, BlockSize, BlockSize) + offset);
                tool.AddVertex(new Vector3(BlockSize, BlockSize, BlockSize) + offset);
                tool.AddVertex(new Vector3(BlockSize, -BlockSize, BlockSize) + offset);
            }
        }
Exemplo n.º 30
0
 /// <summary>
 /// Adds a vertex to the mesh being drawn.
 /// </summary>
 /// <param name="vertex">Vector3 object of the vertex.</param>
 public void AddVertex(RR_Godot.Core.Geometry.Vector3Cp vertex)
 {
     Surface.AddVertex(new Godot.Vector3(vertex.x, vertex.y, vertex.z));
 }