combine two stl into one
Show older comments
I have two 3D geometries ('sol_1.stl' and 'sol_2.stl') and their corresponding nodes and faces.
I would like to combine the two STL geometries into a single geometry, or merge the nodes and faces of the two geometries into one.
- sol_1.st + sol_2.st -> sol_fin.stl
- nodes_sol_1 + nodes_sol_2 -> nodes_sol_fin (simple)
- faces_sol_1 + faces_sol_2 -> faces_sol_fin
Accepted Answer
More Answers (1)
Say we have multiple files or other representations of triangulated surfaces:
% if you have files or other things, just throw them into a cell array
unzip stlpile.zip % prepare things for the forum
% model 1 (a triangulation object)
Tc{1} = stlread('stlpile/stepholecube.stl');
% model 2 (F,V lists)
Tc{2} = stlread('stlpile/sphere_20.stl');
[F V] = t2fv(Tc{2});
V = V/25;
V(:,1) = V(:,1) + 1.5;
Tc{2} = {F V};
% model 3 (an FV struct)
[x y z] = peaks(21);
Tc{3} = surf2patch(x/2,y/2 + 3,z/6,'triangles');
% model 4 (a TriRep object)
% pretend for a moment we're using an old version
[F V] = stlread_2011('stlpile/btpyramid.stl'); % prior to R2018b (FEX #22409)
V = bsxfun(@minus,V,[2 0.5 0.5]); % prior to R2016b
Tc{4} = TriRep(F,V); %#ok<DTRIREP> % prior to R2013a
At this point, we have a cell array of four models in different formats. Combining them is easy.
% concatenate the models and write to a file
[F V] = tricat(Tc); % attached
stlwrite(triangulation(F,V),'test.stl')
% display the composite model
patch('faces',F,'vertices',V,'facecolor',[1 1 1]*0.8,'edgecolor','k');
view(3); view(-45,25); camlight;
axis equal; grid on
As before, this does not do any CSG on the models. It just concatenates and does index offsets and some cleanup.
The input to tricat() is a cell array containing surface data in any of the following formats:
- triangulation objects
- delaunayTriangulation objects
- legacy TriRep or DelaunayTri objects
- FV structs
- cell arrays containing F,V lists
The combined data is pruned and returned as either an FV struct or as F,V lists.
See also:
Categories
Find more on STL (STereoLithography) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!