Ejemplo n.º 1
0
 public static CompressedElement OverwriteUpperBits(this CompressedElement low, CompressedElement up, FloatCrusher[] ec, BitCullingLevel bcl)
 {
     return(new CompressedElement(
                low.crusher,
                ec[0].OverwriteUpperBits(low.cx, up.cx, bcl),
                ec[1].OverwriteUpperBits(low.cy, up.cy, bcl),
                ec[2].OverwriteUpperBits(low.cz, up.cz, bcl)
                ));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Test changes between two compressed Vector3 elements and return the ideal BitCullingLevel for that change.
        /// </summary>
        public static BitCullingLevel GetGuessableBitCullLevel(CompressedElement oldComp, CompressedElement newComp, FloatCrusher[] ec, BitCullingLevel maxCullLvl)
        {
            for (BitCullingLevel lvl = maxCullLvl; lvl > 0; lvl--)
            {
                CompressedElement uppers = oldComp.ZeroLowerBits(ec, lvl);
                CompressedElement lowers = newComp.ZeroUpperBits(ec, lvl);

                CompressedElement merged = new CompressedElement(
                    oldComp.crusher,
                    uppers.cx | lowers.cx,
                    uppers.cy | lowers.cy,
                    uppers.cz | lowers.cz);

                // Starting guess is the new lower bits using the previous upperbits
                if (Compare(newComp, merged))                 //  (oldComp.ZeroLowerBits(lvl) | newComp.ZeroUpperBits(lvl))))
                {
                    return(lvl);
                }
            }
            return(BitCullingLevel.NoCulling);
        }
Ejemplo n.º 3
0
 public static CompressedElement GuessUpperBits(this CompressedElement newcpos, CompressedElement oldcpos, FloatCrusher[] ec, BitCullingLevel bcl)
 {
     return(new CompressedElement(
                oldcpos.crusher,
                ec[0].GuessUpperBits(newcpos[0], oldcpos[0], bcl),
                ec[1].GuessUpperBits(newcpos[1], oldcpos[1], bcl),
                ec[2].GuessUpperBits(newcpos[2], oldcpos[2], bcl)
                ));
 }
Ejemplo n.º 4
0
 public static void Copy(CompressedElement source, CompressedElement target)
 {
     target.cx = source.cx;
     target.cy = source.cy;
     target.cz = source.cz;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// It is preferable to use the overload that takes and int divisor value than a float, to avoid all float math.
        /// </summary>
        public static CompressedElement Extrapolate(CompressedElement curr, CompressedElement prev, float amount = .5f)
        {
            int divisor = (int)(1f / amount);

            return(Extrapolate(curr, prev, divisor));
        }
 // Constructor
 public CompressedMatrix(TransformCrusher crusher, ref CompressedElement cPos, ref CompressedElement cRot, ref CompressedElement cScl, int pBits, int rBits, int sBits)
 {
     this.crusher = crusher;
     this.cPos    = cPos;
     this.cRot    = cRot;
     this.cScl    = cScl;
 }
Ejemplo n.º 7
0
        //public static implicit operator CompressedElement(ulong val)
        //{
        //	return new CompressedElement(null, val);
        //}

        /// <summary>
        /// Basic compare of the X, Y, Z, and W values. True if they all match.
        /// </summary>
        public static bool Compare(CompressedElement a, CompressedElement b)
        {
            return(a.cx == b.cx && a.cy == b.cy && a.cz == b.cz);
        }
Ejemplo n.º 8
0
 public ulong Write(CompressedElement ce, ref Bitstream bitstream)
 {
     bitstream.Write((ulong)ce.cQuat, bits);
     return((ulong)ce.cQuat);
 }
 // Constructor
 public CompressedMatrix(TransformCrusher crusher, CompressedElement cPos, CompressedElement cRot, CompressedElement cScl)
 {
     this.crusher = crusher;
     this.cPos    = cPos;
     this.cRot    = cRot;
     this.cScl    = cScl;
 }
Ejemplo n.º 10
0
        // Constructor
        public CompressedMatrix(TransformCrusher crusher, CompressedElement cPos, CompressedElement cRot, CompressedElement cScl, int pBits, int rBits, int sBits) : this()
        {
            this.crusher = crusher;
            this.cPos    = cPos;
            this.cRot    = cRot;
            this.cScl    = cScl;

            this.bitstream = new Bitstream(cPos.bitstream, pBits, cRot.bitstream, rBits, cScl.bitstream, sBits);
        }
 public static CompressedElement GuessUpperBits(this CompressedElement newcpos, CompressedElement oldcpos, ElementCrusher ec, BitCullingLevel bcl)
 {
     //var crusher = oldcpos.crusher;
     return(new CompressedElement(
                ec,
                ec.XCrusher.GuessUpperBits(newcpos[0], oldcpos[0], bcl),
                ec.YCrusher.GuessUpperBits(newcpos[1], oldcpos[1], bcl),
                ec.ZCrusher.GuessUpperBits(newcpos[2], oldcpos[2], bcl)
                ));
 }
Ejemplo n.º 12
0
        //public Quaternion DecompressToQuat(CompressedElement compressed)
        //{
        //	if (!cached)
        //		CacheValues();

        //	DebugX.LogError("You seem to be trying to decompress a Quaternion from a crusher that is set up for " +
        //		System.Enum.GetName(typeof(TRSType), TRSType) + ". This likely won't end well.", TRSType != TRSType.Quaternion, true);

        //	Quaternion quat = qcrusher.Decompress(compressed.cQuat);
        //	return quat;
        //}

        #endregion

        #region Apply

        /// <summary>
        /// Applies only the enabled axes to the transform, leaving the disabled axes untouched.
        /// </summary>
        public void Apply(Transform trans, CompressedElement cElement)
        {
            Apply(trans, Decompress(cElement));
        }
Ejemplo n.º 13
0
        public CompressedElement Write(CompressedElement compressed, ref ulong buffer, BitCullingLevel bcl = BitCullingLevel.NoCulling)
        {
            int bitposition = 0;

            return(Write(compressed, ref buffer, ref bitposition, bcl));
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Applies only the enabled axes to the transform, leaving the disabled axes untouched.
 /// </summary>
 public void Apply(Rigidbody rb, CompressedElement cElement)
 {
     Apply(rb, Decompress(cElement));
 }