Skip to content

Instantly share code, notes, and snippets.

@jlewin
Created October 3, 2013 00:15
Show Gist options
  • Select an option

  • Save jlewin/6802585 to your computer and use it in GitHub Desktop.

Select an option

Save jlewin/6802585 to your computer and use it in GitHub Desktop.
Reduce an .obj file to its key components for structure evaluation
var inputPath = @"c:\temp\example.obj";
var outputPath = @"c:\temp\results.txt";
var reader = new System.IO.StreamReader(inputPath);
var output = System.IO.File.CreateText(outputPath);
var v = 0;
var vn = 0;
var f = 0;
string line;
while ((line = reader.ReadLine()) != null)
{
var type = line.Substring(0, 2).Trim();
switch(type) {
case "g":
v = 0;
vn = 0;
f = 0;
break;
case "v":
v++;
if (v > 3) line = null;
break;
case "vn":
vn++;
if (vn > 3) line = null;
break;
case "f":
f++;
if (f > 1) line = null;
break;
case "us":
f = 0;
break;
}
if (line != null)
{
output.WriteLine(line);
}
}
output.Close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment