[Closed] help with camera conversion
hello.
i am trying to create a script for 3ds max to convert a txt file with informations about a camera path in order to create a camera in max. initially i thought that this shouldn’t be too hard for somebody who has no experience in maxscript i stumbled upon a problem: the script doesnt read the camera rotation properly.
each line in the text file contains a frame of the camera in the following format:
pos.x pos.y pos.z pitch yaw roll fov
so for example:
2681.052 303.825 292.543 -358.743 167.726 359.968 120.000
the rotation values go from -360 to +360. this could be the first problem as they might switch from -360 to +360 the next frame.
however it isnt the thing that bothers me the most. the camera seems to be totally off. while the position might be ok (not sure) the rotation certainly isnt. i also have to adapt the y and z position to match the 3ds coordinate system and now im unsure whether this affects the pitch and yaw aswell. i’ve also tried to code a command line application to convert the txt file into a ms file similiar to what boujou outputs. in that app i’ve used quaternions for the rotation, but still no luck.
hopefully somebody could point me in the right direction. thanks in advance.
this is the script:
function doCamera =
(
fileName = getOpenFileName types:"camera(*.cam)|*.cam|All|*.*|"
if ( fileName == undefined ) do return 0
fileStream = openFile(fileName)
if ( fileStream == undefined) do return 0
theCam = freeCamera()
theCam.fov.controller = bezier_float()
theCam.pos.controller = bezier_position()
theCam.rotation.controller = bezier_rotation()
theTime = 0;
while ( not eof(fileStream)) do (
theLine = readLine( fileStream ) as stringstream;
print theLine
posKey = addNewKey theCam.pos.controller theTime
posKey.value = [ readToken(theLine) as float, readToken(theLine) as float, readToken(theLine) as float ]
anglesKey = addNewKey theCam.rotation.controller theTime
anglesKey.value = eulerAngles (readToken(theLine) as float ) (readToken(theLine) as float) (readToken(theLine) as float)
fovKey = addNewKey theCam.fov.controller theTime
fovKey.value = readToken(theLine) as float
theTime = theTime + 1
)
)
doCamera()
From what i gather, you do convert the y to z and z to y in max for the positions. do you then also rotate in the right axis?
as for the rotation being +360 and -360, perhaps you can add a check to see if the next read value is going to be + or -. so you would basically only rotate(or transform) the camera after you’ve read the second line:
1)read first line and store data
2)read second line and compare data
3)transform camera
4)promote second line to first
but im just thinking,… perhaps you need to subtract the new_rotation from the old_rotation and apply the result to the transform. because if you rotate by 300 on frame 1 and by 298 by the next, wouldnt that meant that in 1 frame you do not rotate by 2 degrees, but by 298?