Esempio n. 1
0
        public CompressedElement Compress(Vector3 v)
        {
            if (!cached)
            {
                CacheValues();
            }

            if (_trsType == TRSType.Scale && uniformAxes != UniformAxes.NonUniform)
            {
                //Debug.Log(this + " Compress <b>UNIFORM</b>");
                ulong cu = (cache_uEnabled) ? ucrusher.Compress((uniformAxes == UniformAxes.YZ) ? v.y : v.x) : (ulong)0;
                return(new CompressedElement(this, cu, cache_uBits[0]));
            }
            else if (_trsType == TRSType.Quaternion)
            {
                Debug.Log("We shouldn't be seeing this. Quats should not be getting compressed from Eulers!");
                return((cache_uEnabled) ? new CompressedElement(this, qcrusher.Compress(Quaternion.Euler(v)), cache_qBits) : new CompressedElement(this, (ulong)0, cache_qBits));
            }
            else
            {
                FloatCrusherUtilities.CheckBitCount(xcrusher.Bits + ycrusher.Bits + zcrusher.Bits, 64);

                uint cx = (cache_xEnabled ? (uint)xcrusher.Compress(v.x) : 0);
                uint cy = (cache_yEnabled ? (uint)ycrusher.Compress(v.y) : 0);
                uint cz = (cache_zEnabled ? (uint)zcrusher.Compress(v.z) : 0);

                return(new CompressedElement(this, cx, cy, cz, cache_xBits[0], cache_yBits[0], cache_zBits[0]));
            }
        }
        /// <summary>
        /// Serialize an uncompressed value to an array buffer using this FloatCrusher.
        /// </summary>
        /// <param name="f">Uncompressed float</param>
        /// <param name="buffer"></param>
        /// <param name="bitposition"></param>
        /// <param name="bcl"></param>
        /// <returns></returns>
        public static CompressedFloat Write(this FloatCrusher fc, float f, ulong[] buffer, ref int bitposition, BitCullingLevel bcl = BitCullingLevel.NoCulling)
        {
            int  bits = fc._bits[(int)bcl];
            uint c    = fc.Compress(f);

            buffer.Write(c, ref bitposition, bits);
            return(new CompressedFloat(fc, c));
        }
        /// <summary>
        /// Compress (encode) a float value using this FloatCrusher, then Inject() that compressed value into the
        /// supplied buffer starting at the indicated bitposition.
        /// </summary>
        /// <param name="f">Float to be compressed and serialized</param>
        /// <param name="buffer">Target primitive buffer to serialize into.</param>
        /// <param name="bitposition">The auto-incremented position in the array (in bits) where we will begin reading.</param>
        /// <param name="bcl"></param>
        /// <returns>Returns the compressed uint that was serialized.</returns>
        public static CompressedFloat Write(this FloatCrusher fc, float f, ref byte buffer, ref int bitposition, BitCullingLevel bcl = BitCullingLevel.NoCulling)
        {
            int             bits = fc._bits[(int)bcl];
            CompressedFloat c    = fc.Compress(f);

            c.cvalue.Inject(ref buffer, ref bitposition, bits);
            return(c);
        }
        public static CompressedFloat Write(this FloatCrusher fc, float f, ref Bitstream bitstream, BitCullingLevel bcl = BitCullingLevel.NoCulling)
        {
            int  bits = fc._bits[(int)bcl];
            uint c    = fc.Compress(f);

            bitstream.Write(c, bits);
            return(new CompressedFloat(fc, c));
        }