Exemple #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);
        }
Exemple #2
0
        private MyEntitySubpart LoadSubpartFromName(string name)
        {
            MyEntitySubpart subpart;

            base.Subparts.TryGetValue(name, out subpart);
            if (subpart == null)
            {
                subpart = new MyEntitySubpart();
                string model = Path.Combine(Path.GetDirectoryName(base.Model.AssetName), name) + ".mwm";
                subpart.Render.EnableColorMaskHsv = base.Render.EnableColorMaskHsv;
                subpart.Render.ColorMaskHsv       = base.Render.ColorMaskHsv;
                subpart.Render.TextureChanges     = base.Render.TextureChanges;
                float?scale = null;
                subpart.Init(null, model, this, scale, null);
                base.Subparts[name] = subpart;
                if (base.InScene)
                {
                    subpart.OnAddedToScene(this);
                }
            }
            return(subpart);
        }
Exemple #3
0
        public void RefreshModels(string model, string modelCollision)
        {
            if (model != null)
            {
                Render.ModelStorage = MyModels.GetModelOnlyData(model);
                PositionComp.LocalVolumeOffset = Render.GetModel().BoundingSphere.Center;
            }
            if (modelCollision != null)
                m_modelCollision = MyModels.GetModelOnlyData(modelCollision);

            if (Render.ModelStorage != null)
            {
                this.PositionComp.LocalAABB = Render.GetModel().BoundingBox;

                bool idAllocationState = MyEntityIdentifier.AllocationSuspended;
                try
                {
                    MyEntityIdentifier.AllocationSuspended = false;

                    if (Subparts == null)
                        Subparts = new Dictionary<string, MyEntitySubpart>();
                    else
                    {
                        foreach (var existingSubpart in Subparts)
                        {
                            Hierarchy.RemoveChild(existingSubpart.Value);
                            existingSubpart.Value.Close();
                        }
                        Subparts.Clear();
                    }

                    MyEntitySubpart.Data data = new MyEntitySubpart.Data();
                    foreach (var dummy in Render.GetModel().Dummies)
                    {
                        // Check of mirrored matrix of dummy object is under fake, because characters have mirrored dummies
                        if (MyFakes.ENABLE_DUMMY_MIRROR_MATRIX_CHECK)
                        {
                            // This should not be here but if you want to check bad matrices of other types
                            if (!(this is MyCharacter))
                            {
                                Debug.Assert(!dummy.Value.Matrix.IsMirrored());
                            }
                        }

                        if (!MyEntitySubpart.GetSubpartFromDummy(model, dummy.Key, dummy.Value, ref data))
                            continue;

                        MyEntitySubpart subpart = new MyEntitySubpart();
                        subpart.Render.EnableColorMaskHsv = Render.EnableColorMaskHsv;
                        subpart.Render.ColorMaskHsv = Render.ColorMaskHsv;
                        subpart.Init(null, data.File, this, null);
                        subpart.PositionComp.LocalMatrix = data.InitialTransform;
                        Subparts[data.Name] = subpart;

                        if (InScene)
                            subpart.OnAddedToScene(this);
                    }
                }
                finally
                {
                    MyEntityIdentifier.AllocationSuspended = idAllocationState;
                }

                if (Render.GetModel().GlassData != null)
                {
                    Render.NeedsDraw = true;
                    Render.NeedsDrawFromParent = true;
                }

            }
            else
            {   //entities without model has box with side length = 1 by default
                float defaultBoxHalfSize = 0.5f;
                this.PositionComp.LocalAABB = new BoundingBox(new Vector3(-defaultBoxHalfSize), new Vector3(defaultBoxHalfSize));
            }
        }
Exemple #4
0
        public void RefreshModels(string model, string modelCollision)
        {
            if (model != null)
            {
                Render.ModelStorage            = MyModels.GetModelOnlyData(model);
                PositionComp.LocalVolumeOffset = Render.GetModel().BoundingSphere.Center;
            }
            if (modelCollision != null)
            {
                m_modelCollision = MyModels.GetModelOnlyData(modelCollision);
            }

            if (Render.ModelStorage != null)
            {
                this.PositionComp.LocalAABB = Render.GetModel().BoundingBox;

                bool idAllocationState = MyEntityIdentifier.AllocationSuspended;
                try
                {
                    MyEntityIdentifier.AllocationSuspended = false;

                    if (Subparts == null)
                    {
                        Subparts = new Dictionary <string, MyEntitySubpart>();
                    }
                    else
                    {
                        foreach (var existingSubpart in Subparts)
                        {
                            Hierarchy.RemoveChild(existingSubpart.Value);
                            existingSubpart.Value.Close();
                        }
                        Subparts.Clear();
                    }

                    MyEntitySubpart.Data data = new MyEntitySubpart.Data();
                    foreach (var dummy in Render.GetModel().Dummies)
                    {
                        // Check of mirrored matrix of dummy object is under fake, because characters have mirrored dummies
                        if (MyFakes.ENABLE_DUMMY_MIRROR_MATRIX_CHECK)
                        {
                            // This should not be here but if you want to check bad matrices of other types
                            if (!(this is MyCharacter))
                            {
                                Debug.Assert(!dummy.Value.Matrix.IsMirrored());
                            }
                        }

                        if (!MyEntitySubpart.GetSubpartFromDummy(model, dummy.Key, dummy.Value, ref data))
                        {
                            continue;
                        }

                        MyEntitySubpart subpart = new MyEntitySubpart();
                        subpart.Render.EnableColorMaskHsv = Render.EnableColorMaskHsv;
                        subpart.Render.ColorMaskHsv       = Render.ColorMaskHsv;
                        subpart.Init(null, data.File, this, null);
                        subpart.PositionComp.LocalMatrix = data.InitialTransform;
                        Subparts[data.Name] = subpart;

                        if (InScene)
                        {
                            subpart.OnAddedToScene(this);
                        }
                    }
                }
                finally
                {
                    MyEntityIdentifier.AllocationSuspended = idAllocationState;
                }

                if (Render.GetModel().GlassData != null)
                {
                    Render.NeedsDraw           = true;
                    Render.NeedsDrawFromParent = true;
                }
            }
            else
            {   //entities without model has box with side length = 1 by default
                float defaultBoxHalfSize = 0.5f;
                this.PositionComp.LocalAABB = new BoundingBox(new Vector3(-defaultBoxHalfSize), new Vector3(defaultBoxHalfSize));
            }
        }
        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;
        }