Skip to content

Instantly share code, notes, and snippets.

@aescripts
Created June 8, 2018 14:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aescripts/3de0a3aaabe869a4966c90b4200d26fe to your computer and use it in GitHub Desktop.
Save aescripts/3de0a3aaabe869a4966c90b4200d26fe to your computer and use it in GitHub Desktop.
Will read an OBJ file and create After Effects nulls for every vertex #AfterEffects #Script #KBar #OBJ #Nulls
// objFile vertices to AE Nulls
// © 2018 Lloyd Alvarez https://aescripts.com/
//
// Select a comp first then run the script and select the OBJ file
//
objFile_vertices_to_AE_Nulls();
function objFile_vertices_to_AE_Nulls () {
var objFile = File.openDialog("Please choose OBJ file");
if (!objFile) return;
if (!(objFile instanceof File) || !objFile.name.toLowerCase().match(/\.obj$/)) {
alert ("Please make sure it's an objFile file with a .obj file extention")
return;
}
var myComp = app.project.activeItem;
if (!(myComp instanceof CompItem)) {
alert("Please select a comp to generate the nulls into");
return;
}
if(objFile.open("r")) {
var obj = objFile.read();
objFile.close();
var objLines = obj.split(/\r?\n/);
var coords = [];
var myNull;
var vertexArray = [];
for (var i=0; i<objLines.length; i++) {
if (objLines[i].match(/^v\s/)) {
coords = objLines[i].replace(/^v\s/,"").split(/\s/);
if (coords.length == 3) {
vertexArray.push(coords);
}
}
}
if (vertexArray.length > 0) {
app.beginUndoGroup("objFile vertices to AE Nulls");
var parentNull = myComp.layers.addNull();
parentNull.name = objFile.displayName;
parentNull.threeDLayer = true;
parentNull.position.setValue( [myComp.width/2,myComp.height/2] );
for (var i=0; i<vertexArray.length; i++) {
writeLn("Creating null "+(i+1)+" of "+(vertexArray.length));
myNull = myComp.layers.addNull();
myNull.threeDLayer = true;
myNull.parent = parentNull;
myNull.position.setValue(vertexArray[i]);
}
}
parentNull.moveToBeginning();
app.endUndoGroup();
} else {
alert ("There was an error reading the obj file");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment