Exemplo n.º 1
0
        public static VoxelData Parse(Dictionary <V3, Color> voxelColors)
        {
            VoxelData voxel  = GetData();
            var       colors = new Dictionary <Color, int>();
            var       minPos = new V3(int.MaxValue);
            var       maxPos = new V3(int.MinValue);

            foreach (var vc in voxelColors)
            {
                minPos = minPos.MixMin(vc.Key);
                maxPos = maxPos.MixMax(vc.Key);
            }
            voxel.SetSceneScale(maxPos.x - minPos.x, maxPos.y - minPos.y, maxPos.z - minPos.z);
            foreach (var vc in voxelColors)
            {
                var colorIndex = -1;

                if (colors.ContainsKey(vc.Value))
                {
                    colorIndex = colors[vc.Value];
                }
                else
                {
                    colorIndex = colors.Count;
                    colors.Add(vc.Value, colorIndex);
                }


                voxel.SetVoxel(vc.Key.x - minPos.x, vc.Key.y - minPos.y, vc.Key.z - minPos.z, colorIndex);
            }
            foreach (var ci in colors)
            {
                var color = new ColorInfo();
                color.r = ci.Key.r;
                color.g = ci.Key.g;
                color.b = ci.Key.b;
                color.a = ci.Key.a;
                voxel.colors[ci.Value] = color;
            }
            return(voxel);
        }
Exemplo n.º 2
0
        static int ReadColor(BinaryReader reader, VoxelData voxelData)
        {
            int dataSize  = reader.ReadInt32();
            int childSize = reader.ReadInt32();

            for (int i = 0; i < 256; i++)
            {
                var colorInfo = new ColorInfo();
                colorInfo.r = (float)reader.ReadByte() / 256;
                colorInfo.g = (float)reader.ReadByte() / 256;
                colorInfo.b = (float)reader.ReadByte() / 256;
                colorInfo.a = (float)reader.ReadByte() / 256;
                voxelData.colors.Add(colorInfo);
            }
            if (childSize > 0)
            {
                reader.ReadBytes(childSize);
                Warning("RGBA节点拥有多余未知数据");
            }
            return(dataSize + childSize + 4 * 3);
        }