From d109dcc1f874de76dfc19e94a9810ce927355758 Mon Sep 17 00:00:00 2001 From: lancej Date: Sat, 9 Dec 2006 07:55:46 +0000 Subject: [PATCH] * ImportCommand now creates prims. * Added SetTextures, SetLight, SetFlexible functions to ObjectManager. * Added XML defaults to ParticleSystem and TextureAnimation. * Fixed an XML default for LLQuaternion. git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@698 52acb1d6-8a22-11de-b505-999d5b087335 --- libsecondlife-cs/ObjectManager.cs | 83 +++++++++++++++++++ libsecondlife-cs/ParticleSystem.cs | 33 ++++---- libsecondlife-cs/Textures.cs | 19 +++-- libsecondlife-cs/Types.cs | 2 +- .../TestClient/Commands/ImportCommand.cs | 69 ++++++++++++++- .../examples/TestClient/TestClient.cs | 8 ++ 6 files changed, 184 insertions(+), 30 deletions(-) diff --git a/libsecondlife-cs/ObjectManager.cs b/libsecondlife-cs/ObjectManager.cs index 6c196891..a024e4bf 100644 --- a/libsecondlife-cs/ObjectManager.cs +++ b/libsecondlife-cs/ObjectManager.cs @@ -583,6 +583,89 @@ namespace libsecondlife Client.Network.SendPacket(add, simulator); } + /// + /// + /// + /// + /// + /// + public void SetTextures(Simulator simulator, uint localID, TextureEntry textures) + { + ObjectImagePacket image = new ObjectImagePacket(); + + image.AgentData.AgentID = Client.Network.AgentID; + image.AgentData.SessionID = Client.Network.SessionID; + image.ObjectData = new ObjectImagePacket.ObjectDataBlock[1]; + image.ObjectData[0] = new ObjectImagePacket.ObjectDataBlock(); + image.ObjectData[0].ObjectLocalID = localID; + image.ObjectData[0].TextureEntry = textures.ToBytes(); + image.ObjectData[0].MediaURL = new byte[0]; + + Client.Network.SendPacket(image, simulator); + } + + /// + /// + /// + /// + /// + /// + public void SetLight(Simulator simulator, uint localID, PrimLightData light) + { + ObjectExtraParamsPacket extra = new ObjectExtraParamsPacket(); + + extra.AgentData.AgentID = Client.Network.AgentID; + extra.AgentData.SessionID = Client.Network.SessionID; + extra.ObjectData = new ObjectExtraParamsPacket.ObjectDataBlock[1]; + extra.ObjectData[0] = new ObjectExtraParamsPacket.ObjectDataBlock(); + extra.ObjectData[0].ObjectLocalID = localID; + extra.ObjectData[0].ParamType = (byte)ExtraParamType.Light; + if (light == null) + { + extra.ObjectData[0].ParamInUse = false; + extra.ObjectData[0].ParamData = new byte[0]; + } + else + { + extra.ObjectData[0].ParamInUse = true; + extra.ObjectData[0].ParamData = light.GetBytes(); + } + extra.ObjectData[0].ParamSize = (uint)extra.ObjectData[0].ParamData.Length; + + Client.Network.SendPacket(extra, simulator); + } + + /// + /// + /// + /// + /// + /// + public void SetFlexible(Simulator simulator, uint localID, PrimFlexibleData flexible) + { + ObjectExtraParamsPacket extra = new ObjectExtraParamsPacket(); + + extra.AgentData.AgentID = Client.Network.AgentID; + extra.AgentData.SessionID = Client.Network.SessionID; + extra.ObjectData = new ObjectExtraParamsPacket.ObjectDataBlock[1]; + extra.ObjectData[0] = new ObjectExtraParamsPacket.ObjectDataBlock(); + extra.ObjectData[0].ObjectLocalID = localID; + extra.ObjectData[0].ParamType = (byte)ExtraParamType.Flexible; + if (flexible == null) + { + extra.ObjectData[0].ParamInUse = false; + extra.ObjectData[0].ParamData = new byte[0]; + } + else + { + extra.ObjectData[0].ParamInUse = true; + extra.ObjectData[0].ParamData = flexible.GetBytes(); + } + extra.ObjectData[0].ParamSize = (uint)extra.ObjectData[0].ParamData.Length; + + Client.Network.SendPacket(extra, simulator); + } + /// /// /// diff --git a/libsecondlife-cs/ParticleSystem.cs b/libsecondlife-cs/ParticleSystem.cs index e6653a7b..85e64844 100644 --- a/libsecondlife-cs/ParticleSystem.cs +++ b/libsecondlife-cs/ParticleSystem.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Xml.Serialization; namespace libsecondlife @@ -58,35 +59,35 @@ namespace libsecondlife } /// - [XmlAttribute("startrgba")] public uint PartStartRGBA; + [XmlAttribute("startrgba"), DefaultValue(0)] public uint PartStartRGBA; /// - [XmlAttribute("endrgba")] public uint PartEndRGBA; + [XmlAttribute("endrgba"), DefaultValue(0)] public uint PartEndRGBA; /// - [XmlAttribute("maxage")] public float PartMaxAge; + [XmlAttribute("maxage"), DefaultValue(0)] public float PartMaxAge; /// - [XmlAttribute("srcmaxage")] public float SrcMaxAge; + [XmlAttribute("srcmaxage"), DefaultValue(0)] public float SrcMaxAge; /// - [XmlAttribute("srcanglebegin")] public float SrcAngleBegin; + [XmlAttribute("srcanglebegin"), DefaultValue(0)] public float SrcAngleBegin; /// - [XmlAttribute("srcangleend")] public float SrcAngleEnd; + [XmlAttribute("srcangleend"), DefaultValue(0)] public float SrcAngleEnd; /// - [XmlAttribute("srcburstpartcount")] public int SrcBurstPartCount; + [XmlAttribute("srcburstpartcount"), DefaultValue(0)] public int SrcBurstPartCount; /// - [XmlAttribute("srcburstradius")] public float SrcBurstRadius; + [XmlAttribute("srcburstradius"), DefaultValue(0)] public float SrcBurstRadius; /// - [XmlAttribute("srcburstrate")] public float SrcBurstRate; + [XmlAttribute("srcburstrate"), DefaultValue(0)] public float SrcBurstRate; /// - [XmlAttribute("srcburstspeedmin")] public float SrcBurstSpeedMin; + [XmlAttribute("srcburstspeedmin"), DefaultValue(0)] public float SrcBurstSpeedMin; /// - [XmlAttribute("srcburstspeedmax")] public float SrcBurstSpeedMax; + [XmlAttribute("srcburstspeedmax"), DefaultValue(0)] public float SrcBurstSpeedMax; /// Unknown - [XmlAttribute("version")] public uint Version; + [XmlAttribute("serial"), DefaultValue(0)] public uint Serial; /// Unknown - [XmlAttribute("starttick")] public uint StartTick; + [XmlAttribute("starttick"), DefaultValue(0)] public uint StartTick; /// - [XmlAttribute("srcpattern")] public SourcePattern SrcPattern; + [XmlAttribute("srcpattern"), DefaultValue(SourcePattern.None)] public SourcePattern SrcPattern = SourcePattern.None; /// Various options that describe the behavior of this system - [XmlAttribute("particleflags")] public ParticleFlags PartFlags; + [XmlAttribute("particleflags"), DefaultValue(ParticleFlags.None)] public ParticleFlags PartFlags = ParticleFlags.None; /// [XmlElement("srctarget")] public LLUUID SrcTargetKey = LLUUID.Zero; /// Texture that will be applied to the particles @@ -140,7 +141,7 @@ namespace libsecondlife if (data.Length == 0) return; - Version = (uint)(data[i++] + (data[i++] << 8) + + Serial = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24)); StartTick = (uint)(data[i++] + (data[i++] << 8) + diff --git a/libsecondlife-cs/Textures.cs b/libsecondlife-cs/Textures.cs index fcc3a7ce..7c605711 100644 --- a/libsecondlife-cs/Textures.cs +++ b/libsecondlife-cs/Textures.cs @@ -28,6 +28,7 @@ using System; using System.Collections.Generic; using System.Xml; using System.Xml.Serialization; +using System.ComponentModel; using System.IO; namespace libsecondlife @@ -394,8 +395,8 @@ namespace libsecondlife binWriter.Write(GetFaceBitfieldBytes(kv.Value)); binWriter.Write(kv.Key); } - - return memStream.GetBuffer(); + + return memStream.ToArray(); } private byte[] GetFaceBitfieldBytes(uint bitfield) @@ -844,19 +845,19 @@ namespace libsecondlife public class TextureAnimation { /// - [XmlAttribute("flags")] public uint Flags; + [XmlAttribute("flags"), DefaultValue(0)] public uint Flags; /// - [XmlAttribute("face")] public uint Face; + [XmlAttribute("face"), DefaultValue(0)] public uint Face; /// - [XmlAttribute("sizex")] public uint SizeX; + [XmlAttribute("sizex"), DefaultValue(0)] public uint SizeX; /// - [XmlAttribute("sizey")] public uint SizeY; + [XmlAttribute("sizey"), DefaultValue(0)] public uint SizeY; /// - [XmlAttribute("start")] public float Start; + [XmlAttribute("start"), DefaultValue(0)] public float Start; /// - [XmlAttribute("length")] public float Length; + [XmlAttribute("length"), DefaultValue(0)] public float Length; /// - [XmlAttribute("rate")] public float Rate; + [XmlAttribute("rate"), DefaultValue(0)] public float Rate; /// /// Default constructor diff --git a/libsecondlife-cs/Types.cs b/libsecondlife-cs/Types.cs index dd6eb3ac..17baeee4 100644 --- a/libsecondlife-cs/Types.cs +++ b/libsecondlife-cs/Types.cs @@ -682,7 +682,7 @@ namespace libsecondlife /// Z value [XmlAttribute("z"), DefaultValue(0)] public float Z; /// W value - [XmlAttribute("w"), DefaultValue(1)] public float W; + [XmlAttribute("w"), DefaultValue(0)] public float W; ///// ///// Default constructor, initializes to no rotation (0,0,0,1) diff --git a/libsecondlife-cs/examples/TestClient/Commands/ImportCommand.cs b/libsecondlife-cs/examples/TestClient/Commands/ImportCommand.cs index aee961fe..0337b3b7 100644 --- a/libsecondlife-cs/examples/TestClient/Commands/ImportCommand.cs +++ b/libsecondlife-cs/examples/TestClient/Commands/ImportCommand.cs @@ -3,16 +3,27 @@ using System.Collections.Generic; using libsecondlife; using libsecondlife.Packets; using System.Xml; +using System.Threading; using System.Xml.Serialization; using System.IO; + namespace libsecondlife.TestClient { public class ImportCommand : Command { + PrimObject currentPrim; + LLVector3 currentPosition; + SecondLife currentClient; + ManualResetEvent primDone; + List primsCreated; + bool registeredCreateEvent; + public ImportCommand() { Name = "import"; Description = "Import prims from an exported xml file. Usage: import [filename.xml]"; + primDone = new ManualResetEvent(false); + registeredCreateEvent = false; } public override string Execute(SecondLife Client, string[] args, LLUUID fromAgentID) @@ -21,7 +32,8 @@ namespace libsecondlife.TestClient return "Usage: import inputfile.xml"; string name = args[0]; - List prims; + + Dictionary prims; try { @@ -35,7 +47,13 @@ namespace libsecondlife.TestClient events.OnUnknownElement += new XmlElementEventHandler(OnUnknownElement); events.OnUnknownNode += new XmlNodeEventHandler(OnUnknownNode); events.OnUnreferencedObject += new UnreferencedObjectEventHandler(OnUnreferenced); - prims = (List)serializer.Deserialize(XmlReader.Create(name), events); + List listprims = (List)serializer.Deserialize(XmlReader.Create(name), events); + + prims = new Dictionary(); + foreach (PrimObject prim in listprims) + { + prims.Add(prim.LocalID, prim); + } //return list; } catch (Exception ex) @@ -43,8 +61,51 @@ namespace libsecondlife.TestClient return "Deserialize failed: " + ex.ToString(); } - // deserialization done, just need to code to rez and link. - return "Deserialized " + prims.Count + " prims, rez code missing."; + if (!registeredCreateEvent) + { + TestClient.OnPrimCreated += new TestClient.PrimCreatedCallback(TestClient_OnPrimCreated); + registeredCreateEvent = true; + } + + primsCreated = new List(); + Console.WriteLine("Importing " + prims.Count + " prims."); + + foreach (PrimObject prim in prims.Values) + { + currentPrim = prim; + currentClient = Client; + if (prim.ParentID != 0) + { + if (prims.ContainsKey(prim.ParentID)) + { + currentPosition = prims[prim.ParentID].Position + prim.Position; + } + else + { + return "Rez failed, a child prim did not have a matching parent prim. "; + } + } + else + { + currentPosition = prim.Position; + } + Client.Objects.AddPrim(Client.Network.CurrentSim, prim, currentPosition); + if (!primDone.WaitOne(10000, false)) + return "Rez failed, timed out while creating a prim."; + primDone.Reset(); + } + + return "Import complete."; + } + + void TestClient_OnPrimCreated(Simulator simulator, PrimObject prim) + { + primsCreated.Add(prim); + currentClient.Objects.SetPosition(simulator, prim.LocalID, currentPosition); + currentClient.Objects.SetTextures(simulator, prim.LocalID, currentPrim.Textures); + //currentClient.Objects.SetLight(simulator, prim.LocalID, currentPrim.Light); + //currentClient.Objects.SetFlexible(simulator, prim.LocalID, currentPrim.Flexible); + primDone.Set(); } void OnUnknownAttribute(object obj, XmlAttributeEventArgs args) diff --git a/libsecondlife-cs/examples/TestClient/TestClient.cs b/libsecondlife-cs/examples/TestClient/TestClient.cs index c773845a..97208eba 100644 --- a/libsecondlife-cs/examples/TestClient/TestClient.cs +++ b/libsecondlife-cs/examples/TestClient/TestClient.cs @@ -27,6 +27,9 @@ namespace libsecondlife.TestClient public bool Running = true; public string Master = ""; + public delegate void PrimCreatedCallback(Simulator simulator, PrimObject prim); + public event PrimCreatedCallback OnPrimCreated; + private LLQuaternion bodyRotation = LLQuaternion.Identity; private LLVector3 forward = new LLVector3(0, 0.9999f, 0); private LLVector3 left = new LLVector3(0.9999f, 0, 0); @@ -322,6 +325,11 @@ Begin: { Prims[prim.LocalID] = prim; } + + if ((prim.Flags & ObjectFlags.CreateSelected) != 0 && OnPrimCreated != null) + { + OnPrimCreated(simulator, prim); + } } private void Objects_OnNewAvatar(Simulator simulator, Avatar avatar, ulong regionHandle, ushort timeDilation)