把STL文件ACSII格式读入matlab

该函数演示了如何在MATLAB中读取STL ASCII格式的文件。通过逐行解析文件,提取顶点坐标和颜色信息,最终构建面列表。函数返回顶点矩阵、面列表和颜色数据。
摘要由CSDN通过智能技术生成
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,
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值