由于工作需要
function cad2matdemo(filename)
% CAD2MATDEMO, a demonstration of importing 3D CAD data into Matlab.
% To get CAD data into Matlab, the process is:
%
% 1) Export the 3D CAD data as an ASCII STL (or Pro/E render SLP) file.
% 2) This Matlab routine reads the CAD data
% 3) Once read, the CAD data is rotated around a bit.
%
% Program has been tested with: AutoCAD, Cadkey, and Pro/Engineer.
% Should work with most any CAD programs that can export STL.
%
% Format Details: STL is supported, and the color version of STL
% that Pro/E exports, called 'render.' The render (SLP) is just
% like STL but with color added.
%
% Note: This routine has both the import function and some basic
% manipulation for testing. The actual reading mechanism is located
% at the end of this file.
% example:
% cad2matdemo('KaiXuanMen.stl')
% cad2matdemo('USV_boat.stl')
% Readers can ask for data from the authoer by Email:
% 380545156@qq.com,after make a "like" in this article.
if nargin == 0
filename = 'hook.stl'; % a simple demo part
warning(['No file specified, using demo file: ' filename]);
end
%
% Read the CAD data file:
[F, V, C] = rndread(filename);
clf;
p = patch('faces', F, 'vertices' ,V);
%set(p, 'facec', 'b'); % Set the face color (force it)
set(p, 'facec', 'flat'); % Set the face color flat
set(p, 'FaceVertexCData', C); % Set