static bool FindMountPoint(HkShapeCutterUtil cutter, HkShape shape, Vector3 direction, float gridSize, List <Sandbox.Definitions.MyCubeBlockDefinition.MountPoint> mountPoints) { //VRageRender.MyRenderProxy.DebugDrawLine3D(drawMatrix.Translation, Vector3D.Transform(direction, drawMatrix), Color.Green, Color.Green, false); //float offset = (gridSize * 0.9f) / 2.0f; float offset = (gridSize * 0.75f) / 2.0f; //because fracture pieces can be bit inside the cube Plane plane = new Plane(-direction, offset); float minimumSize = 0.2f; Vector3 min, max; if (cutter.Cut(shape, new Vector4(plane.Normal.X, plane.Normal.Y, plane.Normal.Z, plane.D), out min, out max)) { var aabb = new BoundingBox(min, max); aabb.InflateToMinimum(new Vector3(minimumSize)); float centerOffset = gridSize * 0.5f; // VRageRender.MyRenderProxy.DebugDrawOBB(boxC, Color.Red, 0.02f, true, false); MyCubeBlockDefinition.MountPoint mountPoint = new MyCubeBlockDefinition.MountPoint(); mountPoint.Normal = new Vector3I(direction); mountPoint.Start = (aabb.Min + new Vector3(centerOffset)) / gridSize; mountPoint.End = (aabb.Max + new Vector3(centerOffset)) / gridSize; mountPoint.Enabled = true; //because it didnt work if shape wasnt realy near the edge var zExt = Vector3.Abs(direction) * mountPoint.Start; bool add = zExt.AbsMax() > 0.5f; mountPoint.Start -= zExt; mountPoint.Start -= direction * 0.04f; mountPoint.End -= Vector3.Abs(direction) * mountPoint.End; mountPoint.End += direction * 0.04f; if (add) { mountPoint.Start += Vector3.Abs(direction); mountPoint.End += Vector3.Abs(direction); } mountPoints.Add(mountPoint); return(true); } return(false); }
static bool FindMountPoint(HkShapeCutterUtil cutter, HkShape shape, Vector3 direction, float gridSize, List<Sandbox.Definitions.MyCubeBlockDefinition.MountPoint> mountPoints) { //VRageRender.MyRenderProxy.DebugDrawLine3D(drawMatrix.Translation, Vector3D.Transform(direction, drawMatrix), Color.Green, Color.Green, false); //float offset = (gridSize * 0.9f) / 2.0f; float offset = (gridSize * 0.75f) / 2.0f; //because fracture pieces can be bit inside the cube Plane plane = new Plane(-direction, offset); float minimumSize = 0.2f; Vector3 min, max; if (cutter.Cut(shape, new Vector4(plane.Normal.X, plane.Normal.Y, plane.Normal.Z, plane.D), out min, out max)) { var aabb = new BoundingBox(min, max); aabb.InflateToMinimum(new Vector3(minimumSize)); float centerOffset = gridSize * 0.5f; // VRageRender.MyRenderProxy.DebugDrawOBB(boxC, Color.Red, 0.02f, true, false); MyCubeBlockDefinition.MountPoint mountPoint = new MyCubeBlockDefinition.MountPoint(); mountPoint.Normal = new Vector3I(direction); mountPoint.Start = (aabb.Min + new Vector3(centerOffset)) / gridSize; mountPoint.End = (aabb.Max + new Vector3(centerOffset)) / gridSize; mountPoint.Enabled = true; //because it didnt work if shape wasnt realy near the edge var zExt = Vector3.Abs(direction) * mountPoint.Start; bool add = zExt.AbsMax() > 0.5f; mountPoint.Start -= zExt; mountPoint.Start -= direction * 0.04f; mountPoint.End -= Vector3.Abs(direction) * mountPoint.End; mountPoint.End += direction * 0.04f; if (add) { mountPoint.Start += Vector3.Abs(direction); mountPoint.End += Vector3.Abs(direction); } mountPoints.Add(mountPoint); return true; } return false; }
public static List <MyCubeBlockDefinition.MountPoint> AutogenerateMountpoints(HkShape[] shapes, float gridSize) { ProfilerShort.Begin("AutogenerateMountpoints"); HkShapeCutterUtil cutter = new HkShapeCutterUtil(); List <BoundingBox>[] aabbsPerDirection = new List <BoundingBox> [Base6Directions.EnumDirections.Length]; var newMountPoints = new List <MyCubeBlockDefinition.MountPoint>(); foreach (var directionEnum in Base6Directions.EnumDirections) { int dirEnum = (int)directionEnum; //int dirEnum = 2; Vector3 direction = Base6Directions.Directions[dirEnum]; foreach (var shape in shapes) { if (shape.ShapeType == HkShapeType.List) { var listShape = (HkListShape)shape; var iterator = listShape.GetIterator(); while (iterator.IsValid) { HkShape childShape = iterator.CurrentValue; if (childShape.ShapeType == HkShapeType.ConvexTransform) { HkConvexTransformShape transformShape = (HkConvexTransformShape)childShape; FindMountPoint(cutter, transformShape.Base, direction, gridSize, newMountPoints); } else if (childShape.ShapeType == HkShapeType.ConvexTranslate) { HkConvexTranslateShape translateShape = (HkConvexTranslateShape)childShape; FindMountPoint(cutter, translateShape.Base, direction, gridSize, newMountPoints); } else { FindMountPoint(cutter, childShape, direction, gridSize, newMountPoints); } iterator.Next(); } break; } else if (shape.ShapeType == HkShapeType.Mopp) { var compoundShape = (HkMoppBvTreeShape)shape; for (int s = 0; s < compoundShape.ShapeCollection.ShapeCount; s++) { HkShape childShape = compoundShape.ShapeCollection.GetShape((uint)s, null); if (childShape.ShapeType == HkShapeType.ConvexTranslate) { HkConvexTranslateShape translateShape = (HkConvexTranslateShape)childShape; FindMountPoint(cutter, translateShape.Base, direction, gridSize, newMountPoints); } } break; } else { FindMountPoint(cutter, shape, direction, gridSize, newMountPoints); } } } ProfilerShort.End(); return(newMountPoints); }
public static List<MyCubeBlockDefinition.MountPoint> AutogenerateMountpoints(HkShape[] shapes, float gridSize) { ProfilerShort.Begin("AutogenerateMountpoints"); HkShapeCutterUtil cutter = new HkShapeCutterUtil(); List<BoundingBox>[] aabbsPerDirection = new List<BoundingBox>[Base6Directions.EnumDirections.Length]; var newMountPoints = new List<MyCubeBlockDefinition.MountPoint>(); foreach (var directionEnum in Base6Directions.EnumDirections) { int dirEnum = (int)directionEnum; //int dirEnum = 2; Vector3 direction = Base6Directions.Directions[dirEnum]; foreach (var shape in shapes) { if (shape.ShapeType == HkShapeType.List) { var listShape = (HkListShape)shape; var iterator = listShape.GetIterator(); while (iterator.IsValid) { HkShape childShape = iterator.CurrentValue; if (childShape.ShapeType == HkShapeType.ConvexTransform) { HkConvexTransformShape transformShape = (HkConvexTransformShape)childShape; FindMountPoint(cutter, transformShape.Base, direction, gridSize, newMountPoints); } else if (childShape.ShapeType == HkShapeType.ConvexTranslate) { HkConvexTranslateShape translateShape = (HkConvexTranslateShape)childShape; FindMountPoint(cutter, translateShape.Base, direction, gridSize, newMountPoints); } else { FindMountPoint(cutter, childShape, direction, gridSize, newMountPoints); } iterator.Next(); } break; } else if (shape.ShapeType == HkShapeType.Mopp) { var compoundShape = (HkMoppBvTreeShape)shape; for (int s = 0; s < compoundShape.ShapeCollection.ShapeCount; s++) { HkShape childShape = compoundShape.ShapeCollection.GetShape((uint)s, null); if (childShape.ShapeType == HkShapeType.ConvexTranslate) { HkConvexTranslateShape translateShape = (HkConvexTranslateShape)childShape; FindMountPoint(cutter, translateShape.Base, direction, gridSize, newMountPoints); } } break; } else { FindMountPoint(cutter, shape, direction, gridSize, newMountPoints); } } } ProfilerShort.End(); return newMountPoints; }