Esempio n. 1
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. 2
0
		public void build (VoxelData[] datas)
		{
			if (empty) {

				this._product = new VoxelProduct();

				VoxelData2Point vd2p = new VoxelData2Point(datas);
				vd2p.build(this._product);

				VoxelShadowBuild vsb = new VoxelShadowBuild ();
				vsb.build(this._product);


				VoxelMeshBuild vmb = new VoxelMeshBuild ();
				vmb.build(this._product);

				VoxelRemoveSameVertices rsv = new VoxelRemoveSameVertices ();
				rsv.build(this._product);

				//VoxelRemoveFace vrf = new VoxelRemoveFace ();
				//vrf.build(this._product);

				/*
				VoxelRemoveFace vrf = new VoxelRemoveFace ();
				vrf.build(this._product);
				*/

				_geometry = new VoxelGeometry();
				_geometry.draw (this._product, this.gameObject, this._material);
			}

		}
Esempio n. 3
0
        //public List
        public Task task(string name, VoxelData[] datas, GeometryResult cb)
        {
            Task task = new TaskPack (delegate {
                return 	task_(name, datas, cb);
            });

            return task;
        }
Esempio n. 4
0
 private Task oneTask(Voxel vox, VoxelData to)
 {
     TaskSet task = new TaskSet ();
     TweenTask tt1 = new TweenTask(delegate {
         return TweenVoxel.Begin(vox, 1.0f, to, new Vector3(-1, -4, -0.5f));
     });
     task.push (tt1);
     return task;
 }
Esempio n. 5
0
 public VoxelMesh create(VoxelData[] data, VoxelFunctionManager vf)
 {
     VoxelMesh vm = _create();
     vm.build (data);
     if (vf != null) {
         vf.build(vm);
     }
     vm.showMesh();
     return vm;
 }
Esempio n. 6
0
		private VoxelHandler data2Handler (VoxelData data)
		{

			VoxelHandler handler = new VoxelHandler();

			handler.position = new VectorInt3(data.pos.x, data.pos.y, data.pos.z);
			handler.color = data.color;
			handler.id = data.id;

			return handler;

		}
Esempio n. 7
0
		public List<VoxelData> getDatas(){
			List<VoxelData> datas = new List<VoxelData>();
			int i = 0;
			foreach(KeyValuePair<VectorInt3, VoxelData> item in dictionary_){
				VoxelData data = new VoxelData ();
				data.color = item.Value.color;
				data.pos.x = item.Key.x;
				data.pos.y = item.Key.y;
				data.pos.z = item.Key.z;

				data.id = i;
				datas.Add (data);
				++i;
			}
			return datas;
		}
Esempio n. 8
0
        public void build(VoxelData[] datas)
        {
            if (empty) {

                createHandler(datas);

                if(_root != null){
                    for (int i=0; i<_datas.Length; ++i) {
                        VoxelHandler d = _datas[i];
                        this.createVoxel (_datas[i]);

                    }
                }
                this.shadowBuild ();
                this.buildMesh ();
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Start the tweening operation.
 /// </summary>
 //13801889517 zhou ping
 public static TweenVoxel Begin(Voxel vox, float duration, VoxelData to, Vector3 offset)
 {
     TweenVoxel comp = Tween.Begin<TweenVoxel>(vox.gameObject, duration);
     comp.from.localPosition = vox.gameObject.transform.localPosition;// = comp.alpha;
     comp.from.color = vox.color;
     comp.vox = vox;
     comp.to.localPosition.x = to.x + offset.x;//-1;
     comp.to.localPosition.y = to.y + offset.y;//-4;
     comp.to.localPosition.z = to.z + offset.z;//-0.5f;
     comp.to.color = to.color;
     //comp.to = alpha;
     /*
     if (duration <= 0f)
     {
         comp.Sample(1f, true);
         comp.enabled = false;
     }*/
     return comp;
 }
Esempio n. 10
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. 11
0
        public static VoxelData[] FromJsonData(VoxelJson jData)
        {
            VoxelData[] datas = new VoxelData[jData.vox.Length];
            for(int i = 0; i<jData.vox.Length; ++i){
                VoxelData data = new VoxelData();
                data.x = jData.vox[i].x;
                data.y = jData.vox[i].y;
                data.z = jData.vox[i].z;
                data.id = i;
                if(jData.rgba != null && jData.vox[i].c-1 < jData.rgba.Length){

                    data.color.r = (float)(jData.rgba[jData.vox[i].c-1].r)/255.0f;
                    data.color.g = (float)(jData.rgba[jData.vox[i].c-1].g)/255.0f;
                    data.color.b = (float)(jData.rgba[jData.vox[i].c-1].b)/255.0f;
                    data.color.a = (float)(jData.rgba[jData.vox[i].c-1].a)/255.0f;
                }else{

                    ushort c = voxColors[jData.vox[i].c - 1];
                    data.color.a = 1.0f;
                    data.color.r = (float)(c & 0x1f)/31.0f;
                    data.color.g = (float)(c >> 5 & 0x1f)/31.0f;
                    data.color.b = (float)(c >> 10 & 0x1f)/31.0f;

                    string co = "0x" + string.Format("{0,2:X2}", (int)((float)(c & 0x1f)/31.0f * 255.0f))
                        + string.Format("{0,2:X2}", (int)((float)(c >> 5 & 0x1f)/31.0f * 255.0f))
                            +string.Format("{0,2:X2}", (int)((float)(c >> 10 & 0x1f)/31.0f * 255.0f)) ;

                    Debug.Log (data.color.r.ToString() + co + "!" + jData.vox[i].c);

                }
                //_data.vox[i].c
                //data.color =
                datas[i] = data;
                //data.color =

            }
            return datas;
        }
Esempio n. 12
0
        private VoxelHandler data2Handler(VoxelData data)
        {
            VoxelHandler handler = new VoxelHandler();
            VectorInt3 position;
            if (_XReverse) {
                position.x = (int)this.max_.x - data.x + (int)this.min_.x;
            } else {
                position.x = data.x;
            }

            if (_YReverse) {
                position.y = (int)this.max_.y - data.y + (int)this.min_.y;
            } else {
                position.y = data.y;
            }

            if (_ZReverse) {
                position.z = (int)this.max_.z - data.z + (int)this.min_.z;
            } else {
                position.z = data.z;
            }
            handler.position = position;
            handler.color = data.color;
            handler.id = data.id;

            return handler;
        }
Esempio n. 13
0
        private void createHandler(VoxelData[] datas)
        {
            min_ = new Vector3(999, 999, 999);
            max_ = new Vector3(-999, -999, -999);

            _datas = new VoxelHandler[datas.Length];
            for (int i=0; i<datas.Length; ++i) {
                VoxelData d = datas [i];
                this.getMaxMin (d.x, d.y, d.z);
            }
            for (int i=0; i<datas.Length; ++i) {
                _datas[i] = data2Handler(datas [i]);
            }
        }
Esempio n. 14
0
 public void load(VoxelData[] to)
 {
     throw new System.NotImplementedException ();
 }
Esempio n. 15
0
 public void addData(VoxelData data)
 {
     datas_.Add(data);
 }
Esempio n. 16
0
        private static List<VoxelData> CreateVoxelDatas(Point[] points, VectorInt4[] palette)
        {
            //VoxelStruct vs = new VoxelStruct ();

            List<VoxelData> datas = new List<VoxelData>();

            for(int i=0; i < points.Length; ++i){
                VoxelData data = new VoxelData();
                data.pos.x = points[i].x;
                data.pos.y = points[i].y;
                data.pos.z = points[i].z;
                data.id = i;

                //ushort c =  (colors == null ? voxColors[voxelData[i].color - 1] : colors[voxelData[i].color - 1]);
                if(palette == null){

                    ushort c = palette_[points[i].i - 1];

                    data.color = Short2Color (c);

                }else{
                    VectorInt4 v = palette[points[i].i - 1];
                    data.color = Bytes2Color (v);;

                }

                datas.Add (data);
                //	Debug.Log( "r:" + (c >> 10 & 0x1f)+ ",g:"+ (float)(c >> 5 & 0x1f) + ",b:"+ (float)(c & 0x1f));
                //datas[i].cindex = voxelData[i].color;
            }

            return datas;
        }
Esempio n. 17
0
		public VoxelData2Point(VoxelData[] data){
			data_ = data;
		}
Esempio n. 18
0
        /*	public static Color ToColor(){

        }*/
        /// <summary>
        /// Load a MagicaVoxel .vox format file into the custom ushort[] structure that we use for voxel chunks.
        /// </summary>
        /// <param name="stream">An open BinaryReader stream that is the .vox file.</param>
        /// <param name="overrideColors">Optional color lookup table for converting RGB values into my internal engine color format.</param>
        /// <returns>The voxel chunk data for the MagicaVoxel .vox file.</returns>
        public static VoxelData[] _FromMagica(BinaryReader stream)
        {
            // check out http://voxel.codeplex.com/wikipage?title=VOX%20Format&referringTitle=Home for the file format used below
            // we're going to return a voxel chunk worth of data
            //ushort[] data = new ushort[32 * 128 * 32];
            Vector4[] colors = null;
            Data[] voxelData = null;

            string magic = new string(stream.ReadChars(4));
            int version = stream.ReadInt32();

            // a MagicaVoxel .vox file starts with a 'magic' 4 character 'VOX ' identifier
            if (magic == "VOX ")
            {
                int sizex = 0, sizey = 0, sizez = 0;
                bool subsample = false;

                while (stream.BaseStream.Position < stream.BaseStream.Length)
                {
                    // each chunk has an ID, size and child chunks
                    char[] chunkId = stream.ReadChars(4);
                    int chunkSize = stream.ReadInt32();
                    int childChunks = stream.ReadInt32();
                    string chunkName = new string(chunkId);

                    //				Debug.LogError (chunkName);
                    // there are only 2 chunks we only care about, and they are SIZE and XYZI
                    if (chunkName == "SIZE")
                    {
                        sizex = stream.ReadInt32();
                        sizey = stream.ReadInt32();
                        sizez = stream.ReadInt32();

                        if (sizex > 32 || sizey > 32) subsample = true;

                        stream.ReadBytes(chunkSize - 4 * 3);
                    }
                    else if (chunkName == "XYZI")
                    {
                        // XYZI contains n voxels
                        int numVoxels = stream.ReadInt32();
                        //int div = (subsample ? 2 : 1);

                        // each voxel has x, y, z and color index values
                        voxelData = new Data[numVoxels];
                        for (int i = 0; i < voxelData.Length; i++)
                            voxelData[i] = new Data(stream, subsample);
                    }
                    else if (chunkName == "RGBA")
                    {
                        colors = new Vector4[256];

                        for (int i = 0; i < 256; i++)
                        {
                            byte r = stream.ReadByte();
                            byte g = stream.ReadByte();
                            byte b = stream.ReadByte();
                            byte a = stream.ReadByte();
                            colors[i].x = r;
                            colors[i].y = g;
                            colors[i].z = b;
                            colors[i].w = a;
                        }
                    }
                    else stream.ReadBytes(chunkSize);   // read any excess bytes
                }

                VoxelData[] datas = new VoxelData[voxelData.Length];

                for(int i=0; i < voxelData.Length; ++i){
                    datas[i] = new VoxelData();
                    datas[i].x = voxelData[i].x;
                    datas[i].y = voxelData[i].y;
                    datas[i].z = voxelData[i].z;
                    datas[i].id = i;
                    //ushort c =  (colors == null ? voxColors[voxelData[i].color - 1] : colors[voxelData[i].color - 1]);
                    if(colors == null){

                        ushort c = voxColors[voxelData[i].color - 1];

                        datas[i].color.a = 1.0f;
                        datas[i].color.r = (float)(c & 0x1f)/31.0f;
                        datas[i].color.g = (float)(c >> 5 & 0x1f)/31.0f;
                        datas[i].color.b = (float)(c >> 10 & 0x1f)/31.0f;

                    }else{
                        Vector4 c = colors[voxelData[i].color - 1];
                        datas[i].color.r = (float)(c.x)/255.0f;
                        datas[i].color.g = (float)(c.y)/255.0f;
                        datas[i].color.b = (float)(c.z)/255.0f;
                        datas[i].color.a = (float)(c.w)/255.0f;

                        /* */
                    }

                    //	Debug.Log( "r:" + (c >> 10 & 0x1f)+ ",g:"+ (float)(c >> 5 & 0x1f) + ",b:"+ (float)(c & 0x1f));
                    //datas[i].cindex = voxelData[i].color;
                }

                return datas;

            }

            return null;
        }
Esempio n. 19
0
 public void setData(int n, VoxelData data)
 {
     datas_ [n] = data;
 }