ExtendedPhysics.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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 copyrightD
  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. using System;
  28. using System.Collections.Generic;
  29. using System.Linq;
  30. using System.Reflection;
  31. using System.Text;
  32. using System.Threading;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.CoreModules;
  35. using OpenSim.Region.Framework;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenSim.Region.Framework.Scenes;
  38. using OpenSim.Region.Physics.Manager;
  39. using Mono.Addins;
  40. using Nini.Config;
  41. using log4net;
  42. using OpenMetaverse;
  43. namespace OpenSim.Region.OptionalModules.Scripting
  44. {
  45. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
  46. public class ExtendedPhysics : INonSharedRegionModule
  47. {
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. private static string LogHeader = "[EXTENDED PHYSICS]";
  50. // =============================================================
  51. // Since BulletSim is a plugin, this these values aren't defined easily in one place.
  52. // This table must correspond to an identical table in BSScene.
  53. // Per scene functions. See BSScene.
  54. // Per avatar functions. See BSCharacter.
  55. // Per prim functions. See BSPrim.
  56. public const string PhysFunctGetLinksetType = "BulletSim.GetLinksetType";
  57. public const string PhysFunctSetLinksetType = "BulletSim.SetLinksetType";
  58. public const string PhysFunctChangeLinkFixed = "BulletSim.ChangeLinkFixed";
  59. public const string PhysFunctChangeLinkType = "BulletSim.ChangeLinkType";
  60. public const string PhysFunctGetLinkType = "BulletSim.GetLinkType";
  61. public const string PhysFunctChangeLinkParams = "BulletSim.ChangeLinkParams";
  62. public const string PhysFunctAxisLockLimits = "BulletSim.AxisLockLimits";
  63. // =============================================================
  64. private IConfig Configuration { get; set; }
  65. private bool Enabled { get; set; }
  66. private Scene BaseScene { get; set; }
  67. private IScriptModuleComms Comms { get; set; }
  68. #region INonSharedRegionModule
  69. public string Name { get { return this.GetType().Name; } }
  70. public void Initialise(IConfigSource config)
  71. {
  72. BaseScene = null;
  73. Enabled = false;
  74. Configuration = null;
  75. Comms = null;
  76. try
  77. {
  78. if ((Configuration = config.Configs["ExtendedPhysics"]) != null)
  79. {
  80. Enabled = Configuration.GetBoolean("Enabled", Enabled);
  81. }
  82. }
  83. catch (Exception e)
  84. {
  85. m_log.ErrorFormat("{0} Initialization error: {0}", LogHeader, e);
  86. }
  87. m_log.InfoFormat("{0} module {1} enabled", LogHeader, (Enabled ? "is" : "is not"));
  88. }
  89. public void Close()
  90. {
  91. if (BaseScene != null)
  92. {
  93. BaseScene.EventManager.OnObjectAddedToScene -= EventManager_OnObjectAddedToScene;
  94. BaseScene.EventManager.OnSceneObjectPartUpdated -= EventManager_OnSceneObjectPartUpdated;
  95. BaseScene = null;
  96. }
  97. }
  98. public void AddRegion(Scene scene)
  99. {
  100. }
  101. public void RemoveRegion(Scene scene)
  102. {
  103. if (BaseScene != null && BaseScene == scene)
  104. {
  105. Close();
  106. }
  107. }
  108. public void RegionLoaded(Scene scene)
  109. {
  110. if (!Enabled) return;
  111. BaseScene = scene;
  112. Comms = BaseScene.RequestModuleInterface<IScriptModuleComms>();
  113. if (Comms == null)
  114. {
  115. m_log.WarnFormat("{0} ScriptModuleComms interface not defined", LogHeader);
  116. Enabled = false;
  117. return;
  118. }
  119. // Register as LSL functions all the [ScriptInvocation] marked methods.
  120. Comms.RegisterScriptInvocations(this);
  121. Comms.RegisterConstants(this);
  122. // When an object is modified, we might need to update its extended physics parameters
  123. BaseScene.EventManager.OnObjectAddedToScene += EventManager_OnObjectAddedToScene;
  124. BaseScene.EventManager.OnSceneObjectPartUpdated += EventManager_OnSceneObjectPartUpdated;
  125. }
  126. public Type ReplaceableInterface { get { return null; } }
  127. #endregion // INonSharedRegionModule
  128. private void EventManager_OnObjectAddedToScene(SceneObjectGroup obj)
  129. {
  130. }
  131. // Event generated when some property of a prim changes.
  132. private void EventManager_OnSceneObjectPartUpdated(SceneObjectPart sop, bool isFullUpdate)
  133. {
  134. }
  135. [ScriptConstant]
  136. public const int PHYS_CENTER_OF_MASS = 1 << 0;
  137. [ScriptInvocation]
  138. public string physGetEngineType(UUID hostID, UUID scriptID)
  139. {
  140. string ret = string.Empty;
  141. if (BaseScene.PhysicsScene != null)
  142. {
  143. ret = BaseScene.PhysicsScene.EngineType;
  144. }
  145. return ret;
  146. }
  147. // Code for specifying params.
  148. // The choice if 14700 is arbitrary and only serves to catch parameter code misuse.
  149. [ScriptConstant]
  150. public const int PHYS_AXIS_LOCK_LINEAR = 14700;
  151. [ScriptConstant]
  152. public const int PHYS_AXIS_LOCK_LINEAR_X = 14701;
  153. [ScriptConstant]
  154. public const int PHYS_AXIS_LIMIT_LINEAR_X = 14702;
  155. [ScriptConstant]
  156. public const int PHYS_AXIS_LOCK_LINEAR_Y = 14703;
  157. [ScriptConstant]
  158. public const int PHYS_AXIS_LIMIT_LINEAR_Y = 14704;
  159. [ScriptConstant]
  160. public const int PHYS_AXIS_LOCK_LINEAR_Z = 14705;
  161. [ScriptConstant]
  162. public const int PHYS_AXIS_LIMIT_LINEAR_Z = 14706;
  163. [ScriptConstant]
  164. public const int PHYS_AXIS_LOCK_ANGULAR = 14707;
  165. [ScriptConstant]
  166. public const int PHYS_AXIS_LOCK_ANGULAR_X = 14708;
  167. [ScriptConstant]
  168. public const int PHYS_AXIS_LIMIT_ANGULAR_X = 14709;
  169. [ScriptConstant]
  170. public const int PHYS_AXIS_LOCK_ANGULAR_Y = 14710;
  171. [ScriptConstant]
  172. public const int PHYS_AXIS_LIMIT_ANGULAR_Y = 14711;
  173. [ScriptConstant]
  174. public const int PHYS_AXIS_LOCK_ANGULAR_Z = 14712;
  175. [ScriptConstant]
  176. public const int PHYS_AXIS_LIMIT_ANGULAR_Z = 14713;
  177. [ScriptConstant]
  178. public const int PHYS_AXIS_UNLOCK_LINEAR = 14714;
  179. [ScriptConstant]
  180. public const int PHYS_AXIS_UNLOCK_LINEAR_X = 14715;
  181. [ScriptConstant]
  182. public const int PHYS_AXIS_UNLOCK_LINEAR_Y = 14716;
  183. [ScriptConstant]
  184. public const int PHYS_AXIS_UNLOCK_LINEAR_Z = 14717;
  185. [ScriptConstant]
  186. public const int PHYS_AXIS_UNLOCK_ANGULAR = 14718;
  187. [ScriptConstant]
  188. public const int PHYS_AXIS_UNLOCK_ANGULAR_X = 14719;
  189. [ScriptConstant]
  190. public const int PHYS_AXIS_UNLOCK_ANGULAR_Y = 14720;
  191. [ScriptConstant]
  192. public const int PHYS_AXIS_UNLOCK_ANGULAR_Z = 14721;
  193. [ScriptConstant]
  194. public const int PHYS_AXIS_UNLOCK = 14722;
  195. // physAxisLockLimits()
  196. [ScriptInvocation]
  197. public int physAxisLock(UUID hostID, UUID scriptID, object[] parms)
  198. {
  199. int ret = -1;
  200. if (!Enabled) return ret;
  201. PhysicsActor rootPhysActor;
  202. if (GetRootPhysActor(hostID, out rootPhysActor))
  203. {
  204. object[] parms2 = AddToBeginningOfArray(rootPhysActor, null, parms);
  205. ret = MakeIntError(rootPhysActor.Extension(PhysFunctAxisLockLimits, parms2));
  206. }
  207. return ret;
  208. }
  209. [ScriptConstant]
  210. public const int PHYS_LINKSET_TYPE_CONSTRAINT = 0;
  211. [ScriptConstant]
  212. public const int PHYS_LINKSET_TYPE_COMPOUND = 1;
  213. [ScriptConstant]
  214. public const int PHYS_LINKSET_TYPE_MANUAL = 2;
  215. [ScriptInvocation]
  216. public int physSetLinksetType(UUID hostID, UUID scriptID, int linksetType)
  217. {
  218. int ret = -1;
  219. if (!Enabled) return ret;
  220. // The part that is requesting the change.
  221. SceneObjectPart requestingPart = BaseScene.GetSceneObjectPart(hostID);
  222. if (requestingPart != null)
  223. {
  224. // The change is always made to the root of a linkset.
  225. SceneObjectGroup containingGroup = requestingPart.ParentGroup;
  226. SceneObjectPart rootPart = containingGroup.RootPart;
  227. if (rootPart != null)
  228. {
  229. PhysicsActor rootPhysActor = rootPart.PhysActor;
  230. if (rootPhysActor != null)
  231. {
  232. if (rootPhysActor.IsPhysical)
  233. {
  234. // Change a physical linkset by making non-physical, waiting for one heartbeat so all
  235. // the prim and linkset state is updated, changing the type and making the
  236. // linkset physical again.
  237. containingGroup.ScriptSetPhysicsStatus(false);
  238. Thread.Sleep(150); // longer than one heartbeat tick
  239. // A kludge for the moment.
  240. // Since compound linksets move the children but don't generate position updates to the
  241. // simulator, it is possible for compound linkset children to have out-of-sync simulator
  242. // and physical positions. The following causes the simulator to push the real child positions
  243. // down into the physics engine to get everything synced.
  244. containingGroup.UpdateGroupPosition(containingGroup.AbsolutePosition);
  245. containingGroup.UpdateGroupRotationR(containingGroup.GroupRotation);
  246. object[] parms2 = { rootPhysActor, null, linksetType };
  247. ret = MakeIntError(rootPhysActor.Extension(PhysFunctSetLinksetType, parms2));
  248. Thread.Sleep(150); // longer than one heartbeat tick
  249. containingGroup.ScriptSetPhysicsStatus(true);
  250. }
  251. else
  252. {
  253. // Non-physical linksets don't have a physical instantiation so there is no state to
  254. // worry about being updated.
  255. object[] parms2 = { rootPhysActor, null, linksetType };
  256. ret = MakeIntError(rootPhysActor.Extension(PhysFunctSetLinksetType, parms2));
  257. }
  258. }
  259. else
  260. {
  261. m_log.WarnFormat("{0} physSetLinksetType: root part does not have a physics actor. rootName={1}, hostID={2}",
  262. LogHeader, rootPart.Name, hostID);
  263. }
  264. }
  265. else
  266. {
  267. m_log.WarnFormat("{0} physSetLinksetType: root part does not exist. RequestingPartName={1}, hostID={2}",
  268. LogHeader, requestingPart.Name, hostID);
  269. }
  270. }
  271. else
  272. {
  273. m_log.WarnFormat("{0} physSetLinsetType: cannot find script object in scene. hostID={1}", LogHeader, hostID);
  274. }
  275. return ret;
  276. }
  277. [ScriptInvocation]
  278. public int physGetLinksetType(UUID hostID, UUID scriptID)
  279. {
  280. int ret = -1;
  281. if (!Enabled) return ret;
  282. PhysicsActor rootPhysActor;
  283. if (GetRootPhysActor(hostID, out rootPhysActor))
  284. {
  285. object[] parms2 = { rootPhysActor, null };
  286. ret = MakeIntError(rootPhysActor.Extension(PhysFunctGetLinksetType, parms2));
  287. }
  288. else
  289. {
  290. m_log.WarnFormat("{0} physGetLinsetType: cannot find script object in scene. hostID={1}", LogHeader, hostID);
  291. }
  292. return ret;
  293. }
  294. [ScriptConstant]
  295. public const int PHYS_LINK_TYPE_FIXED = 1234;
  296. [ScriptConstant]
  297. public const int PHYS_LINK_TYPE_HINGE = 4;
  298. [ScriptConstant]
  299. public const int PHYS_LINK_TYPE_SPRING = 9;
  300. [ScriptConstant]
  301. public const int PHYS_LINK_TYPE_6DOF = 6;
  302. [ScriptConstant]
  303. public const int PHYS_LINK_TYPE_SLIDER = 7;
  304. // physChangeLinkType(integer linkNum, integer typeCode)
  305. [ScriptInvocation]
  306. public int physChangeLinkType(UUID hostID, UUID scriptID, int linkNum, int typeCode)
  307. {
  308. int ret = -1;
  309. if (!Enabled) return ret;
  310. PhysicsActor rootPhysActor;
  311. PhysicsActor childPhysActor;
  312. if (GetRootAndChildPhysActors(hostID, linkNum, out rootPhysActor, out childPhysActor))
  313. {
  314. object[] parms2 = { rootPhysActor, childPhysActor, typeCode };
  315. ret = MakeIntError(rootPhysActor.Extension(PhysFunctChangeLinkType, parms2));
  316. }
  317. return ret;
  318. }
  319. // physGetLinkType(integer linkNum)
  320. [ScriptInvocation]
  321. public int physGetLinkType(UUID hostID, UUID scriptID, int linkNum)
  322. {
  323. int ret = -1;
  324. if (!Enabled) return ret;
  325. PhysicsActor rootPhysActor;
  326. PhysicsActor childPhysActor;
  327. if (GetRootAndChildPhysActors(hostID, linkNum, out rootPhysActor, out childPhysActor))
  328. {
  329. object[] parms2 = { rootPhysActor, childPhysActor };
  330. ret = MakeIntError(rootPhysActor.Extension(PhysFunctGetLinkType, parms2));
  331. }
  332. return ret;
  333. }
  334. // physChangeLinkFixed(integer linkNum)
  335. // Change the link between the root and the linkNum into a fixed, static physical connection.
  336. [ScriptInvocation]
  337. public int physChangeLinkFixed(UUID hostID, UUID scriptID, int linkNum)
  338. {
  339. int ret = -1;
  340. if (!Enabled) return ret;
  341. PhysicsActor rootPhysActor;
  342. PhysicsActor childPhysActor;
  343. if (GetRootAndChildPhysActors(hostID, linkNum, out rootPhysActor, out childPhysActor))
  344. {
  345. object[] parms2 = { rootPhysActor, childPhysActor , PHYS_LINK_TYPE_FIXED };
  346. ret = MakeIntError(rootPhysActor.Extension(PhysFunctChangeLinkType, parms2));
  347. }
  348. return ret;
  349. }
  350. // Code for specifying params.
  351. // The choice if 14400 is arbitrary and only serves to catch parameter code misuse.
  352. public const int PHYS_PARAM_MIN = 14401;
  353. [ScriptConstant]
  354. public const int PHYS_PARAM_FRAMEINA_LOC = 14401;
  355. [ScriptConstant]
  356. public const int PHYS_PARAM_FRAMEINA_ROT = 14402;
  357. [ScriptConstant]
  358. public const int PHYS_PARAM_FRAMEINB_LOC = 14403;
  359. [ScriptConstant]
  360. public const int PHYS_PARAM_FRAMEINB_ROT = 14404;
  361. [ScriptConstant]
  362. public const int PHYS_PARAM_LINEAR_LIMIT_LOW = 14405;
  363. [ScriptConstant]
  364. public const int PHYS_PARAM_LINEAR_LIMIT_HIGH = 14406;
  365. [ScriptConstant]
  366. public const int PHYS_PARAM_ANGULAR_LIMIT_LOW = 14407;
  367. [ScriptConstant]
  368. public const int PHYS_PARAM_ANGULAR_LIMIT_HIGH = 14408;
  369. [ScriptConstant]
  370. public const int PHYS_PARAM_USE_FRAME_OFFSET = 14409;
  371. [ScriptConstant]
  372. public const int PHYS_PARAM_ENABLE_TRANSMOTOR = 14410;
  373. [ScriptConstant]
  374. public const int PHYS_PARAM_TRANSMOTOR_MAXVEL = 14411;
  375. [ScriptConstant]
  376. public const int PHYS_PARAM_TRANSMOTOR_MAXFORCE = 14412;
  377. [ScriptConstant]
  378. public const int PHYS_PARAM_CFM = 14413;
  379. [ScriptConstant]
  380. public const int PHYS_PARAM_ERP = 14414;
  381. [ScriptConstant]
  382. public const int PHYS_PARAM_SOLVER_ITERATIONS = 14415;
  383. [ScriptConstant]
  384. public const int PHYS_PARAM_SPRING_AXIS_ENABLE = 14416;
  385. [ScriptConstant]
  386. public const int PHYS_PARAM_SPRING_DAMPING = 14417;
  387. [ScriptConstant]
  388. public const int PHYS_PARAM_SPRING_STIFFNESS = 14418;
  389. [ScriptConstant]
  390. public const int PHYS_PARAM_LINK_TYPE = 14419;
  391. [ScriptConstant]
  392. public const int PHYS_PARAM_USE_LINEAR_FRAMEA = 14420;
  393. [ScriptConstant]
  394. public const int PHYS_PARAM_SPRING_EQUILIBRIUM_POINT = 14421;
  395. public const int PHYS_PARAM_MAX = 14421;
  396. // Used when specifying a parameter that has settings for the three linear and three angular axis
  397. [ScriptConstant]
  398. public const int PHYS_AXIS_ALL = -1;
  399. [ScriptConstant]
  400. public const int PHYS_AXIS_LINEAR_ALL = -2;
  401. [ScriptConstant]
  402. public const int PHYS_AXIS_ANGULAR_ALL = -3;
  403. [ScriptConstant]
  404. public const int PHYS_AXIS_LINEAR_X = 0;
  405. [ScriptConstant]
  406. public const int PHYS_AXIS_LINEAR_Y = 1;
  407. [ScriptConstant]
  408. public const int PHYS_AXIS_LINEAR_Z = 2;
  409. [ScriptConstant]
  410. public const int PHYS_AXIS_ANGULAR_X = 3;
  411. [ScriptConstant]
  412. public const int PHYS_AXIS_ANGULAR_Y = 4;
  413. [ScriptConstant]
  414. public const int PHYS_AXIS_ANGULAR_Z = 5;
  415. // physChangeLinkParams(integer linkNum, [ PHYS_PARAM_*, value, PHYS_PARAM_*, value, ...])
  416. [ScriptInvocation]
  417. public int physChangeLinkParams(UUID hostID, UUID scriptID, int linkNum, object[] parms)
  418. {
  419. int ret = -1;
  420. if (!Enabled) return ret;
  421. PhysicsActor rootPhysActor;
  422. PhysicsActor childPhysActor;
  423. if (GetRootAndChildPhysActors(hostID, linkNum, out rootPhysActor, out childPhysActor))
  424. {
  425. object[] parms2 = AddToBeginningOfArray(rootPhysActor, childPhysActor, parms);
  426. ret = MakeIntError(rootPhysActor.Extension(PhysFunctChangeLinkParams, parms2));
  427. }
  428. return ret;
  429. }
  430. private bool GetRootPhysActor(UUID hostID, out PhysicsActor rootPhysActor)
  431. {
  432. SceneObjectGroup containingGroup;
  433. SceneObjectPart rootPart;
  434. return GetRootPhysActor(hostID, out containingGroup, out rootPart, out rootPhysActor);
  435. }
  436. private bool GetRootPhysActor(UUID hostID, out SceneObjectGroup containingGroup, out SceneObjectPart rootPart, out PhysicsActor rootPhysActor)
  437. {
  438. bool ret = false;
  439. rootPhysActor = null;
  440. containingGroup = null;
  441. rootPart = null;
  442. SceneObjectPart requestingPart;
  443. requestingPart = BaseScene.GetSceneObjectPart(hostID);
  444. if (requestingPart != null)
  445. {
  446. // The type is is always on the root of a linkset.
  447. containingGroup = requestingPart.ParentGroup;
  448. if (containingGroup != null && !containingGroup.IsDeleted)
  449. {
  450. rootPart = containingGroup.RootPart;
  451. if (rootPart != null)
  452. {
  453. rootPhysActor = rootPart.PhysActor;
  454. if (rootPhysActor != null)
  455. {
  456. ret = true;
  457. }
  458. else
  459. {
  460. m_log.WarnFormat("{0} GetRootAndChildPhysActors: Root part does not have a physics actor. rootName={1}, hostID={2}",
  461. LogHeader, rootPart.Name, hostID);
  462. }
  463. }
  464. else
  465. {
  466. m_log.WarnFormat("{0} GetRootAndChildPhysActors: Root part does not exist. RequestingPartName={1}, hostID={2}",
  467. LogHeader, requestingPart.Name, hostID);
  468. }
  469. }
  470. else
  471. {
  472. m_log.WarnFormat("{0} GetRootAndChildPhysActors: Containing group missing or deleted. hostID={1}", LogHeader, hostID);
  473. }
  474. }
  475. else
  476. {
  477. m_log.WarnFormat("{0} GetRootAndChildPhysActors: cannot find script object in scene. hostID={1}", LogHeader, hostID);
  478. }
  479. return ret;
  480. }
  481. // Find the root and child PhysActors based on the linkNum.
  482. // Return 'true' if both are found and returned.
  483. private bool GetRootAndChildPhysActors(UUID hostID, int linkNum, out PhysicsActor rootPhysActor, out PhysicsActor childPhysActor)
  484. {
  485. bool ret = false;
  486. rootPhysActor = null;
  487. childPhysActor = null;
  488. SceneObjectGroup containingGroup;
  489. SceneObjectPart rootPart;
  490. if (GetRootPhysActor(hostID, out containingGroup, out rootPart, out rootPhysActor))
  491. {
  492. SceneObjectPart linkPart = containingGroup.GetLinkNumPart(linkNum);
  493. if (linkPart != null)
  494. {
  495. childPhysActor = linkPart.PhysActor;
  496. if (childPhysActor != null)
  497. {
  498. ret = true;
  499. }
  500. else
  501. {
  502. m_log.WarnFormat("{0} GetRootAndChildPhysActors: Link part has no physical actor. rootName={1}, hostID={2}, linknum={3}",
  503. LogHeader, rootPart.Name, hostID, linkNum);
  504. }
  505. }
  506. else
  507. {
  508. m_log.WarnFormat("{0} GetRootAndChildPhysActors: Could not find linknum part. rootName={1}, hostID={2}, linknum={3}",
  509. LogHeader, rootPart.Name, hostID, linkNum);
  510. }
  511. }
  512. else
  513. {
  514. m_log.WarnFormat("{0} GetRootAndChildPhysActors: Root part does not have a physics actor. rootName={1}, hostID={2}",
  515. LogHeader, rootPart.Name, hostID);
  516. }
  517. return ret;
  518. }
  519. // Return an array of objects with the passed object as the first object of a new array
  520. private object[] AddToBeginningOfArray(object firstOne, object secondOne, object[] prevArray)
  521. {
  522. object[] newArray = new object[2 + prevArray.Length];
  523. newArray[0] = firstOne;
  524. newArray[1] = secondOne;
  525. prevArray.CopyTo(newArray, 2);
  526. return newArray;
  527. }
  528. // Extension() returns an object. Convert that object into the integer error we expect to return.
  529. private int MakeIntError(object extensionRet)
  530. {
  531. int ret = -1;
  532. if (extensionRet != null)
  533. {
  534. try
  535. {
  536. ret = (int)extensionRet;
  537. }
  538. catch
  539. {
  540. ret = -1;
  541. }
  542. }
  543. return ret;
  544. }
  545. }
  546. }