public void Quaternions() { LLQuaternion a = new LLQuaternion(1, 0, 0, 0); LLQuaternion b = new LLQuaternion(1, 0, 0, 0); Assert.IsTrue(a == b, "LLQuaternion comparison operator failed"); LLQuaternion expected = new LLQuaternion(0, 0, 0, -1); LLQuaternion result = a * b; Assert.IsTrue(result == expected, a.ToString() + " * " + b.ToString() + " produced " + result.ToString() + " instead of " + expected.ToString()); a = new LLQuaternion(1, 0, 0, 0); b = new LLQuaternion(0, 1, 0, 0); expected = new LLQuaternion(0, 0, 1, 0); result = a * b; Assert.IsTrue(result == expected, a.ToString() + " * " + b.ToString() + " produced " + result.ToString() + " instead of " + expected.ToString()); a = new LLQuaternion(0, 0, 1, 0); b = new LLQuaternion(0, 1, 0, 0); expected = new LLQuaternion(-1, 0, 0, 0); result = a * b; Assert.IsTrue(result == expected, a.ToString() + " * " + b.ToString() + " produced " + result.ToString() + " instead of " + expected.ToString()); }
protected bool MultipleObjUpdate(SimClient simClient, Packet packet) { MultipleObjectUpdatePacket multipleupdate = (MultipleObjectUpdatePacket)packet; for (int i = 0; i < multipleupdate.ObjectData.Length; i++) { if (multipleupdate.ObjectData[i].Type == 9) //change position { libsecondlife.LLVector3 pos = new LLVector3(multipleupdate.ObjectData[i].Data, 0); foreach (Entity ent in m_world.Entities.Values) { if (ent.localid == multipleupdate.ObjectData[i].ObjectLocalID) { ((OpenSim.world.Primitive)ent).UpdatePosition(pos); } } //should update stored position of the prim } else if (multipleupdate.ObjectData[i].Type == 10)//rotation { libsecondlife.LLQuaternion rot = new LLQuaternion(multipleupdate.ObjectData[i].Data, 0, true); foreach (Entity ent in m_world.Entities.Values) { if (ent.localid == multipleupdate.ObjectData[i].ObjectLocalID) { ent.rotation = new Axiom.MathLib.Quaternion(rot.W, rot.X, rot.Y, rot.Z); ((OpenSim.world.Primitive)ent).UpdateFlag = true; } } } else if (multipleupdate.ObjectData[i].Type == 13)//scale { libsecondlife.LLVector3 scale = new LLVector3(multipleupdate.ObjectData[i].Data, 12); foreach (Entity ent in m_world.Entities.Values) { if (ent.localid == multipleupdate.ObjectData[i].ObjectLocalID) { ((OpenSim.world.Primitive)ent).Scale = scale; } } } } return(true); }
public PrimData(byte[] data) { int i = 0; this.OwnerID = new LLUUID(data, i); i += 16; this.PCode = data[i++]; this.PathBegin = (ushort)(data[i++] + (data[i++] << 8)); this.PathEnd = (ushort)(data[i++] + (data[i++] << 8)); this.PathScaleX = data[i++]; this.PathScaleY = data[i++]; this.PathShearX = data[i++]; this.PathShearY = data[i++]; this.PathSkew = (sbyte)data[i++]; this.ProfileBegin = (ushort)(data[i++] + (data[i++] << 8)); this.ProfileEnd = (ushort)(data[i++] + (data[i++] << 8)); this.Scale = new LLVector3(data, i); i += 12; this.PathCurve = data[i++]; this.ProfileCurve = data[i++]; this.ParentID = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24)); this.ProfileHollow = (ushort)(data[i++] + (data[i++] << 8)); this.PathRadiusOffset = (sbyte)data[i++]; this.PathRevolutions = data[i++]; this.PathTaperX = (sbyte)data[i++]; this.PathTaperY = (sbyte)data[i++]; this.PathTwist = (sbyte)data[i++]; this.PathTwistBegin = (sbyte)data[i++]; ushort length = (ushort)(data[i++] + (data[i++] << 8)); this.Texture = new byte[length]; Array.Copy(data, i, Texture, 0, length); i += length; this.CreationDate = (Int32)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24)); this.OwnerMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24)); this.NextOwnerMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24)); this.GroupMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24)); this.EveryoneMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24)); this.BaseMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24)); this.Position = new LLVector3(data, i); i += 12; this.Rotation = new LLQuaternion(data, i, true); i += 12; this.LocalID = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24)); this.FullID = new LLUUID(data, i); i += 16; }
private static object ParseLLSDBlock(LLSDMap blockData, Type blockType) { object block = Activator.CreateInstance(blockType); // Iterate over each field and set the value if a match was found in the LLSD foreach (FieldInfo field in blockType.GetFields()) { if (blockData.ContainsKey(field.Name)) { Type fieldType = field.FieldType; if (fieldType == typeof(ulong)) { // ulongs come in as a byte array, convert it manually here byte[] bytes = blockData[field.Name].AsBinary(); ulong value = Helpers.BytesToUInt64(bytes); field.SetValue(block, value); } else if (fieldType == typeof(uint)) { // uints come in as a byte array, convert it manually here byte[] bytes = blockData[field.Name].AsBinary(); uint value = Helpers.BytesToUIntBig(bytes); field.SetValue(block, value); } else if (fieldType == typeof(ushort)) { // Just need a bit of manual typecasting love here field.SetValue(block, (ushort)blockData[field.Name].AsInteger()); } else if (fieldType == typeof(byte)) { // Just need a bit of manual typecasting love here field.SetValue(block, (byte)blockData[field.Name].AsInteger()); } else if (fieldType == typeof(short)) { field.SetValue(block, (short)blockData[field.Name].AsInteger()); } else if (fieldType == typeof(string)) { field.SetValue(block, blockData[field.Name].AsString()); } else if (fieldType == typeof(bool)) { field.SetValue(block, blockData[field.Name].AsBoolean()); } else if (fieldType == typeof(float)) { field.SetValue(block, (float)blockData[field.Name].AsReal()); } else if (fieldType == typeof(double)) { field.SetValue(block, blockData[field.Name].AsReal()); } else if (fieldType == typeof(int)) { field.SetValue(block, blockData[field.Name].AsInteger()); } else if (fieldType == typeof(LLUUID)) { field.SetValue(block, blockData[field.Name].AsUUID()); } else if (fieldType == typeof(LLVector3)) { LLVector3 vec = (LLVector3)field.GetValue(block); vec.FromLLSD(blockData[field.Name]); field.SetValue(block, vec); } else if (fieldType == typeof(LLVector4)) { LLVector4 vec = (LLVector4)field.GetValue(block); vec.FromLLSD(blockData[field.Name]); field.SetValue(block, vec); } else if (fieldType == typeof(LLQuaternion)) { LLQuaternion quat = (LLQuaternion)field.GetValue(block); quat.FromLLSD(blockData[field.Name]); field.SetValue(block, quat); } } } // Additional fields come as properties, Handle those as well. foreach (PropertyInfo property in blockType.GetProperties()) { if (blockData.ContainsKey(property.Name)) { LLSDType proptype = blockData[property.Name].Type; MethodInfo set = property.GetSetMethod(); if (proptype.Equals(LLSDType.Binary)) { byte[] bytes = blockData[property.Name].AsBinary(); set.Invoke(block, new object[] { blockData[property.Name].AsBinary() }); } else { set.Invoke(block, new object[] { Helpers.StringToField(blockData[property.Name].AsString()) }); } } } return(block); }
private void ExportPrims() { FileStream file = null; StreamWriter stream = null; try { file = new FileStream(Filename, FileMode.Create); stream = new StreamWriter(file); uint type = 0; string output; stream.WriteLine("<primitives>"); lock (Prims) { foreach (PrimObject prim in Prims.Values) { LLVector3 position = prim.Position; LLQuaternion rotation = prim.Rotation; output = ""; if (prim.ParentID != 0) { // This prim is part of a linkset, we need to adjust it's position and rotation if (Prims.ContainsKey(prim.ParentID)) { // The child prim only stores a relative position, add the world position of the parent prim position += Prims[prim.ParentID].Position; // The child prim only stores a relative rotation, start with the parent prim rotation rotation = rotation * Prims[prim.ParentID].Rotation; } else { // We don't have the base position for this child prim, can't render it Log("Couldn't export child prim " + prim.ID.ToString() + ", parent prim is missing"); continue; } } output += "<primitive name=\"Object\" description=\"\" key=\"Num_000" + prim.LocalID + "\" version=\"2\">" + Environment.NewLine; output += "<states><physics params=\"\">false</physics><temporary params=\"\">false</temporary><phantom params=\"\">false</phantom></states>" + Environment.NewLine; output += "<properties>" + Environment.NewLine + "<levelofdetail val=\"9\" />" + Environment.NewLine; switch (prim.ProfileCurve + prim.PathCurve) { case 17: // PRIM_TYPE_BOX type = 0; break; case 16: // PRIM_TYPE_CYLINDER type = 1; break; case 19: // PRIM_TYPE_PRISM type = 2; break; case 37: // PRIM_TYPE_SPHERE type = 3; break; case 32: // PRIM_TYPE_TORUS type = 4; break; case 33: // PRIM_TYPE_TUBE type = 5; break; case 35: // PRIM_TYPE_RING type = 6; break; default: Log("Not exporting an unhandled prim, ProfileCurve=" + prim.ProfileCurve + ", PathCurve=" + prim.PathCurve); continue; } output += "<type val=\"" + type + "\" />" + Environment.NewLine; output += "<position x=\"" + string.Format("{0:F6}", position.X) + "\" y=\"" + string.Format("{0:F6}", position.Y) + "\" z=\"" + string.Format("{0:F6}", position.Z) + "\" />" + Environment.NewLine; output += "<rotation x=\"" + string.Format("{0:F6}", rotation.X) + "\" y=\"" + string.Format("{0:F6}", rotation.Y) + "\" z=\"" + string.Format("{0:F6}", rotation.Z) + "\" s=\"" + string.Format("{0:F6}", rotation.W) + "\" />" + Environment.NewLine; output += "<size x=\"" + string.Format("{0:F3}", prim.Scale.X) + "\" y=\"" + string.Format("{0:F3}", prim.Scale.Y) + "\" z=\"" + string.Format("{0:F3}", prim.Scale.Z) + "\" />" + Environment.NewLine; if (type == 1) { output += "<cut x=\"" + prim.ProfileBegin + "\" y=\"" + prim.ProfileEnd + "\" />" + Environment.NewLine; output += "<dimple x=\"" + prim.PathBegin + "\" y=\"" + prim.PathEnd + "\" />" + Environment.NewLine; } else { output += "<cut x=\"" + prim.PathBegin + "\" y=\"" + prim.PathEnd + "\" />" + Environment.NewLine; output += "<dimple x=\"" + prim.ProfileBegin + "\" y=\"" + prim.ProfileEnd + "\" />" + Environment.NewLine; } output += "<advancedcut x=\"" + prim.ProfileBegin + "\" y=\"" + prim.ProfileEnd + "\" />" + Environment.NewLine; output += "<hollow val=\"" + prim.ProfileHollow + "\" />" + Environment.NewLine; output += "<twist x=\"" + prim.PathTwistBegin + "\" y=\"" + prim.PathTwist + "\" />" + Environment.NewLine; output += "<topsize x=\"" + Math.Abs(prim.PathScaleX - 1.0F) + "\" y=\"" + Math.Abs(prim.PathScaleY - 1.0F) + "\" />" + Environment.NewLine; output += "<holesize x=\"" + (1.0F - prim.PathScaleX) + "\" y=\"" + (1.0F - prim.PathScaleY) + "\" />" + Environment.NewLine; output += "<topshear x=\"" + prim.PathShearX + "\" y=\"" + prim.PathShearY + "\" />" + Environment.NewLine; output += "<taper x=\"" + /*Math.Abs(prim.PathScaleX - 1.0F)*/ prim.PathTaperX + "\" y=\"" + /*Math.Abs(prim.PathScaleY - 1.0F)*/ prim.PathTaperY + "\" />" + Environment.NewLine; output += "<revolutions val=\"" + prim.PathRevolutions + "\" />" + Environment.NewLine; output += "<radiusoffset val=\"" + prim.PathRadiusOffset + "\" />" + Environment.NewLine; output += "<skew val=\"" + prim.PathSkew + "\" />" + Environment.NewLine; output += "<material val=\"" + prim.Material + "\" />" + Environment.NewLine; // TODO: Hollowshape. 16-21 = circle, 32-37 = square, 48-53 = triangle output += "<hollowshape val=\"0\" />" + Environment.NewLine; output += "<textures params=\"\">" + "</textures>" + "<scripts params=\"\">" + "</scripts>" + Environment.NewLine + "</properties>" + Environment.NewLine + "</primitive>" + Environment.NewLine; stream.WriteLine(output); } } stream.WriteLine("</primitives>"); } catch (Exception e) { MessageBox.Show("There was an error writing the prims file, check the log for details", "primexport Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Log("Error writing prims to " + Filename + ": " + e.ToString()); } finally { if (stream != null) { stream.Close(); } if (file != null) { file.Close(); } cmdExport.Enabled = true; } }
public override string Execute(string[] args, LLUUID fromAgentID) { if (args.Length < 1) { return("Usage: import inputfile.xml [usegroup]"); } string filename = args[0]; LLUUID GroupID = (args.Length > 1) ? Client.GroupID : LLUUID.Zero; string xml; List <Primitive> prims; try { xml = File.ReadAllText(filename); } catch (Exception e) { return(e.Message); } try { prims = Helpers.LLSDToPrimList(LLSDParser.DeserializeXml(xml)); } catch (Exception e) { return("Failed to deserialize " + filename + ": " + e.Message); } // Build an organized structure from the imported prims Dictionary <uint, Linkset> linksets = new Dictionary <uint, Linkset>(); for (int i = 0; i < prims.Count; i++) { Primitive prim = prims[i]; if (prim.ParentID == 0) { if (linksets.ContainsKey(prim.LocalID)) { linksets[prim.LocalID].RootPrim = prim; } else { linksets[prim.LocalID] = new Linkset(prim); } } else { if (!linksets.ContainsKey(prim.ParentID)) { linksets[prim.ParentID] = new Linkset(); } linksets[prim.ParentID].Children.Add(prim); } } primsCreated = new List <Primitive>(); Console.WriteLine("Importing " + linksets.Count + " structures."); foreach (Linkset linkset in linksets.Values) { if (linkset.RootPrim.LocalID != 0) { state = ImporterState.RezzingParent; currentPrim = linkset.RootPrim; // HACK: Import the structure just above our head // We need a more elaborate solution for importing with relative or absolute offsets linkset.RootPrim.Position = Client.Self.SimPosition; linkset.RootPrim.Position.Z += 3.0f; currentPosition = linkset.RootPrim.Position; // Rez the root prim with no rotation LLQuaternion rootRotation = linkset.RootPrim.Rotation; linkset.RootPrim.Rotation = LLQuaternion.Identity; Client.Objects.AddPrim(Client.Network.CurrentSim, linkset.RootPrim.Data, GroupID, linkset.RootPrim.Position, linkset.RootPrim.Scale, linkset.RootPrim.Rotation); if (!primDone.WaitOne(10000, false)) { return("Rez failed, timed out while creating the root prim."); } Client.Objects.SetPosition(Client.Network.CurrentSim, primsCreated[primsCreated.Count - 1].LocalID, linkset.RootPrim.Position); state = ImporterState.RezzingChildren; // Rez the child prims foreach (Primitive prim in linkset.Children) { currentPrim = prim; currentPosition = prim.Position + linkset.RootPrim.Position; Client.Objects.AddPrim(Client.Network.CurrentSim, prim.Data, GroupID, currentPosition, prim.Scale, prim.Rotation); if (!primDone.WaitOne(10000, false)) { return("Rez failed, timed out while creating child prim."); } Client.Objects.SetPosition(Client.Network.CurrentSim, primsCreated[primsCreated.Count - 1].LocalID, currentPosition); } // Create a list of the local IDs of the newly created prims List <uint> primIDs = new List <uint>(primsCreated.Count); primIDs.Add(rootLocalID); // Root prim is first in list. if (linkset.Children.Count != 0) { // Add the rest of the prims to the list of local IDs foreach (Primitive prim in primsCreated) { if (prim.LocalID != rootLocalID) { primIDs.Add(prim.LocalID); } } linkQueue = new List <uint>(primIDs.Count); linkQueue.AddRange(primIDs); // Link and set the permissions + rotation state = ImporterState.Linking; Client.Objects.LinkPrims(Client.Network.CurrentSim, linkQueue); if (primDone.WaitOne(1000 * linkset.Children.Count, false)) { Client.Objects.SetRotation(Client.Network.CurrentSim, rootLocalID, rootRotation); } else { Console.WriteLine("Warning: Failed to link {0} prims", linkQueue.Count); } } else { Client.Objects.SetRotation(Client.Network.CurrentSim, rootLocalID, rootRotation); } // Set permissions on newly created prims Client.Objects.SetPermissions(Client.Network.CurrentSim, primIDs, PermissionWho.Everyone | PermissionWho.Group | PermissionWho.NextOwner, PermissionMask.All, true); state = ImporterState.Idle; } else { // Skip linksets with a missing root prim Console.WriteLine("WARNING: Skipping a linkset with a missing root prim"); } // Reset everything for the next linkset primsCreated.Clear(); } return("Import complete."); }
public override string Execute(string[] args, LLUUID fromAgentID) { if (args.Length != 1) { return("Usage: import inputfile.xml"); } string name = args[0]; Dictionary <uint, PrimObject> prims; currentClient = Client; try { XmlReader reader = XmlReader.Create(name); List <PrimObject> listprims = Helpers.PrimListFromXml(reader); reader.Close(); // Create a dictionary indexed by the old local ID of the prims prims = new Dictionary <uint, PrimObject>(); foreach (PrimObject prim in listprims) { prims.Add(prim.LocalID, prim); } } catch (Exception) { return("Failed to import the object XML file, maybe it doesn't exist or is in the wrong format?"); } if (!registeredCreateEvent) { TestClient.OnPrimCreated += new TestClient.PrimCreatedCallback(TestClient_OnPrimCreated); registeredCreateEvent = true; } // Build an organized structure from the imported prims Dictionary <uint, Linkset> linksets = new Dictionary <uint, Linkset>(); foreach (PrimObject prim in prims.Values) { if (prim.ParentID == 0) { if (linksets.ContainsKey(prim.LocalID)) { linksets[prim.LocalID].RootPrim = prim; } else { linksets[prim.LocalID] = new Linkset(prim); } } else { if (!linksets.ContainsKey(prim.ParentID)) { linksets[prim.ParentID] = new Linkset(); } linksets[prim.ParentID].Children.Add(prim); } } primsCreated = new List <PrimObject>(); linking = false; Console.WriteLine("Importing " + linksets.Count + " structures."); foreach (Linkset linkset in linksets.Values) { if (linkset.RootPrim.LocalID != 0) { // HACK: Offset the root prim position so it's not lying on top of the original // We need a more elaborate solution for importing with relative or absolute offsets linkset.RootPrim.Position.Z += 3.0f; currentPosition = linkset.RootPrim.Position; // Rez the root prim with no rotation LLQuaternion rootRotation = linkset.RootPrim.Rotation; linkset.RootPrim.Rotation = LLQuaternion.Identity; rezzingRootPrim = true; currentPrim = linkset.RootPrim; Client.Objects.AddPrim(Client.Network.CurrentSim, linkset.RootPrim, linkset.RootPrim.Position); if (!primDone.WaitOne(10000, false)) { return("Rez failed, timed out while creating a prim."); } primDone.Reset(); rezzingRootPrim = false; // Rez the child prims foreach (PrimObject prim in linkset.Children) { currentPrim = prim; currentPosition = prim.Position + linkset.RootPrim.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(); } // Create a list of the local IDs of the newly created prims List <uint> primIDs = new List <uint>(); foreach (PrimObject prim in primsCreated) { if (prim.LocalID != rootLocalID) { primIDs.Add(prim.LocalID); } } // Make sure the root object is the last in our list so it becomes the new root primIDs.Add(rootLocalID); // Link and set the permissions + rotation linking = true; Client.Objects.LinkPrims(Client.Network.CurrentSim, primIDs); Client.Objects.SetPermissions(Client.Network.CurrentSim, primIDs, Helpers.PermissionWho.Everyone | Helpers.PermissionWho.Group | Helpers.PermissionWho.NextOwner, Helpers.PermissionType.Copy | Helpers.PermissionType.Modify | Helpers.PermissionType.Move | Helpers.PermissionType.Transfer, true); Client.Objects.SetRotation(Client.Network.CurrentSim, rootLocalID, rootRotation); for (int i = 0; i < linkset.Children.Count + 1; i++) { primDone.WaitOne(10000, false); primDone.Reset(); } linking = false; } else { // Skip linksets with a missing root prim Console.WriteLine("WARNING: Skipping a linkset with a missing root prim"); } // Reset everything for the next linkset primsCreated.Clear(); } return("Import complete."); }
private void ExportPrimBlender(StreamWriter stream) { uint type = 0; string output; lock (Prims) { stream.WriteLine("<primitives>"); foreach (PrimObject prim in Prims.Values) { LLVector3 position = prim.Position; LLQuaternion rotation = prim.Rotation; output = ""; if (prim.ParentID != 0) { // This prim is part of a linkset, we need to adjust it's position and rotation if (Prims.ContainsKey(prim.ParentID)) { // The child prim only stores a relative position, add the world position of the parent prim position += Prims[prim.ParentID].Position; // The child prim only stores a relative rotation, start with the parent prim rotation rotation = rotation * Prims[prim.ParentID].Rotation; } else if (Avatars.Contains(prim.ParentID) || Attachments.Contains(prim.ParentID)) { // Skip this } else { // We don't have the base position for this child prim, can't render it Log("Couldn't export child prim " + prim.ID.ToString() + ", parent prim is missing" + Environment.NewLine); continue; } } output += "<primitive name=\"Object\" description=\"\" key=\"Num_000" + prim.LocalID + "\" version=\"2\">" + Environment.NewLine; output += "<states><physics params=\"\">false</physics><temporary params=\"\">false</temporary><phantom params=\"\">false</phantom></states>" + Environment.NewLine; output += "<properties>" + Environment.NewLine + "<levelofdetail val=\"9\" />" + Environment.NewLine; switch (prim.ProfileCurve + prim.PathCurve) { case 17: // PRIM_TYPE_BOX type = 0; break; case 16: // PRIM_TYPE_CYLINDER type = 1; break; case 19: // PRIM_TYPE_PRISM type = 2; break; case 37: // PRIM_TYPE_SPHERE type = 3; break; case 32: // PRIM_TYPE_TORUS type = 4; break; case 33: // PRIM_TYPE_TUBE type = 5; break; case 35: // PRIM_TYPE_RING type = 6; break; default: Log("Not exporting an unhandled prim, ProfileCurve=" + prim.ProfileCurve + ", PathCurve=" + prim.PathCurve + Environment.NewLine); continue; } output += "<type val=\"" + type + "\" />" + Environment.NewLine; output += "<position x=\"" + string.Format("{0:F6}", position.X) + "\" y=\"" + string.Format("{0:F6}", position.Y) + "\" z=\"" + string.Format("{0:F6}", position.Z) + "\" />" + Environment.NewLine; output += "<rotation x=\"" + string.Format("{0:F6}", rotation.X) + "\" y=\"" + string.Format("{0:F6}", rotation.Y) + "\" z=\"" + string.Format("{0:F6}", rotation.Z) + "\" s=\"" + string.Format("{0:F6}", rotation.W) + "\" />" + Environment.NewLine; output += "<size x=\"" + string.Format("{0:F3}", prim.Scale.X) + "\" y=\"" + string.Format("{0:F3}", prim.Scale.Y) + "\" z=\"" + string.Format("{0:F3}", prim.Scale.Z) + "\" />" + Environment.NewLine; if (type == 1) { output += "<cut x=\"" + prim.ProfileBegin + "\" y=\"" + prim.ProfileEnd + "\" />" + Environment.NewLine; output += "<dimple x=\"" + prim.PathBegin + "\" y=\"" + prim.PathEnd + "\" />" + Environment.NewLine; } else { output += "<cut x=\"" + prim.PathBegin + "\" y=\"" + prim.PathEnd + "\" />" + Environment.NewLine; output += "<dimple x=\"" + prim.ProfileBegin + "\" y=\"" + prim.ProfileEnd + "\" />" + Environment.NewLine; } output += "<advancedcut x=\"" + prim.ProfileBegin + "\" y=\"" + prim.ProfileEnd + "\" />" + Environment.NewLine; output += "<hollow val=\"" + prim.ProfileHollow + "\" />" + Environment.NewLine; output += "<twist x=\"" + prim.PathTwistBegin + "\" y=\"" + prim.PathTwist + "\" />" + Environment.NewLine; output += "<topsize x=\"" + Math.Abs(prim.PathScaleX - 1.0f) + "\" y=\"" + Math.Abs(prim.PathScaleY - 1.0f) + "\" />" + Environment.NewLine; output += "<holesize x=\"" + (1.0f - prim.PathScaleX) + "\" y=\"" + (1.0f - prim.PathScaleY) + "\" />" + Environment.NewLine; output += "<topshear x=\"" + prim.PathShearX + "\" y=\"" + prim.PathShearY + "\" />" + Environment.NewLine; output += "<taper x=\"" + prim.PathTaperX + "\" y=\"" + prim.PathTaperY + "\" />" + Environment.NewLine; output += "<revolutions val=\"" + prim.PathRevolutions + "\" />" + Environment.NewLine; output += "<radiusoffset val=\"" + prim.PathRadiusOffset + "\" />" + Environment.NewLine; output += "<skew val=\"" + prim.PathSkew + "\" />" + Environment.NewLine; output += "<material val=\"" + prim.Material + "\" />" + Environment.NewLine; // FIXME: Hollowshape. 16-21 = circle, 32-37 = square, 48-53 = triangle output += "<hollowshape val=\"0\" />" + Environment.NewLine; output += "<textures params=\"\">" + "</textures>" + "<scripts params=\"\">" + "</scripts>" + Environment.NewLine + "</properties>" + Environment.NewLine + "</primitive>" + Environment.NewLine; stream.WriteLine(output); } } stream.WriteLine("</primitives>"); }
/// <summary> /// /// </summary> /// <param name="ViewProjectionMatrix"></param> protected void RenderBasicPrims() { Graphics.GraphicsDevice.VertexDeclaration = PrimVertexDeclaration; EffectBasicPrim.Begin(); lock (Prims) { foreach (EffectPass pass in EffectBasicPrim.CurrentTechnique.Passes) { pass.Begin(); foreach (PrimVisual prim in Prims.Values) { if (prim.Prim.ParentID != 0) { if (!Prims.ContainsKey(prim.Prim.ParentID)) { // We don't have the base position for this child prim, can't render it continue; } else { // Child prim in a linkset // Add the base position of the parent prim and the offset position of this child LLVector3 llBasePosition = Prims[prim.Prim.ParentID].Prim.Position; LLQuaternion llBaseRotation = Prims[prim.Prim.ParentID].Prim.Rotation; Vector3 basePosition = new Vector3(llBasePosition.X, llBasePosition.Y, llBasePosition.Z); Matrix worldOffset = Matrix.CreateTranslation(basePosition); Matrix rootRotation = Matrix.CreateFromQuaternion(new Quaternion(llBaseRotation.X, llBaseRotation.Y, llBaseRotation.Z, llBaseRotation.W)); EffectBasicPrim.Parameters["WorldViewProj"].SetValue(prim.Matrix * rootRotation * worldOffset * ViewProjectionMatrix); EffectBasicPrim.CommitChanges(); } } else { // FIXME: We only do this test on unlinked objects for now, since child bounding boxes are // still broken //ContainmentType contain = Frustum.Contains(prim.BoundBox); //if (contain == ContainmentType.Disjoint) //{ // continue; //} // Root prim or not part of a linkset EffectBasicPrim.Parameters["WorldViewProj"].SetValue(prim.Matrix * ViewProjectionMatrix); EffectBasicPrim.CommitChanges(); } Graphics.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.TriangleList, prim.VertexArray, 0, prim.VertexArray.Length / 3); } pass.End(); } } EffectBasicPrim.End(); }
public byte[] ToBytes() { int i = 0; byte[] bytes = new byte[126 + Texture.Length]; Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16; bytes[i++] = this.PCode; bytes[i++] = (byte)(this.PathBegin % 256); bytes[i++] = (byte)((this.PathBegin >> 8) % 256); bytes[i++] = (byte)(this.PathEnd % 256); bytes[i++] = (byte)((this.PathEnd >> 8) % 256); bytes[i++] = this.PathScaleX; bytes[i++] = this.PathScaleY; bytes[i++] = this.PathShearX; bytes[i++] = this.PathShearY; bytes[i++] = (byte)this.PathSkew; bytes[i++] = (byte)(this.ProfileBegin % 256); bytes[i++] = (byte)((this.ProfileBegin >> 8) % 256); bytes[i++] = (byte)(this.ProfileEnd % 256); bytes[i++] = (byte)((this.ProfileEnd >> 8) % 256); Array.Copy(Scale.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = this.PathCurve; bytes[i++] = this.ProfileCurve; bytes[i++] = (byte)(ParentID % 256); bytes[i++] = (byte)((ParentID >> 8) % 256); bytes[i++] = (byte)((ParentID >> 16) % 256); bytes[i++] = (byte)((ParentID >> 24) % 256); bytes[i++] = (byte)(this.ProfileHollow % 256); bytes[i++] = (byte)((this.ProfileHollow >> 8) % 256); bytes[i++] = ((byte)this.PathRadiusOffset); bytes[i++] = this.PathRevolutions; bytes[i++] = ((byte)this.PathTaperX); bytes[i++] = ((byte)this.PathTaperY); bytes[i++] = ((byte)this.PathTwist); bytes[i++] = ((byte)this.PathTwistBegin); bytes[i++] = (byte)(Texture.Length % 256); bytes[i++] = (byte)((Texture.Length >> 8) % 256); Array.Copy(Texture, 0, bytes, i, Texture.Length); i += Texture.Length; bytes[i++] = (byte)(this.CreationDate % 256); bytes[i++] = (byte)((this.CreationDate >> 8) % 256); bytes[i++] = (byte)((this.CreationDate >> 16) % 256); bytes[i++] = (byte)((this.CreationDate >> 24) % 256); bytes[i++] = (byte)(this.OwnerMask % 256); bytes[i++] = (byte)((this.OwnerMask >> 8) % 256); bytes[i++] = (byte)((this.OwnerMask >> 16) % 256); bytes[i++] = (byte)((this.OwnerMask >> 24) % 256); bytes[i++] = (byte)(this.NextOwnerMask % 256); bytes[i++] = (byte)((this.NextOwnerMask >> 8) % 256); bytes[i++] = (byte)((this.NextOwnerMask >> 16) % 256); bytes[i++] = (byte)((this.NextOwnerMask >> 24) % 256); bytes[i++] = (byte)(this.GroupMask % 256); bytes[i++] = (byte)((this.GroupMask >> 8) % 256); bytes[i++] = (byte)((this.GroupMask >> 16) % 256); bytes[i++] = (byte)((this.GroupMask >> 24) % 256); bytes[i++] = (byte)(this.EveryoneMask % 256); bytes[i++] = (byte)((this.EveryoneMask >> 8) % 256); bytes[i++] = (byte)((this.EveryoneMask >> 16) % 256); bytes[i++] = (byte)((this.EveryoneMask >> 24) % 256); bytes[i++] = (byte)(this.BaseMask % 256); bytes[i++] = (byte)((this.BaseMask >> 8) % 256); bytes[i++] = (byte)((this.BaseMask >> 16) % 256); bytes[i++] = (byte)((this.BaseMask >> 24) % 256); Array.Copy(this.Position.GetBytes(), 0, bytes, i, 12); i += 12; if (this.Rotation == new LLQuaternion(0, 0, 0, 0)) { this.Rotation = new LLQuaternion(0, 1, 0, 0); } Array.Copy(this.Rotation.GetBytes(), 0, bytes, i, 12); i += 12; bytes[i++] = (byte)(this.LocalID % 256); bytes[i++] = (byte)((this.LocalID >> 8) % 256); bytes[i++] = (byte)((this.LocalID >> 16) % 256); bytes[i++] = (byte)((this.LocalID >> 24) % 256); Array.Copy(FullID.GetBytes(), 0, bytes, i, 16); i += 16; return(bytes); }