Contenu principal

resize

R2026b

Resize mesh or scene object to absolute dimensions in world units

Since R2026b

Description

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

resize(meshORsceneObj,dimensions) resizes the mesh or scene object meshORsceneObj to the specified absolute dimensions dimensions in world units.

resize(meshORsceneObj,dimensions,Uniform=uniform) scales the mesh or scene object meshORsceneObj uniformly across all axes. When Uniform is true, specify only one non-NaN dimension in dimensions and set the other two to NaN. The function computes the uniform scale factor from the single specified dimension and applies it to all three axes.

example

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);

Resize the mesh to 5-by-3-by-2 world units.

resizedMesh = copy(pyramidMesh);
resize(resizedMesh,[5 3 2])

Visualize the mesh resized to 5-by-3-by-2 world units compared to the original 1-by-1-by-1 extents.

figure
subplot(1,2,1)
patch(pyramidMesh,EdgeColor="k")
axis equal
title("Extents: [1,1,1]")
subplot(1,2,2)
patch(resizedMesh,EdgeColor="k")
axis equal
title("Extents: [5,3,2]")

Input Arguments

collapse all

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

Target dimensions, specified as a three-element row vector of the form [dx dy dz] in world units. Use NaN for axes that do not require a change. Specified dimensions must be positive and finite. The function does not resize an axis whose current extent is zero.

Data Types: double

Uniform scaling flag, specified as a logical 1 (true) or 0 (false). When true, only one element of dimensions must be non-NaN. The function computes the scale factor from that single specified dimension and applies it uniformly to all three axes, preserving the aspect ratio of the mesh.

Data Types: logical

Version History

Introduced in R2026b

See Also

| |