The thing is: you want to do the following?:
Code: Select allscene.readMXS(...)
...
stepdata = camera.getStep(...)
# modify step data
...
camera.setStep(...,stepdata[0],....,stepdata[5])
...
scene.writeMXS(...)
In that case, the important thing is that if you have to do a setStep() you have to take into account that the focalLength retrieved by getStep() has a correction, so if you will do a setStep() using the values that getStep() gaves you, you must tell setStep() that the focal length does not have to be corrected (it cames corrected already from the MXS generated by your 3D platform), and you can do it by passing an optional parameter to setStep() called ''focalLengthNeedCorrection". Its value is "1" by default, but if you have a corrected focal length already, you have to use "0" instead of "1":
camera.setStep(0,step[0],step[1],step[2],step[3],step[4],step[5],
0)
The following code explains hou to "un-correct" the focal length among other things, but I don't reccomend you to "un-correct" the value, unless you have to get back the original value in order to show it (i.e.). The code can helps you to understand that issue, or maybe make it more messy...:
Code: Select allfrom pymaxwell import *
scene = Cmaxwell(mwcallback);
scene.readMXS("d:/camera.mxs")
camera = scene.getCamera("Camera")
if not camera.isNull():
step = camera.getStep(0)
focalLengthCorrected = step[3]
print "focal length (corrected by default):"
print focalLengthCorrected
# Un-correct focal length
origin = step[0]
focalPoint = step[1]
dir = Cvector()
dir.substract(focalPoint,origin)
focalDistance = dir.norm()
focalLengthUnCorrected = 1.0 / ( 1.0 / focalLengthCorrected - 1 / focalDistance )
print "un-do focal length correction:"
print focalLengthUnCorrected
# Set focal length without applying correction
# WARNING: CmaxwellCamera.setStep() last parameter 'focalLengthNeedCorrection'
# is '1' by default. Use '0' in case you know what you are doing: i.e. setting
# camera step from values obtained in a previous getStep() call
# Maxwell Studio will "un-correct" the focal length ALWAYS to show the
# value in the camera panel, so be careful because if the
# focal length is "un-corrected" already by the user, it will introduce errors
# on the camera focus
camera.setStep(0,step[0],step[1],step[2],0.035,step[4],step[5],0)
step_new = camera.getStep(0)
focalLengthNew = step_new[3]
print "set without correction:"
print focalLengthNew
print ""
print "WARNING: get->set camera step with correction over and over is not correct!:"
for i in range(20):
step = camera.getStep(0)
camera.setStep(0,step[0],step[1],step[2],step[3],step[4],step[5])
step = camera.getStep(0)
print step[3] # focal length
# Set camera focal length to 0.030 with correction (default and recommended)
# to do the following example
print ""
print "setting focalLengt to 0.030 meters"
camera.setStep(0,step[0],step[1],step[2],0.030,step[4],step[5])
# The correct way to get->set the camera is this
print ""
print "right way to set focal length from previous getStep call data:"
print "get original focal length (0.030 with correction):"
step = camera.getStep(0)
print step[3]
# 'step' has the 'focalLength' parameter already corrected!
# ALL MXS SCENES from Maya, Studio, etc. will have the correction applied.
# Modify camera position or whatever
# ...
# and then set the camera step, but without applying correction
# since getStep() give us the already corrected value
camera.setStep(0,step[0],step[1],step[2],step[3],step[4],step[5],0) # <--- NO CORRECTION! ;)
step = camera.getStep(0)
print "saved focal length after read it:"
print str(step[3])+" <- no changes :)"
scene.writeMXS("d:/camera_corrected.mxs")