SketchUcation Plugin Store

 

 

[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
Please, register (free) to access all the attachments on the forums.
Jim
Global Moderator
 
Posts: 4126
Joined: Mon Nov 12, 2007 10:13 pm
Location: NEOH
Name: Jim
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: other
Level of SketchUp: Intermediate

Re: [code] 3ds2obj.rb

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

You got hold of file format specs for 3ds?
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17687
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [code] 3ds2obj.rb

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

It is readily available online.
Jim
Global Moderator
 
Posts: 4126
Joined: Mon Nov 12, 2007 10:13 pm
Location: NEOH
Name: Jim
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: other
Level of SketchUp: Intermediate

Re: [code] 3ds2obj.rb

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

thomthom, does it work, does it work?? :bounce:
“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
 
Posts: 1966
Joined: Sat Feb 16, 2008 1:53 am
Location: Canada
Name: Rocky

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. ;)
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17687
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

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
Jim
Global Moderator
 
Posts: 4126
Joined: Mon Nov 12, 2007 10:13 pm
Location: NEOH
Name: Jim
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: other
Level of SketchUp: Intermediate

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
Jim
Global Moderator
 
Posts: 4126
Joined: Mon Nov 12, 2007 10:13 pm
Location: NEOH
Name: Jim
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: other
Level of SketchUp: Intermediate

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

Jim
Global Moderator
 
Posts: 4126
Joined: Mon Nov 12, 2007 10:13 pm
Location: NEOH
Name: Jim
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: other
Level of SketchUp: Intermediate

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)
Jim
Global Moderator
 
Posts: 4126
Joined: Mon Nov 12, 2007 10:13 pm
Location: NEOH
Name: Jim
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: other
Level of SketchUp: Intermediate

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?
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17687
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

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.
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17687
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

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?
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17687
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

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.
Jim
Global Moderator
 
Posts: 4126
Joined: Mon Nov 12, 2007 10:13 pm
Location: NEOH
Name: Jim
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: other
Level of SketchUp: Intermediate

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
Jim
Global Moderator
 
Posts: 4126
Joined: Mon Nov 12, 2007 10:13 pm
Location: NEOH
Name: Jim
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: other
Level of SketchUp: Intermediate

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?
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom
Global Moderator
 
Posts: 17687
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Keyframe Animation plugin - animate your SketchUp model by adding movement to any object.

Premium Members get 20% discount!

Ad Machine
Robot
 
Posts: 2012


Return to Developers' Forum

Who is online

Users browsing this forum: Google Bot and 1 guest