Class Snapshot

java.lang.Object
eu.svjatoslav.sixth.e3d.headless.Snapshot

public final class Snapshot extends Object
One-call facade for rendering a scene to an image without a window.

Assembles the same transform → sort → paint pipeline that ViewPanel drives on screen, but into an off-screen RenderingContext pixel buffer. No Swing frame, no X display, no render thread — safe to use from tests, doc tooling and batch jobs.

Example:


 ShapeCollection scene = new ShapeCollection();
 scene.addShape(myShape);

 LightingManager lighting = new LightingManager();
 lighting.setAmbientLight(Color.hex("181818"));

 BufferedImage image = Snapshot.render(scene, lighting,
         "290.31, -35.59, -2.10, -0.58, -0.15, 0.0", 640, 480);
 Snapshot.save(image, "/tmp/snapshot.png");
 

The pose string is the same "x, y, z, yaw, pitch, roll" format the demos print for camera positions, so a pose copy-pasted from a bug report reproduces the exact view.

See Also:
  • Method Details

    • render

      public static BufferedImage render(ShapeCollection scene, LightingManager lighting, String pose, int width, int height)
      Renders the scene once from the given pose string.
      Parameters:
      scene - the scene to render
      lighting - lighting for the frame (may be null for unlit scenes)
      pose - "x, y, z, yaw, pitch, roll" — same format demos print
      width - image width in pixels
      height - image height in pixels
      Returns:
      the rendered frame (background is black)
    • render

      public static BufferedImage render(ShapeCollection scene, LightingManager lighting, Camera camera, int width, int height)
      Renders the scene once from the given camera.
      Parameters:
      scene - the scene to render
      lighting - lighting for the frame (may be null for unlit scenes)
      camera - positioned camera
      width - image width in pixels
      height - image height in pixels
      Returns:
      the rendered frame (background is black)
    • renderInto

      public static void renderInto(ShapeCollection scene, Camera camera, RenderingContext ctx, int backgroundArgb)
      Renders one frame into an existing context, filling the background with the given ARGB color first. Use a unique sentinel color when the caller needs to distinguish "nothing painted here" from "painted black" (e.g. hole detection in clipping tests).
      Parameters:
      scene - the scene to render
      camera - positioned camera
      ctx - target context (its pixels buffer is painted)
      backgroundArgb - background fill applied before painting
    • cameraFromPose

      public static Camera cameraFromPose(String pose)
      Builds a camera from a "x, y, z, yaw, pitch, roll" pose string, as printed by demos (see poseString(Camera)).
      Parameters:
      pose - the pose string; commas and extra whitespace tolerated
      Returns:
      a camera at that pose
    • poseString

      public static String poseString(Camera camera)
      Formats a camera's pose as "x, y, z, yaw, pitch, roll" — the exact string cameraFromPose(String) parses back. Intended for bug reports: paste the pose, reproduce the view.
      Parameters:
      camera - the camera to describe
      Returns:
      the pose string
    • save

      public static void save(BufferedImage image, String path) throws IOException
      Saves an image as PNG.
      Parameters:
      image - the image to save
      path - target file path
      Throws:
      IOException - on write failure