コード例 #1
0
        private void LoadMaterialSoundsInheritance(MyPhysicalMaterialDefinition material)
        {
            var thisMaterial = material.Id.SubtypeId;
            if (!m_loaded.Add(thisMaterial))
                return;
            if (material.InheritFrom != MyStringHash.NullOrEmpty)
            {
                MyPhysicalMaterialDefinition def;
                if (MyDefinitionManager.Static.TryGetDefinition<MyPhysicalMaterialDefinition>(new MyDefinitionId(typeof(MyObjectBuilder_PhysicalMaterialDefinition), material.InheritFrom), out def))
                {
                    if (!m_loaded.Contains(material.InheritFrom))
                        LoadMaterialSoundsInheritance(def);
                    foreach (var generalSound in def.GeneralSounds)
                    {
                        material.GeneralSounds[generalSound.Key] = generalSound.Value;
                    }
                }
                foreach (var type in MaterialDictionary.Keys)
                {
                    if (!MaterialDictionary[type].ContainsKey(thisMaterial))
                        MaterialDictionary[type][thisMaterial] = new Dictionary<MyStringHash, MaterialProperties>(MyStringHash.Comparer);
                    MaterialProperties? selfProps =  null;
                    if (!MaterialDictionary[type].ContainsKey(material.InheritFrom))
                        continue;
                    foreach (var pair in MaterialDictionary[type][material.InheritFrom])
                    {
                        if(pair.Key == material.InheritFrom)
                        {
                            selfProps = pair.Value;
                            continue;
                        }
                        // parent should no longer override
                        if (MaterialDictionary[type][thisMaterial].ContainsKey(pair.Key))
                        {
                            if (MaterialDictionary[type][pair.Key].ContainsKey(thisMaterial))
                            {
                                continue;
                            }
                            MaterialDictionary[type][pair.Key][thisMaterial] = pair.Value;
                        }
                        else
                        {
                            MaterialDictionary[type][thisMaterial][pair.Key] = pair.Value;
                            Debug.Assert(MaterialDictionary[type].ContainsKey(pair.Key));
                            MaterialDictionary[type][pair.Key][thisMaterial] = pair.Value;
                        }
                    }

                    if (selfProps != null)
                    {
                        MaterialDictionary[type][thisMaterial][thisMaterial] = selfProps.Value;
                        MaterialDictionary[type][thisMaterial][material.InheritFrom] = selfProps.Value;
                        MaterialDictionary[type][material.InheritFrom][thisMaterial] = selfProps.Value;
                    }
                }
            }
        }
コード例 #2
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_PhysicalModelDefinition;
            MyDebug.AssertDebug(ob != null);

            this.Model = ob.Model;
            this.PhysicalMaterial = MyDestructionData.GetPhysicalMaterial(this, ob.PhysicalMaterial);
            this.Mass = ob.Mass;
        }
コード例 #3
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_PhysicalModelDefinition;

            MyDebug.AssertDebug(ob != null);

            this.Model            = ob.Model;
            this.PhysicalMaterial = MyDestructionData.GetPhysicalMaterial(this, ob.PhysicalMaterial);
            this.Mass             = ob.Mass;
        }
コード例 #4
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_PhysicalModelDefinition;
            MyDebug.AssertDebug(ob != null);

            this.Model = ob.Model;
            if (GetType() == typeof (MyCubeBlockDefinition) || GetType().IsSubclassOf(typeof (MyCubeBlockDefinition)))
                this.PhysicalMaterial = MyDestructionData.GetPhysicalMaterial(this, ob.PhysicalMaterial);
            else
                m_material = ob.PhysicalMaterial;
            this.Mass = ob.Mass;
        }
コード例 #5
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            MyObjectBuilder_PhysicalModelDefinition definition = builder as MyObjectBuilder_PhysicalModelDefinition;

            this.Model = definition.Model;
            if ((base.GetType() == typeof(MyCubeBlockDefinition)) || base.GetType().IsSubclassOf(typeof(MyCubeBlockDefinition)))
            {
                this.PhysicalMaterial = MyDestructionData.GetPhysicalMaterial(this, definition.PhysicalMaterial);
            }
            else
            {
                this.m_material = definition.PhysicalMaterial;
            }
            this.Mass = definition.Mass;
        }
コード例 #6
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_PhysicalModelDefinition;

            MyDebug.AssertDebug(ob != null);

            this.Model = ob.Model;
            if (GetType() == typeof(MyCubeBlockDefinition) || GetType().IsSubclassOf(typeof(MyCubeBlockDefinition)))
            {
                this.PhysicalMaterial = MyDestructionData.GetPhysicalMaterial(this, ob.PhysicalMaterial);
            }
            else
            {
                m_material = ob.PhysicalMaterial;
            }
            this.Mass = ob.Mass;
        }
コード例 #7
0
        private void LoadMaterialSoundsInheritance(MyPhysicalMaterialDefinition material)
        {
            var thisMaterial = material.Id.SubtypeId;
            if (!m_loaded.Add(thisMaterial))
                return;
            if (material.InheritSoundsFrom != MyStringHash.NullOrEmpty)
            {
                MyPhysicalMaterialDefinition def;
                if (MyDefinitionManager.Static.TryGetDefinition<MyPhysicalMaterialDefinition>(new MyDefinitionId(typeof(MyObjectBuilder_PhysicalMaterialDefinition), material.InheritSoundsFrom), out def))
                {
                    if (!m_loaded.Contains(material.InheritSoundsFrom))
                        LoadMaterialSoundsInheritance(def);
                    foreach (var generalSound in def.GeneralSounds)
                    {
                        material.GeneralSounds[generalSound.Key] = generalSound.Value;
                    }
                }
                foreach (var type in MaterialCues.Keys)
                {
                    if (!MaterialCues[type].ContainsKey(thisMaterial))
                        MaterialCues[type][thisMaterial] = new Dictionary<MyStringHash, MySoundPair>(MyStringHash.Comparer);
                    MySoundPair selfCue =  null;
                    foreach (var pair in MaterialCues[type][material.InheritSoundsFrom])
                    {
                        if(pair.Key == material.InheritSoundsFrom)
                        {
                            selfCue = pair.Value;
                            continue;
                        }
                        MaterialCues[type][thisMaterial][pair.Key] = pair.Value;
                        Debug.Assert(MaterialCues[type].ContainsKey(pair.Key));
                        MaterialCues[type][pair.Key][thisMaterial] = pair.Value;
                    }

                    if (selfCue != null)
                    {
                        MaterialCues[type][thisMaterial][thisMaterial] = selfCue;
                        MaterialCues[type][thisMaterial][material.InheritSoundsFrom] = selfCue;
                        MaterialCues[type][material.InheritSoundsFrom][thisMaterial] = selfCue;
                    }
                }
            }
        }
コード例 #8
0
        private void LoadMaterialSounds(MyPhysicalMaterialDefinition material)
        {
            var thisMaterial = material.Id.SubtypeId;
            foreach (var materialSounds in material.CollisionSounds)
            {
                var type = materialSounds.Key;
                if (!MaterialCues.ContainsKey(type))
                    MaterialCues[type] = new Dictionary<MyStringHash, Dictionary<MyStringHash, MySoundPair>>(MyStringHash.Comparer);
                if (!MaterialCues[type].ContainsKey(thisMaterial))
                    MaterialCues[type][thisMaterial] = new Dictionary<MyStringHash, MySoundPair>(MyStringHash.Comparer);
                foreach (var otherMaterial in materialSounds.Value)
                {
                    MaterialCues[type][thisMaterial][otherMaterial.Key] = otherMaterial.Value;

                    //add the sound in oposite direction if not defined
                    if (!MaterialCues[type].ContainsKey(otherMaterial.Key))
                        MaterialCues[type][otherMaterial.Key] = new Dictionary<MyStringHash, MySoundPair>(MyStringHash.Comparer);
                    if (!MaterialCues[type][otherMaterial.Key].ContainsKey(thisMaterial))
                        MaterialCues[type][otherMaterial.Key][thisMaterial] = otherMaterial.Value;
                }
            }
        }
コード例 #9
0
        public static MyPhysicalMaterialDefinition GetPhysicalMaterial(MyPhysicalModelDefinition modelDef, string physicalMaterial)
        {
            if (m_physicalMaterials == null)
            {
                m_physicalMaterials = new Dictionary<string, MyPhysicalMaterialDefinition>();
                foreach (var physMat in MyDefinitionManager.Static.GetPhysicalMaterialDefinitions())
                {
                    m_physicalMaterials.Add(physMat.Id.SubtypeName, physMat);
                }

                m_physicalMaterials["Default"] = new MyPhysicalMaterialDefinition()
                {
                    Density = 1920,
                    HorisontalTransmissionMultiplier = 1,
                    HorisontalFragility = 2,
                    CollisionMultiplier = 1.4f,
                    SupportMultiplier = 1.5f             
                };
            }

            if(MyPerGameSettings.Destruction == false)
            {
              return m_physicalMaterials["Default"];
            }

            if (!string.IsNullOrEmpty(physicalMaterial))
            {
                if (m_physicalMaterials.ContainsKey(physicalMaterial))
                    return m_physicalMaterials[physicalMaterial];
                else
                {
                    string s = "ERROR: Physical material " + physicalMaterial + " does not exist!";
                    System.Diagnostics.Debug.Fail(s);
                    MyLog.Default.WriteLine(s);
                }
            }

            //MyLog.Default.WriteLine("WARNING: " + modelDef.Id.SubtypeName + " has no physical material specified, trying to autodetect from name");


            if (modelDef.Id.SubtypeName.Contains("Stone"))
            {
                return m_physicalMaterials["Stone"];
            }

            if (modelDef.Id.SubtypeName.Contains("Wood"))
            {
                return m_physicalMaterials["Wood"];
            }

            if (modelDef.Id.SubtypeName.Contains("Timber"))
            {
                return m_physicalMaterials["Wood"];
            }


            //MyLog.Default.WriteLine("WARNING: Unable to find proper physical material for " + modelDef.Id.SubtypeName + ", using Default");
            return m_physicalMaterials["Default"];
        }
コード例 #10
0
        private void LoadMaterialProperties(MyPhysicalMaterialDefinition material)
        {
            var thisMaterial = material.Id.SubtypeId;
            foreach (var materialSounds in material.CollisionProperties)
            {
                var type = materialSounds.Key;
                if (!MaterialDictionary.ContainsKey(type))
                    MaterialDictionary[type] = new Dictionary<MyStringHash, Dictionary<MyStringHash, MaterialProperties>>(MyStringHash.Comparer);
                if (!MaterialDictionary[type].ContainsKey(thisMaterial))
                    MaterialDictionary[type][thisMaterial] = new Dictionary<MyStringHash, MaterialProperties>(MyStringHash.Comparer);
                foreach (var otherMaterial in materialSounds.Value)
                {
                    MaterialDictionary[type][thisMaterial][otherMaterial.Key] = new MaterialProperties(otherMaterial.Value.Sound, otherMaterial.Value.ParticleEffect, otherMaterial.Value.ImpactSoundCues);

                    //add the sound in oposite direction if not defined
                    if (!MaterialDictionary[type].ContainsKey(otherMaterial.Key))
                        MaterialDictionary[type][otherMaterial.Key] = new Dictionary<MyStringHash, MaterialProperties>(MyStringHash.Comparer);
                    if (!MaterialDictionary[type][otherMaterial.Key].ContainsKey(thisMaterial))
                        MaterialDictionary[type][otherMaterial.Key][thisMaterial] = new MaterialProperties(otherMaterial.Value.Sound, otherMaterial.Value.ParticleEffect, otherMaterial.Value.ImpactSoundCues);
                }
            }
        }