aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/ODEPrim.cs')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs279
1 files changed, 138 insertions, 141 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index b3045bd..924d7c2 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -61,6 +61,22 @@ namespace OpenSim.Region.Physics.OdePlugin
61 { 61 {
62 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 62 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
63 63
64 private bool m_isphysical;
65
66 /// <summary>
67 /// Is this prim subject to physics? Even if not, it's still solid for collision purposes.
68 /// </summary>
69 public override bool IsPhysical
70 {
71 get { return m_isphysical; }
72 set
73 {
74 m_isphysical = value;
75 if (!m_isphysical) // Zero the remembered last velocity
76 m_lastVelocity = Vector3.Zero;
77 }
78 }
79
64 private Vector3 _position; 80 private Vector3 _position;
65 private Vector3 _velocity; 81 private Vector3 _velocity;
66 private Vector3 _torque; 82 private Vector3 _torque;
@@ -138,12 +154,15 @@ namespace OpenSim.Region.Physics.OdePlugin
138 private List<Vector3> m_forcelist = new List<Vector3>(); 154 private List<Vector3> m_forcelist = new List<Vector3>();
139 private List<Vector3> m_angularforcelist = new List<Vector3>(); 155 private List<Vector3> m_angularforcelist = new List<Vector3>();
140 156
141 private IMesh _mesh;
142 private PrimitiveBaseShape _pbs; 157 private PrimitiveBaseShape _pbs;
143 private OdeScene _parent_scene; 158 private OdeScene _parent_scene;
159
160 /// <summary>
161 /// The physics space which contains prim geometries
162 /// </summary>
144 public IntPtr m_targetSpace = IntPtr.Zero; 163 public IntPtr m_targetSpace = IntPtr.Zero;
164
145 public IntPtr prim_geom; 165 public IntPtr prim_geom;
146 public IntPtr prev_geom;
147 public IntPtr _triMeshData; 166 public IntPtr _triMeshData;
148 167
149 private IntPtr _linkJointGroup = IntPtr.Zero; 168 private IntPtr _linkJointGroup = IntPtr.Zero;
@@ -153,7 +172,6 @@ namespace OpenSim.Region.Physics.OdePlugin
153 private List<OdePrim> childrenPrim = new List<OdePrim>(); 172 private List<OdePrim> childrenPrim = new List<OdePrim>();
154 173
155 private bool iscolliding; 174 private bool iscolliding;
156 private bool m_isphysical;
157 private bool m_isSelected; 175 private bool m_isSelected;
158 176
159 internal bool m_isVolumeDetect; // If true, this prim only detects collisions but doesn't collide actively 177 internal bool m_isVolumeDetect; // If true, this prim only detects collisions but doesn't collide actively
@@ -188,7 +206,7 @@ namespace OpenSim.Region.Physics.OdePlugin
188 internal int m_material = (int)Material.Wood; 206 internal int m_material = (int)Material.Wood;
189 207
190 public OdePrim(String primName, OdeScene parent_scene, Vector3 pos, Vector3 size, 208 public OdePrim(String primName, OdeScene parent_scene, Vector3 pos, Vector3 size,
191 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) 209 Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode)
192 { 210 {
193 Name = primName; 211 Name = primName;
194 m_vehicle = new ODEDynamics(); 212 m_vehicle = new ODEDynamics();
@@ -208,9 +226,7 @@ namespace OpenSim.Region.Physics.OdePlugin
208 // m_tensor = parent_scene.bodyMotorJointMaxforceTensor; 226 // m_tensor = parent_scene.bodyMotorJointMaxforceTensor;
209 body_autodisable_frames = parent_scene.bodyFramesAutoDisable; 227 body_autodisable_frames = parent_scene.bodyFramesAutoDisable;
210 228
211
212 prim_geom = IntPtr.Zero; 229 prim_geom = IntPtr.Zero;
213 prev_geom = IntPtr.Zero;
214 230
215 if (!pos.IsFinite()) 231 if (!pos.IsFinite())
216 { 232 {
@@ -233,20 +249,21 @@ namespace OpenSim.Region.Physics.OdePlugin
233 249
234 _orientation = rotation; 250 _orientation = rotation;
235 m_taintrot = _orientation; 251 m_taintrot = _orientation;
236 _mesh = mesh;
237 _pbs = pbs; 252 _pbs = pbs;
238 253
239 _parent_scene = parent_scene; 254 _parent_scene = parent_scene;
240 m_targetSpace = (IntPtr)0; 255 m_targetSpace = (IntPtr)0;
241 256
242 if (pos.Z < 0) 257 if (pos.Z < 0)
243 m_isphysical = false; 258 {
259 IsPhysical = false;
260 }
244 else 261 else
245 { 262 {
246 m_isphysical = pisPhysical; 263 IsPhysical = pisPhysical;
247 // If we're physical, we need to be in the master space for now. 264 // If we're physical, we need to be in the master space for now.
248 // linksets *should* be in a space together.. but are not currently 265 // linksets *should* be in a space together.. but are not currently
249 if (m_isphysical) 266 if (IsPhysical)
250 m_targetSpace = _parent_scene.space; 267 m_targetSpace = _parent_scene.space;
251 } 268 }
252 269
@@ -289,7 +306,7 @@ namespace OpenSim.Region.Physics.OdePlugin
289 // through it while it's selected 306 // through it while it's selected
290 m_collisionscore = 0; 307 m_collisionscore = 0;
291 308
292 if ((m_isphysical && !_zeroFlag) || !value) 309 if ((IsPhysical && !_zeroFlag) || !value)
293 { 310 {
294 m_taintselected = value; 311 m_taintselected = value;
295 _parent_scene.AddPhysicsActorTaint(this); 312 _parent_scene.AddPhysicsActorTaint(this);
@@ -305,15 +322,21 @@ namespace OpenSim.Region.Physics.OdePlugin
305 } 322 }
306 } 323 }
307 324
325 /// <summary>
326 /// Set a new geometry for this prim.
327 /// </summary>
328 /// <param name="geom"></param>
308 public void SetGeom(IntPtr geom) 329 public void SetGeom(IntPtr geom)
309 { 330 {
310 prev_geom = prim_geom;
311 prim_geom = geom; 331 prim_geom = geom;
312//Console.WriteLine("SetGeom to " + prim_geom + " for " + Name); 332//Console.WriteLine("SetGeom to " + prim_geom + " for " + Name);
313 if (prim_geom != IntPtr.Zero) 333 if (prim_geom != IntPtr.Zero)
314 { 334 {
315 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 335 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
316 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 336 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
337
338 _parent_scene.geom_name_map[prim_geom] = Name;
339 _parent_scene.actor_name_map[prim_geom] = this;
317 } 340 }
318 341
319 if (childPrim) 342 if (childPrim)
@@ -332,7 +355,7 @@ namespace OpenSim.Region.Physics.OdePlugin
332 { 355 {
333 if (!childPrim) 356 if (!childPrim)
334 { 357 {
335 if (m_isphysical && Body != IntPtr.Zero) 358 if (IsPhysical && Body != IntPtr.Zero)
336 { 359 {
337 d.BodyEnable(Body); 360 d.BodyEnable(Body);
338 if (m_vehicle.Type != Vehicle.TYPE_NONE) 361 if (m_vehicle.Type != Vehicle.TYPE_NONE)
@@ -347,12 +370,15 @@ namespace OpenSim.Region.Physics.OdePlugin
347 { 370 {
348 m_disabled = true; 371 m_disabled = true;
349 372
350 if (m_isphysical && Body != IntPtr.Zero) 373 if (IsPhysical && Body != IntPtr.Zero)
351 { 374 {
352 d.BodyDisable(Body); 375 d.BodyDisable(Body);
353 } 376 }
354 } 377 }
355 378
379 /// <summary>
380 /// Make a prim subject to physics.
381 /// </summary>
356 public void enableBody() 382 public void enableBody()
357 { 383 {
358 // Don't enable this body if we're a child prim 384 // Don't enable this body if we're a child prim
@@ -728,6 +754,9 @@ namespace OpenSim.Region.Physics.OdePlugin
728 } 754 }
729 } 755 }
730 756
757 /// <summary>
758 /// Stop a prim from being subject to physics.
759 /// </summary>
731 public void disableBody() 760 public void disableBody()
732 { 761 {
733 //this kills the body so things like 'mesh' can re-create it. 762 //this kills the body so things like 'mesh' can re-create it.
@@ -778,6 +807,7 @@ namespace OpenSim.Region.Physics.OdePlugin
778 Body = IntPtr.Zero; 807 Body = IntPtr.Zero;
779 } 808 }
780 } 809 }
810
781 m_disabled = true; 811 m_disabled = true;
782 m_collisionscore = 0; 812 m_collisionscore = 0;
783 } 813 }
@@ -886,7 +916,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
886 } 916 }
887 } 917 }
888 918
889 if (m_taintPhysics != m_isphysical && !(m_taintparent != _parent)) 919 if (m_taintPhysics != IsPhysical && !(m_taintparent != _parent))
890 changePhysicsStatus(timestep); 920 changePhysicsStatus(timestep);
891 921
892 if (!_size.ApproxEquals(m_taintsize, 0f)) 922 if (!_size.ApproxEquals(m_taintsize, 0f))
@@ -968,7 +998,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
968 OdePrim obj = (OdePrim)m_taintparent; 998 OdePrim obj = (OdePrim)m_taintparent;
969 //obj.disableBody(); 999 //obj.disableBody();
970//Console.WriteLine("changelink calls ParentPrim"); 1000//Console.WriteLine("changelink calls ParentPrim");
971 obj.ParentPrim(this); 1001 obj.AddChildPrim(this);
972 1002
973 /* 1003 /*
974 if (obj.Body != (IntPtr)0 && Body != (IntPtr)0 && obj.Body != Body) 1004 if (obj.Body != (IntPtr)0 && Body != (IntPtr)0 && obj.Body != Body)
@@ -1005,14 +1035,16 @@ Console.WriteLine("ZProcessTaints for " + Name);
1005 } 1035 }
1006 1036
1007 _parent = m_taintparent; 1037 _parent = m_taintparent;
1008 m_taintPhysics = m_isphysical; 1038 m_taintPhysics = IsPhysical;
1009 } 1039 }
1010 1040
1011 // I'm the parent 1041 /// <summary>
1012 // prim is the child 1042 /// Add a child prim to this parent prim.
1013 public void ParentPrim(OdePrim prim) 1043 /// </summary>
1044 /// <param name="prim">Child prim</param>
1045 public void AddChildPrim(OdePrim prim)
1014 { 1046 {
1015//Console.WriteLine("ParentPrim " + Name); 1047//Console.WriteLine("AddChildPrim " + Name);
1016 if (this.m_localID != prim.m_localID) 1048 if (this.m_localID != prim.m_localID)
1017 { 1049 {
1018 if (Body == IntPtr.Zero) 1050 if (Body == IntPtr.Zero)
@@ -1035,7 +1067,6 @@ Console.WriteLine("ZProcessTaints for " + Name);
1035 d.MassSetZero(out m2); 1067 d.MassSetZero(out m2);
1036 d.MassSetBoxTotal(out m2, prim.CalculateMass(), prm._size.X, prm._size.Y, prm._size.Z); 1068 d.MassSetBoxTotal(out m2, prim.CalculateMass(), prm._size.X, prm._size.Y, prm._size.Z);
1037 1069
1038
1039 d.Quaternion quat = new d.Quaternion(); 1070 d.Quaternion quat = new d.Quaternion();
1040 quat.W = prm._orientation.W; 1071 quat.W = prm._orientation.W;
1041 quat.X = prm._orientation.X; 1072 quat.X = prm._orientation.X;
@@ -1105,6 +1136,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
1105 prm.Body = Body; 1136 prm.Body = Body;
1106 _parent_scene.addActivePrim(prm); 1137 _parent_scene.addActivePrim(prm);
1107 } 1138 }
1139
1108 m_collisionCategories |= CollisionCategories.Body; 1140 m_collisionCategories |= CollisionCategories.Body;
1109 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind); 1141 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1110 1142
@@ -1113,7 +1145,6 @@ Console.WriteLine("ZProcessTaints for " + Name);
1113//Console.WriteLine(" Post GeomSetCategoryBits 2"); 1145//Console.WriteLine(" Post GeomSetCategoryBits 2");
1114 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 1146 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1115 1147
1116
1117 d.Quaternion quat2 = new d.Quaternion(); 1148 d.Quaternion quat2 = new d.Quaternion();
1118 quat2.W = _orientation.W; 1149 quat2.W = _orientation.W;
1119 quat2.X = _orientation.X; 1150 quat2.X = _orientation.X;
@@ -1135,7 +1166,6 @@ Console.WriteLine("ZProcessTaints for " + Name);
1135 d.BodySetAutoDisableFlag(Body, true); 1166 d.BodySetAutoDisableFlag(Body, true);
1136 d.BodySetAutoDisableSteps(Body, body_autodisable_frames); 1167 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
1137 1168
1138
1139 m_interpenetrationcount = 0; 1169 m_interpenetrationcount = 0;
1140 m_collisionscore = 0; 1170 m_collisionscore = 0;
1141 m_disabled = false; 1171 m_disabled = false;
@@ -1146,7 +1176,9 @@ Console.WriteLine("ZProcessTaints for " + Name);
1146 createAMotor(m_angularlock); 1176 createAMotor(m_angularlock);
1147 } 1177 }
1148 d.BodySetPosition(Body, Position.X, Position.Y, Position.Z); 1178 d.BodySetPosition(Body, Position.X, Position.Y, Position.Z);
1149 if (m_vehicle.Type != Vehicle.TYPE_NONE) m_vehicle.Enable(Body, _parent_scene); 1179 if (m_vehicle.Type != Vehicle.TYPE_NONE)
1180 m_vehicle.Enable(Body, _parent_scene);
1181
1150 _parent_scene.addActivePrim(this); 1182 _parent_scene.addActivePrim(this);
1151 } 1183 }
1152 } 1184 }
@@ -1156,7 +1188,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
1156 1188
1157 private void ChildSetGeom(OdePrim odePrim) 1189 private void ChildSetGeom(OdePrim odePrim)
1158 { 1190 {
1159 //if (m_isphysical && Body != IntPtr.Zero) 1191 //if (IsPhysical && Body != IntPtr.Zero)
1160 lock (childrenPrim) 1192 lock (childrenPrim)
1161 { 1193 {
1162 foreach (OdePrim prm in childrenPrim) 1194 foreach (OdePrim prm in childrenPrim)
@@ -1172,7 +1204,6 @@ Console.WriteLine("ZProcessTaints for " + Name);
1172 } 1204 }
1173 disableBody(); 1205 disableBody();
1174 1206
1175
1176 if (Body != IntPtr.Zero) 1207 if (Body != IntPtr.Zero)
1177 { 1208 {
1178 _parent_scene.remActivePrim(this); 1209 _parent_scene.remActivePrim(this);
@@ -1183,10 +1214,9 @@ Console.WriteLine("ZProcessTaints for " + Name);
1183 foreach (OdePrim prm in childrenPrim) 1214 foreach (OdePrim prm in childrenPrim)
1184 { 1215 {
1185//Console.WriteLine("ChildSetGeom calls ParentPrim"); 1216//Console.WriteLine("ChildSetGeom calls ParentPrim");
1186 ParentPrim(prm); 1217 AddChildPrim(prm);
1187 } 1218 }
1188 } 1219 }
1189
1190 } 1220 }
1191 1221
1192 private void ChildDelink(OdePrim odePrim) 1222 private void ChildDelink(OdePrim odePrim)
@@ -1223,7 +1253,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
1223 foreach (OdePrim prm in childrenPrim) 1253 foreach (OdePrim prm in childrenPrim)
1224 { 1254 {
1225//Console.WriteLine("ChildDelink calls ParentPrim"); 1255//Console.WriteLine("ChildDelink calls ParentPrim");
1226 ParentPrim(prm); 1256 AddChildPrim(prm);
1227 } 1257 }
1228 } 1258 }
1229 } 1259 }
@@ -1257,7 +1287,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
1257 // first 50 again. then the last 50 are disabled. then the first 50, which were just woken 1287 // first 50 again. then the last 50 are disabled. then the first 50, which were just woken
1258 // up, start simulating again, which in turn wakes up the last 50. 1288 // up, start simulating again, which in turn wakes up the last 50.
1259 1289
1260 if (m_isphysical) 1290 if (IsPhysical)
1261 { 1291 {
1262 disableBodySoft(); 1292 disableBodySoft();
1263 } 1293 }
@@ -1268,7 +1298,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
1268 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 1298 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1269 } 1299 }
1270 1300
1271 if (m_isphysical) 1301 if (IsPhysical)
1272 { 1302 {
1273 disableBodySoft(); 1303 disableBodySoft();
1274 } 1304 }
@@ -1277,7 +1307,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
1277 { 1307 {
1278 m_collisionCategories = CollisionCategories.Geom; 1308 m_collisionCategories = CollisionCategories.Geom;
1279 1309
1280 if (m_isphysical) 1310 if (IsPhysical)
1281 m_collisionCategories |= CollisionCategories.Body; 1311 m_collisionCategories |= CollisionCategories.Body;
1282 1312
1283 m_collisionFlags = m_default_collisionFlags; 1313 m_collisionFlags = m_default_collisionFlags;
@@ -1292,7 +1322,8 @@ Console.WriteLine("ZProcessTaints for " + Name);
1292 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 1322 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1293 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 1323 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1294 } 1324 }
1295 if (m_isphysical) 1325
1326 if (IsPhysical)
1296 { 1327 {
1297 if (Body != IntPtr.Zero) 1328 if (Body != IntPtr.Zero)
1298 { 1329 {
@@ -1311,7 +1342,7 @@ Console.WriteLine("ZProcessTaints for " + Name);
1311 { 1342 {
1312 m_taintposition = _position; 1343 m_taintposition = _position;
1313 m_taintrot = _orientation; 1344 m_taintrot = _orientation;
1314 m_taintPhysics = m_isphysical; 1345 m_taintPhysics = IsPhysical;
1315 m_taintselected = m_isSelected; 1346 m_taintselected = m_isSelected;
1316 m_taintsize = _size; 1347 m_taintsize = _size;
1317 m_taintshape = false; 1348 m_taintshape = false;
@@ -1320,14 +1351,19 @@ Console.WriteLine("ZProcessTaints for " + Name);
1320 m_taintVelocity = Vector3.Zero; 1351 m_taintVelocity = Vector3.Zero;
1321 } 1352 }
1322 1353
1323 public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh) 1354 /// <summary>
1355 /// Create a geometry for the given mesh in the given target space.
1356 /// </summary>
1357 /// <param name="m_targetSpace"></param>
1358 /// <param name="mesh">If null, then a mesh is used that is based on the profile shape data.</param>
1359 public void CreateGeom(IntPtr m_targetSpace, IMesh mesh)
1324 { 1360 {
1325#if SPAM 1361#if SPAM
1326Console.WriteLine("CreateGeom:"); 1362Console.WriteLine("CreateGeom:");
1327#endif 1363#endif
1328 if (_mesh != null) 1364 if (mesh != null)
1329 { 1365 {
1330 setMesh(_parent_scene, _mesh); 1366 setMesh(_parent_scene, mesh);
1331 } 1367 }
1332 else 1368 else
1333 { 1369 {
@@ -1400,6 +1436,39 @@ Console.WriteLine("CreateGeom:");
1400 } 1436 }
1401 } 1437 }
1402 1438
1439 /// <summary>
1440 /// Remove the existing geom from this prim.
1441 /// </summary>
1442 /// <param name="m_targetSpace"></param>
1443 /// <param name="mesh">If null, then a mesh is used that is based on the profile shape data.</param>
1444 /// <returns>true if the geom was successfully removed, false if it was already gone or the remove failed.</returns>
1445 public bool RemoveGeom()
1446 {
1447 if (prim_geom != IntPtr.Zero)
1448 {
1449 try
1450 {
1451 _parent_scene.geom_name_map.Remove(prim_geom);
1452 _parent_scene.actor_name_map.Remove(prim_geom);
1453 d.GeomDestroy(prim_geom);
1454 prim_geom = IntPtr.Zero;
1455 }
1456 catch (System.AccessViolationException)
1457 {
1458 prim_geom = IntPtr.Zero;
1459 m_log.ErrorFormat("[PHYSICS]: PrimGeom dead for {0}", Name);
1460
1461 return false;
1462 }
1463
1464 return true;
1465 }
1466 else
1467 {
1468 return false;
1469 }
1470 }
1471
1403 public void changeadd(float timestep) 1472 public void changeadd(float timestep)
1404 { 1473 {
1405 int[] iprimspaceArrItem = _parent_scene.calculateSpaceArrayItemFromPos(_position); 1474 int[] iprimspaceArrItem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
@@ -1410,15 +1479,14 @@ Console.WriteLine("CreateGeom:");
1410 1479
1411 m_targetSpace = targetspace; 1480 m_targetSpace = targetspace;
1412 1481
1413 if (_mesh == null) 1482 IMesh mesh = null;
1483
1484 if (_parent_scene.needsMeshing(_pbs))
1414 { 1485 {
1415 if (_parent_scene.needsMeshing(_pbs)) 1486 // Don't need to re-enable body.. it's done in SetMesh
1416 { 1487 mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical);
1417 // Don't need to re-enable body.. it's done in SetMesh 1488 // createmesh returns null when it's a shape that isn't a cube.
1418 _mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical); 1489 // m_log.Debug(m_localID);
1419 // createmesh returns null when it's a shape that isn't a cube.
1420 // m_log.Debug(m_localID);
1421 }
1422 } 1490 }
1423 1491
1424 lock (_parent_scene.OdeLock) 1492 lock (_parent_scene.OdeLock)
@@ -1426,7 +1494,7 @@ Console.WriteLine("CreateGeom:");
1426#if SPAM 1494#if SPAM
1427Console.WriteLine("changeadd 1"); 1495Console.WriteLine("changeadd 1");
1428#endif 1496#endif
1429 CreateGeom(m_targetSpace, _mesh); 1497 CreateGeom(m_targetSpace, mesh);
1430 1498
1431 if (prim_geom != IntPtr.Zero) 1499 if (prim_geom != IntPtr.Zero)
1432 { 1500 {
@@ -1439,15 +1507,12 @@ Console.WriteLine("changeadd 1");
1439 d.GeomSetQuaternion(prim_geom, ref myrot); 1507 d.GeomSetQuaternion(prim_geom, ref myrot);
1440 } 1508 }
1441 1509
1442 if (m_isphysical && Body == IntPtr.Zero) 1510 if (IsPhysical && Body == IntPtr.Zero)
1443 { 1511 {
1444 enableBody(); 1512 enableBody();
1445 } 1513 }
1446 } 1514 }
1447 1515
1448 _parent_scene.geom_name_map[prim_geom] = this.Name;
1449 _parent_scene.actor_name_map[prim_geom] = (PhysicsActor)this;
1450
1451 changeSelectedStatus(timestep); 1516 changeSelectedStatus(timestep);
1452 1517
1453 m_taintadd = false; 1518 m_taintadd = false;
@@ -1455,9 +1520,8 @@ Console.WriteLine("changeadd 1");
1455 1520
1456 public void changemove(float timestep) 1521 public void changemove(float timestep)
1457 { 1522 {
1458 if (m_isphysical) 1523 if (IsPhysical)
1459 { 1524 {
1460
1461 if (!m_disabled && !m_taintremove && !childPrim) 1525 if (!m_disabled && !m_taintremove && !childPrim)
1462 { 1526 {
1463 if (Body == IntPtr.Zero) 1527 if (Body == IntPtr.Zero)
@@ -1789,7 +1853,7 @@ Console.WriteLine(" JointCreateFixed");
1789 { 1853 {
1790 // KF: If this is a root prim do BodySet 1854 // KF: If this is a root prim do BodySet
1791 d.BodySetQuaternion(Body, ref myrot); 1855 d.BodySetQuaternion(Body, ref myrot);
1792 if (m_isphysical) 1856 if (IsPhysical)
1793 { 1857 {
1794 if (!m_angularlock.ApproxEquals(Vector3.One, 0f)) 1858 if (!m_angularlock.ApproxEquals(Vector3.One, 0f))
1795 createAMotor(m_angularlock); 1859 createAMotor(m_angularlock);
@@ -1826,7 +1890,7 @@ Console.WriteLine(" JointCreateFixed");
1826 1890
1827 public void changePhysicsStatus(float timestep) 1891 public void changePhysicsStatus(float timestep)
1828 { 1892 {
1829 if (m_isphysical == true) 1893 if (IsPhysical)
1830 { 1894 {
1831 if (Body == IntPtr.Zero) 1895 if (Body == IntPtr.Zero)
1832 { 1896 {
@@ -1846,25 +1910,12 @@ Console.WriteLine(" JointCreateFixed");
1846 { 1910 {
1847 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim) 1911 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
1848 { 1912 {
1849 1913 RemoveGeom();
1850 1914
1851 if (prim_geom != IntPtr.Zero)
1852 {
1853 try
1854 {
1855 d.GeomDestroy(prim_geom);
1856 prim_geom = IntPtr.Zero;
1857 _mesh = null;
1858 }
1859 catch (System.AccessViolationException)
1860 {
1861 prim_geom = IntPtr.Zero;
1862 m_log.ErrorFormat("[PHYSICS]: PrimGeom dead for {0}", Name);
1863 }
1864 }
1865//Console.WriteLine("changePhysicsStatus for " + Name); 1915//Console.WriteLine("changePhysicsStatus for " + Name);
1866 changeadd(2f); 1916 changeadd(2f);
1867 } 1917 }
1918
1868 if (childPrim) 1919 if (childPrim)
1869 { 1920 {
1870 if (_parent != null) 1921 if (_parent != null)
@@ -1883,7 +1934,7 @@ Console.WriteLine(" JointCreateFixed");
1883 changeSelectedStatus(timestep); 1934 changeSelectedStatus(timestep);
1884 1935
1885 resetCollisionAccounting(); 1936 resetCollisionAccounting();
1886 m_taintPhysics = m_isphysical; 1937 m_taintPhysics = IsPhysical;
1887 } 1938 }
1888 1939
1889 public void changesize(float timestamp) 1940 public void changesize(float timestamp)
@@ -1892,18 +1943,10 @@ Console.WriteLine(" JointCreateFixed");
1892 m_log.DebugFormat("[ODE PRIM]: Called changesize"); 1943 m_log.DebugFormat("[ODE PRIM]: Called changesize");
1893#endif 1944#endif
1894 1945
1895 string oldname = _parent_scene.geom_name_map[prim_geom];
1896
1897 if (_size.X <= 0) _size.X = 0.01f; 1946 if (_size.X <= 0) _size.X = 0.01f;
1898 if (_size.Y <= 0) _size.Y = 0.01f; 1947 if (_size.Y <= 0) _size.Y = 0.01f;
1899 if (_size.Z <= 0) _size.Z = 0.01f; 1948 if (_size.Z <= 0) _size.Z = 0.01f;
1900 1949
1901 // Cleanup of old prim geometry
1902 if (_mesh != null)
1903 {
1904 // TODO: Cleanup meshing here
1905 }
1906
1907 //kill body to rebuild 1950 //kill body to rebuild
1908 if (IsPhysical && Body != IntPtr.Zero) 1951 if (IsPhysical && Body != IntPtr.Zero)
1909 { 1952 {
@@ -1927,10 +1970,12 @@ Console.WriteLine(" JointCreateFixed");
1927 d.SpaceRemove(m_targetSpace, prim_geom); 1970 d.SpaceRemove(m_targetSpace, prim_geom);
1928 } 1971 }
1929 1972
1930 d.GeomDestroy(prim_geom); 1973 RemoveGeom();
1931 prim_geom = IntPtr.Zero; 1974
1932 // we don't need to do space calculation because the client sends a position update also. 1975 // we don't need to do space calculation because the client sends a position update also.
1933 1976
1977 IMesh mesh = null;
1978
1934 // Construction of new prim 1979 // Construction of new prim
1935 if (_parent_scene.needsMeshing(_pbs)) 1980 if (_parent_scene.needsMeshing(_pbs))
1936 { 1981 {
@@ -1940,27 +1985,11 @@ Console.WriteLine(" JointCreateFixed");
1940 meshlod = _parent_scene.MeshSculptphysicalLOD; 1985 meshlod = _parent_scene.MeshSculptphysicalLOD;
1941 // Don't need to re-enable body.. it's done in SetMesh 1986 // Don't need to re-enable body.. it's done in SetMesh
1942 1987
1943 IMesh mesh = null;
1944
1945 if (_parent_scene.needsMeshing(_pbs)) 1988 if (_parent_scene.needsMeshing(_pbs))
1946 mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); 1989 mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, meshlod, IsPhysical);
1947
1948#if SPAM
1949Console.WriteLine("changesize 1");
1950#endif
1951 CreateGeom(m_targetSpace, mesh);
1952 }
1953 else
1954 {
1955 _mesh = null;
1956
1957#if SPAM
1958Console.WriteLine("changesize 2");
1959#endif
1960
1961 CreateGeom(m_targetSpace, _mesh);
1962 } 1990 }
1963 1991
1992 CreateGeom(m_targetSpace, mesh);
1964 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); 1993 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
1965 d.Quaternion myrot = new d.Quaternion(); 1994 d.Quaternion myrot = new d.Quaternion();
1966 myrot.X = _orientation.X; 1995 myrot.X = _orientation.X;
@@ -1978,8 +2007,6 @@ Console.WriteLine("changesize 2");
1978 d.BodyEnable(Body); 2007 d.BodyEnable(Body);
1979 } 2008 }
1980 2009
1981 _parent_scene.geom_name_map[prim_geom] = oldname;
1982
1983 changeSelectedStatus(timestamp); 2010 changeSelectedStatus(timestamp);
1984 if (childPrim) 2011 if (childPrim)
1985 { 2012 {
@@ -2013,8 +2040,6 @@ Console.WriteLine("changesize 2");
2013 2040
2014 public void changeshape(float timestamp) 2041 public void changeshape(float timestamp)
2015 { 2042 {
2016 string oldname = _parent_scene.geom_name_map[prim_geom];
2017
2018 // Cleanup of old prim geometry and Bodies 2043 // Cleanup of old prim geometry and Bodies
2019 if (IsPhysical && Body != IntPtr.Zero) 2044 if (IsPhysical && Body != IntPtr.Zero)
2020 { 2045 {
@@ -2031,23 +2056,17 @@ Console.WriteLine("changesize 2");
2031 disableBody(); 2056 disableBody();
2032 } 2057 }
2033 } 2058 }
2034 try
2035 {
2036 d.GeomDestroy(prim_geom);
2037 }
2038 catch (System.AccessViolationException)
2039 {
2040 prim_geom = IntPtr.Zero;
2041 m_log.ErrorFormat("[PHYSICS]: PrimGeom dead for {0}", Name);
2042 }
2043 2059
2044 prim_geom = IntPtr.Zero; 2060 RemoveGeom();
2061
2045 // we don't need to do space calculation because the client sends a position update also. 2062 // we don't need to do space calculation because the client sends a position update also.
2046 if (_size.X <= 0) _size.X = 0.01f; 2063 if (_size.X <= 0) _size.X = 0.01f;
2047 if (_size.Y <= 0) _size.Y = 0.01f; 2064 if (_size.Y <= 0) _size.Y = 0.01f;
2048 if (_size.Z <= 0) _size.Z = 0.01f; 2065 if (_size.Z <= 0) _size.Z = 0.01f;
2049 // Construction of new prim 2066 // Construction of new prim
2050 2067
2068 IMesh mesh = null;
2069
2051 if (_parent_scene.needsMeshing(_pbs)) 2070 if (_parent_scene.needsMeshing(_pbs))
2052 { 2071 {
2053 // Don't need to re-enable body.. it's done in CreateMesh 2072 // Don't need to re-enable body.. it's done in CreateMesh
@@ -2057,22 +2076,10 @@ Console.WriteLine("changesize 2");
2057 meshlod = _parent_scene.MeshSculptphysicalLOD; 2076 meshlod = _parent_scene.MeshSculptphysicalLOD;
2058 2077
2059 // createmesh returns null when it doesn't mesh. 2078 // createmesh returns null when it doesn't mesh.
2060 IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); 2079 mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, meshlod, IsPhysical);
2061#if SPAM
2062Console.WriteLine("changeshape needed meshing");
2063#endif
2064 CreateGeom(m_targetSpace, mesh);
2065 }
2066 else
2067 {
2068 _mesh = null;
2069
2070#if SPAM
2071Console.WriteLine("changeshape not need meshing");
2072#endif
2073 CreateGeom(m_targetSpace, null);
2074 } 2080 }
2075 2081
2082 CreateGeom(m_targetSpace, mesh);
2076 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); 2083 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
2077 d.Quaternion myrot = new d.Quaternion(); 2084 d.Quaternion myrot = new d.Quaternion();
2078 //myrot.W = _orientation.w; 2085 //myrot.W = _orientation.w;
@@ -2093,7 +2100,6 @@ Console.WriteLine("changeshape not need meshing");
2093 d.BodyEnable(Body); 2100 d.BodyEnable(Body);
2094 } 2101 }
2095 } 2102 }
2096 _parent_scene.geom_name_map[prim_geom] = oldname;
2097 2103
2098 changeSelectedStatus(timestamp); 2104 changeSelectedStatus(timestamp);
2099 if (childPrim) 2105 if (childPrim)
@@ -2216,16 +2222,6 @@ Console.WriteLine("changeshape not need meshing");
2216 m_taintVelocity = Vector3.Zero; 2222 m_taintVelocity = Vector3.Zero;
2217 } 2223 }
2218 2224
2219 public override bool IsPhysical
2220 {
2221 get { return m_isphysical; }
2222 set {
2223 m_isphysical = value;
2224 if (!m_isphysical) // Zero the remembered last velocity
2225 m_lastVelocity = Vector3.Zero;
2226 }
2227 }
2228
2229 public void setPrimForRemoval() 2225 public void setPrimForRemoval()
2230 { 2226 {
2231 m_taintremove = true; 2227 m_taintremove = true;
@@ -2404,7 +2400,7 @@ Console.WriteLine("changeshape not need meshing");
2404 { 2400 {
2405 get 2401 get
2406 { 2402 {
2407 if (!m_isphysical || Body == IntPtr.Zero) 2403 if (!IsPhysical || Body == IntPtr.Zero)
2408 return Vector3.Zero; 2404 return Vector3.Zero;
2409 2405
2410 return _torque; 2406 return _torque;
@@ -2986,12 +2982,12 @@ Console.WriteLine("changeshape not need meshing");
2986 public override void SubscribeEvents(int ms) 2982 public override void SubscribeEvents(int ms)
2987 { 2983 {
2988 m_eventsubscription = ms; 2984 m_eventsubscription = ms;
2989 _parent_scene.addCollisionEventReporting(this); 2985 _parent_scene.AddCollisionEventReporting(this);
2990 } 2986 }
2991 2987
2992 public override void UnSubscribeEvents() 2988 public override void UnSubscribeEvents()
2993 { 2989 {
2994 _parent_scene.remCollisionEventReporting(this); 2990 _parent_scene.RemoveCollisionEventReporting(this);
2995 m_eventsubscription = 0; 2991 m_eventsubscription = 0;
2996 } 2992 }
2997 2993
@@ -2999,6 +2995,7 @@ Console.WriteLine("changeshape not need meshing");
2999 { 2995 {
3000 if (CollisionEventsThisFrame == null) 2996 if (CollisionEventsThisFrame == null)
3001 CollisionEventsThisFrame = new CollisionEventUpdate(); 2997 CollisionEventsThisFrame = new CollisionEventUpdate();
2998
3002 CollisionEventsThisFrame.addCollider(CollidedWith, contact); 2999 CollisionEventsThisFrame.addCollider(CollidedWith, contact);
3003 } 3000 }
3004 3001