java.lang.Object
eu.svjatoslav.sixth.e3d.renderer.raster.shapes.AbstractShape
eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.base.AbstractCompositeShape
Direct Known Subclasses:
Graph, Grid2D, Grid3D, GuiComponent, LightSourceMarker, SolidPolygonPyramid, SolidPolygonRectangularBox, SolidPolygonSphere, TexturedRectangle, WireframeBox, WireframeDrawing, WireframeSphere

public class AbstractCompositeShape extends AbstractShape
A composite shape that groups multiple sub-shapes into a single logical unit.

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:
  • Constructor Details

    • AbstractCompositeShape

      public AbstractCompositeShape()
      Creates a composite shape at the world origin with no rotation.
    • AbstractCompositeShape

      public AbstractCompositeShape(Point3D location)
      Creates a composite shape at the specified location with no rotation.
      Parameters:
      location - the position in world space
    • AbstractCompositeShape

      public AbstractCompositeShape(Transform transform)
      Creates a composite shape with the specified transform (position and orientation).
      Parameters:
      transform - the initial transform defining position and rotation
  • Method Details

    • addShape

      public void addShape(AbstractShape shape)
      Adds a sub-shape to this composite shape without a group identifier.
      Parameters:
      shape - the shape to add
    • addShape

      public void addShape(AbstractShape shape, String groupId)
      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), and removeGroup(java.lang.String).

      Parameters:
      shape - the shape to add
      groupId - the group identifier, or null for ungrouped shapes
    • beforeTransformHook

      public void beforeTransformHook(TransformStack transformPipe, RenderingContext context)
      This method should be overridden by anyone wanting to customize shape before it is rendered.
    • getLocation

      public Point3D getLocation()
      Returns the world-space position of this composite shape.
      Returns:
      the translation component of this shape's transform
    • getOriginalSubShapes

      public List<SubShape> getOriginalSubShapes()
      Returns the list of all sub-shapes (including hidden ones).
      Returns:
      the internal list of sub-shapes
    • getViewSpaceTracker

      public ViewSpaceTracker 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

      public void hideGroup(String groupIdentifier)
      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

      public void removeGroup(String groupIdentifier)
      Permanently removes all sub-shapes belonging to the specified group.
      Parameters:
      groupIdentifier - the group to remove
      See Also:
    • getGroup

      public List<SubShape> getGroup(String groupIdentifier)
      Returns all sub-shapes belonging to the specified group.
      Parameters:
      groupIdentifier - the group identifier to match
      Returns:
      list of matching sub-shapes
    • setColor

      public void setColor(Color color)
      Paint solid elements of this composite shape into given color.
    • setGroupForUngrouped

      public void setGroupForUngrouped(String groupIdentifier)
      Assigns a group identifier to all sub-shapes that currently have no group.
      Parameters:
      groupIdentifier - the group to assign to ungrouped shapes
    • setMouseInteractionController

      public void setMouseInteractionController(MouseInteractionController mouseInteractionController)
      Description copied from class: AbstractShape
      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; }
       });
       
      Overrides:
      setMouseInteractionController in class AbstractShape
      Parameters:
      mouseInteractionController - the controller to handle mouse events, or null to disable mouse interaction
    • setTransform

      public void setTransform(Transform transform)
      Replaces this shape's transform (position and orientation).
      Parameters:
      transform - the new transform to apply
    • setLightingManager

      public void setLightingManager(LightingManager lightingManager)
      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

      public void showGroup(String groupIdentifier)
      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: AbstractShape
      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 RenderAggregator for depth-sorted painting.

      Specified by:
      transform in class AbstractShape
      Parameters:
      transformPipe - the current stack of transforms (world-to-camera transformations)
      aggregator - collects transformed shapes for depth-sorted rendering
      context - provides frame dimensions, graphics context, and frame metadata