Class AbstractCompositeShape
- Direct Known Subclasses:
Graph,Grid2D,Grid3D,GuiComponent,LightSourceMarker,SolidPolygonArrow,SolidPolygonCone,SolidPolygonCylinder,SolidPolygonMesh,SolidPolygonPyramid,SolidPolygonRectangularBox,SolidPolygonSphere,TexturedRectangle,WireframeArrow,WireframeBox,WireframeCone,WireframeCylinder,WireframeDrawing,WireframePyramid,WireframeSphere
Use AbstractCompositeShape to build complex 3D objects by combining
primitive shapes (lines, polygons, textured polygons) into a group that can be
positioned, rotated, and manipulated as one entity. Sub-shapes can be organized
into named groups for selective visibility toggling.
Usage example - creating a custom composite shape:
// Create a composite shape at position (0, 0, 200)
AbstractCompositeShape myObject = new AbstractCompositeShape(
new Point3D(0, 0, 200)
);
// Add sub-shapes
myObject.addShape(new Line(
new Point3D(-50, 0, 0), new Point3D(50, 0, 0),
Color.RED, 2.0
));
// Add shapes to a named group for toggling visibility
myObject.addShape(labelShape, "labels");
myObject.hideGroup("labels"); // hide all shapes in "labels" group
myObject.showGroup("labels"); // show them again
// Add to scene
viewPanel.getRootShapeCollection().addShape(myObject);
Level-of-detail slicing:
Textured polygons within the composite shape are automatically sliced into smaller triangles based on distance from the viewer. This provides perspective-correct texture mapping without requiring hardware support. The slicing factor adapts dynamically.
Extending this class:
Override beforeTransformHook(eu.svjatoslav.sixth.e3d.math.TransformStack, eu.svjatoslav.sixth.e3d.gui.RenderingContext) to customize shape appearance or behavior
on each frame (e.g., animations, dynamic geometry updates).
- See Also:
-
Field Summary
Fields inherited from class eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape
mouseInteractionController -
Constructor Summary
ConstructorsConstructorDescriptionCreates a composite shape at the world origin with no rotation.AbstractCompositeShape(Point3D location) Creates a composite shape at the specified location with no rotation.AbstractCompositeShape(Transform transform) Creates a composite shape with the specified transform (position and orientation). -
Method Summary
Modifier and TypeMethodDescriptionvoidaddShape(AbstractShape shape) Adds a sub-shape to this composite shape without a group identifier.voidaddShape(AbstractShape shape, String groupId) Adds a sub-shape to this composite shape with an optional group identifier.voidbeforeTransformHook(TransformStack transformPipe, RenderingContext context) This method should be overridden by anyone wanting to customize the shape before it is rendered.Extracts all SolidPolygon triangles from this composite shape.Returns all sub-shapes belonging to the specified group.Returns the world-space position of this composite shape.Returns the list of all sub-shapes (including hidden ones).Returns the view-space tracker that monitors the distance and angle between the camera and this shape for level-of-detail adjustments.voidHides all sub-shapes belonging to the specified group.voidremoveGroup(String groupIdentifier) Permanently removes all sub-shapes belonging to the specified group.setBackfaceCulling(boolean backfaceCulling) Enables or disables backface culling for all SolidPolygon and TexturedPolygon sub-shapes.voidPaint solid elements of this composite shape into given color.voidsetGroupForUngrouped(String groupIdentifier) Assigns a group identifier to all sub-shapes that currently have no group.voidsetMouseInteractionController(MouseInteractionController mouseInteractionController) Assigns a mouse interaction controller to this shape.setShadingEnabled(boolean shadingEnabled) Enables or disables shading for all SolidPolygon sub-shapes.setTransform(Transform transform) Sets the transform for this composite shape.voidMakes all sub-shapes belonging to the specified group visible.voidtransform(TransformStack transformPipe, RenderAggregator aggregator, RenderingContext context) Transforms this shape from world space to screen space and queues it for rendering.
-
Constructor Details
-
AbstractCompositeShape
public AbstractCompositeShape()Creates a composite shape at the world origin with no rotation. -
AbstractCompositeShape
Creates a composite shape at the specified location with no rotation.- Parameters:
location- the position in world space
-
AbstractCompositeShape
Creates a composite shape with the specified transform (position and orientation).- Parameters:
transform- the initial transform defining position and rotation
-
-
Method Details
-
addShape
Adds a sub-shape to this composite shape without a group identifier.- Parameters:
shape- the shape to add
-
addShape
Adds a sub-shape to this composite shape with an optional group identifier.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
-
beforeTransformHook
This method should be overridden by anyone wanting to customize the shape before it is rendered.- Parameters:
transformPipe- the current transform stackcontext- the rendering context for the current frame
-
getLocation
Returns the world-space position of this composite shape.- Returns:
- the translation component of this shape's transform
-
getOriginalSubShapes
Returns the list of all sub-shapes (including hidden ones).- Returns:
- the internal list of sub-shapes
-
extractSolidPolygons
Extracts all SolidPolygon triangles from this composite shape.Recursively traverses the shape hierarchy and collects all
SolidPolygoninstances. Useful for CSG operations where you need the raw triangles from a composite shape likeSolidPolygonCubeorSolidPolygonSphere.Example:
SolidPolygonCube cube = new SolidPolygonCube(new Point3D(0, 0, 0), 50, Color.RED); List<SolidPolygon> triangles = cube.extractSolidPolygons(); CSGSolid csg = CSGSolid.fromSolidPolygons(triangles);- Returns:
- list of all SolidPolygon sub-shapes
-
getViewSpaceTracker
Returns the view-space tracker that monitors the distance and angle between the camera and this shape for level-of-detail adjustments.- Returns:
- the view-space tracker for this shape
-
hideGroup
Hides all sub-shapes belonging to the specified group. Hidden shapes are not rendered but remain in the collection.- Parameters:
groupIdentifier- the group to hide- See Also:
-
removeGroup
Permanently removes all sub-shapes belonging to the specified group.- Parameters:
groupIdentifier- the group to remove- See Also:
-
getGroup
Returns all sub-shapes belonging to the specified group.- Parameters:
groupIdentifier- the group identifier to match- Returns:
- list of matching sub-shapes
-
setColor
Paint solid elements of this composite shape into given color.- Parameters:
color- the color to apply to all solid sub-shapes
-
setGroupForUngrouped
Assigns a group identifier to all sub-shapes that currently have no group.- Parameters:
groupIdentifier- the group to assign to ungrouped shapes
-
setMouseInteractionController
Description copied from class:AbstractShapeAssigns 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; } });- Overrides:
setMouseInteractionControllerin classAbstractShape- Parameters:
mouseInteractionController- the controller to handle mouse events, ornullto disable mouse interaction
-
setTransform
Sets the transform for this composite shape.- Parameters:
transform- the new transform- Returns:
- this composite shape (for chaining)
-
setShadingEnabled
Enables or disables shading for all SolidPolygon sub-shapes. When enabled, polygons use the global lighting manager from the rendering context to calculate flat shading based on light sources.- Parameters:
shadingEnabled-trueto enable shading,falseto disable- Returns:
- this composite shape (for chaining)
-
setBackfaceCulling
Enables or disables backface culling for all SolidPolygon and TexturedPolygon sub-shapes.- Parameters:
backfaceCulling-trueto enable backface culling,falseto disable- Returns:
- this composite shape (for chaining)
-
showGroup
Makes all sub-shapes belonging to the specified group visible.- Parameters:
groupIdentifier- the group to show- See Also:
-
transform
public void transform(TransformStack transformPipe, RenderAggregator aggregator, RenderingContext context) Description copied from class:AbstractShapeTransforms 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.- Specified by:
transformin classAbstractShape- Parameters:
transformPipe- the current stack of transforms (world-to-camera transformations)aggregator- collects transformed shapes for depth-sorted renderingcontext- provides frame dimensions, graphics context, and frame metadata
-