-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPopPly.js
More file actions
48 lines (39 loc) · 913 Bytes
/
PopPly.js
File metadata and controls
48 lines (39 loc) · 913 Bytes
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
Pop.Ply = {};
Pop.Ply.Parse = function(PlyContents,OnVertex,OnMeta)
{
const PlyLines = PlyContents.split('\n');
if ( PlyLines[0].trim() != 'ply' )
throw "Filename first line is not ply, is " + PlyLines[0];
let HeaderFinished = false;
if ( OnMeta )
{
let Meta = {};
Meta.VertexCount = PlyLines.length;
OnMeta( Meta );
}
Pop.Debug("Parsing x" + PlyLines.length + " lines...");
let ProcessLine = function(Line)
{
Line = Line.trim();
if ( !HeaderFinished )
{
if ( Line == 'end_header' )
HeaderFinished = true;
return;
}
let xyz = Line.split(' ');
if ( xyz.length < 3 )
{
Pop.Debug("ignoring line " + Line, xyz.length);
return;
}
let Floats = xyz.map( parseFloat );
if ( Floats.some( isNaN ) )
{
Pop.Debug("Nan parsed; ignoring line " + Line, ...xyz, ...Floats );
return;
}
OnVertex( ...Floats );
}
PlyLines.forEach(ProcessLine);
}