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])); } }
public Element Decompress(ulong cval) { if (!cached) { CacheValues(); } if (_trsType == TRSType.Scale && uniformAxes != UniformAxes.NonUniform) { float val = ucrusher.Decompress((uint)cval); 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(cval)); } else { // Issue log error for trying to write more than 64 bits to the ulong buffer FloatCrusherUtilities.CheckBitCount(cache_TotalBits[0], 64); int bitposition = 0; return(new Vector3( cache_xEnabled ? (xcrusher.ReadAndDecompress(ref cval, ref bitposition)) : 0, cache_yEnabled ? (ycrusher.ReadAndDecompress(ref cval, ref bitposition)) : 0, cache_zEnabled ? (zcrusher.ReadAndDecompress(ref cval, ref bitposition)) : 0 )); } }
public CompressedElement Write(Vector3 v3, byte[] bytes, ref int bitposition, BitCullingLevel bcl = BitCullingLevel.NoCulling) { if (!cached) { CacheValues(); } if (cache_isUniformScale) { uint c = (uint)ucrusher.Write(uniformAxes == UniformAxes.YZ ? v3.y : v3.x, bytes, ref bitposition, bcl); return(new CompressedElement(this, c, cache_uBits[(int)bcl])); } else if (TRSType == TRSType.Quaternion) { ulong c = qcrusher.Write(Quaternion.Euler(v3), bytes, ref bitposition); return(new CompressedElement(this, c, cache_qBits)); } else if (cache_mustCorrectRotationX) { v3 = FloatCrusherUtilities.GetXCorrectedEuler(v3); } return(new CompressedElement( this, (uint)(cache_xEnabled ? (uint)xcrusher.Write(v3.x, bytes, ref bitposition, bcl) : 0), (uint)(cache_yEnabled ? (uint)ycrusher.Write(v3.y, bytes, ref bitposition, bcl) : 0), (uint)(cache_zEnabled ? (uint)zcrusher.Write(v3.z, bytes, ref bitposition, bcl) : 0), cache_xBits[(int)bcl], cache_yBits[(int)bcl], cache_zBits[(int)bcl])); }