Merge branch 'master' of ssh://opensimulator.org/var/git/opensim
commit
4ff3757f86
|
@ -1568,8 +1568,14 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
// Here's where you get them.
|
// Here's where you get them.
|
||||||
m_AgentControlFlags = flags;
|
m_AgentControlFlags = flags;
|
||||||
m_headrotation = agentData.HeadRotation;
|
m_headrotation = agentData.HeadRotation;
|
||||||
|
byte oldState = State;
|
||||||
State = agentData.State;
|
State = agentData.State;
|
||||||
|
|
||||||
|
// We need to send this back to the client in order to stop the edit beams
|
||||||
|
if ((oldState & (uint)AgentState.Editing) != 0 && State == (uint)AgentState.None)
|
||||||
|
ControllingClient.SendAgentTerseUpdate(this);
|
||||||
|
|
||||||
|
|
||||||
PhysicsActor actor = PhysicsActor;
|
PhysicsActor actor = PhysicsActor;
|
||||||
if (actor == null)
|
if (actor == null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,10 +49,20 @@ public class ExtendedPhysics : INonSharedRegionModule
|
||||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
private static string LogHeader = "[EXTENDED PHYSICS]";
|
private static string LogHeader = "[EXTENDED PHYSICS]";
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
// Since BulletSim is a plugin, this these values aren't defined easily in one place.
|
// Since BulletSim is a plugin, this these values aren't defined easily in one place.
|
||||||
// This table must coorespond to an identical table in BSScene.
|
// This table must correspond to an identical table in BSScene.
|
||||||
|
|
||||||
|
// Per scene functions. See BSScene.
|
||||||
|
|
||||||
|
// Per avatar functions. See BSCharacter.
|
||||||
|
|
||||||
|
// Per prim functions. See BSPrim.
|
||||||
|
public const string PhysFunctGetLinksetType = "BulletSim.GetLinksetType";
|
||||||
public const string PhysFunctSetLinksetType = "BulletSim.SetLinksetType";
|
public const string PhysFunctSetLinksetType = "BulletSim.SetLinksetType";
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
|
||||||
private IConfig Configuration { get; set; }
|
private IConfig Configuration { get; set; }
|
||||||
private bool Enabled { get; set; }
|
private bool Enabled { get; set; }
|
||||||
private Scene BaseScene { get; set; }
|
private Scene BaseScene { get; set; }
|
||||||
|
@ -123,6 +133,7 @@ public class ExtendedPhysics : INonSharedRegionModule
|
||||||
|
|
||||||
// Register as LSL functions all the [ScriptInvocation] marked methods.
|
// Register as LSL functions all the [ScriptInvocation] marked methods.
|
||||||
Comms.RegisterScriptInvocations(this);
|
Comms.RegisterScriptInvocations(this);
|
||||||
|
Comms.RegisterConstants(this);
|
||||||
|
|
||||||
// When an object is modified, we might need to update its extended physics parameters
|
// When an object is modified, we might need to update its extended physics parameters
|
||||||
BaseScene.EventManager.OnObjectAddedToScene += EventManager_OnObjectAddedToScene;
|
BaseScene.EventManager.OnObjectAddedToScene += EventManager_OnObjectAddedToScene;
|
||||||
|
@ -136,7 +147,6 @@ public class ExtendedPhysics : INonSharedRegionModule
|
||||||
|
|
||||||
private void EventManager_OnObjectAddedToScene(SceneObjectGroup obj)
|
private void EventManager_OnObjectAddedToScene(SceneObjectGroup obj)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event generated when some property of a prim changes.
|
// Event generated when some property of a prim changes.
|
||||||
|
@ -168,9 +178,11 @@ public class ExtendedPhysics : INonSharedRegionModule
|
||||||
public static int PHYS_LINKSET_TYPE_MANUAL = 2;
|
public static int PHYS_LINKSET_TYPE_MANUAL = 2;
|
||||||
|
|
||||||
[ScriptInvocation]
|
[ScriptInvocation]
|
||||||
public void physSetLinksetType(UUID hostID, UUID scriptID, int linksetType)
|
public int physSetLinksetType(UUID hostID, UUID scriptID, int linksetType)
|
||||||
{
|
{
|
||||||
if (!Enabled) return;
|
int ret = -1;
|
||||||
|
|
||||||
|
if (!Enabled) return ret;
|
||||||
|
|
||||||
// The part that is requesting the change.
|
// The part that is requesting the change.
|
||||||
SceneObjectPart requestingPart = BaseScene.GetSceneObjectPart(hostID);
|
SceneObjectPart requestingPart = BaseScene.GetSceneObjectPart(hostID);
|
||||||
|
@ -186,7 +198,7 @@ public class ExtendedPhysics : INonSharedRegionModule
|
||||||
Physics.Manager.PhysicsActor rootPhysActor = rootPart.PhysActor;
|
Physics.Manager.PhysicsActor rootPhysActor = rootPart.PhysActor;
|
||||||
if (rootPhysActor != null)
|
if (rootPhysActor != null)
|
||||||
{
|
{
|
||||||
rootPhysActor.Extension(PhysFunctSetLinksetType, linksetType);
|
ret = (int)rootPhysActor.Extension(PhysFunctSetLinksetType, linksetType);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -204,6 +216,49 @@ public class ExtendedPhysics : INonSharedRegionModule
|
||||||
{
|
{
|
||||||
m_log.WarnFormat("{0} physSetLinsetType: cannot find script object in scene. hostID={1}", LogHeader, hostID);
|
m_log.WarnFormat("{0} physSetLinsetType: cannot find script object in scene. hostID={1}", LogHeader, hostID);
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
[ScriptInvocation]
|
||||||
|
public int physGetLinksetType(UUID hostID, UUID scriptID)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (!Enabled) return ret;
|
||||||
|
|
||||||
|
// The part that is requesting the change.
|
||||||
|
SceneObjectPart requestingPart = BaseScene.GetSceneObjectPart(hostID);
|
||||||
|
|
||||||
|
if (requestingPart != null)
|
||||||
|
{
|
||||||
|
// The type is is always on the root of a linkset.
|
||||||
|
SceneObjectGroup containingGroup = requestingPart.ParentGroup;
|
||||||
|
SceneObjectPart rootPart = containingGroup.RootPart;
|
||||||
|
|
||||||
|
if (rootPart != null)
|
||||||
|
{
|
||||||
|
Physics.Manager.PhysicsActor rootPhysActor = rootPart.PhysActor;
|
||||||
|
if (rootPhysActor != null)
|
||||||
|
{
|
||||||
|
ret = (int)rootPhysActor.Extension(PhysFunctGetLinksetType);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.WarnFormat("{0} physGetLinksetType: root part does not have a physics actor. rootName={1}, hostID={2}",
|
||||||
|
LogHeader, rootPart.Name, hostID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.WarnFormat("{0} physGetLinksetType: root part does not exist. RequestingPartName={1}, hostID={2}",
|
||||||
|
LogHeader, requestingPart.Name, hostID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_log.WarnFormat("{0} physGetLinsetType: cannot find script object in scene. hostID={1}", LogHeader, hostID);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,17 @@ public abstract class BSLinkset
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class BSLinkInfo
|
||||||
|
{
|
||||||
|
public BSPrimLinkable member;
|
||||||
|
public BSLinkInfo(BSPrimLinkable pMember)
|
||||||
|
{
|
||||||
|
member = pMember;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinksetImplementation LinksetImpl { get; protected set; }
|
||||||
|
|
||||||
public BSPrimLinkable LinksetRoot { get; protected set; }
|
public BSPrimLinkable LinksetRoot { get; protected set; }
|
||||||
|
|
||||||
protected BSScene m_physicsScene { get; private set; }
|
protected BSScene m_physicsScene { get; private set; }
|
||||||
|
@ -78,7 +89,8 @@ public abstract class BSLinkset
|
||||||
public int LinksetID { get; private set; }
|
public int LinksetID { get; private set; }
|
||||||
|
|
||||||
// The children under the root in this linkset.
|
// The children under the root in this linkset.
|
||||||
protected HashSet<BSPrimLinkable> m_children;
|
// protected HashSet<BSPrimLinkable> m_children;
|
||||||
|
protected Dictionary<BSPrimLinkable, BSLinkInfo> m_children;
|
||||||
|
|
||||||
// We lock the diddling of linkset classes to prevent any badness.
|
// We lock the diddling of linkset classes to prevent any badness.
|
||||||
// This locks the modification of the instances of this class. Changes
|
// This locks the modification of the instances of this class. Changes
|
||||||
|
@ -109,7 +121,7 @@ public abstract class BSLinkset
|
||||||
m_nextLinksetID = 1;
|
m_nextLinksetID = 1;
|
||||||
m_physicsScene = scene;
|
m_physicsScene = scene;
|
||||||
LinksetRoot = parent;
|
LinksetRoot = parent;
|
||||||
m_children = new HashSet<BSPrimLinkable>();
|
m_children = new Dictionary<BSPrimLinkable, BSLinkInfo>();
|
||||||
LinksetMass = parent.RawMass;
|
LinksetMass = parent.RawMass;
|
||||||
Rebuilding = false;
|
Rebuilding = false;
|
||||||
|
|
||||||
|
@ -170,17 +182,7 @@ public abstract class BSLinkset
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
lock (m_linksetActivityLock)
|
lock (m_linksetActivityLock)
|
||||||
{
|
{
|
||||||
ret = m_children.Contains(child);
|
ret = m_children.ContainsKey(child);
|
||||||
/* Safer version but the above should work
|
|
||||||
foreach (BSPrimLinkable bp in m_children)
|
|
||||||
{
|
|
||||||
if (child.LocalID == bp.LocalID)
|
|
||||||
{
|
|
||||||
ret = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -194,7 +196,24 @@ public abstract class BSLinkset
|
||||||
lock (m_linksetActivityLock)
|
lock (m_linksetActivityLock)
|
||||||
{
|
{
|
||||||
action(LinksetRoot);
|
action(LinksetRoot);
|
||||||
foreach (BSPrimLinkable po in m_children)
|
foreach (BSPrimLinkable po in m_children.Keys)
|
||||||
|
{
|
||||||
|
if (action(po))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform an action on each member of the linkset including root prim.
|
||||||
|
// Depends on the action on whether this should be done at taint time.
|
||||||
|
public delegate bool ForEachLinkInfoAction(BSLinkInfo obj);
|
||||||
|
public virtual bool ForEachLinkInfo(ForEachLinkInfoAction action)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
lock (m_linksetActivityLock)
|
||||||
|
{
|
||||||
|
foreach (BSLinkInfo po in m_children.Values)
|
||||||
{
|
{
|
||||||
if (action(po))
|
if (action(po))
|
||||||
break;
|
break;
|
||||||
|
@ -364,7 +383,7 @@ public abstract class BSLinkset
|
||||||
{
|
{
|
||||||
lock (m_linksetActivityLock)
|
lock (m_linksetActivityLock)
|
||||||
{
|
{
|
||||||
foreach (BSPrimLinkable bp in m_children)
|
foreach (BSPrimLinkable bp in m_children.Keys)
|
||||||
{
|
{
|
||||||
mass += bp.RawMass;
|
mass += bp.RawMass;
|
||||||
}
|
}
|
||||||
|
@ -382,7 +401,7 @@ public abstract class BSLinkset
|
||||||
com = LinksetRoot.Position * LinksetRoot.RawMass;
|
com = LinksetRoot.Position * LinksetRoot.RawMass;
|
||||||
float totalMass = LinksetRoot.RawMass;
|
float totalMass = LinksetRoot.RawMass;
|
||||||
|
|
||||||
foreach (BSPrimLinkable bp in m_children)
|
foreach (BSPrimLinkable bp in m_children.Keys)
|
||||||
{
|
{
|
||||||
com += bp.Position * bp.RawMass;
|
com += bp.Position * bp.RawMass;
|
||||||
totalMass += bp.RawMass;
|
totalMass += bp.RawMass;
|
||||||
|
@ -401,7 +420,7 @@ public abstract class BSLinkset
|
||||||
{
|
{
|
||||||
com = LinksetRoot.Position;
|
com = LinksetRoot.Position;
|
||||||
|
|
||||||
foreach (BSPrimLinkable bp in m_children)
|
foreach (BSPrimLinkable bp in m_children.Keys)
|
||||||
{
|
{
|
||||||
com += bp.Position;
|
com += bp.Position;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ public sealed class BSLinksetCompound : BSLinkset
|
||||||
public BSLinksetCompound(BSScene scene, BSPrimLinkable parent)
|
public BSLinksetCompound(BSScene scene, BSPrimLinkable parent)
|
||||||
: base(scene, parent)
|
: base(scene, parent)
|
||||||
{
|
{
|
||||||
|
LinksetImpl = LinksetImplementation.Compound;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================================================================
|
// ================================================================
|
||||||
|
@ -257,7 +258,7 @@ public sealed class BSLinksetCompound : BSLinkset
|
||||||
{
|
{
|
||||||
if (!HasChild(child))
|
if (!HasChild(child))
|
||||||
{
|
{
|
||||||
m_children.Add(child);
|
m_children.Add(child, new BSLinkInfo(child));
|
||||||
|
|
||||||
DetailLog("{0},BSLinksetCompound.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID);
|
DetailLog("{0},BSLinksetCompound.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID);
|
||||||
|
|
||||||
|
@ -353,7 +354,7 @@ public sealed class BSLinksetCompound : BSLinkset
|
||||||
|
|
||||||
// Add the shapes of all the components of the linkset
|
// Add the shapes of all the components of the linkset
|
||||||
int memberIndex = 1;
|
int memberIndex = 1;
|
||||||
ForEachMember(delegate(BSPrimLinkable cPrim)
|
ForEachMember((cPrim) =>
|
||||||
{
|
{
|
||||||
if (IsRoot(cPrim))
|
if (IsRoot(cPrim))
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,8 +36,78 @@ public sealed class BSLinksetConstraints : BSLinkset
|
||||||
{
|
{
|
||||||
// private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]";
|
// private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINTS]";
|
||||||
|
|
||||||
|
public class BSLinkInfoConstraint : BSLinkInfo
|
||||||
|
{
|
||||||
|
public ConstraintType constraintType;
|
||||||
|
public BSConstraint constraint;
|
||||||
|
public OMV.Vector3 linearLimitLow;
|
||||||
|
public OMV.Vector3 linearLimitHigh;
|
||||||
|
public OMV.Vector3 angularLimitLow;
|
||||||
|
public OMV.Vector3 angularLimitHigh;
|
||||||
|
public bool useFrameOffset;
|
||||||
|
public bool enableTransMotor;
|
||||||
|
public float transMotorMaxVel;
|
||||||
|
public float transMotorMaxForce;
|
||||||
|
public float cfm;
|
||||||
|
public float erp;
|
||||||
|
public float solverIterations;
|
||||||
|
|
||||||
|
public BSLinkInfoConstraint(BSPrimLinkable pMember)
|
||||||
|
: base(pMember)
|
||||||
|
{
|
||||||
|
constraint = null;
|
||||||
|
ResetToFixedConstraint();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set all the parameters for this constraint to a fixed, non-movable constraint.
|
||||||
|
public void ResetToFixedConstraint()
|
||||||
|
{
|
||||||
|
constraintType = ConstraintType.D6_CONSTRAINT_TYPE;
|
||||||
|
linearLimitLow = OMV.Vector3.Zero;
|
||||||
|
linearLimitHigh = OMV.Vector3.Zero;
|
||||||
|
angularLimitLow = OMV.Vector3.Zero;
|
||||||
|
angularLimitHigh = OMV.Vector3.Zero;
|
||||||
|
useFrameOffset = BSParam.LinkConstraintUseFrameOffset;
|
||||||
|
enableTransMotor = BSParam.LinkConstraintEnableTransMotor;
|
||||||
|
transMotorMaxVel = BSParam.LinkConstraintTransMotorMaxVel;
|
||||||
|
transMotorMaxForce = BSParam.LinkConstraintTransMotorMaxForce;
|
||||||
|
cfm = BSParam.LinkConstraintCFM;
|
||||||
|
erp = BSParam.LinkConstraintERP;
|
||||||
|
solverIterations = BSParam.LinkConstraintSolverIterations;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Given a constraint, apply the current constraint parameters to same.
|
||||||
|
public void SetConstraintParameters(BSConstraint constrain)
|
||||||
|
{
|
||||||
|
switch (constraintType)
|
||||||
|
{
|
||||||
|
case ConstraintType.D6_CONSTRAINT_TYPE:
|
||||||
|
BSConstraint6Dof constrain6dof = constrain as BSConstraint6Dof;
|
||||||
|
if (constrain6dof != null)
|
||||||
|
{
|
||||||
|
// zero linear and angular limits makes the objects unable to move in relation to each other
|
||||||
|
constrain6dof.SetLinearLimits(linearLimitLow, linearLimitHigh);
|
||||||
|
constrain6dof.SetAngularLimits(angularLimitLow, angularLimitHigh);
|
||||||
|
|
||||||
|
// tweek the constraint to increase stability
|
||||||
|
constrain6dof.UseFrameOffset(useFrameOffset);
|
||||||
|
constrain6dof.TranslationalLimitMotor(enableTransMotor, transMotorMaxVel, transMotorMaxForce);
|
||||||
|
constrain6dof.SetCFMAndERP(cfm, erp);
|
||||||
|
if (solverIterations != 0f)
|
||||||
|
{
|
||||||
|
constrain6dof.SetSolverIterations(solverIterations);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public BSLinksetConstraints(BSScene scene, BSPrimLinkable parent) : base(scene, parent)
|
public BSLinksetConstraints(BSScene scene, BSPrimLinkable parent) : base(scene, parent)
|
||||||
{
|
{
|
||||||
|
LinksetImpl = LinksetImplementation.Constraint;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When physical properties are changed the linkset needs to recalculate
|
// When physical properties are changed the linkset needs to recalculate
|
||||||
|
@ -142,7 +212,7 @@ public sealed class BSLinksetConstraints : BSLinkset
|
||||||
{
|
{
|
||||||
if (!HasChild(child))
|
if (!HasChild(child))
|
||||||
{
|
{
|
||||||
m_children.Add(child);
|
m_children.Add(child, new BSLinkInfoConstraint(child));
|
||||||
|
|
||||||
DetailLog("{0},BSLinksetConstraints.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID);
|
DetailLog("{0},BSLinksetConstraints.AddChildToLinkset,call,child={1}", LinksetRoot.LocalID, child.LocalID);
|
||||||
|
|
||||||
|
@ -190,73 +260,74 @@ public sealed class BSLinksetConstraints : BSLinkset
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a static constraint between the two passed objects
|
// Create a static constraint between the two passed objects
|
||||||
private BSConstraint BuildConstraint(BSPrimLinkable rootPrim, BSPrimLinkable childPrim)
|
private BSConstraint BuildConstraint(BSPrimLinkable rootPrim, BSLinkInfo li)
|
||||||
{
|
{
|
||||||
|
BSLinkInfoConstraint liConstraint = li as BSLinkInfoConstraint;
|
||||||
|
if (liConstraint == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
// Zero motion for children so they don't interpolate
|
// Zero motion for children so they don't interpolate
|
||||||
childPrim.ZeroMotion(true);
|
li.member.ZeroMotion(true);
|
||||||
|
|
||||||
// Relative position normalized to the root prim
|
BSConstraint constrain = null;
|
||||||
// Essentually a vector pointing from center of rootPrim to center of childPrim
|
|
||||||
OMV.Vector3 childRelativePosition = childPrim.Position - rootPrim.Position;
|
|
||||||
|
|
||||||
// real world coordinate of midpoint between the two objects
|
switch (liConstraint.constraintType)
|
||||||
OMV.Vector3 midPoint = rootPrim.Position + (childRelativePosition / 2);
|
{
|
||||||
|
case ConstraintType.D6_CONSTRAINT_TYPE:
|
||||||
|
// Relative position normalized to the root prim
|
||||||
|
// Essentually a vector pointing from center of rootPrim to center of li.member
|
||||||
|
OMV.Vector3 childRelativePosition = liConstraint.member.Position - rootPrim.Position;
|
||||||
|
|
||||||
DetailLog("{0},BSLinksetConstraint.BuildConstraint,taint,root={1},rBody={2},child={3},cBody={4},rLoc={5},cLoc={6},midLoc={7}",
|
// real world coordinate of midpoint between the two objects
|
||||||
rootPrim.LocalID,
|
OMV.Vector3 midPoint = rootPrim.Position + (childRelativePosition / 2);
|
||||||
rootPrim.LocalID, rootPrim.PhysBody.AddrString,
|
|
||||||
childPrim.LocalID, childPrim.PhysBody.AddrString,
|
|
||||||
rootPrim.Position, childPrim.Position, midPoint);
|
|
||||||
|
|
||||||
// create a constraint that allows no freedom of movement between the two objects
|
DetailLog("{0},BSLinksetConstraint.BuildConstraint,taint,root={1},rBody={2},child={3},cBody={4},rLoc={5},cLoc={6},midLoc={7}",
|
||||||
// http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818
|
rootPrim.LocalID,
|
||||||
|
rootPrim.LocalID, rootPrim.PhysBody.AddrString,
|
||||||
|
liConstraint.member.LocalID, liConstraint.member.PhysBody.AddrString,
|
||||||
|
rootPrim.Position, liConstraint.member.Position, midPoint);
|
||||||
|
|
||||||
BSConstraint6Dof constrain = new BSConstraint6Dof(
|
// create a constraint that allows no freedom of movement between the two objects
|
||||||
m_physicsScene.World, rootPrim.PhysBody, childPrim.PhysBody, midPoint, true, true );
|
// http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4818
|
||||||
// PhysicsScene.World, childPrim.BSBody, rootPrim.BSBody, midPoint, true, true );
|
|
||||||
|
|
||||||
/* NOTE: below is an attempt to build constraint with full frame computation, etc.
|
constrain = new BSConstraint6Dof(
|
||||||
* Using the midpoint is easier since it lets the Bullet code manipulate the transforms
|
m_physicsScene.World, rootPrim.PhysBody, liConstraint.member.PhysBody, midPoint, true, true );
|
||||||
* of the objects.
|
|
||||||
* Code left for future programmers.
|
|
||||||
// ==================================================================================
|
|
||||||
// relative position normalized to the root prim
|
|
||||||
OMV.Quaternion invThisOrientation = OMV.Quaternion.Inverse(rootPrim.Orientation);
|
|
||||||
OMV.Vector3 childRelativePosition = (childPrim.Position - rootPrim.Position) * invThisOrientation;
|
|
||||||
|
|
||||||
// relative rotation of the child to the parent
|
/* NOTE: below is an attempt to build constraint with full frame computation, etc.
|
||||||
OMV.Quaternion childRelativeRotation = invThisOrientation * childPrim.Orientation;
|
* Using the midpoint is easier since it lets the Bullet code manipulate the transforms
|
||||||
OMV.Quaternion inverseChildRelativeRotation = OMV.Quaternion.Inverse(childRelativeRotation);
|
* of the objects.
|
||||||
|
* Code left for future programmers.
|
||||||
|
// ==================================================================================
|
||||||
|
// relative position normalized to the root prim
|
||||||
|
OMV.Quaternion invThisOrientation = OMV.Quaternion.Inverse(rootPrim.Orientation);
|
||||||
|
OMV.Vector3 childRelativePosition = (liConstraint.member.Position - rootPrim.Position) * invThisOrientation;
|
||||||
|
|
||||||
DetailLog("{0},BSLinksetConstraint.PhysicallyLinkAChildToRoot,taint,root={1},child={2}", rootPrim.LocalID, rootPrim.LocalID, childPrim.LocalID);
|
// relative rotation of the child to the parent
|
||||||
BS6DofConstraint constrain = new BS6DofConstraint(
|
OMV.Quaternion childRelativeRotation = invThisOrientation * liConstraint.member.Orientation;
|
||||||
PhysicsScene.World, rootPrim.Body, childPrim.Body,
|
OMV.Quaternion inverseChildRelativeRotation = OMV.Quaternion.Inverse(childRelativeRotation);
|
||||||
OMV.Vector3.Zero,
|
|
||||||
OMV.Quaternion.Inverse(rootPrim.Orientation),
|
DetailLog("{0},BSLinksetConstraint.PhysicallyLinkAChildToRoot,taint,root={1},child={2}", rootPrim.LocalID, rootPrim.LocalID, liConstraint.member.LocalID);
|
||||||
OMV.Vector3.Zero,
|
constrain = new BS6DofConstraint(
|
||||||
OMV.Quaternion.Inverse(childPrim.Orientation),
|
PhysicsScene.World, rootPrim.Body, liConstraint.member.Body,
|
||||||
true,
|
OMV.Vector3.Zero,
|
||||||
true
|
OMV.Quaternion.Inverse(rootPrim.Orientation),
|
||||||
);
|
OMV.Vector3.Zero,
|
||||||
// ==================================================================================
|
OMV.Quaternion.Inverse(liConstraint.member.Orientation),
|
||||||
*/
|
true,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
// ==================================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
liConstraint.SetConstraintParameters(constrain);
|
||||||
|
|
||||||
m_physicsScene.Constraints.AddConstraint(constrain);
|
m_physicsScene.Constraints.AddConstraint(constrain);
|
||||||
|
|
||||||
// zero linear and angular limits makes the objects unable to move in relation to each other
|
|
||||||
constrain.SetLinearLimits(OMV.Vector3.Zero, OMV.Vector3.Zero);
|
|
||||||
constrain.SetAngularLimits(OMV.Vector3.Zero, OMV.Vector3.Zero);
|
|
||||||
|
|
||||||
// tweek the constraint to increase stability
|
|
||||||
constrain.UseFrameOffset(BSParam.LinkConstraintUseFrameOffset);
|
|
||||||
constrain.TranslationalLimitMotor(BSParam.LinkConstraintEnableTransMotor,
|
|
||||||
BSParam.LinkConstraintTransMotorMaxVel,
|
|
||||||
BSParam.LinkConstraintTransMotorMaxForce);
|
|
||||||
constrain.SetCFMAndERP(BSParam.LinkConstraintCFM, BSParam.LinkConstraintERP);
|
|
||||||
if (BSParam.LinkConstraintSolverIterations != 0f)
|
|
||||||
{
|
|
||||||
constrain.SetSolverIterations(BSParam.LinkConstraintSolverIterations);
|
|
||||||
}
|
|
||||||
return constrain;
|
return constrain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,23 +388,24 @@ public sealed class BSLinksetConstraints : BSLinkset
|
||||||
return; // Note the 'finally' clause at the botton which will get executed.
|
return; // Note the 'finally' clause at the botton which will get executed.
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (BSPrimLinkable child in m_children)
|
ForEachLinkInfo((li) =>
|
||||||
{
|
{
|
||||||
// A child in the linkset physically shows the mass of the whole linkset.
|
// A child in the linkset physically shows the mass of the whole linkset.
|
||||||
// This allows Bullet to apply enough force on the child to move the whole linkset.
|
// This allows Bullet to apply enough force on the child to move the whole linkset.
|
||||||
// (Also do the mass stuff before recomputing the constraint so mass is not zero.)
|
// (Also do the mass stuff before recomputing the constraint so mass is not zero.)
|
||||||
child.UpdatePhysicalMassProperties(linksetMass, true);
|
li.member.UpdatePhysicalMassProperties(linksetMass, true);
|
||||||
|
|
||||||
BSConstraint constrain;
|
BSConstraint constrain;
|
||||||
if (!m_physicsScene.Constraints.TryGetConstraint(LinksetRoot.PhysBody, child.PhysBody, out constrain))
|
if (!m_physicsScene.Constraints.TryGetConstraint(LinksetRoot.PhysBody, li.member.PhysBody, out constrain))
|
||||||
{
|
{
|
||||||
// If constraint doesn't exist yet, create it.
|
// If constraint doesn't exist yet, create it.
|
||||||
constrain = BuildConstraint(LinksetRoot, child);
|
constrain = BuildConstraint(LinksetRoot, li);
|
||||||
}
|
}
|
||||||
constrain.RecomputeConstraintVariables(linksetMass);
|
constrain.RecomputeConstraintVariables(linksetMass);
|
||||||
|
|
||||||
// PhysicsScene.PE.DumpConstraint(PhysicsScene.World, constrain.Constraint); // DEBUG DEBUG
|
// PhysicsScene.PE.DumpConstraint(PhysicsScene.World, constrain.Constraint); // DEBUG DEBUG
|
||||||
}
|
return false; // 'false' says to keep processing other members
|
||||||
|
});
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
|
@ -1541,6 +1541,50 @@ public class BSPrim : BSPhysObject
|
||||||
PhysicalActors.RemoveDependencies();
|
PhysicalActors.RemoveDependencies();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Extension
|
||||||
|
public override object Extension(string pFunct, params object[] pParams)
|
||||||
|
{
|
||||||
|
object ret = null;
|
||||||
|
switch (pFunct)
|
||||||
|
{
|
||||||
|
case BSScene.PhysFunctGetLinksetType:
|
||||||
|
{
|
||||||
|
BSPrimLinkable myHandle = this as BSPrimLinkable;
|
||||||
|
if (myHandle != null)
|
||||||
|
{
|
||||||
|
ret = (object)myHandle.LinksetType;
|
||||||
|
}
|
||||||
|
m_log.DebugFormat("{0} Extension.physGetLinksetType, type={1}", LogHeader, ret);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BSScene.PhysFunctSetLinksetType:
|
||||||
|
{
|
||||||
|
if (pParams.Length > 0)
|
||||||
|
{
|
||||||
|
BSLinkset.LinksetImplementation linksetType = (BSLinkset.LinksetImplementation)pParams[0];
|
||||||
|
BSPrimLinkable myHandle = this as BSPrimLinkable;
|
||||||
|
if (myHandle != null && myHandle.Linkset.IsRoot(myHandle))
|
||||||
|
{
|
||||||
|
PhysScene.TaintedObject("BSPrim.PhysFunctSetLinksetType", delegate()
|
||||||
|
{
|
||||||
|
// Cause the linkset type to change
|
||||||
|
m_log.DebugFormat("{0} Extension.physSetLinksetType, oldType={1}, newType={2}",
|
||||||
|
LogHeader, myHandle.Linkset.LinksetImpl, linksetType);
|
||||||
|
myHandle.ConvertLinkset(linksetType);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ret = (object)(int)linksetType;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
ret = base.Extension(pFunct, pParams);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endregion // Extension
|
||||||
|
|
||||||
// The physics engine says that properties have updated. Update same and inform
|
// The physics engine says that properties have updated. Update same and inform
|
||||||
// the world that things have changed.
|
// the world that things have changed.
|
||||||
// NOTE: BSPrim.UpdateProperties is overloaded by BSPrimLinkable which modifies updates from root and children prims.
|
// NOTE: BSPrim.UpdateProperties is overloaded by BSPrimLinkable which modifies updates from root and children prims.
|
||||||
|
|
|
@ -233,5 +233,46 @@ public class BSPrimLinkable : BSPrimDisplaced
|
||||||
base.HasSomeCollision = value;
|
base.HasSomeCollision = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert the existing linkset of this prim into a new type.
|
||||||
|
public bool ConvertLinkset(BSLinkset.LinksetImplementation newType)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
if (LinksetType != newType)
|
||||||
|
{
|
||||||
|
// Set the implementation type first so the call to BSLinkset.Factory gets the new type.
|
||||||
|
this.LinksetType = newType;
|
||||||
|
|
||||||
|
BSLinkset oldLinkset = this.Linkset;
|
||||||
|
BSLinkset newLinkset = BSLinkset.Factory(PhysScene, this);
|
||||||
|
|
||||||
|
this.Linkset = newLinkset;
|
||||||
|
|
||||||
|
// Pick up any physical dependencies this linkset might have in the physics engine.
|
||||||
|
oldLinkset.RemoveDependencies(this);
|
||||||
|
|
||||||
|
// Create a list of the children (mainly because can't interate through a list that's changing)
|
||||||
|
List<BSPrimLinkable> children = new List<BSPrimLinkable>();
|
||||||
|
oldLinkset.ForEachMember((child) =>
|
||||||
|
{
|
||||||
|
if (!oldLinkset.IsRoot(child))
|
||||||
|
children.Add(child);
|
||||||
|
return false; // 'false' says to continue to next member
|
||||||
|
});
|
||||||
|
|
||||||
|
// Remove the children from the old linkset and add to the new (will be a new instance from the factory)
|
||||||
|
foreach (BSPrimLinkable child in children)
|
||||||
|
{
|
||||||
|
oldLinkset.RemoveMeFromLinkset(child);
|
||||||
|
newLinkset.AddMeToLinkset(child);
|
||||||
|
child.Linkset = newLinkset;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force the shape and linkset to get reconstructed
|
||||||
|
newLinkset.Refresh(this);
|
||||||
|
this.ForceBodyShapeRebuild(true /* inTaintTime */);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -862,6 +862,23 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
|
||||||
|
|
||||||
public override bool IsThreaded { get { return false; } }
|
public override bool IsThreaded { get { return false; } }
|
||||||
|
|
||||||
|
#region Extensions
|
||||||
|
// =============================================================
|
||||||
|
// Per scene functions. See below.
|
||||||
|
|
||||||
|
// Per avatar functions. See BSCharacter.
|
||||||
|
|
||||||
|
// Per prim functions. See BSPrim.
|
||||||
|
public const string PhysFunctGetLinksetType = "BulletSim.GetLinksetType";
|
||||||
|
public const string PhysFunctSetLinksetType = "BulletSim.SetLinksetType";
|
||||||
|
// =============================================================
|
||||||
|
|
||||||
|
public override object Extension(string pFunct, params object[] pParams)
|
||||||
|
{
|
||||||
|
return base.Extension(pFunct, pParams);
|
||||||
|
}
|
||||||
|
#endregion // Extensions
|
||||||
|
|
||||||
#region Taints
|
#region Taints
|
||||||
// The simulation execution order is:
|
// The simulation execution order is:
|
||||||
// Simulate()
|
// Simulate()
|
||||||
|
|
|
@ -317,7 +317,8 @@ namespace OpenSim.Region.Physics.Manager
|
||||||
// Extendable interface for new, physics engine specific operations
|
// Extendable interface for new, physics engine specific operations
|
||||||
public virtual object Extension(string pFunct, params object[] pParams)
|
public virtual object Extension(string pFunct, params object[] pParams)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
// A NOP of the physics engine does not implement this feature
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -338,7 +338,8 @@ namespace OpenSim.Region.Physics.Manager
|
||||||
// Extendable interface for new, physics engine specific operations
|
// Extendable interface for new, physics engine specific operations
|
||||||
public virtual object Extension(string pFunct, params object[] pParams)
|
public virtual object Extension(string pFunct, params object[] pParams)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
// A NOP if the extension thing is not implemented by the physics engine
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -319,7 +319,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||||
|
|
||||||
object[] convertedParms = new object[parms.Length];
|
object[] convertedParms = new object[parms.Length];
|
||||||
for (int i = 0; i < parms.Length; i++)
|
for (int i = 0; i < parms.Length; i++)
|
||||||
convertedParms[i] = ConvertFromLSL(parms[i],signature[i], fname);
|
convertedParms[i] = ConvertFromLSL(parms[i], signature[i], fname);
|
||||||
|
|
||||||
// now call the function, the contract with the function is that it will always return
|
// now call the function, the contract with the function is that it will always return
|
||||||
// non-null but don't trust it completely
|
// non-null but don't trust it completely
|
||||||
|
@ -444,7 +444,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MODError(String.Format("{1}: parameter type mismatch; expecting {0}",type.Name, fname));
|
MODError(String.Format("{0}: parameter type mismatch; expecting {1}, type(parm)={2}", fname, type.Name, lslparm.GetType()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -937,7 +937,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||||
{
|
{
|
||||||
string retval = null;
|
string retval = null;
|
||||||
if (value is int)
|
if (value is int)
|
||||||
retval = ((int)value).ToString();
|
retval = String.Format("new LSL_Types.LSLInteger({0})",((int)value).ToString());
|
||||||
else if (value is float)
|
else if (value is float)
|
||||||
retval = String.Format("new LSL_Types.LSLFloat({0})",((float)value).ToString());
|
retval = String.Format("new LSL_Types.LSLFloat({0})",((float)value).ToString());
|
||||||
else if (value is string)
|
else if (value is string)
|
||||||
|
|
Loading…
Reference in New Issue