Class AbstractCompositeShape
- Direct Known Subclasses:
Graph,Grid2D,Grid3D,GuiComponent,LightSourceMarker,SolidPolygonPyramid,SolidPolygonRectangularBox,SolidPolygonSphere,TexturedRectangle,WireframeBox,WireframeDrawing,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 shape before it is rendered.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.voidsetBackfaceCulling(boolean backfaceCulling) 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.voidsetLightingManager(LightingManager lightingManager) Sets the lighting manager for this composite shape and enables shading on all SolidPolygon sub-shapes.voidsetMouseInteractionController(MouseInteractionController mouseInteractionController) Assigns a mouse interaction controller to this shape.voidsetShadingEnabled(boolean shadingEnabled) Enables or disables shading for all SolidPolygon sub-shapes.voidsetTransform(Transform transform) Replaces this shape's transform (position and orientation).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 shape before it is rendered. -
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
-
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. -
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
Replaces this shape's transform (position and orientation).- Parameters:
transform- the new transform to apply
-
setLightingManager
Sets the lighting manager for this composite shape and enables shading on all SolidPolygon sub-shapes.- Parameters:
lightingManager- the lighting manager to use for shading calculations
-
setShadingEnabled
public void setShadingEnabled(boolean shadingEnabled) Enables or disables shading for all SolidPolygon sub-shapes.- Parameters:
shadingEnabled- true to enable shading, false to disable
-
setBackfaceCulling
public void setBackfaceCulling(boolean backfaceCulling) -
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
-