aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules')
-rwxr-xr-xOpenSim/Region/OptionalModules/Scripting/ExtendedPhysics/ExtendedPhysics.cs265
1 files changed, 171 insertions, 94 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/ExtendedPhysics/ExtendedPhysics.cs b/OpenSim/Region/OptionalModules/Scripting/ExtendedPhysics/ExtendedPhysics.cs
index 278e9e7..baf5a5b 100755
--- a/OpenSim/Region/OptionalModules/Scripting/ExtendedPhysics/ExtendedPhysics.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/ExtendedPhysics/ExtendedPhysics.cs
@@ -36,6 +36,7 @@ using OpenSim.Region.CoreModules;
36using OpenSim.Region.Framework; 36using OpenSim.Region.Framework;
37using OpenSim.Region.Framework.Interfaces; 37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes; 38using OpenSim.Region.Framework.Scenes;
39using OpenSim.Region.Physics.Manager;
39 40
40using Mono.Addins; 41using Mono.Addins;
41using Nini.Config; 42using Nini.Config;
@@ -62,9 +63,8 @@ public class ExtendedPhysics : INonSharedRegionModule
62 public const string PhysFunctGetLinksetType = "BulletSim.GetLinksetType"; 63 public const string PhysFunctGetLinksetType = "BulletSim.GetLinksetType";
63 public const string PhysFunctSetLinksetType = "BulletSim.SetLinksetType"; 64 public const string PhysFunctSetLinksetType = "BulletSim.SetLinksetType";
64 public const string PhysFunctChangeLinkFixed = "BulletSim.ChangeLinkFixed"; 65 public const string PhysFunctChangeLinkFixed = "BulletSim.ChangeLinkFixed";
65 public const string PhysFunctChangeLinkHinge = "BulletSim.ChangeLinkHinge"; 66 public const string PhysFunctChangeLinkType = "BulletSim.ChangeLinkType";
66 public const string PhysFunctChangeLinkSpring = "BulletSim.ChangeLinkSpring"; 67 public const string PhysFunctChangeLinkParams = "BulletSim.ChangeLinkParams";
67 public const string PhysFunctChangeLinkSlider = "BulletSim.ChangeLinkSlider";
68 68
69 // ============================================================= 69 // =============================================================
70 70
@@ -200,7 +200,7 @@ public class ExtendedPhysics : INonSharedRegionModule
200 200
201 if (rootPart != null) 201 if (rootPart != null)
202 { 202 {
203 Physics.Manager.PhysicsActor rootPhysActor = rootPart.PhysActor; 203 PhysicsActor rootPhysActor = rootPart.PhysActor;
204 if (rootPhysActor != null) 204 if (rootPhysActor != null)
205 { 205 {
206 if (rootPhysActor.IsPhysical) 206 if (rootPhysActor.IsPhysical)
@@ -219,7 +219,7 @@ public class ExtendedPhysics : INonSharedRegionModule
219 containingGroup.UpdateGroupPosition(containingGroup.AbsolutePosition); 219 containingGroup.UpdateGroupPosition(containingGroup.AbsolutePosition);
220 containingGroup.UpdateGroupRotationR(containingGroup.GroupRotation); 220 containingGroup.UpdateGroupRotationR(containingGroup.GroupRotation);
221 221
222 ret = (int)rootPhysActor.Extension(PhysFunctSetLinksetType, linksetType); 222 ret = MakeIntError(rootPhysActor.Extension(PhysFunctSetLinksetType, linksetType));
223 Thread.Sleep(150); // longer than one heartbeat tick 223 Thread.Sleep(150); // longer than one heartbeat tick
224 224
225 containingGroup.ScriptSetPhysicsStatus(true); 225 containingGroup.ScriptSetPhysicsStatus(true);
@@ -228,7 +228,7 @@ public class ExtendedPhysics : INonSharedRegionModule
228 { 228 {
229 // Non-physical linksets don't have a physical instantiation so there is no state to 229 // Non-physical linksets don't have a physical instantiation so there is no state to
230 // worry about being updated. 230 // worry about being updated.
231 ret = (int)rootPhysActor.Extension(PhysFunctSetLinksetType, linksetType); 231 ret = MakeIntError(rootPhysActor.Extension(PhysFunctSetLinksetType, linksetType));
232 } 232 }
233 } 233 }
234 else 234 else
@@ -267,10 +267,10 @@ public class ExtendedPhysics : INonSharedRegionModule
267 267
268 if (rootPart != null) 268 if (rootPart != null)
269 { 269 {
270 Physics.Manager.PhysicsActor rootPhysActor = rootPart.PhysActor; 270 PhysicsActor rootPhysActor = rootPart.PhysActor;
271 if (rootPhysActor != null) 271 if (rootPhysActor != null)
272 { 272 {
273 ret = (int)rootPhysActor.Extension(PhysFunctGetLinksetType); 273 ret = MakeIntError(rootPhysActor.Extension(PhysFunctGetLinksetType));
274 } 274 }
275 else 275 else
276 { 276 {
@@ -291,148 +291,225 @@ public class ExtendedPhysics : INonSharedRegionModule
291 return ret; 291 return ret;
292 } 292 }
293 293
294 [ScriptConstant]
295 public static int PHYS_LINK_TYPE_FIXED = 1234;
296 [ScriptConstant]
297 public static int PHYS_LINK_TYPE_HINGE = 4;
298 [ScriptConstant]
299 public static int PHYS_LINK_TYPE_SPRING = 9;
300 [ScriptConstant]
301 public static int PHYS_LINK_TYPE_6DOF = 6;
302 [ScriptConstant]
303 public static int PHYS_LINK_TYPE_SLIDER = 7;
304
305 // physChangeLinkType(integer linkNum, integer typeCode)
306 [ScriptInvocation]
307 public int physChangeLinkType(UUID hostID, UUID scriptID, int linkNum, int typeCode)
308 {
309 int ret = -1;
310 if (!Enabled) return ret;
311
312 PhysicsActor rootPhysActor;
313 PhysicsActor childPhysActor;
314
315 if (GetRootAndChildPhysActors(hostID, linkNum, out rootPhysActor, out childPhysActor))
316 {
317 ret = MakeIntError(rootPhysActor.Extension(PhysFunctChangeLinkType, childPhysActor, typeCode));
318 }
319
320 return ret;
321 }
322
294 // physChangeLinkFixed(integer linkNum) 323 // physChangeLinkFixed(integer linkNum)
295 // Change the link between the root and the linkNum into a fixed, static physical connection. 324 // Change the link between the root and the linkNum into a fixed, static physical connection.
296 // This needs to change 'linkNum' into the physical object because lower level code has
297 // no access to the link numbers.
298 [ScriptInvocation] 325 [ScriptInvocation]
299 public int physChangeLinkFixed(UUID hostID, UUID scriptID, int linkNum) 326 public int physChangeLinkFixed(UUID hostID, UUID scriptID, int linkNum)
300 { 327 {
301 int ret = -1; 328 int ret = -1;
302 if (!Enabled) return ret; 329 if (!Enabled) return ret;
303 330
304 // The part that is requesting the change. 331 PhysicsActor rootPhysActor;
305 SceneObjectPart requestingPart = BaseScene.GetSceneObjectPart(hostID); 332 PhysicsActor childPhysActor;
333
334 if (GetRootAndChildPhysActors(hostID, linkNum, out rootPhysActor, out childPhysActor))
335 {
336 ret = MakeIntError(rootPhysActor.Extension(PhysFunctChangeLinkType, childPhysActor, PHYS_LINK_TYPE_FIXED));
337 }
338
339 return ret;
340 }
341
342 // Code for specifying params.
343 // The choice if 14400 is arbitrary and only serves to catch parameter code misuse.
344 public static int PHYS_PARAM_MIN = 14401;
345 [ScriptConstant]
346 public static int PHYS_PARAM_FRAMEINA_LOC = 14401;
347 [ScriptConstant]
348 public static int PHYS_PARAM_FRAMEINA_ROT = 14402;
349 [ScriptConstant]
350 public static int PHYS_PARAM_FRAMEINB_LOC = 14403;
351 [ScriptConstant]
352 public static int PHYS_PARAM_FRAMEINB_ROT = 14404;
353 [ScriptConstant]
354 public static int PHYS_PARAM_LINEAR_LIMIT_LOW = 14405;
355 [ScriptConstant]
356 public static int PHYS_PARAM_LINEAR_LIMIT_HIGH = 14406;
357 [ScriptConstant]
358 public static int PHYS_PARAM_ANGULAR_LIMIT_LOW = 14407;
359 [ScriptConstant]
360 public static int PHYS_PARAM_ANGULAR_LIMIT_HIGH = 14408;
361 [ScriptConstant]
362 public static int PHYS_PARAM_USE_FRAME_OFFSET = 14409;
363 [ScriptConstant]
364 public static int PHYS_PARAM_ENABLE_TRANSMOTOR = 14410;
365 [ScriptConstant]
366 public static int PHYS_PARAM_TRANSMOTOR_MAXVEL = 14411;
367 [ScriptConstant]
368 public static int PHYS_PARAM_TRANSMOTOR_MAXFORCE = 14412;
369 [ScriptConstant]
370 public static int PHYS_PARAM_CFM = 14413;
371 [ScriptConstant]
372 public static int PHYS_PARAM_ERP = 14414;
373 [ScriptConstant]
374 public static int PHYS_PARAM_SOLVER_ITERATIONS = 14415;
375 [ScriptConstant]
376 public static int PHYS_PARAM_SPRING_DAMPING = 14416;
377 [ScriptConstant]
378 public static int PHYS_PARAM_SPRING_STIFFNESS = 14417;
379 public static int PHYS_PARAM_MAX = 14417;
306 380
381 // physChangeLinkParams(integer linkNum, [ PHYS_PARAM_*, value, PHYS_PARAM_*, value, ...])
382 [ScriptInvocation]
383 public int physChangeLinkParams(UUID hostID, UUID scriptID, int linkNum, object[] parms)
384 {
385 int ret = -1;
386 if (!Enabled) return ret;
387
388 PhysicsActor rootPhysActor;
389 PhysicsActor childPhysActor;
390
391 if (GetRootAndChildPhysActors(hostID, linkNum, out rootPhysActor, out childPhysActor))
392 {
393 ret = MakeIntError(rootPhysActor.Extension(PhysFunctChangeLinkParams, childPhysActor, parms));
394 }
395
396 return ret;
397 }
398
399 private bool GetRootPhysActor(UUID hostID, out PhysicsActor rootPhysActor)
400 {
401 SceneObjectGroup containingGroup;
402 SceneObjectPart rootPart;
403 return GetRootPhysActor(hostID, out containingGroup, out rootPart, out rootPhysActor);
404 }
405
406 private bool GetRootPhysActor(UUID hostID, out SceneObjectGroup containingGroup, out SceneObjectPart rootPart, out PhysicsActor rootPhysActor)
407 {
408 bool ret = false;
409 rootPhysActor = null;
410 containingGroup = null;
411 rootPart = null;
412
413 SceneObjectPart requestingPart;
414
415 requestingPart = BaseScene.GetSceneObjectPart(hostID);
307 if (requestingPart != null) 416 if (requestingPart != null)
308 { 417 {
309 // The type is is always on the root of a linkset. 418 // The type is is always on the root of a linkset.
310 SceneObjectGroup containingGroup = requestingPart.ParentGroup; 419 containingGroup = requestingPart.ParentGroup;
311 SceneObjectPart rootPart = containingGroup.RootPart; 420 if (containingGroup != null && !containingGroup.IsDeleted)
312
313 if (rootPart != null)
314 { 421 {
315 Physics.Manager.PhysicsActor rootPhysActor = rootPart.PhysActor; 422 rootPart = containingGroup.RootPart;
316 if (rootPhysActor != null) 423 if (rootPart != null)
317 { 424 {
318 SceneObjectPart linkPart = containingGroup.GetLinkNumPart(linkNum); 425 rootPhysActor = rootPart.PhysActor;
319 if (linkPart != null) 426 if (rootPhysActor != null)
320 { 427 {
321 Physics.Manager.PhysicsActor linkPhysActor = linkPart.PhysActor; 428 ret = true;
322 if (linkPhysActor != null)
323 {
324 ret = (int)rootPhysActor.Extension(PhysFunctChangeLinkFixed, linkNum, linkPhysActor);
325 }
326 else
327 {
328 m_log.WarnFormat("{0} physChangeLinkFixed: Link part has no physical actor. rootName={1}, hostID={2}, linknum={3}",
329 LogHeader, rootPart.Name, hostID, linkNum);
330 }
331 } 429 }
332 else 430 else
333 { 431 {
334 m_log.WarnFormat("{0} physChangeLinkFixed: Could not find linknum part. rootName={1}, hostID={2}, linknum={3}", 432 m_log.WarnFormat("{0} GetRootAndChildPhysActors: Root part does not have a physics actor. rootName={1}, hostID={2}",
335 LogHeader, rootPart.Name, hostID, linkNum); 433 LogHeader, rootPart.Name, hostID);
336 } 434 }
337 } 435 }
338 else 436 else
339 { 437 {
340 m_log.WarnFormat("{0} physChangeLinkFixed: Root part does not have a physics actor. rootName={1}, hostID={2}", 438 m_log.WarnFormat("{0} GetRootAndChildPhysActors: Root part does not exist. RequestingPartName={1}, hostID={2}",
341 LogHeader, rootPart.Name, hostID); 439 LogHeader, requestingPart.Name, hostID);
342 } 440 }
343 } 441 }
344 else 442 else
345 { 443 {
346 m_log.WarnFormat("{0} physChangeLinkFixed: Root part does not exist. RequestingPartName={1}, hostID={2}", 444 m_log.WarnFormat("{0} GetRootAndChildPhysActors: Containing group missing or deleted. hostID={1}", LogHeader, hostID);
347 LogHeader, requestingPart.Name, hostID);
348 } 445 }
349 } 446 }
350 else 447 else
351 { 448 {
352 m_log.WarnFormat("{0} physGetLinsetType: cannot find script object in scene. hostID={1}", LogHeader, hostID); 449 m_log.WarnFormat("{0} GetRootAndChildPhysActors: cannot find script object in scene. hostID={1}", LogHeader, hostID);
353 } 450 }
451
354 return ret; 452 return ret;
355 } 453 }
356 454
357 [ScriptInvocation] 455 // Find the root and child PhysActors based on the linkNum.
358 public int physChangeLinkHinge(UUID hostID, UUID scriptID, int linkNum) 456 // Return 'true' if both are found and returned.
457 private bool GetRootAndChildPhysActors(UUID hostID, int linkNum, out PhysicsActor rootPhysActor, out PhysicsActor childPhysActor)
359 { 458 {
360 return -1; 459 bool ret = false;
361 } 460 rootPhysActor = null;
461 childPhysActor = null;
362 462
363 [ScriptInvocation] 463 SceneObjectGroup containingGroup;
364 public int physChangeLinkSpring(UUID hostID, UUID scriptID, int linkNum, 464 SceneObjectPart rootPart;
365 Vector3 frameInAloc, Quaternion frameInArot,
366 Vector3 frameInBloc, Quaternion frameInBrot,
367 Vector3 linearLimitLow, Vector3 linearLimitHigh,
368 Vector3 angularLimitLow, Vector3 angularLimitHigh
369 )
370 {
371 int ret = -1;
372 if (!Enabled) return ret;
373 465
374 // The part that is requesting the change. 466 if (GetRootPhysActor(hostID, out containingGroup, out rootPart, out rootPhysActor))
375 SceneObjectPart requestingPart = BaseScene.GetSceneObjectPart(hostID);
376
377 if (requestingPart != null)
378 { 467 {
379 // The type is is always on the root of a linkset. 468 SceneObjectPart linkPart = containingGroup.GetLinkNumPart(linkNum);
380 SceneObjectGroup containingGroup = requestingPart.ParentGroup; 469 if (linkPart != null)
381 SceneObjectPart rootPart = containingGroup.RootPart;
382
383 if (rootPart != null)
384 { 470 {
385 Physics.Manager.PhysicsActor rootPhysActor = rootPart.PhysActor; 471 childPhysActor = linkPart.PhysActor;
386 if (rootPhysActor != null) 472 if (childPhysActor != null)
387 { 473 {
388 SceneObjectPart linkPart = containingGroup.GetLinkNumPart(linkNum); 474 ret = true;
389 if (linkPart != null)
390 {
391 Physics.Manager.PhysicsActor linkPhysActor = linkPart.PhysActor;
392 if (linkPhysActor != null)
393 {
394 ret = (int)rootPhysActor.Extension(PhysFunctChangeLinkSpring, linkNum, linkPhysActor,
395 frameInAloc, frameInArot,
396 frameInBloc, frameInBrot,
397 linearLimitLow, linearLimitHigh,
398 angularLimitLow, angularLimitHigh
399 );
400 }
401 else
402 {
403 m_log.WarnFormat("{0} physChangeLinkFixed: Link part has no physical actor. rootName={1}, hostID={2}, linknum={3}",
404 LogHeader, rootPart.Name, hostID, linkNum);
405 }
406 }
407 else
408 {
409 m_log.WarnFormat("{0} physChangeLinkFixed: Could not find linknum part. rootName={1}, hostID={2}, linknum={3}",
410 LogHeader, rootPart.Name, hostID, linkNum);
411 }
412 } 475 }
413 else 476 else
414 { 477 {
415 m_log.WarnFormat("{0} physChangeLinkFixed: Root part does not have a physics actor. rootName={1}, hostID={2}", 478 m_log.WarnFormat("{0} GetRootAndChildPhysActors: Link part has no physical actor. rootName={1}, hostID={2}, linknum={3}",
416 LogHeader, rootPart.Name, hostID); 479 LogHeader, rootPart.Name, hostID, linkNum);
417 } 480 }
418 } 481 }
419 else 482 else
420 { 483 {
421 m_log.WarnFormat("{0} physChangeLinkFixed: Root part does not exist. RequestingPartName={1}, hostID={2}", 484 m_log.WarnFormat("{0} GetRootAndChildPhysActors: Could not find linknum part. rootName={1}, hostID={2}, linknum={3}",
422 LogHeader, requestingPart.Name, hostID); 485 LogHeader, rootPart.Name, hostID, linkNum);
423 } 486 }
424 } 487 }
425 else 488 else
426 { 489 {
427 m_log.WarnFormat("{0} physGetLinsetType: cannot find script object in scene. hostID={1}", LogHeader, hostID); 490 m_log.WarnFormat("{0} GetRootAndChildPhysActors: Root part does not have a physics actor. rootName={1}, hostID={2}",
491 LogHeader, rootPart.Name, hostID);
428 } 492 }
493
429 return ret; 494 return ret;
430 } 495 }
431 496
432 [ScriptInvocation] 497 // Extension() returns an object. Convert that object into the integer error we expect to return.
433 public int physChangeLinkSlider(UUID hostID, UUID scriptID, int linkNum) 498 private int MakeIntError(object extensionRet)
434 { 499 {
435 return 0; 500 int ret = -1;
501 if (extensionRet != null)
502 {
503 try
504 {
505 ret = (int)extensionRet;
506 }
507 catch
508 {
509 ret = -1;
510 }
511 }
512 return ret;
436 } 513 }
437} 514}
438} 515}