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); } } } }
void IMyDecalProxy.AddDecals(MyHitInfo hitInfo, MyStringHash source, object customdata, IMyDecalHandler decalHandler) { Debug.Assert(m_mapIdToBlock.Count > 0); MyCubeGridHitInfo gridHitInfo = customdata as MyCubeGridHitInfo; MySlimBlock block = m_mapIdToBlock.First().Value; MyPhysicalMaterialDefinition physicalMaterial = block.BlockDefinition.PhysicalMaterial; MyDecalRenderInfo renderable = new MyDecalRenderInfo(); renderable.Flags = physicalMaterial.Transparent ? MyDecalFlags.Transparent : MyDecalFlags.None; renderable.Position = Vector3D.Transform(hitInfo.Position, CubeGrid.PositionComp.WorldMatrixInvScaled); renderable.Normal = Vector3D.TransformNormal(hitInfo.Normal, CubeGrid.PositionComp.WorldMatrixInvScaled); renderable.RenderObjectId = CubeGrid.Render.GetRenderObjectID(); renderable.Material = MyStringHash.GetOrCompute(physicalMaterial.Id.SubtypeName); if (gridHitInfo != null) { VertexBoneIndicesWeights?boneIndicesWeights = gridHitInfo.Triangle.GetAffectingBoneIndicesWeights(ref m_boneIndexWeightTmp); if (boneIndicesWeights.HasValue) { renderable.BoneIndices = boneIndicesWeights.Value.Indices; renderable.BoneWeights = boneIndicesWeights.Value.Weights; var decalId = decalHandler.AddDecal(ref renderable); if (decalId != null) { CubeGrid.RenderData.AddDecal(Position, gridHitInfo, decalId.Value); } return; } } decalHandler.AddDecal(ref renderable); }
void IMyDecalProxy.AddDecals(ref MyHitInfo hitInfo, MyStringHash source, object customdata, IMyDecalHandler decalHandler, MyStringHash material) { MyCubeGrid.MyCubeGridHitInfo gridHitInfo = customdata as MyCubeGrid.MyCubeGridHitInfo; if (gridHitInfo != null) { MyPhysicalMaterialDefinition physicalMaterial = this.m_mapIdToBlock.First <KeyValuePair <ushort, MySlimBlock> >().Value.BlockDefinition.PhysicalMaterial; MyDecalRenderInfo renderInfo = new MyDecalRenderInfo { Position = Vector3D.Transform(hitInfo.Position, base.CubeGrid.PositionComp.WorldMatrixInvScaled), Normal = (Vector3)Vector3D.TransformNormal(hitInfo.Normal, base.CubeGrid.PositionComp.WorldMatrixInvScaled), RenderObjectIds = base.CubeGrid.Render.RenderObjectIDs, Source = source }; VertexBoneIndicesWeights?affectingBoneIndicesWeights = gridHitInfo.Triangle.GetAffectingBoneIndicesWeights(ref m_boneIndexWeightTmp); if (affectingBoneIndicesWeights != null) { renderInfo.BoneIndices = affectingBoneIndicesWeights.Value.Indices; renderInfo.BoneWeights = affectingBoneIndicesWeights.Value.Weights; } renderInfo.Material = (material.GetHashCode() != 0) ? material : MyStringHash.GetOrCompute(physicalMaterial.Id.SubtypeName); m_tmpIds.Clear(); decalHandler.AddDecal(ref renderInfo, m_tmpIds); foreach (uint num in m_tmpIds) { base.CubeGrid.RenderData.AddDecal(base.Position, gridHitInfo, num); } } }
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 <MyStringId, Dictionary <MyStringId, MySoundPair> >(); } if (!MaterialCues[type].ContainsKey(thisMaterial)) { MaterialCues[type][thisMaterial] = new Dictionary <MyStringId, MySoundPair>(); } 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 <MyStringId, MySoundPair>(); } if (!MaterialCues[type][otherMaterial.Key].ContainsKey(thisMaterial)) { MaterialCues[type][otherMaterial.Key][thisMaterial] = otherMaterial.Value; } } } }
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 (!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") && m_physicalMaterials.ContainsKey("Stone")) { return(m_physicalMaterials["Stone"]); } if (modelDef.Id.SubtypeName.Contains("Wood") && m_physicalMaterials.ContainsKey("Wood")) { return(m_physicalMaterials["Wood"]); } if (modelDef.Id.SubtypeName.Contains("Timber") && m_physicalMaterials.ContainsKey("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"]); }
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, MaterialProperties>(MyStringHash.Comparer); } MaterialProperties?selfProps = null; if (!MaterialCues[type].ContainsKey(material.InheritSoundsFrom)) { continue; } foreach (var pair in MaterialCues[type][material.InheritSoundsFrom]) { if (pair.Key == material.InheritSoundsFrom) { selfProps = 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 (selfProps != null) { MaterialCues[type][thisMaterial][thisMaterial] = selfProps.Value; MaterialCues[type][thisMaterial][material.InheritSoundsFrom] = selfProps.Value; MaterialCues[type][material.InheritSoundsFrom][thisMaterial] = selfProps.Value; } } } }
public static void PlayDestructionSound(MySlimBlock b) { MyPhysicalMaterialDefinition def = null; if (b.FatBlock is MyCompoundCubeBlock) { var compound = b.FatBlock as MyCompoundCubeBlock; if (compound.GetBlocksCount() > 0) { def = compound.GetBlocks()[0].BlockDefinition.PhysicalMaterial; } } else if (b.FatBlock is MyFracturedBlock) { MyCubeBlockDefinition bDef; if (MyDefinitionManager.Static.TryGetDefinition <MyCubeBlockDefinition>((b.FatBlock as MyFracturedBlock).OriginalBlocks[0], out bDef)) { def = bDef.PhysicalMaterial; } } else { def = b.BlockDefinition.PhysicalMaterial; } if (def == null) { return; } MySoundPair destructionCue; if (def.GeneralSounds.TryGetValue(m_destructionSound, out destructionCue) && !destructionCue.SoundId.IsNull) { var emmiter = MyAudioComponent.TryGetSoundEmitter(); if (emmiter == null) { return; } Vector3D pos; b.ComputeWorldCenter(out pos); emmiter.SetPosition(pos); emmiter.PlaySound(destructionCue); } }
void IMyDecalProxy.AddDecals(MyHitInfo hitInfo, MyStringHash source, object customdata, IMyDecalHandler decalHandler) { Debug.Assert(m_mapIdToBlock.Count > 0); MySlimBlock block = m_mapIdToBlock.First().Value; MyPhysicalMaterialDefinition physicalMaterial = block.BlockDefinition.PhysicalMaterial; MyDecalRenderInfo renderable = new MyDecalRenderInfo(); renderable.Flags = physicalMaterial.Transparent ? MyDecalFlags.Transparent : MyDecalFlags.None; renderable.Position = Vector3D.Transform(hitInfo.Position, CubeGrid.PositionComp.WorldMatrixInvScaled); renderable.Normal = Vector3D.TransformNormal(hitInfo.Normal, CubeGrid.PositionComp.WorldMatrixInvScaled); renderable.RenderObjectId = CubeGrid.Render.GetRenderObjectID(); renderable.Material = MyStringHash.GetOrCompute(physicalMaterial.Id.SubtypeName); var decalId = decalHandler.AddDecal(ref renderable); if (decalId != null) { CubeGrid.RenderData.AddDecal(Position, decalId.Value); } }
public static void PlayDestructionSound(MyFracturedPiece fp) { var bDef = MyDefinitionManager.Static.GetCubeBlockDefinition(fp.OriginalBlocks[0]); if (bDef == null) { return; } MyPhysicalMaterialDefinition def = bDef.PhysicalMaterial; MySoundPair destructionCue; if (def.GeneralSounds.TryGetValue(m_destructionSound, out destructionCue) && !destructionCue.SoundId.IsNull) { var emmiter = MyAudioComponent.TryGetSoundEmitter(); if (emmiter == null) { return; } Vector3D pos = fp.PositionComp.GetPosition(); emmiter.SetPosition(pos); emmiter.PlaySound(destructionCue); } }