Ejemplo n.º 1
0
        private void updateVerticesAndTriangleOfProduct(VoxelProduct.Product main)
        {
            List <VoxelDrawData.Vertice> temp_draw_vertices = new List <VoxelDrawData.Vertice>();
            List <Triangle>       temp_triangles_list       = new List <Triangle>();
            Dictionary <int, int> id_to_vertex_index        = new Dictionary <int, int>();

            for (int i = 0, vertices_count = vertices.Count; i < vertices_count; ++i)
            {
                temp_draw_vertices.Add(main.draw.vertices[vertices[i].id]);
                id_to_vertex_index[vertices[i].id] = i;
                for (int j = 0, faces_count = vertices[i].adjacent_faces.Count; j < faces_count; ++j)
                {
                    temp_triangles_list.Add(vertices[i].adjacent_faces[j]);
                }
            }
            main.draw.vertices = temp_draw_vertices;

            distinct(temp_triangles_list);
            List <int> triangles = new List <int>();

            for (int i = 0, faces_count = temp_triangles_list.Count; i < faces_count; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    triangles.Add(id_to_vertex_index[temp_triangles_list[i].triangle_vertices[j].id]);
                }
            }
            main.draw.triangles = triangles;
        }
Ejemplo n.º 2
0
 public void build(VoxelProduct.Product main)
 {
     vertices = new List <Vertex>();
     initVertices(main.draw);
     removeFaces();
     updateVerticesAndTriangleOfProduct(main);
 }
Ejemplo n.º 3
0
        public void build(VoxelProduct product)
        {
            Dictionary <VectorInt3, Dictionary <VectorInt3, VoxelHandler> > dict = new Dictionary <VectorInt3, Dictionary <VectorInt3, VoxelHandler> >();

            foreach (var kv in product.main.voxels)
            {
                VectorInt3 offset = new VectorInt3();
                offset.x = kv.Key.x / box_.x;
                offset.y = kv.Key.y / box_.y;
                offset.z = kv.Key.z / box_.z;
                if (!dict.ContainsKey(offset))
                {
                    dict [offset] = new Dictionary <VectorInt3, VoxelHandler> ();
                }
                dict [offset].Add(kv.Key, kv.Value);
            }
            List <VoxelProduct.Product> list = new List <VoxelProduct.Product>();

            foreach (var o in dict)
            {
                var p = new VoxelProduct.Product();
                p.voxels = o.Value;
                list.Add(p);
            }
            product.sub = list.ToArray();
        }
Ejemplo n.º 4
0
 private void addVertix(VoxelProduct.Product main, Vector3 p, Color c, Vector3 normal)
 {
     VoxelDrawData.Vertice v = new VoxelDrawData.Vertice();
     v.position = p;
     v.normal   = normal;
     v.color    = c;
     main.draw.vertices.Add(v);
 }
Ejemplo n.º 5
0
 public void build(VoxelProduct.Product main, Dictionary <Vector3Int, VoxelHandler> all)
 {
     main.draw = new VoxelDrawData();
     for (int i = 0; i < main.voxels.Count; i += 1000)
     {
         build(main, i, Mathf.Min(i + 1000, main.voxels.Count), main.voxels, all);
     }
 }
Ejemplo n.º 6
0
        static public Task Task(VoxelRemoveFace rsv, VoxelProduct.Product main)
        {
            Task task = new Task();

            TaskManager.PushFront(task, delegate {
                rsv.build(main);
            });
            return(task);
        }
Ejemplo n.º 7
0
        static public Task Task(VoxelMeshBuild vmb, VoxelProduct.Product main, Dictionary <Vector3Int, VoxelHandler> all)
        {
            Task task = new Task();

            TaskManager.PushFront(task, delegate {
                vmb.build(main, all);
            });


            return(task);
        }
Ejemplo n.º 8
0
        private void build(VoxelProduct.Product main, int from, int to, Dictionary <Vector3Int, VoxelHandler> voxs, Dictionary <Vector3Int, VoxelHandler> all)
        {
            List <Vector3Int> keys = new List <Vector3Int> (voxs.Keys);

            for (int i = from; i < to; ++i)
            {
                Vector3Int key = keys [i];

                VoxelHandler value = voxs [key];
                if (!all.ContainsKey(key + new Vector3Int(0, 0, -1)))
                {
                    addRect(main, Vector3.back, key, value.color);
                }

                if (!all.ContainsKey(key + new Vector3Int(0, 0, 1)))
                {
                    addRect(main, Vector3.forward, key, value.color);
                }

                if (!all.ContainsKey(key + new Vector3Int(0, 1, 0)))
                {
                    addRect(main, Vector3.up, key, value.color);
                }


                if (!all.ContainsKey(key + new Vector3Int(0, -1, 0)))
                {
                    addRect(main, Vector3.down, key, value.color);
                }


                if (!all.ContainsKey(key + new Vector3Int(1, 0, 0)))
                {
                    addRect(main, Vector3.left, key, value.color);
                }


                if (!all.ContainsKey(key + new Vector3Int(-1, 0, 0)))
                {
                    addRect(main, Vector3.right, key, value.color);
                }
            }
        }
Ejemplo n.º 9
0
        public void build(VoxelProduct product)
        {
            VoxelProduct.Product[] sub  = product.sub;
            VoxelProduct.Product   main = new VoxelProduct.Product();
            main.draw = new VoxelDrawData();
            main.draw.vertices.Clear();
            main.draw.triangles.Clear();

            for (int i = 0; i < sub.Length; ++i)
            {
                int offset = main.draw.vertices.Count;
                for (int j = 0; j < sub [i].draw.vertices.Count; ++j)
                {
                    main.draw.vertices.Add(sub [i].draw.vertices[j]);
                }

                for (int n = 0; n < sub [i].draw.triangles.Count; ++n)
                {
                    main.draw.triangles.Add(sub [i].draw.triangles[n] + offset);
                }
            }
            product.sub  = null;
            product.main = main;
        }
Ejemplo n.º 10
0
        private void addRect(VoxelProduct.Product main, Vector3 direction, Vector3Int position, Color color)
        {
            Vector3 offset = new Vector3(position.x, position.y, position.z);

            main.draw.triangles.Add(main.draw.vertices.Count + 0);
            main.draw.triangles.Add(main.draw.vertices.Count + 1);
            main.draw.triangles.Add(main.draw.vertices.Count + 2);
            main.draw.triangles.Add(main.draw.vertices.Count + 1);
            main.draw.triangles.Add(main.draw.vertices.Count + 3);
            main.draw.triangles.Add(main.draw.vertices.Count + 2);



            Vector3 p0 = new Vector3();             //
            Vector3 p1 = new Vector3();             //
            Vector3 p2 = new Vector3();             //
            Vector3 p3 = new Vector3();             //

            if (direction == Vector3.up)
            {
                p0 = (new Vector3(-0.5f, 0.5f, 0.5f) + offset);
                p1 = (new Vector3(0.5f, 0.5f, 0.5f) + offset);
                p2 = (new Vector3(-0.5f, 0.5f, -0.5f) + offset);
                p3 = (new Vector3(0.5f, 0.5f, -0.5f) + offset);
            }
            if (direction == Vector3.down)
            {
                p0 = (new Vector3(-0.5f, -0.5f, -0.5f) + offset);
                p1 = (new Vector3(0.5f, -0.5f, -0.5f) + offset);
                p2 = (new Vector3(-0.5f, -0.5f, 0.5f) + offset);
                p3 = (new Vector3(0.5f, -0.5f, 0.5f) + offset);
            }
            else if (direction == Vector3.back)
            {
                p0 = (new Vector3(-0.5f, 0.5f, -0.5f) + offset);
                p1 = (new Vector3(0.5f, 0.5f, -0.5f) + offset);
                p2 = (new Vector3(-0.5f, -0.5f, -0.5f) + offset);
                p3 = (new Vector3(0.5f, -0.5f, -0.5f) + offset);
            }
            else if (direction == Vector3.forward)
            {
                p0 = (new Vector3(-0.5f, -0.5f, 0.5f) + offset);
                p1 = (new Vector3(0.5f, -0.5f, 0.5f) + offset);
                p2 = (new Vector3(-0.5f, 0.5f, 0.5f) + offset);
                p3 = (new Vector3(0.5f, 0.5f, 0.5f) + offset);
            }
            else if (direction == Vector3.left)
            {
                p0 = (new Vector3(0.5f, -0.5f, 0.5f) + offset);
                p1 = (new Vector3(0.5f, -0.5f, -0.5f) + offset);
                p2 = (new Vector3(0.5f, 0.5f, 0.5f) + offset);
                p3 = (new Vector3(0.5f, 0.5f, -0.5f) + offset);
            }
            else if (direction == Vector3.right)
            {
                p0 = (new Vector3(-0.5f, -0.5f, -0.5f) + offset);
                p1 = (new Vector3(-0.5f, -0.5f, 0.5f) + offset);
                p2 = (new Vector3(-0.5f, 0.5f, -0.5f) + offset);
                p3 = (new Vector3(-0.5f, 0.5f, 0.5f) + offset);
            }

            this.addVertix(main, p0, color, direction.normalized);
            this.addVertix(main, p1, color, direction.normalized);
            this.addVertix(main, p2, color, direction.normalized);
            this.addVertix(main, p3, color, direction.normalized);
        }
Ejemplo n.º 11
0
        public void build(VoxelProduct.Product main)
        {
            var draw = main.draw;

            List <VoxelDrawData.Vertice> vertices = draw.vertices;

            List <int> triangles = draw.triangles;

            List <VoxelDrawData.Vertice> tVertices = new List <VoxelDrawData.Vertice>();


            Dictionary <Vector3, Pack> board = new Dictionary <Vector3, Pack>();
            List <Pack> temp = new List <Pack> ();

            List <int>            tTriangles = new List <int>();
            Dictionary <int, int> ht         = new Dictionary <int, int>();


            List <Pack> all = new List <Pack> ();

            for (int i = 0; i < vertices.Count; ++i)
            {
                all.Add(new Pack(i, vertices [i]));
            }

            while (all.Count != 0)
            {
                for (int i = 0; i < all.Count; ++i)
                {
                    if (board.ContainsKey(all [i].vertice.position))
                    {
                        Pack ver = board [all[i].vertice.position];

                        if (ver.vertice.color != all [i].vertice.color || ver.vertice.normal != all [i].vertice.normal)
                        {
                            temp.Add(all [i]);
                        }
                        else
                        {
                            ht [all [i].index] = ht[ver.index];
                        }
                    }
                    else
                    {
                        board [all [i].vertice.position] = all[i];
                        tVertices.Add(all[i].vertice);
                        ht [all [i].index] = tVertices.Count - 1;
                    }
                }

                board.Clear();

                all = temp;


                temp = new List <Pack> ();
            }

            for (int i = 0; i < triangles.Count; ++i)
            {
                int oldIndex = triangles[i];
                int newIndex = ht[oldIndex];
                tTriangles.Add(newIndex);
            }

            main.draw.triangles = tTriangles;
            main.draw.vertices  = tVertices;
        }