把STL文件ACSII格式讀入matlab

function [fout, vout, cout] = ReadSTLACSII(filename)


fid=fopen(filename, 'r');
if fid == -1 
    error('文件打開錯誤!.')
end


%讀取文件頭,STL文件第一行是文件名
File_name = sscanf(fgetl(fid), '%*s %s');  %CAD object name, if needed.


%定義變量
vnum=0;       %Vertex number counter.
report_num=0; %Report the status as we go.
STLvcolor = 0;
STLxyz=0;


%開始讀整個文件,直到結束符爲止
while feof(fid) == 0                    % test for end of file, if not then do stuff
    tline = fgetl(fid);                 % reads a line of data from file.
    fword = sscanf(tline, '%s');       % make the line a character string


%檢查顏色
if strncmpi(fword, 'facet normal',12) == 1;    % Checking if a "C"olor line, as "C" is 1st char.
       STLvcolor = sscanf(tline, '%*s %f %f %f'); % & if a C, get the RGB color data of the face.   % we "*s" skip the name "color" and get the data.  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章