Package eu.svjatoslav.sixth.e3d.headless
Class Snapshot
java.lang.Object
eu.svjatoslav.sixth.e3d.headless.Snapshot
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 Summary
Modifier and TypeMethodDescriptionstatic CameracameraFromPose(String pose) Builds a camera from a "x, y, z, yaw, pitch, roll" pose string, as printed by demos (seeposeString(Camera)).static StringposeString(Camera camera) Formats a camera's pose as "x, y, z, yaw, pitch, roll" — the exact stringcameraFromPose(String)parses back.static BufferedImagerender(ShapeCollection scene, LightingManager lighting, Camera camera, int width, int height) Renders the scene once from the given camera.static BufferedImagerender(ShapeCollection scene, LightingManager lighting, String pose, int width, int height) Renders the scene once from the given pose string.static voidrenderInto(ShapeCollection scene, Camera camera, RenderingContext ctx, int backgroundArgb) Renders one frame into an existing context, filling the background with the given ARGB color first.static voidsave(BufferedImage image, String path) Saves an image as PNG.
-
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 renderlighting- lighting for the frame (may be null for unlit scenes)pose- "x, y, z, yaw, pitch, roll" — same format demos printwidth- image width in pixelsheight- 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 renderlighting- lighting for the frame (may be null for unlit scenes)camera- positioned camerawidth- image width in pixelsheight- 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 rendercamera- positioned cameractx- target context (itspixelsbuffer is painted)backgroundArgb- background fill applied before painting
-
cameraFromPose
Builds a camera from a "x, y, z, yaw, pitch, roll" pose string, as printed by demos (seeposeString(Camera)).- Parameters:
pose- the pose string; commas and extra whitespace tolerated- Returns:
- a camera at that pose
-
poseString
Formats a camera's pose as "x, y, z, yaw, pitch, roll" — the exact stringcameraFromPose(String)parses back. Intended for bug reports: paste the pose, reproduce the view.- Parameters:
camera- the camera to describe- Returns:
- the pose string
-
save
Saves an image as PNG.- Parameters:
image- the image to savepath- target file path- Throws:
IOException- on write failure
-