Main Content

snapshot

R2026b

Capture snapshot of mesh or scene as image

Since R2026b

Description

Add-On Required: This feature requires the 3D Asset Processing Library for MATLAB add-on.

img = snapshot(meshORsceneObj) renders the mesh or scene object meshORsceneObj and returns an RGB image img.

example

img = snapshot(meshORsceneObj,filename) renders the mesh or scene object meshORsceneObj, writes the image to filename, and returns an RGB image img.

[img,info] = snapshot(___) additionally returns a structure info describing the camera used to render.

___ = snapshot(___,Name=Value) specifies additional options using one or more name-value arguments. For example, ImageSize=[768 1024] renders the image at the specified resolution.

Examples

collapse all

Define a simple pyramid with 5 vertices and 6 triangular faces.

vertices = [0 0 0; 1 0 0; 1 1 0; 0 1 0; 0.5 0.5 1];
faces = [1 2 5; 2 3 5; 3 4 5; 4 1 5; 1 3 4; 1 2 3];

Create a mesh with per-face color.

faceColors = uint8([230 50  50;    % red - front
                    50  180 50;    % green - right
                    50  100 230;   % blue - back
                    230 180 25;    % yellow - left
                    150 75  200;   % purple - bottom 1
                    25  200 200]); % cyan - bottom 2
pyramidMesh = asset3d.Mesh(vertices,faces,FaceColors=faceColors);

Render the mesh to an image by using snapshot object function.

img = snapshot(pyramidMesh);

Display the rendered image.

figure
imshow(img)

Input Arguments

collapse all

Source mesh or scene, specified as a Mesh object or Scene object.

Output file path, specified as a string scalar or character vector. The function determines the file format from the extension (for example, ".png", ".jpg").

Data Types: string | char

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: snapshot(mesh,"preview.png",ImageSize=[768 1024]) renders the mesh at 768-by-1024 resolution and saves it.

Output image size in pixels, specified as a two-element row vector of the form [height width].

Data Types: double

Background color, specified as a hexadecimal color string. For example, "#CCCCCC".

Data Types: string

Show axes, specified as a logical 1 (true) or 0 (false).

Data Types: logical

Zoom level, specified as a positive scalar.

Data Types: double

View preset, specified as one of these values:

  • "default" — Elevated 3/4 view along the current up-axis.

  • "isometric" — Isometric view.

  • "XY+", "XY-", "YZ+", "YZ-", "XZ+", "XZ-" — Views the named plane from the positive or negative direction of the remaining axis. For example, "XY+" views the XY plane from +Z-axis.

This argument is mutually exclusive with the CameraPose name-value argument.

Data Types: string

Absolute camera position in world coordinates, specified as a three-element row vector of the form [x y z].

This argument is mutually exclusive with the CameraPose name-value argument.

Data Types: double

Camera look-at point in world coordinates, specified as a three-element row vector of the form [x y z]. By default, the camera looks at the center of the model bounding box.

This argument is mutually exclusive with the CameraPose name-value argument.

Data Types: double

Camera-to-world pose, specified as a rigidtform3d object. Use this when you have explicit camera extrinsics values.

This argument is mutually exclusive with the View, Zoom, CameraPosition, and CameraTarget name-value arguments.

Render timeout in seconds, specified as a positive scalar. The function waits up to this many seconds for the viewer to produce the rendered image.

Data Types: double

Explode scene for inspection, specified as a logical 1 (true) or 0 (false). When set to true, the function visually displaces each geometry in the scene outward from the explosion origin.

Note

This name-value argument is applicable only when you specify the first input argument as a Scene object.

Data Types: logical

Explosion direction, specified as a positive scalar or a three-element row vector of the form [x y z].

  • If you specify a scalar, the function displaces each geometry in the direction from ExplodeOrigin to the geometry centroid, scaled by the scalar value.

  • If you specify a three-element row vector, the function displaces each geometry along the specified direction, proportional to the projection of the vector from ExplodeOrigin to the geometry centroid onto this direction.

If not specified when Explode is true, the function automatically computes the default magnitude from the scene extents.

Note

This name-value argument is applicable only when you specify the first input argument as a Scene object and Explode is set to true.

Data Types: double

Explosion origin point, specified as a three-element row vector of the form [x y z]. The function displaces geometries outward from this point.

Note

This name-value argument is applicable only when you specify the first input as a Scene object and Explode is set to true.

Data Types: double

Output Arguments

collapse all

Rendered RGB image, returned as an H-by-W-by-3 matrix array.

Data Types: uint8

Camera information, returned as a structure with these fields:

  • Pose — Camera-to-world pose, returned as a rigidtform3d object.

  • Intrinsics — Camera intrinsic parameters, returned as a cameraIntrinsics object.

  • ImageSize — Image size used to render, returned as a two-element row vector of the form [height width].

Version History

Introduced in R2026b

See Also

| | |