private void SendAgentSetAppearance() { AgentSetAppearancePacket set = new AgentSetAppearancePacket(); set.AgentData.AgentID = Client.Self.AgentID; set.AgentData.SessionID = Client.Self.SessionID; set.AgentData.SerialNum = SetAppearanceSerialNum++; set.VisualParam = new AgentSetAppearancePacket.VisualParamBlock[VisualParams.Params.Count]; float AgentSizeVPHeight = 0.0f; float AgentSizeVPHeelHeight = 0.0f; float AgentSizeVPPlatformHeight = 0.0f; float AgentSizeVPHeadSize = 0.0f; float AgentSizeVPLegLength = 0.0f; float AgentSizeVPNeckLength = 0.0f; float AgentSizeVPHipLength = 0.0f; lock (Wearables.Dictionary) { // Only for debugging output int count = 0, vpIndex = 0; // Build the visual param array foreach (KeyValuePair<int, VisualParam> kvp in VisualParams.Params) { bool found = false; set.VisualParam[vpIndex] = new AgentSetAppearancePacket.VisualParamBlock(); VisualParam vp = kvp.Value; // Try and find this value in our collection of downloaded wearables foreach (WearableData data in Wearables.Dictionary.Values) { if (data.Asset != null && data.Asset.Params.ContainsKey(vp.ParamID)) { set.VisualParam[vpIndex].ParamValue = Helpers.FloatToByte(data.Asset.Params[vp.ParamID], vp.MinValue, vp.MaxValue); found = true; count++; switch (vp.ParamID) { case 33: AgentSizeVPHeight = data.Asset.Params[vp.ParamID]; break; case 198: AgentSizeVPHeelHeight = data.Asset.Params[vp.ParamID]; break; case 503: AgentSizeVPPlatformHeight = data.Asset.Params[vp.ParamID]; break; case 682: AgentSizeVPHeadSize = data.Asset.Params[vp.ParamID]; break; case 692: AgentSizeVPLegLength = data.Asset.Params[vp.ParamID]; break; case 756: AgentSizeVPNeckLength = data.Asset.Params[vp.ParamID]; break; case 842: AgentSizeVPHipLength = data.Asset.Params[vp.ParamID]; break; } break; } } // Use a default value if we don't have one set for it if (!found) { set.VisualParam[vpIndex].ParamValue = Helpers.FloatToByte(vp.DefaultValue, vp.MinValue, vp.MaxValue); switch (vp.ParamID) { case 33: AgentSizeVPHeight = vp.DefaultValue; break; case 198: AgentSizeVPHeelHeight = vp.DefaultValue; break; case 503: AgentSizeVPPlatformHeight = vp.DefaultValue; break; case 682: AgentSizeVPHeadSize = vp.DefaultValue; break; case 692: AgentSizeVPLegLength = vp.DefaultValue; break; case 756: AgentSizeVPNeckLength = vp.DefaultValue; break; case 842: AgentSizeVPHipLength = vp.DefaultValue; break; } } vpIndex++; } Client.DebugLog("AgentSetAppearance contains " + count + " VisualParams"); // Build the texture entry for our agent LLObject.TextureEntry te = new LLObject.TextureEntry(DEFAULT_AVATAR_TEXTURE); // Put our AgentTextures array in to TextureEntry lock (AgentTextures) { for (uint i = 0; i < AgentTextures.Length; i++) { if (AgentTextures[i] != LLUUID.Zero) { LLObject.TextureEntryFace face = te.CreateFace(i); face.TextureID = AgentTextures[i]; } } } foreach (WearableData data in Wearables.Dictionary.Values) { if (data.Asset != null) { foreach (KeyValuePair<TextureIndex, LLUUID> texture in data.Asset.Textures) { LLObject.TextureEntryFace face = te.CreateFace((uint)texture.Key); face.TextureID = texture.Value; Client.DebugLog("Setting texture " + ((TextureIndex)texture.Key).ToString() + " to " + texture.Value.ToString()); } } } // Set the packet TextureEntry set.ObjectData.TextureEntry = te.ToBytes(); } // FIXME: Our hackish algorithm is making squished avatars. See // http://www.libsecondlife.org/wiki/Agent_Size for discussion of the correct algorithm //float height = Helpers.ByteToFloat(set.VisualParam[33].ParamValue, VisualParams.Params[33].MinValue, // VisualParams.Params[33].MaxValue); // Takes into account the Shoe Heel/Platform offsets but not the Head Size Offset. But seems to work. double AgentSizeBase = 1.706; // The calculation for the Head Size scalar may be incorrect. But seems to work. double AgentHeight = AgentSizeBase + (AgentSizeVPLegLength * .1918) + (AgentSizeVPHipLength * .0375) + (AgentSizeVPHeight * .12022) + (AgentSizeVPHeadSize * .01117) + (AgentSizeVPNeckLength * .038) + (AgentSizeVPHeelHeight * .08) + (AgentSizeVPPlatformHeight * .07); set.AgentData.Size = new LLVector3(0.45f, 0.6f, (float)AgentHeight); // TODO: Account for not having all the textures baked yet set.WearableData = new AgentSetAppearancePacket.WearableDataBlock[BAKED_TEXTURE_COUNT]; // Build hashes for each of the bake layers from the individual components for (int bakedIndex = 0; bakedIndex < BAKED_TEXTURE_COUNT; bakedIndex++) { LLUUID hash = new LLUUID(); for (int wearableIndex = 0; wearableIndex < WEARABLES_PER_LAYER; wearableIndex++) { WearableType type = WEARABLE_BAKE_MAP[bakedIndex][wearableIndex]; LLUUID assetID = GetWearableAsset(type); // Build a hash of all the texture asset IDs in this baking layer if (assetID != LLUUID.Zero) hash ^= assetID; } if (hash != LLUUID.Zero) { // Hash with our secret value for this baked layer hash ^= BAKED_TEXTURE_HASH[bakedIndex]; } // Tell the server what cached texture assetID to use for each bake layer set.WearableData[bakedIndex] = new AgentSetAppearancePacket.WearableDataBlock(); set.WearableData[bakedIndex].TextureIndex = (byte)bakedIndex; set.WearableData[bakedIndex].CacheID = hash; } // Finally, send the packet Client.Network.SendPacket(set); }
public void TextureEntry() { LLObject.TextureEntry te = new LLObject.TextureEntry(LLUUID.Random()); LLObject.TextureEntryFace face = te.CreateFace(0); face.Bump = Bumpiness.Concrete; face.Fullbright = true; face.MediaFlags = true; face.OffsetU = 0.5f; face.OffsetV = -0.5f; face.RepeatU = 3.0f; face.RepeatV = 4.0f; face.RGBA = new LLColor(0f, 0.25f, 0.75f, 1f); face.Rotation = 1.5f; face.Shiny = Shininess.Medium; face.TexMapType = MappingType.Planar; face.TextureID = LLUUID.Random(); byte[] teBytes = te.ToBytes(); LLObject.TextureEntry te2 = new LLObject.TextureEntry(teBytes, 0, teBytes.Length); byte[] teBytes2 = te2.ToBytes(); Assert.IsTrue(teBytes.Length == teBytes2.Length); for (int i = 0; i < teBytes.Length; i++) { Assert.IsTrue(teBytes[i] == teBytes2[i], "Byte " + i + " is not equal"); } }
private void SendAgentSetAppearance() { AgentSetAppearancePacket set = new AgentSetAppearancePacket(); set.AgentData.AgentID = Client.Self.AgentID; set.AgentData.SessionID = Client.Self.SessionID; set.AgentData.SerialNum = SetAppearanceSerialNum++; set.VisualParam = new AgentSetAppearancePacket.VisualParamBlock[VisualParams.Params.Count]; lock (Wearables) { // Only for debugging output int count = 0, vpIndex = 0; // Build the visual param array foreach (KeyValuePair<int,VisualParam> kvp in VisualParams.Params) { bool found = false; set.VisualParam[vpIndex] = new AgentSetAppearancePacket.VisualParamBlock(); VisualParam vp = kvp.Value; // Try and find this value in our collection of downloaded wearables foreach (WearableData data in Wearables.Values) { if (data.Asset != null && data.Asset.Params.ContainsKey(vp.ParamID)) { set.VisualParam[vpIndex].ParamValue = Helpers.FloatToByte(data.Asset.Params[vp.ParamID], vp.MinValue, vp.MaxValue); found = true; count++; break; } } // Use a default value if we don't have one set for it if (!found) { set.VisualParam[vpIndex].ParamValue = Helpers.FloatToByte(vp.DefaultValue, vp.MinValue, vp.MaxValue); } vpIndex++; } Client.DebugLog("AgentSetAppearance contains " + count + " VisualParams"); // Build the texture entry for our agent LLObject.TextureEntry te = new LLObject.TextureEntry(DEFAULT_AVATAR_TEXTURE); // Put our AgentTextures array in to TextureEntry lock (AgentTextures) { for (uint i = 0; i < AgentTextures.Length; i++) { if (AgentTextures[i] != LLUUID.Zero) { LLObject.TextureEntryFace face = te.CreateFace(i); face.TextureID = AgentTextures[i]; } } } foreach (WearableData data in Wearables.Values) { if (data.Asset != null) { foreach (KeyValuePair<TextureIndex, LLUUID> texture in data.Asset.Textures) { LLObject.TextureEntryFace face = te.CreateFace((uint)texture.Key); face.TextureID = texture.Value; Client.DebugLog("Setting texture " + ((TextureIndex)texture.Key).ToString() + " to " + texture.Value.ToString()); } } } // Set the packet TextureEntry set.ObjectData.TextureEntry = te.ToBytes(); } // FIXME: Our hackish algorithm is making squished avatars. See // http://www.libsecondlife.org/wiki/Agent_Size for discussion of the correct algorithm float height = Helpers.ByteToFloat(set.VisualParam[33].ParamValue, VisualParams.Params[33].MinValue, VisualParams.Params[33].MaxValue); set.AgentData.Size = new LLVector3(0.45f, 0.6f, 1.50856f + ((height / 255.0f) * (2.025506f - 1.50856f))); // TODO: Account for not having all the textures baked yet set.WearableData = new AgentSetAppearancePacket.WearableDataBlock[BAKED_TEXTURE_COUNT]; // Build hashes for each of the bake layers from the individual components for (int bakedIndex = 0; bakedIndex < BAKED_TEXTURE_COUNT; bakedIndex++) { LLUUID hash = new LLUUID(); for (int wearableIndex = 0; wearableIndex < WEARABLES_PER_LAYER; wearableIndex++) { WearableType type = WEARABLE_BAKE_MAP[bakedIndex][wearableIndex]; LLUUID assetID = GetWearableAsset(type); // Build a hash of all the texture asset IDs in this baking layer if (assetID != LLUUID.Zero) hash ^= assetID; } if (hash != LLUUID.Zero) { // Hash with our secret value for this baked layer hash ^= BAKED_TEXTURE_HASH[bakedIndex]; } // Tell the server what cached texture assetID to use for each bake layer set.WearableData[bakedIndex] = new AgentSetAppearancePacket.WearableDataBlock(); set.WearableData[bakedIndex].TextureIndex = (byte)bakedIndex; set.WearableData[bakedIndex].CacheID = hash; } // Finally, send the packet Client.Network.SendPacket(set); }
public void CreateFromStorage(PrimData store, LLVector3 posi, uint localID, bool newprim) { //need to clean this up as it shares a lot of code with CreateFromPacket() ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); objupdate.RegionData.RegionHandle = m_regionHandle; objupdate.RegionData.TimeDilation = 64096; objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; this.primData = store; objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock(); objupdate.ObjectData[0].PSBlock = new byte[0]; objupdate.ObjectData[0].ExtraParams = new byte[1]; objupdate.ObjectData[0].MediaURL = new byte[0]; objupdate.ObjectData[0].NameValue = new byte[0]; objupdate.ObjectData[0].Text = new byte[0]; objupdate.ObjectData[0].TextColor = new byte[4]; objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0); objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0); objupdate.ObjectData[0].Material = 3; objupdate.ObjectData[0].UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456; objupdate.ObjectData[0].TextureAnim = new byte[0]; objupdate.ObjectData[0].Sound = LLUUID.Zero; if (store.Texture == null) { LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005")); objupdate.ObjectData[0].TextureEntry = ntex.ToBytes(); } else { objupdate.ObjectData[0].TextureEntry = store.Texture; } objupdate.ObjectData[0].State = 0; objupdate.ObjectData[0].Data = new byte[0]; objupdate.ObjectData[0].OwnerID = this.primData.OwnerID; objupdate.ObjectData[0].PCode = this.primData.PCode; objupdate.ObjectData[0].PathBegin = this.primData.PathBegin; objupdate.ObjectData[0].PathEnd = this.primData.PathEnd; objupdate.ObjectData[0].PathScaleX = this.primData.PathScaleX; objupdate.ObjectData[0].PathScaleY = this.primData.PathScaleY; objupdate.ObjectData[0].PathShearX = this.primData.PathShearX; objupdate.ObjectData[0].PathShearY = this.primData.PathShearY; objupdate.ObjectData[0].PathSkew = this.primData.PathSkew; objupdate.ObjectData[0].ProfileBegin = this.primData.ProfileBegin; objupdate.ObjectData[0].ProfileEnd = this.primData.ProfileEnd; objupdate.ObjectData[0].Scale = this.primData.Scale; objupdate.ObjectData[0].PathCurve = this.primData.PathCurve; objupdate.ObjectData[0].ProfileCurve = this.primData.ProfileCurve; objupdate.ObjectData[0].ParentID = 0; objupdate.ObjectData[0].ProfileHollow = this.primData.ProfileHollow; //finish off copying rest of shape data objupdate.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset; objupdate.ObjectData[0].PathRevolutions = this.primData.PathRevolutions; objupdate.ObjectData[0].PathTaperX = this.primData.PathTaperX; objupdate.ObjectData[0].PathTaperY = this.primData.PathTaperY; objupdate.ObjectData[0].PathTwist = this.primData.PathTwist; objupdate.ObjectData[0].PathTwistBegin = this.primData.PathTwistBegin; objupdate.ObjectData[0].ID = localID; // (uint)store.LocalID; objupdate.ObjectData[0].FullID = store.FullID; objupdate.ObjectData[0].ObjectData = new byte[60]; objupdate.ObjectData[0].ObjectData[46] = 128; objupdate.ObjectData[0].ObjectData[47] = 63; LLVector3 pos1 = posi; // store.Position; //update position byte[] pb = pos1.GetBytes(); Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length); this.uuid = objupdate.ObjectData[0].FullID; this.localid = objupdate.ObjectData[0].ID; this.Pos = pos1; this.OurPacket = objupdate; if (newprim) { this.newPrimFlag = true; } }
public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID agentID, uint localID) { ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); objupdate.RegionData.RegionHandle = m_regionHandle; objupdate.RegionData.TimeDilation = 64096; objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; PrimData PData = new PrimData(); this.primData = PData; this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock(); objupdate.ObjectData[0].PSBlock = new byte[0]; objupdate.ObjectData[0].ExtraParams = new byte[1]; objupdate.ObjectData[0].MediaURL = new byte[0]; objupdate.ObjectData[0].NameValue = new byte[0]; objupdate.ObjectData[0].Text = new byte[0]; objupdate.ObjectData[0].TextColor = new byte[4]; objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0); objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0); objupdate.ObjectData[0].Material = 3; objupdate.ObjectData[0].UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456; objupdate.ObjectData[0].TextureAnim = new byte[0]; objupdate.ObjectData[0].Sound = LLUUID.Zero; LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005")); this.primData.Texture = objupdate.ObjectData[0].TextureEntry = ntex.ToBytes(); objupdate.ObjectData[0].State = 0; objupdate.ObjectData[0].Data = new byte[0]; PData.OwnerID = objupdate.ObjectData[0].OwnerID = agentID; PData.PCode = objupdate.ObjectData[0].PCode = addPacket.ObjectData.PCode; PData.PathBegin = objupdate.ObjectData[0].PathBegin = addPacket.ObjectData.PathBegin; PData.PathEnd = objupdate.ObjectData[0].PathEnd = addPacket.ObjectData.PathEnd; PData.PathScaleX = objupdate.ObjectData[0].PathScaleX = addPacket.ObjectData.PathScaleX; PData.PathScaleY = objupdate.ObjectData[0].PathScaleY = addPacket.ObjectData.PathScaleY; PData.PathShearX = objupdate.ObjectData[0].PathShearX = addPacket.ObjectData.PathShearX; PData.PathShearY = objupdate.ObjectData[0].PathShearY = addPacket.ObjectData.PathShearY; PData.PathSkew = objupdate.ObjectData[0].PathSkew = addPacket.ObjectData.PathSkew; PData.ProfileBegin = objupdate.ObjectData[0].ProfileBegin = addPacket.ObjectData.ProfileBegin; PData.ProfileEnd = objupdate.ObjectData[0].ProfileEnd = addPacket.ObjectData.ProfileEnd; PData.Scale = objupdate.ObjectData[0].Scale = addPacket.ObjectData.Scale; PData.PathCurve = objupdate.ObjectData[0].PathCurve = addPacket.ObjectData.PathCurve; PData.ProfileCurve = objupdate.ObjectData[0].ProfileCurve = addPacket.ObjectData.ProfileCurve; PData.ParentID = objupdate.ObjectData[0].ParentID = 0; PData.ProfileHollow = objupdate.ObjectData[0].ProfileHollow = addPacket.ObjectData.ProfileHollow; PData.PathRadiusOffset = objupdate.ObjectData[0].PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset; PData.PathRevolutions = objupdate.ObjectData[0].PathRevolutions = addPacket.ObjectData.PathRevolutions; PData.PathTaperX = objupdate.ObjectData[0].PathTaperX = addPacket.ObjectData.PathTaperX; PData.PathTaperY = objupdate.ObjectData[0].PathTaperY = addPacket.ObjectData.PathTaperY; PData.PathTwist = objupdate.ObjectData[0].PathTwist = addPacket.ObjectData.PathTwist; PData.PathTwistBegin = objupdate.ObjectData[0].PathTwistBegin = addPacket.ObjectData.PathTwistBegin; objupdate.ObjectData[0].ID = (uint)(localID); objupdate.ObjectData[0].FullID = new LLUUID("edba7151-5857-acc5-b30b-f01efef" + (localID - 702000).ToString("00000")); objupdate.ObjectData[0].ObjectData = new byte[60]; objupdate.ObjectData[0].ObjectData[46] = 128; objupdate.ObjectData[0].ObjectData[47] = 63; LLVector3 pos1 = addPacket.ObjectData.RayEnd; //update position byte[] pb = pos1.GetBytes(); Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length); this.newPrimFlag = true; this.primData.FullID = this.uuid = objupdate.ObjectData[0].FullID; this.localid = objupdate.ObjectData[0].ID; this.primData.Position = this.Pos = pos1; this.OurPacket = objupdate; }
protected static void SetDefaultPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata) { objdata.PSBlock = new byte[0]; objdata.ExtraParams = new byte[1]; objdata.MediaURL = new byte[0]; objdata.NameValue = new byte[0]; objdata.Text = new byte[0]; objdata.TextColor = new byte[4]; objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0); objdata.JointPivot = new LLVector3(0, 0, 0); objdata.Material = 4; objdata.TextureAnim = new byte[0]; objdata.Sound = LLUUID.Zero; LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005")); objdata.TextureEntry = ntex.ToBytes(); objdata.State = 0; objdata.Data = new byte[0]; objdata.ObjectData = new byte[76]; objdata.ObjectData[15] = 128; objdata.ObjectData[16] = 63; objdata.ObjectData[56] = 128; objdata.ObjectData[61] = 102; objdata.ObjectData[62] = 40; objdata.ObjectData[63] = 61; objdata.ObjectData[64] = 189; }
protected void SetDefaultPacketValues(ObjectUpdatePacket.ObjectDataBlock objdata) { objdata.PSBlock = new byte[0]; objdata.ExtraParams = new byte[1]; objdata.MediaURL = new byte[0]; objdata.NameValue = new byte[0]; objdata.Text = new byte[0]; objdata.TextColor = new byte[4]; objdata.JointAxisOrAnchor = new LLVector3(0, 0, 0); objdata.JointPivot = new LLVector3(0, 0, 0); objdata.Material = 3; objdata.TextureAnim = new byte[0]; objdata.Sound = LLUUID.Zero; LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005")); this.primData.Texture = objdata.TextureEntry = ntex.ToBytes(); objdata.State = 0; objdata.Data = new byte[0]; objdata.ObjectData = new byte[60]; objdata.ObjectData[46] = 128; objdata.ObjectData[47] = 63; }