public void WritePolygonsNet(CurvedPolygonsNet net)
        {
            //Debug.Log("On write this.compressionMask:" + this.compressionMask);
            if (compressionMask == 0)
            {
                compressionMask = DEFAULT_COMPRESSION_MASK;

                /*Debug.Log("Since it was 0 we set it to a new Value this.compressionMask:" + this.compressionMask);
                 * Debug.Log("Where Vertices Compression IS:" + GetVertexCompressionMode());
                 * Debug.Log("Where UV Compression IS:" + GetUVCompressionMode());*/
            }

            this.numberOfVertices = net.GetNumberOfVertices();
            this.vertices         = CPVertexArrayData.CompressVertexArray(net.GetVertices(), GetVertexCompressionMode());
            this.uvs = CPUVArrayData.compressUVArray(net.GetUv(), GetUVCompressionMode());
            //Debug.Log("On Write, UVs:" + ToString(net.GetUv()));
            this.normals    = CPVectorArrayData.compressVectorArray(net.GetNormals(), GetVectorCompressionMode());
            this.tangents   = new byte[0];
            this.edges      = CPShortArrayData.CompressShortsArray(net.GetEdges());
            this.edgesIndex = CPShortArrayData.CompressShortsArray(net.GetEdgesIndex());
            this.edgeHints  = CPShortArrayData.CompressShortsArray(net.GetEdgeHints());
            //this.edgeRots = CPFloatArrayData.compressFloatsArray(net.GetEdgesRots(), FLOAT_PRECISION);
            //this.edgeThickness = CPFloatArrayData.compressFloatsArray(net.GetEdgesThickness(), FLOAT_PRECISION);
            this.edgeWeights = CPFloatArrayData.compressFloatsArray(net.GetEdgeWeights(), FLOAT_PRECISION);
            this.geometries  = new CPGeometryAsset[net.GetGeometriesCount()];
            for (int i = 0; i < geometries.Length; i++)
            {
                geometries[i] = new CPGeometryAsset {
                    polygons       = CPShortArrayData.CompressShortsArray(net.GetGeometries()[i].GetPolygons()),
                    polygonsIndex  = CPShortArrayData.CompressShortsArray(net.GetGeometries()[i].GetPolygonsIndex()),
                    polygonsSchema = CPShortArrayData.CompressShortsArray(net.GetGeometries()[i].GetPolygonsSchemas())
                };
            }
        }
        public static byte[] compressFloatsArray(float[] data, float precision)
        {
            float recPrecision = 1.0f / precision;

            int size     = data.Length;
            int maxIndex = size > 0 ? floatToInt(data[0], recPrecision, precision) : 0;
            int minIndex = maxIndex;

            for (int i = 0; i < size; i++)
            {
                int value = floatToInt(data[i], recPrecision, precision);
                maxIndex = value < maxIndex ? maxIndex : value;
                minIndex = value > minIndex ? minIndex : value;
            }

            int bitSize = CPShortArrayData.getBitSize(maxIndex - minIndex);

            /* 7 bytes
             * 3 for minIndex
             * 1 for bitSize
             * 3 for size
             * 1 for rounding ((size * bitSize) >> 3)
             */
            int bytesSize = ((size * bitSize) >> 3) + 8;

            BitOutputStream bitOutputStream = new BitOutputStream(bytesSize);

            bitOutputStream.WriteBits(24, minIndex);
            bitOutputStream.WriteBits(8, bitSize);
            bitOutputStream.WriteBits(24, size);
            for (int i = 0; i < size; i++)
            {
                int value = floatToInt(data[i], recPrecision, precision);
                bitOutputStream.WriteBits(bitSize, value - minIndex);
            }

            return(bitOutputStream.GetData());
        }
        public void ReadPolygonsNet(CurvedPolygonsNet net)
        {
            //Debug.Log("this.precision "+this.compressionMask);
            net.SetVertices(CPVertexArrayData.GetCompressedVertexArray(vertices, GetVertexCompressionMode()));

            net.SetUv(CPUVArrayData.getCompressedUVArray(uvs, GetUVCompressionMode()));

            net.SetNormals(CPVectorArrayData.getCompressedVectorArray(normals, GetVectorCompressionMode()));
            //net.setTangents(CPVectorArrayData.getCompressedVectorArray(vertices, getVectorCompressionMode()));
            short[] edges      = CPShortArrayData.GetCompressedShortsArray(this.edges);
            short[] edgesIndex = CPShortArrayData.GetCompressedShortsArray(this.edgesIndex);
            int     edgesSize  = edgesIndex.Length - 1;

            net.SetNumberOfVertices(numberOfVertices);
            net.SetEdges(edgesIndex.Length - 1, edges, edgesIndex,
                         CPShortArrayData.GetCompressedShortsArray(edgeHints),
                         CPFloatArrayData.getCompressedFloatsArray(edgeWeights, FLOAT_PRECISION));
            CPNGeometry[] geometries = new CPNGeometry[this.geometries.Length];
            for (int i = 0; i < geometries.Length; i++)
            {
                geometries[i] = new CPNGeometry();
                short[] polygonsIndex   = CPShortArrayData.GetCompressedShortsArray(this.geometries[i].polygonsIndex);
                short[] polygons        = CPShortArrayData.GetCompressedShortsArray(this.geometries[i].polygons);
                short[] polygonsSchemas = null;
                if (this.geometries[i].polygonsSchema != null && this.geometries[i].polygonsSchema.Length != 0)
                {
                    polygonsSchemas = CPShortArrayData.GetCompressedShortsArray(this.geometries[i].polygonsSchema);
                }
                else
                {
                    polygonsSchemas = new short[polygonsIndex.Length - 1];
                }
                int polygonsCount = polygonsIndex.Length - 1;
                geometries[i].Setup((short)polygonsCount, polygonsIndex, polygons, polygonsSchemas);
            }
            net.SetGeometries(geometries.Length, geometries);
        }