コード例 #1
0
        private MyEntitySubpart LoadSubpartFromName(string name)
        {
            MyEntitySubpart subpart;

            Subparts.TryGetValue(name, out subpart);

            // simply return the subpart if it exists in the dictionary
            if (subpart != null)
            {
                return(subpart);
            }

            // otherwise load it now and add to dictionary
            subpart = new MyEntitySubpart();

            string fileName = Path.Combine(Path.GetDirectoryName(Model.AssetName), name) + ".mwm";

            subpart.Render.EnableColorMaskHsv = Render.EnableColorMaskHsv;
            subpart.Render.ColorMaskHsv       = Render.ColorMaskHsv;
            subpart.Init(null, fileName, this, null);

            // add to dictionary
            Subparts[name] = subpart;

            if (InScene)
            {
                subpart.OnAddedToScene(this);
            }

            return(subpart);
        }
コード例 #2
0
        private void GetBarrelAndMuzzle()
        {
            MyEntitySubpart barrel;

            if (Subparts.TryGetValue("Barrel", out barrel))
            {
                m_barrel = barrel;
            }

            var model = Engine.Models.MyModels.GetModelOnlyDummies(BlockDefinition.Model);

            m_gunBase.LoadDummies(model.Dummies);

            // backward compatibility for models without dummies or old dummies
            if (!m_gunBase.HasDummies)
            {
                if (model.Dummies.ContainsKey("Muzzle"))
                {
                    m_gunBase.AddMuzzleMatrix(MyAmmoType.HighSpeed, model.Dummies["Muzzle"].Matrix);
                }
                else
                {
                    Matrix muzzleMatrix = Matrix.CreateTranslation(new Vector3(0, 0, -1));
                    m_gunBase.AddMuzzleMatrix(MyAmmoType.HighSpeed, muzzleMatrix);
                }
            }
        }
コード例 #3
0
        public override void UpdateVisual()
        {
            base.UpdateVisual();
            MyEntitySubpart barrel;

            if (Subparts.TryGetValue("Barrel", out barrel))
            {
                m_barrel = barrel;
            }
        }
コード例 #4
0
        private void InitSubparts()
        {
            if (!CubeGrid.CreatePhysics)
            {
                return;
            }
            int             i        = 1;
            StringBuilder   partName = new StringBuilder();
            MyEntitySubpart foundPart;

            m_subparts.Clear();
            while (true)
            {
                partName.Clear().Append("HangarDoor_door").Append(i++);
                Subparts.TryGetValue(partName.ToString(), out foundPart);
                if (foundPart == null)
                {
                    break;
                }
                m_subparts.Add(foundPart);
            }
            ;

            UpdateDoorPosition();

            if (CubeGrid.Projector != null)
            {
                //This is a projected grid, don't add collisions for subparts
                return;
            }
            foreach (var subpart in m_subparts)
            {
                if (subpart != null && subpart.Physics == null)
                {
                    if ((subpart.ModelCollision.HavokCollisionShapes != null) && (subpart.ModelCollision.HavokCollisionShapes.Length > 0))
                    {
                        var shape = subpart.ModelCollision.HavokCollisionShapes[0];
                        subpart.Physics           = new Engine.Physics.MyPhysicsBody(subpart, RigidBodyFlag.RBF_DOUBLED_KINEMATIC | RigidBodyFlag.RBF_KINEMATIC);
                        subpart.Physics.IsPhantom = false;
                        Vector3 center = subpart.PositionComp.LocalVolume.Center;
                        subpart.Physics.CreateFromCollisionObject(shape, center, WorldMatrix, null, MyPhysics.KinematicDoubledCollisionLayer);
                        subpart.Physics.Enabled = true;
                    }
                }
            }

            CubeGrid.OnHavokSystemIDChanged -= CubeGrid_HavokSystemIDChanged;
            CubeGrid.OnHavokSystemIDChanged += CubeGrid_HavokSystemIDChanged;
            CubeGrid.OnPhysicsChanged       -= CubeGrid_OnPhysicsChanged;
            CubeGrid.OnPhysicsChanged       += CubeGrid_OnPhysicsChanged;
            if (CubeGrid.Physics != null)
            {
                UpdateHavokCollisionSystemID(CubeGrid.Physics.HavokCollisionSystemID);
            }
        }
コード例 #5
0
        private void LoadSubparts()
        {
            DisposeSubpartsPhysics();

            Debug.Assert(!this.Closed);
            if (this.Closed)
            {
                // When closed, the welding callback will call this, but the model will already be unloaded
                return;
            }

            if (!Subparts.TryGetValue("PistonSubpart1", out m_subpart1))
            {
                return;
            }
            if (!m_subpart1.Subparts.TryGetValue("PistonSubpart2", out m_subpart2))
            {
                return;
            }
            if (!m_subpart2.Subparts.TryGetValue("PistonSubpart3", out Subpart3))
            {
                return;
            }

            MyModelDummy dummy;

            if (Subpart3.Model.Dummies.TryGetValue("TopBlock", out dummy))
            {
                m_constraintBasePos = dummy.Matrix.Translation;
            }
            if (Model.Dummies.TryGetValue("subpart_PistonSubpart1", out dummy))
            {
                m_subpartsConstraintPos = dummy.Matrix.Translation;
                m_subpart1LocPos        = m_subpartsConstraintPos;
            }
            if (m_subpart1.Model.Dummies.TryGetValue("subpart_PistonSubpart2", out dummy))
            {
                m_subpart2LocPos = dummy.Matrix.Translation;
            }
            if (m_subpart2.Model.Dummies.TryGetValue("subpart_PistonSubpart3", out dummy))
            {
                m_subpart3LocPos = dummy.Matrix.Translation;
            }


            if (!CubeGrid.CreatePhysics)
            {
                return;
            }

            InitSubpartsPhysics();
        }
コード例 #6
0
        protected override void FillSubparts()
        {
            MyEntitySubpart foundPart;

            m_subparts.Clear();
            if (Subparts.TryGetValue("DoorLeft", out foundPart))
            {
                m_subparts.Add(foundPart);
            }
            if (Subparts.TryGetValue("DoorRight", out foundPart))
            {
                m_subparts.Add(foundPart);
            }
        }
コード例 #7
0
 private bool LoadPropeller()
 {
     if (BlockDefinition.PropellerUse && BlockDefinition.PropellerEntity != null)
     {
         MyEntitySubpart propeller;
         if (Subparts.TryGetValue(BlockDefinition.PropellerEntity, out propeller))
         {
             m_propellerEntity       = propeller;
             m_propellerIdleRatio    = BlockDefinition.PropellerIdleSpeed / BlockDefinition.PropellerFullSpeed;
             m_propellerMaxDistance  = BlockDefinition.PropellerMaxDistance * BlockDefinition.PropellerMaxDistance;
             m_propellerAcceleration = (1f / BlockDefinition.PropellerAcceleration) * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
             m_propellerDeceleration = (1f / BlockDefinition.PropellerDeceleration) * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
             return(true);
         }
     }
     return(false);
 }
コード例 #8
0
        private void LoadSubparts()
        {
            DisposeSubpartsPhysics();

            if (!Subparts.TryGetValue("PistonSubpart1", out m_subpart1))
            {
                return;
            }
            if (!m_subpart1.Subparts.TryGetValue("PistonSubpart2", out m_subpart2))
            {
                return;
            }
            if (!m_subpart2.Subparts.TryGetValue("PistonSubpart3", out Subpart3))
            {
                return;
            }

            MyModelDummy dummy;

            if (Subpart3.Model.Dummies.TryGetValue("TopBlock", out dummy))
            {
                m_constraintBasePos = dummy.Matrix.Translation;
            }
            if (Model.Dummies.TryGetValue("subpart_PistonSubpart1", out dummy))
            {
                m_subpartsConstraintPos = dummy.Matrix.Translation;
                m_subpart1LocPos        = m_subpartsConstraintPos;
            }
            if (m_subpart1.Model.Dummies.TryGetValue("subpart_PistonSubpart2", out dummy))
            {
                m_subpart2LocPos = dummy.Matrix.Translation;
            }
            if (m_subpart2.Model.Dummies.TryGetValue("subpart_PistonSubpart3", out dummy))
            {
                m_subpart3LocPos = dummy.Matrix.Translation;
            }


            if (!CubeGrid.CreatePhysics)
            {
                return;
            }

            InitSubpartsPhysics();
        }
コード例 #9
0
ファイル: MyDoor.cs プロジェクト: zorg-kirill/SpaceEngineers
        private void InitSubparts()
        {
            if (!CubeGrid.CreatePhysics)
            {
                return;
            }

            Subparts.TryGetValue("DoorLeft", out m_leftSubpart);
            Subparts.TryGetValue("DoorRight", out m_rightSubpart);

            UpdateSlidingDoorsPosition();

            if (CubeGrid.Projector != null)
            {
                //This is a projected grid, don't add collisions for subparts
                return;
            }

            if (m_leftSubpart != null && m_leftSubpart.Physics == null)
            {
                if ((m_leftSubpart.ModelCollision.HavokCollisionShapes != null) && (m_leftSubpart.ModelCollision.HavokCollisionShapes.Length > 0))
                {
                    var shape = m_leftSubpart.ModelCollision.HavokCollisionShapes[0];
                    m_leftSubpart.Physics           = new Engine.Physics.MyPhysicsBody(m_leftSubpart, RigidBodyFlag.RBF_KINEMATIC);
                    m_leftSubpart.Physics.IsPhantom = false;
                    Vector3 center = new Vector3(0.35f, 0f, 0f) + m_leftSubpart.PositionComp.LocalVolume.Center;
                    m_leftSubpart.GetPhysicsBody().CreateFromCollisionObject(shape, center, WorldMatrix, null, MyPhysics.CollisionLayers.KinematicDoubledCollisionLayer);
                    m_leftSubpart.Physics.Enabled = true;
                }
            }

            if (m_rightSubpart != null && m_rightSubpart.Physics == null)
            {
                if ((m_rightSubpart.ModelCollision.HavokCollisionShapes != null) && (m_rightSubpart.ModelCollision.HavokCollisionShapes.Length > 0))
                {
                    var shape = m_rightSubpart.ModelCollision.HavokCollisionShapes[0];
                    m_rightSubpart.Physics           = new Engine.Physics.MyPhysicsBody(m_rightSubpart, RigidBodyFlag.RBF_KINEMATIC);
                    m_rightSubpart.Physics.IsPhantom = false;
                    Vector3 center = new Vector3(-0.35f, 0f, 0f) + m_rightSubpart.PositionComp.LocalVolume.Center;
                    m_rightSubpart.GetPhysicsBody().CreateFromCollisionObject(shape, center, WorldMatrix, null, MyPhysics.CollisionLayers.KinematicDoubledCollisionLayer);
                    m_rightSubpart.Physics.Enabled = true;
                }
            }
        }
コード例 #10
0
        protected override void FillSubparts()
        {
            int             i        = 1;
            StringBuilder   partName = new StringBuilder();
            MyEntitySubpart foundPart;

            m_subparts.Clear();
            while (true)
            {
                partName.Clear().Append("HangarDoor_door").Append(i++);
                Subparts.TryGetValue(partName.ToString(), out foundPart);
                if (foundPart == null)
                {
                    break;
                }
                m_subparts.Add(foundPart);
            }
            ;
        }