/// <summary> /// /// </summary> /// <returns></returns> public byte[] ToBytes() { byte[] data = new byte[16]; int i = 0; data[i] = (byte)((Softness & 2) << 6); data[i + 1] = (byte)((Softness & 1) << 7); data[i++] |= (byte)((byte)(Tension * 10.0f) & 0x7F); data[i++] |= (byte)((byte)(Drag * 10.0f) & 0x7F); data[i++] = (byte)((Gravity + 10.0f) * 10.0f); data[i++] = (byte)(Wind * 10.0f); Force.GetBytes().CopyTo(data, i); return(data); }
/// <summary> /// /// </summary> /// <returns></returns> public byte[] GetBytes() { byte[] data = new byte[16]; int i = 0; // Softness is packed in the upper bits of tension and drag data[i] = (byte)((Softness & 2) << 6); data[i + 1] = (byte)((Softness & 1) << 7); data[i++] |= (byte)((byte)(Tension * 10.01f) & 0x7F); data[i++] |= (byte)((byte)(Drag * 10.01f) & 0x7F); data[i++] = (byte)((Gravity + 10.0f) * 10.01f); data[i++] = (byte)(Wind * 10.01f); Force.GetBytes().CopyTo(data, i); return(data); }
/// <summary> /// Change the position of an object /// </summary> /// <param name="simulator">A reference to the <seealso cref="libsecondlife.Simulator"/> object where the object resides</param> /// <param name="localID">The objects ID which is local to the simulator the object is in</param> /// <param name="position">The new position of the object</param> public void SetPosition(Simulator simulator, uint localID, LLVector3 position) { MultipleObjectUpdatePacket multiObjectUpdate = new MultipleObjectUpdatePacket(); multiObjectUpdate.AgentData.AgentID = Client.Self.AgentID; multiObjectUpdate.AgentData.SessionID = Client.Self.SessionID; multiObjectUpdate.ObjectData = new MultipleObjectUpdatePacket.ObjectDataBlock[1]; multiObjectUpdate.ObjectData[0] = new MultipleObjectUpdatePacket.ObjectDataBlock(); multiObjectUpdate.ObjectData[0].Type = 9; multiObjectUpdate.ObjectData[0].ObjectLocalID = localID; multiObjectUpdate.ObjectData[0].Data = position.GetBytes(); Client.Network.SendPacket(multiObjectUpdate, simulator); }
public static void SetupTemplate(string name) { FileInfo fInfo = new FileInfo(name); long numBytes = fInfo.Length; FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fStream); byte[] data1 = br.ReadBytes((int)numBytes); br.Close(); fStream.Close(); libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata = new ObjectUpdatePacket.ObjectDataBlock(); // new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i); SetDefaultPacketValues(objdata); objdata.TextureEntry = data1; objdata.UpdateFlags = 61 + (9 << 8) + (130 << 16) + (16 << 24); objdata.PathCurve = 16; objdata.ProfileCurve = 1; objdata.PathScaleX = 100; objdata.PathScaleY = 100; objdata.ParentID = 0; objdata.OwnerID = LLUUID.Zero; objdata.Scale = new LLVector3(1, 1, 1); objdata.PCode = 47; System.Text.Encoding enc = System.Text.Encoding.ASCII; libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16); pos.X = 100f; objdata.ID = 8880000; objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0"); libsecondlife.LLVector3 pos2 = new LLVector3(100f, 100f, 23f); //objdata.FullID=user.AgentID; byte[] pb = pos.GetBytes(); Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length); Avatar.AvatarTemplate = objdata; }
private void cmdImport_Click(object sender, System.EventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Title = "Open Prim.Blender File"; openDialog.Filter = "All files (*.*)|*.*|Prim files (*.prims)|*.prims" ; openDialog.FilterIndex = 2; if(openDialog.ShowDialog() != DialogResult.OK) { return; } XmlDocument xml = new XmlDocument(); XmlNodeList list = null; try { // Try to load the xml file xml.Load(openDialog.FileName); //If there is a document and it has children, if(xml != null && xml.HasChildNodes) { //Get the children into the temp list list = xml.GetElementsByTagName("primitive"); } else { txtLog.AppendText("ERROR: Failed to parse " + openDialog.FileName + "\n"); return; } } catch (Exception err) { txtLog.AppendText("ERROR: " + err.ToString() + "\n"); return; } foreach (XmlNode node in list) { txtLog.AppendText("Parsing primitive " + node.Attributes["key"].Value + "\n"); XmlNode properties = node["properties"]; PrimObject prim = new PrimObject(new LLUUID("8955674724cb43ed920b47caed15465f")); prim.Material = Convert.ToUInt16(properties["material"].Attributes["val"].Value); prim.Name = node.Attributes["key"].Value; // Either PathBegin/End or ProfileBegin/End should be dimple prim.PathBegin = PrimObject.PathBeginByte(Convert.ToSingle(properties["cut"].Attributes["x"].Value)); prim.PathEnd = PrimObject.PathEndByte(Convert.ToSingle(properties["cut"].Attributes["y"].Value)); prim.PathRadiusOffset = PrimObject.PathRadiusOffsetByte(Convert.ToSingle(properties["radiusoffset"].Attributes["val"].Value)); prim.PathRevolutions = PrimObject.PathRevolutionsByte(Convert.ToSingle(properties["revolutions"].Attributes["val"].Value)); prim.PathScaleX = PrimObject.PathScaleByte(Convert.ToSingle(properties["topsize"].Attributes["x"].Value)); prim.PathScaleY = PrimObject.PathScaleByte(Convert.ToSingle(properties["topsize"].Attributes["y"].Value)); prim.PathShearX = PrimObject.PathShearByte(Convert.ToSingle(properties["topshear"].Attributes["x"].Value)); prim.PathShearY = PrimObject.PathShearByte(Convert.ToSingle(properties["topshear"].Attributes["y"].Value)); prim.PathSkew = PrimObject.PathSkewByte(Convert.ToSingle(properties["skew"].Attributes["val"].Value)); prim.PathTaperX = PrimObject.PathTaperByte(Convert.ToSingle(properties["taper"].Attributes["x"].Value)); prim.PathTaperY = PrimObject.PathTaperByte(Convert.ToSingle(properties["taper"].Attributes["y"].Value)); prim.PathTwist = PrimObject.PathTwistByte(Convert.ToSingle(properties["twist"].Attributes["y"].Value)); prim.PathTwistBegin = PrimObject.PathTwistByte(Convert.ToSingle(properties["twist"].Attributes["x"].Value)); prim.ProfileBegin = PrimObject.ProfileBeginByte(Convert.ToSingle(properties["cut"].Attributes["x"].Value)); prim.ProfileEnd = PrimObject.ProfileEndByte(Convert.ToSingle(properties["cut"].Attributes["y"].Value)); ushort curve = Convert.ToUInt16(properties["type"].Attributes["val"].Value); switch (curve) { case 0: // Box prim.ProfileCurve = 1; prim.PathCurve = 16; break; case 1: // Cylinder prim.ProfileCurve = 0; prim.PathCurve = 16; break; case 2: // Prism prim.ProfileCurve = 3; prim.PathCurve = 16; break; case 3: // Sphere prim.ProfileCurve = 5; prim.PathCurve = 32; break; case 4: // Torus prim.ProfileCurve = 0; prim.PathCurve = 32; break; case 5: // Tube prim.ProfileCurve = 1; prim.PathCurve = 32; break; case 6: // Ring prim.ProfileCurve = 3; prim.PathCurve = 16; break; } prim.ProfileHollow = Convert.ToUInt32(properties["hollow"].Attributes["val"].Value); prim.Rotation = new LLQuaternion( Convert.ToSingle(properties["rotation"].Attributes["x"].Value), Convert.ToSingle(properties["rotation"].Attributes["y"].Value), Convert.ToSingle(properties["rotation"].Attributes["z"].Value), Convert.ToSingle(properties["rotation"].Attributes["s"].Value)); prim.Scale = new LLVector3( Convert.ToSingle(properties["size"].Attributes["x"].Value), Convert.ToSingle(properties["size"].Attributes["y"].Value), Convert.ToSingle(properties["size"].Attributes["z"].Value)); LLVector3 position = new LLVector3( Convert.ToSingle(properties["position"].Attributes["x"].Value) + (float)Client.Avatar.Position.X, Convert.ToSingle(properties["position"].Attributes["y"].Value) + (float)Client.Avatar.Position.Y, Convert.ToSingle(properties["position"].Attributes["z"].Value) + (float)Client.Avatar.Position.Z + 50.0F); prim.Position = position; CurrentPrim = prim; WaitingOnUpdate = true; Client.CurrentRegion.RezObject(prim, position, new LLVector3(Client.Avatar.Position)); while (WaitingOnUpdate) { System.Threading.Thread.Sleep(100); Application.DoEvents(); } txtLog.AppendText("Rezzed primitive with UUID " + CurrentPrim.UUID + " and ID " + CurrentPrim.ID + " \n"); Hashtable blocks = new Hashtable(); Hashtable fields = new Hashtable(); /*fields["ObjectLocalID"] = CurrentPrim.ID; blocks[fields] = "ObjectData"; fields = new Hashtable(); fields["AgentID"] = Client.Network.AgentID; blocks[fields] = "AgentData"; Packet packet = PacketBuilder.BuildPacket("ObjectSelect", Client.Protocol, blocks, Helpers.MSG_RELIABLE); Client.Network.SendPacket(packet); System.Threading.Thread.Sleep(100);*/ Packet packet; byte[] byteArray = new byte[12]; Array.Copy(position.GetBytes(), byteArray, 12); fields["Data"] = byteArray; fields["Type"] = (byte)9; fields["ObjectLocalID"] = CurrentPrim.ID; blocks[fields] = "ObjectData"; fields = new Hashtable(); fields["AgentID"] = Client.Network.AgentID; blocks[fields] = "AgentData"; packet = PacketBuilder.BuildPacket("MultipleObjectUpdate", Client.Protocol, blocks, Helpers.MSG_RELIABLE); Client.Network.SendPacket(packet); Client.Network.SendPacket(packet); Client.Network.SendPacket(packet); System.Threading.Thread.Sleep(500); } }
//test only private void SetupTemplate(string name) { //should be replaced with completely code generated packets int i = 0; FileInfo fInfo = new FileInfo(name); long numBytes = fInfo.Length; FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fStream); byte [] data1 = br.ReadBytes((int)numBytes); br.Close(); fStream.Close(); libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock objdata = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock(data1, ref i); System.Text.Encoding enc = System.Text.Encoding.ASCII; libsecondlife.LLVector3 pos = new LLVector3(objdata.ObjectData, 16); pos.X = 100f; objdata.ID = 8880000; objdata.NameValue = enc.GetBytes("FirstName STRING RW SV Test \nLastName STRING RW SV User \0"); libsecondlife.LLVector3 pos2 = new LLVector3(13.981f,100.0f,20.0f); //objdata.FullID=user.AgentID; byte[] pb = pos.GetBytes(); Array.Copy(pb, 0, objdata.ObjectData, 16, pb.Length); _avatarTemplate = objdata; }
/// <summary> /// Send a Multiple Object Update packet to change the size, scale or rotation of a primitive /// </summary> /// <param name="simulator">A reference to the <seealso cref="libsecondlife.Simulator"/> object where the object resides</param> /// <param name="localID">The objects ID which is local to the simulator the object is in</param> /// <param name="data">The new rotation, size, or position of the target object</param> /// <param name="type">The flags from the <seealso cref="UpdateType"/> Enum</param> public void UpdateObject(Simulator simulator, uint localID, LLVector3 data, UpdateType type) { MultipleObjectUpdatePacket multiObjectUpdate = new MultipleObjectUpdatePacket(); multiObjectUpdate.AgentData.AgentID = Client.Self.AgentID; multiObjectUpdate.AgentData.SessionID = Client.Self.SessionID; multiObjectUpdate.ObjectData = new MultipleObjectUpdatePacket.ObjectDataBlock[1]; multiObjectUpdate.ObjectData[0] = new MultipleObjectUpdatePacket.ObjectDataBlock(); multiObjectUpdate.ObjectData[0].Type = (byte)type; multiObjectUpdate.ObjectData[0].ObjectLocalID = localID; multiObjectUpdate.ObjectData[0].Data = data.GetBytes(); Client.Network.SendPacket(multiObjectUpdate, simulator); }
private void SendAvatarDataToAll(AvatarData avatar) { ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); objupdate.RegionData.RegionHandle = Globals.Instance.RegionHandle; objupdate.RegionData.TimeDilation = 0; objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; objupdate.ObjectData[0] = _avatarTemplate; objupdate.ObjectData[0].ID = avatar.LocalID; objupdate.ObjectData[0].FullID = avatar.NetInfo.User.AgentID; objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + avatar.NetInfo.User.FirstName + "\nLastName STRING RW SV " + avatar.NetInfo.User.LastName + " \0"); libsecondlife.LLVector3 pos2 = new LLVector3(100f, 100.0f, 22.0f); byte[] pb = pos2.GetBytes(); Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length); SendInfo send = new SendInfo(); send.Incr = true; send.NetInfo = avatar.NetInfo; send.Packet = objupdate; send.SentTo = 1; //to all clients this._updateSender.SendList.Enqueue(send); }
//test only private void SendAvatarData(NetworkInfo userInfo) { ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); objupdate.RegionData.RegionHandle = Globals.Instance.RegionHandle; objupdate.RegionData.TimeDilation = 64096; objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; objupdate.ObjectData[0] = _avatarTemplate; //give this avatar object a local id and assign the user a name objupdate.ObjectData[0].ID = 8880000;// + this._localNumber; userInfo.User.AvatarLocalID = objupdate.ObjectData[0].ID; //User_info.name="Test"+this.local_numer+" User"; //this.GetAgent(userInfo.UserAgentID).Started = true; objupdate.ObjectData[0].FullID = userInfo.User.AgentID; objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + userInfo.User.FirstName + "\nLastName STRING RW SV " + userInfo.User.LastName + " \0"); //userInfo.User.FullName = "FirstName STRING RW SV " + userInfo.first_name + "\nLastName STRING RW SV " + userInfo.last_name + " \0"; libsecondlife.LLVector3 pos2 = new LLVector3(100f, 100.0f, 22.0f); byte[] pb = pos2.GetBytes(); Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length); //this._localNumber++; _server.SendPacket(objupdate, true, userInfo); }
public ObjectUpdatePacket CreateUpdatePacket() { System.Text.Encoding _enc = System.Text.Encoding.ASCII; //send a objectupdate packet with information about the clients avatar ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); objupdate.RegionData.RegionHandle = m_regionHandle; objupdate.RegionData.TimeDilation = 64096; objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; objupdate.ObjectData[0] = AvatarTemplate; //give this avatar object a local id and assign the user a name objupdate.ObjectData[0].ID = this.localid; objupdate.ObjectData[0].FullID = ControllingClient.AgentID; objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0"); libsecondlife.LLVector3 pos2 = new LLVector3((float)this._physActor.Position.X, (float)this._physActor.Position.Y, (float)this._physActor.Position.Z); byte[] pb = pos2.GetBytes(); Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length); return objupdate; }
public void SendInitialPosition() { System.Text.Encoding _enc = System.Text.Encoding.ASCII; //send a objectupdate packet with information about the clients avatar ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); objupdate.RegionData.RegionHandle = m_regionHandle; objupdate.RegionData.TimeDilation = 64096; objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; objupdate.ObjectData[0] = AvatarTemplate; //give this avatar object a local id and assign the user a name objupdate.ObjectData[0].ID = this.localid; this.uuid = objupdate.ObjectData[0].FullID = ControllingClient.AgentID; objupdate.ObjectData[0].NameValue = _enc.GetBytes("FirstName STRING RW SV " + firstname + "\nLastName STRING RW SV " + lastname + " \0"); libsecondlife.LLVector3 pos2 = new LLVector3((float)this.Pos.X, (float)this.Pos.Y, (float)this.Pos.Z); byte[] pb = pos2.GetBytes(); Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length); m_world._localNumber++; foreach (SimClient client in m_clientThreads.Values) { client.OutPacket(objupdate); if (client.AgentID != ControllingClient.AgentID) { //the below line is already in Simclient.cs at line number 245 , directly below the call to this method //if there is a problem/bug with that , then lets fix it there rather than duplicating it here //client.ClientAvatar.SendAppearanceToOtherAgent(this.ControllingClient); SendAppearanceToOtherAgent(client); } } }
public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateTerseBlock() { byte[] bytes = new byte[60]; int i = 0; ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock(); dat.TextureEntry = new byte[0];// AvatarTemplate.TextureEntry; libsecondlife.LLVector3 pos2 = new LLVector3(0, 0, 0); lock (m_world.LockPhysicsEngine) { pos2 = new LLVector3(this._physActor.Position.X, this._physActor.Position.Y, this._physActor.Position.Z); } uint ID = this.localid; bytes[i++] = (byte)(ID % 256); bytes[i++] = (byte)((ID >> 8) % 256); bytes[i++] = (byte)((ID >> 16) % 256); bytes[i++] = (byte)((ID >> 24) % 256); bytes[i++] = 0; bytes[i++] = 1; i += 14; bytes[i++] = 128; bytes[i++] = 63; byte[] pb = pos2.GetBytes(); Array.Copy(pb, 0, bytes, i, pb.Length); i += 12; ushort InternVelocityX; ushort InternVelocityY; ushort InternVelocityZ; Axiom.MathLib.Vector3 internDirec = new Axiom.MathLib.Vector3(0, 0, 0); lock (m_world.LockPhysicsEngine) { internDirec = new Axiom.MathLib.Vector3(this._physActor.Velocity.X, this._physActor.Velocity.Y, this._physActor.Velocity.Z); } internDirec = internDirec / 128.0f; internDirec.x += 1; internDirec.y += 1; internDirec.z += 1; InternVelocityX = (ushort)(32768 * internDirec.x); InternVelocityY = (ushort)(32768 * internDirec.y); InternVelocityZ = (ushort)(32768 * internDirec.z); ushort ac = 32767; bytes[i++] = (byte)(InternVelocityX % 256); bytes[i++] = (byte)((InternVelocityX >> 8) % 256); bytes[i++] = (byte)(InternVelocityY % 256); bytes[i++] = (byte)((InternVelocityY >> 8) % 256); bytes[i++] = (byte)(InternVelocityZ % 256); bytes[i++] = (byte)((InternVelocityZ >> 8) % 256); //accel bytes[i++] = (byte)(ac % 256); bytes[i++] = (byte)((ac >> 8) % 256); bytes[i++] = (byte)(ac % 256); bytes[i++] = (byte)((ac >> 8) % 256); bytes[i++] = (byte)(ac % 256); bytes[i++] = (byte)((ac >> 8) % 256); //rot bytes[i++] = (byte)(ac % 256); bytes[i++] = (byte)((ac >> 8) % 256); bytes[i++] = (byte)(ac % 256); bytes[i++] = (byte)((ac >> 8) % 256); bytes[i++] = (byte)(ac % 256); bytes[i++] = (byte)((ac >> 8) % 256); bytes[i++] = (byte)(ac % 256); bytes[i++] = (byte)((ac >> 8) % 256); //rotation vel bytes[i++] = (byte)(ac % 256); bytes[i++] = (byte)((ac >> 8) % 256); bytes[i++] = (byte)(ac % 256); bytes[i++] = (byte)((ac >> 8) % 256); bytes[i++] = (byte)(ac % 256); bytes[i++] = (byte)((ac >> 8) % 256); dat.Data = bytes; return (dat); }