Boujou

I have boujou tracking data in a text document that I am trying to import into blender via this script:

Simple script used for importing camera tracking data generated by BouJou4

BouJou4 will not export to Blender, though it will export to a text file.

This script will read that file.

Mon 15 Oct 2007 - Simon Beeching (enhzflep)

import Blender;
from Blender import Camera, Object, Scene, NMesh
from Blender import Mathutils
from Blender.Mathutils import *
print ‘-------------------------------------------------------’
print ‘------------- BouJou4 import script v0.0 --------------’
print ‘-------------------------------------------------------’

declaration of function used to load the file

def myLoader(fileName):
file = open(fileName, ‘r’);
i = 1;
readVerts = False;
readCam = False;
numFrames = 0;
for curLine in file.readlines():

check for correct file header.

if it’s not found, print an error and exit

if (i==1) and (‘boujou export’ not in curLine):
print ‘ERROR: incorrect file header.’
print ‘line #: ‘+str(i)
print ’ - expecting “# boujou export: text”’;
print ’ - found "’+curLine+’"’;
file.close();
break;

################################################## ##############################

Camera loading code

################################################## ##############################

if we find the string that signifies the end of the file,

change our flag to false - we can’t read nothing!!

if (readCam == True):
coOrds = curLine.split()
if (len(coOrds) == 0):
readCam = False;
print(’(’+str(i)+’): Found end of camera block’);
allObj = Object.Get()
for curObj in allObj:
if curObj.name[:10]==‘boujou_tmp’:
cur.unlink(curObj);

CAMERA FRAME DATA FOUND!!

else:

set the camera rotation/translation matrix

rX = [float(coOrds[0]), float(coOrds[1]), float(coOrds[2]), 0.0];
rY = [float(coOrds[3]), float(coOrds[4]), float(coOrds[5]), 0.0];
rZ = [float(coOrds[6]), float(coOrds[7]), float(coOrds[8]), 0.0];
tR = [float(coOrds[9]), float(coOrds[11])*-1.0, float(coOrds[10]), 1.0];
tmpObj.setMatrix(Mathutils.Matrix(rX, rY, rZ, tR));

set the lens

tmpCam.lens = float(coOrds[12]);

add point(keyframe) for camera position IPOs

locx.addBezier((numFrames+1, tmpObj.LocX))
locy.addBezier((numFrames+1, tmpObj.LocY))
locz.addBezier((numFrames+1, tmpObj.LocZ))

add point(keyframe) for the camera rotation IPOs

rotx.addBezier((numFrames+1, (tmpObj.RotX18/3.141593)-9))
roty.addBezier((numFrames+1, -1.0
tmpObj.RotZ18/3.141593))
rotz.addBezier((numFrames+1, 1.0
tmpObj.RotY*18/3.141593))

add point on IPO curve for lens (focal distance)

lenscurve.addBezier((numFrames+1, tmpCam.lens))

increment the index used for setting IPOs to point to next frame

numFrames += 1;

CAMERA BLOCK FOUND!!

if ‘#R(0,0)’ is found, then we have the start of the vertex data

if (’#R(0,0)’ in curLine):
print( ‘(’ +str(i) +’): Camera data found in export file’);
readCam = True; # set flag to indicate we’re in a camera block
cRend = Camera.New(‘persp’);
cRend.lens = 35.0
cRend.setDrawSize(1.0);
oRend = Object.New(‘Camera’);
oRend.name = ‘BouJou_Cam’
oRend.link(cRend);
cur = Scene.GetCurrent();
cur.link(oRend);
cur.setCurrentCamera(oRend);
ipo = Blender.Ipo.New(‘Object’, ‘render_cam_objipo’);
oRend.setIpo(ipo);

create the ipo curves that we’ll be needing

locx = ipo.addCurve(‘LocX’)
locx.setInterpolation(‘Linear’)
locy = ipo.addCurve(‘LocY’)
locy.setInterpolation(‘Linear’)
locz = ipo.addCurve(‘LocZ’)
locz.setInterpolation(‘Linear’)
rotx = ipo.addCurve(‘RotX’)
rotx.setInterpolation(‘Linear’)
roty = ipo.addCurve(‘RotY’)
roty.setInterpolation(‘Linear’)
rotz = ipo.addCurve(‘RotZ’)
rotz.setInterpolation(‘Linear’)
camipo = Blender.Ipo.New(‘Camera’,‘render_cam_camipo’)
cRend.setIpo(camipo)
lenscurve = camipo.addCurve(‘Lens’)
lenscurve.setInterpolation(‘Linear’)

create the temporary camera that is used to convert our camera matrix

into rotation and translation figures. This dummy camera also holds the

lens info. This temp camera is needed to create the IPO curves

tmpCam = Camera.New(‘persp’);
tmpCam.lens = 35.0;
tmpObj = Object.New(‘Camera’);
tmpObj.name = ‘boujou_tmp’
tmpObj.link(tmpCam);
cur.link(tmpObj);

################################################## ##############################

Vertex loading code

################################################## ##############################

if we find the string that signifies the end of the file,

change our flag to false - there’s nothing left to read

if (’#End of boujou export file’ in curLine):
print( ‘(’ +str(i) +’): Found end of boujou export file’);
readVerts = False;
mesh.update()
cur.update()

if we’re currently allowed to read vertex positions, then

split the line up into individual ‘words’ - putting the first 3

into a 3 element array used to hold 1 point

if (readVerts==True):
coOrds = curLine.split();
if len(coOrds):
x = float(coOrds[0]);
y = float(coOrds[1]);
z = float(coOrds[2]);
v = NMesh.Vert(x, -z, y)
mesh.verts.append(v);

if ‘#x y z’ is found, then we have the start of the vertex data

(the x, y and x are all separated with tab characters ( ))

if (’#x y z’ in curLine):
readVerts = True;
ob = Object.New(‘Mesh’, ‘BouJouData’)
ob.setLocation(0.0, 0.0, 0.0)
mesh = ob.getData();
cur = Scene.getCurrent()
cur.link(ob)
print( ‘(’ +str(i) +’): Vertex data found in export file’);
################################################## ########################

increment the file’s line counter

i += 1;
########### End of loop performed on each lie of the file ################
print ‘Total of ‘+str(numFrames)+’ frames tracked.’;
file.close();
##################### End of myLoader(filename) ##############################

Script starts execution here

call function myLoader with the file chosen in a file open dialog

use the string “Import .txt” on the button

Blender.Window.FileSelector(myLoader, “Import .txt”);

However I keep getting “Python script error, check console” errors when I try to run it in blenders text editor. The consols says “indentation error: expected an indented block”

So I tried to indent all of the lines for which that error came up, then it spat out another error. Any ideas?

Had you used the search feature you would have found the script with the indentation intact.

I would like to strangle the insane idiot who invented an indentation based language like python!:spin:

Why, why choose that delimiter. It gets mangled so often.

Luckily they have seen the light!

from __future__ import braces

:wink:

Thanks, that seems to work.
The lens distortion is wierd and it doesn’t match up nearly as well as the test object in boujou does, but those are seperate issues.