clockwerk-opensim-stable – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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  
28 using System;
29 using System.Net;
30 using System.Collections.Generic;
31 using Nini.Config;
32 using OpenMetaverse;
33 using OpenSim.Framework;
34 using OpenSim.Framework.Communications;
35 using OpenSim.Framework.Console;
36 using OpenSim.Framework.Servers;
37 using OpenSim.Framework.Servers.HttpServer;
38 using OpenSim.Region.Physics.Manager;
39 using OpenSim.Region.Framework;
40 using OpenSim.Region.Framework.Interfaces;
41 using OpenSim.Region.Framework.Scenes;
42 using OpenSim.Region.CoreModules.Avatar.Gods;
43 using OpenSim.Region.CoreModules.Asset;
44 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset;
45 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication;
46 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory;
47 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid;
48 using OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts;
49 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence;
50 using OpenSim.Services.Interfaces;
51 using OpenSim.Tests.Common.Mock;
52 using GridRegion = OpenSim.Services.Interfaces.GridRegion;
53  
54 namespace 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 private AgentCircuitManager m_acm = new AgentCircuitManager();
67 private ISimulationDataService m_simDataService
68 = OpenSim.Server.Base.ServerUtils.LoadPlugin<ISimulationDataService>("OpenSim.Tests.Common.dll", null);
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  
101 /// <summary>
102 /// Set up a test scene
103 /// </summary>
104 /// <remarks>
105 /// Automatically starts services, as would the normal runtime.
106 /// </remarks>
107 /// <returns></returns>
108 public TestScene SetupScene()
109 {
110 return SetupScene("Unit test region", UUID.Random(), 1000, 1000);
111 }
112  
113 public TestScene SetupScene(string name, UUID id, uint x, uint y)
114 {
115 return SetupScene(name, id, x, y, new IniConfigSource());
116 }
117  
118 /// <summary>
119 /// Set up a scene.
120 /// </summary>
121 /// <param name="name">Name of the region</param>
122 /// <param name="id">ID of the region</param>
123 /// <param name="x">X co-ordinate of the region</param>
124 /// <param name="y">Y co-ordinate of the region</param>
125 /// <param name="configSource"></param>
126 /// <returns></returns>
127 public TestScene SetupScene(
128 string name, UUID id, uint x, uint y, IConfigSource configSource)
129 {
130 Console.WriteLine("Setting up test scene {0}", name);
131  
132 // We must set up a console otherwise setup of some modules may fail
133 MainConsole.Instance = new MockConsole();
134  
135 RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1");
136 regInfo.RegionName = name;
137 regInfo.RegionID = id;
138  
139 SceneCommunicationService scs = new SceneCommunicationService();
140  
141 TestScene testScene = new TestScene(
142 regInfo, m_acm, scs, m_simDataService, m_estateDataService, configSource, null);
143  
144 INonSharedRegionModule godsModule = new GodsModule();
145 godsModule.Initialise(new IniConfigSource());
146 godsModule.AddRegion(testScene);
147  
148 // Add scene to services
149 m_assetService.AddRegion(testScene);
150  
151 if (m_cache != null)
152 {
153 m_cache.AddRegion(testScene);
154 m_cache.RegionLoaded(testScene);
155 testScene.AddRegionModule(m_cache.Name, m_cache);
156 }
157  
158 m_assetService.RegionLoaded(testScene);
159 testScene.AddRegionModule(m_assetService.Name, m_assetService);
160  
161 m_authenticationService.AddRegion(testScene);
162 m_authenticationService.RegionLoaded(testScene);
163 testScene.AddRegionModule(m_authenticationService.Name, m_authenticationService);
164  
165 m_inventoryService.AddRegion(testScene);
166 m_inventoryService.RegionLoaded(testScene);
167 testScene.AddRegionModule(m_inventoryService.Name, m_inventoryService);
168  
169 m_gridService.AddRegion(testScene);
170 m_gridService.RegionLoaded(testScene);
171 testScene.AddRegionModule(m_gridService.Name, m_gridService);
172  
173 m_userAccountService.AddRegion(testScene);
174 m_userAccountService.RegionLoaded(testScene);
175 testScene.AddRegionModule(m_userAccountService.Name, m_userAccountService);
176  
177 m_presenceService.AddRegion(testScene);
178 m_presenceService.RegionLoaded(testScene);
179 testScene.AddRegionModule(m_presenceService.Name, m_presenceService);
180  
181 testScene.RegionInfo.EstateSettings.EstateOwner = UUID.Random();
182 testScene.SetModuleInterfaces();
183  
184 testScene.LandChannel = new TestLandChannel(testScene);
185 testScene.LoadWorldMap();
186  
187 PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager();
188 physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll");
189 testScene.PhysicsScene
190 = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", new IniConfigSource(), "test");
191  
192 testScene.RegionInfo.EstateSettings = new EstateSettings();
193 testScene.LoginsEnabled = true;
194 testScene.RegisterRegionWithGrid();
195  
196 SceneManager.Add(testScene);
197  
198 return testScene;
199 }
200  
201 private static LocalAssetServicesConnector StartAssetService(CoreAssetCache cache)
202 {
203 IConfigSource config = new IniConfigSource();
204 config.AddConfig("Modules");
205 config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector");
206 config.AddConfig("AssetService");
207 config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService");
208 config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
209  
210 LocalAssetServicesConnector assetService = new LocalAssetServicesConnector();
211 assetService.Initialise(config);
212  
213 if (cache != null)
214 {
215 IConfigSource cacheConfig = new IniConfigSource();
216 cacheConfig.AddConfig("Modules");
217 cacheConfig.Configs["Modules"].Set("AssetCaching", "CoreAssetCache");
218 cacheConfig.AddConfig("AssetCache");
219  
220 cache.Initialise(cacheConfig);
221 }
222  
223 return assetService;
224 }
225  
226 private static LocalAuthenticationServicesConnector StartAuthenticationService()
227 {
228 IConfigSource config = new IniConfigSource();
229 config.AddConfig("Modules");
230 config.AddConfig("AuthenticationService");
231 config.Configs["Modules"].Set("AuthenticationServices", "LocalAuthenticationServicesConnector");
232 config.Configs["AuthenticationService"].Set(
233 "LocalServiceModule", "OpenSim.Services.AuthenticationService.dll:PasswordAuthenticationService");
234 config.Configs["AuthenticationService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
235  
236 LocalAuthenticationServicesConnector service = new LocalAuthenticationServicesConnector();
237 service.Initialise(config);
238  
239 return service;
240 }
241  
242 private static LocalInventoryServicesConnector StartInventoryService()
243 {
244 IConfigSource config = new IniConfigSource();
245 config.AddConfig("Modules");
246 config.AddConfig("InventoryService");
247 config.Configs["Modules"].Set("InventoryServices", "LocalInventoryServicesConnector");
248 config.Configs["InventoryService"].Set("LocalServiceModule", "OpenSim.Services.InventoryService.dll:XInventoryService");
249 config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll");
250  
251 LocalInventoryServicesConnector inventoryService = new LocalInventoryServicesConnector();
252 inventoryService.Initialise(config);
253  
254 return inventoryService;
255 }
256  
257 private static LocalGridServicesConnector StartGridService()
258 {
259 IConfigSource config = new IniConfigSource();
260 config.AddConfig("Modules");
261 config.AddConfig("GridService");
262 config.Configs["Modules"].Set("GridServices", "LocalGridServicesConnector");
263 config.Configs["GridService"].Set("StorageProvider", "OpenSim.Data.Null.dll:NullRegionData");
264 config.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Services.GridService.dll:GridService");
265 config.Configs["GridService"].Set("ConnectionString", "!static");
266  
267 LocalGridServicesConnector gridService = new LocalGridServicesConnector();
268 gridService.Initialise(config);
269  
270 return gridService;
271 }
272  
273 /// <summary>
274 /// Start a user account service
275 /// </summary>
276 /// <param name="testScene"></param>
277 /// <returns></returns>
278 private static LocalUserAccountServicesConnector StartUserAccountService()
279 {
280 IConfigSource config = new IniConfigSource();
281 config.AddConfig("Modules");
282 config.AddConfig("UserAccountService");
283 config.Configs["Modules"].Set("UserAccountServices", "LocalUserAccountServicesConnector");
284 config.Configs["UserAccountService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
285 config.Configs["UserAccountService"].Set(
286 "LocalServiceModule", "OpenSim.Services.UserAccountService.dll:UserAccountService");
287  
288 LocalUserAccountServicesConnector userAccountService = new LocalUserAccountServicesConnector();
289 userAccountService.Initialise(config);
290  
291 return userAccountService;
292 }
293  
294 /// <summary>
295 /// Start a presence service
296 /// </summary>
297 /// <param name="testScene"></param>
298 private static LocalPresenceServicesConnector StartPresenceService()
299 {
300 IConfigSource config = new IniConfigSource();
301 config.AddConfig("Modules");
302 config.AddConfig("PresenceService");
303 config.Configs["Modules"].Set("PresenceServices", "LocalPresenceServicesConnector");
304 config.Configs["PresenceService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
305 config.Configs["PresenceService"].Set(
306 "LocalServiceModule", "OpenSim.Services.PresenceService.dll:PresenceService");
307  
308 LocalPresenceServicesConnector presenceService = new LocalPresenceServicesConnector();
309 presenceService.Initialise(config);
310  
311 return presenceService;
312 }
313  
314 /// <summary>
315 /// Setup modules for a scene using their default settings.
316 /// </summary>
317 /// <param name="scene"></param>
318 /// <param name="modules"></param>
319 public static void SetupSceneModules(Scene scene, params object[] modules)
320 {
321 SetupSceneModules(scene, new IniConfigSource(), modules);
322 }
323  
324 /// <summary>
325 /// Setup modules for a scene.
326 /// </summary>
327 /// <remarks>
328 /// If called directly, then all the modules must be shared modules.
329 /// </remarks>
330 /// <param name="scenes"></param>
331 /// <param name="config"></param>
332 /// <param name="modules"></param>
333 public static void SetupSceneModules(Scene scene, IConfigSource config, params object[] modules)
334 {
335 SetupSceneModules(new Scene[] { scene }, config, modules);
336 }
337  
338 /// <summary>
339 /// Setup modules for a scene using their default settings.
340 /// </summary>
341 /// <param name="scenes"></param>
342 /// <param name="modules"></param>
343 public static void SetupSceneModules(Scene[] scenes, params object[] modules)
344 {
345 SetupSceneModules(scenes, new IniConfigSource(), modules);
346 }
347  
348 /// <summary>
349 /// Setup modules for scenes.
350 /// </summary>
351 /// <remarks>
352 /// If called directly, then all the modules must be shared modules.
353 ///
354 /// We are emulating here the normal calls made to setup region modules
355 /// (Initialise(), PostInitialise(), AddRegion, RegionLoaded()).
356 /// TODO: Need to reuse normal runtime module code.
357 /// </remarks>
358 /// <param name="scenes"></param>
359 /// <param name="config"></param>
360 /// <param name="modules"></param>
361 public static void SetupSceneModules(Scene[] scenes, IConfigSource config, params object[] modules)
362 {
363 List<IRegionModuleBase> newModules = new List<IRegionModuleBase>();
364 foreach (object module in modules)
365 {
366 IRegionModuleBase m = (IRegionModuleBase)module;
367 // Console.WriteLine("MODULE {0}", m.Name);
368 m.Initialise(config);
369 newModules.Add(m);
370 }
371  
372 foreach (IRegionModuleBase module in newModules)
373 {
374 if (module is ISharedRegionModule) ((ISharedRegionModule)module).PostInitialise();
375 }
376  
377 foreach (IRegionModuleBase module in newModules)
378 {
379 foreach (Scene scene in scenes)
380 {
381 module.AddRegion(scene);
382 scene.AddRegionModule(module.Name, module);
383 }
384 }
385  
386 // RegionLoaded is fired after all modules have been appropriately added to all scenes
387 foreach (IRegionModuleBase module in newModules)
388 foreach (Scene scene in scenes)
389 module.RegionLoaded(scene);
390  
391 foreach (Scene scene in scenes) { scene.SetModuleInterfaces(); }
392 }
393  
394 /// <summary>
395 /// Generate some standard agent connection data.
396 /// </summary>
397 /// <param name="agentId"></param>
398 /// <returns></returns>
399 public static AgentCircuitData GenerateAgentData(UUID agentId)
400 {
401 AgentCircuitData acd = GenerateCommonAgentData();
402  
403 acd.AgentID = agentId;
404 acd.firstname = "testfirstname";
405 acd.lastname = "testlastname";
406 acd.ServiceURLs = new Dictionary<string, object>();
407  
408 return acd;
409 }
410  
411 /// <summary>
412 /// Generate some standard agent connection data.
413 /// </summary>
414 /// <param name="agentId"></param>
415 /// <returns></returns>
416 public static AgentCircuitData GenerateAgentData(UserAccount ua)
417 {
418 AgentCircuitData acd = GenerateCommonAgentData();
419  
420 acd.AgentID = ua.PrincipalID;
421 acd.firstname = ua.FirstName;
422 acd.lastname = ua.LastName;
423 acd.ServiceURLs = ua.ServiceURLs;
424  
425 return acd;
426 }
427  
428 private static AgentCircuitData GenerateCommonAgentData()
429 {
430 AgentCircuitData acd = new AgentCircuitData();
431  
432 // XXX: Sessions must be unique, otherwise one presence can overwrite another in NullPresenceData.
433 acd.SessionID = UUID.Random();
434 acd.SecureSessionID = UUID.Random();
435  
436 acd.circuitcode = 123;
437 acd.BaseFolder = UUID.Zero;
438 acd.InventoryFolder = UUID.Zero;
439 acd.startpos = Vector3.Zero;
440 acd.CapsPath = "http://wibble.com";
441 acd.Appearance = new AvatarAppearance();
442  
443 return acd;
444 }
445  
446 /// <summary>
447 /// Add a root agent where the details of the agent connection (apart from the id) are unimportant for the test
448 /// </summary>
449 /// <remarks>
450 /// XXX: Use the version of this method that takes the UserAccount structure wherever possible - this will
451 /// make the agent circuit data (e.g. first, lastname) consistent with the user account data.
452 /// </remarks>
453 /// <param name="scene"></param>
454 /// <param name="agentId"></param>
455 /// <returns></returns>
456 public static ScenePresence AddScenePresence(Scene scene, UUID agentId)
457 {
458 return AddScenePresence(scene, GenerateAgentData(agentId));
459 }
460  
461 /// <summary>
462 /// Add a root agent.
463 /// </summary>
464 /// <param name="scene"></param>
465 /// <param name="ua"></param>
466 /// <returns></returns>
467 public static ScenePresence AddScenePresence(Scene scene, UserAccount ua)
468 {
469 return AddScenePresence(scene, GenerateAgentData(ua));
470 }
471  
472 /// <summary>
473 /// Add a root agent.
474 /// </summary>
475 /// <remarks>
476 /// This function
477 ///
478 /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the
479 /// userserver if grid) would give initial login data back to the client and separately tell the scene that the
480 /// agent was coming.
481 ///
482 /// 2) Connects the agent with the scene
483 ///
484 /// This function performs actions equivalent with notifying the scene that an agent is
485 /// coming and then actually connecting the agent to the scene. The one step missed out is the very first
486 /// </remarks>
487 /// <param name="scene"></param>
488 /// <param name="agentData"></param>
489 /// <returns></returns>
490 public static ScenePresence AddScenePresence(Scene scene, AgentCircuitData agentData)
491 {
492 return AddScenePresence(scene, new TestClient(agentData, scene), agentData);
493 }
494  
495 /// <summary>
496 /// Add a root agent.
497 /// </summary>
498 /// <remarks>
499 /// This function
500 ///
501 /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the
502 /// userserver if grid) would give initial login data back to the client and separately tell the scene that the
503 /// agent was coming.
504 ///
505 /// 2) Connects the agent with the scene
506 ///
507 /// This function performs actions equivalent with notifying the scene that an agent is
508 /// coming and then actually connecting the agent to the scene. The one step missed out is the very first
509 /// </remarks>
510 /// <param name="scene"></param>
511 /// <param name="agentData"></param>
512 /// <returns></returns>
513 public static ScenePresence AddScenePresence(
514 Scene scene, IClientAPI client, AgentCircuitData agentData)
515 {
516 // We emulate the proper login sequence here by doing things in four stages
517  
518 // Stage 0: login
519 // We need to punch through to the underlying service because scene will not, correctly, let us call it
520 // through it's reference to the LPSC
521 LocalPresenceServicesConnector lpsc = (LocalPresenceServicesConnector)scene.PresenceService;
522 lpsc.m_PresenceService.LoginAgent(agentData.AgentID.ToString(), agentData.SessionID, agentData.SecureSessionID);
523  
524 // Stages 1 & 2
525 ScenePresence sp = IntroduceClientToScene(scene, client, agentData, TeleportFlags.ViaLogin);
526  
527 // Stage 3: Complete the entrance into the region. This converts the child agent into a root agent.
528 sp.CompleteMovement(sp.ControllingClient, true);
529  
530 return sp;
531 }
532  
533 /// <summary>
534 /// Introduce an agent into the scene by adding a new client.
535 /// </summary>
536 /// <returns>The scene presence added</returns>
537 /// <param name='scene'></param>
538 /// <param name='testClient'></param>
539 /// <param name='agentData'></param>
540 /// <param name='tf'></param>
541 private static ScenePresence IntroduceClientToScene(
542 Scene scene, IClientAPI client, AgentCircuitData agentData, TeleportFlags tf)
543 {
544 string reason;
545  
546 // Stage 1: tell the scene to expect a new user connection
547 if (!scene.NewUserConnection(agentData, (uint)tf, out reason))
548 Console.WriteLine("NewUserConnection failed: " + reason);
549  
550 // Stage 2: add the new client as a child agent to the scene
551 scene.AddNewAgent(client, PresenceType.User);
552  
553 return scene.GetScenePresence(client.AgentId);
554 }
555  
556 public static ScenePresence AddChildScenePresence(Scene scene, UUID agentId)
557 {
558 AgentCircuitData acd = GenerateAgentData(agentId);
559 acd.child = true;
560  
561 // XXX: ViaLogin may not be correct for child agents
562 TestClient client = new TestClient(acd, scene);
563 return IntroduceClientToScene(scene, client, acd, TeleportFlags.ViaLogin);
564 }
565  
566 /// <summary>
567 /// Add a test object
568 /// </summary>
569 /// <param name="scene"></param>
570 /// <returns></returns>
571 public static SceneObjectGroup AddSceneObject(Scene scene)
572 {
573 return AddSceneObject(scene, "Test Object", UUID.Zero);
574 }
575  
576 /// <summary>
577 /// Add a test object
578 /// </summary>
579 /// <param name="scene"></param>
580 /// <param name="name"></param>
581 /// <param name="ownerId"></param>
582 /// <returns></returns>
583 public static SceneObjectGroup AddSceneObject(Scene scene, string name, UUID ownerId)
584 {
585 SceneObjectGroup so = new SceneObjectGroup(CreateSceneObjectPart(name, UUID.Random(), ownerId));
586  
587 //part.UpdatePrimFlags(false, false, true);
588 //part.ObjectFlags |= (uint)PrimFlags.Phantom;
589  
590 scene.AddNewSceneObject(so, false);
591  
592 return so;
593 }
594  
595 /// <summary>
596 /// Create a scene object part.
597 /// </summary>
598 /// <param name="name"></param>
599 /// <param name="id"></param>
600 /// <param name="ownerId"></param>
601 /// <returns></returns>
602 public static SceneObjectPart CreateSceneObjectPart(string name, UUID id, UUID ownerId)
603 {
604 return new SceneObjectPart(
605 ownerId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero)
606 { Name = name, UUID = id, Scale = new Vector3(1, 1, 1) };
607 }
608  
609 /// <summary>
610 /// Create a scene object but do not add it to the scene.
611 /// </summary>
612 /// <remarks>
613 /// UUID always starts at 00000000-0000-0000-0000-000000000001. For some purposes, (e.g. serializing direct
614 /// to another object's inventory) we do not need a scene unique ID. So it would be better to add the
615 /// UUID when we actually add an object to a scene rather than on creation.
616 /// </remarks>
617 /// <param name="parts">The number of parts that should be in the scene object</param>
618 /// <param name="ownerId"></param>
619 /// <returns></returns>
620 public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId)
621 {
622 return CreateSceneObject(parts, ownerId, 0x1);
623 }
624  
625 /// <summary>
626 /// Create a scene object but do not add it to the scene.
627 /// </summary>
628 /// <param name="parts">The number of parts that should be in the scene object</param>
629 /// <param name="ownerId"></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 CreateSceneObject(int parts, UUID ownerId, int uuidTail)
636 {
637 return CreateSceneObject(parts, ownerId, "", uuidTail);
638 }
639  
640 /// <summary>
641 /// Create a scene object but do not add it to the scene.
642 /// </summary>
643 /// <param name="parts">
644 /// The number of parts that should be in the scene object
645 /// </param>
646 /// <param name="ownerId"></param>
647 /// <param name="partNamePrefix">
648 /// The prefix to be given to part names. This will be suffixed with "Part<part no>"
649 /// (e.g. mynamePart1 for the root part)
650 /// </param>
651 /// <param name="uuidTail">
652 /// The hexadecimal last part of the UUID for parts created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}"
653 /// will be given to the root part, and incremented for each part thereafter.
654 /// </param>
655 /// <returns></returns>
656 public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId, string partNamePrefix, int uuidTail)
657 {
658 string rawSogId = string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail);
659  
660 SceneObjectGroup sog
661 = new SceneObjectGroup(
662 CreateSceneObjectPart(string.Format("{0}Part1", partNamePrefix), new UUID(rawSogId), ownerId));
663  
664 if (parts > 1)
665 for (int i = 2; i <= parts; i++)
666 sog.AddPart(
667 CreateSceneObjectPart(
668 string.Format("{0}Part{1}", partNamePrefix, i),
669 new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail + i - 1)),
670 ownerId));
671  
672 return sog;
673 }
674 }
675 }