Exemplo n.º 1
0
        public static MeshFilter Data2Filter(VoxelGeometry.MeshData data)
        {
            var mesh   = VoxelBuilder.Data2Mesh(data);
            var filter = VoxelBuilder.Mesh2Filter(mesh);

            return(filter);
        }
Exemplo n.º 2
0
        public Task buildTask(string name, VoxelStruct vs, GeometryResult cb)
        {
            VoxelGeometry.MeshData data = null;
            TaskPack tp = new TaskPack(delegate(){
                vs.arrange();
                string md5 = VoxelFormater.GetMd5(vs);
                data       = this.LoadFromFile(GetKey(md5));
                if (data == null)
                {
                    return(buildData(vs, delegate(VoxelGeometry.MeshData result) {
                        data = result;
//						Debug.Log(md5);

                        this.SaveToFile(GetKey(md5), data);
                    }));
                }
                return(new Task());
            });


            TaskManager.PushBack(tp, delegate {
                if (this.gameObject.GetComponent <VoxelMesh>() == null)
                {
                    this.gameObject.AddComponent <VoxelMesh>();
                }
                VoxelMesh mesh = VoxelGeometry.Draw(name, data, this.gameObject, this._material);
                mesh.vs        = vs;
                cb(mesh);
            });
            return(tp);
        }
Exemplo n.º 3
0
 private void readVoxFile(TextAsset voxFile)
 {
     vs_ = createStruct(voxFile);
     vs_.arrange();
     this._md5            = VoxelFormater.GetMd5(vs_);
     this.data_           = createMeshData(this._md5);
     this.gameObject.name = voxFile.name;
 }
Exemplo n.º 4
0
        public static void SaveToFile(string key, VoxelGeometry.MeshData data)
        {
            GK7Zip.SetToFile(key, JsonUtility.ToJson(data));

            /*var json = JsonUtility.ToJson(data);
             * var zip = GK7Zip.Compression (json);
             * PlayerPrefs.SetString (key,zip);
             * PlayerPrefs.Save ();*/
        }
Exemplo n.º 5
0
        public VoxelMesh draw(string name, VoxelStruct vs, VoxelGeometry.MeshData data, GameObject obj = null)
        {
            if (obj == null)
            {
                obj = this.gameObject;
            }
            VoxelMesh mesh = VoxelGeometry.Draw(name, data, obj, this._material);

            mesh.vs = vs;
            return(mesh);
        }
Exemplo n.º 6
0
        public static VoxelGeometry.MeshData LoadFromFile(string key)
        {
            VoxelGeometry.MeshData data = null;
            if (GK7Zip.FileHas(key))
            {
                var json = GK7Zip.GetFromFile(key);
                data = JsonUtility.FromJson <VoxelGeometry.MeshData> (json);
            }

            return(data);
        }
Exemplo n.º 7
0
        public VoxelMesh build(VoxelStruct vs, GameObject obj = null)
        {
            //VoxelData[] datas = vs.datas.ToArray ();
            if (obj == null)
            {
                obj = this.gameObject;
            }
            VoxelGeometry.MeshData data = BuildMeshData(vs);
            VoxelMesh mesh = VoxelGeometry.Draw("Mesh", data, obj, this._material);

            mesh.vs = vs;
            return(mesh);
        }
Exemplo n.º 8
0
        public static VoxelGeometry.MeshData BuildMeshData(VoxelStruct vs)
        {
            vs.arrange();
            string md5 = VoxelFormater.GetMd5(vs);

            VoxelGeometry.MeshData data = LoadFromFile(GetKey(md5));
            if (data == null)
            {
                data = CreateMeshData(vs);
                SaveToFile(GetKey(md5), data);
            }
            return(data);
        }
Exemplo n.º 9
0
        public static Mesh Data2Mesh(VoxelGeometry.MeshData data)         //创建mesh
        {
            Mesh mesh = new Mesh();

            mesh.name = "ScriptedMesh";
            mesh.SetVertices(data.vertices);
            mesh.SetColors(data.colors);

            mesh.SetUVs(0, data.uvs);
            mesh.SetTriangles(data.triangles, 0);
            mesh.RecalculateNormals();

            return(mesh);
        }
Exemplo n.º 10
0
        public override VoxelGeometry.MeshData filter(VoxelGeometry.MeshData data)
        {
            VoxelGeometry.MeshData clone = (VoxelGeometry.MeshData)data.Clone();
            for (int i = 0; i < clone.colors.Count; ++i)
            {
                Color   c  = clone.colors [i];
                Vector2 uv = Vector2.zero;

                uv.x = 1.0f;

                clone.uvs [i] = uv;
            }
            return(clone);
        }
Exemplo n.º 11
0
        public VoxelGeometry.MeshData createMeshData(string md5)
        {
            string key = VoxelDirector.GetKey(md5);

            VoxelGeometry.MeshData data = null;
            if (!GK7Zip.FileHas(key))
            {
                data = VoxelDirector.CreateMeshData(this.voxel);
                VoxelDirector.SaveToFile(key, data);
            }
            else
            {
                data = VoxelDirector.LoadFromFile(key);
            }
            return(data);
        }
Exemplo n.º 12
0
        public VoxelGeometry.MeshData getMeshData()
        {
            if (data_ == null)
            {
                data_ = new VoxelGeometry.MeshData();
            }

            data_.max = this.max;
            data_.min = this.min;
            //Debug.Log ("!!!!!!");
            if (this.sub != null)
            {
                List <int> triangles = new List <int>();
                for (int i = 0; i < this.sub.Length; ++i)
                {
                    int offset = data_.vertices.Count;


                    for (int j = 0; j < this.sub [i].draw.vertices.Count; ++j)
                    {
                        data_.addPoint(this.sub [i].draw.vertices [j].position, this.sub [i].draw.vertices [j].color);
                        //data_.colors.Add (this.sub [i].draw.vertices [j].color);
                        //data_.vertices.Add (this.sub [i].draw.vertices [j].position);
                    }

                    for (int n = 0; n < this.sub [i].draw.triangles.Count; ++n)
                    {
                        data_.triangles.Add(this.sub [i].draw.triangles[n] + offset);
                    }
                }
            }
            else
            {
                for (int i = 0; i < main.draw.vertices.Count; ++i)
                {
                    data_.addPoint(main.draw.vertices [i].position, main.draw.vertices [i].color);
                    //	data_.vertices.Add (main.draw.vertices [i].position);
                    //data_.colors.Add (main.draw.vertices [i].color);
                }
                data_.triangles = main.draw.triangles;
            }

            return(data_);
        }
Exemplo n.º 13
0
        public static VoxelGeometry.MeshData CreateData(string md5, VoxelStruct vs)
        {
            string key = VoxelDirector.GetKey(md5);

            VoxelGeometry.MeshData data = null;
            if (!GK7Zip.FileHas(key))
            {
                if (vs == null)
                {
                    return(null);
                }
                data = VoxelDirector.CreateMeshData(vs);
                VoxelDirector.SaveToFile(key, data);
            }
            else
            {
                data = VoxelDirector.LoadFromFile(key);
            }
            return(data);
        }
Exemplo n.º 14
0
        public VoxelGeometry.MeshData getMeshData()
        {
            if (data_ == null)
            {
                data_ = new VoxelGeometry.MeshData();
            }

            data_.max = this.max;
            data_.min = this.min;

            for (int i = 0; i < main.draw.vertices.Count; ++i)
            {
                data_.vertices.Add(main.draw.vertices [i].position);
                data_.colors.Add(main.draw.vertices [i].color);
            }
            //data_.triangles = main.draw.triangles;

            for (int i = 0; i < main.draw.triangles.Count; i += 3)
            {
                int     n0     = main.draw.triangles[i];
                int     n1     = main.draw.triangles[i + 1];
                int     n2     = main.draw.triangles[i + 2];
                Vector3 v0     = data_.vertices [n0];
                Vector3 v1     = data_.vertices [n1];
                Vector3 v2     = data_.vertices [n2];
                Vector3 normal = Vector3.Cross((v1 - v0), (v2 - v1)).normalized;
                if (normal != Vector3.zero)
                {
                    data_.triangles.Add(n0);
                    data_.triangles.Add(n1);
                    data_.triangles.Add(n2);
                }
            }


            return(data_);
        }
Exemplo n.º 15
0
 public virtual VoxelGeometry.MeshData filter(VoxelGeometry.MeshData data)
 {
     return((VoxelGeometry.MeshData)(data.Clone()));
 }