public void Clear()
 {
     this.crusher = null;
     this.cx      = new CompressedFloat(null, 0);
     this.cy      = new CompressedFloat(null, 0);
     this.cz      = new CompressedFloat(null, 0);
 }
        public Bitstream ExtractBitstream(ElementCrusher crusher, BitCullingLevel bcl = BitCullingLevel.NoCulling)
        {
            Bitstream bitstream = new Bitstream();

            crusher.Write(this, ref bitstream, BitCullingLevel.NoCulling);
            return(bitstream);
        }
 public void Set(ElementCrusher crusher, uint cx, uint cy, uint cz)
 {
     this.crusher = crusher;
     this.cx      = new CompressedFloat(crusher.XCrusher, cx);
     this.cy      = new CompressedFloat(crusher.YCrusher, cy);
     this.cz      = new CompressedFloat(crusher.ZCrusher, cz);
 }
 public void Set(ElementCrusher crusher, CompressedFloat cx, CompressedFloat cy, CompressedFloat cz)
 {
     this.crusher = crusher;
     this.cx      = cx;
     this.cy      = cy;
     this.cz      = cz;
 }
Exemplo n.º 5
0
 // Constructor
 public CompressedElement(ElementCrusher crusher, uint cx, uint cy, uint cz) : this()
 {
     this.crusher = crusher;
     this.cx      = cx;
     this.cy      = cy;
     this.cz      = cz;
 }
 // Constructor
 public CompressedElement(ElementCrusher crusher, uint cx, uint cy, uint cz)         /*: this()*/
 {
     UnityEngine.Debug.LogWarning("CE Construct");
     this.crusher = crusher;
     this.cx      = new CompressedFloat(crusher.XCrusher, cx);
     this.cy      = new CompressedFloat(crusher.YCrusher, cy);
     this.cz      = new CompressedFloat(crusher.ZCrusher, cz);
 }
Exemplo n.º 7
0
 // Constructor for half-float
 public CompressedElement(ElementCrusher ec, ushort cx, ushort cy, ushort cz) : this()
 {
     this.crusher   = ec;
     this.cx        = cx;
     this.cy        = cy;
     this.cz        = cz;
     this.bitstream = new Bitstream(cx, 16, cy, 16, cz, 16);
 }
Exemplo n.º 8
0
 // Constructor
 public CompressedElement(ElementCrusher crusher, uint cx, uint cy, uint cz, int xbits, int ybits, int zbits) : this()
 {
     this.crusher   = crusher;
     this.cx        = cx;
     this.cy        = cy;
     this.cz        = cz;
     this.bitstream = new Bitstream(cx, xbits, cy, ybits, cz, zbits);
 }
 // Constructor
 public CompressedElement(ElementCrusher crusher, CompressedFloat cx, CompressedFloat cy, CompressedFloat cz)        /* : this()*/
 {
     //UnityEngine.Debug.LogWarning("CE Construct");
     this.crusher = crusher;
     this.cx      = cx;
     this.cy      = cy;
     this.cz      = cz;
 }
Exemplo n.º 10
0
 // Constructor
 public CompressedElement(ElementCrusher ec, float x, float y, float z) : this()
 {
     this.crusher   = ec;
     floatx         = x;
     floaty         = y;
     floatz         = z;
     this.bitstream = new Bitstream(cx, 32, cy, 32, cz, 32);
 }
Exemplo n.º 11
0
 // Constructor
 public CompressedElement(ElementCrusher crusher, CompressedValue cx, CompressedValue cy, CompressedValue cz) : this()
 {
     this.crusher   = crusher;
     this.cx        = cx;
     this.cy        = cy;
     this.cz        = cz;
     this.bitstream = new Bitstream(cx, cy, cz);
 }
 public static CompressedElement Extrapolate(ElementCrusher crusher, CompressedElement curr, CompressedElement prev, int divisor = 2)
 {
     return(new CompressedElement
            (
                crusher,
                (uint)(curr.cx + (((long)curr.cx - prev.cx)) / divisor),
                (uint)(curr.cy + (((long)curr.cy - prev.cy)) / divisor),
                (uint)(curr.cz + (((long)curr.cz - prev.cz)) / divisor)
            ));
 }
 /// <summary>
 /// Alternative to OverwriteUpperBits that attempts to guess the upperbits by seeing if each axis of the new position would be
 /// closer to the old one if the upper bit is incremented by one, two, three etc. Stops trying when it fails to get a better result.
 /// </summary>
 /// <param name="oldcpos">Last best position test against.</param>
 /// <returns>Returns a corrected CompressPos</returns>
 public static void GuessUpperBits(this CompressedElement newcpos, ElementCrusher ec, CompressedElement oldcpos, BitCullingLevel bcl)
 {
     //var crusher = oldcpos.crusher;
     newcpos.Set(
         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)
         );
 }
        //public static CompressedElement operator +(CompressedElement a, CompressedElement b)
        //{
        //	return new CompressedElement(a.crusher, (uint)((long)a.cx + b.cx), (uint)((long)a.cy + b.cy), (uint)((long)a.cz + b.cz));
        //}
        //public static CompressedElement operator -(CompressedElement a, CompressedElement b)
        //{
        //	return new CompressedElement(a.crusher, (uint)((long)a.cx - b.cx), (uint)((long)a.cy - b.cy), (uint)((long)a.cz - b.cz));
        //}
        //public static CompressedElement operator *(CompressedElement a, float b)
        //{
        //	return new CompressedElement(a.crusher, (uint)(a.cx * b), (uint)(a.cy * b), (uint)(a.cz * b));
        //}

        ///<summary>
        /// It may preferable to use the overload that takes and int divisor value than a float, to avoid all float math to possibly reduce jitter.
        /// </summary>
        public static void Extrapolate(ElementCrusher crusher, CompressedElement target, CompressedElement curr, CompressedElement prev, int divisor = 2)
        {
            target.Set
            (
                crusher,
                (uint)(curr.cx + (((long)curr.cx - prev.cx)) / divisor),
                (uint)(curr.cy + (((long)curr.cy - prev.cy)) / divisor),
                (uint)(curr.cz + (((long)curr.cz - prev.cz)) / divisor)
            );
        }
        //public static CompressedElement OverwriteUpperBits(this CompressedElement low, CompressedElement up, FloatCrusher[] ec, BitCullingLevel bcl)
        //{
        //	return new CompressedElement(
        //		//ec,
        //		ec[0].OverwriteUpperBits(low.cx, up.cx, bcl),
        //		ec[1].OverwriteUpperBits(low.cy, up.cy, bcl),
        //		ec[2].OverwriteUpperBits(low.cz, up.cz, bcl)
        //		);
        //}

        public static void ZeroLowerBits(this CompressedElement fullpos, CompressedElement target, BitCullingLevel bcl)
        {
            ElementCrusher ec = fullpos.crusher;

            target.Set(
                ec,                 //fullpos.crusher,
                ec.XCrusher.ZeroLowerBits(fullpos.cx, bcl),
                ec.YCrusher.ZeroLowerBits(fullpos.cy, bcl),
                ec.ZCrusher.ZeroLowerBits(fullpos.cz, bcl)
                );
        }
        //public static CompressedElement GuessUpperBits(this CompressedElement newcpos, CompressedElement oldcpos, FloatCrusher[] ec, BitCullingLevel bcl)
        //{
        //	var crusher = oldcpos.crusher;
        //	return new CompressedElement(
        //		crusher,
        //		new CompressedValue(crusher.xcrusher, ec[0].GuessUpperBits(newcpos.cx, oldcpos.cx, bcl), crusher.xcrusher.GetBits(bcl)),
        //		new CompressedValue(crusher.ycrusher, ec[1].GuessUpperBits(newcpos.cx, oldcpos.cx, bcl), crusher.xcrusher.GetBits(bcl)),
        //		new CompressedValue(crusher.zcrusher, ec[2].GuessUpperBits(newcpos.cx, oldcpos.cx, bcl), crusher.xcrusher.GetBits(bcl))
        //		);
        //}

        /// <summary>
        /// Replace the upperbits of the first compressed element with the upper bits of the second, using BitCullingLevel as the separation point.
        /// </summary>
        public static void OverwriteUpperBits(this CompressedElement low, CompressedElement uppers, BitCullingLevel bcl)
        {
            ElementCrusher ec = low.crusher;

            low.Set(
                ec,
                ec.XCrusher.OverwriteUpperBits(low.cx, uppers.cx, bcl),
                ec.YCrusher.OverwriteUpperBits(low.cy, uppers.cy, bcl),
                ec.ZCrusher.OverwriteUpperBits(low.cz, uppers.cz, bcl)
                );
        }
        public static bool TestMatchingUpper(CompressedElement a, CompressedElement b, BitCullingLevel bcl)
        {
            ElementCrusher ec = a.crusher;

            return
                (
                TestMatchingUpper(a.cx, b.cx, ec.XCrusher.GetBits(bcl)) &&
                TestMatchingUpper(a.cy, b.cy, ec.YCrusher.GetBits(bcl)) &&
                TestMatchingUpper(a.cz, b.cz, ec.ZCrusher.GetBits(bcl))
                );
        }
 public static CompressedElement Extrapolate(ElementCrusher crusher, CompressedElement curr, CompressedElement prev, float amount = .5f)
 {
     //int divisor = (int)(1f / amount);
     //return Extrapolate(curr, prev, divisor);
     return(new CompressedElement
            (
                crusher,
                (uint)(curr.cx + ((long)curr.cx - prev.cx) * amount),
                (uint)(curr.cy + ((long)curr.cy - prev.cy) * amount),
                (uint)(curr.cz + ((long)curr.cz - prev.cz) * amount)
            ));
 }
Exemplo n.º 19
0
        protected override void ConstructDefault(bool isStatic = false)
        {
            Debug.Log("RB Crusher ConstructDefault ");
            base.ConstructDefault(isStatic);

            if (isStatic)
            {
                // Statics initialize all crushers as null.
            }
            else
            {
                VelocityCrusher    = new ElementCrusher(TRSType.Position, false);
                AngVelocityCrusher = new ElementCrusher(TRSType.Position, false);
            }
        }
Exemplo n.º 20
0
        public override void Initialize()
        {
            base.Initialize();

            if (worldBoundsGroups.Count == 0)
            {
                worldBoundsGroups.Add(new WorldBoundsGroup());
            }

            defaultWorldBoundsCrusher = worldBoundsGroups[0].crusher;

            foreach (var wbs in worldBoundsGroups)
            {
                wbs.RecalculateWorldCombinedBounds();
            }
        }
        /// <summary>
        /// Return the smallest bit culling level that will be able to communicate the changes between two compressed elements.
        /// </summary>
        public static BitCullingLevel FindBestBitCullLevel(CompressedElement a, CompressedElement b, BitCullingLevel maxCulling)
        {
            ElementCrusher ec = a.crusher;

            if (ec == null)
            {
                UnityEngine.Debug.Log("NUL CE CRUSHER FindBestBitCullLevel");
                return(BitCullingLevel.NoCulling);
            }

            /// Quats can't cull upper bits, so its an all or nothing. Either the bits match or they don't
            if (ec.TRSType == TRSType.Quaternion)
            {
                if ((ulong)a.cQuat == (ulong)b.cQuat)
                {
                    return(BitCullingLevel.DropAll);
                }
                else
                {
                    return(BitCullingLevel.NoCulling);
                }
            }

            if (maxCulling == BitCullingLevel.NoCulling || !TestMatchingUpper(a, b, BitCullingLevel.DropThird))
            {
                return(BitCullingLevel.NoCulling);
            }

            if (maxCulling == BitCullingLevel.DropThird || !TestMatchingUpper(a, b, BitCullingLevel.DropHalf))
            {
                return(BitCullingLevel.DropThird);
            }

            if (maxCulling == BitCullingLevel.DropHalf || !TestMatchingUpper(a, b, BitCullingLevel.DropAll))
            {
                return(BitCullingLevel.DropHalf);
            }

            // both values are the same
            return(BitCullingLevel.DropAll);
        }
        private void GetCrusherFromSharedSO()
        {
            ElementCrusher pc = null;
            ElementCrusher rc = null;
            ElementCrusher sc = null;

            var sharedDefine = SharedCrushersSO.single.GetCrusher <T>(hashcode);

            if (sharedDefine == null)
            {
                return;
            }

            if (!ReferenceEquals(sharedDefine.CrusherRef, _crusher) && sharedDefine.CrusherRef != null)
            {
                if (sharedDefine.CrusherRef != null)
                {
                    _crusher = sharedDefine.CrusherRef as T;
                }

                /// If the stored crusher uses WorldBounds, make sure we change the refs to that.
                var tc = _crusher as TransformCrusher;

                if (tc != null)
                {
                    pc = tc.PosCrusher;
                    rc = tc.RotCrusher;
                    sc = tc.SclCrusher;

                    if (pc != null)
                    {
                        pc.ApplyWorldCrusherSettings();
                        pc.CacheValues();
                    }
                    if (rc != null)
                    {
                        rc.CacheValues();
                    }
                    if (sc != null)
                    {
                        sc.CacheValues();
                    }
                }
                else
                {
                    var ec = _crusher as ElementCrusher;
                    if (ec != null)
                    {
                        if (ec.TRSType == TRSType.Position && ec.UseWorldBounds)
                        {
                            ec.ApplyWorldCrusherSettings();
                        }
                        ec.CacheValues();
                    }
                }

                return;
            }

            if (sharedDefine.CrusherHold.GetHashCode() != _crusher.GetHashCode())
            {
                //#if !UNITY_EDITOR
                //					var tc = _crusher as TransformCrusher;
                //					UnityEngine.Debug.LogError("SC SetAlready PRE" +tc.PosCrusher.XCrusher.BitsDeterminedBy
                //						+ " tally: " + tc.PosCrusher.TallyBits() + " cache: " + tc.PosCrusher.Cached_TotalBits);

                //					tc = sharedDefine.CrusherHold as TransformCrusher;
                //					UnityEngine.Debug.LogError("SC SetAlready PST" + tc.PosCrusher.XCrusher.BitsDeterminedBy
                //						+ " tally: " + tc.PosCrusher.TallyBits() + " cache: " + tc.PosCrusher.Cached_TotalBits);
                //#endif
                var holdcrusher = sharedDefine.CrusherHold as ICrusherCopy <T>;
                (_crusher as ICrusherCopy <T>).CopyFrom(holdcrusher as T);
            }
        }
Exemplo n.º 23
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, ElementCrusher 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);
        }
Exemplo n.º 24
0
 // Constructor for Quaternion rotation
 public CompressedElement(ElementCrusher crusher, ulong cQuat, int qbits) : this()
 {
     this.crusher   = crusher;
     this.cQuat     = cQuat;
     this.bitstream = new Bitstream(cQuat, qbits);
 }
Exemplo n.º 25
0
        /// <summary>
        /// Return the smallest bit culling level that will be able to communicate the changes between two compressed elements.
        /// </summary>
        public static BitCullingLevel FindBestBitCullLevel(CompressedElement a, CompressedElement b, ElementCrusher ec, BitCullingLevel maxCulling)
        {
            /// Quats can't cull upper bits, so its an all or nothing. Either the bits match or they don't
            if (ec.TRSType == TRSType.Quaternion)
            {
                if (a.cQuat == b.cQuat)
                {
                    return(BitCullingLevel.DropAll);
                }
                else
                {
                    return(BitCullingLevel.NoCulling);
                }
            }

            if (maxCulling == BitCullingLevel.NoCulling || !TestMatchingUpper(a, b, ec, BitCullingLevel.DropThird))
            {
                return(BitCullingLevel.NoCulling);
            }

            if (maxCulling == BitCullingLevel.DropThird || !TestMatchingUpper(a, b, ec, BitCullingLevel.DropHalf))
            {
                return(BitCullingLevel.DropThird);
            }

            if (maxCulling == BitCullingLevel.DropHalf || a != b)
            {
                return(BitCullingLevel.DropHalf);
            }

            // both values are the same
            return(BitCullingLevel.DropAll);
        }
Exemplo n.º 26
0
 // Constructor for uniform scale
 public CompressedElement(ElementCrusher crusher, uint cUniform, int ubits) : this()
 {
     this.crusher   = crusher;
     this.cUniform  = cUniform;
     this.bitstream = new Bitstream(cUniform, ubits);
 }
Exemplo n.º 27
0
 public static bool TestMatchingUpper(CompressedElement prevPos, CompressedElement b, ElementCrusher ar, BitCullingLevel bcl)
 {
     return
         (
         TestMatchingUpper(prevPos.cx, b.cx, ar[0].GetBitsAtCullLevel(bcl)) &&
         TestMatchingUpper(prevPos.cy, b.cy, ar[1].GetBitsAtCullLevel(bcl)) &&
         TestMatchingUpper(prevPos.cz, b.cz, ar[2].GetBitsAtCullLevel(bcl))
         );
 }
Exemplo n.º 28
0
 public static CompressedElement ZeroUpperBits(this CompressedElement fullpos, ElementCrusher ec, BitCullingLevel bcl)
 {
     return(new CompressedElement(
                fullpos.crusher,
                ec[0].ZeroUpperBits(fullpos.cx, bcl),
                ec[1].ZeroUpperBits(fullpos.cy, bcl),
                ec[2].ZeroUpperBits(fullpos.cz, bcl)
                ));
 }
Exemplo n.º 29
0
 /// <summary>
 /// Replace the upperbits of the first compressed element with the upper bits of the second, using BitCullingLevel as the separation point.
 /// </summary>
 public static CompressedElement OverwriteUpperBits(this CompressedElement low, CompressedElement up, ElementCrusher 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)
                ));
 }
Exemplo n.º 30
0
 /// <summary>
 /// Alternative to OverwriteUpperBits that attempts to guess the upperbits by seeing if each axis of the new position would be
 /// closer to the old one if the upper bit is incremented by one, two, three etc. Stops trying when it fails to get a better result.
 /// </summary>
 /// <param name="oldcpos">Last best position test against.</param>
 /// <returns>Returns a corrected CompressPos</returns>
 public static CompressedElement GuessUpperBits(this CompressedElement newcpos, CompressedElement oldcpos, ElementCrusher 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)
                ));
 }