카테고리
Course Basiccourse-basic
코드와 해설을 함께 읽는 학습 문서
Code Detail
Data I/O 중심의 Octave 학습 예제
course/basic/load_mesh.m
코드를 복사해 Octave에서 바로 실행할 수 있습니다.
function [vert, face] = load_mesh(filename)
31 lines
function [vert, face] = load_mesh(filename)
# read mesh
# intput:
# filename
# output:
# vertex x, y, z
# face v1, v2, v3
fid = fopen(filename, 'r');
vert = [];
face = [];
while ~feof(fid)
line = strtrim(fgetl(fid));
if isempty(line) || startsWith(line, '#')
continue;
end
tokens = strsplit(line);
if strcmp(tokens{1}, 'v')
vert(end+1, :) = str2double(tokens(2:4));
elseif strcmp(tokens{1}, 'f')
face(end+1, :) = str2double(tokens(2:4));
end
end
fclose(fid);
end