/// 24 bit vector3. This is a trivial optimization, and not amazing in terms of commpression. private static short SerializeVector3Compressed(StreamBuffer outStream, object customobject) { Vector3 v = (Vector3)customobject; /// Short sacrifices one value (-32768) - but encodes 0 simply and precisely UintToBytes qV = new UintToBytes(); qV.data = CompressFloatToUint24(v.x); outStream.WriteBytes(qV.byte0, qV.byte1, qV.byte2); qV.data = CompressFloatToUint24(v.y); outStream.WriteBytes(qV.byte0, qV.byte1, qV.byte2); qV.data = CompressFloatToUint24(v.z); outStream.WriteBytes(qV.byte0, qV.byte1, qV.byte2); return(9); }
private static object DeserializeVector3Compressed(StreamBuffer inStream, short length) { Vector3 v = new Vector3(); UintToBytes qV = new UintToBytes(); qV.byte0 = (byte)inStream.ReadByte(); qV.byte1 = (byte)inStream.ReadByte(); qV.byte2 = (byte)inStream.ReadByte(); v.x = DecompressFloatFromUint24(qV.data); qV.byte0 = (byte)inStream.ReadByte(); qV.byte1 = (byte)inStream.ReadByte(); qV.byte2 = (byte)inStream.ReadByte(); v.y = DecompressFloatFromUint24(qV.data); qV.byte0 = (byte)inStream.ReadByte(); qV.byte1 = (byte)inStream.ReadByte(); qV.byte2 = (byte)inStream.ReadByte(); v.z = DecompressFloatFromUint24(qV.data); return(v); }