Blender camera...- never mind. fixed.


(infurno) #1

Could someone please take a look at this short python script and possibly recommend a fix?

I am working on a short film where i am using a combination of blender and terragen. I understand there are plenty of ter2blend topics but my search found nothing about the python script that interprets terragen camera animation script files.

Im using python 2.3, blender 2.37, Ter2Blendv4p, windows xp

I think i did do everything correctly but i get the following output in my console window:
http://www.buysmartpc.com/blenderscreen2.JPG

Here is the python script for the camera animation:

#################################################################
# #
# Ter2Blend  v3   CAMERA                                        #
# #
# Terragen's terrain file to Blender file converter #
# #
# copyright (c) 2001  Guy Van Rentergem #
# #
# email: [email protected]                  #
# #
#################################################################




# Terragen script file
# --------------------
#
# script commands usefull for Ter2Blend:
#   InitAnim BaseName, StartFrame - only use for StartFrame, the first frame to rendered
#   CamPos x,y,z - sets the camera's position in Terrain Units
#   TarPos x,y,z - sets the target's position in Terrain Units
#   CamH head - sets the camera's heading in degrees
#   CamP pitch - sets the camera's pitch in degrees
#   CamB bank - sets the camera's bank in degrees
#   SunDir head, alt - sets the heading and altitude of the sun in degrees (next version)
#   FRend - renders a frame
#
# Forbidden script commands in Ter2Blend:
#   Zoom z - sets the Zoom value
#   Exp e - sets the Exposure value
#
# Useless script commands in Ter2Blend:
#   CloudPos x,y
#   CloudVel Speed, Heading

### MOD by pat
### all changes marked like this one
###
### list of changes:
### import glob commented
### banking error solved: divide by 60
#################################################################

import Blender
import string
from math import *
import os #,glob
from os import path,name,sep


camera = Blender.link


filename=Blender.Get('filename')
lpath,lname=os.path.split(filename)

tgsfile = lpath+r"	er2blend.tgs"
try:
tgs=open(tgsfile, 'r')
except IOError:
print tgsfile + " does not exist!"
else:
blenderframe = Blender.Get("curframe")
print 'frame: ', blenderframe

CamPosCount = 0
TarPosCount = 0
CamHCount = 0
CamPCount = 0
CamBCount = 0
FRendCount = 0
CamB = 0

while 1:
line = tgs.readline()
line = string.lower(line)
line = string.replace(line,' ',',')

if string.find(line, 'initanim') > -1:
k=string.rfind(line, ',')
tgsstartframe = line[k+1:]

if string.find(line, 'campos') > -1:
CamPosCount=CamPosCount+1
if CamPosCount == blenderframe:
L1 = string.split(line,',')
CamPosX = string.atof(L1[1])
CamPosY = string.atof(L1[2])
CamPosZ = string.atof(L1[3])

if string.find(line, 'tarpos') > -1:
TarPosCount=TarPosCount+1
if TarPosCount == blenderframe:
L1 = string.split(line,',')
TarPosX = string.atof(L1[1])
TarPosY = string.atof(L1[2])
TarPosZ = string.atof(L1[3])

ly = sqrt((TarPosY-CamPosY)**2)
lp = sqrt((TarPosX-CamPosX)**2+(TarPosY-CamPosY)**2)
lt = sqrt((TarPosX-CamPosX)**2+(TarPosY-CamPosY)**2+(TarPosZ-CamPosZ)**2)

if CamPosZ > TarPosZ:
CamP =  pi/2 +(-acos(lp/lt))
else:
CamP =  pi/2 +(acos(lp/lt)) 

if CamPosX < TarPosX:
if CamPosY < TarPosY:
CamH = -acos(ly/lp)
else:
CamH = -(pi - acos(ly/lp))

else:
if CamPosY < TarPosY:
CamH = acos(ly/lp)
else:
CamH = pi - acos(ly/lp)


if string.find(line, 'camh') > -1:
CamHCount=CamHCount+1
if CamHCount == blenderframe:
L1 = string.split(line,',')
CamH = string.atof(L1[1])

if string.find(line, 'camp') > -1:
CamPCount=CamPCount+1
if CamPCount == blenderframe:
L1 = string.split(line,',')
CamP = string.atof(L1[1])

if string.find(line, 'camb') > -1:
CamBCount=CamBCount+1
if CamBCount == blenderframe:
L1 = string.split(line,',')
CamB = string.atof(L1[1])

if string.find(line, 'frend') > -1:
FRendCount=FRendCount+1
if FRendCount == blenderframe:
break

if not line: 
break # exit loop on end-of-file

camera = Blender.Object.Get("Camera")
print dir(camera)
camera.LocX = CamPosX
camera.LocY = CamPosY
camera.LocZ = CamPosZ
camera.RotX = CamP
camera.RotY = CamB / 60. ### 60:tested value
camera.RotZ = CamH

tgs.close()

#########################END OF CODE##############################

And finally an example of the structure from the teragen animation script file:

initanim,"c:\anim\anim",0
;framenum,0
campos,5.000000000000,48.000000000000,17.489173936873
tarpos,6.000000000000,48.000000000000,5.864553968307
camb,0.000000005016
frend
;framenum,1
campos,5.187293667539,47.930150426082,17.482608379146
tarpos,6.228875137597,47.918264184399,5.858920333822
camb,-0.000316974246
frend
;framenum,2
campos,5.374586153668,47.860302940492,17.476039196327
tarpos,6.457769085383,47.836553471346,5.853288028137
camb,-0.000633641237
frend
;framenum,3
campos,5.561889995057,47.790454513622,17.469462286654
tarpos,6.686717393915,47.754886948478,5.847657965939
camb,-0.000949738259
frend


(infurno) #2

You dont just load and run the script, you use it as a scriptlink. Sorry, i have never heard of or used a script this way.