/// <summary> /// Asserts that the contents of the SDBinary match the values and length /// of the supplied byte array /// </summary> /// <param name="inBinary"></param> /// <param name="inExpected"></param> private void TestBinary(OSDBinary inBinary, byte[] inExpected) { byte[] binary = inBinary.AsBinary(); Assert.AreEqual(inExpected.Length, binary.Length); for (int i = 0; i < inExpected.Length; i++) { if (inExpected[i] != binary[i]) { Assert.Fail("Expected " + inExpected[i].ToString() + " at position " + i.ToString() + " but saw " + binary[i].ToString()); } } }
/// <summary> /// Create an OSDMap from the appearance data /// </summary> public OSDMap Pack() { OSDMap data = new OSDMap(); data["owner"] = OSD.FromUUID(Owner); data["serial"] = OSD.FromInteger(m_serial); data["height"] = OSD.FromReal(m_avatarHeight); // Wearables List <AvatarWearable> wearables = GetWearables(); OSDArray wears = new OSDArray(wearables.Count); foreach (AvatarWearable wearable in wearables) { wears.Add(wearable.Pack()); } data["wearables"] = wears; // Avatar Textures OSDArray textures = new OSDArray(AvatarAppearance.TEXTURE_COUNT); for (uint i = 0; i < AvatarAppearance.TEXTURE_COUNT; i++) { if (m_texture.FaceTextures[i] != null) { textures.Add(OSD.FromUUID(m_texture.FaceTextures[i].TextureID)); } else { textures.Add(OSD.FromUUID(AppearanceManager.DEFAULT_AVATAR_TEXTURE)); } } data["textures"] = textures; // Visual Parameters OSDBinary visualparams = new OSDBinary(m_visualparams); data["visualparams"] = visualparams; // Attachments List <AvatarAttachment> attachments = GetAttachments(); OSDArray attachs = new OSDArray(attachments.Count); foreach (AvatarAttachment attach in attachments) { attachs.Add(attach.Pack()); } data["attachments"] = attachs; return(data); }
public void DeserializeBinary() { OSD theSD = null; OSDArray array = null; OSDBinary tempBinary = null; String testSD = @"<?xml version='1.0' encoding='UTF-8'?> <llsd> <array> <binary encoding='base64'>cmFuZG9t</binary> <binary>dGhlIHF1aWNrIGJyb3duIGZveA==</binary> <binary/> </array> </llsd>"; //Deserialize the string byte[] bytes = Encoding.UTF8.GetBytes(testSD); theSD = OSDParser.DeserializeLLSDXml(bytes); Assert.IsTrue(theSD is OSDArray); array = (OSDArray)theSD; Assert.AreEqual(OSDType.Binary, array[0].Type); tempBinary = (OSDBinary)array[0]; byte[] testData1 = { 114, 97, 110, 100, 111, 109 }; TestBinary(tempBinary, testData1); Assert.AreEqual(OSDType.Binary, array[1].Type); tempBinary = (OSDBinary)array[1]; byte[] testData2 = { 116, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 102, 111, 120 }; TestBinary(tempBinary, testData2); Assert.AreEqual(OSDType.Binary, array[1].Type); tempBinary = (OSDBinary)array[2]; Assert.AreEqual(0, tempBinary.AsBinary().Length); }
/// <summary> /// Create an OSDMap from the appearance data /// </summary> public OSDMap Pack() { OSDMap data = new OSDMap(); data["serial"] = OSD.FromInteger(m_serial); data["height"] = OSD.FromReal(m_avatarHeight); // Wearables OSDArray wears = new OSDArray(AvatarWearable.MAX_WEARABLES); for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++) wears.Add(m_wearables[i].Pack()); data["wearables"] = wears; // Avatar Textures OSDArray textures = new OSDArray(AvatarAppearance.TEXTURE_COUNT); for (uint i = 0; i < AvatarAppearance.TEXTURE_COUNT; i++) { if (m_texture.FaceTextures[i] != null) textures.Add(OSD.FromUUID(m_texture.FaceTextures[i].TextureID)); else textures.Add(OSD.FromUUID(AppearanceManager.DEFAULT_AVATAR_TEXTURE)); } data["textures"] = textures; // Visual Parameters OSDBinary visualparams = new OSDBinary(m_visualparams); data["visualparams"] = visualparams; // Attachments OSDArray attachs = new OSDArray(m_attachments.Count); foreach (AvatarAttachment attach in GetAttachments()) attachs.Add(attach.Pack()); data["attachments"] = attachs; return data; }
/// <summary> /// Create an OSDMap from the appearance data /// </summary> public OSDMap Pack(EntityTransferContext ctx) { OSDMap data = new OSDMap(); data["serial"] = OSD.FromInteger(m_serial); data["height"] = OSD.FromReal(m_avatarHeight); // Wearables // // This will send as many or as few wearables as we have, unless a count // is given. Used for legacy (pre 0.4) versions. int count = ctx.WearablesCount; if (ctx.WearablesCount == -1) count = m_wearables.Length; OSDArray wears = new OSDArray(count); for (int i = 0; i < count; i++) { AvatarWearable dummyWearable = new AvatarWearable(); if (i < m_wearables.Length) wears.Add(m_wearables[i].Pack()); else wears.Add(dummyWearable.Pack()); } data["wearables"] = wears; // Avatar Textures OSDArray textures = new OSDArray(AvatarAppearance.TEXTURE_COUNT); for (uint i = 0; i < AvatarAppearance.TEXTURE_COUNT; i++) { if (m_texture.FaceTextures[i] != null) textures.Add(OSD.FromUUID(m_texture.FaceTextures[i].TextureID)); else textures.Add(OSD.FromUUID(AppearanceManager.DEFAULT_AVATAR_TEXTURE)); } data["textures"] = textures; if (m_cacheitems != null) { OSDArray baked = WearableCacheItem.BakedToOSD(m_cacheitems); if (baked != null) data["bakedcache"] = baked; } // Visual Parameters OSDBinary visualparams = new OSDBinary(m_visualparams); data["visualparams"] = visualparams; lock (m_attachments) { // Attachments OSDArray attachs = new OSDArray(m_attachments.Count); foreach (AvatarAttachment attach in GetAttachments()) attachs.Add(attach.Pack()); data["attachments"] = attachs; } return data; }
/// <summary> /// Create an OSDMap from the appearance data /// </summary> public OSDMap Pack() { OSDMap block1 = new OSDMap(); block1["regionID"] = OSD.FromUUID(regionID); OSDArray block2 = new OSDArray(2); block2.Add(currentFloat); block2.Add(currentSetting); OSDMap block3 = new OSDMap(); block3["regionID"] = OSD.FromUUID(regionID); block3["fresnel_scale"] = OSD.FromReal(fresnelScale); block3["fresnel_offset"] = OSD.FromReal(fresnelOffset); #if false data["water_color_r"] = OSD.FromReal(waterColor.X); data["water_color_g"] = OSD.FromReal(waterColor.Y); data["water_color_b"] = OSD.FromReal(waterColor.Z); data["water_fog_density_exponent"] = OSD.FromReal(waterFogDensityExponent); data["reflection_wavelet_scale_1"] = OSD.FromReal(reflectionWaveletScale.X); data["reflection_wavelet_scale_2"] = OSD.FromReal(reflectionWaveletScale.Y); data["reflection_wavelet_scale_3"] = OSD.FromReal(reflectionWaveletScale.Z); data["refract_scale_above"] = OSD.FromReal(refractScaleAbove); data["refract_scale_below"] = OSD.FromReal(refractScaleBelow); data["blur_multiplier"] = OSD.FromReal(blurMultiplier); data["big_wave_direction_x"] = OSD.FromReal(bigWaveDirection.X); data["big_wave_direction_y"] = OSD.FromReal(bigWaveDirection.Y); data["little_wave_direction_x"] = OSD.FromReal(littleWaveDirection.X); data["little_wave_direction_y"] = OSD.FromReal(littleWaveDirection.Y); data["normal_map_texture"] = OSD.FromUUID(normalMapTexture); data["x"] = OSD.FromReal(x); data["x"] = OSD.FromReal(x); // Wearables List<AvatarWearable> wearables = GetWearables(); OSDArray wears = new OSDArray(wearables.Count); foreach (AvatarWearable wearable in wearables) wears.Add(wearable.Pack()); data["wearables"] = wears; // Avatar Textures OSDArray textures = new OSDArray(AvatarAppearance.TEXTURE_COUNT); for (uint i = 0; i < AvatarAppearance.TEXTURE_COUNT; i++) { if (m_texture.FaceTextures[i] != null) textures.Add(OSD.FromUUID(m_texture.FaceTextures[i].TextureID)); else textures.Add(OSD.FromUUID(AppearanceManager.DEFAULT_AVATAR_TEXTURE)); } data["textures"] = textures; // Visual Parameters OSDBinary visualparams = new OSDBinary(m_visualparams); data["visualparams"] = visualparams; // Attachments List<AvatarAttachment> attachments = GetAttachments(); OSDArray attachs = new OSDArray(attachments.Count); foreach (AvatarAttachment attach in attachments) attachs.Add(attach.Pack()); data["attachments"] = attachs; #endif return block1; }
/// <summary> /// Create an OSDMap from the appearance data /// </summary> public OSDMap Pack() { OSDMap block1 = new OSDMap(); block1["regionID"] = OSD.FromUUID(regionID); OSDArray block2 = new OSDArray(2); block2.Add(currentFloat); block2.Add(currentSetting); OSDMap block3 = new OSDMap(); block3["regionID"] = OSD.FromUUID(regionID); block3["fresnel_scale"] = OSD.FromReal(fresnelScale); block3["fresnel_offset"] = OSD.FromReal(fresnelOffset); #if false data["water_color_r"] = OSD.FromReal(waterColor.X); data["water_color_g"] = OSD.FromReal(waterColor.Y); data["water_color_b"] = OSD.FromReal(waterColor.Z); data["water_fog_density_exponent"] = OSD.FromReal(waterFogDensityExponent); data["reflection_wavelet_scale_1"] = OSD.FromReal(reflectionWaveletScale.X); data["reflection_wavelet_scale_2"] = OSD.FromReal(reflectionWaveletScale.Y); data["reflection_wavelet_scale_3"] = OSD.FromReal(reflectionWaveletScale.Z); data["refract_scale_above"] = OSD.FromReal(refractScaleAbove); data["refract_scale_below"] = OSD.FromReal(refractScaleBelow); data["blur_multiplier"] = OSD.FromReal(blurMultiplier); data["big_wave_direction_x"] = OSD.FromReal(bigWaveDirection.X); data["big_wave_direction_y"] = OSD.FromReal(bigWaveDirection.Y); data["little_wave_direction_x"] = OSD.FromReal(littleWaveDirection.X); data["little_wave_direction_y"] = OSD.FromReal(littleWaveDirection.Y); data["normal_map_texture"] = OSD.FromUUID(normalMapTexture); data["x"] = OSD.FromReal(x); data["x"] = OSD.FromReal(x); // Wearables List <AvatarWearable> wearables = GetWearables(); OSDArray wears = new OSDArray(wearables.Count); foreach (AvatarWearable wearable in wearables) { wears.Add(wearable.Pack()); } data["wearables"] = wears; // Avatar Textures OSDArray textures = new OSDArray(AvatarAppearance.TEXTURE_COUNT); for (uint i = 0; i < AvatarAppearance.TEXTURE_COUNT; i++) { if (m_texture.FaceTextures[i] != null) { textures.Add(OSD.FromUUID(m_texture.FaceTextures[i].TextureID)); } else { textures.Add(OSD.FromUUID(AppearanceManager.DEFAULT_AVATAR_TEXTURE)); } } data["textures"] = textures; // Visual Parameters OSDBinary visualparams = new OSDBinary(m_visualparams); data["visualparams"] = visualparams; // Attachments List <AvatarAttachment> attachments = GetAttachments(); OSDArray attachs = new OSDArray(attachments.Count); foreach (AvatarAttachment attach in attachments) { attachs.Add(attach.Pack()); } data["attachments"] = attachs; #endif return(block1); }
/// <summary> /// Create an OSDMap from the appearance data /// </summary> public OSDMap Pack() { if (m_log.IsDebugEnabled) { m_log.DebugFormat ("{0} called", System.Reflection.MethodBase.GetCurrentMethod ().Name); } OSDMap data = new OSDMap(); data["serial"] = OSD.FromInteger(m_serial); data["height"] = OSD.FromReal(m_avatarHeight); // Hashes OSDArray hashes = new OSDArray(AvatarAppearance.TEXTURE_COUNT); for (uint i = 0; i < AvatarAppearance.TEXTURE_COUNT; i++) hashes.Add(OSD.FromUUID(m_texturehashes[i])); data["hashes"] = hashes; // Wearables OSDArray wears = new OSDArray(AvatarWearable.MAX_WEARABLES); for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++) wears.Add(m_wearables[i].Pack()); data["wearables"] = wears; // Avatar Textures OSDArray textures = new OSDArray(AvatarAppearance.TEXTURE_COUNT); for (uint i = 0; i < AvatarAppearance.TEXTURE_COUNT; i++) { if (m_texture.FaceTextures[i] != null) textures.Add(OSD.FromUUID(m_texture.FaceTextures[i].TextureID)); else textures.Add(OSD.FromUUID(AppearanceManager.DEFAULT_AVATAR_TEXTURE)); } data["textures"] = textures; // Visual Parameters OSDBinary visualparams = new OSDBinary(m_visualparams); data["visualparams"] = visualparams; // Attachments List<AvatarAttachment> attachments = GetAttachments(); OSDArray attachs = new OSDArray(attachments.Count); foreach (AvatarAttachment attach in GetAttachments()) attachs.Add(attach.Pack()); data["attachments"] = attachs; return data; }
//The input, two ODSMaps, are assumed to be packed by AvatarAppearance.Pack(), //that is, they each have the fields: //serial //height //wearables //textures //visualparams //attachments private bool PropertyValueEquals_AvatarAppearance(OSDMap sceneValue, OSDMap syncValue) { if (sceneValue.ContainsKey("serial") && syncValue.ContainsKey("serial")) { if (!sceneValue["serial"].AsInteger().Equals(syncValue["serial"].AsInteger())) { return(false); } } if (sceneValue.ContainsKey("height") && syncValue.ContainsKey("height")) { if (!sceneValue["height"].AsReal().Equals(syncValue["height"].AsReal())) { return(false); } } if (sceneValue.ContainsKey("wearables") && syncValue.ContainsKey("wearables")) { OSDArray sceneWears = (OSDArray)sceneValue["wearables"]; OSDArray syncWears = (OSDArray)syncValue["wearables"]; if (sceneWears.Count != syncWears.Count) { return(false); } if (!sceneWears.ToString().Equals(syncWears.ToString())) { return(false); } } if (sceneValue.ContainsKey("textures") && syncValue.ContainsKey("textures")) { OSDArray sceneTextures = (OSDArray)sceneValue["textures"]; OSDArray syncTextures = (OSDArray)syncValue["textures"]; if (sceneTextures.Count != syncTextures.Count) { return(false); } if (!sceneTextures.ToString().Equals(syncTextures.ToString())) { return(false); } } if (sceneValue.ContainsKey("visualparams") && syncValue.ContainsKey("visualparams")) { OSDBinary sceneTextures = (OSDBinary)sceneValue["visualparams"]; OSDBinary syncTextures = (OSDBinary)syncValue["visualparams"]; byte[] sceneBytes = sceneTextures.AsBinary(); byte[] syncBytes = syncTextures.AsBinary(); if (sceneBytes.Length != syncBytes.Length) { return(false); } for (int i = 0; i < sceneBytes.Length; i++) { if (!sceneBytes[i].Equals(syncBytes[i])) { return(false); } } } if (sceneValue.ContainsKey("attachments") && syncValue.ContainsKey("attachments")) { OSDArray sceneAttachs = (OSDArray)sceneValue["attachments"]; OSDArray syncAttachs = (OSDArray)syncValue["attachments"]; if (sceneAttachs.Count != syncAttachs.Count) { return(false); } if (!sceneAttachs.ToString().Equals(syncAttachs.ToString())) { return(false); } } return(true); }