opensim – Blame information for rev 1

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