sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [code] 3ds2obj.rb

    Scheduled Pinned Locked Moved Developers' Forum
    15 Posts 3 Posters 2.7k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      Jim
      last edited by

      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


      3ds2obj.rb

      Hi

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jim
          last edited by

          It is readily available online.

          Hi

          1 Reply Last reply Reply Quote 0
          • X Offline
            xrok1
            last edited by

            thomthom, does it work, does it work?? πŸŽ‰

            β€œ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!

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @xrok1 said:

              thomthom, does it work, does it work?? πŸŽ‰

              A bit early to ask that. πŸ˜‰

              Thomas Thomassen β€” SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • J Offline
                Jim
                last edited by

                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
                
                

                Hi

                1 Reply Last reply Reply Quote 0
                • J Offline
                  Jim
                  last edited by

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

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

                  Hi

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    Jim
                    last edited by

                    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
                    
                    
                    

                    Hi

                    1 Reply Last reply Reply Quote 0
                    • J Offline
                      Jim
                      last edited by

                      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)

                      Hi

                      1 Reply Last reply Reply Quote 0
                      • thomthomT Offline
                        thomthom
                        last edited by

                        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

                        1 Reply Last reply Reply Quote 0
                        • thomthomT Offline
                          thomthom
                          last edited by

                          @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.

                          Thomas Thomassen β€” SketchUp Monkey & Coding addict
                          List of my plugins and link to the CookieWare fund

                          1 Reply Last reply Reply Quote 0
                          • thomthomT Offline
                            thomthom
                            last edited by

                            @jim said:

                            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

                            1 Reply Last reply Reply Quote 0
                            • J Offline
                              Jim
                              last edited by

                              @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.

                              Hi

                              1 Reply Last reply Reply Quote 0
                              • J Offline
                                Jim
                                last edited by

                                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
                                

                                Hi

                                1 Reply Last reply Reply Quote 0
                                • thomthomT Offline
                                  thomthom
                                  last edited by

                                  @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?

                                  Thomas Thomassen β€” SketchUp Monkey & Coding addict
                                  List of my plugins and link to the CookieWare fund

                                  1 Reply Last reply Reply Quote 0
                                  • 1 / 1
                                  • First post
                                    Last post
                                  Buy SketchPlus
                                  Buy SUbD
                                  Buy WrapR
                                  Buy eBook
                                  Buy Modelur
                                  Buy Vertex Tools
                                  Buy SketchCuisine
                                  Buy FormFonts

                                  Advertisement