示例#1
0
        /*
         *      public static VoxelMeshData LoadFromCache(string key){
         *
         *
         *              VoxelMeshData data = null;
         *              if (Cache.HasKey (key)) {
         *                      string json = Encoding.UTF8.GetString(ZipFile.Decompressed((Cache.GetBytes (key))));
         *                      data = JsonUtility.FromJson<VoxelMeshData> (json);
         *              }
         *
         *              return data;
         *      }*/
        /*
         *      public static void SaveToCache(string key, VoxelMeshData data){
         *              string json = JsonUtility.ToJson (data);
         *              GDGeek.Cache.SetBytes (key, GDGeek.ZipFile.Compression(Encoding.UTF8.GetBytes(json)));
         *              //GK7Zip.SetToFile (key, JsonUtility.ToJson(data));
         *              //JsonUtility.ToJson(data)
         *      }*/
        /*
         *      public static VoxelMeshData Struct2DataInCache(VoxelStruct vs){
         *
         *
         *              Debug.Log ("!!!!");
         *              string md5 = MagicaVoxelFormater.GetMd5 (vs);
         *              VoxelMeshData data = LoadFromCache (GetKey(md5));
         *
         *              if(data == null){
         *
         *                      Debug.Log ("???");
         *                      data =  VoxelBuilder.Struct2Data(vs);
         *                      SaveToCache (GetKey(md5), data);
         *              }
         *              return data;
         *
         *
         * }*/
        public static MeshFilter Struct2Filter(VoxelStruct vs)
        {
            var data   = VoxelBuilder.Struct2Data(vs);
            var mesh   = VoxelBuilder.Data2Mesh(data);
            var filter = VoxelBuilder.Mesh2Filter(mesh);

            return(filter);
        }
示例#2
0
        public static VoxelMeshData Struct2DataInCache(VoxelStruct vs)
        {
            string        md5  = MagicaVoxelFormater.GetMd5(vs);
            VoxelMeshData data = LoadFromCache(GetKey(md5));

            if (data == null)
            {
                data = VoxelBuilder.Struct2Data(vs);
                SaveToCache(GetKey(md5), data);
            }
            return(data);
        }
示例#3
0
        public static VoxelGeometry.MeshData Struct2DataInCache(VoxelStruct vs)
        {
            return(VoxelBuilder.Struct2Data(vs));

            /*
             *          string md5 = MagicaVoxelFormater.GetMd5 (vs);
             *          VoxelGeometry.MeshData data = VoxelDirectorFile.LoadFromFile (VoxelDirectorFile.GetKey(md5));
             *
             *          if(data == null){
             *                  data = VoxelBuilder.Struct2Data (vs);
             *                  VoxelDirectorFile.SaveToFile (VoxelDirectorFile.GetKey(md5), data);
             *          }
             *          return data;
             */
        }
示例#4
0
        public static GameObject Building(GameObject obj, System.IO.BinaryReader br, Material material, int reversal = 0)
        {
            MagicaVoxel magica = MagicaVoxelFormater.ReadFromBinary(br);
            VoxelStruct vs     = VoxelStruct.Reversal(magica.vs, reversal); // VoxelBuilder.Reversal(magica.vs, reversal);
            var         data   = VoxelBuilder.Struct2Data(vs);              // VoxelBuilderHelper.Struct2DataInCache (vs);
            var         mesh   = VoxelBuilder.Data2Mesh(data);
            var         filter = VoxelBuilder.Mesh2Filter(mesh);

            VoxelBuilder.FilterAddRenderer(filter, material);


            filter.transform.SetParent(obj.transform);
            filter.transform.localEulerAngles = Vector3.zero;
            filter.transform.localPosition    = data.offset;
            filter.gameObject.layer           = obj.layer;
            filter.name = "Voxel";
            return(filter.gameObject);
        }
示例#5
0
 // Update is called once per frame
 void Update()
 {
     if (_building == true && _voxFile != null)
     {
         init();
         if (_voxFile != null)
         {
             var vs     = MagicaVoxelFormater.ReadFromFile(_voxFile).vs;
             var data   = VoxelBuilder.Struct2Data(vs);
             var mesh   = VoxelBuilder.Data2Mesh(data);
             var filter = VoxelBuilder.Mesh2Filter(mesh);
             VoxelBuilder.FilterAddRenderer(filter, this._material);
             filter.transform.SetParent(this.transform);
             filter.transform.localEulerAngles = Vector3.zero;
             filter.transform.localPosition    = data.offset;
             filter.gameObject.layer           = this.gameObject.layer;
             filter.name = "Voxel";
         }
         _building = false;
     }
 }