Image export
model.activeView is an export View with its
own camera. Set the camera, then call writeImage:
const { Camera } = modlumi;const model = modlumi.activeModel;model.operation("Box", () => { model.entities.addEdges([[0, 0, 0], [4, 0, 0], [4, 3, 0], [0, 3, 0], [0, 0, 0]]); const [face] = model.entities.ofType("Face"); face.extrude(2);});
const view = model.activeView;view.camera = new Camera([5, -7, 5.5], [2, 1.5, 1], { perspective: false, fieldOfView: 35 });view.writeImage("box.png", { width: 640, height: 480 });The image shows the committed model with its axes and background, but without the interface, tool previews or selection highlights. It’s rendered with four-sample antialiasing.
- Call
writeImageafter the operation ends, so the edits are committed. - The file name must end in
.png. A relative name is relative to the folder Modlumi was started from. - Width and height must be whole numbers between 1 and 8192 pixels.
- Existing files are overwritten. The folder must already exist.
- Invalid arguments throw
TypeErrororRangeError; rendering or file errors throwmodlumi.ModelError.
Cameras
Section titled “Cameras”A Camera is defined by an eye position and a
target point in meters, and optionally an up direction, perspective
and a vertical fieldOfView in degrees. Cameras are immutable, so assign a
new camera to view.camera to change it. The export camera starts out as the
standard camera and is separate from the camera in the window.
This renders the model from four sides:
const { Camera, Point3d } = modlumi;const view = modlumi.activeModel.activeView;["front", "right", "back", "left"].forEach((side, i) => { const angle = -Math.PI / 2 + (i * Math.PI) / 2; const eye = new Point3d(10 * Math.cos(angle), 10 * Math.sin(angle), 4); view.camera = new Camera(eye, [0, 0, 1], { fieldOfView: 40 }); view.writeImage(`turntable-${side}.png`, { width: 400, height: 300 });});Without a window
Section titled “Without a window”Image export also works in background runs,
without a window. On Linux this needs a build with
MODLUMI_ENABLE_HEADLESS_RENDERING and an EGL driver that supports
surfaceless OpenGL 4.1; Mesa’s software renderer works. Background image
export isn’t available on Windows yet, and the browser preview can’t write
image files.