29 using System.Collections.Generic;
30 using System.Reflection;
31 using NUnit.Framework;
33 using OpenSim.Framework;
34 using OpenSim.Region.Framework.Scenes;
35 using OpenSim.Tests.Common;
38 namespace OpenSim.
Region.Framework.Scenes.Tests
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 TestHelpers.InMethod();
53 UUID ownerId = TestHelpers.ParseTail(0x1);
57 SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(nParts, ownerId,
"TestLinkToSelf_", 0x10);
58 scene.AddSceneObject(sog1);
59 scene.LinkObjects(ownerId, sog1.LocalId,
new List<uint>() { sog1.Parts[1].LocalId });
62 Assert.That(sog1.Parts.Length, Is.EqualTo(nParts));
68 TestHelpers.InMethod();
70 bool debugtest =
false;
78 grp1.AbsolutePosition =
new Vector3(10, 10, 10);
79 grp2.AbsolutePosition = Vector3.Zero;
85 grp2.UpdateGroupRotationR(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0));
88 grp1.RootPart.ClearUpdateSchedule();
89 grp2.RootPart.ClearUpdateSchedule();
92 Assert.IsFalse(grp1.GroupContainsForeignPrims);
93 grp1.LinkToGroup(grp2);
94 Assert.IsTrue(grp1.GroupContainsForeignPrims);
97 Assert.IsFalse(grp1.GroupContainsForeignPrims);
101 Assert.That(grp2.IsDeleted,
"SOG 2 was not registered as deleted after link.");
102 Assert.That(grp2.Parts.Length, Is.EqualTo(0),
"Group 2 still contained children after delink.");
103 Assert.That(grp1.Parts.Length == 2);
107 m_log.Debug(
"parts: " + grp1.Parts.Length);
108 m_log.Debug(
"Group1: Pos:"+grp1.AbsolutePosition+
", Rot:"+grp1.GroupRotation);
109 m_log.Debug(
"Group1: Prim1: OffsetPosition:"+ part1.OffsetPosition+
", OffsetRotation:"+part1.RotationOffset);
110 m_log.Debug(
"Group1: Prim2: OffsetPosition:"+part2.OffsetPosition+
", OffsetRotation:"+part2.RotationOffset);
114 Assert.That(part1.OffsetPosition == Vector3.Zero && part1.RotationOffset == Quaternion.Identity,
115 "root part should have no offset position or rotation");
118 Assert.That(part2.OffsetPosition ==
new Vector3(-10, -10, -10),
119 "offset position should be root part position - part2.absolute position.");
126 part1.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw);
127 Vector3 rotEuler1 =
new Vector3(roll *
Utils.RAD_TO_DEG, pitch *
Utils.RAD_TO_DEG, yaw *
Utils.RAD_TO_DEG);
130 m_log.Debug(rotEuler1);
132 part2.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw);
133 Vector3 rotEuler2 =
new Vector3(roll *
Utils.RAD_TO_DEG, pitch *
Utils.RAD_TO_DEG, yaw *
Utils.RAD_TO_DEG);
136 m_log.Debug(rotEuler2);
138 Assert.That(rotEuler2.ApproxEquals(
new Vector3(-180, 0, 0), 0.001f) || rotEuler2.ApproxEquals(
new Vector3(180, 0, 0), 0.001f),
139 "Not exactly sure what this is asserting...");
145 m_log.Debug(
"Group2: Prim2: OffsetPosition:" + part2.AbsolutePosition +
", OffsetRotation:" + part2.RotationOffset);
147 Assert.That(grp1.Parts.Length, Is.EqualTo(1),
"Group 1 still contained part2 after delink.");
148 Assert.That(part2.AbsolutePosition == Vector3.Zero,
"The absolute position should be zero");
149 Assert.NotNull(grp3);
155 TestHelpers.InMethod();
157 bool debugtest =
false;
169 grp1.AbsolutePosition =
new Vector3(10, 10, 10);
170 grp2.AbsolutePosition = Vector3.Zero;
171 grp3.AbsolutePosition =
new Vector3(20, 20, 20);
172 grp4.AbsolutePosition =
new Vector3(40, 40, 40);
178 grp2.UpdateGroupRotationR(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0));
184 grp4.UpdateGroupRotationR(Quaternion.CreateFromEulers(0, 90 * Utils.DEG_TO_RAD, 0));
187 grp1.RootPart.ClearUpdateSchedule();
188 grp2.RootPart.ClearUpdateSchedule();
189 grp3.RootPart.ClearUpdateSchedule();
190 grp4.RootPart.ClearUpdateSchedule();
193 grp1.LinkToGroup(grp2);
196 grp3.LinkToGroup(grp4);
199 Assert.That(grp1.Parts.Length == 2,
"Group1 children count should be 2");
200 Assert.That(grp2.IsDeleted,
"Group 2 was not registered as deleted after link.");
201 Assert.That(grp2.Parts.Length, Is.EqualTo(0),
"Group 2 still contained parts after delink.");
202 Assert.That(grp3.Parts.Length == 2,
"Group3 children count should be 2");
203 Assert.That(grp4.IsDeleted,
"Group 4 was not registered as deleted after link.");
204 Assert.That(grp4.Parts.Length, Is.EqualTo(0),
"Group 4 still contained parts after delink.");
208 m_log.Debug(
"--------After Link-------");
209 m_log.Debug(
"Group1: parts:" + grp1.Parts.Length);
210 m_log.Debug(
"Group1: Pos:"+grp1.AbsolutePosition+
", Rot:"+grp1.GroupRotation);
211 m_log.Debug(
"Group1: Prim1: OffsetPosition:" + part1.OffsetPosition +
", OffsetRotation:" + part1.RotationOffset);
212 m_log.Debug(
"Group1: Prim2: OffsetPosition:"+part2.OffsetPosition+
", OffsetRotation:"+ part2.RotationOffset);
214 m_log.Debug(
"Group3: parts:" + grp3.Parts.Length);
215 m_log.Debug(
"Group3: Pos:"+grp3.AbsolutePosition+
", Rot:"+grp3.GroupRotation);
216 m_log.Debug(
"Group3: Prim1: OffsetPosition:"+part3.OffsetPosition+
", OffsetRotation:"+part3.RotationOffset);
217 m_log.Debug(
"Group3: Prim2: OffsetPosition:"+part4.OffsetPosition+
", OffsetRotation:"+part4.RotationOffset);
221 grp1.RootPart.ClearUpdateSchedule();
222 grp3.RootPart.ClearUpdateSchedule();
225 Assert.That(part1.OffsetPosition == Vector3.Zero && part1.RotationOffset == Quaternion.Identity,
226 "root part should have no offset position or rotation (again)");
229 Assert.That(part2.OffsetPosition ==
new Vector3(-10, -10, -10),
230 "offset position should be root part position - part2.absolute position (again)");
237 part1.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw);
238 Vector3 rotEuler1 =
new Vector3(roll *
Utils.RAD_TO_DEG, pitch *
Utils.RAD_TO_DEG, yaw *
Utils.RAD_TO_DEG);
241 m_log.Debug(rotEuler1);
243 part2.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw);
244 Vector3 rotEuler2 =
new Vector3(roll *
Utils.RAD_TO_DEG, pitch *
Utils.RAD_TO_DEG, yaw *
Utils.RAD_TO_DEG);
247 m_log.Debug(rotEuler2);
249 Assert.That(rotEuler2.ApproxEquals(
new Vector3(-180, 0, 0), 0.001f) || rotEuler2.ApproxEquals(
new Vector3(180, 0, 0), 0.001f),
250 "Not sure what this assertion is all about...");
253 grp3.LinkToGroup(grp1);
256 grp3.DelinkFromGroup(part2.LocalId);
257 grp3.DelinkFromGroup(part3.LocalId);
261 m_log.Debug(
"--------After De-Link-------");
262 m_log.Debug(
"Group1: parts:" + grp1.Parts.Length);
263 m_log.Debug(
"Group1: Pos:" + grp1.AbsolutePosition +
", Rot:" + grp1.GroupRotation);
264 m_log.Debug(
"Group1: Prim1: OffsetPosition:" + part1.OffsetPosition +
", OffsetRotation:" + part1.RotationOffset);
265 m_log.Debug(
"Group1: Prim2: OffsetPosition:" + part2.OffsetPosition +
", OffsetRotation:" + part2.RotationOffset);
267 m_log.Debug(
"Group3: parts:" + grp3.Parts.Length);
268 m_log.Debug(
"Group3: Pos:" + grp3.AbsolutePosition +
", Rot:" + grp3.GroupRotation);
269 m_log.Debug(
"Group3: Prim1: OffsetPosition:" + part3.OffsetPosition +
", OffsetRotation:" + part3.RotationOffset);
270 m_log.Debug(
"Group3: Prim2: OffsetPosition:" + part4.OffsetPosition +
", OffsetRotation:" + part4.RotationOffset);
273 Assert.That(part2.AbsolutePosition == Vector3.Zero,
"Badness 1");
274 Assert.That(part4.OffsetPosition ==
new Vector3(20, 20, 20),
"Badness 2");
275 Quaternion compareQuaternion =
new Quaternion(0, 0.7071068f, 0, 0.7071068f);
276 Assert.That((part4.RotationOffset.X - compareQuaternion.X < 0.00003)
277 && (part4.RotationOffset.Y - compareQuaternion.Y < 0.00003)
278 && (part4.RotationOffset.Z - compareQuaternion.Z < 0.00003)
279 && (part4.RotationOffset.W - compareQuaternion.W < 0.00003),
289 TestHelpers.InMethod();
294 string rootPartName =
"rootpart";
295 UUID rootPartUuid =
new UUID(
"00000000-0000-0000-0000-000000000001");
296 string linkPartName =
"linkpart";
297 UUID linkPartUuid =
new UUID(
"00000000-0000-0000-0001-000000000000");
301 { Name = rootPartName, UUID = rootPartUuid };
304 { Name = linkPartName, UUID = linkPartUuid };
307 sog.AddPart(linkPart);
308 scene.AddNewSceneObject(sog,
true);
314 List<SceneObjectGroup> storedObjects = scene.SimulationDataService.LoadObjects(scene.RegionInfo.RegionID);
316 Assert.That(storedObjects.Count, Is.EqualTo(1));
317 Assert.That(storedObjects[0].Parts.Length, Is.EqualTo(2));
318 Assert.That(storedObjects[0].ContainsPart(rootPartUuid));
319 Assert.That(storedObjects[0].ContainsPart(linkPartUuid));
328 TestHelpers.InMethod();
333 string rootPartName =
"rootpart";
334 UUID rootPartUuid =
new UUID(
"00000000-0000-0000-0000-000000000001");
335 string linkPartName =
"linkpart";
336 UUID linkPartUuid =
new UUID(
"00000000-0000-0000-0001-000000000000");
340 { Name = rootPartName, UUID = rootPartUuid };
344 { Name = linkPartName, UUID = linkPartUuid };
346 scene.AddNewSceneObject(linkGroup,
true);
349 scene.AddNewSceneObject(sog,
true);
351 Assert.IsFalse(sog.GroupContainsForeignPrims);
352 sog.LinkToGroup(linkGroup);
353 Assert.IsTrue(sog.GroupContainsForeignPrims);
356 Assert.AreEqual(1, scene.SimulationDataService.LoadObjects(scene.RegionInfo.RegionID).Count);
360 Assert.IsFalse(groupToDelete.GroupContainsForeignPrims);
void TestLinkToSelf()
Links to self should be ignored.
OpenSim.Server.Handlers.Simulation.Utils Utils
static PrimitiveBaseShape Default
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
void TestNewSceneObjectLinkPersistence()
Test that a new scene object which is already linked is correctly persisted to the persistence layer...
void TestLinkDelink2SceneObjects()
Helpers for setting up scenes.
void TestDelinkPersistence()
Test that a delink of a previously linked object is correctly persisted to the database ...
void TestLinkDelink2groups4SceneObjects()