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

    [Plugin] Import OBJ with Materials v2.1 20131118

    Scheduled Pinned Locked Moved Plugins
    279 Posts 87 Posters 378.6k Views 87 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.
    • thomthomT Offline
      thomthom
      last edited by

      Any ideas what caused these glitches? http://forums.sketchucation.com/viewtopic.php?f=323&t=20584&start=75#p264875

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

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        Thomthom, I assume you are referring to the size/units ?
        If the file has a '# units = meters' line then the importer defaults to 'meters' [or whatever it says].
        If it doesn't then it defaults to 'inches'.
        However, as it starts a dialog lets you choose whatever units you'd like to use anyway [preset to those default units].
        Some meshes don't form the tiny faces if the units are set too small - e.g. if you were to choose 'mm' when it was made in 'meters'. So if you are unclear about the units and none are specified then you can try out alternatives until you get a proper mesh without holes...
        The reason the tool has three options is speed - 'as mesh' is fast but can fail when the OBJ code is convoluted; otherwise the textures can be added or not as desired.
        The old sizing issue seems resolved.
        PS: I can't tested your problem 'van' OBJ/MTL because PPartner010000.jpg wasn't in the zip file?
        But I can see that its geometry seems a bit messed up around the side windows and the image file-names have spaces in them which confuses the MTL parser. I thought that you were 'recommended' to avoid having spaces in these paths/names - however, manually editing the MTL and the corresponding image-names so they are without spaces fixes that... BUT the 'PPartner010000.jpg' file is still missing altogether - see the Ruby Console error reporting πŸ˜•

        TIG

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          Busy today! Heres 1.8 - Trapped for spaces in image-names/paths.
          http://forums.sketchucation.com/viewtopic.php?p=172790#p172790

          TIG

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

            @tig said:

            Thomthom, I assume you are referring to the size/units ?

            No - it was the messed up geometry you noticed. You see it in the screenshots I posted - with the red circles.

            @tig said:

            PS: I can't tested your problem 'van' OBJ/MTL because PPartner010000.jpg wasn't in the zip file?
            But I can see that its geometry seems a bit messed up around the side windows and the image file-names have spaces in them which confuses the MTL parser. I thought that you were 'recommended' to avoid having spaces in these paths/names - however, manually editing the MTL and the corresponding image-names so they are without spaces fixes that... BUT the 'PPartner010000.jpg' file is still missing altogether - see the Ruby Console error reporting πŸ˜•

            The OBJ was initially created by SketchUp - then edited textures in PhotoShop.

            I've attached the missing texture.

            Will try v 1.8


            missing texture

            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

              Even with 1.8 some geometry is messed up. Seem to be the same faces.

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

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                I see the messed up UV textures.
                I re-imported it as 'mm' and the messed geometry went.
                BUT I had to edit the faulty UV mapped parts manually.
                As it's symmetrical a quick mirror/copy of the correct panel on the other side fixed them.
                The 'Badge' is messed up though - did you map that on separately ?
                I've no idea why just those few parts fail to map properly πŸ˜•
                VAN.PNGVAN.skp

                TIG

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

                  I import in mm - but it's not just the UV being messed up. It's the actual geometry.
                  Notice that for the incorrect mapping the face is split diagonally-crossing itself - as opposed to the mirrored side.
                  When you compare against the 3ds import you see that Max does not do this.

                  I did not do anything to the mapping other than take the OBS into PS and adding the text on the side of the van. The model came from a pre-modelled and pre-mapped third party model.

                  I wonder if it's the order of the vertices that's abnormal in these cases... ?

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

                  1 Reply Last reply Reply Quote 0
                  • TIGT Offline
                    TIG Moderator
                    last edited by

                    The cross-threading of the faces' vertices into 'bowtie' triangles - which then probably mess up the UV-mapping - must be in the OBJ file itself [?].
                    The OBJ Importer simply uses the f n/n nn/nn/ nnn/nnn... values to form the faces and mapping ? Unfortunately unless you can reproduce the problem in a file with relatively few faces it'll be all but impossible to plough through the data to find the problem instances... [+460+ faces here?].
                    I was hoping that the OBJ had some -ve face indices that were causing the problem which recent versions might have solved... but NO! πŸ˜’
                    In SUp export the ordering of a face's vertices shouldn't be a problem as they should always return ordered, and in the correct 'clockwise-ness' for the face's normal direct ?

                    TIG

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

                      The vertexes in the 'f' line are out of order for whatever reason.

                      Creates a "bow tie":

                      Sketchup.active_model.entities.add_face([0,0], [1,1], [1,0], [0,1])

                      Hi

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

                        So it's the OBJ data that's invalid... but Max manage to deal with it somehow.

                        I'll compare against the raw output from SU and see if it's SU or PS that mangles the geometry.

                        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

                          It's SU generating the odd vertex order. Here's the OBJ directly from SU:


                          SU Export

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

                          1 Reply Last reply Reply Quote 0
                          • TIGT Offline
                            TIG Moderator
                            last edited by

                            Could you PM me the original textured SKP - I have a new embryonic OBJ-Exporter that might NOT do this glitch ?

                            TIG

                            1 Reply Last reply Reply Quote 0
                            • N Offline
                              notareal
                              last edited by

                              Here is a model that seems to fail http://www.fileden.com/files/2009/5/30/2461193//dragon_scene_OBJ.rar (From CGTalk Frosted Glass Challenge). Maybe it's a bit large... but simlab obj importer seems to handle it.

                              Welcome to try [Thea Render](http://www.thearender.com/), Thea support | [kerkythea.net](http://www.kerkythea.net/) -team member

                              1 Reply Last reply Reply Quote 0
                              • honoluludesktopH Offline
                                honoluludesktop
                                last edited by

                                TIG, Wow, nice piece of code. Lots stuff I have to learn, like next, case, when, def file.run(par1, par2), etc. Makes the code look more compact and easy to read. Oh well, if I looked here before starting what I am working on, I may not have understood:-)

                                Some of the stuff that's driving me nuts when writing importers, is that different exporters do not format the data exactly. SU's DxfIn treats "10", and " 10" equally, and many exporters ignore the convention that is " 10". I don't know if I should go back and fix my code to read "10" or not. It's no problem for my use, and would like to "share", but am concerned about posting something that may not work for some.

                                1 Reply Last reply Reply Quote 0
                                • TIGT Offline
                                  TIG Moderator
                                  last edited by

                                  honoluludesktop
                                  A DXF has alternating lines for 'code' and 'value'.
                                  So if it's an odd-numbered line then it's always 'code' and if it's an even-numbered line it's always the previous line's code's 'value'...
                                  It's a DXF convention to indent the 'code' number, BUT it's not necessary and any importer should strip off leading spaces anyway...

                                    0
                                  SECTION
                                    2
                                  HEADER
                                    9
                                  etc
                                  

                                  is the same as

                                  0
                                  SECTION
                                  2
                                  HEADER
                                  9
                                  etc
                                  

                                  To see a DXF 'parser' look at my DXF Text Importer http://forums.sketchucation.com/viewtopic.php?p=194488#p194488
                                  πŸ€“

                                  TIG

                                  1 Reply Last reply Reply Quote 0
                                  • honoluludesktopH Offline
                                    honoluludesktop
                                    last edited by

                                    OK, thanks, I will look at it. I may have to wait for a complete rewrite to parse the 'code'. Isn't some of that done in the Obj translator? I couldn't tell since I am not at all familiar with Obj.

                                    When I think about it, any translator can be a modular app., just as you did with the text importer as a supplement to SUs DxfIn. My own interest has been limited to very basic geometry, and dealing with the anomalies of my Cad's DxfIn/Out. It suits me since I use SU exclusively for visualization and modeling, and Cad for functional diagramming and production drawings. Accordingly, I only require the basic geometry to pass between SU and Cad.

                                    1 Reply Last reply Reply Quote 0
                                    • O Offline
                                      onesimo
                                      last edited by

                                      hi tig! thanks for the importer. its working perfectly for me on my archmodels.
                                      i should have tried it when i first saw the post. thanks so much and i really appreciate your work.

                                      1 Reply Last reply Reply Quote 0
                                      • O Offline
                                        onesimo
                                        last edited by

                                        hi tig! im using 3ds max design 2011. when i open/obj import my exported file the textures are not showing.. it seems my .mtl file is different from the one posted (the one with the building). thanks!


                                        my exported file from 3ds max

                                        1 Reply Last reply Reply Quote 0
                                        • KrisidiousK Offline
                                          Krisidious
                                          last edited by

                                          I imported an Obj file and the uvw map came in perfectly.

                                          objimporter02.jpg

                                          but some geometry was lost... any ideas on why?

                                          objimporter01.jpg

                                          By: Kristoff Rand
                                          Home DesignerUnique House Plans

                                          1 Reply Last reply Reply Quote 0
                                          • TIGT Offline
                                            TIG Moderator
                                            last edited by

                                            @onesimo said:

                                            hi tig! im using 3ds max design 2011. when i open/obj import my exported file the textures are not showing.. it seems my .mtl file is different from the one posted (the one with the building). thanks!

                                            The MTL file has the lines

                                            Ka 0.0000 0.0000 0.0000
                                            Kd 0.0000 0.0000 0.0000
                                            Ks 0.3500 0.3500 0.3500
                                            

                                            they should read

                                            Ka 0.0000 0.0000 0.0000
                                            Kd 0.3500 0.3500 0.3500
                                            Ks 0.0000 0.0000 0.0000
                                            

                                            The Kd value sets the material's RGB color in the original MTL file it is [0,0,0] = 'black'
                                            If you swap the Kd and Ks values and it renders 'gray' as expected...
                                            Only the 'Kd' value is read by the SUp importer - the other twp 'K' values involve reflectivity and spectral info that SUp can't use and are superfluous...
                                            Also if an MTL material has an image_file defined at the end of its text_block that will be used as its 'texture', overriding any RGB 'color' - but this material does not have a texture.
                                            When you make an OBJ file check that its MTL file's 'Kd' is set to RGB otherwise it will be 'black'.

                                            TIG

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 10
                                            • 11
                                            • 12
                                            • 13
                                            • 14
                                            • 14 / 14
                                            • First post
                                              Last post
                                            Buy SketchPlus
                                            Buy SUbD
                                            Buy WrapR
                                            Buy eBook
                                            Buy Modelur
                                            Buy Vertex Tools
                                            Buy SketchCuisine
                                            Buy FormFonts

                                            Advertisement