29 using System.Collections.Generic;
31 using System.Reflection;
32 using System.Threading;
35 using OpenSim.Framework;
36 using OpenSim.Region.Framework.Interfaces;
37 using OpenSim.Region.Framework.Scenes;
38 using OpenSim.Region.PhysicsModules.SharedBase;
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 get {
return m_animations; }
58 public string CurrentMovementAnimation {
get;
private set; }
60 private int m_animTickFall;
61 private int m_animTickLand;
62 private int m_animTickJump;
64 public bool m_jumping =
false;
71 public bool Falling {
get;
private set; }
73 private float m_lastFallVelocity;
83 CurrentMovementAnimation =
"CROUCH";
88 if (m_scenePresence.IsChildAgent)
92 if (m_scenePresence.Scene.DebugAnimations)
94 "[SCENE PRESENCE ANIMATOR]: Adding animation {0} {1} for {2}",
95 GetAnimName(animID), animID, m_scenePresence.Name);
97 if (m_animations.Add(animID, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, objectID))
100 m_scenePresence.TriggerScenePresenceUpdated();
107 if (m_scenePresence.IsChildAgent)
112 UUID animID = DefaultAvatarAnimations.GetDefaultAnimation(name.ToUpper());
113 if (animID ==
UUID.Zero)
118 AddAnimation(animID, objectID);
131 if (m_scenePresence.IsChildAgent)
134 if (m_scenePresence.Scene.DebugAnimations)
136 "[SCENE PRESENCE ANIMATOR]: Removing animation {0} {1} for {2}",
137 GetAnimName(animID), animID, m_scenePresence.Name);
139 if (m_animations.Remove(animID, allowNoDefault))
142 m_scenePresence.TriggerScenePresenceUpdated();
148 if (m_scenePresence.IsChildAgent)
151 if (animID !=
UUID.Zero)
154 m_animations.Add(animID, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, UUID.Zero);
156 m_animations.Remove(animID,
false);
165 if (m_scenePresence.IsChildAgent)
170 UUID animID = DefaultAvatarAnimations.GetDefaultAnimation(name.ToUpper());
171 if (animID ==
UUID.Zero)
174 RemoveAnimation(animID,
true);
179 if (m_scenePresence.Scene.DebugAnimations)
181 "[SCENE PRESENCE ANIMATOR]: Resetting animations for {0} in {1}",
182 m_scenePresence.Name, m_scenePresence.Scene.RegionInfo.RegionName);
184 m_animations.Clear();
188 UUID aoSitGndAnim = UUID.Zero;
202 if (!m_scenePresence.IsChildAgent)
208 if (aoSitGndAnim !=
UUID.Zero)
210 avnChangeAnim(aoSitGndAnim,
false,
true);
211 aoSitGndAnim = UUID.Zero;
214 UUID overridenAnim = m_scenePresence.Overrides.GetOverriddenAnimation(anim);
215 if (overridenAnim !=
UUID.Zero)
217 if (anim ==
"SITGROUND")
219 UUID defsit = DefaultAvatarAnimations.AnimsUUID[
"SIT_GROUND_CONSTRAINED"];
220 if (defsit ==
UUID.Zero)
222 m_animations.SetDefaultAnimation(defsit, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, m_scenePresence.UUID);
223 aoSitGndAnim = overridenAnim;
224 avnChangeAnim(overridenAnim,
true,
false);
228 m_animations.SetDefaultAnimation(overridenAnim, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, m_scenePresence.UUID);
230 m_scenePresence.SendScriptEventToAttachments(
"changed",
new Object[] { (int)
Changed.ANIMATION });
237 if (anim ==
"SIT" || anim ==
"SITGROUND")
238 anim = m_scenePresence.sitAnimation;
240 if (m_animations.TrySetDefaultAnimation(
241 anim, m_scenePresence.ControllingClient.NextAnimationSequenceNumber, m_scenePresence.UUID))
248 m_scenePresence.SendScriptEventToAttachments(
"changed",
new Object[] { (int)
Changed.ANIMATION });
257 "[SCENE PRESENCE ANIMATOR]: Tried to set movement animation {0} on child presence {1}",
258 anim, m_scenePresence.Name);
278 private string DetermineMovementAnimation()
280 const int FALL_DELAY = 800;
281 const int PREJUMP_DELAY = 200;
282 const int JUMP_PERIOD = 800;
285 if (m_scenePresence.IsInTransit)
286 return CurrentMovementAnimation;
288 if (m_scenePresence.SitGround)
290 currentControlState = motionControlStates.sitted;
293 if (m_scenePresence.ParentID != 0 || m_scenePresence.ParentUUID !=
UUID.Zero)
295 currentControlState = motionControlStates.sitted;
299 AgentManager.ControlFlags controlFlags = (AgentManager.ControlFlags)m_scenePresence.AgentControlFlags;
302 const AgentManager.ControlFlags ANYXYMASK = (
303 AgentManager.ControlFlags.AGENT_CONTROL_AT_POS | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_POS |
304 AgentManager.ControlFlags.AGENT_CONTROL_AT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_AT_NEG |
305 AgentManager.ControlFlags.AGENT_CONTROL_LEFT_POS | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_POS |
306 AgentManager.ControlFlags.AGENT_CONTROL_LEFT_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_LEFT_NEG
316 bool heldTurnLeft = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_LEFT;
317 bool heldTurnRight = (controlFlags & AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT) == AgentManager.ControlFlags.AGENT_CONTROL_TURN_RIGHT;
320 bool heldUp = ((controlFlags & (AgentManager.ControlFlags.AGENT_CONTROL_UP_POS)) != 0);
321 bool heldDown = ((controlFlags & (AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG | AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG)) != 0);
325 bool heldOnXY = ((controlFlags & ANYXYMASK) != 0);
326 if (heldOnXY || heldUp || heldDown)
328 heldTurnLeft =
false;
329 heldTurnRight =
false;
339 currentControlState = motionControlStates.onsurface;
348 bool isColliding = actor.IsColliding;
357 currentControlState = motionControlStates.flying;
361 return (m_scenePresence.Scene.m_useFlySlow ?
"FLYSLOW" :
"FLY");
371 actor.Flying =
false;
372 currentControlState = motionControlStates.landing;
373 m_animTickLand = Environment.TickCount;
388 currentControlState = motionControlStates.landing;
389 m_animTickLand = Environment.TickCount;
396 #region Falling/Floating/Landing
400 float fallVelocity = actor.Velocity.Z;
403 if(actor.PIDHoverActive && fallVelocity < 0.05f)
406 currentControlState = motionControlStates.falling;
407 m_lastFallVelocity = fallVelocity;
411 if (fallVelocity < -2.5f)
414 if (m_animTickFall == 0 || (fallVelocity >= -0.5f))
416 m_animTickFall = Environment.TickCount;
420 int fallElapsed = (Environment.TickCount - m_animTickFall);
421 if ((fallElapsed > FALL_DELAY) && (fallVelocity < -3.0f))
423 currentControlState = motionControlStates.falling;
424 m_lastFallVelocity = fallVelocity;
431 if (CurrentMovementAnimation ==
"WALK" && !heldOnXY && !heldDown && !heldUp)
434 return CurrentMovementAnimation;
439 #endregion Falling/Floating/Landing
441 #region Jumping // section added for jumping...
443 if (isColliding && heldUp && currentControlState !=
motionControlStates.jumping && !actor.PIDHoverActive)
446 currentControlState = motionControlStates.jumping;
449 m_animTickJump = Environment.TickCount;
455 int jumptime = Environment.TickCount - m_animTickJump;
456 if ((jumptime > (JUMP_PERIOD * 1.5f)) && actor.IsColliding)
461 actor.Selected =
false;
462 m_animTickLand = Environment.TickCount;
463 currentControlState = motionControlStates.landing;
466 else if (jumptime > JUMP_PERIOD)
471 else if (jumptime > PREJUMP_DELAY)
477 return CurrentMovementAnimation;
482 #region Ground Movement
487 currentControlState = motionControlStates.landing;
488 m_animTickLand = Environment.TickCount;
490 float fallVsq = m_lastFallVelocity * m_lastFallVelocity;
493 else if (fallVsq > 160f)
503 int landElapsed = Environment.TickCount - m_animTickLand;
505 if (CurrentMovementAnimation ==
"LAND")
509 if ((m_animTickLand != 0) && (landElapsed <= limit))
511 return CurrentMovementAnimation;
515 currentControlState = motionControlStates.onsurface;
525 currentControlState = motionControlStates.onsurface;
534 else if (!m_scenePresence.AgentControlStopActive)
536 if (m_scenePresence.SetAlwaysRun)
544 currentControlState = motionControlStates.onsurface;
549 else if (heldTurnLeft)
551 else if (heldTurnRight)
556 #endregion Ground Movement
558 return CurrentMovementAnimation;
572 string newMovementAnimation = DetermineMovementAnimation();
573 if (CurrentMovementAnimation != newMovementAnimation)
575 CurrentMovementAnimation = newMovementAnimation;
583 ret = TrySetMovementAnimation(CurrentMovementAnimation);
593 CurrentMovementAnimation = DetermineMovementAnimation();
594 return TrySetMovementAnimation(CurrentMovementAnimation);
602 CurrentMovementAnimation = motionState;
603 return TrySetMovementAnimation(CurrentMovementAnimation);
612 m_animations.GetArrays(out animIDs, out sequenceNums, out objectIDs);
618 int rnditerations = 3;
620 List<string> parts =
new List<string>();
621 parts.Add(
"mPelvis"); parts.Add(
"mHead"); parts.Add(
"mTorso");
622 parts.Add(
"mHipLeft"); parts.Add(
"mHipRight"); parts.Add(
"mHipLeft"); parts.Add(
"mKneeLeft");
623 parts.Add(
"mKneeRight"); parts.Add(
"mCollarLeft"); parts.Add(
"mCollarRight"); parts.Add(
"mNeck");
624 parts.Add(
"mElbowLeft"); parts.Add(
"mElbowRight"); parts.Add(
"mWristLeft"); parts.Add(
"mWristRight");
625 parts.Add(
"mShoulderLeft"); parts.Add(
"mShoulderRight"); parts.Add(
"mAnkleLeft"); parts.Add(
"mAnkleRight");
626 parts.Add(
"mEyeRight"); parts.Add(
"mChest"); parts.Add(
"mToeLeft"); parts.Add(
"mToeRight");
627 parts.Add(
"mFootLeft"); parts.Add(
"mFootRight"); parts.Add(
"mEyeLeft");
630 anim.OutPoint = (rnditerations * .10f);
633 anim.Length = (rnditerations * .10f);
634 anim.ExpressionName =
"afraid";
636 anim.EaseOutTime = 0;
638 string[] strjoints = parts.ToArray();
640 for (
int j = 0; j < strjoints.Length; j++)
643 anim.Joints[j].Name = strjoints[j];
644 anim.Joints[j].Priority = 7;
647 Random rnd =
new Random();
648 for (
int i = 0; i < rnditerations; i++)
651 anim.Joints[j].rotationkeys[i].time = (i * .10f);
652 anim.Joints[j].rotationkeys[i].key_element.X = ((float)rnd.NextDouble() * 2 - 1);
653 anim.Joints[j].rotationkeys[i].key_element.Y = ((float)rnd.NextDouble() * 2 - 1);
654 anim.Joints[j].rotationkeys[i].key_element.Z = ((float)rnd.NextDouble() * 2 - 1);
656 anim.Joints[j].positionkeys[i].time = (i * .10f);
657 anim.Joints[j].positionkeys[i].key_element.X = 0;
658 anim.Joints[j].positionkeys[i].key_element.Y = 0;
659 anim.Joints[j].positionkeys[i].key_element.Z = 0;
663 AssetBase Animasset =
new AssetBase(
UUID.Random(),
"Random Animation", (sbyte)AssetType.Animation, m_scenePresence.UUID.ToString());
664 Animasset.Data = anim.ToBytes();
665 Animasset.Temporary =
true;
666 Animasset.Local =
true;
667 Animasset.Description =
"dance";
670 m_scenePresence.Scene.AssetService.Store(Animasset);
671 AddAnimation(Animasset.
FullID, m_scenePresence.UUID);
681 public void SendAnimPack(UUID[] animations,
int[] seqs, UUID[] objectIDs)
683 m_scenePresence.SendAnimPack(animations, seqs, objectIDs);
686 public void GetArrays(out UUID[] animIDs, out
int[] sequenceNums, out UUID[] objectIDs)
692 if (m_animations != null)
693 m_animations.GetArrays(out animIDs, out sequenceNums, out objectIDs);
698 if (m_scenePresence.IsChildAgent)
705 m_animations.GetArrays(out animIDs, out sequenceNums, out objectIDs);
706 client.SendAnimations(animIDs, sequenceNums, m_scenePresence.ControllingClient.AgentId, objectIDs);
716 if (m_scenePresence.IsChildAgent)
723 m_animations.GetArrays(out animIDs, out sequenceNums, out objectIDs);
726 m_scenePresence.SendAnimPack(animIDs, sequenceNums, objectIDs);
735 AssetMetadata amd = m_scenePresence.Scene.AssetService.GetMetadata(animId.ToString());
739 animName =
"Unknown";
UUID[] GetAnimationArray()
bool ForceUpdateMovementAnimations()
void SendAnimPack(UUID[] animations, int[] seqs, UUID[] objectIDs)
ScenePresenceAnimator(ScenePresence sp)
ScenePresence m_scenePresence
Information about an Animation
bool TrySetMovementAnimation(string anim)
The movement animation is reserved for "main" animations that are mutually exclusive, e.g. flying and sitting.
void avnChangeAnim(UUID animID, bool addRemove, bool sendPack)
Handle all animation duties for a scene presence
void SendAnimPackToClient(IClientAPI client)
void GetArrays(out UUID[] animIDs, out int[] sequenceNums, out UUID[] objectIDs)
Asset class. All Assets are reference by this class or a class derived from this class ...
Written to decode and encode a binary animation asset. The SecondLife Client reads in a BVH file and ...
BinBVHAnimation GenerateRandomAnimation()
void SendAnimPack()
Send animation information about this avatar to all clients.
A Joint and it's associated meta data and keyframes
void AddAnimation(string name, UUID objectID)
bool SetMovementAnimations(string motionState)
bool UpdateMovementAnimations()
Update the movement animation of this avatar according to its current state
void AddAnimation(UUID animID, UUID objectID)
void RemoveAnimation(string name)
static Dictionary< UUID, string > AnimsNames
string GetAnimName(UUID animId)
A Joint Keyframe. This is either a position or a rotation.
OpenSim.Region.Framework.Scenes.Animation.AnimationSet AnimationSet
void RemoveAnimation(UUID animID, bool allowNoDefault)
Remove the specified animation