Skip to content

Instantly share code, notes, and snippets.

@Ravenstine
Last active September 12, 2016 16:00
Show Gist options
  • Save Ravenstine/a6c3a5ea682068c51bc4d0fdb97f7f27 to your computer and use it in GitHub Desktop.
Save Ravenstine/a6c3a5ea682068c51bc4d0fdb97f7f27 to your computer and use it in GitHub Desktop.
const fs = require('fs');
process.stdin.setEncoding('utf8');
var capturing, frame, melCode, triangles, trimatcher;
trimatcher = /<glTri>\s(\-*\d+\.\d+)\s(\-*\d+\.\d+)\s(\-*\d+\.\d+)\s(\-*\d+\.\d+)\s(\-*\d+\.\d+)\s(\-*\d+\.\d+)\s(\-*\d+\.\d+)\s(\-*\d+\.\d+)\s(\-*\d+\.\d+)\s(\-*\d+\.\d+)\s(\-*\d+\.\d+)\s(\-*\d+\.\d+)/
var euclidianizeVertex = function(w, x, y, z){
return {
x: x/w,
y: y/w,
z: z/w
}
}
var initVars = function(){
capturing = false;
frame = ""; // acts as a buffer for our lines
triangles = {}; // this is used as a distinct array
melCode = `
createNode transform -n "playerCam";\n
setAttr ".t" -type "double3" 1.7575689290363643e-15 0 -14.351639429916055 ;\n
setAttr ".r" -type "double3" 0 180 -5.172681101354183e-14 ;\n
createNode camera -n "playerCamShape" -p "playerCam";\n
setAttr -k off ".v";\n
setAttr ".rnd" no;\n
setAttr ".cap" -type "double2" 0.94488 0.94488 ;\n
setAttr ".ovr" 1.3;\n
setAttr ".fl" 10.804840730034487;\n
setAttr ".coi" 59.173509091945995;\n
setAttr ".imn" -type "string" "persp1";\n
setAttr ".den" -type "string" "persp1_depth";\n
setAttr ".man" -type "string" "persp1_mask";\n
setAttr ".hc" -type "string" "viewSet -p %camera";\n
setAttr ".dr" yes;\n
`
}
var correctX = function(x){
return parseFloat(x) * -1.0;
}
process.stdin.on('data', (data) => {
if(capturing){
frame += `${data}`;
}
});
process.on("SIGINT", () => {
// SIGINT is how we can toggle this process.
if(capturing){
capturing = false;
frame.split("\n").forEach((line)=>{
var triangle = line.match(trimatcher);
if(triangle){
triangle.shift() // first match result is the whole line
triangles[triangle] = undefined
}
})
var count = 0;
Object.keys(triangles).forEach((triangle)=>{
count++;
var coords = triangle.split(",")
melCode += `polyCreateFacet -ch on -tx 1 -s 1 -p ${correctX(coords[1])} ${coords[2]} ${coords[3]} -p ${correctX(coords[5])} ${coords[6]} ${coords[7]} -p ${correctX(coords[9])} ${coords[10]} ${coords[11]} ;\n`
})
console.log(`${count} triangles captured`)
fs.writeFile("./out.mel", melCode, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
console.log("CAPTURING DISABLED");
} else {
initVars();
capturing = true;
console.log("CAPTURING ENABLED");
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment