-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathload_smf.m
executable file
·58 lines (49 loc) · 1.27 KB
/
load_smf.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function [points,faces] = load_smf(filename)
% load_smf - read data from SMF file.
%
% [points,faces] = load_smf(filename);
%
fid = fopen(filename,'r');
if( fid==-1 )
error('Can''t open the file.');
return;
end
points = [];
faces = [];
tmp = 1;
while ( ~isempty(tmp) )
tmp = fscanf(fid, '%s %g %g %g', [4 inf]);
if isempty(tmp)
continue
end
idx = find(tmp(1,:) == uint8('v'));
if ~isempty(idx)
points = [points,tmp(2:4,idx)];
end
idx = find(tmp(1,:) == uint8('t'));
idx = [idx ; find(tmp(1,:) == uint8('f'))];
if ~isempty(idx)
faces = [faces,tmp(2:4,idx)];
end
end
points = points';
faces = faces';
return
str = 0;
while ( str ~= -1)
str = fgets(fid); % -1 if eof
if str(1)=='v'
[a,str] = strtok(str);
[a,str] = strtok(str); x = str2num(a);
[a,str] = strtok(str); y = str2num(a);
[a,str] = strtok(str); z = str2num(a);
points = [points;[x y z]];
elseif str(1)=='t' || str(1)=='f'
[a,str] = strtok(str);
[a,str] = strtok(str); x = str2num(a);
[a,str] = strtok(str); y = str2num(a);
[a,str] = strtok(str); z = str2num(a);
faces = [faces;[x y z]];
end
end
fclose(fid);