コード例 #1
0
ファイル: SplitVoxel.cs プロジェクト: lzxkulou/GDGeek
        public VoxelStruct[] doIt()
        {
            VoxelStruct[] vs = new VoxelStruct[list_.Count];
            for (int i = 0; i < vs.Length; ++i)
            {
                vs [i] = new VoxelStruct();
            }

            for (int i = 0; i < vs_.count; ++i)
            {
                var data = vs_.getData(i);
                for (int j = 0; j < vs.Length; ++j)
                {
                    if (list_ [j].contain(data.position))
                    {
                        vs [j].addData(data);
                    }
                    /*//vs[j]*/
                }
            }
            //for (int i = 0; i < vs.Length; ++i) {
            //		vs [i].arrange(true);
            //	}
            return(vs);
        }
コード例 #2
0
        public static void WriteToBinary(VoxelStruct vs, System.IO.BinaryWriter bw)
        {
            bw.Write("VOX ".ToCharArray());
            MagicaVoxel magic = new MagicaVoxel(vs);

            bw.Write((int)magic.version);


            if (magic.main != null)
            {
                bw.Write(magic.main.name.ToCharArray());
                bw.Write((int)magic.main.size);
                bw.Write((int)magic.main.chunks);
            }

            if (magic.size != null)
            {
                bw.Write(magic.size.name.ToCharArray());
                bw.Write((int)magic.size.size);
                bw.Write((int)magic.size.chunks);
                bw.Write((int)magic.size.box.x);
                bw.Write((int)magic.size.box.y);
                bw.Write((int)magic.size.box.z);
            }


            if (magic.rgba != null && magic.rgba.palette != null)
            {
                int length = magic.rgba.palette.Length;
                bw.Write(magic.rgba.name.ToCharArray());
                bw.Write((int)(length * 4));
                bw.Write((int)magic.size.chunks);


                for (int i = 0; i < length; i++)
                {
                    VectorInt4 c = magic.rgba.palette [i];
                    bw.Write((byte)(c.x));
                    bw.Write((byte)(c.y));
                    bw.Write((byte)(c.z));
                    bw.Write((byte)(c.w));
                }
            }
            Point[] points = WritePoints(vs.datas, magic.rgba.palette);
            bw.Write("XYZI".ToCharArray());

            bw.Write((int)(points.Length * 4) + 4);
            bw.Write((int)0);

            bw.Write((int)points.Length);

            for (int i = 0; i < points.Length; ++i)
            {
                Point p = points[i];
                bw.Write((byte)(p.x));
                bw.Write((byte)(p.y));
                bw.Write((byte)(p.z));
                bw.Write((byte)(p.i));
            }
        }
コード例 #3
0
        public VoxelStruct[] doIt()
        {
            VoxelStruct[] vs = new VoxelStruct[list_.Count];
            for (int i = 0; i < vs.Length; ++i)
            {
                vs [i] = new VoxelStruct();
            }

            for (int i = 0; i < vs_.datas.Count; ++i)
            {
                for (int j = 0; j < vs.Length; ++j)
                {
                    if (list_ [j].contain(vs_.datas[i].pos))
                    {
                        vs [j].datas.Add(vs_.datas[i]);
                    }
                    /*//vs[j]*/
                }
            }
            for (int i = 0; i < vs.Length; ++i)
            {
                vs [i].arrange(true);
            }
            return(vs);
        }
コード例 #4
0
        public static VoxelNormal Normal(VoxelStruct st)
        {
            VoxelNormal normal = new VoxelNormal();
            VectorInt3  min    = new VectorInt3(9999, 9999, 9999);
            VectorInt3  max    = new VectorInt3(-9999, -9999, -9999);

            for (int i = 0; i < st.datas.Count; ++i)
            {
                VectorInt3 pos = st.datas [i].pos;
                min.x = Mathf.Min(pos.x, min.x);
                min.y = Mathf.Min(pos.y, min.y);
                min.z = Mathf.Min(pos.z, min.z);
                max.x = Mathf.Max(pos.x, max.x);
                max.y = Mathf.Max(pos.y, max.y);
                max.z = Mathf.Max(pos.z, max.z);
            }
            normal.vs = new VoxelStruct();
            for (int i = 0; i < st.datas.Count; ++i)
            {
                VoxelData data = st.datas [i];
                data.pos -= min;
                normal.vs.datas.Add(data);
            }

            normal.shifting = min;
            return(normal);
        }
コード例 #5
0
ファイル: JoinVoxel.cs プロジェクト: CzDreamer/eat
		public void addVoxel(VoxelStruct vs, VectorInt3 offset){
//			Debug.Log (offset.x +","+ offset.y+","+ offset.z);
			Packed packed = new Packed ();
			packed.vs = vs;
			packed.offset = offset;
			list_.Add (packed);
		}
コード例 #6
0
ファイル: VoxelDirector.cs プロジェクト: jack7Dgame/FirstVr
        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);
        }
コード例 #7
0
ファイル: VoxelStruct.cs プロジェクト: lzxkulou/GDGeek
        static public BoundsInt CreateBounds(VoxelStruct st)
        {
            if (st == null || st.count == 0)
            {
                return(new BoundsInt());
            }

            Vector3Int min = new Vector3Int(9999, 9999, 9999);
            Vector3Int max = new Vector3Int(-9999, -9999, -9999);

            for (int i = 0; i < st.datas_.Count; ++i)
            {
                Vector3Int pos = st.datas_ [i].position;
                min.x = Mathf.Min(pos.x, min.x);
                min.y = Mathf.Min(pos.y, min.y);
                min.z = Mathf.Min(pos.z, min.z);
                max.x = Mathf.Max(pos.x, max.x);
                max.y = Mathf.Max(pos.y, max.y);
                max.z = Mathf.Max(pos.z, max.z);
            }
            Vector3Int size   = new Vector3Int(max.x - min.x + 1, max.y - min.y + 1, max.z - min.z + 1);
            Vector3Int center = new Vector3Int(size.x / 2, size.y / 2, size.z / 2);
            BoundsInt  bounds = new BoundsInt(center, size);

            return(bounds);
        }
コード例 #8
0
ファイル: VoxelBuilder.cs プロジェクト: lzxkulou/GDGeek
        public static MeshFilter Struct2Filter(VoxelStruct vs)
        {
            var data   = Struct2DataInCache(vs);
            var mesh   = VoxelBuilder.Data2Mesh(data);
            var filter = VoxelBuilder.Mesh2Filter(mesh);

            return(filter);
        }
コード例 #9
0
 public MagicaVoxel(VoxelStruct vs, Main main, Size size, Rgba rgba, int version = 0)
 {
     this.structure_ = vs;
     this.main       = main;
     this.size       = size;
     this.rgba       = rgba;
     this.version    = version;
 }
コード例 #10
0
ファイル: JoinVoxel.cs プロジェクト: zhangf911/GDGeek
        public void addVoxel(VoxelStruct vs, VectorInt3 offset)
        {
            Packed packed = new Packed();

            packed.vs     = vs;
            packed.offset = offset;
            list_.Add(packed);
        }
コード例 #11
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;
 }
コード例 #12
0
        static public VoxelStruct Create(HashSet <VectorInt3> hs, Color color)
        {
            VoxelStruct vs = new VoxelStruct();

            foreach (var data in hs)
            {
                vs.datas.Add(new VoxelData(data, color));
            }
            return(vs);
        }
コード例 #13
0
ファイル: VoxelBuilderThread.cs プロジェクト: lzxkulou/GDGeek
		public void struct2Data(VoxelStruct vs, Action<VoxelMeshData> ret){

			ret_ = delegate(VoxelProduct product) {
				ret (product.getMeshData ());
			};
			vs_ = vs;


		
		
		}
コード例 #14
0
ファイル: VoxelDirector.cs プロジェクト: jack7Dgame/FirstVr
        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);
        }
コード例 #15
0
ファイル: VoxelBuilder.cs プロジェクト: lzxkulou/GDGeek
        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);
        }
コード例 #16
0
        public static VoxelStruct Unusual(VectorInt3 shifting, VoxelStruct st)
        {
            VoxelStruct ret = new VoxelStruct();

            for (int i = 0; i < st.datas.Count; ++i)
            {
                VoxelData data = st.datas [i];
                data.pos += shifting;
                ret.datas.Add(data);
            }

            return(ret);
        }
コード例 #17
0
ファイル: VoxelDirector.cs プロジェクト: jack7Dgame/FirstVr
        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);
        }
コード例 #18
0
ファイル: VoxelDirector.cs プロジェクト: jack7Dgame/FirstVr
        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);
        }
コード例 #19
0
        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.datas = this.getDatas();
            return(vs);
        }
コード例 #20
0
 public override void read()
 {
     if (_voxFile != null)
     {
         Stream sw = new MemoryStream(_voxFile.bytes);
         System.IO.BinaryReader br = new System.IO.BinaryReader(sw);
         if (_model != null)
         {
             VoxelStruct vs = VoxelFormater.ReadFromMagicaVoxel(br);
             _model.data = vs.datas.ToArray();
             _model.vs   = vs;
         }
     }
 }
コード例 #21
0
ファイル: JoinVoxel.cs プロジェクト: CzDreamer/eat
		/*
		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;

		}
コード例 #22
0
ファイル: JoinVoxel.cs プロジェクト: zhangf911/GDGeek
        public VoxelStruct doIt()
        {
            this.clear();
            for (int i = 0; i < list_.Count; ++i)
            {
                Packed p = this.list_ [i];
//				Debug.Log ("p vs data is" + p.vs.datas.Count);
//				Debug.Break ();
                this.readIt(p);
            }
            VoxelStruct vs = new VoxelStruct();

            vs.datas = this.getDatas();
            return(vs);
        }
コード例 #23
0
ファイル: VoxelDirector.cs プロジェクト: jack7Dgame/FirstVr
        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);
        }
コード例 #24
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;
             */
        }
コード例 #25
0
ファイル: VoxelBuilder.cs プロジェクト: lzxkulou/GDGeek
        static public GameObject CreateMesh(VoxelStruct vs, Transform parent, Material material, string name = "Voxel")
        {
            var data   = VoxelBuilderHelper.Struct2DataInCache(vs);
            var mesh   = VoxelBuilder.Data2Mesh(data);
            var filter = VoxelBuilder.Mesh2Filter(mesh);

            VoxelBuilder.FilterAddRenderer(filter, material);


            filter.transform.SetParent(parent);
            filter.transform.localEulerAngles = Vector3.zero;
            filter.transform.localPosition    = Vector3.zero;
            filter.gameObject.layer           = parent.gameObject.layer;
            filter.name = name;
            return(filter.gameObject);
        }
コード例 #26
0
ファイル: VoxelDirector.cs プロジェクト: jack7Dgame/FirstVr
        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);
        }
コード例 #27
0
        public static VoxelStruct Reversal(VoxelStruct st, int reversal)
        {
            if (reversal == 0)
            {
                return(st);
            }
            VectorInt3 min = new VectorInt3(9999, 9999, 9999);
            VectorInt3 max = new VectorInt3(-9999, -9999, -9999);

            for (int i = 0; i < st.datas.Count; ++i)
            {
                VectorInt3 pos = st.datas[i].pos;
                min.x = Mathf.Min(pos.x, min.x);
                min.y = Mathf.Min(pos.y, min.y);
                min.z = Mathf.Min(pos.z, min.z);
                max.x = Mathf.Max(pos.x, max.x);
                max.y = Mathf.Max(pos.y, max.y);
                max.z = Mathf.Max(pos.z, max.z);
            }


            VoxelStruct ret = new VoxelStruct();

            for (int i = 0; i < st.datas.Count; ++i)
            {
                var        data = st.datas[i];
                VectorInt3 pos  = data.pos;
                if ((reversal & (int)(ReversalAxis.XAxis)) != 0)
                {
                    pos.x = max.x - pos.x - 1 + min.x;
                }

                if ((reversal & (int)(ReversalAxis.YAxis)) != 0)
                {
                    pos.y = max.y - pos.y - 1 + min.y;
                }
                if ((reversal & (int)(ReversalAxis.ZAxis)) != 0)
                {
                    pos.z = max.z - pos.z - 1 + min.z;
                }

                ret.datas.Add(new VoxelData(pos, data.color));
            }
            return(ret);
        }
コード例 #28
0
        public static string GetMd5(VoxelStruct vs)
        {
            MemoryStream memoryStream = new MemoryStream();
            BinaryWriter binaryWriter = new BinaryWriter(memoryStream);

            WriteToBinary(vs, binaryWriter);
            byte[] data = memoryStream.GetBuffer();
            MD5    md5  = new MD5CryptoServiceProvider();

            byte[] result  = md5.ComputeHash(data);
            string fileMD5 = "";

            foreach (byte b in result)
            {
                fileMD5 += Convert.ToString(b, 16);
            }
            return(fileMD5);
        }
コード例 #29
0
ファイル: VoxelTaskBuilder.cs プロジェクト: zhangf911/GDGeek
        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);
        }
コード例 #30
0
ファイル: MagicaVoxelFormater.cs プロジェクト: gdgeek/qclass
        public static string GetMd5(VoxelStruct vs)
        {
            return("");

            /*
             *          MemoryStream memoryStream = new MemoryStream ();
             *          BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
             *          WriteToBinary (vs, binaryWriter);
             *          byte[] data = memoryStream.GetBuffer();
             *          MD5 md5 = new MD5CryptoServiceProvider();
             *          byte[] result = md5.ComputeHash(data);
             *          string fileMD5 = "";
             *          foreach (byte b in result)
             *          {
             *                  fileMD5 += Convert.ToString(b, 16);
             *          }*/
            //return fileMD5;
        }
コード例 #31
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);
        }
コード例 #32
0
        static public Bounds CreateBounds(VoxelStruct st)
        {
            VectorInt3 min = new VectorInt3(9999, 9999, 9999);
            VectorInt3 max = new VectorInt3(-9999, -9999, -9999);

            for (int i = 0; i < st.datas.Count; ++i)
            {
                VectorInt3 pos = st.datas [i].pos;
                min.x = Mathf.Min(pos.x, min.x);
                min.y = Mathf.Min(pos.y, min.y);
                min.z = Mathf.Min(pos.z, min.z);
                max.x = Mathf.Max(pos.x, max.x);
                max.y = Mathf.Max(pos.y, max.y);
                max.z = Mathf.Max(pos.z, max.z);
            }
            Vector3 size   = new Vector3(max.x - min.x + 1, max.y - min.y + 1, max.z - min.z + 1);
            Bounds  bounds = new Bounds(size / 2, size);

            return(bounds);
        }
コード例 #33
0
ファイル: VoxelFormater.cs プロジェクト: FlyTeeth1128/GDGeek
        public static VoxelStruct ReadFromMagicaVoxel(System.IO.BinaryReader br)
        {
            VoxelStruct vs = new VoxelStruct ();

            // 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];
            VectorInt4[] palette = null;
            Point[] points = null;

            string vox = new string(br.ReadChars(4));
            if (vox != "VOX ") {

                Debug.Log (vox);
                return vs;
            }

            int version = br.ReadInt32();
            vs.version = version;
            VectorInt3 box = new VectorInt3 ();
            bool subsample = false;

            while (br.BaseStream.Position < br.BaseStream.Length)
            {
                // each chunk has an ID, size and child chunks
                string name = new string(br.ReadChars(4));
                int size = br.ReadInt32();
                int chunks = br.ReadInt32();
                // Debug.LogError (chunkName);
                // there are only 2 chunks we only care about, and they are SIZE and XYZI
                if(name == "MAIN"){
                    vs.main = new VoxelStruct.Main ();
                    vs.main.size = size;
                    vs.main.name = name;
                    vs.main.chunks = chunks;
                }
                if (name == "SIZE")
                {

                    box.x = br.ReadInt32();
                    box.y = br.ReadInt32();
                    box.z = br.ReadInt32();

                    vs.size = new VoxelStruct.Size ();
                    vs.size.size = 12;
                    vs.size.name = name;
                    vs.size.chunks = chunks;
                    vs.size.box = box;

                    if (box.x > 32 || box.y > 32) {
                        subsample = true;
                    }

                    br.ReadBytes(size - 4 * 3);
                }
                else if (name == "XYZI")
                {

                    // XYZI contains n voxels
                    int count = br.ReadInt32();
                    //int div = (subsample ? 2 : 1);
                    // each voxel has x, y, z and color index values
                    points = new Point[count];
                    for (int i = 0; i < points.Length; i++) {
                        points [i] = VoxelFormater.CreatePoint (br, subsample);//new Data (stream, subsample);
                    }

                }
                else if (name == "RGBA")
                {

                    int n = size / 4;
                    palette = new VectorInt4[n];
                    for (int i = 0; i < n; i++)
                    {
                        byte r = br.ReadByte();
                        byte g = br.ReadByte();
                        byte b = br.ReadByte();
                        byte a = br.ReadByte();
                        palette[i].x = r;
                        palette[i].y = g;
                        palette[i].z = b;
                        palette[i].w = a;
                    }

                    vs.rgba = new VoxelStruct.Rgba ();
                    vs.rgba.size = size;
                    vs.rgba.name = name;
                    vs.rgba.chunks = chunks;
                    vs.rgba.palette = palette;
                }
                else {
                    br.ReadBytes(size);   // read any excess bytes
                }
            }
            vs.datas = CreateVoxelDatas(points, palette);
            return vs;
        }
コード例 #34
0
ファイル: VoxelFormater.cs プロジェクト: FlyTeeth1128/GDGeek
        public static void WriteToMagicaVoxel(VoxelStruct vs, System.IO.BinaryWriter bw)
        {
            bw.Write ("VOX ".ToCharArray());
            bw.Write ((int)vs.version);

            if (vs.main != null) {
                bw.Write (vs.main.name.ToCharArray ());
                bw.Write ((int)vs.main.size);
                bw.Write ((int)vs.main.chunks);
            }

            if (vs.size != null) {
                bw.Write (vs.size.name.ToCharArray ());
                bw.Write ((int)vs.size.size);
                bw.Write ((int)vs.size.chunks);
                bw.Write ((int)vs.size.box.x);
                bw.Write ((int)vs.size.box.y);
                bw.Write ((int)vs.size.box.z);
            }

            if (vs.rgba != null && vs.rgba.palette != null) {

                int length = vs.rgba.palette.Length;
                bw.Write (vs.rgba.name.ToCharArray ());
                bw.Write ((int)(length * 4));
                bw.Write ((int)vs.size.chunks);

                for (int i = 0; i < length; i++)
                {
                    VectorInt4 c = vs.rgba.palette [i];
                    bw.Write ((byte)(c.x));
                    bw.Write ((byte)(c.y));
                    bw.Write ((byte)(c.z));
                    bw.Write ((byte)(c.w));
                }
            }
            Point[] points = CreatePoint (vs.datas, vs.rgba.palette);
            bw.Write ("XYZI".ToCharArray ());

            bw.Write ((int)(points.Length * 4) + 4);
            bw.Write ((int)0);

            bw.Write ((int)points.Length);

            //Point[] points = CreatePoint (vs.datas, vs.rgba.palette);
            for (int i = 0; i < points.Length; ++i) {
                Point p = points[i];
                bw.Write ((byte)(p.x));
                bw.Write ((byte)(p.y));
                bw.Write ((byte)(p.z));
                bw.Write ((byte)(p.i));

            }
        }