[code] 3ds2obj.rb
-
-
It appears there is a CAMERA chunk (0x4700), so if you can't find the format for that chunck, then you should be able to dump the chunk and view it in a hex editor to see if it can be deciphered.
So once the chuck is identified, it is followed by its length. this line gives you the number of bytes to read the rest chunk:
when 0x4700 puts "# CAMERA DATA" # NOT sure of the proper way to unpack? chunk_len = f.read(2).unpack('s')[0] chuck_len.times do # something? end next
-
Whoops, check that command-line example I gave for usage - I changed it.
$ 3ds2obj.rb model.3ds > model.obj
-
getting closer..
* 4700 - Camera Describes the details of the camera in the scene start end size type name 0 3 4 float Camera pos X 4 7 4 float Camera pos Y 8 11 4 float Camera pos Z 12 15 4 float Camera target X 16 19 4 float Camera target X 20 23 4 float Camera target X 24 27 4 float Camera bank ( rotation angle ) 28 31 4 float Camera lens
-
I see , the camera is a fixed-length chuck so has no length - you just start reading the values:
when 0x4700 puts "# CAMERA DATA" xpos = f.read(4).unpack('f')[0] puts "xpos;#{xpos}" ypos = f.read(4).unpack('f')[0] puts "ypos;#{ypos}" zpos = f.read(4).unpack('f')[0] puts "zpos;#{zpos}" next
Although strangely the values are close but not exact as:
Sketchup.send_action(10624)
-
Ah, I see. It's a standalone ruby - not a SU ruby. have not looked at the code yet.
28 31 4 float Camera lens
- what would this be then? -
@jim said:
I see , the camera is a fixed-length chuck so has no length - you just start reading the values:
when 0x4700 > puts "# CAMERA DATA" > xpos = f.read(4).unpack('f')[0] > puts "xpos;#{xpos}" > ypos = f.read(4).unpack('f')[0] > puts "ypos;#{ypos}" > zpos = f.read(4).unpack('f')[0] > puts "zpos;#{zpos}" > next
Although strangely the values are close but not exact as:
Sketchup.send_action(10624)
would this not be doing the same?
xpos, ypos, zpos = f.read(12).unpack('fff')
a one-liner.
-
@jim said:
Although strangely the values are close but not exact as:
How close? Minor - something that could be explained by floating precision?
-
@thomthom said:
would this not be doing the same?
xpos, ypos, zpos = f.read(12).unpack('fff')Maybe - I'm in "make it work" mode. Optimize mode comes later.
-
Yeah, that's pretty much all there is to it. Make sure to read all the values; you can't skip them even if you don't use them.
I made a mistake when I said the values did not match - it works out no problem.
when 0x4700 puts "# CAMERA DATA" xpos, ypos, zpos = f.read(12).unpack('fff') puts "eye; (#{xpos}, #{ypos}, #{zpos})" tx, ty, tz = f.read(12).unpack('fff') puts "target(#{tx}, #{ty}, #{tz})" rotation = f.read(4).unpack('f')[0] puts "#rotation;#{rotation}" lens = f.read(4).unpack('f')[0] puts "#lens;#{lens}" next
-
@jim said:
Yeah, that's pretty much all there is to it. Make sure to read all the values; you can't skip them even if you don't use them.
Because of variable chunk length?
@jim said:
I made a mistake when I said the values did not match - it works out no problem.
You managed to recreate an SU camera?
What's the lens value? AOV? FOV?
Advertisement