private void DebugDrawMountPoints(MySlimBlock block) { if (block.FatBlock is MyCompoundCubeBlock) { MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock; foreach (MySlimBlock componentBlock in compoundBlock.GetBlocks()) { DebugDrawMountPoints(componentBlock); } } else { Matrix blockMatrix; block.GetLocalMatrix(out blockMatrix); MatrixD blockWorldMatrix = blockMatrix * m_cubeGrid.WorldMatrix; if (MyFakes.ENABLE_FRACTURE_COMPONENT && block.FatBlock != null && block.FatBlock.Components.Has <MyFractureComponentBase>()) { var fractureComponent = block.GetFractureComponent(); if (fractureComponent != null) { MyCubeBuilder.DrawMountPoints(m_cubeGrid.GridSize, block.BlockDefinition, blockWorldMatrix, fractureComponent.MountPoints.GetInternalArray()); } } else { MyCubeBuilder.DrawMountPoints(m_cubeGrid.GridSize, block.BlockDefinition, ref blockWorldMatrix); } } }
public override bool DebugDraw() { if (!MyDebugDrawSettings.DEBUG_DRAW_MOUNT_POINTS || m_block.MountPoints == null) { return(true); } //var cube = BoundingBox.CreateInvalid(); //for (int i = 0; i < m_block.OriginalBlocks.Count; i++) //{ // var b = m_block.OriginalBlocks[i]; // Matrix m2; // m_block.Orientations[i].GetMatrix(out m2); // var size = new Vector3(MyDefinitionManager.Static.GetCubeBlockDefinition(b).Size); // var bb2 = new BoundingBox(-size / 2, size / 2); // cube = cube.Include(bb2.Transform(m2)); //} //var obb = new MyOrientedBoundingBoxD(m_block.WorldMatrix.Translation, cube.HalfExtents * m_block.CubeGrid.GridSize, Quaternion.CreateFromRotationMatrix(m_block.WorldMatrix)); //VRageRender.MyRenderProxy.DebugDrawOBB(obb, Color.Red, 0.05f, false, false); MatrixD m = m_block.CubeGrid.PositionComp.WorldMatrix; m.Translation = m_block.CubeGrid.GridIntegerToWorld(m_block.Position); MyCubeBuilder.DrawMountPoints(m_block.CubeGrid.GridSize, m_block.BlockDefinition, m, m_block.MountPoints.ToArray()); return(true); }
static void OnMessageSpawnGrid(ref SpawnGridMsg msg, MyNetworkClient sender) { Debug.Assert(MyCubeBuilder.BuildComponent != null, "The build component was not set in cube builder!"); MyEntity builder = null; MyEntities.TryGetEntityById(msg.BuilderEntityId, out builder); var definition = Definitions.MyDefinitionManager.Static.GetCubeBlockDefinition(msg.Definition); MatrixD worldMatrix = MatrixD.CreateWorld(msg.Position, msg.Forward, msg.Up); var reply = new SpawnGridReplyMsg(); MyCubeBuilder.BuildComponent.GetGridSpawnMaterials(definition, worldMatrix, msg.Static); bool canSpawn = MyCubeBuilder.BuildComponent.HasBuildingMaterials(builder); MySession.Static.SyncLayer.SendMessage(ref reply, sender.SteamUserId, canSpawn ? MyTransportMessageEnum.Success : MyTransportMessageEnum.Failure); if (!canSpawn) { return; } MyCubeBuilder.SpawnGrid(definition, worldMatrix, builder, msg.Static); }
private bool PasteGridsInStaticMode(bool deactivate) { List <MyObjectBuilder_CubeGrid> itemsToAdd = new List <MyObjectBuilder_CubeGrid>(); List <MatrixD> list2 = new List <MatrixD>(); MyObjectBuilder_CubeGrid grid = base.CopiedGrids[0]; base.BeforeCreateGrid(grid); itemsToAdd.Add(grid); MatrixD worldMatrix = base.PreviewGrids[0].WorldMatrix; MyObjectBuilder_CubeGrid grid2 = MyCubeBuilder.ConvertGridBuilderToStatic(grid, worldMatrix); base.CopiedGrids[0] = grid2; list2.Add(worldMatrix); for (int i = 1; i < base.CopiedGrids.Count; i++) { MyObjectBuilder_CubeGrid grid3 = base.CopiedGrids[i]; base.BeforeCreateGrid(grid3); itemsToAdd.Add(grid3); MatrixD item = base.PreviewGrids[i].WorldMatrix; list2.Add(item); if (base.CopiedGrids[i].IsStatic) { base.CopiedGrids[i] = MyCubeBuilder.ConvertGridBuilderToStatic(grid3, item); } } bool flag = base.PasteGridInternal(deactivate, null, base.m_touchingGrids, null, true, true); base.CopiedGrids.Clear(); base.CopiedGrids.AddList <MyObjectBuilder_CubeGrid>(itemsToAdd); for (int j = 0; j < base.PreviewGrids.Count; j++) { base.PreviewGrids[j].WorldMatrix = list2[j]; } return(flag); }
private void CheckProjection() { var weldBlock = GetTargetBlock(); if (weldBlock != null && CanWeld(weldBlock)) { m_targetProjectionGrid = null; return; } var info = FindProjectedBlock(); if (info.raycastResult != MyProjectorBase.BuildCheckResult.NotFound) { if (info.raycastResult == MyProjectorBase.BuildCheckResult.OK) { MyCubeBuilder.DrawSemiTransparentBox(info.hitCube.CubeGrid, info.hitCube, Color.Green.ToVector4(), true); m_targetProjectionCube = info.hitCube.Position; m_targetProjectionGrid = info.hitCube.CubeGrid; return; } else if (info.raycastResult == MyProjectorBase.BuildCheckResult.IntersectedWithGrid || info.raycastResult == MyProjectorBase.BuildCheckResult.IntersectedWithSomethingElse) { MyCubeBuilder.DrawSemiTransparentBox(info.hitCube.CubeGrid, info.hitCube, Color.Red.ToVector4(), true); } else if (info.raycastResult == MyProjectorBase.BuildCheckResult.NotConnected) { MyCubeBuilder.DrawSemiTransparentBox(info.hitCube.CubeGrid, info.hitCube, Color.Yellow.ToVector4(), true); } } m_targetProjectionGrid = null; }
protected virtual void SetupDragDistance() { if (!IsActive) { return; } if (PreviewGrids.Count > 0) { double?currentRayInts = MyCubeBuilder.GetCurrentRayIntersection(); if (currentRayInts.HasValue && m_dragDistance > currentRayInts.Value) { m_dragDistance = (float)currentRayInts.Value; } float boxRadius = (float)PreviewGrids[0].PositionComp.WorldAABB.HalfExtents.Length(); float dragDistance = 2.5f * boxRadius; if (m_dragDistance < dragDistance) { m_dragDistance = dragDistance; } } else { m_dragDistance = 0; } }
private void DebugDrawMountPoints(MySlimBlock block) { if (block.FatBlock is MyCompoundCubeBlock) { foreach (MySlimBlock block2 in (block.FatBlock as MyCompoundCubeBlock).GetBlocks()) { this.DebugDrawMountPoints(block2); } } else { Matrix matrix; block.GetLocalMatrix(out matrix); MatrixD drawMatrix = matrix * this.m_cubeGrid.WorldMatrix; if ((!MyFakes.ENABLE_FRACTURE_COMPONENT || (block.FatBlock == null)) || !block.FatBlock.Components.Has <MyFractureComponentBase>()) { MyCubeBuilder.DrawMountPoints(this.m_cubeGrid.GridSize, block.BlockDefinition, ref drawMatrix); } else { MyFractureComponentCubeBlock fractureComponent = block.GetFractureComponent(); if (fractureComponent != null) { MyCubeBuilder.DrawMountPoints(this.m_cubeGrid.GridSize, block.BlockDefinition, drawMatrix, fractureComponent.MountPoints.GetInternalArray <MyCubeBlockDefinition.MountPoint>()); } } } }
private bool PasteGridsInStaticMode(MyInventoryBase buildInventory, bool deactivate) { // Paste generates grid from builder and use matrix from preview List <MyObjectBuilder_CubeGrid> copiedGridsOrig = new List <MyObjectBuilder_CubeGrid>(); List <MatrixD> previewGridsWorldMatrices = new List <MatrixD>(); { // First grid is forced static MyObjectBuilder_CubeGrid originalCopiedGrid = CopiedGrids[0]; BeforeCreateGrid(originalCopiedGrid); copiedGridsOrig.Add(originalCopiedGrid); MatrixD previewGridWorldMatrix = PreviewGrids[0].WorldMatrix; // Convert grid builder to static var gridBuilder = MyCubeBuilder.ConvertGridBuilderToStatic(originalCopiedGrid, previewGridWorldMatrix); // Set it to copied grids CopiedGrids[0] = gridBuilder; previewGridsWorldMatrices.Add(previewGridWorldMatrix); //PreviewGrids[0].WorldMatrix = MatrixD.CreateTranslation(previewGridWorldMatrix.Translation); } for (int i = 1; i < CopiedGrids.Count; ++i) { MyObjectBuilder_CubeGrid originalCopiedGrid = CopiedGrids[i]; BeforeCreateGrid(originalCopiedGrid); copiedGridsOrig.Add(originalCopiedGrid); MatrixD previewGridWorldMatrix = PreviewGrids[i].WorldMatrix; previewGridsWorldMatrices.Add(previewGridWorldMatrix); if (CopiedGrids[i].IsStatic) { // Convert grid builder to static var gridBuilder = MyCubeBuilder.ConvertGridBuilderToStatic(originalCopiedGrid, previewGridWorldMatrix); // Set it to copied grids CopiedGrids[i] = gridBuilder; //PreviewGrids[i].WorldMatrix = MatrixD.CreateTranslation(previewGridWorldMatrix.Translation); } } Debug.Assert(CopiedGrids.Count == copiedGridsOrig.Count); Debug.Assert(CopiedGrids.Count == previewGridsWorldMatrices.Count); bool result = PasteGridInternal(buildInventory: buildInventory, deactivate: deactivate, multiBlock: true, touchingGrids: m_touchingGrids); // Set original grids back CopiedGrids.Clear(); CopiedGrids.AddList(copiedGridsOrig); for (int i = 0; i < PreviewGrids.Count; ++i) { PreviewGrids[i].WorldMatrix = previewGridsWorldMatrices[i]; } return(result); }
private void FixSnapTransformationBase6() { if (base.CopiedGrids.Count != 0) { MyCubeGrid hitEntity = base.m_hitEntity as MyCubeGrid; if (hitEntity != null) { Matrix rotationDeltaMatrixToHitGrid = this.GetRotationDeltaMatrixToHitGrid(hitEntity); foreach (MyCubeGrid local1 in base.PreviewGrids) { MatrixD worldMatrix = local1.WorldMatrix; Matrix matrix2 = (Matrix)(worldMatrix.GetOrientation() * rotationDeltaMatrixToHitGrid); MatrixD xd = MatrixD.CreateWorld(base.m_pastePosition, matrix2.Forward, matrix2.Up); local1.PositionComp.SetWorldMatrix(xd, null, false, true, true, false, false, false); } if ((hitEntity.GridSizeEnum == MyCubeSize.Large) && (base.PreviewGrids[0].GridSizeEnum == MyCubeSize.Small)) { base.m_pastePosition = hitEntity.GridIntegerToWorld(MyCubeBuilder.TransformLargeGridHitCoordToSmallGrid(base.m_hitPos, hitEntity.PositionComp.WorldMatrixNormalizedInv, hitEntity.GridSize)); } else { Vector3I vectori = Vector3I.Round(base.m_hitNormal); Vector3I gridOffset = hitEntity.WorldToGridInteger(base.m_pastePosition); Vector3I min = base.PreviewGrids[0].Min; Vector3I vectori4 = Vector3I.Abs(Vector3I.Round(Vector3D.TransformNormal(Vector3D.TransformNormal((Vector3D)((base.PreviewGrids[0].Max - min) + Vector3I.One), base.PreviewGrids[0].WorldMatrix), hitEntity.PositionComp.WorldMatrixNormalizedInv))); int num = Math.Abs(Vector3I.Dot(ref vectori, ref vectori4)); int num2 = 0; while (true) { if ((num2 >= num) || hitEntity.CanMergeCubes(base.PreviewGrids[0], gridOffset)) { if (num2 == num) { gridOffset = hitEntity.WorldToGridInteger(base.m_pastePosition); } base.m_pastePosition = hitEntity.GridIntegerToWorld(gridOffset); break; } gridOffset = (Vector3I)(gridOffset + vectori); num2++; } } for (int i = 0; i < base.PreviewGrids.Count; i++) { MyCubeGrid local2 = base.PreviewGrids[i]; MatrixD worldMatrix = local2.WorldMatrix; worldMatrix.Translation = base.m_pastePosition + Vector3.Transform(base.m_copiedGridOffsets[i], rotationDeltaMatrixToHitGrid); local2.PositionComp.SetWorldMatrix(worldMatrix, null, false, true, true, false, false, false); } if (MyDebugDrawSettings.DEBUG_DRAW_COPY_PASTE) { MyRenderProxy.DebugDrawLine3D(base.m_hitPos, base.m_hitPos + base.m_hitNormal, Color.Red, Color.Green, false, false); } } } }
public override void Execute(Data.Data data) { var player = Utils.GetPlayer(); if (player != null) { var id = new MyDefinitionId((MyObjectBuilderType)typeof(MyObjectBuilder_Warhead), "LargeWarhead"); var definitionBase = (MyWarheadDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(id); var pos = player.GetPosition() + Vector3.Up * 100; MatrixD world = MatrixD.CreateWorld(pos, Vector3.Forward, Vector3.Up); Vector3 color = Color.Red.ColorToHSV(); MyCubeBuilder.SpawnDynamicGrid(definitionBase, player.Character.Entity, world, color, MyStringHash.NullOrEmpty); } }
public override void DebugDraw() { if (!MyDebugDrawSettings.DEBUG_DRAW_MOUNT_POINTS || !m_block.Components.Has <MyFractureComponentBase>()) { return; } MyFractureComponentCubeBlock component = m_block.GetFractureComponent(); if (component != null) { MatrixD m = m_block.CubeGrid.PositionComp.WorldMatrix; m.Translation = m_block.CubeGrid.GridIntegerToWorld(m_block.Position); MyCubeBuilder.DrawMountPoints(m_block.CubeGrid.GridSize, m_block.BlockDefinition, m, component.MountPoints.ToArray()); } }
private void UpdatePreview() { if (PreviewGrids == null) { return; } if (m_visible == false || HasPreviewBBox == false) { return; } // Switch off shadows - does not work //foreach (var grid in PreviewGrids) //{ // grid.Render.CastShadows = false; // foreach (var block in grid.GetBlocks()) // { // if (block.FatBlock != null) // { // block.FatBlock.Render.CastShadows = false; // } // } //} string lineMaterial = m_canBePlaced ? "GizmoDrawLine" : "GizmoDrawLineRed"; Color white = Color.White; foreach (var grid in PreviewGrids) { BoundingBoxD localAABB = (BoundingBoxD)grid.PositionComp.LocalAABB; MatrixD drawMatrix = grid.PositionComp.WorldMatrix; MySimpleObjectDraw.DrawTransparentBox(ref drawMatrix, ref localAABB, ref white, MySimpleObjectRasterizer.Wireframe, 1, 0.04f, lineMaterial: lineMaterial); //foreach (var block in grid.GetBlocks()) //{ // if (block.FatBlock != null) // MyEntities.EnableEntityBoundingBoxDraw(block.FatBlock, true, color, lineWidth: 0.04f); //} } if (RemoveBlock != null) { Vector4 red = new Vector4(Color.Red.ToVector3() * 0.8f, 1); MyCubeBuilder.DrawSemiTransparentBox(RemoveBlock.CubeGrid, RemoveBlock, red, lineMaterial: "GizmoDrawLineRed"); } }
private void CreateMountPoints() { ProfilerShort.Begin("FractureComponent.CreateMountPoints"); Debug.Assert(m_tmpChildren.Count == 0); if (MyFakes.FRACTURED_BLOCK_AABB_MOUNT_POINTS) { if (MountPoints == null) { MountPoints = new List <MyCubeBlockDefinition.MountPoint>(); } else { MountPoints.Clear(); } var blockDef = Block.BlockDefinition; var size = new Vector3(blockDef.Size); var bb = new BoundingBox(-size / 2, size / 2); var he = bb.HalfExtents; bb.Min += he; bb.Max += he; Shape.GetChildren(m_tmpChildren); if (m_tmpChildren.Count > 0) { foreach (var child in m_tmpChildren) { var shape = child.Shape; shape = AddMountForShape(shape, Matrix.Identity, ref bb, Block.CubeGrid.GridSize, MountPoints); } } else { AddMountForShape(Shape, Matrix.Identity, ref bb, Block.CubeGrid.GridSize, MountPoints); } m_tmpChildren.Clear(); } else { MountPoints = MyCubeBuilder.AutogenerateMountpoints(new HkShape[] { Shape.GetShape() }, Block.CubeGrid.GridSize); } ProfilerShort.End(); }
void onClick_Save(MyGuiControlButton sender) { foreach (var def in MyDefinitionManager.Static.GetAllDefinitions()) { MyCubeBlockDefinition cubeDef = def as MyCubeBlockDefinition; if (cubeDef != null) { if (!string.IsNullOrEmpty(cubeDef.Model)) { var model = VRage.Game.Models.MyModels.GetModel(cubeDef.Model); var newMountpoints = MyCubeBuilder.AutogenerateMountpoints(model, MyDefinitionManager.Static.GetCubeSize(cubeDef.CubeSize)); cubeDef.MountPoints = newMountpoints.ToArray(); } } } MyDefinitionManager.Static.Save("CubeBlocks_*.*"); }
static void OnMessageAfterGridCreated(ref AfterGridCreatedMsg msg, MyNetworkClient sender) { MyEntity builder; MyEntity gridEntity; MyCubeGrid grid; MyEntities.TryGetEntityById(msg.BuilderEntityId, out builder); MyEntities.TryGetEntityById(msg.GridEntityId, out gridEntity); grid = gridEntity as MyCubeGrid; Debug.Assert(grid != null, "Could not find the grid entity!"); if (grid == null) { return; } MyCubeBuilder.AfterGridBuild(builder, grid); }
static void OnMessageSpawnGrid(ref SpawnGridMsg msg, MyNetworkClient sender) { if (Sync.IsServer) { var definition = Definitions.MyDefinitionManager.Static.GetCubeBlockDefinition(msg.Definition); MatrixD worldMatrix = MatrixD.CreateWorld(msg.Position, msg.Forward, msg.Up); MyCubeGrid grid = null; if (msg.Static) { grid = MyCubeBuilder.SpawnStaticGrid(definition, worldMatrix); } else { grid = MyCubeBuilder.SpawnDynamicGrid(definition, worldMatrix); } if (grid != null) { msg.Grid = grid.GetObjectBuilder() as MyObjectBuilder_CubeGrid; MySession.Static.SyncLayer.SendMessageToAll(ref msg); } if (grid != null && msg.Static) { MyCubeBuilder.AfterStaticGridSpawn(grid); } } else { System.Diagnostics.Debug.Assert(msg.Grid != null, "Client must obtain complete grid from server"); MyCubeGrid grid = MyEntities.CreateFromObjectBuilderAndAdd(msg.Grid) as MyCubeGrid; if (grid != null) { if (grid.IsStatic) { MyCubeBuilder.AfterStaticGridSpawn(grid); } } } }
private void DebugDrawMountPoints(MySlimBlock block) { if (block.FatBlock is MyCompoundCubeBlock) { MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock; foreach (MySlimBlock componentBlock in compoundBlock.GetBlocks()) { DebugDrawMountPoints(componentBlock); } } else { MatrixD blockWorldMatrix = m_cubeGrid.WorldMatrix; Matrix blockMatrix; block.Orientation.GetMatrix(out blockMatrix); blockWorldMatrix *= blockMatrix; blockWorldMatrix.Translation = m_cubeGrid.GridIntegerToWorld(block.Position); MyCubeBuilder.DrawMountPoints(m_cubeGrid.GridSize, block.BlockDefinition, ref blockWorldMatrix); } }
private void CreateMountPoints() { ProfilerShort.Begin("FB.CreateMountPoints"); if (MyFakes.FRACTURED_BLOCK_AABB_MOUNT_POINTS) { MountPoints = new List <MyCubeBlockDefinition.MountPoint>(); var blockBB = BoundingBox.CreateInvalid(); for (int i = 0; i < OriginalBlocks.Count; i++) { var b = OriginalBlocks[i]; Matrix m; Orientations[i].GetMatrix(out m); var size = new Vector3(MyDefinitionManager.Static.GetCubeBlockDefinition(b).Size); var bb = new BoundingBox(-size / 2, size / 2); blockBB = blockBB.Include(bb.Transform(m)); } var he = blockBB.HalfExtents; blockBB.Min += he; blockBB.Max += he; Shape.GetChildren(m_children); foreach (var child in m_children) { var shape = child.Shape; shape = MyFractureComponentCubeBlock.AddMountForShape(shape, child.GetTransform(), ref blockBB, CubeGrid.GridSize, MountPoints); } if (m_children.Count == 0) { MyFractureComponentCubeBlock.AddMountForShape(Shape, Matrix.Identity, ref blockBB, CubeGrid.GridSize, MountPoints); } m_children.Clear(); } else { MountPoints = MyCubeBuilder.AutogenerateMountpoints(new HkShape[] { Shape.GetShape() }, CubeGrid.GridSize); } ProfilerShort.End(); }
public override void Execute(Data.Data data, Dictionary <string, object> parameters) { SessionHandler.EnqueueAction(() => { var player = Utils.GetPlayer(); if (player != null) { var id = new MyDefinitionId((MyObjectBuilderType)typeof(MyObjectBuilder_Warhead), "LargeWarhead"); var definitionBase = (MyWarheadDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(id); var inSpace = Utils.IsInSpace(player.GetPosition()); var up = player.Character.PositionComp.GetOrientation().Up; up.Normalize(); var pos = player.GetPosition() + up * GetEventValue(inSpace && SpaceDistance != null ? SpaceDistance: Distance, 100, parameters); MatrixD world = MatrixD.CreateWorld(pos, Vector3.Forward, Vector3.Up); Vector3 color = Color.Red.ColorToHSV(); var pirateFaction = MySession.Static.Factions.TryGetFactionByTag("SPRT"); MyCubeBuilder.SpawnDynamicGrid(definitionBase, player.Character, world, color, MyStringHash.NullOrEmpty, 0L, MyCubeBuilder.SpawnFlags.Default | MyCubeBuilder.SpawnFlags.SpawnAsMaster, Hostile ? pirateFaction.FounderId: player.Character.EntityId, entity => { var grid = (MyCubeGrid)entity; foreach (var warhead in grid.GetFatBlocks <MyWarhead>()) { warhead.IsArmed = true; warhead.DetonationTime = (float)GetEventValue(inSpace && SpaceCountdown != null ? SpaceCountdown: Countdown, 10, parameters); warhead.StartCountdown(); } var direction = player.GetPosition() - grid.PositionComp.GetPosition(); direction.Normalize(); grid.Physics.LinearVelocity += direction * GetEventValue(inSpace && SpaceSpeed != null ? SpaceSpeed: Speed, 5, parameters); }); } }); }
private unsafe void CreateMountPoints() { if (!MyFakes.FRACTURED_BLOCK_AABB_MOUNT_POINTS) { HkShape[] shapes = new HkShape[] { this.Shape.GetShape() }; this.MountPoints = MyCubeBuilder.AutogenerateMountpoints(shapes, base.CubeGrid.GridSize); } else { this.MountPoints = new List <MyCubeBlockDefinition.MountPoint>(); BoundingBox blockBB = BoundingBox.CreateInvalid(); for (int i = 0; i < this.OriginalBlocks.Count; i++) { Matrix matrix; MyDefinitionId id = this.OriginalBlocks[i]; this.Orientations[i].GetMatrix(out matrix); Vector3 vector2 = new Vector3(MyDefinitionManager.Static.GetCubeBlockDefinition(id).Size); BoundingBox box2 = new BoundingBox(-vector2 / 2f, vector2 / 2f); blockBB = blockBB.Include(box2.Transform(matrix)); } Vector3 halfExtents = blockBB.HalfExtents; Vector3 *vectorPtr1 = (Vector3 *)ref blockBB.Min; vectorPtr1[0] += halfExtents; Vector3 *vectorPtr2 = (Vector3 *)ref blockBB.Max; vectorPtr2[0] += halfExtents; this.Shape.GetChildren(m_children); foreach (HkdShapeInstanceInfo info in m_children) { MyFractureComponentCubeBlock.AddMountForShape(info.Shape, info.GetTransform(), ref blockBB, base.CubeGrid.GridSize, this.MountPoints); } if (m_children.Count == 0) { MyFractureComponentCubeBlock.AddMountForShape(this.Shape, Matrix.Identity, ref blockBB, base.CubeGrid.GridSize, this.MountPoints); } m_children.Clear(); } }
private void UpdatePreview() { if ((base.PreviewGrids != null) && (base.m_visible && this.HasPreviewBBox)) { Vector4? nullable2; MyStringId id = base.m_canBePlaced ? MyGridClipboard.ID_GIZMO_DRAW_LINE : MyGridClipboard.ID_GIZMO_DRAW_LINE_RED; Color white = Color.White; foreach (MyCubeGrid local1 in base.PreviewGrids) { BoundingBoxD localAABB = local1.PositionComp.LocalAABB; MatrixD worldMatrix = local1.PositionComp.WorldMatrix; MyStringId? faceMaterial = null; MySimpleObjectDraw.DrawTransparentBox(ref worldMatrix, ref localAABB, ref white, MySimpleObjectRasterizer.Wireframe, 1, 0.04f, faceMaterial, new MyStringId?(id), false, -1, MyBillboard.BlendTypeEnum.Standard, 1f, null); } Vector4 color = new Vector4(Color.Red.ToVector3() * 0.8f, 1f); if (this.RemoveBlocksInMultiBlock.Count <= 0) { if (this.RemoveBlock != null) { nullable2 = null; MyCubeBuilder.DrawSemiTransparentBox(this.RemoveBlock.CubeGrid, this.RemoveBlock, color, false, new MyStringId?(MyGridClipboard.ID_GIZMO_DRAW_LINE_RED), nullable2); } } else { this.m_tmpBlockPositionsSet.Clear(); MyCubeBuilder.GetAllBlocksPositions(this.RemoveBlocksInMultiBlock, this.m_tmpBlockPositionsSet); foreach (Vector3I local2 in this.m_tmpBlockPositionsSet) { nullable2 = null; MyCubeBuilder.DrawSemiTransparentBox(local2, local2, this.RemoveBlock.CubeGrid, color, false, new MyStringId?(MyGridClipboard.ID_GIZMO_DRAW_LINE_RED), nullable2); } this.m_tmpBlockPositionsSet.Clear(); } } }
private bool TestPlacement() { bool retval = true; m_touchingGrids.Clear(); for (int i = 0; i < PreviewGrids.Count; ++i) { var grid = PreviewGrids[i]; m_touchingGrids.Add(null); if (MyCubeBuilder.Static.DynamicMode) { if (!m_dynamicBuildAllowed) { var settings = m_settings.GetGridPlacementSettings(grid, false); retval = retval && MyCubeGrid.TestPlacementArea(grid, false, ref settings, (BoundingBoxD)grid.PositionComp.LocalAABB, true); //foreach (var block in grid.GetBlocks()) //{ // Vector3 minLocal = block.Min * PreviewGrids[i].GridSize - Vector3.Half * PreviewGrids[i].GridSize; // Vector3 maxLocal = block.Max * PreviewGrids[i].GridSize + Vector3.Half * PreviewGrids[i].GridSize; // BoundingBoxD aabbLocal = new BoundingBoxD(minLocal, maxLocal); // retval &= MyCubeGrid.TestPlacementArea(grid, false, ref settings, aabbLocal, true); // if (!retval) // break; //} } } else { if (i == 0 && m_hitEntity is MyCubeGrid && IsSnapped && SnapMode == MyGridPlacementSettings.SnapMode.Base6Directions) { var settings = grid.GridSizeEnum == MyCubeSize.Large ? MyPerGameSettings.BuildingSettings.LargeStaticGrid : MyPerGameSettings.BuildingSettings.SmallStaticGrid; var hitGrid = m_hitEntity as MyCubeGrid; if (hitGrid.GridSizeEnum == MyCubeSize.Small && grid.GridSizeEnum == MyCubeSize.Large) { retval = false; break; } bool smallOnLargeGrid = hitGrid.GridSizeEnum == MyCubeSize.Large && grid.GridSizeEnum == MyCubeSize.Small; if (MyFakes.ENABLE_STATIC_SMALL_GRID_ON_LARGE /*&& grid.IsStatic*/ && smallOnLargeGrid) { if (!hitGrid.IsStatic) { retval = false; break; } foreach (var block in grid.CubeBlocks) { if (block.FatBlock is MyCompoundCubeBlock) { MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock; foreach (var blockInCompound in compoundBlock.GetBlocks()) { retval = retval && TestBlockPlacement(blockInCompound, ref settings); if (!retval) { break; } } } else { retval = retval && TestBlockPlacement(block, ref settings); } if (!retval) { break; } } } else { retval = retval && TestGridPlacementOnGrid(grid, ref settings, hitGrid); } } else { // Check with grid settings { MyCubeGrid touchingGrid = null; var settings = i == 0 ? (grid.GridSizeEnum == MyCubeSize.Large ? MyPerGameSettings.BuildingSettings.LargeStaticGrid : MyPerGameSettings.BuildingSettings.SmallStaticGrid) : MyPerGameSettings.BuildingSettings.GetGridPlacementSettings(grid); if (grid.IsStatic) { foreach (var block in grid.CubeBlocks) { if (block.FatBlock is MyCompoundCubeBlock) { MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock; foreach (var blockInCompound in compoundBlock.GetBlocks()) { MyCubeGrid touchingGridLocal = null; retval = retval && TestBlockPlacementNoAABBInflate(blockInCompound, ref settings, out touchingGridLocal); if (retval && touchingGridLocal != null && touchingGrid == null) { touchingGrid = touchingGridLocal; } if (!retval) { break; } } } else { MyCubeGrid touchingGridLocal = null; retval = retval && TestBlockPlacementNoAABBInflate(block, ref settings, out touchingGridLocal); if (retval && touchingGridLocal != null && touchingGrid == null) { touchingGrid = touchingGridLocal; } } if (!retval) { break; } } if (retval && touchingGrid != null) { m_touchingGrids[i] = touchingGrid; } } else { foreach (var block in grid.CubeBlocks) { Vector3 minLocal = block.Min * PreviewGrids[i].GridSize - Vector3.Half * PreviewGrids[i].GridSize; Vector3 maxLocal = block.Max * PreviewGrids[i].GridSize + Vector3.Half * PreviewGrids[i].GridSize; BoundingBoxD aabbLocal = new BoundingBoxD(minLocal, maxLocal); retval = retval && MyCubeGrid.TestPlacementArea(grid, grid.IsStatic, ref settings, aabbLocal, true); if (!retval) { break; } } m_touchingGrids[i] = null; } } // Check connectivity with touching grid if (retval && m_touchingGrids[i] != null) { var settings = grid.GridSizeEnum == MyCubeSize.Large ? MyPerGameSettings.BuildingSettings.LargeStaticGrid : MyPerGameSettings.BuildingSettings.SmallStaticGrid; retval = retval && TestGridPlacementOnGrid(grid, ref settings, m_touchingGrids[i]); } // Check with paste settings only first grid { if (retval && i == 0) { bool smallStaticGrid = grid.GridSizeEnum == MyCubeSize.Small && grid.IsStatic; if (smallStaticGrid || !grid.IsStatic) { var settings = i == 0 ? m_settings.GetGridPlacementSettings(grid, false) : MyPerGameSettings.BuildingSettings.SmallStaticGrid; bool localRetVal = true; foreach (var block in grid.CubeBlocks) { Vector3 minLocal = block.Min * PreviewGrids[i].GridSize - Vector3.Half * PreviewGrids[i].GridSize; Vector3 maxLocal = block.Max * PreviewGrids[i].GridSize + Vector3.Half * PreviewGrids[i].GridSize; BoundingBoxD blockLocalAABB = new BoundingBoxD(minLocal, maxLocal); localRetVal = localRetVal && MyCubeGrid.TestPlacementArea(grid, false, ref settings, blockLocalAABB, false); if (!localRetVal) { break; } } retval &= !localRetVal; } else if (m_touchingGrids[i] == null) { var settings = m_settings.GetGridPlacementSettings(grid, i == 0 ? true : grid.IsStatic); MyCubeGrid touchingGridLocal = null; bool localRetVal = false; foreach (var block in grid.CubeBlocks) { if (block.FatBlock is MyCompoundCubeBlock) { MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock; foreach (var blockInCompound in compoundBlock.GetBlocks()) { localRetVal |= TestBlockPlacementNoAABBInflate(blockInCompound, ref settings, out touchingGridLocal); if (localRetVal) { break; } } } else { localRetVal |= TestBlockPlacementNoAABBInflate(block, ref settings, out touchingGridLocal); } if (localRetVal) { break; } } retval &= localRetVal; } } } } } BoundingBoxD aabb = (BoundingBoxD)grid.PositionComp.LocalAABB; MatrixD invGridWorlMatrix = grid.PositionComp.GetWorldMatrixNormalizedInv(); // Character collisions. if (MySector.MainCamera != null) { Vector3D cameraPos = Vector3D.Transform(MySector.MainCamera.Position, invGridWorlMatrix); retval = retval && aabb.Contains(cameraPos) != ContainmentType.Contains; } if (retval) { m_tmpCollisionPoints.Clear(); MyCubeBuilder.PrepareCharacterCollisionPoints(m_tmpCollisionPoints); foreach (var pt in m_tmpCollisionPoints) { Vector3D ptLocal = Vector3D.Transform(pt, invGridWorlMatrix); retval = retval && aabb.Contains(ptLocal) != ContainmentType.Contains; if (!retval) { break; } } } if (!retval) { break; } } return(retval); }
public override void Execute(Data.Data data, Dictionary <string, object> parameters) { SessionHandler.EnqueueAction(() => { var player = Utils.GetPlayer(); if (player != null) { var id = new MyDefinitionId((MyObjectBuilderType)typeof(MyObjectBuilder_RadioAntenna), "SmallBlockRadioAntenna"); var up = player.Character.PositionComp.GetOrientation().Up; up.Normalize(); var definitionBase = (MyRadioAntennaDefinition)MyDefinitionManager.Static.GetCubeBlockDefinition(id); var pos = player.GetPosition() + up * 50; var world = MatrixD.CreateWorld(pos, Vector3.Forward, Vector3.Up); var color = Color.Red.ColorToHSV(); var pirateFaction = MySession.Static.Factions.TryGetFactionByTag("SPRT"); MyCubeBuilder.SpawnDynamicGrid(definitionBase, player.Character, world, color, MyStringHash.NullOrEmpty, 0L, MyCubeBuilder.SpawnFlags.Default | MyCubeBuilder.SpawnFlags.SpawnAsMaster, pirateFaction.FounderId, entity => { var grid = (MyCubeGrid)entity; var pirateAntennas = MySession.Static.GetComponent <MyPirateAntennas>(); if (pirateAntennas != null) { var drones = Utils.IsInSpace(pos) ? Configuration.Plugin.Get(c => c.SpaceDrones): Configuration.Plugin.Get(c => c.PlanetDrones); var drone = (string.IsNullOrEmpty(Drone) ? drones[_random.Next(drones.Length)]: Drone) ?? "Vulture Drone"; MyDefinitionManager.Static.TryGetDefinition( new MyDefinitionId( (MyObjectBuilderType)typeof(MyObjectBuilder_SpawnGroupDefinition), drone), out MySpawnGroupDefinition spawnGroup); if (spawnGroup != null) { Vector3D?nullable = new Vector3D?(); for (int index = 0; index < 10; ++index) { world = entity.WorldMatrix; nullable = MyEntities.FindFreePlace( world.Translation + MyUtils.GetRandomVector3Normalized() * 1500, spawnGroup.SpawnRadius); if (nullable.HasValue) { break; } } foreach (var antenna in grid.GetFatBlocks <MyRadioAntenna>()) { _spawnDrone.Invoke(pirateAntennas, new object[] { antenna, pirateFaction.FounderId, nullable.Value, spawnGroup, new Vector3?(), new Vector3?() }); } var spawns = spawnGroup.Prefabs.Select(prefab => prefab.SubtypeId.ToSplitCase()) .GroupBy(s => s).Select(grouping => (grouping.Count() > 1 ? grouping.Count() + "x " : "") + grouping.Key) .Join(); var msg = "Spawned " + spawns; Utils.SendChat(msg); ActionNotification.SendActionMessage(msg, Color.Red, "ArcHudGPSNotification1"); } } grid.CubeBlocks.ToList().ForEach(block => grid.RemoveBlock(block)); }); } }); }
protected bool TestGridPlacementOnGrid(MyCubeGrid previewGrid, ref MyGridPlacementSettings settings, MyCubeGrid hitGrid) { Debug.Assert(previewGrid.GridSizeEnum == hitGrid.GridSizeEnum); bool retval = true; Vector3I gridOffset = hitGrid.WorldToGridInteger(previewGrid.PositionComp.WorldMatrix.Translation); MatrixI transform = hitGrid.CalculateMergeTransform(previewGrid, gridOffset); Matrix localPreviewMatrix = transform.GetFloatMatrix(); localPreviewMatrix.Translation *= previewGrid.GridSize; if (MyDebugDrawSettings.DEBUG_DRAW_COPY_PASTE) { MyRenderProxy.DebugDrawText2D(new Vector2(0.0f, 60.0f), "First grid offset: " + gridOffset.ToString(), Color.Red, 1.0f); } retval = retval && MyCubeBuilder.CheckValidBlocksRotation(localPreviewMatrix, previewGrid); retval = retval && hitGrid.GridSizeEnum == previewGrid.GridSizeEnum && hitGrid.CanMergeCubes(previewGrid, gridOffset); retval = retval && MyCubeGrid.CheckMergeConnectivity(hitGrid, previewGrid, gridOffset); // Check if any block connects to hit grid if (retval) { bool connected = false; foreach (var block in previewGrid.CubeBlocks) { if (block.FatBlock is MyCompoundCubeBlock) { MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock; foreach (var blockInCompound in compoundBlock.GetBlocks()) { connected |= CheckConnectivityOnGrid(blockInCompound, ref transform, ref settings, hitGrid); if (connected) { break; } } } else { connected |= CheckConnectivityOnGrid(block, ref transform, ref settings, hitGrid); } if (connected) { break; } } retval &= connected; } if (retval) { foreach (var block in previewGrid.CubeBlocks) { if (block.FatBlock is MyCompoundCubeBlock) { MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock; foreach (var blockInCompound in compoundBlock.GetBlocks()) { retval = retval && TestBlockPlacementOnGrid(blockInCompound, ref transform, ref settings, hitGrid); if (!retval) { break; } } } else { retval = retval && TestBlockPlacementOnGrid(block, ref transform, ref settings, hitGrid); } if (!retval) { break; } } } return(retval); }
/// <summary> /// Casts preview grids aabbs and get shortest distance. Returns shortest intersection or null. /// </summary> protected Vector3D?GetFreeSpacePlacementPositionGridAabbs(bool copyPaste, out bool buildAllowed) { Vector3D?freePlacementIntersectionPoint = null; buildAllowed = true; float gridSize = PreviewGrids[0].GridSize; double shortestDistance = double.MaxValue; double?currentRayInts = MyCubeBuilder.GetCurrentRayIntersection(); if (currentRayInts.HasValue) { shortestDistance = currentRayInts.Value; } Vector3D worldRefPointOffset = Vector3D.Zero; if (copyPaste) { Matrix firstGridOrientation = GetFirstGridOrientationMatrix(); worldRefPointOffset = Vector3.TransformNormal(m_dragPointToPositionLocal, firstGridOrientation); } Vector3D worldRefPoint = PreviewGrids[0].GridIntegerToWorld(Vector3I.Zero); foreach (var grid in PreviewGrids) { Vector3 halfExt = grid.PositionComp.LocalAABB.HalfExtents; Vector3 minLocal = grid.Min * grid.GridSize - Vector3.Half * grid.GridSize; Vector3 maxLocal = grid.Max * grid.GridSize + Vector3.Half * grid.GridSize; MatrixD gridWorlTransform = MatrixD.Identity; gridWorlTransform.Translation = 0.5f * (minLocal + maxLocal); gridWorlTransform = gridWorlTransform * grid.WorldMatrix; Vector3I size = grid.Max - grid.Min + Vector3I.One; Vector3 sizeOffset = Vector3I.Abs((size % 2) - Vector3I.One) * 0.5 * grid.GridSize; sizeOffset = Vector3.TransformNormal(sizeOffset, grid.WorldMatrix); Vector3D offset = gridWorlTransform.Translation + worldRefPointOffset - worldRefPoint /*- sizeOffset*/;// Vector3.Zero;// gridWorlTransform.Translation + worldRefPointOffset - worldRefPoint; HkShape shape = new HkBoxShape(halfExt); Vector3D rayStart = MyCubeBuilder.IntersectionStart + offset; double castPlaneDistanceToRayStart = DistanceFromCharacterPlane(ref rayStart); rayStart -= castPlaneDistanceToRayStart * MyCubeBuilder.IntersectionDirection; Vector3D rayEnd = MyCubeBuilder.IntersectionStart + (m_dragDistance - castPlaneDistanceToRayStart) * MyCubeBuilder.IntersectionDirection + offset; MatrixD matrix = gridWorlTransform; matrix.Translation = rayStart; try { float?dist = MyPhysics.CastShape(rayEnd, shape, ref matrix, MyPhysics.CollisionLayers.CollisionLayerWithoutCharacter); if (dist.HasValue && dist.Value != 0f) { Vector3D intersectionPoint = rayStart + dist.Value * (rayEnd - rayStart); const bool debugDraw = true; if (debugDraw) { Color green = Color.Green; BoundingBoxD localAABB = new BoundingBoxD(-halfExt, halfExt); localAABB.Inflate(0.03f); MatrixD drawMatrix = matrix; drawMatrix.Translation = intersectionPoint; MySimpleObjectDraw.DrawTransparentBox(ref drawMatrix, ref localAABB, ref green, MySimpleObjectRasterizer.Wireframe, 1, 0.04f); } double fixedDistance = DistanceFromCharacterPlane(ref intersectionPoint) - castPlaneDistanceToRayStart; if (fixedDistance <= 0) { fixedDistance = 0; shortestDistance = 0; buildAllowed = false; break; } if (fixedDistance < shortestDistance) { shortestDistance = fixedDistance; } } else { buildAllowed = false; } } finally { shape.RemoveReference(); } } if (shortestDistance != 0 && shortestDistance < m_dragDistance) { freePlacementIntersectionPoint = MyCubeBuilder.IntersectionStart + shortestDistance * MyCubeBuilder.IntersectionDirection; } else { buildAllowed = false; } return(freePlacementIntersectionPoint); }
protected Vector3D?GetFreeSpacePlacementPosition(bool copyPaste, out bool buildAllowed) { Vector3D?freePlacementIntersectionPoint = null; buildAllowed = false; double shortestDistance = double.MaxValue; double?currentRayInts = MyCubeBuilder.GetCurrentRayIntersection(); if (currentRayInts.HasValue) { shortestDistance = currentRayInts.Value; } Vector3D worldRefPointOffset = Vector3D.Zero; if (copyPaste) { Matrix firstGridOrientation = GetFirstGridOrientationMatrix(); worldRefPointOffset = Vector3.TransformNormal(m_dragPointToPositionLocal, firstGridOrientation); } Vector3D worldRefPoint = PreviewGrids[0].GridIntegerToWorld(Vector3I.Zero); Matrix blockLocalTransform; foreach (var block in PreviewGrids[0].GetBlocks()) { Vector3 halfExt = block.BlockDefinition.Size * PreviewGrids[0].GridSize * 0.5f; Vector3 minLocal = block.Min * PreviewGrids[0].GridSize - Vector3.Half * PreviewGrids[0].GridSize; Vector3 maxLocal = block.Max * PreviewGrids[0].GridSize + Vector3.Half * PreviewGrids[0].GridSize; block.Orientation.GetMatrix(out blockLocalTransform); blockLocalTransform.Translation = 0.5f * (minLocal + maxLocal); MatrixD blockWorldTransform = blockLocalTransform * PreviewGrids[0].WorldMatrix; Vector3D offset = blockWorldTransform.Translation + worldRefPointOffset - worldRefPoint; HkShape shape = new HkBoxShape(halfExt); Vector3D rayStart = MyCubeBuilder.IntersectionStart + offset; double castPlaneDistanceToRayStart = DistanceFromCharacterPlane(ref rayStart); rayStart -= castPlaneDistanceToRayStart * MyCubeBuilder.IntersectionDirection; Vector3D rayEnd = MyCubeBuilder.IntersectionStart + (m_dragDistance - castPlaneDistanceToRayStart) * MyCubeBuilder.IntersectionDirection + offset; MatrixD matrix = blockWorldTransform; matrix.Translation = rayStart; try { float?dist = MyPhysics.CastShape(rayEnd, shape, ref matrix, MyPhysics.CollisionLayers.CollisionLayerWithoutCharacter); if (dist.HasValue && dist.Value != 0f) { Vector3D intersectionPoint = rayStart + dist.Value * (rayEnd - rayStart); const bool debugDraw = false; if (debugDraw) { Color green = Color.Green; BoundingBoxD localAABB = new BoundingBoxD(-halfExt, halfExt); MatrixD drawMatrix = matrix; drawMatrix.Translation = intersectionPoint; MySimpleObjectDraw.DrawTransparentBox(ref drawMatrix, ref localAABB, ref green, MySimpleObjectRasterizer.Wireframe, 1, 0.04f); } double fixedDistance = DistanceFromCharacterPlane(ref intersectionPoint) - castPlaneDistanceToRayStart; if (fixedDistance <= 0) { fixedDistance = 0; shortestDistance = 0; break; } if (fixedDistance < shortestDistance) { shortestDistance = fixedDistance; } buildAllowed = true; } } finally { shape.RemoveReference(); } } float boxRadius = (float)PreviewGrids[0].PositionComp.WorldAABB.HalfExtents.Length(); float dragDistance = 1.5f * boxRadius; if (shortestDistance < dragDistance) { shortestDistance = dragDistance; buildAllowed = false; } if (shortestDistance < m_dragDistance) { freePlacementIntersectionPoint = MyCubeBuilder.IntersectionStart + shortestDistance * MyCubeBuilder.IntersectionDirection; } return(freePlacementIntersectionPoint); }
private new void FixSnapTransformationBase6() { Debug.Assert(CopiedGrids.Count > 0); if (CopiedGrids.Count == 0) { return; } var hitGrid = m_hitEntity as MyCubeGrid; if (hitGrid == null) { return; } // Fix rotation of the first pasted grid Matrix rotationDelta = GetRotationDeltaMatrixToHitGrid(hitGrid); foreach (var grid in PreviewGrids) { Matrix rotation = grid.WorldMatrix.GetOrientation(); rotation = rotation * rotationDelta; Vector3D position = m_pastePosition; MatrixD newWorld = MatrixD.CreateWorld(position, rotation.Forward, rotation.Up); Debug.Assert(newWorld.GetOrientation().IsRotation()); grid.PositionComp.SetWorldMatrix(newWorld); } bool smallOnLargeGrid = hitGrid.GridSizeEnum == MyCubeSize.Large && PreviewGrids[0].GridSizeEnum == MyCubeSize.Small; if (smallOnLargeGrid) { Vector3 pasteOffset = MyCubeBuilder.TransformLargeGridHitCoordToSmallGrid(m_hitPos, hitGrid.PositionComp.WorldMatrixNormalizedInv, hitGrid.GridSize); m_pastePosition = hitGrid.GridIntegerToWorld(pasteOffset); } else { // Find a collision-free position for the first paste grid along the raycast normal Vector3I collisionTestStep = Vector3I.Round(m_hitNormal); Vector3I pasteOffset = hitGrid.WorldToGridInteger(m_pastePosition); Vector3I previewGridMin = PreviewGrids[0].Min; Vector3I previewGridMax = PreviewGrids[0].Max; Vector3I previewGridSize = previewGridMax - previewGridMin + Vector3I.One; Vector3D previewGridSizeInWorld = Vector3D.TransformNormal((Vector3D)previewGridSize, PreviewGrids[0].WorldMatrix); Vector3I previewGridSizeInHitGrid = Vector3I.Abs(Vector3I.Round(Vector3D.TransformNormal(previewGridSizeInWorld, hitGrid.PositionComp.WorldMatrixNormalizedInv))); int attemptsCount = Math.Abs(Vector3I.Dot(ref collisionTestStep, ref previewGridSizeInHitGrid)); Debug.Assert(attemptsCount > 0); int i; for (i = 0; i < attemptsCount; ++i) { if (hitGrid.CanMergeCubes(PreviewGrids[0], pasteOffset)) { break; } pasteOffset += collisionTestStep; } if (i == attemptsCount) { pasteOffset = hitGrid.WorldToGridInteger(m_pastePosition); } m_pastePosition = hitGrid.GridIntegerToWorld(pasteOffset); } // Move all the grids according to the collision-free position of the first one for (int i = 0; i < PreviewGrids.Count; ++i) { var grid = PreviewGrids[i]; MatrixD matrix = grid.WorldMatrix; matrix.Translation = m_pastePosition + Vector3.Transform(m_copiedGridOffsets[i], rotationDelta); grid.PositionComp.SetWorldMatrix(matrix); } if (MyDebugDrawSettings.DEBUG_DRAW_COPY_PASTE) { MyRenderProxy.DebugDrawLine3D(m_hitPos, m_hitPos + m_hitNormal, Color.Red, Color.Green, false); } }
private new bool TestPlacement() { bool retval = true; m_touchingGrids.Clear(); for (int i = 0; i < PreviewGrids.Count; ++i) { var grid = PreviewGrids[i]; var settings = m_settings.GetGridPlacementSettings(grid.GridSizeEnum); m_touchingGrids.Add(null); if (MySession.Static.SurvivalMode && !MyCubeBuilder.SpectatorIsBuilding && !MySession.Static.IsAdminModeEnabled(Sync.MyId)) { if (i == 0 && MyCubeBuilder.CameraControllerSpectator) { m_visible = false; return(false); } if (i == 0 && !MyCubeBuilder.Static.DynamicMode) { MatrixD invMatrix = grid.PositionComp.WorldMatrixNormalizedInv; if (!MyCubeBuilderGizmo.DefaultGizmoCloseEnough(ref invMatrix, (BoundingBoxD)grid.PositionComp.LocalAABB, grid.GridSize, MyCubeBuilder.IntersectionDistance)) { m_visible = false; return(false); } } /*if (!MySession.Static.SimpleSurvival && MySession.Static.ControlledEntity is MyCharacter) * { * foreach (var block in grid.GetBlocks()) * { * retval &= (MySession.Static.ControlledEntity as MyCharacter).CanStartConstruction(block.BlockDefinition); * if (!retval) * break; * } * } * * if (i == 0 && MySession.Static.SimpleSurvival) * { * retval = retval && MyCubeBuilder.Static.CanBuildBlockSurvivalTime(); * }*/ if (!retval) { return(false); } } if (MyCubeBuilder.Static.DynamicMode) { // if (!m_dynamicBuildAllowed) // { var settingsLocal = grid.GridSizeEnum == MyCubeSize.Large ? m_settings.LargeGrid : m_settings.SmallGrid; bool anyBlockVoxelHit = false; foreach (var block in grid.GetBlocks()) { Vector3 minLocal = block.Min * PreviewGrids[i].GridSize - Vector3.Half * PreviewGrids[i].GridSize; Vector3 maxLocal = block.Max * PreviewGrids[i].GridSize + Vector3.Half * PreviewGrids[i].GridSize; BoundingBoxD aabbLocal = new BoundingBoxD(minLocal, maxLocal); if (!anyBlockVoxelHit) { anyBlockVoxelHit = TestVoxelPlacement(block, ref settings, true); } retval = retval && MyCubeGrid.TestPlacementArea(grid, grid.IsStatic, ref settingsLocal, aabbLocal, true, testVoxel: false); if (!retval) { break; } } retval = retval && anyBlockVoxelHit; // } } else if (i == 0 && m_hitEntity is MyCubeGrid && IsSnapped /* && SnapMode == SnapMode.Base6Directions*/) { var hitGrid = m_hitEntity as MyCubeGrid; var settingsLocal = m_settings.GetGridPlacementSettings(hitGrid.GridSizeEnum, hitGrid.IsStatic); bool smallOnLargeGrid = hitGrid.GridSizeEnum == MyCubeSize.Large && grid.GridSizeEnum == MyCubeSize.Small; if (smallOnLargeGrid) { retval = retval && MyCubeGrid.TestPlacementArea(grid, ref settings, (BoundingBoxD)grid.PositionComp.LocalAABB, false); } else { retval = retval && TestGridPlacementOnGrid(grid, ref settingsLocal, hitGrid); } m_touchingGrids.Clear(); m_touchingGrids.Add(hitGrid); } else if (i == 0 && m_hitEntity is MyVoxelMap) { bool anyBlockVoxelHit = false; foreach (var block in grid.CubeBlocks) { if (block.FatBlock is MyCompoundCubeBlock) { MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock; foreach (var blockInCompound in compoundBlock.GetBlocks()) { if (!anyBlockVoxelHit) { anyBlockVoxelHit = TestVoxelPlacement(blockInCompound, ref settings, false); } retval = retval && TestBlockPlacementArea(blockInCompound, ref settings, false, false); if (!retval) { break; } } } else { if (!anyBlockVoxelHit) { anyBlockVoxelHit = TestVoxelPlacement(block, ref settings, false); } retval = retval && TestBlockPlacementArea(block, ref settings, false, false); } if (!retval) { break; } } retval = retval && anyBlockVoxelHit; Debug.Assert(i == 0); m_touchingGrids[i] = DetectTouchingGrid(); } else { var settingsLocal = m_settings.GetGridPlacementSettings(grid.GridSizeEnum, grid.IsStatic && !MyCubeBuilder.Static.DynamicMode); retval = retval && MyCubeGrid.TestPlacementArea(grid, grid.IsStatic, ref settingsLocal, (BoundingBoxD)grid.PositionComp.LocalAABB, false); } BoundingBoxD aabb = (BoundingBoxD)grid.PositionComp.LocalAABB; MatrixD invGridWorlMatrix = grid.PositionComp.WorldMatrixNormalizedInv; // Character collisions. if (MySector.MainCamera != null) { Vector3D cameraPos = Vector3D.Transform(MySector.MainCamera.Position, invGridWorlMatrix); retval = retval && aabb.Contains(cameraPos) != ContainmentType.Contains; } if (retval) { m_tmpCollisionPoints.Clear(); MyCubeBuilder.PrepareCharacterCollisionPoints(m_tmpCollisionPoints); foreach (var pt in m_tmpCollisionPoints) { Vector3D ptLocal = Vector3D.Transform(pt, invGridWorlMatrix); retval = retval && aabb.Contains(ptLocal) != ContainmentType.Contains; if (!retval) { break; } } } } return(retval); }
private bool TestPlacement() { MyCubeGrid grid; MyGridPlacementSettings gridPlacementSettings; BoundingBoxD xd; bool flag3; MyGridPlacementSettings settings4; bool flag1; bool flag = true; base.m_touchingGrids.Clear(); int num = 0; goto TR_0047; TR_000F: xd = grid.PositionComp.LocalAABB; MatrixD worldMatrixNormalizedInv = grid.PositionComp.WorldMatrixNormalizedInv; if (MySector.MainCamera != null) { Vector3D point = Vector3D.Transform(MySector.MainCamera.Position, worldMatrixNormalizedInv); flag = flag && (xd.Contains(point) != ContainmentType.Contains); } if (flag) { m_tmpCollisionPoints.Clear(); MyCubeBuilder.PrepareCharacterCollisionPoints(m_tmpCollisionPoints); using (List <Vector3D> .Enumerator enumerator3 = m_tmpCollisionPoints.GetEnumerator()) { while (enumerator3.MoveNext()) { Vector3D point = Vector3D.Transform(enumerator3.Current, worldMatrixNormalizedInv); flag = flag && (xd.Contains(point) != ContainmentType.Contains); if (!flag) { break; } } } } num++; goto TR_0047; TR_001D: flag &= flag3; base.m_touchingGrids[num] = this.DetectTouchingGrid(); goto TR_000F; TR_0033: settings4 = base.m_settings.GetGridPlacementSettings(grid.GridSizeEnum, grid.IsStatic && !MyCubeBuilder.Static.DynamicMode); flag = flag && MyCubeGrid.TestPlacementArea(grid, grid.IsStatic, ref settings4, grid.PositionComp.LocalAABB, false, null, true, true); goto TR_000F; TR_0047: while (true) { if (num >= base.PreviewGrids.Count) { return(flag); } grid = base.PreviewGrids[num]; if (!Sandbox.Game.Entities.MyEntities.IsInsideWorld(grid.PositionComp.GetPosition())) { return(false); } gridPlacementSettings = base.m_settings.GetGridPlacementSettings(grid.GridSizeEnum); base.m_touchingGrids.Add(null); if ((MySession.Static.SurvivalMode && !MyBlockBuilderBase.SpectatorIsBuilding) && !MySession.Static.CreativeToolsEnabled(Sync.MyId)) { if ((num == 0) && MyBlockBuilderBase.CameraControllerSpectator) { base.m_visible = false; return(false); } if (((num == 0) && !MyCubeBuilder.Static.DynamicMode) && !MyCubeBuilderGizmo.DefaultGizmoCloseEnough(ref grid.PositionComp.WorldMatrixNormalizedInv, grid.PositionComp.LocalAABB, grid.GridSize, MyBlockBuilderBase.IntersectionDistance)) { base.m_visible = false; return(false); } if (!flag) { return(false); } } if (!MyCubeBuilder.Static.DynamicMode) { if (num != 0) { break; } if (!(base.m_hitEntity is MyCubeGrid)) { break; } if (!base.IsSnapped) { break; } MyCubeGrid hitEntity = base.m_hitEntity as MyCubeGrid; MyGridPlacementSettings gridPlacementSettings = base.m_settings.GetGridPlacementSettings(hitEntity.GridSizeEnum, hitEntity.IsStatic); flag = ((hitEntity.GridSizeEnum != MyCubeSize.Large) || (grid.GridSizeEnum != MyCubeSize.Small)) ? (flag && base.TestGridPlacementOnGrid(grid, ref gridPlacementSettings, hitEntity)) : (flag && flag1); base.m_touchingGrids.Clear(); base.m_touchingGrids.Add(hitEntity); } else { MyGridPlacementSettings settings2 = (grid.GridSizeEnum == MyCubeSize.Large) ? base.m_settings.LargeGrid : base.m_settings.SmallGrid; bool flag2 = false; foreach (MySlimBlock block in grid.GetBlocks()) { Vector3 min = ((Vector3)(block.Min * base.PreviewGrids[num].GridSize)) - (Vector3.Half * base.PreviewGrids[num].GridSize); Vector3 max = (block.Max * base.PreviewGrids[num].GridSize) + (Vector3.Half * base.PreviewGrids[num].GridSize); BoundingBoxD localAabb = new BoundingBoxD(min, max); if (!flag2) { flag2 = TestVoxelPlacement(block, ref gridPlacementSettings, true); } flag = flag && MyCubeGrid.TestPlacementArea(grid, grid.IsStatic, ref settings2, localAabb, true, null, false, true); if (!flag) { break; } } flag &= flag2; } goto TR_000F; } if (num != 0) { goto TR_0033; } else if (!(base.m_hitEntity is MyVoxelMap)) { goto TR_0033; } else { flag3 = false; using (HashSet <MySlimBlock> .Enumerator enumerator = grid.CubeBlocks.GetEnumerator()) { do { while (true) { if (enumerator.MoveNext()) { MySlimBlock block3; bool flag4; MySlimBlock current = enumerator.Current; if (current.FatBlock is MyCompoundCubeBlock) { using (List <MySlimBlock> .Enumerator enumerator2 = (current.FatBlock as MyCompoundCubeBlock).GetBlocks().GetEnumerator()) { while (enumerator2.MoveNext()) { if (!flag3) { flag1 = MyCubeGrid.TestPlacementArea(grid, ref gridPlacementSettings, grid.PositionComp.LocalAABB, false, null); flag3 = TestVoxelPlacement(block3, ref gridPlacementSettings, false); } flag = flag && flag4; if (!flag) { break; } } break; } } if (!flag3) { flag4 = TestBlockPlacementArea(block3, ref gridPlacementSettings, false, false); flag3 = TestVoxelPlacement(current, ref gridPlacementSettings, false); } flag = flag && TestBlockPlacementArea(current, ref gridPlacementSettings, false, false); } else { goto TR_001D; } break; } }while (flag); } } goto TR_001D; }
private bool TestPlacement() { bool retval = true; for (int i = 0; i < PreviewGrids.Count; ++i) { var grid = PreviewGrids[i]; var settings = m_settings.GetGridPlacementSettings(grid); if (MySession.Static.SurvivalMode && !MyCubeBuilder.DeveloperSpectatorIsBuilding) { if (i == 0 && MyCubeBuilder.CameraControllerSpectator) { m_visible = false; return(false); } if (i == 0 && !MyCubeBuilder.Static.DynamicMode) { MatrixD invMatrix = grid.PositionComp.WorldMatrixNormalizedInv; if (!MyCubeBuilderGizmo.DefaultGizmoCloseEnough(ref invMatrix, (BoundingBoxD)grid.PositionComp.LocalAABB, grid.GridSize, MyCubeBuilder.Static.IntersectionDistance)) { m_visible = false; return(false); } } if (!MySession.Static.SimpleSurvival && MySession.ControlledEntity is MyCharacter) { foreach (var block in grid.GetBlocks()) { retval &= (MySession.ControlledEntity as MyCharacter).CanStartConstruction(block.BlockDefinition); if (!retval) { break; } } } if (i == 0 && MySession.Static.SimpleSurvival) { retval = retval && MyCubeBuilder.Static.CanBuildBlockSurvivalTime(); } if (!retval) { return(false); } } if (MyCubeBuilder.Static.DynamicMode) { if (!m_dynamicBuildAllowed) { var settingsLocal = grid.GridSizeEnum == MyCubeSize.Large ? MyPerGameSettings.PastingSettings.LargeGrid : MyPerGameSettings.PastingSettings.SmallGrid; foreach (var block in grid.GetBlocks()) { Vector3 minLocal = block.Min * PreviewGrids[i].GridSize - Vector3.Half * PreviewGrids[i].GridSize; Vector3 maxLocal = block.Max * PreviewGrids[i].GridSize + Vector3.Half * PreviewGrids[i].GridSize; BoundingBoxD aabbLocal = new BoundingBoxD(minLocal, maxLocal); retval = retval && MyCubeGrid.TestPlacementArea(grid, grid.IsStatic, ref settingsLocal, aabbLocal, true); } } } else if (i == 0 && m_hitEntity is MyCubeGrid && IsSnapped && SnapMode == MyGridPlacementSettings.SnapMode.Base6Directions) { var hitGrid = m_hitEntity as MyCubeGrid; bool smallOnLargeGrid = hitGrid.GridSizeEnum == MyCubeSize.Large && grid.GridSizeEnum == MyCubeSize.Small; if (smallOnLargeGrid) { retval = retval && MyCubeGrid.TestPlacementArea(grid, ref settings, (BoundingBoxD)grid.PositionComp.LocalAABB, false /*, hitGrid*/); } else { retval = retval && TestGridPlacementOnGrid(grid, ref settings, hitGrid); } } else if (i == 0 && m_hitEntity is MyVoxelMap) { foreach (var block in grid.CubeBlocks) { if (block.FatBlock is MyCompoundCubeBlock) { MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock; foreach (var blockInCompound in compoundBlock.GetBlocks()) { retval = retval && TestBlockPlacementArea(blockInCompound, ref settings, false); if (!retval) { break; } } } else { retval = retval && TestBlockPlacementArea(block, ref settings, false); } if (!retval) { break; } } } else { var settingsLocal = m_settings.GetGridPlacementSettings(grid, grid.IsStatic && !MyCubeBuilder.Static.DynamicMode); retval = retval && MyCubeGrid.TestPlacementArea(grid, grid.IsStatic, ref settingsLocal, (BoundingBoxD)grid.PositionComp.LocalAABB, false); } BoundingBoxD aabb = (BoundingBoxD)grid.PositionComp.LocalAABB; MatrixD invGridWorlMatrix = grid.PositionComp.GetWorldMatrixNormalizedInv(); // Character collisions. if (MySector.MainCamera != null) { Vector3D cameraPos = Vector3D.Transform(MySector.MainCamera.Position, invGridWorlMatrix); retval = retval && aabb.Contains(cameraPos) != ContainmentType.Contains; } if (retval) { m_tmpCollisionPoints.Clear(); MyCubeBuilder.PrepareCharacterCollisionPoints(m_tmpCollisionPoints); foreach (var pt in m_tmpCollisionPoints) { Vector3D ptLocal = Vector3D.Transform(pt, invGridWorlMatrix); retval = retval && aabb.Contains(ptLocal) != ContainmentType.Contains; if (!retval) { break; } } } } return(retval); }