aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tests/Common/Helpers/SceneHelpers.cs')
-rw-r--r--OpenSim/Tests/Common/Helpers/SceneHelpers.cs724
1 files changed, 724 insertions, 0 deletions
diff --git a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
new file mode 100644
index 0000000..1fb1c5c
--- /dev/null
+++ b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs
@@ -0,0 +1,724 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Net;
30using System.Collections.Generic;
31using Nini.Config;
32using OpenMetaverse;
33using OpenSim.Data.Null;
34using OpenSim.Framework;
35using OpenSim.Framework.Communications;
36using OpenSim.Framework.Console;
37using OpenSim.Framework.Servers;
38using OpenSim.Framework.Servers.HttpServer;
39using OpenSim.Region.Physics.Manager;
40using OpenSim.Region.Framework;
41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.Framework.Scenes;
43using OpenSim.Region.CoreModules.Avatar.Gods;
44using OpenSim.Region.CoreModules.Asset;
45using OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset;
46using OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication;
47using OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory;
48using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid;
49using OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts;
50using OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence;
51using OpenSim.Services.Interfaces;
52using GridRegion = OpenSim.Services.Interfaces.GridRegion;
53
54namespace OpenSim.Tests.Common
55{
56 /// <summary>
57 /// Helpers for setting up scenes.
58 /// </summary>
59 public class SceneHelpers
60 {
61 /// <summary>
62 /// We need a scene manager so that test clients can retrieve a scene when performing teleport tests.
63 /// </summary>
64 public SceneManager SceneManager { get; private set; }
65
66 public ISimulationDataService SimDataService { get; private set; }
67
68 private AgentCircuitManager m_acm = new AgentCircuitManager();
69 private IEstateDataService m_estateDataService = null;
70
71 private LocalAssetServicesConnector m_assetService;
72 private LocalAuthenticationServicesConnector m_authenticationService;
73 private LocalInventoryServicesConnector m_inventoryService;
74 private LocalGridServicesConnector m_gridService;
75 private LocalUserAccountServicesConnector m_userAccountService;
76 private LocalPresenceServicesConnector m_presenceService;
77
78 private CoreAssetCache m_cache;
79
80 public SceneHelpers() : this(null) {}
81
82 public SceneHelpers(CoreAssetCache cache)
83 {
84 SceneManager = new SceneManager();
85
86 m_assetService = StartAssetService(cache);
87 m_authenticationService = StartAuthenticationService();
88 m_inventoryService = StartInventoryService();
89 m_gridService = StartGridService();
90 m_userAccountService = StartUserAccountService();
91 m_presenceService = StartPresenceService();
92
93 m_inventoryService.PostInitialise();
94 m_assetService.PostInitialise();
95 m_userAccountService.PostInitialise();
96 m_presenceService.PostInitialise();
97
98 m_cache = cache;
99
100 SimDataService
101 = OpenSim.Server.Base.ServerUtils.LoadPlugin<ISimulationDataService>("OpenSim.Tests.Common.dll", null);
102 }
103
104 /// <summary>
105 /// Set up a test scene
106 /// </summary>
107 /// <remarks>
108 /// Automatically starts services, as would the normal runtime.
109 /// </remarks>
110 /// <returns></returns>
111 public TestScene SetupScene()
112 {
113 return SetupScene("Unit test region", UUID.Random(), 1000, 1000);
114 }
115
116 public TestScene SetupScene(string name, UUID id, uint x, uint y)
117 {
118 return SetupScene(name, id, x, y, new IniConfigSource());
119 }
120
121 public TestScene SetupScene(string name, UUID id, uint x, uint y, IConfigSource configSource)
122 {
123 return SetupScene(name, id, x, y, Constants.RegionSize, Constants.RegionSize, configSource);
124 }
125
126 /// <summary>
127 /// Set up a scene.
128 /// </summary>
129 /// <param name="name">Name of the region</param>
130 /// <param name="id">ID of the region</param>
131 /// <param name="x">X co-ordinate of the region</param>
132 /// <param name="y">Y co-ordinate of the region</param>
133 /// <param name="sizeX">X size of scene</param>
134 /// <param name="sizeY">Y size of scene</param>
135 /// <param name="configSource"></param>
136 /// <returns></returns>
137 public TestScene SetupScene(
138 string name, UUID id, uint x, uint y, uint sizeX, uint sizeY, IConfigSource configSource)
139 {
140 Console.WriteLine("Setting up test scene {0}", name);
141
142 // We must set up a console otherwise setup of some modules may fail
143 MainConsole.Instance = new MockConsole();
144
145 RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1");
146 regInfo.RegionName = name;
147 regInfo.RegionID = id;
148 regInfo.RegionSizeX = sizeX;
149 regInfo.RegionSizeY = sizeY;
150
151 SceneCommunicationService scs = new SceneCommunicationService();
152
153 PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager();
154 physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll");
155 Vector3 regionExtent = new Vector3( regInfo.RegionSizeX, regInfo.RegionSizeY, regInfo.RegionSizeZ);
156 PhysicsScene physicsScene
157 = physicsPluginManager.GetPhysicsScene(
158 "basicphysics", "ZeroMesher", new IniConfigSource(), "test", regionExtent);
159
160 TestScene testScene = new TestScene(
161 regInfo, m_acm, physicsScene, scs, SimDataService, m_estateDataService, configSource, null);
162
163 INonSharedRegionModule godsModule = new GodsModule();
164 godsModule.Initialise(new IniConfigSource());
165 godsModule.AddRegion(testScene);
166
167 // Add scene to services
168 m_assetService.AddRegion(testScene);
169
170 if (m_cache != null)
171 {
172 m_cache.AddRegion(testScene);
173 m_cache.RegionLoaded(testScene);
174 testScene.AddRegionModule(m_cache.Name, m_cache);
175 }
176
177 m_assetService.RegionLoaded(testScene);
178 testScene.AddRegionModule(m_assetService.Name, m_assetService);
179
180 m_authenticationService.AddRegion(testScene);
181 m_authenticationService.RegionLoaded(testScene);
182 testScene.AddRegionModule(m_authenticationService.Name, m_authenticationService);
183
184 m_inventoryService.AddRegion(testScene);
185 m_inventoryService.RegionLoaded(testScene);
186 testScene.AddRegionModule(m_inventoryService.Name, m_inventoryService);
187
188 m_gridService.AddRegion(testScene);
189 m_gridService.RegionLoaded(testScene);
190 testScene.AddRegionModule(m_gridService.Name, m_gridService);
191
192 m_userAccountService.AddRegion(testScene);
193 m_userAccountService.RegionLoaded(testScene);
194 testScene.AddRegionModule(m_userAccountService.Name, m_userAccountService);
195
196 m_presenceService.AddRegion(testScene);
197 m_presenceService.RegionLoaded(testScene);
198 testScene.AddRegionModule(m_presenceService.Name, m_presenceService);
199
200 testScene.RegionInfo.EstateSettings.EstateOwner = UUID.Random();
201 testScene.SetModuleInterfaces();
202
203 testScene.LandChannel = new TestLandChannel(testScene);
204 testScene.LoadWorldMap();
205
206 testScene.RegionInfo.EstateSettings = new EstateSettings();
207 testScene.LoginsEnabled = true;
208 testScene.RegisterRegionWithGrid();
209
210 SceneManager.Add(testScene);
211
212 return testScene;
213 }
214
215 private static LocalAssetServicesConnector StartAssetService(CoreAssetCache cache)
216 {
217 IConfigSource config = new IniConfigSource();
218 config.AddConfig("Modules");
219 config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector");
220 config.AddConfig("AssetService");
221 config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService");
222 config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
223
224 LocalAssetServicesConnector assetService = new LocalAssetServicesConnector();
225 assetService.Initialise(config);
226
227 if (cache != null)
228 {
229 IConfigSource cacheConfig = new IniConfigSource();
230 cacheConfig.AddConfig("Modules");
231 cacheConfig.Configs["Modules"].Set("AssetCaching", "CoreAssetCache");
232 cacheConfig.AddConfig("AssetCache");
233
234 cache.Initialise(cacheConfig);
235 }
236
237 return assetService;
238 }
239
240 private static LocalAuthenticationServicesConnector StartAuthenticationService()
241 {
242 IConfigSource config = new IniConfigSource();
243 config.AddConfig("Modules");
244 config.AddConfig("AuthenticationService");
245 config.Configs["Modules"].Set("AuthenticationServices", "LocalAuthenticationServicesConnector");
246 config.Configs["AuthenticationService"].Set(
247 "LocalServiceModule", "OpenSim.Services.AuthenticationService.dll:PasswordAuthenticationService");
248 config.Configs["AuthenticationService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
249
250 LocalAuthenticationServicesConnector service = new LocalAuthenticationServicesConnector();
251 service.Initialise(config);
252
253 return service;
254 }
255
256 private static LocalInventoryServicesConnector StartInventoryService()
257 {
258 IConfigSource config = new IniConfigSource();
259 config.AddConfig("Modules");
260 config.AddConfig("InventoryService");
261 config.Configs["Modules"].Set("InventoryServices", "LocalInventoryServicesConnector");
262 config.Configs["InventoryService"].Set("LocalServiceModule", "OpenSim.Services.InventoryService.dll:XInventoryService");
263 config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
264
265 LocalInventoryServicesConnector inventoryService = new LocalInventoryServicesConnector();
266 inventoryService.Initialise(config);
267
268 return inventoryService;
269 }
270
271 private static LocalGridServicesConnector StartGridService()
272 {
273 IConfigSource config = new IniConfigSource();
274 config.AddConfig("Modules");
275 config.AddConfig("GridService");
276 config.Configs["Modules"].Set("GridServices", "LocalGridServicesConnector");
277 config.Configs["GridService"].Set("StorageProvider", "OpenSim.Data.Null.dll:NullRegionData");
278 config.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Services.GridService.dll:GridService");
279 config.Configs["GridService"].Set("ConnectionString", "!static");
280
281 LocalGridServicesConnector gridService = new LocalGridServicesConnector();
282 gridService.Initialise(config);
283
284 return gridService;
285 }
286
287 /// <summary>
288 /// Start a user account service
289 /// </summary>
290 /// <param name="testScene"></param>
291 /// <returns></returns>
292 private static LocalUserAccountServicesConnector StartUserAccountService()
293 {
294 IConfigSource config = new IniConfigSource();
295 config.AddConfig("Modules");
296 config.AddConfig("UserAccountService");
297 config.Configs["Modules"].Set("UserAccountServices", "LocalUserAccountServicesConnector");
298 config.Configs["UserAccountService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
299 config.Configs["UserAccountService"].Set(
300 "LocalServiceModule", "OpenSim.Services.UserAccountService.dll:UserAccountService");
301
302 LocalUserAccountServicesConnector userAccountService = new LocalUserAccountServicesConnector();
303 userAccountService.Initialise(config);
304
305 return userAccountService;
306 }
307
308 /// <summary>
309 /// Start a presence service
310 /// </summary>
311 /// <param name="testScene"></param>
312 private static LocalPresenceServicesConnector StartPresenceService()
313 {
314 // Unfortunately, some services share data via statics, so we need to null every time to stop interference
315 // between tests.
316 // This is a massive non-obvious pita.
317 NullPresenceData.Instance = null;
318
319 IConfigSource config = new IniConfigSource();
320 config.AddConfig("Modules");
321 config.AddConfig("PresenceService");
322 config.Configs["Modules"].Set("PresenceServices", "LocalPresenceServicesConnector");
323 config.Configs["PresenceService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
324 config.Configs["PresenceService"].Set(
325 "LocalServiceModule", "OpenSim.Services.PresenceService.dll:PresenceService");
326
327 LocalPresenceServicesConnector presenceService = new LocalPresenceServicesConnector();
328 presenceService.Initialise(config);
329
330 return presenceService;
331 }
332
333 /// <summary>
334 /// Setup modules for a scene using their default settings.
335 /// </summary>
336 /// <param name="scene"></param>
337 /// <param name="modules"></param>
338 public static void SetupSceneModules(Scene scene, params object[] modules)
339 {
340 SetupSceneModules(scene, new IniConfigSource(), modules);
341 }
342
343 /// <summary>
344 /// Setup modules for a scene.
345 /// </summary>
346 /// <remarks>
347 /// If called directly, then all the modules must be shared modules.
348 /// </remarks>
349 /// <param name="scenes"></param>
350 /// <param name="config"></param>
351 /// <param name="modules"></param>
352 public static void SetupSceneModules(Scene scene, IConfigSource config, params object[] modules)
353 {
354 SetupSceneModules(new Scene[] { scene }, config, modules);
355 }
356
357 /// <summary>
358 /// Setup modules for a scene using their default settings.
359 /// </summary>
360 /// <param name="scenes"></param>
361 /// <param name="modules"></param>
362 public static void SetupSceneModules(Scene[] scenes, params object[] modules)
363 {
364 SetupSceneModules(scenes, new IniConfigSource(), modules);
365 }
366
367 /// <summary>
368 /// Setup modules for scenes.
369 /// </summary>
370 /// <remarks>
371 /// If called directly, then all the modules must be shared modules.
372 ///
373 /// We are emulating here the normal calls made to setup region modules
374 /// (Initialise(), PostInitialise(), AddRegion, RegionLoaded()).
375 /// TODO: Need to reuse normal runtime module code.
376 /// </remarks>
377 /// <param name="scenes"></param>
378 /// <param name="config"></param>
379 /// <param name="modules"></param>
380 public static void SetupSceneModules(Scene[] scenes, IConfigSource config, params object[] modules)
381 {
382 List<IRegionModuleBase> newModules = new List<IRegionModuleBase>();
383 foreach (object module in modules)
384 {
385 IRegionModuleBase m = (IRegionModuleBase)module;
386// Console.WriteLine("MODULE {0}", m.Name);
387 m.Initialise(config);
388 newModules.Add(m);
389 }
390
391 foreach (IRegionModuleBase module in newModules)
392 {
393 if (module is ISharedRegionModule) ((ISharedRegionModule)module).PostInitialise();
394 }
395
396 foreach (IRegionModuleBase module in newModules)
397 {
398 foreach (Scene scene in scenes)
399 {
400 module.AddRegion(scene);
401 scene.AddRegionModule(module.Name, module);
402 }
403 }
404
405 // RegionLoaded is fired after all modules have been appropriately added to all scenes
406 foreach (IRegionModuleBase module in newModules)
407 foreach (Scene scene in scenes)
408 module.RegionLoaded(scene);
409
410 foreach (Scene scene in scenes) { scene.SetModuleInterfaces(); }
411 }
412
413 /// <summary>
414 /// Generate some standard agent connection data.
415 /// </summary>
416 /// <param name="agentId"></param>
417 /// <returns></returns>
418 public static AgentCircuitData GenerateAgentData(UUID agentId)
419 {
420 AgentCircuitData acd = GenerateCommonAgentData();
421
422 acd.AgentID = agentId;
423 acd.firstname = "testfirstname";
424 acd.lastname = "testlastname";
425 acd.ServiceURLs = new Dictionary<string, object>();
426
427 return acd;
428 }
429
430 /// <summary>
431 /// Generate some standard agent connection data.
432 /// </summary>
433 /// <param name="agentId"></param>
434 /// <returns></returns>
435 public static AgentCircuitData GenerateAgentData(UserAccount ua)
436 {
437 AgentCircuitData acd = GenerateCommonAgentData();
438
439 acd.AgentID = ua.PrincipalID;
440 acd.firstname = ua.FirstName;
441 acd.lastname = ua.LastName;
442 acd.ServiceURLs = ua.ServiceURLs;
443
444 return acd;
445 }
446
447 private static AgentCircuitData GenerateCommonAgentData()
448 {
449 AgentCircuitData acd = new AgentCircuitData();
450
451 // XXX: Sessions must be unique, otherwise one presence can overwrite another in NullPresenceData.
452 acd.SessionID = UUID.Random();
453 acd.SecureSessionID = UUID.Random();
454
455 acd.circuitcode = 123;
456 acd.BaseFolder = UUID.Zero;
457 acd.InventoryFolder = UUID.Zero;
458 acd.startpos = Vector3.Zero;
459 acd.CapsPath = "http://wibble.com";
460 acd.Appearance = new AvatarAppearance();
461
462 return acd;
463 }
464
465 /// <summary>
466 /// Add a root agent where the details of the agent connection (apart from the id) are unimportant for the test
467 /// </summary>
468 /// <remarks>
469 /// XXX: Use the version of this method that takes the UserAccount structure wherever possible - this will
470 /// make the agent circuit data (e.g. first, lastname) consistent with the user account data.
471 /// </remarks>
472 /// <param name="scene"></param>
473 /// <param name="agentId"></param>
474 /// <returns></returns>
475 public static ScenePresence AddScenePresence(Scene scene, UUID agentId)
476 {
477 return AddScenePresence(scene, GenerateAgentData(agentId));
478 }
479
480 /// <summary>
481 /// Add a root agent.
482 /// </summary>
483 /// <param name="scene"></param>
484 /// <param name="ua"></param>
485 /// <returns></returns>
486 public static ScenePresence AddScenePresence(Scene scene, UserAccount ua)
487 {
488 return AddScenePresence(scene, GenerateAgentData(ua));
489 }
490
491 /// <summary>
492 /// Add a root agent.
493 /// </summary>
494 /// <remarks>
495 /// This function
496 ///
497 /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the
498 /// userserver if grid) would give initial login data back to the client and separately tell the scene that the
499 /// agent was coming.
500 ///
501 /// 2) Connects the agent with the scene
502 ///
503 /// This function performs actions equivalent with notifying the scene that an agent is
504 /// coming and then actually connecting the agent to the scene. The one step missed out is the very first
505 /// </remarks>
506 /// <param name="scene"></param>
507 /// <param name="agentData"></param>
508 /// <returns></returns>
509 public static ScenePresence AddScenePresence(Scene scene, AgentCircuitData agentData)
510 {
511 return AddScenePresence(scene, new TestClient(agentData, scene), agentData);
512 }
513
514 /// <summary>
515 /// Add a root agent.
516 /// </summary>
517 /// <remarks>
518 /// This function
519 ///
520 /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the
521 /// userserver if grid) would give initial login data back to the client and separately tell the scene that the
522 /// agent was coming.
523 ///
524 /// 2) Connects the agent with the scene
525 ///
526 /// This function performs actions equivalent with notifying the scene that an agent is
527 /// coming and then actually connecting the agent to the scene. The one step missed out is the very first
528 /// </remarks>
529 /// <param name="scene"></param>
530 /// <param name="agentData"></param>
531 /// <returns></returns>
532 public static ScenePresence AddScenePresence(
533 Scene scene, IClientAPI client, AgentCircuitData agentData)
534 {
535 // We emulate the proper login sequence here by doing things in four stages
536
537 // Stage 0: login
538 // We need to punch through to the underlying service because scene will not, correctly, let us call it
539 // through it's reference to the LPSC
540 LocalPresenceServicesConnector lpsc = (LocalPresenceServicesConnector)scene.PresenceService;
541 lpsc.m_PresenceService.LoginAgent(agentData.AgentID.ToString(), agentData.SessionID, agentData.SecureSessionID);
542
543 // Stages 1 & 2
544 ScenePresence sp = IntroduceClientToScene(scene, client, agentData, TeleportFlags.ViaLogin);
545
546 // Stage 3: Complete the entrance into the region. This converts the child agent into a root agent.
547 sp.CompleteMovement(sp.ControllingClient, true);
548
549 return sp;
550 }
551
552 /// <summary>
553 /// Introduce an agent into the scene by adding a new client.
554 /// </summary>
555 /// <returns>The scene presence added</returns>
556 /// <param name='scene'></param>
557 /// <param name='testClient'></param>
558 /// <param name='agentData'></param>
559 /// <param name='tf'></param>
560 private static ScenePresence IntroduceClientToScene(
561 Scene scene, IClientAPI client, AgentCircuitData agentData, TeleportFlags tf)
562 {
563 string reason;
564
565 // Stage 1: tell the scene to expect a new user connection
566 if (!scene.NewUserConnection(agentData, (uint)tf, null, out reason))
567 Console.WriteLine("NewUserConnection failed: " + reason);
568
569 // Stage 2: add the new client as a child agent to the scene
570 scene.AddNewAgent(client, PresenceType.User);
571
572 return scene.GetScenePresence(client.AgentId);
573 }
574
575 public static ScenePresence AddChildScenePresence(Scene scene, UUID agentId)
576 {
577 return AddChildScenePresence(scene, GenerateAgentData(agentId));
578 }
579
580 public static ScenePresence AddChildScenePresence(Scene scene, AgentCircuitData acd)
581 {
582 acd.child = true;
583
584 // XXX: ViaLogin may not be correct for child agents
585 TestClient client = new TestClient(acd, scene);
586 return IntroduceClientToScene(scene, client, acd, TeleportFlags.ViaLogin);
587 }
588
589 /// <summary>
590 /// Add a test object
591 /// </summary>
592 /// <param name="scene"></param>
593 /// <returns></returns>
594 public static SceneObjectGroup AddSceneObject(Scene scene)
595 {
596 return AddSceneObject(scene, "Test Object", UUID.Zero);
597 }
598
599 /// <summary>
600 /// Add a test object
601 /// </summary>
602 /// <param name="scene"></param>
603 /// <param name="name"></param>
604 /// <param name="ownerId"></param>
605 /// <returns></returns>
606 public static SceneObjectGroup AddSceneObject(Scene scene, string name, UUID ownerId)
607 {
608 SceneObjectGroup so = new SceneObjectGroup(CreateSceneObjectPart(name, UUID.Random(), ownerId));
609
610 //part.UpdatePrimFlags(false, false, true);
611 //part.ObjectFlags |= (uint)PrimFlags.Phantom;
612
613 scene.AddNewSceneObject(so, true);
614
615 return so;
616 }
617
618 /// <summary>
619 /// Add a test object
620 /// </summary>
621 /// <param name="scene"></param>
622 /// <param name="parts">
623 /// The number of parts that should be in the scene object
624 /// </param>
625 /// <param name="ownerId"></param>
626 /// <param name="partNamePrefix">
627 /// The prefix to be given to part names. This will be suffixed with "Part<part no>"
628 /// (e.g. mynamePart1 for the root part)
629 /// </param>
630 /// <param name="uuidTail">
631 /// The hexadecimal last part of the UUID for parts created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
632 /// will be given to the root part, and incremented for each part thereafter.
633 /// </param>
634 /// <returns></returns>
635 public static SceneObjectGroup AddSceneObject(Scene scene, int parts, UUID ownerId, string partNamePrefix, int uuidTail)
636 {
637 SceneObjectGroup so = CreateSceneObject(parts, ownerId, partNamePrefix, uuidTail);
638
639 scene.AddNewSceneObject(so, false);
640
641 return so;
642 }
643
644 /// <summary>
645 /// Create a scene object part.
646 /// </summary>
647 /// <param name="name"></param>
648 /// <param name="id"></param>
649 /// <param name="ownerId"></param>
650 /// <returns></returns>
651 public static SceneObjectPart CreateSceneObjectPart(string name, UUID id, UUID ownerId)
652 {
653 return new SceneObjectPart(
654 ownerId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
655 { Name = name, UUID = id, Scale = new Vector3(1, 1, 1) };
656 }
657
658 /// <summary>
659 /// Create a scene object but do not add it to the scene.
660 /// </summary>
661 /// <remarks>
662 /// UUID always starts at 00000000-0000-0000-0000-000000000001. For some purposes, (e.g. serializing direct
663 /// to another object's inventory) we do not need a scene unique ID. So it would be better to add the
664 /// UUID when we actually add an object to a scene rather than on creation.
665 /// </remarks>
666 /// <param name="parts">The number of parts that should be in the scene object</param>
667 /// <param name="ownerId"></param>
668 /// <returns></returns>
669 public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId)
670 {
671 return CreateSceneObject(parts, ownerId, 0x1);
672 }
673
674 /// <summary>
675 /// Create a scene object but do not add it to the scene.
676 /// </summary>
677 /// <param name="parts">The number of parts that should be in the scene object</param>
678 /// <param name="ownerId"></param>
679 /// <param name="uuidTail">
680 /// The hexadecimal last part of the UUID for parts created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
681 /// will be given to the root part, and incremented for each part thereafter.
682 /// </param>
683 /// <returns></returns>
684 public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId, int uuidTail)
685 {
686 return CreateSceneObject(parts, ownerId, "", uuidTail);
687 }
688
689 /// <summary>
690 /// Create a scene object but do not add it to the scene.
691 /// </summary>
692 /// <param name="parts">
693 /// The number of parts that should be in the scene object
694 /// </param>
695 /// <param name="ownerId"></param>
696 /// <param name="partNamePrefix">
697 /// The prefix to be given to part names. This will be suffixed with "Part<part no>"
698 /// (e.g. mynamePart1 for the root part)
699 /// </param>
700 /// <param name="uuidTail">
701 /// The hexadecimal last part of the UUID for parts created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
702 /// will be given to the root part, and incremented for each part thereafter.
703 /// </param>
704 /// <returns></returns>
705 public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId, string partNamePrefix, int uuidTail)
706 {
707 string rawSogId = string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail);
708
709 SceneObjectGroup sog
710 = new SceneObjectGroup(
711 CreateSceneObjectPart(string.Format("{0}Part1", partNamePrefix), new UUID(rawSogId), ownerId));
712
713 if (parts > 1)
714 for (int i = 2; i <= parts; i++)
715 sog.AddPart(
716 CreateSceneObjectPart(
717 string.Format("{0}Part{1}", partNamePrefix, i),
718 new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail + i - 1)),
719 ownerId));
720
721 return sog;
722 }
723 }
724}