public void PlayCharacterAnimation( string animationName, MyBlendOption blendOption, MyFrameOption frameOption, float blendTime, float timeScale = 1, bool sync = false, string influenceArea = null, //use defined boneset area from character definitions bool excludeLegsWhenMoving = false ) { bool disableAnimations = MySandboxGame.IsDedicated && MyPerGameSettings.DisableAnimationsOnDS; if (disableAnimations && !sync) { return; } if (!m_animationCommandsEnabled) { return; } if (animationName == null) { System.Diagnostics.Debug.Fail("Cannot play null animation!"); return; } string animationSubtype = null; if (!m_characterDefinition.AnimationNameToSubtypeName.TryGetValue(animationName, out animationSubtype)) { animationSubtype = animationName; } var command = new MyAnimationCommand() { AnimationSubtypeName = animationSubtype, PlaybackCommand = MyPlaybackCommand.Play, BlendOption = blendOption, FrameOption = frameOption, BlendTime = blendTime, TimeScale = timeScale, Area = influenceArea, ExcludeLegsWhenMoving = excludeLegsWhenMoving }; // CH: If we don't want to play the animation ourselves, but it has to be synced, we have to send it to clients at least if (disableAnimations && sync) { SyncObject.SendAnimationCommand(ref command); } else { AddCommand(command, sync); } }
public void Initialize(AnimationClip clip, MySkinnedEntity skinnedEntity, float weight, float timeScale, MyFrameOption frameOption, string[] explicitBones = null) { m_clip = clip; m_skinnedEntity = skinnedEntity; m_weight = weight; m_timeScale = timeScale; m_frameOption = frameOption; // Create the bone information classes var maxBoneCount = explicitBones == null ? clip.Bones.Count : explicitBones.Length; if (m_boneInfos == null || m_boneInfos.Length < maxBoneCount) { m_boneInfos = new BoneInfo[maxBoneCount]; } int neededBonesCount = 0; for (int b = 0; b < maxBoneCount; b++) { var bone = explicitBones == null ? clip.Bones[b] : FindBone(clip.Bones, explicitBones[b]); if (bone == null) { continue; } if (bone.Keyframes.Count == 0) { continue; } // Create it m_boneInfos[neededBonesCount] = new BoneInfo(bone, this); // Assign it to a model bone m_boneInfos[neededBonesCount].SetModel(skinnedEntity); neededBonesCount++; } m_boneCount = neededBonesCount; Position = 0; m_initialized = true; }
public void Initialize(AnimationPlayer player) { m_clip = player.Clip; m_skinnedEntity = player.m_skinnedEntity; m_weight = player.Weight; m_timeScale = player.m_timeScale; m_frameOption = player.m_frameOption; m_boneCount = player.m_boneCount; if (m_boneInfos == null || m_boneInfos.Length < m_boneCount) { m_boneInfos = new BoneInfo[m_boneCount]; } Position = player.Position; for (int b = 0; b < m_boneCount; b++) { if (m_boneInfos[b] == null) { m_boneInfos[b] = new BoneInfo(); } // Create it m_boneInfos[b].ClipBone = player.m_boneInfos[b].ClipBone; m_boneInfos[b].Player = this; // Assign it to a model bone m_boneInfos[b].SetModel(m_skinnedEntity); m_boneInfos[b].CurrentKeyframe = player.m_boneInfos[b].CurrentKeyframe; m_boneInfos[b].SetPosition(Position); if (MyFakes.ENABLE_BONES_AND_ANIMATIONS_DEBUG) { int index; System.Diagnostics.Debug.Assert(m_skinnedEntity.FindBone(m_boneInfos[b].ClipBone.Name, out index) != null, "Can not find clip bone with name: " + m_boneInfos[b].ClipBone.Name + " in model: " + m_skinnedEntity.Name); } } m_initialized = true; }
public void PlayCharacterAnimation( string animationName, MyBlendOption blendOption, MyFrameOption frameOption, float blendTime, float timeScale = 1, bool sync = false, string influenceArea = null, //use defined boneset area from character definitions bool excludeLegsWhenMoving = false ) { if (animationName == null) { System.Diagnostics.Debug.Fail("Cannot play null animation!"); return; } string animationSubtype = null; if (!m_characterDefinition.AnimationNameToSubtypeName.TryGetValue(animationName, out animationSubtype)) { animationSubtype = animationName; } AddCommand(new MyAnimationCommand() { AnimationSubtypeName = animationSubtype, PlaybackCommand = MyPlaybackCommand.Play, BlendOption = blendOption, FrameOption = frameOption, BlendTime = blendTime, TimeScale = timeScale, Area = influenceArea, ExcludeLegsWhenMoving = excludeLegsWhenMoving }, sync); }
protected override void OnAnimationPlay(MyAnimationDefinition animDefinition, MyAnimationCommand command, ref string bonesArea, ref MyFrameOption frameOption, ref bool useFirstPersonVersion) { var currentMovementState = GetCurrentMovementState(); if (DefinitionId.Value.SubtypeId == medievelMaleSubtypeId) { if (command.ExcludeLegsWhenMoving) { //In this case, we must stop all upper animations correctly if (currentMovementState == MyCharacterMovementEnum.RotatingLeft || currentMovementState == MyCharacterMovementEnum.RotatingRight || currentMovementState == MyCharacterMovementEnum.Standing) { bonesArea = TopBody + " LowerBody"; } else { bonesArea = TopBody; } frameOption = frameOption != MyFrameOption.JustFirstFrame ? MyFrameOption.PlayOnce : frameOption; } else if (m_lastBonesArea == TopBody + " LowerBody") { StopLowerCharacterAnimation(0.2f); } m_lastBonesArea = bonesArea; } else { if (currentMovementState != MyCharacterMovementEnum.Standing && currentMovementState != MyCharacterMovementEnum.RotatingLeft && currentMovementState != MyCharacterMovementEnum.RotatingRight && command.ExcludeLegsWhenMoving) { //In this case, we must stop all upper animations correctly bonesArea = TopBody; frameOption = frameOption != MyFrameOption.JustFirstFrame ? MyFrameOption.PlayOnce : frameOption; } } useFirstPersonVersion = IsInFirstPersonView; if (animDefinition.AllowWithWeapon) { if (!UseAnimationForWeapon) { StoreWeaponRelativeMatrix(); UseAnimationForWeapon = true; m_resetWeaponAnimationState = true; } } if (!animDefinition.LeftHandItem.TypeId.IsNull) { if (m_leftHandItem != null) { (m_leftHandItem as IMyHandheldGunObject <Sandbox.Game.Weapons.MyDeviceBase>).OnControlReleased(); m_leftHandItem.Close(); } // CH: TODO: The entity id is not synced, but it never was in this place. It should be fixed later long handItemId = MyEntityIdentifier.AllocateId(); uint?inventoryItemId = null; var builder = GetObjectBuilderForWeapon(animDefinition.LeftHandItem, ref inventoryItemId, handItemId); var leftHandItem = CreateGun(builder, inventoryItemId); if (leftHandItem != null) { m_leftHandItem = leftHandItem as MyEntity; leftHandItem.OnControlAcquired(this); UpdateLeftHandItemPosition(); MyEntities.Add(m_leftHandItem); } } }
protected override void OnAnimationPlay(MyAnimationDefinition animDefinition, MyAnimationCommand command, ref string bonesArea, ref MyFrameOption frameOption, ref bool useFirstPersonVersion) { var currentMovementState = GetCurrentMovementState(); if (DefinitionId.Value.SubtypeId == medievelMaleSubtypeId) { if (command.ExcludeLegsWhenMoving) { //In this case, we must stop all upper animations correctly if (currentMovementState == MyCharacterMovementEnum.RotatingLeft || currentMovementState == MyCharacterMovementEnum.RotatingRight || currentMovementState == MyCharacterMovementEnum.Standing) { bonesArea = TopBody + " LowerBody"; } else { bonesArea = TopBody; } frameOption = frameOption != MyFrameOption.JustFirstFrame ? MyFrameOption.PlayOnce : frameOption; } else if (m_lastBonesArea == TopBody + " LowerBody") { StopLowerCharacterAnimation(0.2f); } m_lastBonesArea = bonesArea; } else { if (currentMovementState != MyCharacterMovementEnum.Standing && currentMovementState != MyCharacterMovementEnum.RotatingLeft && currentMovementState != MyCharacterMovementEnum.RotatingRight && command.ExcludeLegsWhenMoving) { //In this case, we must stop all upper animations correctly bonesArea = TopBody; frameOption = frameOption != MyFrameOption.JustFirstFrame ? MyFrameOption.PlayOnce : frameOption; } } useFirstPersonVersion = IsInFirstPersonView; if (animDefinition.AllowWithWeapon) { m_resetWeaponAnimationState = true; } }
public void Initialize(AnimationPlayer player) { m_clip = player.Clip; m_skinnedEntity = player.m_skinnedEntity; m_weight = player.Weight; m_timeScale = player.m_timeScale; m_frameOption = player.m_frameOption; m_boneCount = player.m_boneCount; if (m_boneInfos == null || m_boneInfos.Length < m_boneCount) m_boneInfos = new BoneInfo[m_boneCount]; Position = player.Position; for (int b = 0; b < m_boneCount; b++) { if (m_boneInfos[b] == null) m_boneInfos[b] = new BoneInfo(); // Create it m_boneInfos[b].ClipBone = player.m_boneInfos[b].ClipBone; m_boneInfos[b].Player = this; // Assign it to a model bone m_boneInfos[b].SetModel(m_skinnedEntity); m_boneInfos[b].CurrentKeyframe = player.m_boneInfos[b].CurrentKeyframe; m_boneInfos[b].SetPosition(Position); if (MyFakes.ENABLE_BONES_AND_ANIMATIONS_DEBUG) { int index; System.Diagnostics.Debug.Assert(m_skinnedEntity.FindBone(m_boneInfos[b].ClipBone.Name, out index) != null, "Can not find clip bone with name: " + m_boneInfos[b].ClipBone.Name + " in model: " + m_skinnedEntity.Name); } } m_initialized = true; }
protected override void OnAnimationPlay(MyAnimationDefinition animDefinition, MyAnimationCommand command, ref string bonesArea, ref MyFrameOption frameOption, ref bool useFirstPersonVersion) { if (GetCurrentMovementState() != MyCharacterMovementEnum.Standing && GetCurrentMovementState() != MyCharacterMovementEnum.RotatingLeft && GetCurrentMovementState() != MyCharacterMovementEnum.RotatingRight && command.ExcludeLegsWhenMoving) { //In this case, we must stop all upper animations correctly bonesArea = TopBody; frameOption = MyFrameOption.None; } useFirstPersonVersion = IsInFirstPersonView; if (animDefinition.AllowWithWeapon) { if (!UseAnimationForWeapon) { StoreWeaponRelativeMatrix(); UseAnimationForWeapon = true; m_resetWeaponAnimationState = true; } } if (!animDefinition.LeftHandItem.TypeId.IsNull) { if (m_leftHandItem != null) { (m_leftHandItem as IMyHandheldGunObject <Sandbox.Game.Weapons.MyDeviceBase>).OnControlReleased(); m_leftHandItem.Close(); } m_leftHandItem = MyEntityFactory.CreateEntity(animDefinition.LeftHandItem.TypeId); var ob = MyEntityFactory.CreateObjectBuilder(m_leftHandItem); m_leftHandItem.Init(ob); (m_leftHandItem as IMyHandheldGunObject <Sandbox.Game.Weapons.MyDeviceBase>).OnControlAcquired(this); UpdateLeftHandItemPosition(); MyEntities.Add(m_leftHandItem); } }
public void Play(MyAnimationDefinition animationDefinition, bool firstPerson, MyFrameOption frameOption, float blendTime, float timeScale) { string model = firstPerson && !string.IsNullOrEmpty(animationDefinition.AnimationModelFPS) ? animationDefinition.AnimationModelFPS : animationDefinition.AnimationModel; System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(model)); if (string.IsNullOrEmpty(animationDefinition.AnimationModel)) return; if (animationDefinition.Status == MyAnimationDefinition.AnimationStatus.Unchecked) { var fsPath = System.IO.Path.IsPathRooted(model) ? model : System.IO.Path.Combine(MyFileSystem.ContentPath, model); if (!MyFileSystem.FileExists(fsPath)) { animationDefinition.Status = MyAnimationDefinition.AnimationStatus.Failed; return; } } animationDefinition.Status = MyAnimationDefinition.AnimationStatus.OK; MyModel animation = VRage.Game.Models.MyModels.GetModelOnlyAnimationData(model); Debug.Assert(animation != null && animation.Animations != null && animation.Animations.Clips.Count > 0); if (animation != null && animation.Animations == null || animation.Animations.Clips.Count == 0) return; Debug.Assert(animationDefinition.ClipIndex < animation.Animations.Clips.Count); if (animation.Animations.Clips.Count <= animationDefinition.ClipIndex) return; if (ActualPlayer.IsInitialized) { BlendPlayer.Initialize(ActualPlayer); } // Create a clip player and assign it to this model ActualPlayer.Initialize(animation, m_name, animationDefinition.ClipIndex, m_skinnedEntity, 1, timeScale, frameOption, m_bones, m_boneLODs); ActualPlayer.AnimationMwmPathDebug = model; ActualPlayer.AnimationNameDebug = animationDefinition.Id.SubtypeName; m_state = AnimationBlendState.BlendIn; m_currentBlendTime = 0; m_totalBlendTime = blendTime; }
public void Initialize(MyModel animationModel, string playerName, int clipIndex, MySkinnedEntity skinnedEntity, float weight, float timeScale, MyFrameOption frameOption, string[] explicitBones = null, Dictionary<float, string[]> boneLODs = null) { if (m_hash != 0) { CachedAnimationPlayers.Remove(m_hash); m_hash = 0; } var clip = animationModel.Animations.Clips[clipIndex]; Name = MyStringId.GetOrCompute(animationModel.AssetName + " : " + playerName); m_duration = (float)clip.Duration; m_skinnedEntity = skinnedEntity; m_weight = weight; m_timeScale = timeScale; m_frameOption = frameOption; foreach (var list in m_boneLODs.Values) list.Clear(); //m_boneLODs.Clear(); List<BoneInfo> lod0; if (!m_boneLODs.TryGetValue(0, out lod0)) { lod0 = new List<BoneInfo>(); m_boneLODs.Add(0, lod0); } // Create the bone information classes var maxBoneCount = explicitBones == null ? clip.Bones.Count : explicitBones.Length; if (m_boneInfos == null || m_boneInfos.Length < maxBoneCount) m_boneInfos = new BoneInfo[maxBoneCount]; int neededBonesCount = 0; for (int b = 0; b < maxBoneCount; b++) { var bone = explicitBones == null ? clip.Bones[b] : FindBone(clip.Bones, explicitBones[b]); if (bone == null) continue; if (bone.Keyframes.Count == 0) continue; // Create it BoneInfo boneInfo = m_boneInfos[neededBonesCount]; if(m_boneInfos[neededBonesCount] == null) boneInfo = new BoneInfo(bone, this); else { boneInfo.Clear(); boneInfo.Init(bone, this); } m_boneInfos[neededBonesCount] = boneInfo; // Assign it to a model bone m_boneInfos[neededBonesCount].SetModel(skinnedEntity); if (boneInfo.ModelBone != null) { lod0.Add(boneInfo); if (boneLODs != null) { foreach (var boneLOD in boneLODs) { List<BoneInfo> lodBones; if (!m_boneLODs.TryGetValue(boneLOD.Key, out lodBones)) { lodBones = new List<BoneInfo>(); m_boneLODs.Add(boneLOD.Key, lodBones); } foreach (var boneName in boneLOD.Value) { if (boneInfo.ModelBone.Name == boneName) { lodBones.Add(boneInfo); break; } } } } } neededBonesCount++; } m_boneCount = neededBonesCount; Position = 0; m_initialized = true; }
/// <summary> /// Virtual method called when animation is started, used in MyCharacter. /// </summary> protected virtual void OnAnimationPlay(MyAnimationDefinition animDefinition, MyAnimationCommand command, ref string bonesArea, ref MyFrameOption frameOption, ref bool useFirstPersonVersion) { }
public void Initialize(AnimationPlayer player) { if (m_hash != 0) { CachedAnimationPlayers.Remove(m_hash); m_hash = 0; } Name = player.Name; m_duration = player.m_duration; m_skinnedEntity = player.m_skinnedEntity; m_weight = player.Weight; m_timeScale = player.m_timeScale; m_frameOption = player.m_frameOption; foreach (var list in m_boneLODs.Values) { list.Clear(); } //m_boneLODs.Clear(); m_boneCount = player.m_boneCount; if (m_boneInfos == null || m_boneInfos.Length < m_boneCount) { m_boneInfos = new BoneInfo[m_boneCount]; } Position = player.Position; for (int b = 0; b < m_boneCount; b++) { var boneInfo = m_boneInfos[b]; if (boneInfo == null) { boneInfo = new BoneInfo(); m_boneInfos[b] = boneInfo; } // Create it boneInfo.ClipBone = player.m_boneInfos[b].ClipBone; boneInfo.Player = this; // Assign it to a model bone boneInfo.SetModel(m_skinnedEntity); boneInfo.CurrentKeyframe = player.m_boneInfos[b].CurrentKeyframe; boneInfo.SetPosition(Position); if (player.m_boneLODs != null && boneInfo.ModelBone != null && ENABLE_ANIMATION_LODS) { foreach (var boneLOD in player.m_boneLODs) { List <BoneInfo> lodBones; if (!m_boneLODs.TryGetValue(boneLOD.Key, out lodBones)) { lodBones = new List <BoneInfo>(); m_boneLODs.Add(boneLOD.Key, lodBones); } foreach (var boneName in boneLOD.Value) { if (boneName.ModelBone == null) { continue; } if (boneInfo.ModelBone.Name == boneName.ModelBone.Name) { lodBones.Add(boneInfo); break; } } } } if (MyFakes.ENABLE_BONES_AND_ANIMATIONS_DEBUG) { int index; System.Diagnostics.Debug.Assert(m_skinnedEntity.AnimationController.FindBone(boneInfo.ClipBone.Name, out index) != null, "Can not find clip bone with name: " + boneInfo.ClipBone.Name + " in model: " + m_skinnedEntity.Name); } } m_initialized = true; }
internal void PlayersPlay(string bonesArea, MyAnimationDefinition animDefinition, bool firstPerson, MyFrameOption frameOption, float blendTime, float timeScale) { string[] players = bonesArea.Split(' '); if (animDefinition.AnimationSets != null) { foreach (var animationSet in animDefinition.AnimationSets) { var animationSetData = new MyAnimationSetData() { BlendTime = blendTime, Area = bonesArea, AnimationSet = animationSet }; if (animationSet.Continuous) { m_continuingAnimSets.Add(animationSetData); continue; } PlayAnimationSet(animationSetData); } return; } foreach (var player in players) { PlayerPlay(player, animDefinition, firstPerson, frameOption, blendTime, timeScale); } }
internal void PlayerPlay(string playerName, MyAnimationDefinition animDefinition, bool firstPerson, MyFrameOption frameOption, float blendTime, float timeScale) { MyAnimationPlayerBlendPair player; if (TryGetAnimationPlayer(playerName, out player)) { player.Play(animDefinition, firstPerson, frameOption, blendTime, timeScale); } // else // Debug.Fail("Non existing animation set"); }
protected override void OnAnimationPlay(MyAnimationDefinition animDefinition,MyAnimationCommand command, ref string bonesArea, ref MyFrameOption frameOption, ref bool useFirstPersonVersion) { var currentMovementState = GetCurrentMovementState(); if (currentMovementState != MyCharacterMovementEnum.Standing && currentMovementState != MyCharacterMovementEnum.RotatingLeft && currentMovementState != MyCharacterMovementEnum.RotatingRight && command.ExcludeLegsWhenMoving) { //In this case, we must stop all upper animations correctly bonesArea = TopBody; frameOption = frameOption != MyFrameOption.JustFirstFrame ? MyFrameOption.PlayOnce : frameOption; } useFirstPersonVersion = IsInFirstPersonView; if (animDefinition.AllowWithWeapon) { if (!UseAnimationForWeapon) { StoreWeaponRelativeMatrix(); UseAnimationForWeapon = true; m_resetWeaponAnimationState = true; } } if (!animDefinition.LeftHandItem.TypeId.IsNull) { if (m_leftHandItem != null) { (m_leftHandItem as IMyHandheldGunObject<Sandbox.Game.Weapons.MyDeviceBase>).OnControlReleased(); m_leftHandItem.Close(); } m_leftHandItem = MyEntityFactory.CreateEntity(animDefinition.LeftHandItem.TypeId); var ob = MyEntityFactory.CreateObjectBuilder(m_leftHandItem); m_leftHandItem.Init(ob); (m_leftHandItem as IMyHandheldGunObject<Sandbox.Game.Weapons.MyDeviceBase>).OnControlAcquired(this); UpdateLeftHandItemPosition(); MyEntities.Add(m_leftHandItem); } }
public virtual void Shoot(MyShootActionEnum shootAction, VRageMath.Vector3 direction, string gunAction) { m_shotToolAction = null; m_wasShooting = false; m_swingSoundPlayed = false; m_isHit = false; if (!string.IsNullOrEmpty(gunAction)) { switch (shootAction) { case MyShootActionEnum.PrimaryAction: GetPreferredToolAction(m_toolItemDef.PrimaryActions, gunAction, out m_primaryToolAction, out m_primaryHitCondition); break; case MyShootActionEnum.SecondaryAction: GetPreferredToolAction(m_toolItemDef.SecondaryActions, gunAction, out m_secondaryToolAction, out m_secondaryHitCondition); break; } } switch (shootAction) { case MyShootActionEnum.PrimaryAction: m_shotToolAction = m_primaryToolAction; m_shotHitCondition = m_primaryHitCondition; break; case MyShootActionEnum.SecondaryAction: m_shotToolAction = m_secondaryToolAction; m_shotHitCondition = m_secondaryHitCondition; break; default: System.Diagnostics.Debug.Fail("Unknown shooting state!"); break; } MyTuple <ushort, MyStringHash> message; if (!string.IsNullOrEmpty(m_shotHitCondition.StatsAction) && m_owner.StatComp != null && !m_owner.StatComp.CanDoAction(m_shotHitCondition.StatsAction, out message)) { if (MySession.Static != null && MySession.Static.LocalCharacter == m_owner && message.Item1 == MyStatLogic.STAT_VALUE_TOO_LOW && message.Item2.String.CompareTo("Stamina") == 0) { m_notEnoughStatNotification.SetTextFormatArguments(message.Item2); MyHud.Notifications.Add(m_notEnoughStatNotification); } return; } if (m_shotToolAction.HasValue) { IMyHandToolComponent toolComponent; if (m_toolComponents.TryGetValue(m_shotHitCondition.Component, out toolComponent)) { toolComponent.Shoot(); } MyFrameOption frameOption = MyFrameOption.StayOnLastFrame; if (m_shotToolAction.Value.HitDuration == 0) { frameOption = MyFrameOption.JustFirstFrame; } // Stop upper character animation called because character can have some animation set (blocking, ...). m_owner.StopUpperCharacterAnimation(0.1f); m_owner.PlayCharacterAnimation(m_shotHitCondition.Animation, MyBlendOption.Immediate, frameOption, 0.2f, m_shotHitCondition.AnimationTimeScale, false, null, true); if (m_owner.StatComp != null) { if (!string.IsNullOrEmpty(m_shotHitCondition.StatsAction)) { m_owner.StatComp.DoAction(m_shotHitCondition.StatsAction); } if (!string.IsNullOrEmpty(m_shotHitCondition.StatsModifier)) { m_owner.StatComp.ApplyModifier(m_shotHitCondition.StatsModifier); } } Physics.Enabled = m_shotToolAction.Value.Name == BlockId; m_lastShot = MySandboxGame.Static.UpdateTime; } }
protected override void OnAnimationPlay(MyAnimationDefinition animDefinition,MyAnimationCommand command, ref string bonesArea, ref MyFrameOption frameOption, ref bool useFirstPersonVersion) { var currentMovementState = GetCurrentMovementState(); if (DefinitionId.Value.SubtypeId == medievelMaleSubtypeId) { if (command.ExcludeLegsWhenMoving) { //In this case, we must stop all upper animations correctly if (currentMovementState == MyCharacterMovementEnum.RotatingLeft || currentMovementState == MyCharacterMovementEnum.RotatingRight || currentMovementState == MyCharacterMovementEnum.Standing) bonesArea = TopBody + " LowerBody"; else bonesArea = TopBody; frameOption = frameOption != MyFrameOption.JustFirstFrame ? MyFrameOption.PlayOnce : frameOption; } else if (m_lastBonesArea == TopBody + " LowerBody") StopLowerCharacterAnimation(0.2f); m_lastBonesArea = bonesArea; } else { if (currentMovementState != MyCharacterMovementEnum.Standing && currentMovementState != MyCharacterMovementEnum.RotatingLeft && currentMovementState != MyCharacterMovementEnum.RotatingRight && command.ExcludeLegsWhenMoving) { //In this case, we must stop all upper animations correctly bonesArea = TopBody; frameOption = frameOption != MyFrameOption.JustFirstFrame ? MyFrameOption.PlayOnce : frameOption; } } useFirstPersonVersion = IsInFirstPersonView; if (animDefinition.AllowWithWeapon) { if (!UseAnimationForWeapon) { UseAnimationForWeapon = true; m_resetWeaponAnimationState = true; } } }
protected virtual void OnAnimationPlay(MyAnimationDefinition animDefinition, MyAnimationCommand command, ref string bonesArea, ref MyFrameOption frameOption, ref bool useFirstPersonVersion) { }
public void PlayCharacterAnimation( string animationName, MyBlendOption blendOption, MyFrameOption frameOption, float blendTime, float timeScale = 1, bool sync = false, string influenceArea = null, //use defined boneset area from character definitions bool excludeLegsWhenMoving = false ) { if (UseNewAnimationSystem) return; bool disableAnimations = MySandboxGame.IsDedicated && MyPerGameSettings.DisableAnimationsOnDS; if (disableAnimations && !sync) { return; } if (!m_animationCommandsEnabled) return; if (animationName == null) { System.Diagnostics.Debug.Fail("Cannot play null animation!"); return; } string animationSubtype = null; if (!m_characterDefinition.AnimationNameToSubtypeName.TryGetValue(animationName, out animationSubtype)) { animationSubtype = animationName; } var command = new MyAnimationCommand() { AnimationSubtypeName = animationSubtype, PlaybackCommand = MyPlaybackCommand.Play, BlendOption = blendOption, FrameOption = frameOption, BlendTime = blendTime, TimeScale = timeScale, Area = influenceArea, ExcludeLegsWhenMoving = excludeLegsWhenMoving }; // CH: If we don't want to play the animation ourselves, but it has to be synced, we have to send it to clients at least // MZ: when sync is on, we always want to send the message if (sync) { SendAnimationCommand(ref command); } else { // if animations are disabled and sync is off, don't do anything if (!disableAnimations) AddCommand(command, sync); } }
public void Initialize(MyModel animationModel, string playerName, int clipIndex, MySkinnedEntity skinnedEntity, float weight, float timeScale, MyFrameOption frameOption, string[] explicitBones = null, Dictionary <float, string[]> boneLODs = null) { if (m_hash != 0) { CachedAnimationPlayers.Remove(m_hash); m_hash = 0; } var clip = animationModel.Animations.Clips[clipIndex]; Name = MyStringId.GetOrCompute(animationModel.AssetName + " : " + playerName); m_duration = (float)clip.Duration; m_skinnedEntity = skinnedEntity; m_weight = weight; m_timeScale = timeScale; m_frameOption = frameOption; foreach (var list in m_boneLODs.Values) { list.Clear(); } //m_boneLODs.Clear(); List <BoneInfo> lod0; if (!m_boneLODs.TryGetValue(0, out lod0)) { lod0 = new List <BoneInfo>(); m_boneLODs.Add(0, lod0); } // Create the bone information classes var maxBoneCount = explicitBones == null ? clip.Bones.Count : explicitBones.Length; if (m_boneInfos == null || m_boneInfos.Length < maxBoneCount) { m_boneInfos = new BoneInfo[maxBoneCount]; } int neededBonesCount = 0; for (int b = 0; b < maxBoneCount; b++) { var bone = explicitBones == null ? clip.Bones[b] : FindBone(clip.Bones, explicitBones[b]); if (bone == null) { continue; } if (bone.Keyframes.Count == 0) { continue; } // Create it BoneInfo boneInfo = m_boneInfos[neededBonesCount]; if (m_boneInfos[neededBonesCount] == null) { boneInfo = new BoneInfo(bone, this); } else { boneInfo.Clear(); boneInfo.Init(bone, this); } m_boneInfos[neededBonesCount] = boneInfo; // Assign it to a model bone m_boneInfos[neededBonesCount].SetModel(skinnedEntity); if (boneInfo.ModelBone != null) { lod0.Add(boneInfo); if (boneLODs != null) { foreach (var boneLOD in boneLODs) { List <BoneInfo> lodBones; if (!m_boneLODs.TryGetValue(boneLOD.Key, out lodBones)) { lodBones = new List <BoneInfo>(); m_boneLODs.Add(boneLOD.Key, lodBones); } foreach (var boneName in boneLOD.Value) { if (boneInfo.ModelBone.Name == boneName) { lodBones.Add(boneInfo); break; } } } } } neededBonesCount++; } m_boneCount = neededBonesCount; Position = 0; m_initialized = true; }
public void Initialize(MyModel animationModel, string playerName, int clipIndex, MySkinnedEntity skinnedEntity, float weight, float timeScale, MyFrameOption frameOption, string[] explicitBones = null, Dictionary <float, string[]> boneLODs = null) { List <BoneInfo> list; if (this.m_hash != 0) { CachedAnimationPlayers.Remove(this.m_hash); this.m_hash = 0; } MyAnimationClip clip = animationModel.Animations.Clips[clipIndex]; this.Name = MyStringId.GetOrCompute(animationModel.AssetName + " : " + playerName); this.m_duration = (float)clip.Duration; this.m_skinnedEntity = skinnedEntity; this.m_weight = weight; this.m_timeScale = timeScale; this.m_frameOption = frameOption; using (Dictionary <float, List <BoneInfo> > .ValueCollection.Enumerator enumerator = this.m_boneLODs.Values.GetEnumerator()) { while (enumerator.MoveNext()) { enumerator.Current.Clear(); } } if (!this.m_boneLODs.TryGetValue(0f, out list)) { list = new List <BoneInfo>(); this.m_boneLODs.Add(0f, list); } int num = (explicitBones == null) ? clip.Bones.Count : explicitBones.Length; if ((this.m_boneInfos == null) || (this.m_boneInfos.Length < num)) { this.m_boneInfos = new BoneInfo[num]; } int index = 0; for (int i = 0; i < num; i++) { MyAnimationClip.Bone bone = (explicitBones == null) ? clip.Bones[i] : this.FindBone(clip.Bones, explicitBones[i]); if ((bone != null) && (bone.Keyframes.Count != 0)) { BoneInfo item = this.m_boneInfos[index]; if (this.m_boneInfos[index] == null) { item = new BoneInfo(bone, this); } else { item.Clear(); item.Init(bone, this); } this.m_boneInfos[index] = item; this.m_boneInfos[index].SetModel(skinnedEntity); if (item.ModelBone != null) { list.Add(item); if (boneLODs != null) { foreach (KeyValuePair <float, string[]> pair in boneLODs) { List <BoneInfo> list2; if (!this.m_boneLODs.TryGetValue(pair.Key, out list2)) { list2 = new List <BoneInfo>(); this.m_boneLODs.Add(pair.Key, list2); } foreach (string str in pair.Value) { if (item.ModelBone.Name == str) { list2.Add(item); break; } } } } } index++; } } this.m_boneCount = index; this.Position = 0f; this.m_initialized = true; }
public void Initialize(AnimationPlayer player) { if (m_hash != 0) { CachedAnimationPlayers.Remove(m_hash); m_hash = 0; } Name = player.Name; m_duration = player.m_duration; m_skinnedEntity = player.m_skinnedEntity; m_weight = player.Weight; m_timeScale = player.m_timeScale; m_frameOption = player.m_frameOption; foreach(var list in m_boneLODs.Values) list.Clear(); //m_boneLODs.Clear(); m_boneCount = player.m_boneCount; if (m_boneInfos == null || m_boneInfos.Length < m_boneCount) m_boneInfos = new BoneInfo[m_boneCount]; Position = player.Position; for (int b = 0; b < m_boneCount; b++) { var boneInfo = m_boneInfos[b]; if (boneInfo == null) { boneInfo = new BoneInfo(); m_boneInfos[b] = boneInfo; } // Create it boneInfo.ClipBone = player.m_boneInfos[b].ClipBone; boneInfo.Player = this; // Assign it to a model bone boneInfo.SetModel(m_skinnedEntity); boneInfo.CurrentKeyframe = player.m_boneInfos[b].CurrentKeyframe; boneInfo.SetPosition(Position); if (player.m_boneLODs != null && boneInfo.ModelBone != null && ENABLE_ANIMATION_LODS) { foreach (var boneLOD in player.m_boneLODs) { List<BoneInfo> lodBones; if (!m_boneLODs.TryGetValue(boneLOD.Key, out lodBones)) { lodBones = new List<BoneInfo>(); m_boneLODs.Add(boneLOD.Key, lodBones); } foreach (var boneName in boneLOD.Value) { if (boneName.ModelBone == null) continue; if (boneInfo.ModelBone.Name == boneName.ModelBone.Name) { lodBones.Add(boneInfo); break; } } } } if (MyFakes.ENABLE_BONES_AND_ANIMATIONS_DEBUG) { int index; System.Diagnostics.Debug.Assert(m_skinnedEntity.AnimationController.FindBone(boneInfo.ClipBone.Name, out index) != null, "Can not find clip bone with name: " + boneInfo.ClipBone.Name + " in model: " + m_skinnedEntity.Name); } } m_initialized = true; }
public void Play(MyAnimationDefinition animationDefinition, bool firstPerson, MyFrameOption frameOption, float blendTime, float timeScale) { string animationModel; if (!firstPerson || string.IsNullOrEmpty(animationDefinition.AnimationModelFPS)) { animationModel = animationDefinition.AnimationModel; } else { animationModel = animationDefinition.AnimationModelFPS; } string path = animationModel; if (!string.IsNullOrEmpty(animationDefinition.AnimationModel)) { if ((animationDefinition.Status == MyAnimationDefinition.AnimationStatus.Unchecked) && !MyFileSystem.FileExists(Path.IsPathRooted(path) ? path : Path.Combine(MyFileSystem.ContentPath, path))) { animationDefinition.Status = MyAnimationDefinition.AnimationStatus.Failed; } else { animationDefinition.Status = MyAnimationDefinition.AnimationStatus.OK; MyModel modelOnlyAnimationData = MyModels.GetModelOnlyAnimationData(path, false); if ((((modelOnlyAnimationData == null) || (modelOnlyAnimationData.Animations != null)) && (modelOnlyAnimationData.Animations.Clips.Count != 0)) && (modelOnlyAnimationData.Animations.Clips.Count > animationDefinition.ClipIndex)) { if (this.ActualPlayer.IsInitialized) { this.BlendPlayer.Initialize(this.ActualPlayer); } this.ActualPlayer.Initialize(modelOnlyAnimationData, this.m_name, animationDefinition.ClipIndex, this.m_skinnedEntity, 1f, timeScale, frameOption, this.m_bones, this.m_boneLODs); this.ActualPlayer.AnimationMwmPathDebug = path; this.ActualPlayer.AnimationNameDebug = animationDefinition.Id.SubtypeName; this.m_state = AnimationBlendState.BlendIn; this.m_currentBlendTime = 0f; this.m_totalBlendTime = blendTime; } } } }
public void Play(MyAnimationDefinition animationDefinition, bool firstPerson, MyFrameOption frameOption, float blendTime, float timeScale) { string model = firstPerson && !string.IsNullOrEmpty(animationDefinition.AnimationModelFPS) ? animationDefinition.AnimationModelFPS : animationDefinition.AnimationModel; System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(model)); if (string.IsNullOrEmpty(animationDefinition.AnimationModel)) { return; } if (animationDefinition.Status == MyAnimationDefinition.AnimationStatus.Unchecked) { var fsPath = System.IO.Path.IsPathRooted(model) ? model : System.IO.Path.Combine(MyFileSystem.ContentPath, model); if (!MyFileSystem.FileExists(fsPath)) { animationDefinition.Status = MyAnimationDefinition.AnimationStatus.Failed; return; } } animationDefinition.Status = MyAnimationDefinition.AnimationStatus.OK; MyModel animation = VRage.Game.Models.MyModels.GetModelOnlyAnimationData(model); Debug.Assert(animation != null && animation.Animations != null && animation.Animations.Clips.Count > 0); if (animation != null && animation.Animations == null || animation.Animations.Clips.Count == 0) { return; } Debug.Assert(animationDefinition.ClipIndex < animation.Animations.Clips.Count); if (animation.Animations.Clips.Count <= animationDefinition.ClipIndex) { return; } if (ActualPlayer.IsInitialized) { BlendPlayer.Initialize(ActualPlayer); } // Create a clip player and assign it to this model ActualPlayer.Initialize(animation, m_name, animationDefinition.ClipIndex, m_skinnedEntity, 1, timeScale, frameOption, m_bones, m_boneLODs); ActualPlayer.AnimationMwmPathDebug = model; ActualPlayer.AnimationNameDebug = animationDefinition.Id.SubtypeName; m_state = AnimationBlendState.BlendIn; m_currentBlendTime = 0; m_totalBlendTime = blendTime; }
protected override void OnAnimationPlay(MyAnimationDefinition animDefinition, MyAnimationCommand command, ref string bonesArea, ref MyFrameOption frameOption, ref bool useFirstPersonVersion) { var currentMovementState = GetCurrentMovementState(); if (DefinitionId.Value.SubtypeId == medievelMaleSubtypeId) { if (command.ExcludeLegsWhenMoving) { //In this case, we must stop all upper animations correctly if (currentMovementState == MyCharacterMovementEnum.RotatingLeft || currentMovementState == MyCharacterMovementEnum.RotatingRight || currentMovementState == MyCharacterMovementEnum.Standing) { bonesArea = TopBody + " LowerBody"; } else { bonesArea = TopBody; } frameOption = frameOption != MyFrameOption.JustFirstFrame ? MyFrameOption.PlayOnce : frameOption; } else if (m_lastBonesArea == TopBody + " LowerBody") { StopLowerCharacterAnimation(0.2f); } m_lastBonesArea = bonesArea; } else { if (currentMovementState != MyCharacterMovementEnum.Standing && currentMovementState != MyCharacterMovementEnum.RotatingLeft && currentMovementState != MyCharacterMovementEnum.RotatingRight && command.ExcludeLegsWhenMoving) { //In this case, we must stop all upper animations correctly bonesArea = TopBody; frameOption = frameOption != MyFrameOption.JustFirstFrame ? MyFrameOption.PlayOnce : frameOption; } } useFirstPersonVersion = IsInFirstPersonView; if (animDefinition.AllowWithWeapon) { if (!UseAnimationForWeapon) { StoreWeaponRelativeMatrix(); UseAnimationForWeapon = true; m_resetWeaponAnimationState = true; } } if (!animDefinition.LeftHandItem.TypeId.IsNull) { if (m_leftHandItem != null) { (m_leftHandItem as IMyHandheldGunObject <Sandbox.Game.Weapons.MyDeviceBase>).OnControlReleased(); m_leftHandItem.Close(); } m_leftHandItem = MyEntityFactory.CreateEntity(animDefinition.LeftHandItem.TypeId); var ob = MyEntityFactory.CreateObjectBuilder(m_leftHandItem); m_leftHandItem.Init(ob); var leftHandTool = m_leftHandItem as IMyHandheldGunObject <Sandbox.Game.Weapons.MyDeviceBase>; if (leftHandTool != null) { leftHandTool.OnControlAcquired(this); } (m_leftHandItem as IMyHandheldGunObject <Sandbox.Game.Weapons.MyDeviceBase>).OnControlAcquired(this); UpdateLeftHandItemPosition(); MyEntities.Add(m_leftHandItem); } }
public void Initialize(AnimationClip clip, MySkinnedEntity skinnedEntity, float weight, float timeScale, MyFrameOption frameOption, string[] explicitBones = null) { m_clip = clip; m_skinnedEntity = skinnedEntity; m_weight = weight; m_timeScale = timeScale; m_frameOption = frameOption; // Create the bone information classes var maxBoneCount = explicitBones == null ? clip.Bones.Count : explicitBones.Length; if (m_boneInfos == null || m_boneInfos.Length < maxBoneCount) m_boneInfos = new BoneInfo[maxBoneCount]; int neededBonesCount = 0; for (int b = 0; b < maxBoneCount; b++) { var bone = explicitBones == null ? clip.Bones[b] : FindBone(clip.Bones, explicitBones[b]); if (bone == null) continue; if (bone.Keyframes.Count == 0) continue; // Create it m_boneInfos[neededBonesCount] = new BoneInfo(bone, this); // Assign it to a model bone m_boneInfos[neededBonesCount].SetModel(skinnedEntity); neededBonesCount++; } m_boneCount = neededBonesCount; Position = 0; m_initialized = true; }
public void Initialize(AnimationPlayer player) { if (this.m_hash != 0) { CachedAnimationPlayers.Remove(this.m_hash); this.m_hash = 0; } this.Name = player.Name; this.m_duration = player.m_duration; this.m_skinnedEntity = player.m_skinnedEntity; this.m_weight = player.Weight; this.m_timeScale = player.m_timeScale; this.m_frameOption = player.m_frameOption; using (Dictionary <float, List <BoneInfo> > .ValueCollection.Enumerator enumerator = this.m_boneLODs.Values.GetEnumerator()) { while (enumerator.MoveNext()) { enumerator.Current.Clear(); } } this.m_boneCount = player.m_boneCount; if ((this.m_boneInfos == null) || (this.m_boneInfos.Length < this.m_boneCount)) { this.m_boneInfos = new BoneInfo[this.m_boneCount]; } this.Position = player.Position; for (int i = 0; i < this.m_boneCount; i++) { BoneInfo item = this.m_boneInfos[i]; if (item == null) { item = new BoneInfo(); this.m_boneInfos[i] = item; } item.ClipBone = player.m_boneInfos[i].ClipBone; item.Player = this; item.SetModel(this.m_skinnedEntity); item.CurrentKeyframe = player.m_boneInfos[i].CurrentKeyframe; item.SetPosition(this.Position); if (((player.m_boneLODs != null) && (item.ModelBone != null)) && ENABLE_ANIMATION_LODS) { foreach (KeyValuePair <float, List <BoneInfo> > pair in player.m_boneLODs) { List <BoneInfo> list; if (!this.m_boneLODs.TryGetValue(pair.Key, out list)) { list = new List <BoneInfo>(); this.m_boneLODs.Add(pair.Key, list); } foreach (BoneInfo info2 in pair.Value) { if ((info2.ModelBone != null) && (item.ModelBone.Name == info2.ModelBone.Name)) { list.Add(item); break; } } } } bool flag1 = MyFakes.ENABLE_BONES_AND_ANIMATIONS_DEBUG; } this.m_initialized = true; }
protected override void OnAnimationPlay(MyAnimationDefinition animDefinition,MyAnimationCommand command, ref string bonesArea, ref MyFrameOption frameOption, ref bool useFirstPersonVersion) { var currentMovementState = GetCurrentMovementState(); if (DefinitionId.Value.SubtypeId == medievelMaleSubtypeId) { if (command.ExcludeLegsWhenMoving) { //In this case, we must stop all upper animations correctly if (currentMovementState == MyCharacterMovementEnum.RotatingLeft || currentMovementState == MyCharacterMovementEnum.RotatingRight || currentMovementState == MyCharacterMovementEnum.Standing) bonesArea = TopBody + " LowerBody"; else bonesArea = TopBody; frameOption = frameOption != MyFrameOption.JustFirstFrame ? MyFrameOption.PlayOnce : frameOption; } else if (m_lastBonesArea == TopBody + " LowerBody") StopLowerCharacterAnimation(0.2f); m_lastBonesArea = bonesArea; } else { if (currentMovementState != MyCharacterMovementEnum.Standing && currentMovementState != MyCharacterMovementEnum.RotatingLeft && currentMovementState != MyCharacterMovementEnum.RotatingRight && command.ExcludeLegsWhenMoving) { //In this case, we must stop all upper animations correctly bonesArea = TopBody; frameOption = frameOption != MyFrameOption.JustFirstFrame ? MyFrameOption.PlayOnce : frameOption; } } useFirstPersonVersion = IsInFirstPersonView; if (animDefinition.AllowWithWeapon) { if (!UseAnimationForWeapon) { StoreWeaponRelativeMatrix(); UseAnimationForWeapon = true; m_resetWeaponAnimationState = true; } } if (!animDefinition.LeftHandItem.TypeId.IsNull) { if (m_leftHandItem != null) { (m_leftHandItem as IMyHandheldGunObject<Sandbox.Game.Weapons.MyDeviceBase>).OnControlReleased(); m_leftHandItem.Close(); } // CH: TODO: The entity id is not synced, but it never was in this place. It should be fixed later long handItemId = MyEntityIdentifier.AllocateId(); uint? inventoryItemId = null; var builder = GetObjectBuilderForWeapon(animDefinition.LeftHandItem, ref inventoryItemId, handItemId); var leftHandItem = CreateGun(builder, inventoryItemId); if (leftHandItem != null) { m_leftHandItem = leftHandItem as MyEntity; leftHandItem.OnControlAcquired(this); UpdateLeftHandItemPosition(); MyEntities.Add(m_leftHandItem); } } }