aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/PhysicsModules')
-rwxr-xr-xOpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs8
-rw-r--r--OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs45
-rwxr-xr-xOpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs34
-rw-r--r--OpenSim/Region/PhysicsModules/BulletS/BSPrim.cs11
-rw-r--r--OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs40
-rw-r--r--OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs9
-rw-r--r--OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs17
-rw-r--r--OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs276
8 files changed, 240 insertions, 200 deletions
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs b/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs
index 79ee00f..40c6b98 100755
--- a/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs
+++ b/OpenSim/Region/PhysicsModules/BulletS/BSActorAvatarMove.cs
@@ -108,10 +108,6 @@ public class BSActorAvatarMove : BSActor
108 { 108 {
109 if (m_velocityMotor != null) 109 if (m_velocityMotor != null)
110 { 110 {
111// if (targ == OMV.Vector3.Zero)
112// Util.PrintCallStack();
113//
114// Console.WriteLine("SetVelocityAndTarget, {0} {1}", vel, targ);
115 m_velocityMotor.Reset(); 111 m_velocityMotor.Reset();
116 m_velocityMotor.SetTarget(targ); 112 m_velocityMotor.SetTarget(targ);
117 m_velocityMotor.SetCurrent(vel); 113 m_velocityMotor.SetCurrent(vel);
@@ -128,7 +124,7 @@ public class BSActorAvatarMove : BSActor
128 m_waitingForLowVelocityForStationary = true; 124 m_waitingForLowVelocityForStationary = true;
129 } 125 }
130 126
131 // If a movement motor has not been created, create one and start the hovering. 127 // If a movement motor has not been created, create one and start the movement
132 private void ActivateAvatarMove() 128 private void ActivateAvatarMove()
133 { 129 {
134 if (m_velocityMotor == null) 130 if (m_velocityMotor == null)
@@ -161,7 +157,7 @@ public class BSActorAvatarMove : BSActor
161 } 157 }
162 } 158 }
163 159
164 // Called just before the simulation step. Update the vertical position for hoverness. 160 // Called just before the simulation step.
165 private void Mover(float timeStep) 161 private void Mover(float timeStep)
166 { 162 {
167 // Don't do movement while the object is selected. 163 // Don't do movement while the object is selected.
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs b/OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs
index 757f06c..6322695 100644
--- a/OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs
+++ b/OpenSim/Region/PhysicsModules/BulletS/BSCharacter.cs
@@ -449,6 +449,7 @@ public sealed class BSCharacter : BSPhysObject
449 public override OMV.Vector3 GeometricCenter { get { return OMV.Vector3.Zero; } } 449 public override OMV.Vector3 GeometricCenter { get { return OMV.Vector3.Zero; } }
450 public override OMV.Vector3 CenterOfMass { get { return OMV.Vector3.Zero; } } 450 public override OMV.Vector3 CenterOfMass { get { return OMV.Vector3.Zero; } }
451 451
452 // PhysicsActor.TargetVelocity
452 // Sets the target in the motor. This starts the changing of the avatar's velocity. 453 // Sets the target in the motor. This starts the changing of the avatar's velocity.
453 public override OMV.Vector3 TargetVelocity 454 public override OMV.Vector3 TargetVelocity
454 { 455 {
@@ -459,7 +460,7 @@ public sealed class BSCharacter : BSPhysObject
459 set 460 set
460 { 461 {
461 DetailLog("{0},BSCharacter.setTargetVelocity,call,vel={1}", LocalID, value); 462 DetailLog("{0},BSCharacter.setTargetVelocity,call,vel={1}", LocalID, value);
462 m_targetVelocity = value; 463 base.m_targetVelocity = value;
463 OMV.Vector3 targetVel = value; 464 OMV.Vector3 targetVel = value;
464 if (_setAlwaysRun && !_flying) 465 if (_setAlwaysRun && !_flying)
465 targetVel *= new OMV.Vector3(BSParam.AvatarAlwaysRunFactor, BSParam.AvatarAlwaysRunFactor, 1f); 466 targetVel *= new OMV.Vector3(BSParam.AvatarAlwaysRunFactor, BSParam.AvatarAlwaysRunFactor, 1f);
@@ -472,46 +473,38 @@ public sealed class BSCharacter : BSPhysObject
472 public override OMV.Vector3 Velocity { 473 public override OMV.Vector3 Velocity {
473 get { return RawVelocity; } 474 get { return RawVelocity; }
474 set { 475 set {
475 RawVelocity = value; 476 if (m_moveActor != null)
476 OMV.Vector3 vel = RawVelocity;
477
478 DetailLog("{0}: set Velocity = {1}", LocalID, value);
479
480 PhysScene.TaintedObject(LocalID, "BSCharacter.setVelocity", delegate()
481 { 477 {
482 if (m_moveActor != null) 478 // m_moveActor.SetVelocityAndTarget(OMV.Vector3.Zero, OMV.Vector3.Zero, false /* inTaintTime */);
483 m_moveActor.SetVelocityAndTarget(vel, vel, true /* inTaintTime */); 479 m_moveActor.SetVelocityAndTarget(RawVelocity, RawVelocity, false /* inTaintTime */);
480 }
481 base.Velocity = value;
482 }
483 }
484 484
485 DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, vel); 485 // SetMomentum just sets the velocity without a target. We need to stop the movement actor if a character.
486 ForceVelocity = vel; 486 public override void SetMomentum(OMV.Vector3 momentum)
487 }); 487 {
488 if (m_moveActor != null)
489 {
490 // m_moveActor.SetVelocityAndTarget(OMV.Vector3.Zero, OMV.Vector3.Zero, false /* inTaintTime */);
491 m_moveActor.SetVelocityAndTarget(RawVelocity, RawVelocity, false /* inTaintTime */);
488 } 492 }
493 base.SetMomentum(momentum);
489 } 494 }
490 495
491 public override OMV.Vector3 ForceVelocity { 496 public override OMV.Vector3 ForceVelocity {
492 get { return RawVelocity; } 497 get { return RawVelocity; }
493 set { 498 set {
494 PhysScene.AssertInTaintTime("BSCharacter.ForceVelocity"); 499 PhysScene.AssertInTaintTime("BSCharacter.ForceVelocity");
495// Util.PrintCallStack(); 500 DetailLog("{0}: BSCharacter.ForceVelocity.set = {1}", LocalID, value);
496 DetailLog("{0}: set ForceVelocity = {1}", LocalID, value);
497 501
498 RawVelocity = value; 502 RawVelocity = Util.ClampV(value, BSParam.MaxLinearVelocity);
499 PhysScene.PE.SetLinearVelocity(PhysBody, RawVelocity); 503 PhysScene.PE.SetLinearVelocity(PhysBody, RawVelocity);
500 PhysScene.PE.Activate(PhysBody, true); 504 PhysScene.PE.Activate(PhysBody, true);
501 } 505 }
502 } 506 }
503 507
504 // SetMomentum just sets the velocity without a target. We need to stop the movement actor if a character.
505 public override void SetMomentum(OMV.Vector3 momentum)
506 {
507 if (m_moveActor != null)
508 {
509 m_moveActor.SetVelocityAndTarget(OMV.Vector3.Zero, OMV.Vector3.Zero, false /* inTaintTime */);
510 }
511 base.SetMomentum(momentum);
512 }
513
514
515 public override OMV.Vector3 Torque { 508 public override OMV.Vector3 Torque {
516 get { return RawTorque; } 509 get { return RawTorque; }
517 set { RawTorque = value; 510 set { RawTorque = value;
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs b/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs
index 3682455..a846869 100755
--- a/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs
+++ b/OpenSim/Region/PhysicsModules/BulletS/BSPhysObject.cs
@@ -230,15 +230,22 @@ public abstract class BSPhysObject : PhysicsActor
230 // Update the physical location and motion of the object. Called with data from Bullet. 230 // Update the physical location and motion of the object. Called with data from Bullet.
231 public abstract void UpdateProperties(EntityProperties entprop); 231 public abstract void UpdateProperties(EntityProperties entprop);
232 232
233 // The position value as known by BulletSim. Does not effect the physics engine.
233 public virtual OMV.Vector3 RawPosition { get; set; } 234 public virtual OMV.Vector3 RawPosition { get; set; }
235 // Set position in BulletSim and the physics engined to a value immediately. Must be called at taint time.
234 public abstract OMV.Vector3 ForcePosition { get; set; } 236 public abstract OMV.Vector3 ForcePosition { get; set; }
235 237
238 // The orientation value as known by BulletSim. Does not effect the physics engine.
236 public virtual OMV.Quaternion RawOrientation { get; set; } 239 public virtual OMV.Quaternion RawOrientation { get; set; }
240 // Set orientation in BulletSim and the physics engine to a value immediately. Must be called at taint time.
237 public abstract OMV.Quaternion ForceOrientation { get; set; } 241 public abstract OMV.Quaternion ForceOrientation { get; set; }
238 242
243 // The velocity value as known by BulletSim. Does not effect the physics engine.
239 public virtual OMV.Vector3 RawVelocity { get; set; } 244 public virtual OMV.Vector3 RawVelocity { get; set; }
245 // Set velocity in BulletSim and the physics engined to a value immediately. Must be called at taint time.
240 public abstract OMV.Vector3 ForceVelocity { get; set; } 246 public abstract OMV.Vector3 ForceVelocity { get; set; }
241 247
248 // The rotational velocity value as known by BulletSim. Does not effect the physics engine.
242 public OMV.Vector3 RawRotationalVelocity { get; set; } 249 public OMV.Vector3 RawRotationalVelocity { get; set; }
243 250
244 // RawForce is a constant force applied to object (see Force { set; } ) 251 // RawForce is a constant force applied to object (see Force { set; } )
@@ -252,17 +259,28 @@ public abstract class BSPhysObject : PhysicsActor
252 public abstract void AddAngularForce(bool inTaintTime, OMV.Vector3 force); 259 public abstract void AddAngularForce(bool inTaintTime, OMV.Vector3 force);
253 public abstract void AddForce(bool inTaintTime, OMV.Vector3 force); 260 public abstract void AddForce(bool inTaintTime, OMV.Vector3 force);
254 261
262 // PhysicsActor.Velocity
263 public override OMV.Vector3 Velocity
264 {
265 get { return RawVelocity; }
266 set
267 {
268 // This sets the velocity now. BSCharacter will override to clear target velocity
269 // before calling this.
270 RawVelocity = value;
271 PhysScene.TaintedObject(LocalID, TypeName + ".SetVelocity", delegate () {
272 // DetailLog("{0},BSPhysObject.Velocity.set,vel={1}", LocalID, RawVelocity);
273 ForceVelocity = RawVelocity;
274 });
275 }
276 }
277
255 // PhysicsActor.SetMomentum 278 // PhysicsActor.SetMomentum
256 // All the physics engined use this as a way of forcing the velocity to something. 279 // All the physics engines use this as a way of forcing the velocity to something.
280 // BSCharacter overrides this so it can set the target velocity to zero before calling this.
257 public override void SetMomentum(OMV.Vector3 momentum) 281 public override void SetMomentum(OMV.Vector3 momentum)
258 { 282 {
259 // This doesn't just set Velocity=momentum because velocity is ramped up to (see MoveActor) 283 this.Velocity = momentum;
260 RawVelocity = momentum;
261 PhysScene.TaintedObject(LocalID, TypeName + ".SetMomentum", delegate()
262 {
263 // DetailLog("{0},BSPrim.SetMomentum,taint,vel={1}", LocalID, RawVelocity);
264 ForceVelocity = RawVelocity;
265 });
266 } 284 }
267 285
268 public override OMV.Vector3 RotationalVelocity { 286 public override OMV.Vector3 RotationalVelocity {
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSPrim.cs b/OpenSim/Region/PhysicsModules/BulletS/BSPrim.cs
index 78a617d..db2b9db 100644
--- a/OpenSim/Region/PhysicsModules/BulletS/BSPrim.cs
+++ b/OpenSim/Region/PhysicsModules/BulletS/BSPrim.cs
@@ -787,17 +787,6 @@ public class BSPrim : BSPhysObject
787 } 787 }
788 } 788 }
789 } 789 }
790 public override OMV.Vector3 Velocity {
791 get { return RawVelocity; }
792 set {
793 RawVelocity = value;
794 PhysScene.TaintedObject(LocalID, "BSPrim.setVelocity", delegate()
795 {
796 // DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, RawVelocity);
797 ForceVelocity = RawVelocity;
798 });
799 }
800 }
801 public override OMV.Vector3 ForceVelocity { 790 public override OMV.Vector3 ForceVelocity {
802 get { return RawVelocity; } 791 get { return RawVelocity; }
803 set { 792 set {
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs b/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs
index 9640e91..f7e1044 100644
--- a/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs
+++ b/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs
@@ -632,6 +632,25 @@ namespace OpenSim.Region.PhysicsModule.ubOde
632 } 632 }
633 } 633 }
634 634
635 public override Vector3 TargetVelocity
636 {
637 get
638 {
639 return m_targetVelocity;
640 }
641 set
642 {
643 if (value.IsFinite())
644 {
645 AddChange(changes.TargetVelocity, value);
646 }
647 else
648 {
649 m_log.Warn("[PHYSICS]: Got a NaN velocity from Scene in a Character");
650 }
651 }
652 }
653
635 public override Vector3 Torque 654 public override Vector3 Torque
636 { 655 {
637 get { return Vector3.Zero; } 656 get { return Vector3.Zero; }
@@ -689,7 +708,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
689 } 708 }
690 else 709 else
691 { 710 {
692 AddChange(changes.Velocity, force); 711 AddChange(changes.TargetVelocity, force);
693 } 712 }
694 } 713 }
695 else 714 else
@@ -1671,16 +1690,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1671 { 1690 {
1672 AvatarGeomAndBodyDestroy(); 1691 AvatarGeomAndBodyDestroy();
1673 1692
1674
1675 float oldsz = m_size.Z; 1693 float oldsz = m_size.Z;
1676 m_size = pSize; 1694 m_size = pSize;
1677 1695
1678
1679 AvatarGeomAndBodyCreation(_position.X, _position.Y, 1696 AvatarGeomAndBodyCreation(_position.X, _position.Y,
1680 _position.Z + (m_size.Z - oldsz) * 0.5f); 1697 _position.Z + (m_size.Z - oldsz) * 0.5f);
1681 1698
1682 Velocity = Vector3.Zero; 1699// Velocity = Vector3.Zero;
1683 1700 m_targetVelocity = Vector3.Zero;
1684 1701
1685 _parent_scene.actor_name_map[collider] = (PhysicsActor)this; 1702 _parent_scene.actor_name_map[collider] = (PhysicsActor)this;
1686 _parent_scene.actor_name_map[capsule] = (PhysicsActor)this; 1703 _parent_scene.actor_name_map[capsule] = (PhysicsActor)this;
@@ -1739,6 +1756,15 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1739 1756
1740 private void changeVelocity(Vector3 newVel) 1757 private void changeVelocity(Vector3 newVel)
1741 { 1758 {
1759 _velocity = newVel;
1760 setFreeMove();
1761
1762 if (Body != IntPtr.Zero)
1763 d.BodySetLinearVel(Body, newVel.X, newVel.Y, newVel.Z);
1764 }
1765
1766 private void changeTargetVelocity(Vector3 newVel)
1767 {
1742 m_pidControllerActive = true; 1768 m_pidControllerActive = true;
1743 m_freemove = false; 1769 m_freemove = false;
1744 _target_velocity = newVel; 1770 _target_velocity = newVel;
@@ -1881,6 +1907,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1881 changeVelocity((Vector3)arg); 1907 changeVelocity((Vector3)arg);
1882 break; 1908 break;
1883 1909
1910 case changes.TargetVelocity:
1911 changeTargetVelocity((Vector3)arg);
1912 break;
1913
1884 // case changes.Acceleration: 1914 // case changes.Acceleration:
1885 // changeacceleration((Vector3)arg); 1915 // changeacceleration((Vector3)arg);
1886 // break; 1916 // break;
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs
index 4adf87e..60b24ec 100644
--- a/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs
+++ b/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs
@@ -1157,6 +1157,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1157 1157
1158 m_building = true; // control must set this to false when done 1158 m_building = true; // control must set this to false when done
1159 1159
1160 AddChange(changes.Add, null);
1161
1160 // get basic mass parameters 1162 // get basic mass parameters
1161 ODEPhysRepData repData = _parent_scene.m_meshWorker.NewActorPhysRep(this, _pbs, _size, m_shapetype); 1163 ODEPhysRepData repData = _parent_scene.m_meshWorker.NewActorPhysRep(this, _pbs, _size, m_shapetype);
1162 1164
@@ -1165,8 +1167,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1165 m_OBBOffset = repData.OBBOffset; 1167 m_OBBOffset = repData.OBBOffset;
1166 1168
1167 UpdatePrimBodyData(); 1169 UpdatePrimBodyData();
1168
1169 AddChange(changes.Add, null);
1170 } 1170 }
1171 1171
1172 private void resetCollisionAccounting() 1172 private void resetCollisionAccounting()
@@ -3805,6 +3805,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
3805 changevelocity((Vector3)arg); 3805 changevelocity((Vector3)arg);
3806 break; 3806 break;
3807 3807
3808 case changes.TargetVelocity:
3809 break;
3810
3808// case changes.Acceleration: 3811// case changes.Acceleration:
3809// changeacceleration((Vector3)arg); 3812// changeacceleration((Vector3)arg);
3810// break; 3813// break;
@@ -3933,8 +3936,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
3933 donullchange(); 3936 donullchange();
3934 break; 3937 break;
3935 3938
3936
3937
3938 default: 3939 default:
3939 donullchange(); 3940 donullchange();
3940 break; 3941 break;
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
index e6aa7ef..f642699 100644
--- a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
+++ b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
@@ -112,6 +112,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
112 OriOffset, // not in use 112 OriOffset, // not in use
113 // arg Vector3 new position in local coords. Changes prim position in object 113 // arg Vector3 new position in local coords. Changes prim position in object
114 Velocity, 114 Velocity,
115 TargetVelocity,
115 AngVelocity, 116 AngVelocity,
116 Acceleration, 117 Acceleration,
117 Force, 118 Force,
@@ -1220,8 +1221,11 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1220 /// <param name="obj"></param> 1221 /// <param name="obj"></param>
1221 public void RemoveCollisionEventReporting(PhysicsActor obj) 1222 public void RemoveCollisionEventReporting(PhysicsActor obj)
1222 { 1223 {
1223 if (_collisionEventPrim.Contains(obj) && !_collisionEventPrimRemove.Contains(obj)) 1224 lock(_collisionEventPrimRemove)
1224 _collisionEventPrimRemove.Add(obj); 1225 {
1226 if (_collisionEventPrim.Contains(obj) && !_collisionEventPrimRemove.Contains(obj))
1227 _collisionEventPrimRemove.Add(obj);
1228 }
1225 } 1229 }
1226 1230
1227 public override float TimeDilation 1231 public override float TimeDilation
@@ -1758,10 +1762,13 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1758 prm.SleeperAddCollisionEvents(); 1762 prm.SleeperAddCollisionEvents();
1759 sleepers.Clear(); 1763 sleepers.Clear();
1760 1764
1761 foreach (PhysicsActor obj in _collisionEventPrimRemove) 1765 lock(_collisionEventPrimRemove)
1762 _collisionEventPrim.Remove(obj); 1766 {
1767 foreach (PhysicsActor obj in _collisionEventPrimRemove)
1768 _collisionEventPrim.Remove(obj);
1763 1769
1764 _collisionEventPrimRemove.Clear(); 1770 _collisionEventPrimRemove.Clear();
1771 }
1765 1772
1766 // do a ode simulation step 1773 // do a ode simulation step
1767 d.WorldQuickStep(world, ODE_STEPSIZE); 1774 d.WorldQuickStep(world, ODE_STEPSIZE);
diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs
index bcd1530..ca94034 100644
--- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs
+++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs
@@ -395,6 +395,10 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
395 { 395 {
396// m_log.DebugFormat("[MESH]: experimental mesh proxy generation for {0}", primName); 396// m_log.DebugFormat("[MESH]: experimental mesh proxy generation for {0}", primName);
397 397
398
399 // for ubOde we have a diferent mesh use priority
400 // priority is to use full mesh then decomposition
401 // SL does the oposite
398 bool usemesh = false; 402 bool usemesh = false;
399 403
400 coords = new List<Coord>(); 404 coords = new List<Coord>();
@@ -443,16 +447,10 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
443 447
444 if (physicsParms != null) 448 if (physicsParms != null)
445 usemesh = true; 449 usemesh = true;
446 else
447 {
448 m_log.WarnFormat("[MESH]: Data for PRIM shape type not found for prim {0}",primName);
449 return false;
450 }
451 } 450 }
452 451
453 if(!usemesh && (map.ContainsKey("physics_convex"))) 452 if(!usemesh && (map.ContainsKey("physics_convex")))
454 physicsParms = (OSDMap)map["physics_convex"]; 453 physicsParms = (OSDMap)map["physics_convex"];
455
456 454
457 if (physicsParms == null) 455 if (physicsParms == null)
458 { 456 {
@@ -555,160 +553,168 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
555 range = range - min; 553 range = range - min;
556 range *= invMaxU16; 554 range *= invMaxU16;
557 555
558 if (!convex && cmap.ContainsKey("HullList") && cmap.ContainsKey("Positions")) 556 if(!convex)
559 { 557 {
560 List<int> hsizes = new List<int>(); 558 // if mesh data not present and not convex then we need convex decomposition data
561 int totalpoints = 0; 559 if (cmap.ContainsKey("HullList") && cmap.ContainsKey("Positions"))
562 data = cmap["HullList"].AsBinary();
563 for (i = 0; i < data.Length; i++)
564 { 560 {
565 t1 = data[i]; 561 List<int> hsizes = new List<int>();
566 if (t1 == 0) 562 int totalpoints = 0;
567 t1 = 256; 563 data = cmap["HullList"].AsBinary();
568 totalpoints += t1; 564 for (i = 0; i < data.Length; i++)
569 hsizes.Add(t1); 565 {
570 } 566 t1 = data[i];
567 if (t1 == 0)
568 t1 = 256;
569 totalpoints += t1;
570 hsizes.Add(t1);
571 }
571 572
572 data = cmap["Positions"].AsBinary(); 573 data = cmap["Positions"].AsBinary();
573 int ptr = 0; 574 int ptr = 0;
574 int vertsoffset = 0; 575 int vertsoffset = 0;
575 576
576 if (totalpoints == data.Length / 6) // 2 bytes per coord, 3 coords per point 577 if (totalpoints == data.Length / 6) // 2 bytes per coord, 3 coords per point
577 {
578 foreach (int hullsize in hsizes)
579 { 578 {
580 for (i = 0; i < hullsize; i++ ) 579 foreach (int hullsize in hsizes)
581 {
582 t1 = data[ptr++];
583 t1 += data[ptr++] << 8;
584 t2 = data[ptr++];
585 t2 += data[ptr++] << 8;
586 t3 = data[ptr++];
587 t3 += data[ptr++] << 8;
588
589 f3 = new float3((t1 * range.X + min.X),
590 (t2 * range.Y + min.Y),
591 (t3 * range.Z + min.Z));
592 vs.Add(f3);
593 }
594
595 if(hullsize <3)
596 { 580 {
597 vs.Clear(); 581 for (i = 0; i < hullsize; i++ )
598 continue; 582 {
599 } 583 t1 = data[ptr++];
584 t1 += data[ptr++] << 8;
585 t2 = data[ptr++];
586 t2 += data[ptr++] << 8;
587 t3 = data[ptr++];
588 t3 += data[ptr++] << 8;
589
590 f3 = new float3((t1 * range.X + min.X),
591 (t2 * range.Y + min.Y),
592 (t3 * range.Z + min.Z));
593 vs.Add(f3);
594 }
600 595
601 if (hullsize <5) 596 if(hullsize <3)
602 {
603 foreach (float3 point in vs)
604 { 597 {
605 c.X = point.x; 598 vs.Clear();
606 c.Y = point.y; 599 continue;
607 c.Z = point.z;
608 coords.Add(c);
609 } 600 }
610 f = new Face(vertsoffset, vertsoffset + 1, vertsoffset + 2);
611 faces.Add(f);
612 601
613 if (hullsize == 4) 602 if (hullsize <5)
614 { 603 {
615 // not sure about orientation.. 604 foreach (float3 point in vs)
616 f = new Face(vertsoffset, vertsoffset + 2, vertsoffset + 3); 605 {
617 faces.Add(f); 606 c.X = point.x;
618 f = new Face(vertsoffset, vertsoffset + 3, vertsoffset + 1); 607 c.Y = point.y;
619 faces.Add(f); 608 c.Z = point.z;
620 f = new Face(vertsoffset + 3, vertsoffset + 2, vertsoffset + 1); 609 coords.Add(c);
610 }
611 f = new Face(vertsoffset, vertsoffset + 1, vertsoffset + 2);
621 faces.Add(f); 612 faces.Add(f);
613
614 if (hullsize == 4)
615 {
616 // not sure about orientation..
617 f = new Face(vertsoffset, vertsoffset + 2, vertsoffset + 3);
618 faces.Add(f);
619 f = new Face(vertsoffset, vertsoffset + 3, vertsoffset + 1);
620 faces.Add(f);
621 f = new Face(vertsoffset + 3, vertsoffset + 2, vertsoffset + 1);
622 faces.Add(f);
623 }
624 vertsoffset += vs.Count;
625 vs.Clear();
626 continue;
627 }
628 /*
629 if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f))
630 {
631 vs.Clear();
632 continue;
622 } 633 }
623 vertsoffset += vs.Count;
624 vs.Clear();
625 continue;
626 }
627/*
628 if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f))
629 {
630 vs.Clear();
631 continue;
632 }
633 634
634 nverts = hullr.Vertices.Count; 635 nverts = hullr.Vertices.Count;
635 nindexs = hullr.Indices.Count; 636 nindexs = hullr.Indices.Count;
636 637
637 if (nindexs % 3 != 0) 638 if (nindexs % 3 != 0)
638 { 639 {
639 vs.Clear(); 640 vs.Clear();
640 continue; 641 continue;
641 } 642 }
642 643
643 for (i = 0; i < nverts; i++) 644 for (i = 0; i < nverts; i++)
644 { 645 {
645 c.X = hullr.Vertices[i].x; 646 c.X = hullr.Vertices[i].x;
646 c.Y = hullr.Vertices[i].y; 647 c.Y = hullr.Vertices[i].y;
647 c.Z = hullr.Vertices[i].z; 648 c.Z = hullr.Vertices[i].z;
648 coords.Add(c); 649 coords.Add(c);
649 } 650 }
650 651
651 for (i = 0; i < nindexs; i += 3) 652 for (i = 0; i < nindexs; i += 3)
652 { 653 {
653 t1 = hullr.Indices[i]; 654 t1 = hullr.Indices[i];
654 if (t1 > nverts) 655 if (t1 > nverts)
655 break; 656 break;
656 t2 = hullr.Indices[i + 1]; 657 t2 = hullr.Indices[i + 1];
657 if (t2 > nverts) 658 if (t2 > nverts)
658 break; 659 break;
659 t3 = hullr.Indices[i + 2]; 660 t3 = hullr.Indices[i + 2];
660 if (t3 > nverts) 661 if (t3 > nverts)
661 break; 662 break;
662 f = new Face(vertsoffset + t1, vertsoffset + t2, vertsoffset + t3); 663 f = new Face(vertsoffset + t1, vertsoffset + t2, vertsoffset + t3);
663 faces.Add(f); 664 faces.Add(f);
664 } 665 }
665*/ 666 */
666 List<int> indices; 667 List<int> indices;
667 if (!HullUtils.ComputeHull(vs, out indices)) 668 if (!HullUtils.ComputeHull(vs, out indices))
668 { 669 {
669 vs.Clear(); 670 vs.Clear();
670 continue; 671 continue;
671 } 672 }
672 673
673 nverts = vs.Count; 674 nverts = vs.Count;
674 nindexs = indices.Count; 675 nindexs = indices.Count;
675 676
676 if (nindexs % 3 != 0) 677 if (nindexs % 3 != 0)
677 { 678 {
678 vs.Clear(); 679 vs.Clear();
679 continue; 680 continue;
680 } 681 }
681 682
682 for (i = 0; i < nverts; i++) 683 for (i = 0; i < nverts; i++)
683 { 684 {
684 c.X = vs[i].x; 685 c.X = vs[i].x;
685 c.Y = vs[i].y; 686 c.Y = vs[i].y;
686 c.Z = vs[i].z; 687 c.Z = vs[i].z;
687 coords.Add(c); 688 coords.Add(c);
688 } 689 }
689 690
690 for (i = 0; i < nindexs; i += 3) 691 for (i = 0; i < nindexs; i += 3)
691 { 692 {
692 t1 = indices[i]; 693 t1 = indices[i];
693 if (t1 > nverts) 694 if (t1 > nverts)
694 break; 695 break;
695 t2 = indices[i + 1]; 696 t2 = indices[i + 1];
696 if (t2 > nverts) 697 if (t2 > nverts)
697 break; 698 break;
698 t3 = indices[i + 2]; 699 t3 = indices[i + 2];
699 if (t3 > nverts) 700 if (t3 > nverts)
700 break; 701 break;
701 f = new Face(vertsoffset + t1, vertsoffset + t2, vertsoffset + t3); 702 f = new Face(vertsoffset + t1, vertsoffset + t2, vertsoffset + t3);
702 faces.Add(f); 703 faces.Add(f);
704 }
705 vertsoffset += nverts;
706 vs.Clear();
703 } 707 }
704 vertsoffset += nverts;
705 vs.Clear();
706 } 708 }
709 if (coords.Count > 0 && faces.Count > 0)
710 return true;
711 }
712 else
713 {
714 // if neither mesh or decomposition present, warn and use convex
715 m_log.WarnFormat("[MESH]: Data for PRIM shape type ( mesh or decomposition) not found for prim {0}",primName);
707 } 716 }
708 if (coords.Count > 0 && faces.Count > 0)
709 return true;
710 } 717 }
711
712 vs.Clear(); 718 vs.Clear();
713 719
714 if (cmap.ContainsKey("BoundingVerts")) 720 if (cmap.ContainsKey("BoundingVerts"))