Beispiel #1
0
        public static Vector3[] GetCompressedVertexArray(byte[] data, CPVertexCompressionMode compressionMode)
        {
            float precision = GetPrecision(compressionMode);
            //Debug.Log("Decompress Vertex Data precision:" + precision + " compressionMode:" + compressionMode);
            BitInputStream bitInputStream = new BitInputStream(data);
            int            minX           = bitInputStream.ReadBits(24) - CPFloatArrayData.MIDDLE_VALUE;
            int            minY           = bitInputStream.ReadBits(24) - CPFloatArrayData.MIDDLE_VALUE;
            int            minZ           = bitInputStream.ReadBits(24) - CPFloatArrayData.MIDDLE_VALUE;

            int bitsSize = bitInputStream.ReadBits(8);
            int size     = bitInputStream.ReadBits(24);

            Vector3[] values = new Vector3[size];
            for (int i = 0; i < values.Length; i++)
            {
                int read = bitInputStream.ReadBits(bitsSize);
                values[i].x = (minX + read) * precision;
                read        = bitInputStream.ReadBits(bitsSize);
                values[i].y = (minY + read) * precision;
                read        = bitInputStream.ReadBits(bitsSize);
                values[i].z = (minZ + read) * precision;
            }

            return(values);
        }
Beispiel #2
0
        public static short[] GetCompressedShortsArray(byte[] data)
        {
            BitInputStream bitInputStream = new BitInputStream(data);
            int            min            = bitInputStream.ReadBits(16);
            int            bitsSize       = bitInputStream.ReadBits(8);
            int            size           = bitInputStream.ReadBits(24);

            short[] values = new short[size];
            int     delta  = min - MIDDLE_VALUE;

            for (int i = 0; i < values.Length; i++)
            {
                int read = bitInputStream.ReadBits(bitsSize);
                values[i] = (short)(delta + read);
            }

            return(values);
        }
        public static Vector3[] getCompressedVectorArray(byte[] data, CPVectorCompressionMode compressionMode)
        {
            float          recPrecision   = getModeResize(compressionMode);
            float          precision      = 1.0f / recPrecision;
            BitInputStream bitInputStream = new BitInputStream(data);
            int            bitsSize       = getModeBitsize(compressionMode);

            int size = bitInputStream.ReadBits(24);

            Vector3[] values = new Vector3[size];
            for (int i = 0; i < values.Length; i++)
            {
                int read = bitInputStream.ReadBits(bitsSize);
                values[i].x = (read) * precision - 1;
                read        = bitInputStream.ReadBits(bitsSize);
                values[i].y = (read) * precision - 1;
                read        = bitInputStream.ReadBits(bitsSize);
                values[i].z = (read) * precision - 1;
                values[i].Normalize();
            }

            return(values);
        }