diff options
Merge branch 'master' into careminster
Conflicts:
OpenSim/Data/MySQL/MySQLSimulationData.cs
OpenSim/Data/MySQL/Resources/RegionStore.migrations
OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs
OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs
OpenSim/Region/CoreModules/World/LightShare/LightShareModule.cs
OpenSim/Region/Framework/Scenes/Scene.cs
OpenSim/Region/Framework/Scenes/ScenePresence.cs
OpenSim/Region/Framework/Scenes/Tests/ScenePresenceCapabilityTests.cs
OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/ExtendedPhysics')
-rwxr-xr-x | OpenSim/Region/OptionalModules/Scripting/ExtendedPhysics/ExtendedPhysics.cs | 335 |
1 files changed, 326 insertions, 9 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/ExtendedPhysics/ExtendedPhysics.cs b/OpenSim/Region/OptionalModules/Scripting/ExtendedPhysics/ExtendedPhysics.cs index d1d318c..9daf9d7 100755 --- a/OpenSim/Region/OptionalModules/Scripting/ExtendedPhysics/ExtendedPhysics.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ExtendedPhysics/ExtendedPhysics.cs | |||
@@ -29,12 +29,14 @@ using System.Collections.Generic; | |||
29 | using System.Linq; | 29 | using System.Linq; |
30 | using System.Reflection; | 30 | using System.Reflection; |
31 | using System.Text; | 31 | using System.Text; |
32 | using System.Threading; | ||
32 | 33 | ||
33 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
34 | using OpenSim.Region.CoreModules; | 35 | using OpenSim.Region.CoreModules; |
35 | using OpenSim.Region.Framework; | 36 | using OpenSim.Region.Framework; |
36 | using OpenSim.Region.Framework.Interfaces; | 37 | using OpenSim.Region.Framework.Interfaces; |
37 | using OpenSim.Region.Framework.Scenes; | 38 | using OpenSim.Region.Framework.Scenes; |
39 | using OpenSim.Region.Physics.Manager; | ||
38 | 40 | ||
39 | using Mono.Addins; | 41 | using Mono.Addins; |
40 | using Nini.Config; | 42 | using Nini.Config; |
@@ -60,6 +62,10 @@ public class ExtendedPhysics : INonSharedRegionModule | |||
60 | // Per prim functions. See BSPrim. | 62 | // Per prim functions. See BSPrim. |
61 | public const string PhysFunctGetLinksetType = "BulletSim.GetLinksetType"; | 63 | public const string PhysFunctGetLinksetType = "BulletSim.GetLinksetType"; |
62 | public const string PhysFunctSetLinksetType = "BulletSim.SetLinksetType"; | 64 | public const string PhysFunctSetLinksetType = "BulletSim.SetLinksetType"; |
65 | public const string PhysFunctChangeLinkFixed = "BulletSim.ChangeLinkFixed"; | ||
66 | public const string PhysFunctChangeLinkType = "BulletSim.ChangeLinkType"; | ||
67 | public const string PhysFunctGetLinkType = "BulletSim.GetLinkType"; | ||
68 | public const string PhysFunctChangeLinkParams = "BulletSim.ChangeLinkParams"; | ||
63 | 69 | ||
64 | // ============================================================= | 70 | // ============================================================= |
65 | 71 | ||
@@ -155,7 +161,7 @@ public class ExtendedPhysics : INonSharedRegionModule | |||
155 | } | 161 | } |
156 | 162 | ||
157 | [ScriptConstant] | 163 | [ScriptConstant] |
158 | public static int PHYS_CENTER_OF_MASS = 1 << 0; | 164 | public const int PHYS_CENTER_OF_MASS = 1 << 0; |
159 | 165 | ||
160 | [ScriptInvocation] | 166 | [ScriptInvocation] |
161 | public string physGetEngineType(UUID hostID, UUID scriptID) | 167 | public string physGetEngineType(UUID hostID, UUID scriptID) |
@@ -171,11 +177,11 @@ public class ExtendedPhysics : INonSharedRegionModule | |||
171 | } | 177 | } |
172 | 178 | ||
173 | [ScriptConstant] | 179 | [ScriptConstant] |
174 | public static int PHYS_LINKSET_TYPE_CONSTRAINT = 0; | 180 | public const int PHYS_LINKSET_TYPE_CONSTRAINT = 0; |
175 | [ScriptConstant] | 181 | [ScriptConstant] |
176 | public static int PHYS_LINKSET_TYPE_COMPOUND = 1; | 182 | public const int PHYS_LINKSET_TYPE_COMPOUND = 1; |
177 | [ScriptConstant] | 183 | [ScriptConstant] |
178 | public static int PHYS_LINKSET_TYPE_MANUAL = 2; | 184 | public const int PHYS_LINKSET_TYPE_MANUAL = 2; |
179 | 185 | ||
180 | [ScriptInvocation] | 186 | [ScriptInvocation] |
181 | public int physSetLinksetType(UUID hostID, UUID scriptID, int linksetType) | 187 | public int physSetLinksetType(UUID hostID, UUID scriptID, int linksetType) |
@@ -195,10 +201,38 @@ public class ExtendedPhysics : INonSharedRegionModule | |||
195 | 201 | ||
196 | if (rootPart != null) | 202 | if (rootPart != null) |
197 | { | 203 | { |
198 | Physics.Manager.PhysicsActor rootPhysActor = rootPart.PhysActor; | 204 | PhysicsActor rootPhysActor = rootPart.PhysActor; |
199 | if (rootPhysActor != null) | 205 | if (rootPhysActor != null) |
200 | { | 206 | { |
201 | ret = (int)rootPhysActor.Extension(PhysFunctSetLinksetType, linksetType); | 207 | if (rootPhysActor.IsPhysical) |
208 | { | ||
209 | // Change a physical linkset by making non-physical, waiting for one heartbeat so all | ||
210 | // the prim and linkset state is updated, changing the type and making the | ||
211 | // linkset physical again. | ||
212 | containingGroup.ScriptSetPhysicsStatus(false); | ||
213 | Thread.Sleep(150); // longer than one heartbeat tick | ||
214 | |||
215 | // A kludge for the moment. | ||
216 | // Since compound linksets move the children but don't generate position updates to the | ||
217 | // simulator, it is possible for compound linkset children to have out-of-sync simulator | ||
218 | // and physical positions. The following causes the simulator to push the real child positions | ||
219 | // down into the physics engine to get everything synced. | ||
220 | containingGroup.UpdateGroupPosition(containingGroup.AbsolutePosition); | ||
221 | containingGroup.UpdateGroupRotationR(containingGroup.GroupRotation); | ||
222 | |||
223 | object[] parms2 = { rootPhysActor, null, linksetType }; | ||
224 | ret = MakeIntError(rootPhysActor.Extension(PhysFunctSetLinksetType, parms2)); | ||
225 | Thread.Sleep(150); // longer than one heartbeat tick | ||
226 | |||
227 | containingGroup.ScriptSetPhysicsStatus(true); | ||
228 | } | ||
229 | else | ||
230 | { | ||
231 | // Non-physical linksets don't have a physical instantiation so there is no state to | ||
232 | // worry about being updated. | ||
233 | object[] parms2 = { rootPhysActor, null, linksetType }; | ||
234 | ret = MakeIntError(rootPhysActor.Extension(PhysFunctSetLinksetType, parms2)); | ||
235 | } | ||
202 | } | 236 | } |
203 | else | 237 | else |
204 | { | 238 | { |
@@ -223,7 +257,6 @@ public class ExtendedPhysics : INonSharedRegionModule | |||
223 | public int physGetLinksetType(UUID hostID, UUID scriptID) | 257 | public int physGetLinksetType(UUID hostID, UUID scriptID) |
224 | { | 258 | { |
225 | int ret = -1; | 259 | int ret = -1; |
226 | |||
227 | if (!Enabled) return ret; | 260 | if (!Enabled) return ret; |
228 | 261 | ||
229 | // The part that is requesting the change. | 262 | // The part that is requesting the change. |
@@ -237,10 +270,11 @@ public class ExtendedPhysics : INonSharedRegionModule | |||
237 | 270 | ||
238 | if (rootPart != null) | 271 | if (rootPart != null) |
239 | { | 272 | { |
240 | Physics.Manager.PhysicsActor rootPhysActor = rootPart.PhysActor; | 273 | PhysicsActor rootPhysActor = rootPart.PhysActor; |
241 | if (rootPhysActor != null) | 274 | if (rootPhysActor != null) |
242 | { | 275 | { |
243 | ret = (int)rootPhysActor.Extension(PhysFunctGetLinksetType); | 276 | object[] parms2 = { rootPhysActor, null }; |
277 | ret = MakeIntError(rootPhysActor.Extension(PhysFunctGetLinksetType, parms2)); | ||
244 | } | 278 | } |
245 | else | 279 | else |
246 | { | 280 | { |
@@ -260,5 +294,288 @@ public class ExtendedPhysics : INonSharedRegionModule | |||
260 | } | 294 | } |
261 | return ret; | 295 | return ret; |
262 | } | 296 | } |
297 | |||
298 | [ScriptConstant] | ||
299 | public const int PHYS_LINK_TYPE_FIXED = 1234; | ||
300 | [ScriptConstant] | ||
301 | public const int PHYS_LINK_TYPE_HINGE = 4; | ||
302 | [ScriptConstant] | ||
303 | public const int PHYS_LINK_TYPE_SPRING = 9; | ||
304 | [ScriptConstant] | ||
305 | public const int PHYS_LINK_TYPE_6DOF = 6; | ||
306 | [ScriptConstant] | ||
307 | public const int PHYS_LINK_TYPE_SLIDER = 7; | ||
308 | |||
309 | // physChangeLinkType(integer linkNum, integer typeCode) | ||
310 | [ScriptInvocation] | ||
311 | public int physChangeLinkType(UUID hostID, UUID scriptID, int linkNum, int typeCode) | ||
312 | { | ||
313 | int ret = -1; | ||
314 | if (!Enabled) return ret; | ||
315 | |||
316 | PhysicsActor rootPhysActor; | ||
317 | PhysicsActor childPhysActor; | ||
318 | |||
319 | if (GetRootAndChildPhysActors(hostID, linkNum, out rootPhysActor, out childPhysActor)) | ||
320 | { | ||
321 | object[] parms2 = { rootPhysActor, childPhysActor, typeCode }; | ||
322 | ret = MakeIntError(rootPhysActor.Extension(PhysFunctChangeLinkType, parms2)); | ||
323 | } | ||
324 | |||
325 | return ret; | ||
326 | } | ||
327 | |||
328 | // physGetLinkType(integer linkNum) | ||
329 | [ScriptInvocation] | ||
330 | public int physGetLinkType(UUID hostID, UUID scriptID, int linkNum) | ||
331 | { | ||
332 | int ret = -1; | ||
333 | if (!Enabled) return ret; | ||
334 | |||
335 | PhysicsActor rootPhysActor; | ||
336 | PhysicsActor childPhysActor; | ||
337 | |||
338 | if (GetRootAndChildPhysActors(hostID, linkNum, out rootPhysActor, out childPhysActor)) | ||
339 | { | ||
340 | object[] parms2 = { rootPhysActor, childPhysActor }; | ||
341 | ret = MakeIntError(rootPhysActor.Extension(PhysFunctGetLinkType, parms2)); | ||
342 | } | ||
343 | |||
344 | return ret; | ||
345 | } | ||
346 | |||
347 | // physChangeLinkFixed(integer linkNum) | ||
348 | // Change the link between the root and the linkNum into a fixed, static physical connection. | ||
349 | [ScriptInvocation] | ||
350 | public int physChangeLinkFixed(UUID hostID, UUID scriptID, int linkNum) | ||
351 | { | ||
352 | int ret = -1; | ||
353 | if (!Enabled) return ret; | ||
354 | |||
355 | PhysicsActor rootPhysActor; | ||
356 | PhysicsActor childPhysActor; | ||
357 | |||
358 | if (GetRootAndChildPhysActors(hostID, linkNum, out rootPhysActor, out childPhysActor)) | ||
359 | { | ||
360 | object[] parms2 = { rootPhysActor, childPhysActor , PHYS_LINK_TYPE_FIXED }; | ||
361 | ret = MakeIntError(rootPhysActor.Extension(PhysFunctChangeLinkType, parms2)); | ||
362 | } | ||
363 | |||
364 | return ret; | ||
365 | } | ||
366 | |||
367 | // Code for specifying params. | ||
368 | // The choice if 14400 is arbitrary and only serves to catch parameter code misuse. | ||
369 | public const int PHYS_PARAM_MIN = 14401; | ||
370 | |||
371 | [ScriptConstant] | ||
372 | public const int PHYS_PARAM_FRAMEINA_LOC = 14401; | ||
373 | [ScriptConstant] | ||
374 | public const int PHYS_PARAM_FRAMEINA_ROT = 14402; | ||
375 | [ScriptConstant] | ||
376 | public const int PHYS_PARAM_FRAMEINB_LOC = 14403; | ||
377 | [ScriptConstant] | ||
378 | public const int PHYS_PARAM_FRAMEINB_ROT = 14404; | ||
379 | [ScriptConstant] | ||
380 | public const int PHYS_PARAM_LINEAR_LIMIT_LOW = 14405; | ||
381 | [ScriptConstant] | ||
382 | public const int PHYS_PARAM_LINEAR_LIMIT_HIGH = 14406; | ||
383 | [ScriptConstant] | ||
384 | public const int PHYS_PARAM_ANGULAR_LIMIT_LOW = 14407; | ||
385 | [ScriptConstant] | ||
386 | public const int PHYS_PARAM_ANGULAR_LIMIT_HIGH = 14408; | ||
387 | [ScriptConstant] | ||
388 | public const int PHYS_PARAM_USE_FRAME_OFFSET = 14409; | ||
389 | [ScriptConstant] | ||
390 | public const int PHYS_PARAM_ENABLE_TRANSMOTOR = 14410; | ||
391 | [ScriptConstant] | ||
392 | public const int PHYS_PARAM_TRANSMOTOR_MAXVEL = 14411; | ||
393 | [ScriptConstant] | ||
394 | public const int PHYS_PARAM_TRANSMOTOR_MAXFORCE = 14412; | ||
395 | [ScriptConstant] | ||
396 | public const int PHYS_PARAM_CFM = 14413; | ||
397 | [ScriptConstant] | ||
398 | public const int PHYS_PARAM_ERP = 14414; | ||
399 | [ScriptConstant] | ||
400 | public const int PHYS_PARAM_SOLVER_ITERATIONS = 14415; | ||
401 | [ScriptConstant] | ||
402 | public const int PHYS_PARAM_SPRING_AXIS_ENABLE = 14416; | ||
403 | [ScriptConstant] | ||
404 | public const int PHYS_PARAM_SPRING_DAMPING = 14417; | ||
405 | [ScriptConstant] | ||
406 | public const int PHYS_PARAM_SPRING_STIFFNESS = 14418; | ||
407 | [ScriptConstant] | ||
408 | public const int PHYS_PARAM_LINK_TYPE = 14419; | ||
409 | [ScriptConstant] | ||
410 | public const int PHYS_PARAM_USE_LINEAR_FRAMEA = 14420; | ||
411 | [ScriptConstant] | ||
412 | public const int PHYS_PARAM_SPRING_EQUILIBRIUM_POINT = 14421; | ||
413 | |||
414 | public const int PHYS_PARAM_MAX = 14421; | ||
415 | |||
416 | // Used when specifying a parameter that has settings for the three linear and three angular axis | ||
417 | [ScriptConstant] | ||
418 | public const int PHYS_AXIS_ALL = -1; | ||
419 | [ScriptConstant] | ||
420 | public const int PHYS_AXIS_LINEAR_ALL = -2; | ||
421 | [ScriptConstant] | ||
422 | public const int PHYS_AXIS_ANGULAR_ALL = -3; | ||
423 | [ScriptConstant] | ||
424 | public const int PHYS_AXIS_LINEAR_X = 0; | ||
425 | [ScriptConstant] | ||
426 | public const int PHYS_AXIS_LINEAR_Y = 1; | ||
427 | [ScriptConstant] | ||
428 | public const int PHYS_AXIS_LINEAR_Z = 2; | ||
429 | [ScriptConstant] | ||
430 | public const int PHYS_AXIS_ANGULAR_X = 3; | ||
431 | [ScriptConstant] | ||
432 | public const int PHYS_AXIS_ANGULAR_Y = 4; | ||
433 | [ScriptConstant] | ||
434 | public const int PHYS_AXIS_ANGULAR_Z = 5; | ||
435 | |||
436 | // physChangeLinkParams(integer linkNum, [ PHYS_PARAM_*, value, PHYS_PARAM_*, value, ...]) | ||
437 | [ScriptInvocation] | ||
438 | public int physChangeLinkParams(UUID hostID, UUID scriptID, int linkNum, object[] parms) | ||
439 | { | ||
440 | int ret = -1; | ||
441 | if (!Enabled) return ret; | ||
442 | |||
443 | PhysicsActor rootPhysActor; | ||
444 | PhysicsActor childPhysActor; | ||
445 | |||
446 | if (GetRootAndChildPhysActors(hostID, linkNum, out rootPhysActor, out childPhysActor)) | ||
447 | { | ||
448 | object[] parms2 = AddToBeginningOfArray(rootPhysActor, childPhysActor, parms); | ||
449 | ret = MakeIntError(rootPhysActor.Extension(PhysFunctChangeLinkParams, parms2)); | ||
450 | } | ||
451 | |||
452 | return ret; | ||
453 | } | ||
454 | |||
455 | private bool GetRootPhysActor(UUID hostID, out PhysicsActor rootPhysActor) | ||
456 | { | ||
457 | SceneObjectGroup containingGroup; | ||
458 | SceneObjectPart rootPart; | ||
459 | return GetRootPhysActor(hostID, out containingGroup, out rootPart, out rootPhysActor); | ||
460 | } | ||
461 | |||
462 | private bool GetRootPhysActor(UUID hostID, out SceneObjectGroup containingGroup, out SceneObjectPart rootPart, out PhysicsActor rootPhysActor) | ||
463 | { | ||
464 | bool ret = false; | ||
465 | rootPhysActor = null; | ||
466 | containingGroup = null; | ||
467 | rootPart = null; | ||
468 | |||
469 | SceneObjectPart requestingPart; | ||
470 | |||
471 | requestingPart = BaseScene.GetSceneObjectPart(hostID); | ||
472 | if (requestingPart != null) | ||
473 | { | ||
474 | // The type is is always on the root of a linkset. | ||
475 | containingGroup = requestingPart.ParentGroup; | ||
476 | if (containingGroup != null && !containingGroup.IsDeleted) | ||
477 | { | ||
478 | rootPart = containingGroup.RootPart; | ||
479 | if (rootPart != null) | ||
480 | { | ||
481 | rootPhysActor = rootPart.PhysActor; | ||
482 | if (rootPhysActor != null) | ||
483 | { | ||
484 | ret = true; | ||
485 | } | ||
486 | else | ||
487 | { | ||
488 | m_log.WarnFormat("{0} GetRootAndChildPhysActors: Root part does not have a physics actor. rootName={1}, hostID={2}", | ||
489 | LogHeader, rootPart.Name, hostID); | ||
490 | } | ||
491 | } | ||
492 | else | ||
493 | { | ||
494 | m_log.WarnFormat("{0} GetRootAndChildPhysActors: Root part does not exist. RequestingPartName={1}, hostID={2}", | ||
495 | LogHeader, requestingPart.Name, hostID); | ||
496 | } | ||
497 | } | ||
498 | else | ||
499 | { | ||
500 | m_log.WarnFormat("{0} GetRootAndChildPhysActors: Containing group missing or deleted. hostID={1}", LogHeader, hostID); | ||
501 | } | ||
502 | } | ||
503 | else | ||
504 | { | ||
505 | m_log.WarnFormat("{0} GetRootAndChildPhysActors: cannot find script object in scene. hostID={1}", LogHeader, hostID); | ||
506 | } | ||
507 | |||
508 | return ret; | ||
509 | } | ||
510 | |||
511 | // Find the root and child PhysActors based on the linkNum. | ||
512 | // Return 'true' if both are found and returned. | ||
513 | private bool GetRootAndChildPhysActors(UUID hostID, int linkNum, out PhysicsActor rootPhysActor, out PhysicsActor childPhysActor) | ||
514 | { | ||
515 | bool ret = false; | ||
516 | rootPhysActor = null; | ||
517 | childPhysActor = null; | ||
518 | |||
519 | SceneObjectGroup containingGroup; | ||
520 | SceneObjectPart rootPart; | ||
521 | |||
522 | if (GetRootPhysActor(hostID, out containingGroup, out rootPart, out rootPhysActor)) | ||
523 | { | ||
524 | SceneObjectPart linkPart = containingGroup.GetLinkNumPart(linkNum); | ||
525 | if (linkPart != null) | ||
526 | { | ||
527 | childPhysActor = linkPart.PhysActor; | ||
528 | if (childPhysActor != null) | ||
529 | { | ||
530 | ret = true; | ||
531 | } | ||
532 | else | ||
533 | { | ||
534 | m_log.WarnFormat("{0} GetRootAndChildPhysActors: Link part has no physical actor. rootName={1}, hostID={2}, linknum={3}", | ||
535 | LogHeader, rootPart.Name, hostID, linkNum); | ||
536 | } | ||
537 | } | ||
538 | else | ||
539 | { | ||
540 | m_log.WarnFormat("{0} GetRootAndChildPhysActors: Could not find linknum part. rootName={1}, hostID={2}, linknum={3}", | ||
541 | LogHeader, rootPart.Name, hostID, linkNum); | ||
542 | } | ||
543 | } | ||
544 | else | ||
545 | { | ||
546 | m_log.WarnFormat("{0} GetRootAndChildPhysActors: Root part does not have a physics actor. rootName={1}, hostID={2}", | ||
547 | LogHeader, rootPart.Name, hostID); | ||
548 | } | ||
549 | |||
550 | return ret; | ||
551 | } | ||
552 | |||
553 | // Return an array of objects with the passed object as the first object of a new array | ||
554 | private object[] AddToBeginningOfArray(object firstOne, object secondOne, object[] prevArray) | ||
555 | { | ||
556 | object[] newArray = new object[2 + prevArray.Length]; | ||
557 | newArray[0] = firstOne; | ||
558 | newArray[1] = secondOne; | ||
559 | prevArray.CopyTo(newArray, 2); | ||
560 | return newArray; | ||
561 | } | ||
562 | |||
563 | // Extension() returns an object. Convert that object into the integer error we expect to return. | ||
564 | private int MakeIntError(object extensionRet) | ||
565 | { | ||
566 | int ret = -1; | ||
567 | if (extensionRet != null) | ||
568 | { | ||
569 | try | ||
570 | { | ||
571 | ret = (int)extensionRet; | ||
572 | } | ||
573 | catch | ||
574 | { | ||
575 | ret = -1; | ||
576 | } | ||
577 | } | ||
578 | return ret; | ||
579 | } | ||
263 | } | 580 | } |
264 | } | 581 | } |