Everything related to SDK.
By d76
#364391
Hi
I have a test scene with just a camera.

Image

When i run this code:
Code: Select all
#!/Library/Frameworks/Python.framework/Versions/3.2/bin/python3
# -*- coding: utf-8 -*-

from pymaxwell import *

def main():
	scene = Cmaxwell(mwcallback)
	scene.readMXS("camera.mxs")
	camera = scene.getActiveCamera()
	step = camera.getStep(0)
	print(step[3]*1000.0)

if __name__ == "__main__":
	main()
I get 33.81642509082491 instead 35.0.

Is it a bug? Or is something wrong with my code..

Thanks.
User avatar
By Brany
#364403
Maxwell SDK can do a correction to the focal length depending on the focal point and the camera position. It's done always by default.

You can avoid that correction (better not) if you want setting the camera step at python with CmaxwellCamera.setStep(), setting the "focalLengthNeedCorrection" parameter to 0 (and the focal length you want to force).
Code: Select all
from pymaxwell import *

scene = Cmaxwell(mwcallback);
scene.readMXS("d:/camera.mxs")
camera = scene.getCamera("Camera")
if not camera.isNull():
	step = camera.getStep(0)
	print "corrected by default:"
	print step[3]
	camera.setStep(0,step[0],step[1],step[2],[b]0.035[/b],step[4],step[5],[b]0[/b])
	step_new = camera.getStep(0)
	print "without correction:"
	print step_new[3]
Result:
corrected by default:
0.0348487142144
without correction:
0.035

Anyway, we have to review how to handle this parameter from the SDK. By now, assume that the corrected value is right. If you need code to un-correct the focalLenght in order to retrieve the original value, I can post it.

So, there is no bug or something wrong in your code, simply maxwell do a correction to this parameter internally.
By d76
#364409
Ah alright, I think I can understand it. My camera was focused on a very close point.
Please post the code, because what I am trying to do, is to read camera back from scene. I modified camera a bit in Studio and now I'd like to make some wire renders from the same angle as final renders..
Thanks
User avatar
By Brany
#364413
The thing is: you want to do the following?:
Code: Select all
scene.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 all
from 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")
By d76
#364415
I'm sorry, I think I wasn't clear in what I want to do.. basically it is the following:
Code: Select all
1 read final mxs
2 get camera
3 write its values to template .py file
4 run in blender to setup camera inside original scene
5 render wireframe
6 put to portfolio
but with your uncorrected focal length code I will be able to do it..

Thanks a LOT!

...and 3 Days later, 82.528 Views !!! ...NL, every[…]

Hello dear customers, We have just released a new[…]

grass generator extension

Just downloaded MWR5 for Rhino 6 and want to use g[…]

Hello everyone, I have a new bug with the latest M[…]