Пример #1
0
        /// <summary>
        /// Add part for animation.
        /// </summary>
        /// <param name="parent">parent part, null for root.</param>
        /// <param name="modelFile">Model file name inside Models folder, excluding extension.</param>
        /// <param name="smoothAnim">smooth animation, linear lerp between keyframes.</param>
        /// <param name="visible">initialize it visible?</param>
        /// <returns>part or null for failure.</returns>
        public AnimaPart AddPart(AnimaPart parent, string modelFile, bool smoothAnim = false, bool visible = true)
        {
            if (m_entity == null)
            {
                return(null);
            }

            // Create part
            MyEntity parentEntity = (parent != null) ? parent.Entity : m_entity;
            MyEntity part_entity  = new MyEntitySubpart();

            part_entity.Flags     = EntityFlags.Visible | EntityFlags.NeedsDraw | EntityFlags.NeedsDrawFromParent | EntityFlags.InvalidateOnMove;
            part_entity.IsPreview = true;
            part_entity.Init(null, m_modelsFolder + modelFile + ".mwm", parentEntity, null, null);
            part_entity.Render.EnableColorMaskHsv = true;
            part_entity.Render.ColorMaskHsv       = m_entity.Render.ColorMaskHsv;
            part_entity.Render.PersistentFlags    = MyPersistentEntityFlags2.CastShadows;
            part_entity.PositionComp.LocalMatrix  = Matrix.Identity;
            part_entity.OnAddedToScene(parent);

            AnimaPart part = new AnimaPart(this, parent, part_entity);

            if (!visible)
            {
                part.Visible = false;
            }
            m_partList.Add(part);
            return(part);
        }
Пример #2
0
        // Your block initialization
        public void BlockInit()
        {
            // No point to run this script if is a dedicated server because there's no graphics
            if (Anima.DedicatedServer) return;

            // Create the main Anima class
            m_anima = new Anima();

            // Initialize Anima
            if (!m_anima.Init(Entity as MyEntity, "Anima Examples", "AnimaExamples")) throw new ArgumentException("Anima failed to initialize!");

            // Add parts
            m_part_core = m_anima.AddPart(null, @"AnimaExamples\ModelCore");
            m_part_topcap = m_anima.AddPart(m_part_core, @"animaexamples\TopCap");
            m_part_bottomcap = m_anima.AddPart(m_part_core, @"animaexamples\BottomCap");

            // Assign sequences
            coreFunctionality(m_part_core);
            m_part_core.OnComplete = coreFunctionality;

            // Play sequences
            m_anima.Play(Anima.Playback.LOOP);

            // Update each frame, note this may not work for all object's types!
            Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME;
        }
Пример #3
0
 /// <summary>
 /// Anima main class constructor.
 /// </summary>
 public AnimaPart(Anima anima, AnimaPart parent, MyEntity entity)
 {
     m_anima            = anima;
     m_entity           = entity;
     m_parent           = parent;
     m_smoothAnim       = false;
     m_enabled          = true;
     m_visible          = true;
     m_onTransform      = null;
     m_onComplete       = null;
     m_seq              = null;
     m_playMode         = Anima.Playback.HALT;
     m_playMode2        = Anima.Playback.HALT;
     m_cursorPos        = 0f;
     m_speed            = 1f;
     m_lastCursorPos    = 0;
     m_disableRootColor = false;
     m_position         = Vector3.Zero;
     m_rotation         = Quaternion.Identity;
     m_scale            = Vector3.One;
 }
Пример #4
0
        // Your block initialization
        public void BlockInit()
        {
            // ( Your initialization code here! )

            // No point to run this script if is a dedicated server because there's no graphics
            if (Anima.DedicatedServer) return;

            // Create the main Anima class
            m_anima = new Anima();

            // Initialize Anima
            if (!m_anima.Init(Entity as MyEntity, "Anima Examples", "AnimaExamples")) throw new ArgumentException("Anima failed to initialize!");

            // Add parts
            m_part = m_anima.AddPart(null, @"AnimaExamples\ModelCube");

            // Assign sequences
            m_part.Sequence = Seq_Cube.Adquire();

            // Play sequences
            m_part.Play(Anima.Playback.LOOP);
        }
Пример #5
0
 // Our callback to change sequences
 public void coreFunctionality(AnimaPart part)
 {
     bool status = block.IsWorking;
     if (!lastStatus && status)
     {
         // Powering on
         m_part_core.Sequence = Seq_Core_powerOn.Adquire();
         m_part_topcap.Sequence = Seq_TopCap_powerOn.Adquire();
         m_part_bottomcap.Sequence = Seq_BottomCap_powerOn.Adquire();
         gravMode = GravMode.POWER_ON;
     }
     else if (lastStatus && !status)
     {
         // Powering off
         m_part_core.Sequence = Seq_Core_powerOff.Adquire();
         m_part_topcap.Sequence = Seq_TopCap_powerOff.Adquire();
         m_part_bottomcap.Sequence = Seq_BottomCap_powerOff.Adquire();
         gravMode = GravMode.POWER_OFF;
     }
     else if (status)
     {
         // While active
         m_part_core.Sequence = Seq_Core_active.Adquire();
         m_part_topcap.Sequence = Seq_TopCap_active.Adquire();
         m_part_bottomcap.Sequence = Seq_BottomCap_active.Adquire();
         gravMode = GravMode.ACTIVE;
     }
     else
     {
         // While inactive
         m_part_core.Sequence = Seq_Core_inactive.Adquire();
         m_part_topcap.Sequence = Seq_TopCap_inactive.Adquire();
         m_part_bottomcap.Sequence = Seq_BottomCap_inactive.Adquire();
         gravMode = GravMode.INACTIVE;
     }
     lastStatus = status;
 }
Пример #6
0
 /// <summary>
 /// Anima main class constructor.
 /// </summary>
 public AnimaPart(Anima anima, AnimaPart parent, MyEntity entity)
 {
     m_anima = anima;
     m_entity = entity;
     m_parent = parent;
     m_smoothAnim = false;
     m_enabled = true;
     m_visible = true;
     m_onTransform = null;
     m_onComplete = null;
     m_seq = null;
     m_playMode = Anima.Playback.HALT;
     m_playMode2 = Anima.Playback.HALT;
     m_cursorPos = 0f;
     m_speed = 1f;
     m_lastCursorPos = 0;
     m_disableRootColor = false;
     m_position = Vector3.Zero;
     m_rotation = Quaternion.Identity;
     m_scale = Vector3.One;
 }
Пример #7
0
        /// <summary>
        /// Add anima part for animation, parent will be one of root's subpart.
        /// </summary>
        /// <param name="subpartName">root subpart name.</param>
        /// <param name="modelFile">>Model file name inside Models folder, excluding extension.</param>
        /// <param name="smoothAnim">smooth animation, linear lerp between keyframes.</param>
        /// <param name="visible">initialize it visible?</param>
        /// <returns>part or null for failure.</returns>
        public AnimaPart AddPartToSubpart(string subpartName, string modelFile, bool smoothAnim = false, bool visible = true)
        {
            if (m_entity == null) return null;
            if (!m_entity.Subparts.ContainsKey(subpartName)) return null;

            // Create part
            MyEntity parentEntity = m_entity.Subparts[subpartName];
            MyEntity part_entity = new MyEntity();
            part_entity.Init(null, m_modelsFolder + modelFile + ".mwm", parentEntity, null, null);
            part_entity.Render.EnableColorMaskHsv = true;
            part_entity.Render.ColorMaskHsv = m_entity.Render.ColorMaskHsv;
            part_entity.Render.PersistentFlags = MyPersistentEntityFlags2.CastShadows;
            part_entity.PositionComp.LocalMatrix = Matrix.Identity;
            part_entity.Flags = EntityFlags.Visible | EntityFlags.NeedsDraw | EntityFlags.NeedsDrawFromParent | EntityFlags.InvalidateOnMove;
            part_entity.OnAddedToScene(parentEntity);

            AnimaPart part = new AnimaPart(this, null, part_entity);
            if (!visible) part.Visible = false;
            m_partList.Add(part);
            return part;
        }