Export STL to 2d PDF at multiple viewpoints

26 vues (au cours des 30 derniers jours)
Lee
Lee le 2 Nov 2022
Commenté : Suvansh Arora le 7 Nov 2022
Is there a simple function to convert .stl files to 2d .pdf or .jpeg files?
I have a large set of .stl files of 3d objects.
I want to save out these 3D objects as pdfs at different viewpoints (i.e. rotating around x axis).
Thank you.

Réponse acceptée

Suvansh Arora
Suvansh Arora le 4 Nov 2022
In order to import “STL” file (3D image) into MATLAB you can use a customer created function in MathWorks File Exchange which can load “STL” file into MATLAB. The customer created function can be downloaded from the following link:
As you mentioned you have large set of “STL” images to convert, you can use the below mentioned code to save out the 3D objects as “PDFs” at different viewpoints (In order to use it, please download the above package first).
%% 3D Model Demo (stldemo.m)
% This file will help in saving femur.stl (3D image) same view, 7 times in 7 different pdf files.
for idx=1:7
fv = stlread('femur.stl');
%% Render
% The model is rendered with a PATCH graphics object. We also add some dynamic
% lighting, and adjust the material properties to change the specular
% highlighting.
patch(fv,'FaceColor', [0.8 0.8 1.0], ...
'EdgeColor', 'none', ...
'FaceLighting', 'gouraud', ...
'AmbientStrength', 0.15);
% Add a camera light, and tone down the specular highlighting
camlight('headlight');
material('dull');
% Fix the axes scaling, and set a nice view angle
axis('image');
view([135 35]);
exportgraphics(gcf,'test'+string(idx)+'.pdf')
close
end
Please look at the following documentations and related ML answers articles, if you face any issues:
I hope the above information helps you.
  3 commentaires
Lee
Lee le 4 Nov 2022
Thank you this is extremely helpful! It works great for my object set.
I had one more followup question, is there a simple argument I could add to make the pdf backgrounds black and the object white?
Thanks again, really appreciate it especially as a new matlab user.
Suvansh Arora
Suvansh Arora le 7 Nov 2022
I had one more followup question, is there a simple argument I could add to make the pdf backgrounds black and the object white?
You can use the “exportgraphics” function to add the background colors to your “PDF”.
Please follow the documentation mentioned, for your reference: Add background to your PDF

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by