Contenido principal

copy

R2026b

Create copy of mesh or scene object

Since R2026b

Description

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

meshORsceneCopy = copy(meshORsceneObj) creates a deep copy meshORsceneCopy of the input mesh or scene object meshORsceneObj. Because Mesh and Scene are handle objects, assigning one to another variable creates a reference, not an independent copy. Use this function to create an independent copy that you can modify without affecting the original.

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

Create a copy of the raw mesh.

translatedMesh = copy(pyramidMesh);

Shift the mesh 2 units along the X-axis.

translate(translatedMesh,[2 0 0])

Visualize the mesh shifted 2 units along the X-axis compared to the original position.

figure
subplot(1,2,1)
patch(pyramidMesh,EdgeColor="k")
axis equal
title("Position: [0 0 0]")
subplot(1,2,2)
patch(translatedMesh,EdgeColor="k")
axis equal
title("Position: [2 0 0]")

Input Arguments

collapse all

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

Output Arguments

collapse all

Copy of the input mesh or scene object, returned as a Mesh object or Scene object.

Version History

Introduced in R2026b