protected List<Vector3D> GetAdditionalPoints(List<Vector3D> points, REShapeComposite composite) { List<Vector3D> additional = new List<Vector3D>(); foreach (REBaseShape child in composite) { RESphere sphere = child as RESphere; if (child is REShapeComposite) { sphere = ((REShapeComposite)child).BoundingShape as RESphere; } if (sphere == null) continue; for (int i = 0; i < points.Count; i++) { Vector3D c = points[i]; Vector3D dir = sphere.Position - c; additional.Add(sphere.Position + dir.Normalize() * sphere.Radius); } } return additional; }
protected virtual void OptimizeComposite(REShapeComposite composite) { var points = new List<Vector3D>(); foreach (REBaseShape child in composite) { if (child is RETriangle) { RETriangle triangle = (RETriangle)child; points.Add(triangle.A); points.Add(triangle.B); points.Add(triangle.C); continue; } if (child is RERectangle) { var rectangle = (RERectangle)child; points.Add(rectangle.A); points.Add(rectangle.B); points.Add(rectangle.C); points.Add(rectangle.B + rectangle.C - rectangle.A); continue; } } List<Vector3D> prev = points; for (int i = 0; i < 0; i++) { List<Vector3D> additional = GetAdditionalPoints(prev, composite); points.AddRange(additional); prev = additional; } Vector3D a = new Vector3D(), b = new Vector3D(); float maxLength = float.MinValue; for (int i = 0; i < points.Count; i++) { for (int j = 0; j < points.Count; j++) { float length = (points[i] - points[j]).Length; if (length > maxLength) { a = points[i]; b = points[j]; maxLength = length; } } } if ((a - b).Length > 0.01) { Sphere3D holder = new Sphere3D(); Vector3D center = (a + b) * 0.5f; holder.CoordinateSystem.Position = center; holder.Radius = (a - b).Length / 2; composite.BoundingShape = new RESphere(holder); } }
public void Visit(Shape3DComposite composite) { _context.PushCoordinateSystem(composite.CoordinateSystem); var decorated = new REShapeComposite(composite); foreach (Shape3D child in composite) { child.AcceptVisitor(this); decorated.Add(_decoratedShape); } OptimizeComposite(decorated); _context.PopCoordinateSystem(); _decoratedShape = decorated; }