Class ShapeCollection
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.
Architecture:
The collection contains a single AbstractCompositeShape as its root container.
This root composite:
- Stores all scene shapes in its sub-shapes registry
- Triangulates N-vertex polygons (quads, etc.) into triangles during rendering
- Provides group-based visibility management (show/hide groups)
- Applies camera transform (position and rotation) to all shapes
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
));
// Add shapes with group identifier for visibility control
scene.addShape(debugShape, "debug");
scene.hideGroup("debug"); // hide all debug shapes
scene.showGroup("debug"); // show them again
// Add N-vertex polygons (quads, etc.) - automatically triangulated
scene.addShape(SolidPolygon.quad(p1, p2, p3, p4, color));
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
ConstructorsConstructorDescriptionCreates a new empty shape collection with a root composite. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddShape(AbstractShape shape) Adds a shape to this collection without a group identifier.voidaddShape(AbstractShape shape, String groupId) Adds a shape to this collection with a group identifier for visibility control.voidclear()Removes all shapes from this collection.Returns all sub-shapes belonging to the specified group.intReturns the number of shapes queued for rendering.Returns all shapes currently in this collection (including hidden ones).Returns the sub-shapes registry with group and visibility metadata.voidHides all shapes belonging to the specified group.voidpaintShapes(RenderingContext renderingContext) Paints all already-sorted shapes to the rendering context.voidremoveGroup(String groupId) Permanently removes all shapes belonging to the specified group.voidsetCacheNeedsRebuild(boolean needsRebuild) Sets the cache rebuild flag on the root composite.voidShows all shapes belonging to the specified group.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 with a root composite.
-
-
Method Details
-
addShape
Adds a shape to this collection without a group identifier. This method is thread-safe.- Parameters:
shape- the shape to add to the scene
-
addShape
Adds a shape to this collection with a group identifier for visibility control. This method is thread-safe.Grouped shapes can be shown, hidden, or removed together using
showGroup(java.lang.String),hideGroup(java.lang.String), andremoveGroup(java.lang.String).- Parameters:
shape- the shape to addgroupId- the group identifier, ornullfor ungrouped shapes
-
getShapes
Returns all shapes currently in this collection (including hidden ones).This returns the sub-shapes from the registry, unwrapped from their
SubShapecontainers. For access to group and visibility metadata, usegetSubShapesRegistry().- Returns:
- a collection of all shapes in the scene
-
getSubShapesRegistry
Returns the sub-shapes registry with group and visibility metadata.This provides direct access to the registry for advanced operations like inspecting group assignments or visibility states.
- Returns:
- the list of sub-shapes with their metadata
-
clear
public void clear()Removes all shapes from this collection. This method is thread-safe. -
showGroup
Shows all shapes belonging to the specified group.- Parameters:
groupId- the group identifier to show
-
hideGroup
Hides all shapes belonging to the specified group. Hidden shapes are not rendered but remain in the collection.- Parameters:
groupId- the group identifier to hide
-
removeGroup
Permanently removes all shapes belonging to the specified group.- Parameters:
groupId- the group identifier to remove
-
getGroup
Returns all sub-shapes belonging to the specified group.- Parameters:
groupId- the group identifier to match- Returns:
- list of matching sub-shapes
-
transformShapes
Transforms all shapes to screen space and queues them for rendering. This is phase 1 of the multi-threaded render pipeline.Updates the root composite's transform to match the camera position and rotation, then delegates to the root composite's transform method which handles all shapes.
Frustum culling: The view frustum is computed from camera state and screen dimensions before transforming shapes. Composite shapes can test their bounding boxes against this frustum to skip invisible objects.
Culling statistics: Statistics are reset and total shape count computed at the start of each frame. Visible shapes are counted as they are queued.
- 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
-
setCacheNeedsRebuild
public void setCacheNeedsRebuild(boolean needsRebuild) Sets the cache rebuild flag on the root composite.Used internally to force reslice when needed. Public for advanced use cases.
- Parameters:
needsRebuild-trueto force cache rebuild
-