BulletSim: add extended physics function physGetLinkType(linkNum). Add implementation of physChangeLinkParams() in BSLinksetConstraint.
parent
8755aeb348
commit
e1120cb74d
|
@ -64,6 +64,7 @@ public class ExtendedPhysics : INonSharedRegionModule
|
||||||
public const string PhysFunctSetLinksetType = "BulletSim.SetLinksetType";
|
public const string PhysFunctSetLinksetType = "BulletSim.SetLinksetType";
|
||||||
public const string PhysFunctChangeLinkFixed = "BulletSim.ChangeLinkFixed";
|
public const string PhysFunctChangeLinkFixed = "BulletSim.ChangeLinkFixed";
|
||||||
public const string PhysFunctChangeLinkType = "BulletSim.ChangeLinkType";
|
public const string PhysFunctChangeLinkType = "BulletSim.ChangeLinkType";
|
||||||
|
public const string PhysFunctGetLinkType = "BulletSim.GetLinkType";
|
||||||
public const string PhysFunctChangeLinkParams = "BulletSim.ChangeLinkParams";
|
public const string PhysFunctChangeLinkParams = "BulletSim.ChangeLinkParams";
|
||||||
|
|
||||||
// =============================================================
|
// =============================================================
|
||||||
|
@ -320,6 +321,24 @@ public class ExtendedPhysics : INonSharedRegionModule
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// physGetLinkType(integer linkNum)
|
||||||
|
[ScriptInvocation]
|
||||||
|
public int physGetLinkType(UUID hostID, UUID scriptID, int linkNum, int typeCode)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
if (!Enabled) return ret;
|
||||||
|
|
||||||
|
PhysicsActor rootPhysActor;
|
||||||
|
PhysicsActor childPhysActor;
|
||||||
|
|
||||||
|
if (GetRootAndChildPhysActors(hostID, linkNum, out rootPhysActor, out childPhysActor))
|
||||||
|
{
|
||||||
|
ret = MakeIntError(rootPhysActor.Extension(PhysFunctGetLinkType, childPhysActor));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// physChangeLinkFixed(integer linkNum)
|
// physChangeLinkFixed(integer linkNum)
|
||||||
// Change the link between the root and the linkNum into a fixed, static physical connection.
|
// Change the link between the root and the linkNum into a fixed, static physical connection.
|
||||||
[ScriptInvocation]
|
[ScriptInvocation]
|
||||||
|
|
|
@ -209,6 +209,17 @@ public abstract class BSLinkset
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool TryGetLinkInfo(BSPrimLinkable child, out BSLinkInfo foundInfo)
|
||||||
|
{
|
||||||
|
bool ret = false;
|
||||||
|
BSLinkInfo found = null;
|
||||||
|
lock (m_linksetActivityLock)
|
||||||
|
{
|
||||||
|
ret = m_children.TryGetValue(child, out found);
|
||||||
|
}
|
||||||
|
foundInfo = found;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
// Perform an action on each member of the linkset including root prim.
|
// 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.
|
// Depends on the action on whether this should be done at taint time.
|
||||||
public delegate bool ForEachLinkInfoAction(BSLinkInfo obj);
|
public delegate bool ForEachLinkInfoAction(BSLinkInfo obj);
|
||||||
|
|
|
@ -168,6 +168,8 @@ public sealed class BSLinksetConstraints : BSLinkset
|
||||||
LinksetImpl = LinksetImplementation.Constraint;
|
LinksetImpl = LinksetImplementation.Constraint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string LogHeader = "[BULLETSIM LINKSET CONSTRAINT]";
|
||||||
|
|
||||||
// When physical properties are changed the linkset needs to recalculate
|
// When physical properties are changed the linkset needs to recalculate
|
||||||
// its internal properties.
|
// its internal properties.
|
||||||
// This is queued in the 'post taint' queue so the
|
// This is queued in the 'post taint' queue so the
|
||||||
|
@ -511,7 +513,7 @@ public sealed class BSLinksetConstraints : BSLinkset
|
||||||
RemoveDependencies(child);
|
RemoveDependencies(child);
|
||||||
|
|
||||||
BSLinkInfo linkInfo = null;
|
BSLinkInfo linkInfo = null;
|
||||||
if (m_children.TryGetValue(child, out linkInfo))
|
if (TryGetLinkInfo(child, out linkInfo))
|
||||||
{
|
{
|
||||||
BSLinkInfoConstraint linkInfoC = linkInfo as BSLinkInfoConstraint;
|
BSLinkInfoConstraint linkInfoC = linkInfo as BSLinkInfoConstraint;
|
||||||
if (linkInfoC != null)
|
if (linkInfoC != null)
|
||||||
|
@ -529,28 +531,129 @@ public sealed class BSLinksetConstraints : BSLinkset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ExtendedPhysics.PhysFunctChangeLinkParams:
|
case ExtendedPhysics.PhysFunctGetLinkType:
|
||||||
int setParam = 2;
|
if (pParams.Length > 0)
|
||||||
switch (setParam)
|
|
||||||
{
|
{
|
||||||
case ExtendedPhysics.PHYS_PARAM_FRAMEINA_LOC:
|
BSPrimLinkable child = pParams[0] as BSPrimLinkable;
|
||||||
case ExtendedPhysics.PHYS_PARAM_FRAMEINA_ROT:
|
if (child != null)
|
||||||
case ExtendedPhysics.PHYS_PARAM_FRAMEINB_LOC:
|
{
|
||||||
case ExtendedPhysics.PHYS_PARAM_FRAMEINB_ROT:
|
BSLinkInfo linkInfo = null;
|
||||||
case ExtendedPhysics.PHYS_PARAM_LINEAR_LIMIT_LOW:
|
if (TryGetLinkInfo(child, out linkInfo))
|
||||||
case ExtendedPhysics.PHYS_PARAM_LINEAR_LIMIT_HIGH:
|
{
|
||||||
case ExtendedPhysics.PHYS_PARAM_ANGULAR_LIMIT_LOW:
|
BSLinkInfoConstraint linkInfoC = linkInfo as BSLinkInfoConstraint;
|
||||||
case ExtendedPhysics.PHYS_PARAM_ANGULAR_LIMIT_HIGH:
|
if (linkInfoC != null)
|
||||||
case ExtendedPhysics.PHYS_PARAM_USE_FRAME_OFFSET:
|
{
|
||||||
case ExtendedPhysics.PHYS_PARAM_ENABLE_TRANSMOTOR:
|
ret = (object)(int)linkInfoC.constraintType;
|
||||||
case ExtendedPhysics.PHYS_PARAM_TRANSMOTOR_MAXVEL:
|
}
|
||||||
case ExtendedPhysics.PHYS_PARAM_TRANSMOTOR_MAXFORCE:
|
}
|
||||||
case ExtendedPhysics.PHYS_PARAM_CFM:
|
}
|
||||||
case ExtendedPhysics.PHYS_PARAM_ERP:
|
}
|
||||||
case ExtendedPhysics.PHYS_PARAM_SOLVER_ITERATIONS:
|
break;
|
||||||
case ExtendedPhysics.PHYS_PARAM_SPRING_DAMPING:
|
case ExtendedPhysics.PhysFunctChangeLinkParams:
|
||||||
case ExtendedPhysics.PHYS_PARAM_SPRING_STIFFNESS:
|
// There should be two parameters: the childActor and a list of parameters to set
|
||||||
break;
|
try
|
||||||
|
{
|
||||||
|
if (pParams.Length > 1)
|
||||||
|
{
|
||||||
|
BSPrimLinkable child = pParams[0] as BSPrimLinkable;
|
||||||
|
object[] setOps = (object[])pParams[1];
|
||||||
|
BSLinkInfo baseLinkInfo = null;
|
||||||
|
if (TryGetLinkInfo(child, out baseLinkInfo))
|
||||||
|
{
|
||||||
|
BSLinkInfoConstraint linkInfo = baseLinkInfo as BSLinkInfoConstraint;
|
||||||
|
if (linkInfo != null)
|
||||||
|
{
|
||||||
|
float valueFloat;
|
||||||
|
bool valueBool;
|
||||||
|
OMV.Vector3 valueVector;
|
||||||
|
OMV.Quaternion valueQuaternion;
|
||||||
|
|
||||||
|
int opIndex = 0;
|
||||||
|
while (opIndex < setOps.Length)
|
||||||
|
{
|
||||||
|
int thisOp = (int)setOps[opIndex];
|
||||||
|
switch (thisOp)
|
||||||
|
{
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_FRAMEINA_LOC:
|
||||||
|
valueVector = (OMV.Vector3)setOps[opIndex + 1];
|
||||||
|
linkInfo.frameInAloc = valueVector;
|
||||||
|
break;
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_FRAMEINA_ROT:
|
||||||
|
valueQuaternion = (OMV.Quaternion)setOps[opIndex + 1];
|
||||||
|
linkInfo.frameInArot = valueQuaternion;
|
||||||
|
break;
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_FRAMEINB_LOC:
|
||||||
|
valueVector = (OMV.Vector3)setOps[opIndex + 1];
|
||||||
|
linkInfo.frameInBloc = valueVector;
|
||||||
|
break;
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_FRAMEINB_ROT:
|
||||||
|
valueQuaternion = (OMV.Quaternion)setOps[opIndex + 1];
|
||||||
|
linkInfo.frameInBrot = valueQuaternion;
|
||||||
|
break;
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_LINEAR_LIMIT_LOW:
|
||||||
|
valueVector = (OMV.Vector3)setOps[opIndex + 1];
|
||||||
|
linkInfo.linearLimitLow = valueVector;
|
||||||
|
break;
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_LINEAR_LIMIT_HIGH:
|
||||||
|
valueVector = (OMV.Vector3)setOps[opIndex + 1];
|
||||||
|
linkInfo.linearLimitHigh = valueVector;
|
||||||
|
break;
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_ANGULAR_LIMIT_LOW:
|
||||||
|
valueVector = (OMV.Vector3)setOps[opIndex + 1];
|
||||||
|
linkInfo.angularLimitLow = valueVector;
|
||||||
|
break;
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_ANGULAR_LIMIT_HIGH:
|
||||||
|
valueVector = (OMV.Vector3)setOps[opIndex + 1];
|
||||||
|
linkInfo.angularLimitHigh = valueVector;
|
||||||
|
break;
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_USE_FRAME_OFFSET:
|
||||||
|
valueBool = (bool)setOps[opIndex + 1];
|
||||||
|
linkInfo.useFrameOffset = valueBool;
|
||||||
|
break;
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_ENABLE_TRANSMOTOR:
|
||||||
|
valueBool = (bool)setOps[opIndex + 1];
|
||||||
|
linkInfo.enableTransMotor = valueBool;
|
||||||
|
break;
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_TRANSMOTOR_MAXVEL:
|
||||||
|
valueFloat = (float)setOps[opIndex + 1];
|
||||||
|
linkInfo.transMotorMaxVel = valueFloat;
|
||||||
|
break;
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_TRANSMOTOR_MAXFORCE:
|
||||||
|
valueFloat = (float)setOps[opIndex + 1];
|
||||||
|
linkInfo.transMotorMaxForce = valueFloat;
|
||||||
|
break;
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_CFM:
|
||||||
|
valueFloat = (float)setOps[opIndex + 1];
|
||||||
|
linkInfo.cfm = valueFloat;
|
||||||
|
break;
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_ERP:
|
||||||
|
valueFloat = (float)setOps[opIndex + 1];
|
||||||
|
linkInfo.erp = valueFloat;
|
||||||
|
break;
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_SOLVER_ITERATIONS:
|
||||||
|
valueFloat = (float)setOps[opIndex + 1];
|
||||||
|
linkInfo.solverIterations = valueFloat;
|
||||||
|
break;
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_SPRING_DAMPING:
|
||||||
|
valueFloat = (float)setOps[opIndex + 1];
|
||||||
|
linkInfo.springDamping = valueFloat;
|
||||||
|
break;
|
||||||
|
case ExtendedPhysics.PHYS_PARAM_SPRING_STIFFNESS:
|
||||||
|
valueFloat = (float)setOps[opIndex + 1];
|
||||||
|
linkInfo.springStiffness = valueFloat;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// There are many ways to mess up the parameters. If not just right don't fail without some error.
|
||||||
|
m_physicsScene.Logger.WarnFormat("{0} bad parameters in physSetLinksetParams: {1}", LogHeader, e);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -317,14 +317,21 @@ public class BSPrimLinkable : BSPrimDisplaced
|
||||||
// Params: PhysActor linkedPrim, int typeCode
|
// Params: PhysActor linkedPrim, int typeCode
|
||||||
case ExtendedPhysics.PhysFunctChangeLinkType:
|
case ExtendedPhysics.PhysFunctChangeLinkType:
|
||||||
{
|
{
|
||||||
Linkset.Extension(pFunct, pParams);
|
ret = Linkset.Extension(pFunct, pParams);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// physGetLinkType(linknum);
|
||||||
|
// Params: PhysActor linkedPrim
|
||||||
|
case ExtendedPhysics.PhysFunctGetLinkType:
|
||||||
|
{
|
||||||
|
ret = Linkset.Extension(pFunct, pParams);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// physChangeLinkParams(linknum, [code, value, code, value, ...]);
|
// physChangeLinkParams(linknum, [code, value, code, value, ...]);
|
||||||
// Params: PhysActor linkedPrim, object[] params
|
// Params: PhysActor linkedPrim, object[] params
|
||||||
case ExtendedPhysics.PhysFunctChangeLinkParams:
|
case ExtendedPhysics.PhysFunctChangeLinkParams:
|
||||||
{
|
{
|
||||||
Linkset.Extension(pFunct, pParams);
|
ret = Linkset.Extension(pFunct, pParams);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue