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);
            }
        }
예제 #2
0
        public override void AddCommand(MyAnimationCommand command, bool sync = false)
        {
            base.AddCommand(command, sync);

            if (sync)
            {
                SyncObject.SendAnimationCommand(ref command);
            }
        }
예제 #3
0
        public void SendAnimationCommand(ref MyAnimationCommand command)
        {
            var msg = new AnimationCommandMsg();

            msg.CharacterEntityId = Entity.EntityId;

            msg.AnimationSubtypeName = command.AnimationSubtypeName;
            msg.Loop      = command.Loop;
            msg.Mode      = command.Mode;
            msg.BlendTime = command.BlendTime;
            msg.TimeScale = command.TimeScale;

            Sync.Layer.SendMessageToAll(ref msg);
        }
        public override void AddCommand(MyAnimationCommand command, bool sync = false)
        {
            if (UseNewAnimationSystem)
            {
                return;
            }

            base.AddCommand(command, sync);

            if (sync)
            {
                SendAnimationCommand(ref command);
            }
        }
        public override bool HandleInput()
        {
            if (base.HandleInput())
            {
                return(true);
            }

            bool handled = false;


            //foreach (var ent in MyEntities.GetEntities())
            //{
            //    if (ent is MyCubeGrid)
            //    {
            //        if (ent.PositionComp.WorldAABB.Contains(MySector.MainCamera.Position) == ContainmentType.Disjoint)
            //        {
            //            ent.Close();
            //        }
            //    }
            //}

            //var measureStart = new VRage.Library.Utils.MyTimeSpan(System.Diagnostics.Stopwatch.GetTimestamp());

            var list = MyDefinitionManager.Static.GetAnimationDefinitions();

            foreach (var skin in m_skins)
            {
                skin.UpdateAnimation();

                if (MyRandom.Instance.NextFloat() > 0.95f)
                {
                    var randomAnim = list.ItemAt(MyRandom.Instance.Next(0, list.Count));
                    var command    = new MyAnimationCommand()
                    {
                        AnimationSubtypeName = randomAnim.Id.SubtypeName,
                        FrameOption          = MyFrameOption.Loop,
                        TimeScale            = 1,
                        BlendTime            = 0.3f
                    };
                    skin.AddCommand(command);
                }
            }


            //var measureEnd = new VRage.Library.Utils.MyTimeSpan(System.Diagnostics.Stopwatch.GetTimestamp());
            //var total = measureEnd - measureStart;
            //m_skins.Clear();

            return(handled);
        }
예제 #6
0
        public void SendAnimationCommand(ref MyAnimationCommand command)
        {
            var msg = new AnimationCommandMsg();

            msg.CharacterEntityId = Entity.EntityId;

            msg.AnimationSubtypeName = command.AnimationSubtypeName;
            msg.PlaybackCommand      = command.PlaybackCommand;
            msg.BlendOption          = command.BlendOption;
            msg.FrameOption          = command.FrameOption;
            msg.BlendTime            = command.BlendTime;
            msg.TimeScale            = command.TimeScale;

            Sync.Layer.SendMessageToServer(ref msg);
        }
        void SpawnSimpleSkinnedObject()
        {
            var skin = new MySkinnedEntity();

            MyObjectBuilder_Character ob = new MyObjectBuilder_Character();

            ob.PositionAndOrientation = new VRage.MyPositionAndOrientation(MySector.MainCamera.Position + 2 * MySector.MainCamera.ForwardVector, MySector.MainCamera.ForwardVector, MySector.MainCamera.UpVector);
            skin.Init(null, @"Models\Characters\Basic\ME_barbar.mwm", null, null);
            skin.Init(ob);

            MyEntities.Add(skin);

            var command = new MyAnimationCommand()
            {
                AnimationSubtypeName = "IdleBarbar",
                FrameOption          = MyFrameOption.Loop,
                TimeScale            = 1
            };

            skin.AddCommand(command);

            m_skins.Add(skin);
        }
예제 #8
0
        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);
            }
        }
        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;
            }
        }
예제 #10
0
        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);
            }
        }
예제 #11
0
        public void SendAnimationCommand(ref MyAnimationCommand command)
        {
            var msg = new AnimationCommandMsg();
            msg.CharacterEntityId = Entity.EntityId;

            msg.AnimationSubtypeName = command.AnimationSubtypeName;
            msg.PlaybackCommand = command.PlaybackCommand;
            msg.BlendOption = command.BlendOption;
            msg.FrameOption = command.FrameOption;
            msg.BlendTime = command.BlendTime;
            msg.TimeScale = command.TimeScale;

            Sync.Layer.SendMessageToServer(ref msg);
        }
        void SpawnSimpleSkinnedObject()
        {

            var skin = new MySkinnedEntity();

            MyObjectBuilder_Character ob = new MyObjectBuilder_Character();
            ob.EntityDefinitionId = new SerializableDefinitionId(typeof(MyObjectBuilder_Character), "Medieval_barbarian");
            ob.PositionAndOrientation = new VRage.MyPositionAndOrientation(MySector.MainCamera.Position + 2 * MySector.MainCamera.ForwardVector, MySector.MainCamera.ForwardVector, MySector.MainCamera.UpVector);
            skin.Init(null, @"Models\Characters\Basic\ME_barbar.mwm", null, null);
            skin.Init(ob);

            MyEntities.Add(skin);

            var command = new MyAnimationCommand()
            {
                AnimationSubtypeName = "IdleBarbar",
                FrameOption = MyFrameOption.Loop,
                TimeScale = 1
            };
            skin.AddCommand(command);

            m_skins.Add(skin);
        }
        public override bool HandleInput()
        {
            if (base.HandleInput())
                return true;

            bool handled = false;

          
            //foreach (var ent in MyEntities.GetEntities())
            //{
            //    if (ent is MyCubeGrid)
            //    {
            //        if (ent.PositionComp.WorldAABB.Contains(MySector.MainCamera.Position) == ContainmentType.Disjoint)
            //        {
            //            ent.Close();
            //        }
            //    }
            //}

            //var measureStart = new VRage.Library.Utils.MyTimeSpan(System.Diagnostics.Stopwatch.GetTimestamp());

            var list = MyDefinitionManager.Static.GetAnimationDefinitions();

            foreach (var skin in m_skins)
            {                
                skin.UpdateAnimation(Vector3.Distance(MySector.MainCamera.Position,skin.PositionComp.GetPosition()));

                if (MyRandom.Instance.NextFloat() > 0.95f)
                {
                    var randomAnim = list.ItemAt(MyRandom.Instance.Next(0, list.Count));
                    var command = new MyAnimationCommand()
                    {
                        AnimationSubtypeName = randomAnim.Id.SubtypeName,
                        FrameOption = MyFrameOption.Loop,
                        TimeScale = 1,
                        BlendTime = 0.3f
                    };
                    skin.AddCommand(command);
                }
            }


//            var measureEnd = new VRage.Library.Utils.MyTimeSpan(System.Diagnostics.Stopwatch.GetTimestamp());
 //           var total = measureEnd - measureStart;
   //         m_skins.Clear();

            if (m_voxelMap != null && m_voxelMap.PositionComp != null)
            {
                Vector3D center = m_voxelMap.PositionComp.WorldAABB.Center;
                Vector3D centerDelta = m_voxelMap.PositionComp.WorldMatrix.Translation - center;



                MatrixD worldMatrix = m_voxelMap.PositionComp.WorldMatrix;

                var rotationMatrix = Matrix.CreateRotationZ(0.01f);
                worldMatrix *= rotationMatrix;
                centerDelta = Vector3.TransformNormal(centerDelta, rotationMatrix);

                worldMatrix.Translation = center + centerDelta;

                //m_voxelMap.PositionComp.WorldMatrix = worldMatrix;


                SI_DYNAMICS_MULTIPLIER += 0.01f;

                //var tr = worldMatrix.Translation;
                //worldMatrix.Translation = new Vector3D(tr.X += (double)MyMath.FastSin(SI_DYNAMICS_MULTIPLIER), tr.Y, tr.Z);
                //worldMatrix.Translation = new Vector3D(tr.X + 100, tr.Y, tr.Z);

                //m_voxelMap.PositionComp.WorldMatrix = worldMatrix;

                var localBB = m_voxelMap.PositionComp.LocalAABB;
                MyOrientedBoundingBoxD orb = new MyOrientedBoundingBoxD((BoundingBoxD)localBB, m_voxelMap.PositionComp.WorldMatrix);
                VRageRender.MyRenderProxy.DebugDrawOBB(orb, Color.White, 0, false, false);
            }

            return handled;
        }
예제 #14
0
        public void SendAnimationCommand(ref MyAnimationCommand command)
        {
            var msg = new AnimationCommandMsg();
            msg.CharacterEntityId = Entity.EntityId;

            msg.AnimationSubtypeName = command.AnimationSubtypeName;
            msg.Loop = command.Loop;
            msg.Mode = command.Mode;
            msg.BlendTime = command.BlendTime;
            msg.TimeScale = command.TimeScale;

            Sync.Layer.SendMessageToAll(ref msg);
        }
예제 #15
0
        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);
                }
            }
        }
        public override bool HandleInput()
        {
            if (base.HandleInput())
                return true;

            bool handled = false;

          
            //foreach (var ent in MyEntities.GetEntities())
            //{
            //    if (ent is MyCubeGrid)
            //    {
            //        if (ent.PositionComp.WorldAABB.Contains(MySector.MainCamera.Position) == ContainmentType.Disjoint)
            //        {
            //            ent.Close();
            //        }
            //    }
            //}

            //var measureStart = new VRage.Library.Utils.MyTimeSpan(System.Diagnostics.Stopwatch.GetTimestamp());

            var list = MyDefinitionManager.Static.GetAnimationDefinitions();

            foreach (var skin in m_skins)
            {                
                skin.UpdateAnimation();

                if (MyRandom.Instance.NextFloat() > 0.95f)
                {
                    var randomAnim = list.ItemAt(MyRandom.Instance.Next(0, list.Count));
                    var command = new MyAnimationCommand()
                    {
                        AnimationSubtypeName = randomAnim.Id.SubtypeName,
                        FrameOption = MyFrameOption.Loop,
                        TimeScale = 1,
                        BlendTime = 0.3f
                    };
                    skin.AddCommand(command);
                }
            }


            //var measureEnd = new VRage.Library.Utils.MyTimeSpan(System.Diagnostics.Stopwatch.GetTimestamp());
            //var total = measureEnd - measureStart;
            //m_skins.Clear();

            return handled;
        }