Power Tools from 2.49 to 2.5x (HELP)

Hi , I’m using the official script of Octane Render Power Tools to export the blender camera to an TXT file to be loaded in that program, the official script is working fine in 2.49 but not in 2.5x, could somebody have a look to that script to see if it’s possible to migrate to 2.5x???, here’s the file:

http://www.megaupload.com/?d=Q178A4AR

Thanks in advance.

See here:
http://www.octanepowertools.com/content/blender-25-script

I know, that was me asking in the Power tools forum hehehe, and as you can see I come here for help because the developers are busy with other scripts at the moment.

Hi,
does not look so difficult to convert.
(maybe I have time to look at it tomorrow)

Any luck PKHG?

no and yes, I looked at the old script and partly I know how to convert, one thing is not yet totally clear, but I think, that one wants to
save the camera setting while the camera is moving etc from some frame to the end(frame) … right?
Though I can see the change of the world matrix … I haven’t find out how to access these values with Python … (should be possible).
What I eventually need are two things … a .blend where the camera moves and the correspoing output which is expected …
I am someone who needs a ‘Vorbild’(example)
… but my attention is at this moment the Ivy-generator ;-(

So the needed ‘knoff hoff’ is probably this peace of code:


import bpy

obj = bpy.context.active_object
#the fcurves of animated 
try:
    ca = obj.animation_data.action.fcurves
    print(len(ca))
    fLocations = []
    for fcu in ca:
        #possible values: location, scale, rotation_euler
        if fcu.data_path ==  'rotation_euler': #'location':
            fLocations.append(fcu)
    print(fLocations)        

    from mathutils import Vector        
    listOfLocations =[]
#the Api knoff hoff is evaluate(frame_number) !!!
    for i in range(1,11):
        tmp = [el.evaluate(i) for el in fLocations]
        #print(tmp)
        listOfLocations.append([i,Vector(tmp)]) # i is the frame number!!!

    for el in listOfLocations:
        print(el)
except:
    print("ERROR, not an animated object selected")            

It looks like I have solved all problems … now converting ;-), afterwards there are small wishes … to set
(which frame-range e.g. in the original it looked like adjustable via Draw …, what I did not see in 2.49?)

So this is to be checked …
Animate a camera in 2.49 and use old octam …

Animate the camera in 2.58 the SAME! way.
put the code into a text of blender and execute see file(NEWOctaneCamera.txt) and console
compare if ok!


#PKHG octane_pkhg.py, no warranty, change as you wish 4 aug 2011 version 0.1

#import Blender
#from Blender.BGL import *
#from Blender import Mesh, Scene, Window, sys, Image, Draw, Material, Mathutils, Ipo
import bpy
#import BPyMesh
#import BPyObject
#import BPySys
#import BPyMessages
from sys import *
import os, subprocess
from string import *

from mathutils import Vector, Matrix, Euler
from math import degrees
print("=========================pkhg=======")    

scene= bpy.context.scene

#???ostype = platform
GLOBALS = {}
defaultDir=''
blendFileName=''


## an gui exporter needed???? PKHG TODO

#octaneCameraMotion=Draw.Create(0)
#octaneNativeUnitSize=Draw.Create(3)
#octaneActiveCamera=Draw.Create('')
#octaneAnimationStart=Draw.Create(1)
#octaneAnimationEnd=Draw.Create(250)
#octaneAnimationStep=Draw.Create(1)



'''
def matrix_vect(mat,vec):
    vecr = [0.,0.,0.,0.,0.]
    for i in range(4):
        for j in range(4):
            vecr[i] += vec[j] * mat[j][i] 
    return vecr
'''
def matrix_vect(mat,vec):
    return mat * Vector(vec)

def rotate90x(vect):
    return Vector([vect[0],vect[2],-vect[1]]) #PKHG ???
    

#######3#rotation and location assumed to exist! check it the animation ! PKHG
def buildWorldMatrix(fcurves,frame):
    fRotation = []
    for fcu in fcurves:         
        if fcu.data_path ==  'rotation_euler': #'location':
            fRotation.append(fcu)
    fLocation = []            
    for fcu in fcurves:         
        if fcu.data_path ==  'location': #'location':
            fLocation.append(fcu)
    position = Vector([fLocation[0].evaluate(frame), fLocation[1].evaluate(frame), fLocation[2].evaluate(frame),1])
    euler = Euler([fRotation[0].evaluate(frame), fRotation[1].evaluate(frame), fRotation[2].evaluate(frame)])    
    meu = euler.to_matrix()
    meu4 = meu.to_4x4()
    meu4[3]= position
    return(meu4)

octaneNativeUnitSize = 3
def write_command(filename,scene_frames):
    file = open(filename,"w")
#    print("dbg file = ", file)
    #Set the unit factor
    unitFactor = {
        0:0.001,
        1:0.01,
        2:0.1,
        3:1,
        4:10,
        5:100,
        6:1000,
        7:0.0254,
        8:0.3048,
        9:0.9144,
        10:201.168,
        11:1609.344               
#pkhg    }[octaneNativeUnitSize.val]
    }[octaneNativeUnitSize]        
#    scene_frames = xrange(octaneAnimationStart.val, octaneAnimationEnd.val+1,octaneAnimationStep.val) 
#    scene_frames = 10 #test from 1 to 21 #now parameter! PKHG
    camera_param = ''
#not needed???    axes = ['x','y','z']
#    octaneActiveCamera.val=Scene.GetCurrent().getCurrentCamera().getName()
#pkhg ???        
    
        
    camera = bpy.data.objects['Camera'] #??? Blender.Object.Get(octaneActiveCamera.val)
#    camera = scene.objects.camera#Scene.GetCurrent().getCurrentCamera()
#    print(dir(camera))
    
    angle = degrees(camera.data.angle) #WAS radians??!! Check PKHG!
    
    
    ######################################3
    cameradata = camera.animation_data.action.fcurves     
 
    for frame in range(scene_frames): # in scene_frames ???
#        Blender.Set('curframe', frame)
#        cameradata = camera.getData()
        
#        matrix = camera.mat
#        matrix = camera.matrix_world
        
        matrix = buildWorldMatrix(cameradata, frame)
        position = rotate90x(matrix_vect(matrix,[0.0,0.0,0.0,1.0]))
#        print("position", position)

        target = rotate90x(matrix_vect(matrix,[0.0,0.0,-1.0,1.0]))
        up = rotate90x(matrix_vect(matrix,[0.0,1.0,0.0,0.0]))
        
        for i in range(3):
            camera_param += "#%f" % (position[i]*unitFactor)
        for i in range(3):
            camera_param += "#%f" % (target[i]*unitFactor)
        camera_param += "#%f" % angle #???????????cameradata.angle CHECK! PKHG
        for i in range(3):
            camera_param += "#%f" % (up[i]*unitFactor)            
            
        new=camera_param.replace('#', '', 1)
        file.write(new)
        file.write("
")
        print("new",new) # see console! pKHG
        camera_param = ""
        
    file.close()            
                                
octcam = 'NEWOctaneCamera.txt'
write_command(octcam, 3) #Three frames  change?! PKHG

Hi Peter, what a work you’re doing… wow! thanks mate! :slight_smile: , when I try to run the last code you put here I got an error and no longer works, I’m using 2.58 (official build), does it works for you? what version are you using?

This is the error I got:

=========================pkhg=======
Traceback (most recent call last):
File “C:\Users\Sam\Desktop\OctanePowerTools\example est249.blend\Text.001”, l
ine 139, in <module>
File “C:\Users\Sam\Desktop\OctanePowerTools\example est249.blend\Text.001”, l
ine 116, in write_command
File “C:\Users\Sam\Desktop\OctanePowerTools\example est249.blend\Text.001”, l
ine 47, in matrix_vect
TypeError: Matrix multiplication: not supported between ‘mathutils.Matrix’ and ’
mathutils.Vector’ types

Oh, I compile nearly every morning so the SVN is already 39006 …
but you should give the error-message (otherwise start Blender from a REAL command window, to see the error message)

The Camera should really be animated! … (not reading an existing one bur fresh done!)
If I read the result of your 2.49 example it does not work in 2.58 (the script) it is known that animation of a 2.49 .blend may not work in 2.58
(though Alt A seems to work) …

That looks like a too old version of Blender, the order of … has been changed in the API meanwhile … :wink:

I just tried with a new version and wow… it really works, I tried with the test file and I get only 3 lines while in 2.49 script I got several lines, apart of that looks like your script is having the second line repeated:

7.481132#5.343665#6.507640#6.826270#4.898420#5.896974#49.134342#-0.317370#0.895343#-0.312469
7.481132#5.343665#6.507640#6.826270#4.898420#5.896974#49.134342#-0.317370#0.895343#-0.312469
7.396554#5.341011#6.521340#6.746758#4.895683#5.905345#49.134342#-0.314904#0.895303#-0.315068

and here’s the first lines of the original:

7.481132#5.343665#6.507640#6.826270#4.898420#5.896974#49.134342#-0.317370#0.895343#-0.312469
7.396554#5.341011#6.521340#6.746758#4.895683#5.905345#49.134342#-0.314904#0.895303#-0.315068
7.153456#5.332986#6.562666#6.518921#4.887411#5.931138#49.134342#-0.307481#0.895182#-0.322652
6.768388#5.319578#6.631567#6.159587#4.873587#5.975476#49.134342#-0.294973#0.894979#-0.334669
6.258650#5.300897#6.727330#5.686437#4.854329#6.039472#49.134342#-0.277194#0.894697#-0.350260
5.642218#5.277221#6.848423#5.117697#4.829921#6.123992#49.134342#-0.254011#0.894337#-0.368293
4.937653#5.249022#6.992343#4.471796#4.800851#6.229375#49.134342#-0.225462#0.893908#-0.387422
4.164012#5.216987#7.155538#3.767042#4.767828#6.355119#49.134342#-0.191873#0.893419#-0.406187
3.340745#5.182019#7.333422#3.021368#4.731781#6.499585#49.134342#-0.153930#0.892883#-0.423162

Thanks again, it’s an amazing work, I thougt it would be easier to adapt the original code :-S

I have a parameter in twrite_command(octcam, 3) #Three frames change?! PKHG

The 3 (at the end of the script) should be changed to what you wish.

In principle it was only the contruction of the world_matrix … which was ‘difficult’ … if one has to see what
is done …

he script, the number of frames you want to get …(no GUI yet to set ) …

The line twice … may be because you did not start the animation at the same point??
maybe check further …