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); }
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; }
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); }
/* public VectorInt4[] getPalette(){ int size = Mathf.Max (palette_.Count, 256); VectorInt4[] palette = new VectorInt4[size]; int i = 0; foreach (Color c in palette_) { palette [i] = VoxelFormater.Color2Bytes (c); ++i; } return palette; } */ //public public VoxelStruct doIt(){ this.clear (); for (int i = 0; i < list_.Count; ++i) { Packed p = this.list_ [i]; this.readIt(p); } VoxelStruct vs = new VoxelStruct(); /* vs.main = new VoxelStruct.Main (); vs.main.name = "MAIN"; vs.main.size = 0; vs.size = new VoxelStruct.Size (); vs.size.name = "SIZE"; vs.size.size = 12; vs.size.chunks = 0; vs.size.box = new VectorInt3 (); vs.size.box.x = this.max_.x - this.min_.x +1; vs.size.box.y = this.max_.y - this.min_.y +1; vs.size.box.z = this.max_.z - this.min_.z +1; vs.rgba = new VoxelStruct.Rgba ();//list_ [0].vs.rgba; vs.rgba.palette = this.getPalette (); vs.rgba.size = vs.rgba.palette.Length * 4; vs.rgba.name = "RGBA"; vs.rgba.chunks = 0; /**/ vs.datas = this.getDatas (); vs.arrange (true); /* Debug.Log (vs.datas.Count); vs.version = 150; vs.main.chunks = 52 + vs.rgba.palette.Length *4 + vs.datas.Count *4; Debug.Log (vs.main.chunks); */ return vs; }