Class ShapeCollection
java.lang.Object
eu.svjatoslav.sixth.e3d.renderer.raster.ShapeCollection
Root container that holds all 3D shapes in a scene and orchestrates their rendering.
ShapeCollection is the top-level scene graph. You add shapes to it, and during
each render frame it transforms all shapes from world space to screen space (relative to the
camera), sorts them by depth, and paints them back-to-front.
Usage example:
// Get the root shape collection from the view panel
ShapeCollection scene = viewPanel.getRootShapeCollection();
// Add shapes to the scene
scene.addShape(new Line(
new Point3D(0, 0, 100),
new Point3D(100, 0, 100),
Color.RED, 2.0
));
scene.addShape(new WireframeCube(
new Point3D(0, 0, 200), 50,
new LineAppearance(5, Color.GREEN)
));
The addShape(eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape) method is synchronized, making it safe to add shapes from
any thread while the rendering loop is active.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddShape(AbstractShape shape) Adds a shape to this collection.voidclear()Removes all shapes from this collection.intReturns the number of shapes queued for rendering.Returns the list of all shapes currently in this collection.voidpaintShapes(RenderingContext renderingContext) Paints all already-sorted shapes to the rendering context.voidSorts all queued shapes by Z-depth (back to front).voidtransformShapes(ViewPanel viewPanel, RenderingContext renderingContext) Transforms all shapes to screen space and queues them for rendering.
-
Constructor Details
-
ShapeCollection
public ShapeCollection()Creates a new empty shape collection.
-
-
Method Details
-
addShape
Adds a shape to this collection. This method is thread-safe.- Parameters:
shape- the shape to add to the scene
-
getShapes
Returns the list of all shapes currently in this collection.- Returns:
- unmodifiable view would be safer, but currently returns the internal list
-
clear
public void clear()Removes all shapes from this collection. This method is thread-safe. -
transformShapes
Transforms all shapes to screen space and queues them for rendering. This is phase 1 of the multi-threaded render pipeline.- Parameters:
viewPanel- the view panel providing the camera staterenderingContext- the rendering context with frame metadata
-
sortShapes
public void sortShapes()Sorts all queued shapes by Z-depth (back to front). This is phase 2 of the multi-threaded render pipeline. -
paintShapes
Paints all already-sorted shapes to the rendering context. This is phase 3 of the multi-threaded render pipeline. Can be called multiple times with different segment contexts.- Parameters:
renderingContext- the rendering context to paint into
-
getQueuedShapeCount
public int getQueuedShapeCount()Returns the number of shapes queued for rendering.- Returns:
- the shape count
-