Exemplo n.º 1
0
        /// <summary>
        /// Decode (decompresss) and restore an element that was compressed by this crusher.
        /// </summary>
        public Element Decompress(CompressedElement compressed)
        {
            if (!cached)
            {
                CacheValues();
            }

            if (_trsType == TRSType.Scale && uniformAxes != UniformAxes.NonUniform)
            {
                float val = ucrusher.Decompress((uint)compressed.cx);
                return(new Vector3(val, val, val));
            }
            else if (_trsType == TRSType.Quaternion)
            {
                //Debug.Log("We should not see this! Quats should be getting called to DecompressToQuat");
                return(qcrusher.Decompress(compressed.cQuat));
            }
            else
            {
                // Issue log error for trying to write more than 64 bits to the ulong buffer
                FloatCrusherUtilities.CheckBitCount(cache_TotalBits[0], 64);

                return(new Vector3(
                           cache_xEnabled ? (xcrusher.Decompress((uint)compressed.cx)) : 0,
                           cache_yEnabled ? (ycrusher.Decompress((uint)compressed.cy)) : 0,
                           cache_zEnabled ? (zcrusher.Decompress((uint)compressed.cz)) : 0
                           ));
            }
        }
        //UNTESTED
        /// <summary>
        /// Reads (deserialize) a compressed value from the buffer, decmpress, and return a restored float.
        /// </summary>
        /// <param name="buffer">Source buffer to read from.</param>
        /// <param name="bitposition">Auto-incremented read position for the buffer. Will begin reading bits from this position.</param>
        /// <param name="bcl"></param>
        /// <returns></returns>
        public static float ReadAndDecompress(this FloatCrusher fc, ulong buffer, ref int bitposition, BitCullingLevel bcl = BitCullingLevel.NoCulling)
        {
            int  bits = fc._bits[(int)bcl];
            uint c    = (uint)buffer.Read(ref bitposition, bits);

            return(fc.Decompress(c));
        }
        /// <summary>
        /// Deserializes a compressed (encoded) float out of an array from the indicated bitpostion, and Decode() it.
        /// </summary>
        /// <param name="buffer">Source array buffer.</param>
        /// <param name="bitposition">The auto-incremented position in the array (in bits) where we will begin reading.</param>
        /// <returns>Restored float value.</returns>
        public static float ReadAndDecompress(this FloatCrusher fc, ulong[] buffer, ref int bitposition)
        {
            uint c = buffer.ReadUInt32(ref bitposition, fc._bits[0]);

            return(fc.Decompress(c));
        }
        public static float ReadAndDecompress(this FloatCrusher fc, ref Bitstream bitstream, BitCullingLevel bcl = BitCullingLevel.NoCulling)
        {
            CompressedFloat c = fc.Read(ref bitstream, bcl);

            return(fc.Decompress(c));
        }