[code] 3ds2obj.rb

[code] 3ds2obj.rb

Postby Jim » Wed Feb 17, 2010 6:14 pm

This is not a plugin - but a rudimentary code snippet that extracts data from a binary .3ds and outputs it to std out.

usage:

$ 3ds2obj.rb model.3ds > model.obj
0
Hi

Jim 
Global Moderator
 

Re: [code] 3ds2obj.rb

Postby thomthom » Wed Feb 17, 2010 6:22 pm

You got hold of file format specs for 3ds?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [code] 3ds2obj.rb

Postby Jim » Wed Feb 17, 2010 6:23 pm

It is readily available online.
0
Hi

Jim 
Global Moderator
 

Re: [code] 3ds2obj.rb

Postby xrok1 » Wed Feb 17, 2010 6:28 pm

thomthom, does it work, does it work?? :bounce:
0
“There are three classes of people: those who see. Those who see when they are shown. Those who do not see.”

http://www.Twilightrender.com try it!

xrok1 
 

Re: [code] 3ds2obj.rb

Postby thomthom » Wed Feb 17, 2010 6:34 pm

xrok1 wrote:thomthom, does it work, does it work?? :bounce:

A bit early to ask that. ;)
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [code] 3ds2obj.rb

Postby Jim » Wed Feb 17, 2010 6:35 pm

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:

Code: Select all
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
0
Hi

Jim 
Global Moderator
 

Re: [code] 3ds2obj.rb

Postby Jim » Wed Feb 17, 2010 6:43 pm

Whoops, check that command-line example I gave for usage - I changed it.

$ 3ds2obj.rb model.3ds > model.obj
0
Hi

Jim 
Global Moderator
 

Re: [code] 3ds2obj.rb

Postby Jim » Wed Feb 17, 2010 6:53 pm

getting closer..
Code: Select all
* 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

0
Hi

Jim 
Global Moderator
 

Re: [code] 3ds2obj.rb

Postby Jim » Wed Feb 17, 2010 7:04 pm

I see , the camera is a fixed-length chuck so has no length - you just start reading the values:

Code: Select all
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)
0
Hi

Jim 
Global Moderator
 

Re: [code] 3ds2obj.rb

Postby thomthom » Wed Feb 17, 2010 7:05 pm

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?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [code] 3ds2obj.rb

Postby thomthom » Wed Feb 17, 2010 7:08 pm

Jim wrote:I see , the camera is a fixed-length chuck so has no length - you just start reading the values:

Code: Select all
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.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [code] 3ds2obj.rb

Postby thomthom » Wed Feb 17, 2010 7:09 pm

Jim wrote:Although strangely the values are close but not exact as:

How close? Minor - something that could be explained by floating precision?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [code] 3ds2obj.rb

Postby Jim » Wed Feb 17, 2010 7:10 pm

thomthom wrote: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.
0
Hi

Jim 
Global Moderator
 

Re: [code] 3ds2obj.rb

Postby Jim » Wed Feb 17, 2010 7:29 pm

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.

Code: Select all
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
0
Hi

Jim 
Global Moderator
 

Re: [code] 3ds2obj.rb

Postby thomthom » Wed Feb 17, 2010 7:37 pm

Jim wrote: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 wrote: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?
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: Pavi Anu and 15 guests