protected static bool CheckConnectivityOnGrid(MySlimBlock block, ref MatrixI transform, ref MyGridPlacementSettings settings, MyCubeGrid hitGrid) { Vector3I position; Vector3I.Transform(ref block.Position, ref transform, out position); Vector3I forward = Base6Directions.GetIntVector(transform.GetDirection(block.Orientation.Forward)); Vector3I up = Base6Directions.GetIntVector(transform.GetDirection(block.Orientation.Up)); MyBlockOrientation blockOrientation = new MyBlockOrientation(Base6Directions.GetDirection(forward), Base6Directions.GetDirection(up)); Quaternion rotation; blockOrientation.GetQuaternion(out rotation); return(MyCubeGrid.CheckConnectivity(hitGrid, block.BlockDefinition, ref rotation, ref position)); }
protected static bool CheckConnectivityOnGrid(MySlimBlock block, ref MatrixI transform, ref MyGridPlacementSettings settings, MyCubeGrid hitGrid) { Vector3I position; Vector3I.Transform(ref block.Position, ref transform, out position); var forward = transform.GetDirection(block.Orientation.Forward); var up = transform.GetDirection(block.Orientation.Up); MyBlockOrientation blockOrientation = new MyBlockOrientation(forward, up); Quaternion rotation; blockOrientation.GetQuaternion(out rotation); var blockDefinition = block.BlockDefinition; return(MyCubeGrid.CheckConnectivity(hitGrid, blockDefinition, blockDefinition.GetBuildProgressModelMountPoints(block.BuildLevelRatio), ref rotation, ref position)); }
private bool CanBuildBlock(MyObjectBuilder_CubeBlock block, MyCubeGrid blockGrid, MyCubeBlock projector, MyCubeGrid projectorGrid, MyObjectBuilder_ProjectorBase projectorBuilder) { MyBlockOrientation blockOrientation = block.BlockOrientation; Matrix local; blockOrientation.GetMatrix(out local); var gridOrientation = GetGridOrientation(projectorBuilder); if (gridOrientation != Matrix.Identity) { var afterRotation = Matrix.Multiply(local, gridOrientation); blockOrientation = new MyBlockOrientation(ref afterRotation); } Quaternion blockOrientationQuat; blockOrientation.GetQuaternion(out blockOrientationQuat); Quaternion projQuat = Quaternion.Identity; projector.Orientation.GetQuaternion(out projQuat); blockOrientationQuat = Quaternion.Multiply(projQuat, blockOrientationQuat); MyCubeBlockDefinition blockDefinition; MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDefinition); // Get real block max Vector3I blockMax = Vector3I.Zero; Vector3I blockMin = block.Min; ComputeMax(blockDefinition, block.BlockOrientation, ref blockMin, out blockMax); var position = ComputePositionInGrid(new MatrixI(block.BlockOrientation), blockDefinition, blockMin); Vector3I projectedMin = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(block.Min)); Vector3I projectedMax = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(blockMax)); Vector3I blockPos = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(position)); Vector3I min = new Vector3I(Math.Min(projectedMin.X, projectedMax.X), Math.Min(projectedMin.Y, projectedMax.Y), Math.Min(projectedMin.Z, projectedMax.Z)); Vector3I max = new Vector3I(Math.Max(projectedMin.X, projectedMax.X), Math.Max(projectedMin.Y, projectedMax.Y), Math.Max(projectedMin.Z, projectedMax.Z)); projectedMin = min; projectedMax = max; if (!projectorGrid.CanAddCubes(projectedMin, projectedMax)) { IMySlimBlock slimBlock = (IMySlimBlock)blockGrid.GetCubeBlock(block.Min); if (slimBlock == null || slimBlock.FatBlock == null) { return(false); } Logging.Instance.WriteLine(string.Format("Can not add block: {0}: {1} - {2} {3} {4} {5}", slimBlock.FatBlock.EntityId, blockDefinition.Id, projectedMin, projectedMax, blockMin, blockMax)); //, slimBlock.FatBlock.EntityId)); return(false); } var mountPoints = blockDefinition.GetBuildProgressModelMountPoints(1.0f); bool isConnected = MyCubeGrid.CheckConnectivity(projectorGrid, blockDefinition, mountPoints, ref blockOrientationQuat, ref blockPos); if (isConnected) { if (projectorGrid.GetCubeBlock(blockPos) == null) { return(true); } else { return(false); } } else { return(false); } }
private MyCubeGrid DetectTouchingGrid(MySlimBlock block) { MyCubeGrid grid2; if (MyCubeBuilder.Static.DynamicMode) { return(null); } if (block == null) { return(null); } if (block.FatBlock is MyCompoundCubeBlock) { using (List <MySlimBlock> .Enumerator enumerator = (block.FatBlock as MyCompoundCubeBlock).GetBlocks().GetEnumerator()) { while (true) { if (enumerator.MoveNext()) { MySlimBlock current = enumerator.Current; MyCubeGrid grid = this.DetectTouchingGrid(current); if (grid == null) { continue; } grid2 = grid; } else { return(null); } break; } return(grid2); } } else { BoundingBoxD xd; block.GetWorldBoundingBox(out xd, false); xd.Inflate((double)(block.CubeGrid.GridSize / 2f)); m_tmpNearEntities.Clear(); Sandbox.Game.Entities.MyEntities.GetElementsInBox(ref xd, m_tmpNearEntities); MyCubeBlockDefinition.MountPoint[] buildProgressModelMountPoints = block.BlockDefinition.GetBuildProgressModelMountPoints(block.BuildLevelRatio); try { int num2 = 0; while (true) { if (num2 >= m_tmpNearEntities.Count) { break; } MyCubeGrid objA = m_tmpNearEntities[num2] as MyCubeGrid; if (((objA != null) && (!ReferenceEquals(objA, block.CubeGrid) && ((objA.Physics != null) && (objA.Physics.Enabled && objA.IsStatic)))) && (objA.GridSizeEnum == block.CubeGrid.GridSizeEnum)) { Vector3I gridOffset = objA.WorldToGridInteger(base.m_pastePosition); if (objA.CanMergeCubes(block.CubeGrid, gridOffset)) { Quaternion quaternion; MatrixI transformation = objA.CalculateMergeTransform(block.CubeGrid, gridOffset); new MyBlockOrientation(transformation.GetDirection(block.Orientation.Forward), transformation.GetDirection(block.Orientation.Up)).GetQuaternion(out quaternion); Vector3I position = Vector3I.Transform(block.Position, transformation); if (MyCubeGrid.CheckConnectivity(objA, block.BlockDefinition, buildProgressModelMountPoints, ref quaternion, ref position)) { return(objA); } } } num2++; } } finally { m_tmpNearEntities.Clear(); } return(null); } return(grid2); }
private MyCubeGrid DetectTouchingGrid(MySlimBlock block) { if (MyCubeBuilder.Static.DynamicMode) { return(null); } if (block == null) { return(null); } if (block.FatBlock is MyCompoundCubeBlock) { foreach (var blockInCompound in (block.FatBlock as MyCompoundCubeBlock).GetBlocks()) { MyCubeGrid touchingGrid = DetectTouchingGrid(blockInCompound); if (touchingGrid != null) { return(touchingGrid); } } return(null); } ProfilerShort.Begin("MultiBlockClipboard: DetectMerge"); float gridSize = block.CubeGrid.GridSize; BoundingBoxD aabb; block.GetWorldBoundingBox(out aabb); // Inflate by half cube, so it will intersect for sure when there's anything aabb.Inflate(gridSize / 2); m_tmpNearEntities.Clear(); MyEntities.GetElementsInBox(ref aabb, m_tmpNearEntities); var mountPoints = block.BlockDefinition.GetBuildProgressModelMountPoints(block.BuildLevelRatio); try { for (int i = 0; i < m_tmpNearEntities.Count; i++) { var grid = m_tmpNearEntities[i] as MyCubeGrid; if (grid != null && grid != block.CubeGrid && grid.Physics != null && grid.Physics.Enabled && grid.IsStatic && grid.GridSizeEnum == block.CubeGrid.GridSizeEnum) { Vector3I gridOffset = grid.WorldToGridInteger(m_pastePosition); if (!grid.CanMergeCubes(block.CubeGrid, gridOffset)) { continue; } MatrixI transform = grid.CalculateMergeTransform(block.CubeGrid, gridOffset); Base6Directions.Direction forward = transform.GetDirection(block.Orientation.Forward); Base6Directions.Direction up = transform.GetDirection(block.Orientation.Up); MyBlockOrientation newOrientation = new MyBlockOrientation(forward, up); Quaternion newRotation; newOrientation.GetQuaternion(out newRotation); Vector3I newPosition = Vector3I.Transform(block.Position, transform); if (!MyCubeGrid.CheckConnectivity(grid, block.BlockDefinition, mountPoints, ref newRotation, ref newPosition)) { continue; } return(grid); } } } finally { m_tmpNearEntities.Clear(); ProfilerShort.End(); } return(null); }
public BuildCheckResult CanBuild(MySlimBlock projectedBlock, bool checkHavokIntersections) { MyBlockOrientation blockOrientation = projectedBlock.Orientation; Matrix local; blockOrientation.GetMatrix(out local); var gridOrientation = (m_clipboard as MyGridClipboard).GetFirstGridOrientationMatrix(); if (gridOrientation != Matrix.Identity) { var afterRotation = Matrix.Multiply(local, gridOrientation); blockOrientation = new MyBlockOrientation(ref afterRotation); } Quaternion blockOrientationQuat; blockOrientation.GetQuaternion(out blockOrientationQuat); Quaternion projQuat = Quaternion.Identity; Orientation.GetQuaternion(out projQuat); blockOrientationQuat = Quaternion.Multiply(projQuat, blockOrientationQuat); Vector3I projectedMin = CubeGrid.WorldToGridInteger(projectedBlock.CubeGrid.GridIntegerToWorld(projectedBlock.Min)); Vector3I projectedMax = CubeGrid.WorldToGridInteger(projectedBlock.CubeGrid.GridIntegerToWorld(projectedBlock.Max)); Vector3I blockPos = CubeGrid.WorldToGridInteger(projectedBlock.CubeGrid.GridIntegerToWorld(projectedBlock.Position)); Vector3I min = new Vector3I(Math.Min(projectedMin.X, projectedMax.X), Math.Min(projectedMin.Y, projectedMax.Y), Math.Min(projectedMin.Z, projectedMax.Z)); Vector3I max = new Vector3I(Math.Max(projectedMin.X, projectedMax.X), Math.Max(projectedMin.Y, projectedMax.Y), Math.Max(projectedMin.Z, projectedMax.Z)); projectedMin = min; projectedMax = max; if (!CubeGrid.CanAddCubes(projectedMin, projectedMax)) { return(BuildCheckResult.IntersectedWithGrid); } MyGridPlacementSettings settings = new MyGridPlacementSettings(); settings.Mode = MyGridPlacementSettings.SnapMode.OneFreeAxis; var mountPoints = projectedBlock.BlockDefinition.GetBuildProgressModelMountPoints(1.0f); bool isConnected = MyCubeGrid.CheckConnectivity(this.CubeGrid, projectedBlock.BlockDefinition, mountPoints, ref blockOrientationQuat, ref blockPos); if (isConnected) { if (CubeGrid.GetCubeBlock(blockPos) == null) { if (checkHavokIntersections) { if (MyCubeGrid.TestPlacementAreaCube(CubeGrid, ref settings, projectedMin, projectedMax, blockOrientation, projectedBlock.BlockDefinition, CubeGrid)) { return(BuildCheckResult.OK); } else { return(BuildCheckResult.IntersectedWithSomethingElse); } } else { return(BuildCheckResult.OK); } } else { return(BuildCheckResult.AlreadyBuilt); } } else { return(BuildCheckResult.NotConnected); } }
public BuildCheckResult CanBuild(MySlimBlock projectedBlock, bool checkHavokIntersections) { MyBlockOrientation blockOrientation = projectedBlock.Orientation; //GR: For rotation take into account: //the projected block orientation Quaternion blockOrientationQuat; blockOrientation.GetQuaternion(out blockOrientationQuat); //GR: The projector block orientation (which is relative to the Cubegrid orientation) Quaternion projQuat = Quaternion.Identity; Orientation.GetQuaternion(out projQuat); blockOrientationQuat = Quaternion.Multiply(projQuat, blockOrientationQuat); //GR: The orienation settings of the projector //Take into account order of multiplication to review! blockOrientationQuat = Quaternion.Multiply(ProjectionRotationQuaternion, blockOrientationQuat); Vector3I projectedMin = CubeGrid.WorldToGridInteger(projectedBlock.CubeGrid.GridIntegerToWorld(projectedBlock.Min)); Vector3I projectedMax = CubeGrid.WorldToGridInteger(projectedBlock.CubeGrid.GridIntegerToWorld(projectedBlock.Max)); Vector3I blockPos = CubeGrid.WorldToGridInteger(projectedBlock.CubeGrid.GridIntegerToWorld(projectedBlock.Position)); Vector3I min = new Vector3I(Math.Min(projectedMin.X, projectedMax.X), Math.Min(projectedMin.Y, projectedMax.Y), Math.Min(projectedMin.Z, projectedMax.Z)); Vector3I max = new Vector3I(Math.Max(projectedMin.X, projectedMax.X), Math.Max(projectedMin.Y, projectedMax.Y), Math.Max(projectedMin.Z, projectedMax.Z)); projectedMin = min; projectedMax = max; if (!CubeGrid.CanAddCubes(projectedMin, projectedMax)) { return(BuildCheckResult.IntersectedWithGrid); } MyGridPlacementSettings settings = new MyGridPlacementSettings(); settings.SnapMode = SnapMode.OneFreeAxis; var mountPoints = projectedBlock.BlockDefinition.GetBuildProgressModelMountPoints(1.0f); bool isConnected = MyCubeGrid.CheckConnectivity(this.CubeGrid, projectedBlock.BlockDefinition, mountPoints, ref blockOrientationQuat, ref blockPos); if (isConnected) { if (CubeGrid.GetCubeBlock(blockPos) == null) { if (checkHavokIntersections) { if (MyCubeGrid.TestPlacementAreaCube(CubeGrid, ref settings, projectedMin, projectedMax, blockOrientation, projectedBlock.BlockDefinition, CubeGrid)) { return(BuildCheckResult.OK); } else { return(BuildCheckResult.IntersectedWithSomethingElse); } } else { return(BuildCheckResult.OK); } } else { return(BuildCheckResult.AlreadyBuilt); } } else { return(BuildCheckResult.NotConnected); } }