Physical phantoms testable with chOde. Volume detection was changed and also needs testing. Started making it more independent of phantom acording to new sl. ** 99.999...% UNTESTED ***

avinationmerge
UbitUmarov 2012-03-11 11:01:38 +00:00
parent dab7e03584
commit 7832889437
1 changed files with 159 additions and 152 deletions

View File

@ -1577,16 +1577,12 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary> /// </summary>
/// <param name="rootObjectFlags"></param> /// <param name="rootObjectFlags"></param>
/// <param name="VolumeDetectActive"></param> /// <param name="VolumeDetectActive"></param>
// public void ApplyPhysics(uint rootObjectFlags, bool VolumeDetectActive)
public void ApplyPhysics(uint rootObjectFlags, bool VolumeDetectActive, bool building) public void ApplyPhysics(uint rootObjectFlags, bool VolumeDetectActive, bool building)
{ {
if (!ParentGroup.Scene.CollidablePrims) if (!ParentGroup.Scene.CollidablePrims)
return; return;
// m_log.DebugFormat(
// "[SCENE OBJECT PART]: Applying physics to {0} {1}, m_physicalPrim {2}",
// Name, LocalId, UUID, m_physicalPrim);
bool isPhysical = (rootObjectFlags & (uint) PrimFlags.Physics) != 0; bool isPhysical = (rootObjectFlags & (uint) PrimFlags.Physics) != 0;
bool isPhantom = (rootObjectFlags & (uint) PrimFlags.Phantom) != 0; bool isPhantom = (rootObjectFlags & (uint) PrimFlags.Phantom) != 0;
@ -1597,15 +1593,16 @@ namespace OpenSim.Region.Framework.Scenes
else else
{ {
// Special case for VolumeDetection: If VolumeDetection is set, the phantom flag is locally ignored // Special case for VolumeDetection: If VolumeDetection is set, the phantom flag is locally ignored
if (VolumeDetectActive) // if (VolumeDetectActive)
isPhantom = false; // isPhantom = false;
// Added clarification.. since A rigid body is an object that you can kick around, etc. // Added clarification.. since A rigid body is an object that you can kick around, etc.
bool RigidBody = isPhysical && !isPhantom; // bool RigidBody = isPhysical && !isPhantom;
// The only time the physics scene shouldn't know about the prim is if it's phantom or an attachment, which is phantom by definition // The only time the physics scene shouldn't know about the prim is if it's phantom or an attachment, which is phantom by definition
// or flexible // or flexible
if (!isPhantom && !ParentGroup.IsAttachment && !(Shape.PathCurve == (byte)Extrusion.Flexible)) // if (!isPhantom && !ParentGroup.IsAttachment && !(Shape.PathCurve == (byte)Extrusion.Flexible))
if ((!isPhantom || isPhysical || VolumeDetectActive) && !ParentGroup.IsAttachment && !(Shape.PathCurve == (byte)Extrusion.Flexible))
{ {
Vector3 velocity = Velocity; Vector3 velocity = Velocity;
Vector3 rotationalVelocity = AngularVelocity; Vector3 rotationalVelocity = AngularVelocity;
@ -1616,9 +1613,9 @@ namespace OpenSim.Region.Framework.Scenes
Shape, Shape,
AbsolutePosition, AbsolutePosition,
Scale, Scale,
// RotationOffset, GetWorldRotation(),
GetWorldRotation(), // physics wants world rotation isPhysical,
RigidBody, isPhantom,
m_localId); m_localId);
} }
catch catch
@ -1637,8 +1634,9 @@ namespace OpenSim.Region.Framework.Scenes
if (m_vehicle != null && LocalId == ParentGroup.RootPart.LocalId) if (m_vehicle != null && LocalId == ParentGroup.RootPart.LocalId)
m_vehicle.SetVehicle(PhysActor); m_vehicle.SetVehicle(PhysActor);
DoPhysicsPropertyUpdate(RigidBody, true); DoPhysicsPropertyUpdate(isPhysical, true);
PhysActor.SetVolumeDetect(VolumeDetectActive ? 1 : 0); if(VolumeDetectActive) // change if not the default only
PhysActor.SetVolumeDetect(1);
if (!building) if (!building)
PhysActor.Building = false; PhysActor.Building = false;
@ -1888,9 +1886,10 @@ namespace OpenSim.Region.Framework.Scenes
{ {
if (UsePhysics != PhysActor.IsPhysical || isNew) if (UsePhysics != PhysActor.IsPhysical || isNew)
{ {
if (PhysActor.IsPhysical) // implies UsePhysics==false for this block if (PhysActor.IsPhysical)
{
if (!isNew) // implies UsePhysics==false for this block
{ {
if (!isNew)
ParentGroup.Scene.RemovePhysicalPrim(1); ParentGroup.Scene.RemovePhysicalPrim(1);
Velocity = new Vector3(0, 0, 0); Velocity = new Vector3(0, 0, 0);
@ -1898,42 +1897,27 @@ namespace OpenSim.Region.Framework.Scenes
if (ParentGroup.RootPart == this) if (ParentGroup.RootPart == this)
AngularVelocity = new Vector3(0, 0, 0); AngularVelocity = new Vector3(0, 0, 0);
if (PhysActor.Phantom)
{
RemoveFromPhysics();
return;
}
PhysActor.IsPhysical = UsePhysics;
PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate; PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
PhysActor.OnOutOfBounds -= PhysicsOutOfBounds; PhysActor.OnOutOfBounds -= PhysicsOutOfBounds;
PhysActor.delink(); PhysActor.delink();
if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints && (!isNew))
{ {
// destroy all joints connected to this now deactivated body // destroy all joints connected to this now deactivated body
ParentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(PhysActor); ParentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(PhysActor);
} }
}
// stop client-side interpolation of all joint proxy objects that have just been deleted
// this is done because RemoveAllJointsConnectedToActor invokes the OnJointDeactivated callback,
// which stops client-side interpolation of deactivated joint proxy objects.
}
if (!UsePhysics && !isNew)
{
// reset velocity to 0 on physics switch-off. Without that, the client thinks the
// prim still has velocity and continues to interpolate its position along the old
// velocity-vector.
Velocity = new Vector3(0, 0, 0);
Acceleration = new Vector3(0, 0, 0);
if (ParentGroup.RootPart == this)
AngularVelocity = new Vector3(0, 0, 0);
//RotationalVelocity = new Vector3(0, 0, 0);
} }
if (PhysActor.IsPhysical != UsePhysics)
PhysActor.IsPhysical = UsePhysics; PhysActor.IsPhysical = UsePhysics;
// If we're not what we're supposed to be in the physics scene, recreate ourselves.
//m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor);
/// that's not wholesome. Had to make Scene public
//PhysActor = null;
if ((Flags & PrimFlags.Phantom) == 0)
{
if (UsePhysics) if (UsePhysics)
{ {
if (ParentGroup.RootPart.KeyframeMotion != null) if (ParentGroup.RootPart.KeyframeMotion != null)
@ -1953,7 +1937,10 @@ namespace OpenSim.Region.Framework.Scenes
} }
} }
} }
}
bool phan = ((Flags & PrimFlags.Phantom) != 0);
if (PhysActor.Phantom != phan)
PhysActor.Phantom = phan;
// If this part is a sculpt then delay the physics update until we've asynchronously loaded the // If this part is a sculpt then delay the physics update until we've asynchronously loaded the
// mesh data. // mesh data.
@ -4355,24 +4342,28 @@ namespace OpenSim.Region.Framework.Scenes
bool wasPhantom = ((Flags & PrimFlags.Phantom) != 0); bool wasPhantom = ((Flags & PrimFlags.Phantom) != 0);
bool wasVD = VolumeDetectActive; bool wasVD = VolumeDetectActive;
// m_log.DebugFormat("[SOP]: Old states: phys: {0} temp: {1} phan: {2} vd: {3}", wasUsingPhysics, wasTemporary, wasPhantom, wasVD);
// m_log.DebugFormat("[SOP]: New states: phys: {0} temp: {1} phan: {2} vd: {3}", UsePhysics, SetTemporary, SetPhantom, SetVD);
if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD)) if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD))
return; return;
// do this first
if (building && PhysActor != null && PhysActor.Building != building)
PhysActor.Building = building;
// Special cases for VD. VD can only be called from a script // Special cases for VD. VD can only be called from a script
// and can't be combined with changes to other states. So we can rely // and can't be combined with changes to other states. So we can rely
// that... // that...
// ... if VD is changed, all others are not. // ... if VD is changed, all others are not.
// ... if one of the others is changed, VD is not. // ... if one of the others is changed, VD is not.
// do this first
if (building && PhysActor != null && PhysActor.Building != building)
PhysActor.Building = building;
if (SetVD) // VD is active, special logic applies if (SetVD) // VD is active, special logic applies
/* volume detection is now independent of phantom in sl
{ {
// State machine logic for VolumeDetect // State machine logic for VolumeDetect
// More logic below // More logic below
bool phanReset = (SetPhantom != wasPhantom) && !SetPhantom; bool phanReset = (SetPhantom != wasPhantom) && !SetPhantom;
if (phanReset) // Phantom changes from on to off switch VD off too if (phanReset) // Phantom changes from on to off switch VD off too
@ -4387,8 +4378,9 @@ namespace OpenSim.Region.Framework.Scenes
// If volumedetect is active we don't want phantom to be applied. // If volumedetect is active we don't want phantom to be applied.
// If this is a new call to VD out of the state "phantom" // If this is a new call to VD out of the state "phantom"
// this will also cause the prim to be visible to physics // this will also cause the prim to be visible to physics
*/
SetPhantom = false; SetPhantom = false;
} /* }
} }
else if (wasVD) else if (wasVD)
{ {
@ -4400,10 +4392,11 @@ namespace OpenSim.Region.Framework.Scenes
{ {
SetPhantom = true; SetPhantom = true;
} }
*/
if (UsePhysics) if (UsePhysics)
{ {
AddFlag(PrimFlags.Physics); AddFlag(PrimFlags.Physics);
/*
if (!wasUsingPhysics) if (!wasUsingPhysics)
{ {
DoPhysicsPropertyUpdate(UsePhysics, false); DoPhysicsPropertyUpdate(UsePhysics, false);
@ -4416,43 +4409,57 @@ namespace OpenSim.Region.Framework.Scenes
} }
} }
} }
*/
} }
else else
{ {
RemFlag(PrimFlags.Physics); RemFlag(PrimFlags.Physics);
/*
if (wasUsingPhysics) if (wasUsingPhysics)
{ {
DoPhysicsPropertyUpdate(UsePhysics, false); DoPhysicsPropertyUpdate(UsePhysics, false);
} }
*/
} }
if (SetPhantom if (SetPhantom)
|| ParentGroup.IsAttachment AddFlag(PrimFlags.Phantom);
else
RemFlag(PrimFlags.Phantom);
if ((SetPhantom && !UsePhysics) || ParentGroup.IsAttachment
|| (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints || (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints
{ {
AddFlag(PrimFlags.Phantom); AddFlag(PrimFlags.Phantom);
Velocity = new Vector3(0, 0, 0);
Acceleration = new Vector3(0, 0, 0);
if (ParentGroup.RootPart == this)
AngularVelocity = new Vector3(0, 0, 0);
if (PhysActor != null) if (PhysActor != null)
{
ParentGroup.Scene.RemovePhysicalPrim(1);
RemoveFromPhysics(); RemoveFromPhysics();
} }
else // Not phantom }
else
{ {
RemFlag(PrimFlags.Phantom);
if (ParentGroup.Scene == null) if (ParentGroup.Scene == null)
return; return;
if (ParentGroup.Scene.CollidablePrims && PhysActor == null) if (ParentGroup.Scene.CollidablePrims)
{
if (PhysActor == null)
{ {
// It's not phantom anymore. So make sure the physics engine get's knowledge of it
PhysActor = ParentGroup.Scene.PhysicsScene.AddPrimShape( PhysActor = ParentGroup.Scene.PhysicsScene.AddPrimShape(
string.Format("{0}/{1}", Name, UUID), string.Format("{0}/{1}", Name, UUID),
Shape, Shape,
AbsolutePosition, AbsolutePosition,
Scale, Scale,
// RotationOffset,
GetWorldRotation(), //physics wants world rotation like all other functions send GetWorldRotation(), //physics wants world rotation like all other functions send
UsePhysics, UsePhysics,
SetPhantom,
m_localId); m_localId);
PhysActor.SetMaterial(Material); PhysActor.SetMaterial(Material);
@ -4487,7 +4494,7 @@ namespace OpenSim.Region.Framework.Scenes
} }
else // it already has a physical representation else // it already has a physical representation
{ {
DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status. If it's phantom this will remove the prim DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status.
if (!ParentGroup.IsDeleted) if (!ParentGroup.IsDeleted)
{ {
@ -4498,6 +4505,7 @@ namespace OpenSim.Region.Framework.Scenes
} }
} }
} }
}
if (SetVD) if (SetVD)
{ {
@ -4509,7 +4517,7 @@ namespace OpenSim.Region.Framework.Scenes
if (this.PhysActor != null) if (this.PhysActor != null)
{ {
PhysActor.SetVolumeDetect(1); PhysActor.SetVolumeDetect(1);
AddFlag(PrimFlags.Phantom); // We set this flag also if VD is active // AddFlag(PrimFlags.Phantom); // We set this flag also if VD is active
this.VolumeDetectActive = true; this.VolumeDetectActive = true;
} }
} }
@ -4517,8 +4525,7 @@ namespace OpenSim.Region.Framework.Scenes
{ {
// Remove VolumeDetect in any case. Note, it's safe to call SetVolumeDetect as often as you like // Remove VolumeDetect in any case. Note, it's safe to call SetVolumeDetect as often as you like
// (mumbles, well, at least if you have infinte CPU powers :-)) // (mumbles, well, at least if you have infinte CPU powers :-))
PhysicsActor pa = this.PhysActor; if (this.PhysActor != null)
if (pa != null)
{ {
PhysActor.SetVolumeDetect(0); PhysActor.SetVolumeDetect(0);
} }