internal void AvatarKicked(PhysxPrim physxPrim) { if (_standingOnPrim == physxPrim) { AvatarNotStandingOnPrim(); } }
public void AvatarStandingOn(PhysxPrim prim) { if (_standingOnPrim != prim) { _timeBeganStandingOnPrim = (uint)Environment.TickCount; _standingOnPrim = prim; } }
internal void AddPrimSync(PhysxPrim prim, bool physical, bool kinematicStatic) { _allPrims.Add(prim); if (physical) { _dynPrims.Add(prim); } if (kinematicStatic) { _kinematicManager.KinematicChanged(prim); } }
private bool TryInformPrimOfContactChange(PhysX.ContactPairHeader contactPairHeader, PhysX.ContactPair[] pairs, int actorIndex) { PhysxPrim prim = contactPairHeader.Actors[actorIndex].UserData as PhysxPrim; if (prim != null) { prim.OnContactChangeSync(contactPairHeader, pairs, actorIndex); return(true); } else { return(false); } }
void OnTrigger(PhysX.TriggerPair[] pairs) { foreach (var pair in pairs) { if (pair.TriggerShape != null) { PhysxPrim triggerPrim = pair.TriggerShape.Actor.UserData as PhysxPrim; if (triggerPrim != null) { triggerPrim.OnTrigger(pair); } } } }
internal void EndDelayCommands(PhysxPrim prim) { DelayedCommandInfo delayedCmds; if (_delayedCommands.TryGetValue(prim, out delayedCmds)) { _delayedCommands.Remove(prim); foreach (Commands.ICommand cmd in delayedCmds.Commands) { if (cmd.RemoveWaitAndCheckReady()) { this.EnqueueFreedCommand(cmd); } } } }
private void TransitionKinematic(PhysxPrim physxPrim) { //if the prim is selected, we want to leave it as a kinematic for a bit longer if (physxPrim.Selected) { this.KinematicChanged(physxPrim); return; } //if the prim is physical, it doesnt belong in here if (physxPrim.IsPhysical) { _trackedObjects.Remove(physxPrim); return; } //otherwise, this prim is a good candidate to be made static //note that there is no need to run this through meshing etc //as kinematics are "static" in the eyes of the mesh cache physxPrim.MakeStatic(); }
private void HandlePrimMadeStatic(PhysxPrim prim, TaintType taint) { this.QueueCommand(new Commands.SetPhysicalityCmd(prim, false)); }
/// <summary> /// Sets the given prim in our linkset to the given material /// </summary> /// <param name="material"></param> /// <param name="affectedPrim"></param> private void SetMaterialSync(Material material, PhysxPrim affectedPrim, bool applyToObject) { IEnumerable<PhysX.Shape> shapes; if (applyToObject) { ReplaceMaterialOnAllShapes(material); return; } if (affectedPrim == this) { shapes = _actor.Shapes; } else { RelatedShapes childShapes; if (_childShapes.TryGetValue(affectedPrim, out childShapes)) { shapes = childShapes.PhyShapes; } else { m_log.ErrorFormat("[InWorldz.PhysxPhysics] Asked to set material for unknown child shape"); return; } } ReplaceMaterialOnShapes(material, affectedPrim, shapes); }
/// <summary> /// Should be called when a kinematic is removed or changed to a static or dynamic /// </summary> /// <param name="obj"></param> public void KinematicRemoved(PhysxPrim obj) { _trackedObjects.Remove(obj); }
internal void DisableKinematicTransitionTracking(PhysxPrim physxPrim) { _kinematicManager.KinematicRemoved(physxPrim); }
internal void PrimMadeDynamic(PhysxPrim prim) { _dynPrims.Add(prim); _kinematicManager.KinematicRemoved(prim); }
internal void UpdateKinematic(PhysxPrim actor) { _kinematicManager.KinematicChanged(actor); }
private void SetToRemoveAfterReport(PhysX.Shape otherShape, PhysxPrim colPrim) { ExternalReport report; if (_externalCollisionReports.TryGetValue(otherShape, out report)) { if (report.Reported) { //this collision was reported already. remove it RemoveExternalCollidingPrimShape(otherShape, colPrim); } else { //this collision hasn't been reported yet. make sure the //collision processor knows to remove it after it is reported report.RemoveAfterReport = true; } } }
/// <summary> /// Should be called whenever a kinematic has changed to move it back down the list /// of objects to be made static /// </summary> /// <param name="obj"></param> public void KinematicChanged(PhysxPrim obj) { _trackedObjects[obj] = Util.GetLongTickCount(); }
private void ContactedActorDeleted(PhysxPrim deletedActor, PhysxPrim ourActor) { if (!_touchCounts.IsValueCreated) return; int touchCount; if (_touchCounts.Value.TryGetValue(deletedActor, out touchCount)) { ProcessContactChange(-touchCount, ourActor, deletedActor); } }
/// <summary> /// Called when a prim actor shape changes or an actor is deleted. /// This invalidates the controller cache to prevent PhysX crashes /// due to bugs /// </summary> /// <param name="prim"></param> internal void InvalidateControllerCacheIfContacting(PhysxPrim prim) { if (_collidingPrims.ContainsKey(prim)) { _controller.InvalidateCache(); } }
private void ContactedActorDeleted(PhysxPrim deletedActor) { if (_disposed) return; if (this.HasActor) { this.ContactedActorDeleted(deletedActor, this); } else { _parentPrim.ContactedActorDeleted(deletedActor, this); } }
public PhysxPrim(PhysxPrim parent, PhysxScene scene, PrimitiveBaseShape baseShape, OpenMetaverse.Vector3 pos, OpenMetaverse.Quaternion rotation, PhysicsShape myShape, PhysX.RigidActor myActor, bool isPhysical, IPhysicsProperties properties, CollisionGroupFlag collisionGroup) { _parentPrim = parent; _scene = scene; _pbs = baseShape; _position = pos; _rotation = rotation; _isPhysical = isPhysical; _properties = (PhysicsProperties)properties; _collisionGroup = collisionGroup; this.AssignActor(myActor, myShape, _isPhysical, DeleteActorFlags.None); if (_properties.VehicleProps != null && _properties.VehicleProps.Type != VehicleType.None) { //init dynamics CheckCreateVehicleDynamics(); } }
private void ReplaceMaterialOnShapes(Material material, PhysxPrim affectedPrim, IEnumerable<PhysX.Shape> shapes) { Material oldMaterial = affectedPrim.PhysxProperties.PhysxMaterial; affectedPrim.PhysxProperties.PhysxMaterial = material; PhysX.Material[] materialArr = new PhysX.Material[] { material.PhyMaterial }; foreach (PhysX.Shape shape in shapes) { shape.SetMaterials(materialArr); } if (oldMaterial.Density != material.Density) UpdateMassAndInertia(); oldMaterial.CheckedDispose(); }
internal void BeginDelayCommands(PhysxPrim prim, Commands.ICommand initiator) { DelayedCommandInfo info = new DelayedCommandInfo { Commands = new LinkedList<Commands.ICommand>(), Initiator = initiator }; _delayedCommands.Add(prim, info); }
private void RemoveExternalCollidingPrimShape(PhysX.Shape otherShape, PhysxPrim colPrim) { _externalCollisionReports.Remove(otherShape); HashSet<PhysX.Shape> primShapes; if (_externalCollisionPrims.TryGetValue(colPrim, out primShapes)) { primShapes.Remove(otherShape); if (primShapes.Count == 0) { _externalCollisionPrims.Remove(colPrim); colPrim.OnDeleted -= colPrim_OnDeleted; } } }
public void PrimWantsCollisionRepeat(PhysxPrim prim) { _collisionRepeatPrims.Add(prim); }
private void AddExternalCollidingPrimShape(PhysX.Shape otherShape, PhysxPrim colPrim) { _externalCollisionReports[otherShape] = new ExternalReport { RemoveAfterReport = false, Reported = false }; HashSet<PhysX.Shape> primShapes; if (!_externalCollisionPrims.TryGetValue(colPrim, out primShapes)) { primShapes = new HashSet<PhysX.Shape>(); _externalCollisionPrims.Add(colPrim, primShapes); colPrim.OnDeleted += colPrim_OnDeleted; } primShapes.Add(otherShape); }
private void HandlePrimChangedShape(PhysxPrim prim, TaintType taint) { this.QueueCommand(new Commands.ChangedShapeCmd(prim)); }
/// <summary> /// Called when one of the prims we're doing external tracking on is deleted or makes /// a shape/state change and our collision data becomes invalid /// </summary> /// <param name="obj"></param> void colPrim_OnDeleted(PhysxPrim obj) { HashSet<PhysX.Shape> shapes; if (_externalCollisionPrims.TryGetValue(obj, out shapes)) { foreach (var shape in shapes) { _externalCollisionReports.Remove(shape); } _externalCollisionPrims.Remove(obj); } }
internal void PrimMadeStaticKinematic(PhysxPrim actor) { _dynPrims.Remove(actor); _kinematicManager.KinematicChanged(actor); }
/// <summary> /// Called when a change has been posted for touches between one of our prims and an avatar. We must track /// these touches by shape because the collision detection is sometimes one sided in the case of an avatar /// touching a prim /// </summary> /// <param name="change"></param> /// <param name="other"></param> private void ProcessCharacterContactChange(int change, PhysxPrim ourPrim, PhysX.Shape primShape, PhysxCharacter other) { if (IsChild && _properties.WantsCollisionNotification) { HandleTrackedCharacterContactChange(change, ourPrim, primShape, other); } else if (IsChild && !_properties.WantsCollisionNotification) { _parentPrim.ProcessCharacterContactChange(change, ourPrim, primShape, other); } else if (HasActor && (_properties.WantsCollisionNotification || _properties.ChildrenWantCollisionNotification)) { HandleTrackedCharacterContactChange(change, ourPrim, primShape, other); } }
internal void AddPrimSync(PhysxPrim prim, bool physical, bool kinematicStatic) { _allPrims.Add(prim); if (physical) _dynPrims.Add(prim); if (kinematicStatic) _kinematicManager.KinematicChanged(prim); }
public void AvatarNotStandingOnPrim() { _standingOnPrim = null; _timeBeganStandingOnPrim = 0; }
internal void ChildPrimDeleted(PhysxPrim childPrim) { _collisionRepeatPrims.Remove(childPrim); }
internal void RemovePrim(PhysxPrim prim) { _dynPrims.Remove(prim); _allPrims.Remove(prim); _collisionRepeatPrims.Remove(prim); _kinematicManager.KinematicRemoved(prim); _delayedCommands.Remove(prim); prim.Dispose(); }
private void HandlePrimMadeDynamic(PhysxPrim prim, TaintType taint) { this.QueueCommand(new Commands.SetPhysicalityCmd(prim, true)); }
private void HandleTrackedCharacterContactChange(int change, PhysxPrim ourPrim, PhysX.Shape primShape, PhysxCharacter other) { HashSet<PhysX.Shape> collidingShapes; if (!_avatarTouchCounts.Value.TryGetValue(other, out collidingShapes)) { if (change < 0) { //we have no record of colliding with this object. therefore removing a //collision leaves no change to state return; } collidingShapes = new HashSet<PhysX.Shape>(); _avatarTouchCounts.Value[other] = collidingShapes; } if (change > 0 && !collidingShapes.Add(primShape)) { //we're already colliding with this object. no change in state return; } else if (change < 0 && !collidingShapes.Remove(primShape)) { //we weren't colliding with this object. no change in state return; } int newTotal = collidingShapes.Count; //m_log.DebugFormat("Char Contact Change: This: {0}, Other: {1}, Chg: {2}, Tot: {3}", this.SOPName, other.SOPName, change, collidingShapes.Count); if (newTotal == 0 && change < 0) { //we've lost all contact with this prim, notify of collision_end ourPrim.SendCollisionUpdate(new CollisionEventUpdate { OtherColliderLocalId = other.LocalID, Type = CollisionEventUpdateType.CharacterCollisionEnded }); _avatarTouchCounts.Value.Remove(other); return; } if (newTotal == 1 && change > 0) { //we have begun colliding with a new object ourPrim.SendCollisionUpdate(new CollisionEventUpdate { OtherColliderLocalId = other.LocalID, Type = CollisionEventUpdateType.CharacterCollisionBegan }); } return; }
private bool CheckAddDelay(Commands.ICommand cmd, PhysxPrim target) { DelayedCommandInfo delayInfo; if (_delayedCommands.TryGetValue(target, out delayInfo) && delayInfo.Initiator != cmd) { //if we're already the last delayed command delayed behind the other command //for the given prim, we only need to be added once per command so we can safely //just return if (delayInfo.Commands.Count > 0 && delayInfo.Commands.Last.Value == cmd) { return true; } //before adding this new command to wait, check to see if it is cullable. //if the command is cullable, and has the same targets, we replace it with this command //maintaining its position in the queue LinkedListNode<Commands.ICommand> cmdNode; if (cmd.IsCullable && delayInfo.TopCullables != null && delayInfo.TopCullables.TryGetValue(cmd.GetType(), out cmdNode) && HasSameTargets(cmdNode.Value, cmd)) { cmdNode.Value = cmd; if (cmd.AffectsMultiplePrims()) ((Commands.IMultiPrimCommand)cmd).AddDelay(); return true; } else { cmdNode = delayInfo.Commands.AddLast(cmd); if (cmd.AffectsMultiplePrims()) ((Commands.IMultiPrimCommand)cmd).AddDelay(); if (cmd.IsCullable) { if (delayInfo.TopCullables == null) { delayInfo.TopCullables = new Dictionary<Type, LinkedListNode<Commands.ICommand>>(); } delayInfo.TopCullables.Add(cmd.GetType(), cmdNode); } return true; } } return false; }
public void PrimDisabledCollisionRepeat(PhysxPrim prim) { _collisionRepeatPrims.Remove(prim); }
internal void PrimBecameChild(PhysxPrim prim) { _dynPrims.Remove(prim); _allPrims.Remove(prim); _kinematicManager.KinematicRemoved(prim); _delayedCommands.Remove(prim); }