Class AbstractShape
- Direct Known Subclasses:
AbstractCompositeShape,AbstractCoordinateShape
Every shape that can be rendered must extend this class and implement the
transform(TransformStack, RenderAggregator, RenderingContext) method,
which projects the shape from world space into screen space during each render frame.
Shapes can optionally have a MouseInteractionController attached to receive
mouse click and hover events when the user interacts with the shape in the 3D view.
Shape hierarchy overview:
AbstractShape +-- AbstractCoordinateShape (shapes with vertex coordinates: lines, polygons) +-- AbstractCompositeShape (groups of sub-shapes: boxes, grids, text canvases)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BoxCached bounding box in local coordinates.Optional controller that receives mouse interaction events (click, enter, exit) when the user interacts with this shape in the 3D view. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the axis-aligned bounding box for this shape in local coordinates.voidInvalidates the cached bounding box, forcing recomputation on next call togetBoundingBox().voidsetMouseInteractionController(MouseInteractionController mouseInteractionController) Assigns a mouse interaction controller to this shape.abstract voidtransform(TransformStack transforms, RenderAggregator aggregator, RenderingContext renderingContext) Transforms this shape from world space to screen space and queues it for rendering.
-
Field Details
-
mouseInteractionController
Optional controller that receives mouse interaction events (click, enter, exit) when the user interacts with this shape in the 3D view. Set tonullif mouse interaction is not needed. -
cachedBoundingBox
Cached bounding box in local coordinates. Lazily computed on first call togetBoundingBox(). Subclasses should set this to null when geometry changes to trigger recomputation.
-
-
Constructor Details
-
AbstractShape
public AbstractShape()Default constructor for abstract shape.
-
-
Method Details
-
getBoundingBox
Returns the axis-aligned bounding box for this shape in local coordinates.The bounding box is used for frustum culling to determine if the shape is potentially visible before expensive vertex transformations.
Conservative default: Returns a very large box that ensures the shape is always considered visible. Subclasses should override to provide tight bounds computed from their geometry.
Caching: The bounding box is cached after first computation. If geometry changes, call
invalidateBounds()to trigger recomputation on next call.- Returns:
- the axis-aligned bounding box in local coordinates
-
invalidateBounds
public void invalidateBounds()Invalidates the cached bounding box, forcing recomputation on next call togetBoundingBox().Call this method whenever the shape's geometry changes to ensure frustum culling uses up-to-date bounds. This is critical for shapes that move or deform after creation.
Usage example:
// After modifying vertex coordinates directly: vertex.coordinate.translate(0, 10, 0); shape.invalidateBounds(); // Or use translate() on AbstractCoordinateShape which handles this automatically -
setMouseInteractionController
Assigns a mouse interaction controller to this shape.Example usage:
shape.setMouseInteractionController(new MouseInteractionController() { public boolean mouseClicked(int button) { System.out.println("Shape clicked!"); return true; } public boolean mouseEntered() { return false; } public boolean mouseExited() { return false; } });- Parameters:
mouseInteractionController- the controller to handle mouse events, ornullto disable mouse interaction
-
transform
public abstract void transform(TransformStack transforms, RenderAggregator aggregator, RenderingContext renderingContext) Transforms this shape from world space to screen space and queues it for rendering.This method is called once per frame for each shape in the scene. Implementations should apply the current transform stack to their vertices, compute screen-space coordinates, and if the shape is visible, add it to the
RenderAggregatorfor depth-sorted painting.- Parameters:
transforms- the current stack of transforms (world-to-camera transformations)aggregator- collects transformed shapes for depth-sorted renderingrenderingContext- provides frame dimensions, graphics context, and frame metadata
-