public static MyFracturedPiece CreateFracturePiece(MyFracturedBlock fracturedBlock, bool sync) { System.Diagnostics.Debug.Assert(Sync.IsServer, "Only on server"); var m = fracturedBlock.CubeGrid.PositionComp.WorldMatrix; m.Translation = fracturedBlock.CubeGrid.GridIntegerToWorld(fracturedBlock.Position); var fp = CreateFracturePiece(ref fracturedBlock.Shape, fracturedBlock.CubeGrid.GetPhysicsBody().HavokWorld.DestructionWorld, ref m, false); fp.OriginalBlocks = fracturedBlock.OriginalBlocks; MyPhysicalModelDefinition def; if (MyDefinitionManager.Static.TryGetDefinition <MyPhysicalModelDefinition>(fp.OriginalBlocks[0], out def)) { fp.Physics.MaterialType = def.PhysicalMaterial.Id.SubtypeId; } // Check valid shapes from block definitions. if (MyFakes.ENABLE_FRACTURE_PIECE_SHAPE_CHECK) { fp.DebugCheckValidShapes(); } ProfilerShort.Begin("MyEntities.Add"); MyEntities.RaiseEntityCreated(fp); MyEntities.Add(fp); ProfilerShort.End(); return(fp); }
public void DebugCheckValidShapes() { bool hasBlock = false; HashSet <Tuple <string, float> > shapeNamesAndProgress = new HashSet <Tuple <string, float> >(); HashSet <Tuple <string, float> > shapeNamesAndProgressInShape = new HashSet <Tuple <string, float> >(); foreach (var defId in OriginalBlocks) { MyCubeBlockDefinition blockDef; if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(defId, out blockDef)) { hasBlock = true; MyFracturedBlock.GetAllBlockBreakableShapeNames(blockDef, shapeNamesAndProgress); } } MyFracturedBlock.GetAllBlockBreakableShapeNames(Shape, shapeNamesAndProgressInShape, 0); // Check foreach (var tupleInShape in shapeNamesAndProgressInShape) { bool found = false; foreach (var tuple in shapeNamesAndProgress) { if (tupleInShape.Item1 == tuple.Item1) { found = true; break; } } if (!found && hasBlock && !tupleInShape.Item1.ToLower().Contains("compound")) { Debug.Fail("Found shape which is not in any definition: " + tupleInShape.Item1); } } }
public static MyFracturedPiece CreateFracturePiece(MyFracturedBlock fracturedBlock, bool sync) { System.Diagnostics.Debug.Assert(Sync.IsServer, "Only on server"); var m = fracturedBlock.CubeGrid.PositionComp.WorldMatrix; m.Translation = fracturedBlock.CubeGrid.GridIntegerToWorld(fracturedBlock.Position); var fp = CreateFracturePiece(ref fracturedBlock.Shape, fracturedBlock.CubeGrid.Physics.HavokWorld.DestructionWorld, ref m, false); fp.OriginalBlocks = fracturedBlock.OriginalBlocks; MyPhysicalModelDefinition def; if (MyDefinitionManager.Static.TryGetDefinition <MyPhysicalModelDefinition>(fp.OriginalBlocks[0], out def)) { fp.Physics.MaterialType = def.PhysicalMaterial.Id.SubtypeId; } if (sync) { MySyncDestructions.CreateFracturePiece((Sandbox.Common.ObjectBuilders.MyObjectBuilder_FracturedPiece)fp.GetObjectBuilder()); } return(fp); }
public static MyFracturedPiece CreateFracturePiece(MyFracturedBlock fracturedBlock, bool sync) { MyPhysicalModelDefinition definition; MatrixD worldMatrix = fracturedBlock.CubeGrid.PositionComp.WorldMatrix; worldMatrix.Translation = fracturedBlock.CubeGrid.GridIntegerToWorld(fracturedBlock.Position); MyFracturedPiece piece = CreateFracturePiece(ref fracturedBlock.Shape, ref worldMatrix, false); piece.OriginalBlocks = fracturedBlock.OriginalBlocks; if (MyDefinitionManager.Static.TryGetDefinition <MyPhysicalModelDefinition>(piece.OriginalBlocks[0], out definition)) { piece.Physics.MaterialType = definition.PhysicalMaterial.Id.SubtypeId; } if (MyFakes.ENABLE_FRACTURE_PIECE_SHAPE_CHECK) { piece.DebugCheckValidShapes(); } if (MyExternalReplicable.FindByObject(piece) == null) { Sandbox.Game.Entities.MyEntities.RaiseEntityCreated(piece); } Sandbox.Game.Entities.MyEntities.Add(piece, true); return(piece); }