• Login
sketchucation logo sketchucation
  • Login
πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

[Plugin] OBJexporter v3.0 20130131

Scheduled Pinned Locked Moved Plugins
304 Posts 96 Posters 451.3k Views
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.
  • T Offline
    TIG Moderator
    last edited by 1 Apr 2011, 22:19

    I've checked your linked SKP.BrukSKP.PNG
    It isn't modeled perfectly - there are a few reversed or missing faces [showing as blue or 'nothing' here].BrukMono.PNG
    My Octane render seems much like the SKp.BrukOctane.png
    My Twilight render is too [although it does auto-correct the rubbish modeling [reversed face on the end of the stone-wall and a triangle pane in particular].BrukTW.jpg
    This crap render from AC3D also mimics Octane's output with the expected problemsBrukAC3D.PNG
    Finally here's it exported to OBJ, re-imported into an empty SKP and a Twilight renderBrukOBJ=TW.jpg

    They all seem to cope quite well with the original SKP - TW even forgives the reversed faces πŸ˜’

    What's your renderer that seems to be causing this weirdness ? πŸ˜•

    TIG

    1 Reply Last reply Reply Quote 0
    • A Offline
      Alienizer
      last edited by 1 Apr 2011, 22:47

      I was only using a simple raytrace to verify the orientation of the faces. When I click on a face, it shows me the reflected vector (also shows the normals etc), and it shows it correctly with the skp export, but with yours, it shows the reflected vector to go inwards. Not for the whole model, only for the 2 brown doors to the right. When I reverse the face (f #/#/#...) as I explained, then the reflected verctor is proper. The same thing happens with the body of the allo dinosaur, but not the head.

      I know the renders takes care of that, but imho I think it's better to have a flawless obj than one the render has to fix, so I present you my findings. It seems that for those 2 doors, the triangles are CWW instead of CC (or CC instead of CCW). This makes a big difference when you do a ray/troiangle test and test for face culling or want to know if it hit the back face or not.

      I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

      1 Reply Last reply Reply Quote 0
      • T Offline
        TIG Moderator
        last edited by 1 Apr 2011, 23:25

        Thanks for the analysis...
        The tool's 'triangulation' method is built in to the Ruby API's face / mesh methods.
        There's little control over it, other than telling it what extent of detail the mesh will include - like back face UVs...
        ...except that there are some arcane face / edge methods 'reversed_in' etc that are used to orient faces that share an edge but face opposite directions [i.e. one is reversed].
        At the moment I can't see how... BUT perhaps you could reverse an edge's vertices on a particular face that is 'wrong' before making the triangulated mesh... I wonder if the problem 'door' face has some small facets - fluking it? I'll look more closely...

        As it is, I see this glitch as a shortcoming of the API mesh method that is making occasional glitches in the mesh that the OBJ is then using in its exporting... πŸ˜•

        TIG

        1 Reply Last reply Reply Quote 0
        • A Offline
          Alienizer
          last edited by 1 Apr 2011, 23:58

          I see what you mean. I did a test on that door, and I can't push/pull inward, skp says it's offset is at zero! If I remove the back face of the door and keep 5 sides, then it export find in yours. I don't know why it will not push/pull, I see no triangulation in skp that would show this 3D rectangle door not being 100% rectangular. If one face wasn't the same size, other faces would be triangulated accordingly in skp, and the hidden geom would show that, but it doesn't!!

          I was wondering, I know little about skp api but I've look at all the api and I was wondering if there was a better way to get the data. For example, I see that you do not use uvhelper. Maybe there is a way to get the normals and tex uv using an api rather than doing it all over? skp diplays it right, so it must be stored somewhere no?

          I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

          1 Reply Last reply Reply Quote 0
          • T Offline
            TIG Moderator
            last edited by 2 Apr 2011, 11:22

            It doesn't need to have a 'get_uv_helper' method because it gets the UVs directly from the face.mesh using
            f_uvs=(1..mesh.count_points).map{|i|mesh.uv_at(i,1)}###1=front
            which avoids lots of complex 'getting' otherwise...

            Clearly there's something adrift with those bi-folding doors...
            If you edit one and select-all you get 18 entities - the correct number of faces+edges for a cuboid so there's no tiny bits of stray geometry to mess with us...
            If you edit one of them you you'll find that the door 'slab' is not actually a cuboid - it's slightly skewed - faces don't meet quite at right angles, so PushPulling any vertical face 'inwards' is disallowed. To see this just try making a simple skewed cube and try to PushPull a face 'in' - you can't! because it clashes with connected internal geometry; however, it will PushPull 'out' as there's no clash and it makes two new edges and faces, because the extended side faces aren't coplanar with the original they spring from. This in itself shouldn't mess with the faces' mesh/UV mapping - it's weird...
            Also if you edit the door 'slab' so you can see the axes [switch them 'on' and v8 displays the actual component-axes during the edit, rather than the model-axes as in v7] you find it has been made [or at least inserted] 'upside-down' - the Z/blue axes is 'down' not and not 'up' as it ought to be...
            This might also be confusing the issue, but again it shouldn't matter.
            None of these issues ought to matter but it seems that they do πŸ˜•Capture.PNG

            TIG

            1 Reply Last reply Reply Quote 0
            • A Offline
              Alienizer
              last edited by 2 Apr 2011, 17:23

              I should know better not to ask you about the api, you're the expert, and I'm sure you've already taken the best possible route to make your exporter 😳

              About the door, you're right! I didn't catch that. Is it possible that your exporter reverse the order of the triangle's vertex because the Zaxis is down rather than up? say, p1,p2,p3 becomes p3,p2,p1 but the uv's are for p1,p2,p3, and that's why I get the face normal going in rather then out? My raytrace sees the face material just fine, but becuase it shoots a ray inward (bounce off the face normal) it hits no light, and shows real dark. When I manually reverse p3,p2,p1 to p1,p2,p3, then the bouce of the normal is outward and hits a light, and looks fine.

              One suggestion, is it possible to modify your exporter to save the textures all in png rather than mixed jpg, tga etc? no matter what the original was?

              Thanks tig for taking the time, I appreciate it.

              I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

              1 Reply Last reply Reply Quote 0
              • T Offline
                TIG Moderator
                last edited by 2 Apr 2011, 17:54

                Clever idea about changing the Texture Files' format on export... πŸ˜„

                Here's v1.6 http://forums.sketchucation.com/viewtopic.php?p=294844#p294844
                Option to export all Texture files in PNG format added [after the OBJ save path has been given].
                'Yes' makes all the exported textures into PNG files: note that the processing might then take a second or two longer as these conversions will take a finite amount of time.
                'No' leaves them in their original format [as <v1.6 exports].

                TIG

                1 Reply Last reply Reply Quote 0
                • A Offline
                  Alienizer
                  last edited by 2 Apr 2011, 19:31

                  WOW that was FAST 😍 Thank you, thank you!

                  Any thought about the Zaxis and the reverse p1,p2,p3?

                  I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    TIG Moderator
                    last edited by 2 Apr 2011, 19:33

                    @alienizer said:

                    WOW that was FAST 😍 Thank you, thank you!
                    Any thought about the Zaxis and the reverse p1,p2,p3?

                    That bit was easy - but that other bit is too obscure... because you should be able to have oddly place components and still return correct UVs πŸ˜•

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      Alienizer
                      last edited by 2 Apr 2011, 20:09

                      @tig said:

                      but that other bit is too obscure... because you should be able to have oddly place components and still return correct UVs πŸ˜•

                      hmmm, but when the vertex are CC instead of CCW, the ray/triangle intersect report the hit being on the back face rather then the front! Is there a way in the exporter to know which is p1, p2 and p3? and save them in the proper order? SKP must do it right for it to be able to display the back face in blue when viewed in mono.

                      I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                      1 Reply Last reply Reply Quote 0
                      • A Offline
                        Alienizer
                        last edited by 3 Apr 2011, 02:04

                        tig, I found the problem. If you can do a test, (use a model with all faces facing the right way), run your raytrace and for every pixels on the screen, if it hits the back face (turn off back face culling) display that pixel in red, otherwise use some other color, material color perhaps. You will see that using skp exporter, they are fine, using yours, some are not. Now, a quick fix I did was to get the normal <-- cross(edge1,edge2) and then, calculate the normal for p1. Do a dot(Normal, NormalAtP1) and if the result is negative, recreate the face as p3,p2,p1 as oppose to p1,p2,p3, and swap 1 and 3 for the UVs as well. Then your raytrace will show the face correctly. I hope I make sense? Pehars that's how other render do it to correct such problem?

                        I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                        1 Reply Last reply Reply Quote 0
                        • A Offline
                          Alienizer
                          last edited by 8 Apr 2011, 03:55

                          Sorry to be a pest TIG, but have you had a chance to read me posts? πŸ˜•

                          I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            TIG Moderator
                            last edited by 8 Apr 2011, 07:49

                            I have read it, but I am busy on several other things right now. 😞
                            Why don't you poke around in my code [the #500s lines] and see if you can fix it - then you can have joint (c) credit πŸ˜‰

                            TIG

                            1 Reply Last reply Reply Quote 0
                            • A Offline
                              Alienizer
                              last edited by 9 Apr 2011, 02:34

                              @tig said:

                              I have read it, but I am busy on several other things right now. 😞
                              Why don't you poke around in my code [the #500s lines] and see if you can fix it - then you can have joint (c) credit πŸ˜‰

                              🀣 If I was as smart as you perhaps I would!

                              I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                              1 Reply Last reply Reply Quote 0
                              • T Offline
                                TIG Moderator
                                last edited by 9 Apr 2011, 12:52

                                OK I try to make time to look at it next week... πŸ˜’

                                TIG

                                1 Reply Last reply Reply Quote 0
                                • A Offline
                                  Alienizer
                                  last edited by 9 Apr 2011, 15:39

                                  @tig said:

                                  OK I try to make time to look at it next week... πŸ˜’

                                  THANK YOU TIG 😍

                                  I'm from Mars and moved to Earth to alienize you. Unfortunately, I became humanized.

                                  1 Reply Last reply Reply Quote 0
                                  • K Offline
                                    Kralizek
                                    last edited by 10 Apr 2011, 18:38

                                    Works great for for me, thanks a lot TIG!

                                    1 Reply Last reply Reply Quote 0
                                    • I Offline
                                      Immer
                                      last edited by 16 Apr 2011, 00:08

                                      Thanks TIG, this is an incredibly useful plugin, the most reliable obj-exporter I've tried.

                                      I have one feature request though - could you add an option to export faces with distorted textures using the original texture and just save the "distorted" UV coordinates in the .obj file? As it is now doing something as simple as exporting a spherically-mapped globe can generate hundreds of distorted texture files and a correspondingly complicated .obj file, not exactly ideal for loading into another program.

                                      I've modified version 1.1 to normalize the UVQ coordinates before export and it seems to work fine, it would be nice to have access to the more recent features though so I'm sending you the change in hopes that you'll incorporate it into the next version

                                      the relevant change was changing the line
                                      f_uvs=(1..mesh.count_points).map{|i|mesh.uv_at(i,1)}####1=front
                                      to
                                      f_uvs=(1..mesh.count_points).map{|i|flattenUVQ(mesh.uv_at(i,1))}####1=front
                                      where flattenUVQ is defined as
                                      def flattenUVQ(uvq)
                                      return Geom::Point3d.new((uvq.x/uvq.z), (uvq.y/uvq.z), 1.0)
                                      end

                                      Thanks a bunch!

                                      1 Reply Last reply Reply Quote 0
                                      • T Offline
                                        TIG Moderator
                                        last edited by 16 Apr 2011, 16:06

                                        Sketchup's own OBJexporter also makes individual 'distorted' images when a texture has been 'distorted' by UV mapping - simple rotations or scaling shouldn't produce multiple images.
                                        I added the feature to mimic it because otherwise you don't get the correct 'distortion' - I have previously tried the very method you outline in your code snippet but it never gave satisfactory results. The flattenUVQ method is actually in the code 'unused' [until the more recent updates that make distorted images...].
                                        A distorted texture has 4 uvs but a triangulated mesh makes just 3 per facet ??

                                        TIG

                                        1 Reply Last reply Reply Quote 0
                                        • I Offline
                                          Immer
                                          last edited by 16 Apr 2011, 21:52

                                          Yeah, I had noticed and used the flattenUVQ method provided - I figured it was something you had brought in from someone else's code but didn't use. I didn't see it in the latest version so I thought I'd include it in case you didn't have an archive of older versions.

                                          Don't get me wrong, it's awesome that you've managed to export non-linearly distorted faces accurately, however for many situations a linear approximation is preferable, especially if lots of additional textures or a complicated group layout present problems - like if you intend to use the exported object in a game engine, or want to fine-tune the UV mapping in another program. It may even be what was actually intended: for example UVTools' spherical map apparently uses distorted textures when linear interpolation is the correct method. In fact I'm not sure it's even possible to specify a lineraly distorted face in Sketchup. I've yet to find a way to, for example, squeeze a rectangular texture onto a trapezoid so the edges and center-points line up perfectly, and that's UV mapping 101.

                                          All I'm suggesting is a checkbox on the option screen to choose between the accurate method and the "clean" one, it should just be a matter of changing the logic to

                                          
                                          if "face is distorted"     *AND* "use accurate method"
                                             create accurate texture
                                             export face using accurate texture
                                          else
                                             output face with normalized UVs # normalizing should have no effect on non-distorted faces
                                          
                                          
                                          1 Reply Last reply Reply Quote 0
                                          • 1
                                          • 2
                                          • 3
                                          • 4
                                          • 5
                                          • 6
                                          • 15
                                          • 16
                                          • 4 / 16
                                          4 / 16
                                          • First post
                                            67/304
                                            Last post
                                          Buy SketchPlus
                                          Buy SUbD
                                          Buy WrapR
                                          Buy eBook
                                          Buy Modelur
                                          Buy Vertex Tools
                                          Buy SketchCuisine
                                          Buy FormFonts

                                          Advertisement