Esempio n. 1
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();
        }
Esempio n. 2
0
        private void updateVerticesAndTriangleOfProduct(VoxelProduct product)
        {
            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(product.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]);
                }
            }
            product.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]);
                }
            }
            product.draw.triangles = triangles;
        }
Esempio n. 3
0
        public void build(VoxelProduct product)
        {
            product.min    = new Vector3(999, 999, 999);
            product.max    = new Vector3(-999, -999, -999);
            product.voxels = new Dictionary <VectorInt3, VoxelHandler>();

//			Debug.Log (product.voxels.Count);
            for (int i = 0; i < data_.Length; ++i)
            {
                VoxelData d = data_ [i];
                product.min.x = Mathf.Min(product.min.x, d.pos.x);
                product.min.y = Mathf.Min(product.min.y, d.pos.y);
                product.min.z = Mathf.Min(product.min.z, d.pos.z);
                product.max.x = Mathf.Max(product.max.x, d.pos.x);
                product.max.y = Mathf.Max(product.max.y, d.pos.y);
                product.max.z = Mathf.Max(product.max.z, d.pos.z);
            }
            for (int i = 0; i < data_.Length; ++i)
            {
                VoxelHandler handler = data2Handler(data_[i]);
                if (product.voxels.ContainsKey(handler.position))
                {
                    Debug.Log(data_.Length);
                    Debug.Log(handler.position.x + ":" + handler.position.y + ":" + handler.position.z);
                }
                product.voxels.Add(handler.position, handler);
            }
        }
Esempio n. 4
0
        public void build(VoxelProduct product)
        {
            product.min         = new Vector3(999, 999, 999);
            product.max         = new Vector3(-999, -999, -999);
            product.main.voxels = new Dictionary <VectorInt3, VoxelHandler>();

//			Debug.Log (product.main.voxels.Count);
            for (int i = 0; i < data_.Length; ++i)
            {
                VoxelData d   = data_ [i];
                var       min = product.min;
                var       max = product.max;

                min.x = Mathf.Min(min.x, d.pos.x);
                min.y = Mathf.Min(min.y, d.pos.y);
                min.z = Mathf.Min(min.z, d.pos.z);
                max.x = Mathf.Max(max.x, d.pos.x);
                max.y = Mathf.Max(max.y, d.pos.y);
                max.z = Mathf.Max(max.z, d.pos.z);


                product.min = min;
                product.max = max;
            }
            for (int i = 0; i < data_.Length; ++i)
            {
                VoxelHandler handler = data2Handler(data_[i]);

                product.main.voxels.Add(handler.position, handler);
            }
        }
Esempio n. 5
0
        private Task task_(string name, VoxelData[] datas, GeometryResult cb)
        {
            if (list_.Count == 0)
            {
                init();
            }

            VoxelProduct product = new VoxelProduct();

            begin_.setup(datas);

            TaskList tl = new TaskList();


            tl.push(begin_.task(product));
            for (int i = 0; i < list_.Count; ++i)
            {
                tl.push(list_[i].task(product));
            }

            TaskManager.PushBack(tl, delegate {
                VoxelGeometry geometry = new VoxelGeometry();
                geometry.draw(name, product, this.gameObject, this._material);;
                cb(geometry);
            });
            return(tl);
        }
Esempio n. 6
0
        public VoxelGeometry build(VoxelData[] datas, GameObject obj = null)
        {
            if (obj == null)
            {
                obj = this.gameObject;
            }

            VoxelProduct product = new VoxelProduct();

            begin_.init();
            begin_.setup(datas);
            begin_.build(product);


            for (int i = 0; i < list_.Count; ++i)
            {
                list_ [i].init();
                list_[i].build(product);
            }



            VoxelGeometry geometry = new VoxelGeometry();

            geometry.draw("Mesh", product, obj, this._material);
            return(geometry);
        }
Esempio n. 7
0
        public Task task(VoxelProduct product)
        {
            Task task = new Task();

            TaskManager.PushFront(task, delegate {
                build(product);
            });
            return(task);
        }
Esempio n. 8
0
        static public Task Task(VoxelRemoveSameVertices rsv, VoxelProduct product)
        {
            Task task = new Task();

            TaskManager.PushFront(task, delegate {
                rsv.build(product);
            });
            return(task);
        }
Esempio n. 9
0
        /*private Task removeFacesTask(){
         *      Task task = new Task ();
         *      task.init = delegate {
         *              removeFaces();
         *      };
         *      return task;
         * }*/
        private Task updateVerticesAndTriangleOfProductTask(VoxelProduct product)
        {
            Task task = new Task();

            task.init = delegate {
                updateVerticesAndTriangleOfProduct(product);
            };
            return(task);
        }
Esempio n. 10
0
        static public Task Task(VoxelSplitSmall vss, VoxelProduct product)
        {
            Task task = new Task();

            TaskManager.PushFront(task, delegate {
                Build.Run(vss, product);
            });
            return(task);
        }
Esempio n. 11
0
        static public Task Task(VoxelData2Point d2p, VoxelProduct product)
        {
            Task task = new Task();

            TaskManager.PushFront(task, delegate {
                Build.Run(d2p, product);
            });
            return(task);
        }
Esempio n. 12
0
        public Task task(VoxelProduct product)
        {
            Task task = new Task();

            task.init = delegate {
                build(product);
            };
            return(task);
        }
Esempio n. 13
0
        private Task task_(VoxelProduct product)
        {
            TaskList tl = new TaskList();

            tl.push(TaskLog.Logger(initVerticesTask(product.draw), "init_vertices"));
            tl.push(TaskLog.Logger(removeFacesTask(), "remove_face"));
            tl.push(TaskLog.Logger(updateVerticesAndTriangleOfProductTask(product), "update_vertices"));

            return(tl);
        }
Esempio n. 14
0
        public void build(VoxelProduct product)
        {
            this.product_ = product;
            product_.draw = new VoxelDrawData();

            for (int i = 0; i < product.voxels.Count; i += 1000)
            {
                build(i, Mathf.Min(i + 1000, product.voxels.Count), product.voxels);
            }
        }
        public void build2(VoxelProduct product)
        {
            draw_ = product.draw;

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

            //Debug.Log ("!@@" + vertices.Count);
            List <int> triangles = draw_.triangles;

            List <VoxelDrawData.Vertice> tVertices = new List <VoxelDrawData.Vertice>();
            List <int>            tTriangles       = new List <int>();
            Dictionary <int, int> ht = new Dictionary <int, int>();

            for (int i = 0; i < vertices.Count; ++i)
            {
                int index = tVertices.FindIndex(delegate(VoxelDrawData.Vertice v) {
                    if (v.position == vertices[i].position &&
                        v.color == vertices[i].color &&
                        v.normal == vertices[i].normal
                        )
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                });

                int newIndex = -1;
                int oldIndex = i;
                if (index == -1)
                {
                    newIndex = tVertices.Count;
                    tVertices.Add(vertices[i]);
                }
                else
                {
                    newIndex = index;
                }
                ht[oldIndex] = newIndex;
            }

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

            //	Debug.Log ("!@@" + tVertices.Count);
            product.draw.triangles = tTriangles;
            product.draw.vertices  = tVertices;
        }
Esempio n. 16
0
        public MeshFilter crateMeshFilter(VoxelProduct product, string name, Material material)
        {
            GameObject go         = new GameObject(name);
            MeshFilter meshFilter = go.AddComponent <MeshFilter>();

            meshFilter.mesh = createMesh(product);
            MeshRenderer renderer = go.AddComponent <MeshRenderer>();

            renderer.material = material;


            return(meshFilter);
        }
Esempio n. 17
0
 /**
  * do reduce faces number of product
  */
 public void build(VoxelProduct product)
 {
     if (product.sub != null)
     {
         for (int i = 0; i < product.sub.Length; ++i)
         {
             build(product.sub [i]);
         }
     }
     else
     {
         build(product.main);
     }
 }
Esempio n. 18
0
        public void draw(string name, VoxelProduct product, GameObject gameObject, Material material)
        {
            this._mesh = this.crateMeshFilter(product, name, material);
            this._mesh.gameObject.transform.SetParent(gameObject.transform);
            this._mesh.gameObject.transform.localPosition = Vector3.zero;
            this._mesh.gameObject.transform.localScale    = Vector3.one;
            this._mesh.gameObject.transform.localRotation = Quaternion.Euler(Vector3.zero);

            this._mesh.gameObject.SetActive(true);

            Renderer renderer = this._mesh.GetComponent <Renderer> ();

            renderer.material = material;
            refresh(product, gameObject);
        }
Esempio n. 19
0
        public static VoxelGeometry.MeshData CreateMeshData(VoxelStruct vs)
        {
            VoxelProduct product = new VoxelProduct();

            VoxelData[] datas = vs.datas.ToArray();
            Build.Run(new VoxelData2Point(datas), product);
            Build.Run(new VoxelSplitSmall(new VectorInt3(8, 8, 8)), product);
            Build.Run(new VoxelMeshBuild(), product);
            Build.Run(new VoxelRemoveSameVertices(), product);
            Build.Run(new VoxelRemoveFace(), product);

            var data = product.getMeshData();

            return(data);
        }
Esempio n. 20
0
		public void product(){
			VoxelProduct product = new VoxelProduct();
			Debug.Log ("!??!");
			VoxelData[] datas = VoxelBuilderThread.Instance.vs_.toArray ();
			Build.Run (new VoxelData2Point (datas), product);
			Build.Run (new VoxelSplitSmall (new Vector3Int(8, 8, 8)), product);
			Build.Run (new VoxelMeshBuild (), product);
			Build.Run (new VoxelRemoveSameVertices (), product);
			Build.Run (new VoxelRemoveFace (), product);
			Build.Run (new VoxelRemoveSameVertices (), product);
			Debug.Log ("!!!!");
			ret_ (product);
			//var data = product.getMeshData ();
			//VoxelBuilderThread.Instance.ret_ (data);
		
		}
Esempio n. 21
0
        public Task buildData(VoxelStruct vs, MeshDataResult result)
        {
            VoxelProduct product = new VoxelProduct();
            TaskList     tl      = new TaskList();

            VoxelData[] datas = vs.datas.ToArray();
            tl.push(TaskLog.Logger(Build.Task(new VoxelData2Point(datas), product), "d2p"));
            tl.push(TaskLog.Logger(Build.Task(new VoxelSplitSmall(new VectorInt3(8, 8, 8)), product), "vss"));
            tl.push(TaskLog.Logger(Build.Task(new VoxelMeshBuild(), product), "vmb"));             //43%
            tl.push(TaskLog.Logger(Build.Task(new VoxelRemoveSameVertices(), product), "vrv"));
            tl.push(TaskLog.Logger(Build.Task(new VoxelRemoveFace(), product), "vrf"));            //47%
            TaskManager.PushBack(tl, delegate {
                result(product.getMeshData());
            });
            return(tl);
        }
Esempio n. 22
0
        public static Task Struct2Data(VoxelStruct vs, Struct2DataReturn ret)
        {
            TaskList     tl      = new TaskList();
            VoxelProduct product = new VoxelProduct();

            VoxelData[] datas = vs.datas.ToArray();
            tl.push(Build.Task(new VoxelData2Point(datas), product));
            tl.push(Build.Task(new VoxelSplitSmall(new VectorInt3(8, 8, 8)), product));
            tl.push(Build.Task(new VoxelMeshBuild(), product));
            tl.push(Build.Task(new VoxelRemoveSameVertices(), product));
            tl.push(Build.Task(new VoxelRemoveFace(), product));
            tl.push(Build.Task(new VoxelRemoveSameVertices(), product));
            TaskManager.PushBack(tl, delegate {
                ret(product.getMeshData());
            });

            return(tl);
        }
Esempio n. 23
0
        private Mesh createMesh(VoxelProduct product)
        {
            Mesh m = new Mesh();

            m.name = "ScriptedMesh";


            product.draw.refresh();
            m.vertices = product.draw.postions;
            m.colors   = product.draw.colors;
            m.uv       = product.draw.uv1s;
            m.uv2      = product.draw.uv2s;

            m.triangles = product.draw.triangles.ToArray();
            m.RecalculateNormals();

            return(m);
        }
Esempio n. 24
0
        private Task _task(VoxelProduct product)
        {
//			Debug.Log ("****************");

            TaskList tl = new TaskList();

            TaskManager.PushFront(tl, delegate {
                //Debug.Log("!!!!!!");
                this.product_ = product;
                product_.draw = new VoxelDrawData();
            });


            for (int i = 0; i < product.voxels.Count; i += 1000)
            {
                tl.push(buildTask(i, Mathf.Min(i + 1000, product.voxels.Count), product.voxels));
            }

            return(tl);
        }
Esempio n. 25
0
        public void refresh(VoxelProduct product, GameObject gameObject)
        {
            Vector3 offset = Vector3.zero;
            Vector3 size   = new Vector3(product.max.x - product.min.x, product.max.z - product.min.z, product.max.y - product.min.y);

            offset = size / -2.0f - new Vector3(product.min.x, product.min.z, product.min.y);

            this._mesh.transform.localPosition = offset;

            if (_collider == null)
            {
                _collider = gameObject.GetComponent <BoxCollider>();
            }

            if (_collider == null)
            {
                _collider = gameObject.AddComponent <BoxCollider>();
            }
            _collider.size = size + Vector3.one;
        }
Esempio n. 26
0
        static public Task Task(VoxelRemoveFace vrf, VoxelProduct product)
        {
            TaskPack tp = new TaskPack(delegate() {
                if (product.sub != null)
                {
                    TaskList tl = new TaskList();
                    for (int i = 0; i < product.sub.Length; ++i)
                    {
                        tl.push(Build.Task(vrf, product.sub[i]));
                    }

                    return(tl);
                }
                else
                {
                    return(Build.Task(vrf, product.main));
                }
            });

            return(tp);
        }
Esempio n. 27
0
        static public Task Task(VoxelMeshBuild vmb, VoxelProduct product)
        {
            TaskPack tp = new TaskPack(delegate() {
                if (product.sub != null)
                {
                    TaskList tl = new TaskList();

                    for (int i = 0; i < product.sub.Length; ++i)
                    {
                        tl.push(Build.Task(vmb, product.sub[i], product.main.voxels));
                    }
                    return(tl);
                }
                else
                {
                    return(Build.Task(vmb, product.main, product.main.voxels));
                }
            });

            return(tp);
        }
Esempio n. 28
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;
        }
Esempio n. 29
0
 /**
  * do reduce faces number of product
  */
 public void build(VoxelProduct product)
 {
     initVertices(product.draw);
     removeFaces();
     updateVerticesAndTriangleOfProduct(product);
 }
Esempio n. 30
0
 public Task task(VoxelProduct product)
 {
     return(new TaskPack(delegate {
         return _task(product);
     }));
 }