File: readobjmesh.m

package info (click to toggle)
octave-iso2mesh 1.9.8%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 11,128 kB
  • sloc: cpp: 11,982; ansic: 10,158; sh: 365; makefile: 59
file content (27 lines) | stat: -rw-r--r-- 833 bytes parent folder | download
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
function [node, face] = readobjmesh(fname)
%
% [node,face]=readobjmesh(fname)
%
% read Wavefront obj-formatted surface mesh files (.obj)
%
% author: Qianqian Fang, <q.fang at neu.edu>
%
% input:
%    fname: name of the .obj data file
%
% output:
%    node: node coordinates of the mesh
%    face: list of elements of the surface mesh
%
% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
%

str = fileread(fname);
nodestr = regexp(str, 'v\s+([0-9.\-e]+\s+[0-9.\-e]+\s+[0-9.\-e]+)', 'tokens');
nodestr = [nodestr{:}];
node = sscanf(sprintf('%s ', nodestr{:}), '%f %f %f', [3, inf])';
facestr = regexp(str, 'f\s+(\d+(/\d+)*\s+\d+(/\d+)*\s+\d+(/\d+)*)', 'tokens');
facestr = [facestr{:}];
facestr = sprintf('%s ', facestr{:});
facestr = regexprep(facestr, '/\d+', '');
face = sscanf(facestr, '%d %d %d', [3, inf])';