diff options
author | Justin Clark-Casey (justincc) | 2011-05-21 00:51:34 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2011-05-21 00:51:34 +0100 |
commit | 4073f1013346e206131f2f7d40508fd2bf0505d4 (patch) | |
tree | e788de7181beeaddfb74858f40e515c1e37f7da4 /OpenSim/Tests/Common/Helpers/SceneSetupHelpers.cs | |
parent | rename UserInventoryTestsUtils -> UserInventoryHelpers for consistency (diff) | |
download | opensim-SC_OLD-4073f1013346e206131f2f7d40508fd2bf0505d4.zip opensim-SC_OLD-4073f1013346e206131f2f7d40508fd2bf0505d4.tar.gz opensim-SC_OLD-4073f1013346e206131f2f7d40508fd2bf0505d4.tar.bz2 opensim-SC_OLD-4073f1013346e206131f2f7d40508fd2bf0505d4.tar.xz |
rename test helpers enclosing package from Setup to Helpers
Diffstat (limited to 'OpenSim/Tests/Common/Helpers/SceneSetupHelpers.cs')
-rw-r--r-- | OpenSim/Tests/Common/Helpers/SceneSetupHelpers.cs | 483 |
1 files changed, 483 insertions, 0 deletions
diff --git a/OpenSim/Tests/Common/Helpers/SceneSetupHelpers.cs b/OpenSim/Tests/Common/Helpers/SceneSetupHelpers.cs new file mode 100644 index 0000000..d122409 --- /dev/null +++ b/OpenSim/Tests/Common/Helpers/SceneSetupHelpers.cs | |||
@@ -0,0 +1,483 @@ | |||
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.ServiceConnectorsOut.Asset; | ||
44 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication; | ||
45 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory; | ||
46 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid; | ||
47 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts; | ||
48 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence; | ||
49 | using OpenSim.Services.Interfaces; | ||
50 | using OpenSim.Tests.Common.Mock; | ||
51 | |||
52 | namespace OpenSim.Tests.Common.Setup | ||
53 | { | ||
54 | /// <summary> | ||
55 | /// Helpers for setting up scenes. | ||
56 | /// </summary> | ||
57 | public class SceneSetupHelpers | ||
58 | { | ||
59 | /// <summary> | ||
60 | /// Set up a test scene | ||
61 | /// </summary> | ||
62 | /// <remarks> | ||
63 | /// Automatically starts service threads, as would the normal runtime. | ||
64 | /// </remarks> | ||
65 | /// <returns></returns> | ||
66 | public static TestScene SetupScene() | ||
67 | { | ||
68 | return SetupScene("Unit test region", UUID.Random(), 1000, 1000); | ||
69 | } | ||
70 | |||
71 | /// <summary> | ||
72 | /// Set up a scene. If it's more then one scene, use the same CommunicationsManager to link regions | ||
73 | /// or a different, to get a brand new scene with new shared region modules. | ||
74 | /// </summary> | ||
75 | /// <param name="name">Name of the region</param> | ||
76 | /// <param name="id">ID of the region</param> | ||
77 | /// <param name="x">X co-ordinate of the region</param> | ||
78 | /// <param name="y">Y co-ordinate of the region</param> | ||
79 | /// <param name="cm">This should be the same if simulating two scenes within a standalone</param> | ||
80 | /// <returns></returns> | ||
81 | public static TestScene SetupScene(string name, UUID id, uint x, uint y) | ||
82 | { | ||
83 | Console.WriteLine("Setting up test scene {0}", name); | ||
84 | |||
85 | // We must set up a console otherwise setup of some modules may fail | ||
86 | MainConsole.Instance = new MockConsole("TEST PROMPT"); | ||
87 | |||
88 | RegionInfo regInfo = new RegionInfo(x, y, new IPEndPoint(IPAddress.Loopback, 9000), "127.0.0.1"); | ||
89 | regInfo.RegionName = name; | ||
90 | regInfo.RegionID = id; | ||
91 | |||
92 | AgentCircuitManager acm = new AgentCircuitManager(); | ||
93 | SceneCommunicationService scs = new SceneCommunicationService(); | ||
94 | |||
95 | ISimulationDataService simDataService = OpenSim.Server.Base.ServerUtils.LoadPlugin<ISimulationDataService>("OpenSim.Tests.Common.dll", null); | ||
96 | IEstateDataService estateDataService = null; | ||
97 | IConfigSource configSource = new IniConfigSource(); | ||
98 | |||
99 | TestScene testScene = new TestScene( | ||
100 | regInfo, acm, scs, simDataService, estateDataService, null, false, false, false, configSource, null); | ||
101 | |||
102 | IRegionModule godsModule = new GodsModule(); | ||
103 | godsModule.Initialise(testScene, new IniConfigSource()); | ||
104 | testScene.AddModule(godsModule.Name, godsModule); | ||
105 | |||
106 | LocalAssetServicesConnector assetService = StartAssetService(testScene); | ||
107 | StartAuthenticationService(testScene); | ||
108 | LocalInventoryServicesConnector inventoryService = StartInventoryService(testScene); | ||
109 | StartGridService(testScene); | ||
110 | LocalUserAccountServicesConnector userAccountService = StartUserAccountService(testScene); | ||
111 | LocalPresenceServicesConnector presenceService = StartPresenceService(testScene); | ||
112 | |||
113 | inventoryService.PostInitialise(); | ||
114 | assetService.PostInitialise(); | ||
115 | userAccountService.PostInitialise(); | ||
116 | presenceService.PostInitialise(); | ||
117 | |||
118 | testScene.RegionInfo.EstateSettings.EstateOwner = UUID.Random(); | ||
119 | testScene.SetModuleInterfaces(); | ||
120 | |||
121 | testScene.LandChannel = new TestLandChannel(testScene); | ||
122 | testScene.LoadWorldMap(); | ||
123 | |||
124 | PhysicsPluginManager physicsPluginManager = new PhysicsPluginManager(); | ||
125 | physicsPluginManager.LoadPluginsFromAssembly("Physics/OpenSim.Region.Physics.BasicPhysicsPlugin.dll"); | ||
126 | testScene.PhysicsScene | ||
127 | = physicsPluginManager.GetPhysicsScene("basicphysics", "ZeroMesher", new IniConfigSource(), "test"); | ||
128 | |||
129 | testScene.RegionInfo.EstateSettings = new EstateSettings(); | ||
130 | testScene.LoginsDisabled = false; | ||
131 | |||
132 | return testScene; | ||
133 | } | ||
134 | |||
135 | private static LocalAssetServicesConnector StartAssetService(Scene testScene) | ||
136 | { | ||
137 | LocalAssetServicesConnector assetService = new LocalAssetServicesConnector(); | ||
138 | IConfigSource config = new IniConfigSource(); | ||
139 | |||
140 | config.AddConfig("Modules"); | ||
141 | config.Configs["Modules"].Set("AssetServices", "LocalAssetServicesConnector"); | ||
142 | config.AddConfig("AssetService"); | ||
143 | config.Configs["AssetService"].Set("LocalServiceModule", "OpenSim.Services.AssetService.dll:AssetService"); | ||
144 | config.Configs["AssetService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); | ||
145 | |||
146 | assetService.Initialise(config); | ||
147 | assetService.AddRegion(testScene); | ||
148 | assetService.RegionLoaded(testScene); | ||
149 | testScene.AddRegionModule(assetService.Name, assetService); | ||
150 | |||
151 | return assetService; | ||
152 | } | ||
153 | |||
154 | private static void StartAuthenticationService(Scene testScene) | ||
155 | { | ||
156 | ISharedRegionModule service = new LocalAuthenticationServicesConnector(); | ||
157 | IConfigSource config = new IniConfigSource(); | ||
158 | |||
159 | config.AddConfig("Modules"); | ||
160 | config.AddConfig("AuthenticationService"); | ||
161 | config.Configs["Modules"].Set("AuthenticationServices", "LocalAuthenticationServicesConnector"); | ||
162 | config.Configs["AuthenticationService"].Set( | ||
163 | "LocalServiceModule", "OpenSim.Services.AuthenticationService.dll:PasswordAuthenticationService"); | ||
164 | config.Configs["AuthenticationService"].Set("StorageProvider", "OpenSim.Data.Null.dll"); | ||
165 | |||
166 | service.Initialise(config); | ||
167 | service.AddRegion(testScene); | ||
168 | service.RegionLoaded(testScene); | ||
169 | testScene.AddRegionModule(service.Name, service); | ||
170 | //m_authenticationService = service; | ||
171 | } | ||
172 | |||
173 | private static LocalInventoryServicesConnector StartInventoryService(Scene testScene) | ||
174 | { | ||
175 | LocalInventoryServicesConnector inventoryService = new LocalInventoryServicesConnector(); | ||
176 | |||
177 | IConfigSource config = new IniConfigSource(); | ||
178 | config.AddConfig("Modules"); | ||
179 | config.AddConfig("InventoryService"); | ||
180 | config.Configs["Modules"].Set("InventoryServices", "LocalInventoryServicesConnector"); | ||
181 | config.Configs["InventoryService"].Set("LocalServiceModule", "OpenSim.Services.InventoryService.dll:InventoryService"); | ||
182 | config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll"); | ||
183 | |||
184 | inventoryService.Initialise(config); | ||
185 | inventoryService.AddRegion(testScene); | ||
186 | inventoryService.RegionLoaded(testScene); | ||
187 | testScene.AddRegionModule(inventoryService.Name, inventoryService); | ||
188 | |||
189 | return inventoryService; | ||
190 | } | ||
191 | |||
192 | private static LocalGridServicesConnector StartGridService(Scene testScene) | ||
193 | { | ||
194 | IConfigSource config = new IniConfigSource(); | ||
195 | config.AddConfig("Modules"); | ||
196 | config.AddConfig("GridService"); | ||
197 | config.Configs["Modules"].Set("GridServices", "LocalGridServicesConnector"); | ||
198 | config.Configs["GridService"].Set("StorageProvider", "OpenSim.Data.Null.dll:NullRegionData"); | ||
199 | config.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Services.GridService.dll:GridService"); | ||
200 | |||
201 | LocalGridServicesConnector gridService = new LocalGridServicesConnector(); | ||
202 | gridService.Initialise(config); | ||
203 | gridService.AddRegion(testScene); | ||
204 | gridService.RegionLoaded(testScene); | ||
205 | |||
206 | return gridService; | ||
207 | } | ||
208 | |||
209 | /// <summary> | ||
210 | /// Start a user account service | ||
211 | /// </summary> | ||
212 | /// <param name="testScene"></param> | ||
213 | /// <returns></returns> | ||
214 | private static LocalUserAccountServicesConnector StartUserAccountService(Scene testScene) | ||
215 | { | ||
216 | IConfigSource config = new IniConfigSource(); | ||
217 | config.AddConfig("Modules"); | ||
218 | config.AddConfig("UserAccountService"); | ||
219 | config.Configs["Modules"].Set("UserAccountServices", "LocalUserAccountServicesConnector"); | ||
220 | config.Configs["UserAccountService"].Set("StorageProvider", "OpenSim.Data.Null.dll"); | ||
221 | config.Configs["UserAccountService"].Set( | ||
222 | "LocalServiceModule", "OpenSim.Services.UserAccountService.dll:UserAccountService"); | ||
223 | |||
224 | LocalUserAccountServicesConnector userAccountService = new LocalUserAccountServicesConnector(); | ||
225 | userAccountService.Initialise(config); | ||
226 | |||
227 | userAccountService.AddRegion(testScene); | ||
228 | userAccountService.RegionLoaded(testScene); | ||
229 | testScene.AddRegionModule(userAccountService.Name, userAccountService); | ||
230 | |||
231 | return userAccountService; | ||
232 | } | ||
233 | |||
234 | /// <summary> | ||
235 | /// Start a presence service | ||
236 | /// </summary> | ||
237 | /// <param name="testScene"></param> | ||
238 | private static LocalPresenceServicesConnector StartPresenceService(Scene testScene) | ||
239 | { | ||
240 | IConfigSource config = new IniConfigSource(); | ||
241 | config.AddConfig("Modules"); | ||
242 | config.AddConfig("PresenceService"); | ||
243 | config.Configs["Modules"].Set("PresenceServices", "LocalPresenceServicesConnector"); | ||
244 | config.Configs["PresenceService"].Set("StorageProvider", "OpenSim.Data.Null.dll"); | ||
245 | config.Configs["PresenceService"].Set( | ||
246 | "LocalServiceModule", "OpenSim.Services.PresenceService.dll:PresenceService"); | ||
247 | |||
248 | LocalPresenceServicesConnector presenceService = new LocalPresenceServicesConnector(); | ||
249 | presenceService.Initialise(config); | ||
250 | |||
251 | presenceService.AddRegion(testScene); | ||
252 | presenceService.RegionLoaded(testScene); | ||
253 | testScene.AddRegionModule(presenceService.Name, presenceService); | ||
254 | |||
255 | return presenceService; | ||
256 | } | ||
257 | |||
258 | /// <summary> | ||
259 | /// Setup modules for a scene using their default settings. | ||
260 | /// </summary> | ||
261 | /// <param name="scene"></param> | ||
262 | /// <param name="modules"></param> | ||
263 | public static void SetupSceneModules(Scene scene, params object[] modules) | ||
264 | { | ||
265 | SetupSceneModules(scene, new IniConfigSource(), modules); | ||
266 | } | ||
267 | |||
268 | /// <summary> | ||
269 | /// Setup modules for a scene. | ||
270 | /// </summary> | ||
271 | /// <param name="scene"></param> | ||
272 | /// <param name="config"></param> | ||
273 | /// <param name="modules"></param> | ||
274 | public static void SetupSceneModules(Scene scene, IConfigSource config, params object[] modules) | ||
275 | { | ||
276 | List<IRegionModuleBase> newModules = new List<IRegionModuleBase>(); | ||
277 | foreach (object module in modules) | ||
278 | { | ||
279 | if (module is IRegionModule) | ||
280 | { | ||
281 | IRegionModule m = (IRegionModule)module; | ||
282 | m.Initialise(scene, config); | ||
283 | scene.AddModule(m.Name, m); | ||
284 | m.PostInitialise(); | ||
285 | } | ||
286 | else if (module is IRegionModuleBase) | ||
287 | { | ||
288 | // for the new system, everything has to be initialised first, | ||
289 | // shared modules have to be post-initialised, then all get an AddRegion with the scene | ||
290 | IRegionModuleBase m = (IRegionModuleBase)module; | ||
291 | m.Initialise(config); | ||
292 | newModules.Add(m); | ||
293 | } | ||
294 | } | ||
295 | |||
296 | foreach (IRegionModuleBase module in newModules) | ||
297 | { | ||
298 | if (module is ISharedRegionModule) ((ISharedRegionModule)module).PostInitialise(); | ||
299 | } | ||
300 | |||
301 | foreach (IRegionModuleBase module in newModules) | ||
302 | { | ||
303 | module.AddRegion(scene); | ||
304 | scene.AddRegionModule(module.Name, module); | ||
305 | } | ||
306 | |||
307 | // RegionLoaded is fired after all modules have been appropriately added to all scenes | ||
308 | foreach (IRegionModuleBase module in newModules) | ||
309 | module.RegionLoaded(scene); | ||
310 | |||
311 | scene.SetModuleInterfaces(); | ||
312 | } | ||
313 | |||
314 | /// <summary> | ||
315 | /// Generate some standard agent connection data. | ||
316 | /// </summary> | ||
317 | /// <param name="agentId"></param> | ||
318 | /// <returns></returns> | ||
319 | public static AgentCircuitData GenerateAgentData(UUID agentId) | ||
320 | { | ||
321 | string firstName = "testfirstname"; | ||
322 | |||
323 | AgentCircuitData agentData = new AgentCircuitData(); | ||
324 | agentData.AgentID = agentId; | ||
325 | agentData.firstname = firstName; | ||
326 | agentData.lastname = "testlastname"; | ||
327 | agentData.SessionID = UUID.Zero; | ||
328 | agentData.SecureSessionID = UUID.Zero; | ||
329 | agentData.circuitcode = 123; | ||
330 | agentData.BaseFolder = UUID.Zero; | ||
331 | agentData.InventoryFolder = UUID.Zero; | ||
332 | agentData.startpos = Vector3.Zero; | ||
333 | agentData.CapsPath = "http://wibble.com"; | ||
334 | |||
335 | return agentData; | ||
336 | } | ||
337 | |||
338 | /// <summary> | ||
339 | /// Add a root agent where the details of the agent connection (apart from the id) are unimportant for the test | ||
340 | /// </summary> | ||
341 | /// <param name="scene"></param> | ||
342 | /// <param name="agentId"></param> | ||
343 | /// <returns></returns> | ||
344 | public static TestClient AddRootAgent(Scene scene, UUID agentId) | ||
345 | { | ||
346 | return AddRootAgent(scene, GenerateAgentData(agentId)); | ||
347 | } | ||
348 | |||
349 | /// <summary> | ||
350 | /// Add a root agent. | ||
351 | /// </summary> | ||
352 | /// <remarks> | ||
353 | /// This function | ||
354 | /// | ||
355 | /// 1) Tells the scene that an agent is coming. Normally, the login service (local if standalone, from the | ||
356 | /// userserver if grid) would give initial login data back to the client and separately tell the scene that the | ||
357 | /// agent was coming. | ||
358 | /// | ||
359 | /// 2) Connects the agent with the scene | ||
360 | /// | ||
361 | /// This function performs actions equivalent with notifying the scene that an agent is | ||
362 | /// coming and then actually connecting the agent to the scene. The one step missed out is the very first | ||
363 | /// </remarks> | ||
364 | /// <param name="scene"></param> | ||
365 | /// <param name="agentData"></param> | ||
366 | /// <returns></returns> | ||
367 | public static TestClient AddRootAgent(Scene scene, AgentCircuitData agentData) | ||
368 | { | ||
369 | string reason; | ||
370 | |||
371 | // We emulate the proper login sequence here by doing things in four stages | ||
372 | |||
373 | // Stage 0: log the presence | ||
374 | scene.PresenceService.LoginAgent(agentData.AgentID.ToString(), agentData.SessionID, agentData.SecureSessionID); | ||
375 | |||
376 | // Stage 1: simulate login by telling the scene to expect a new user connection | ||
377 | if (!scene.NewUserConnection(agentData, (uint)TeleportFlags.ViaLogin, out reason)) | ||
378 | Console.WriteLine("NewUserConnection failed: " + reason); | ||
379 | |||
380 | // Stage 2: add the new client as a child agent to the scene | ||
381 | TestClient client = new TestClient(agentData, scene); | ||
382 | scene.AddNewClient(client); | ||
383 | |||
384 | // Stage 3: Complete the entrance into the region. This converts the child agent into a root agent. | ||
385 | ScenePresence scp = scene.GetScenePresence(agentData.AgentID); | ||
386 | scp.CompleteMovement(client); | ||
387 | //scp.MakeRootAgent(new Vector3(90, 90, 90), true); | ||
388 | |||
389 | return client; | ||
390 | } | ||
391 | |||
392 | /// <summary> | ||
393 | /// Add a test object | ||
394 | /// </summary> | ||
395 | /// <param name="scene"></param> | ||
396 | /// <returns></returns> | ||
397 | public static SceneObjectPart AddSceneObject(Scene scene) | ||
398 | { | ||
399 | return AddSceneObject(scene, "Test Object"); | ||
400 | } | ||
401 | |||
402 | /// <summary> | ||
403 | /// Add a test object | ||
404 | /// </summary> | ||
405 | /// <param name="scene"></param> | ||
406 | /// <param name="name"></param> | ||
407 | /// <returns></returns> | ||
408 | public static SceneObjectPart AddSceneObject(Scene scene, string name) | ||
409 | { | ||
410 | SceneObjectPart part = CreateSceneObjectPart(name, UUID.Random(), UUID.Zero); | ||
411 | |||
412 | //part.UpdatePrimFlags(false, false, true); | ||
413 | //part.ObjectFlags |= (uint)PrimFlags.Phantom; | ||
414 | |||
415 | scene.AddNewSceneObject(new SceneObjectGroup(part), false); | ||
416 | |||
417 | return part; | ||
418 | } | ||
419 | |||
420 | /// <summary> | ||
421 | /// Create a scene object part. | ||
422 | /// </summary> | ||
423 | /// <param name="name"></param> | ||
424 | /// <param name="id"></param> | ||
425 | /// <param name="ownerId"></param> | ||
426 | /// <returns></returns> | ||
427 | public static SceneObjectPart CreateSceneObjectPart(string name, UUID id, UUID ownerId) | ||
428 | { | ||
429 | return new SceneObjectPart( | ||
430 | ownerId, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) | ||
431 | { Name = name, UUID = id, Scale = new Vector3(1, 1, 1) }; | ||
432 | } | ||
433 | |||
434 | /// <summary> | ||
435 | /// Create a scene object but do not add it to the scene. | ||
436 | /// </summary> | ||
437 | /// <remarks> | ||
438 | /// UUID always starts at 00000000-0000-0000-0000-000000000001 | ||
439 | /// </remarks> | ||
440 | /// <param name="parts">The number of parts that should be in the scene object</param> | ||
441 | /// <param name="ownerId"></param> | ||
442 | /// <returns></returns> | ||
443 | public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId) | ||
444 | { | ||
445 | return CreateSceneObject(parts, ownerId, "", 0x1); | ||
446 | } | ||
447 | |||
448 | /// <summary> | ||
449 | /// Create a scene object but do not add it to the scene. | ||
450 | /// </summary> | ||
451 | /// <param name="parts"> | ||
452 | /// The number of parts that should be in the scene object | ||
453 | /// </param> | ||
454 | /// <param name="ownerId"></param> | ||
455 | /// <param name="partNamePrefix"> | ||
456 | /// The prefix to be given to part names. This will be suffixed with "Part<part no>" | ||
457 | /// (e.g. mynamePart0 for the root part) | ||
458 | /// </param> | ||
459 | /// <param name="uuidTail"> | ||
460 | /// The hexadecimal last part of the UUID for parts created. A UUID of the form "00000000-0000-0000-0000-{0:XD12}" | ||
461 | /// will be given to the root part, and incremented for each part thereafter. | ||
462 | /// </param> | ||
463 | /// <returns></returns> | ||
464 | public static SceneObjectGroup CreateSceneObject(int parts, UUID ownerId, string partNamePrefix, int uuidTail) | ||
465 | { | ||
466 | string rawSogId = string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail); | ||
467 | |||
468 | SceneObjectGroup sog | ||
469 | = new SceneObjectGroup( | ||
470 | CreateSceneObjectPart(string.Format("{0}Part0", partNamePrefix), new UUID(rawSogId), ownerId)); | ||
471 | |||
472 | if (parts > 1) | ||
473 | for (int i = 1; i < parts; i++) | ||
474 | sog.AddPart( | ||
475 | CreateSceneObjectPart( | ||
476 | string.Format("{0}Part{1}", partNamePrefix, i), | ||
477 | new UUID(string.Format("00000000-0000-0000-0000-{0:X12}", uuidTail + i)), | ||
478 | ownerId)); | ||
479 | |||
480 | return sog; | ||
481 | } | ||
482 | } | ||
483 | } \ No newline at end of file | ||