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

[Req] Texture Corrector.... PLEASE

Scheduled Pinned Locked Moved Plugins
40 Posts 10 Posters 10.1k 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
    thomthom
    last edited by 2 Dec 2008, 16:37

    I tried having a go at this myself. But I can't work out how the API's related to textures work. I'm thinking this isn't the best challenge for a first ruby...

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

    1 Reply Last reply Reply Quote 0
    • B Offline
      BillW
      last edited by 2 Dec 2008, 17:39

      I dont know if this is of any use - a ruby I call via the ruby console with load "<filename>"
      after selecting the faces I want to work on.

      What it does is set the front face (of selected faces) to have the same material and texture mapping as the back face. It worked for me with a particular problem I had in which an imported image I exploded and did a pushpull - the top face didnt show the texture map - it was on the other side ie back face.
      Reapplying the material didn't do the trick as the image had been scaled on import. For your situation
      the code will need to changed ie

      get_back_UVQ to get_front_UVQ
      ent.material = ent.back_material to ent.back_material = ent.material

      
      model = Sketchup.active_model
      tw = Sketchup.create_texture_writer
          
      model.selection.each { | ent | 
        case ent.typename
          when "Face" then
      
      # sets front material and mapping as back material
      
           ent.material = ent.back_material
            uvHelp = ent.get_UVHelper(true, true, tw)
      
            pt_array = []
            
            numint = (ent.outer_loop.vertices.length / 4).floor
      
            vert = ent.outer_loop.vertices[numint-1]
            uvq = uvHelp.get_back_UVQ(vert.position)
            pt_array.push(vert.position,uvq)
      
            vert = ent.outer_loop.vertices[(numint*2) - 1]
            uvq = uvHelp.get_back_UVQ(vert.position)
            pt_array.push(vert.position,uvq)
      
            vert = ent.outer_loop.vertices[(numint*3) - 1]
            uvq = uvHelp.get_back_UVQ(vert.position)
            pt_array.push(vert.position,uvq)
      
            vert = ent.outer_loop.vertices[(numint*4) - 1]
            uvq = uvHelp.get_back_UVQ(vert.position)
            pt_array.push(vert.position,uvq)
      		  
           ent.position_material ent.material,  pt_array , true # Set front coords
      
        end
      }
      
      
      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 2 Dec 2008, 22:28

        !!! Bill!
        That's excellent! ๐Ÿ˜

        That's just what I needed. Do you mind if I publish a ruby with your code in it? There's a bunch of V-Ray users that sorely need this in order to be able to use X-Frog trees for rendering vegetation in models.

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

        1 Reply Last reply Reply Quote 0
        • E Offline
          EarthMover
          last edited by 3 Dec 2008, 02:28

          Thomas,

          Have you tested this code out? Does it work? (fingers crossed.....)

          3D Artist at Clearstory 3D Imaging
          Guide Tool at Winning With Sketchup
          Content Creator at Skapeup

          1 Reply Last reply Reply Quote 0
          • T Offline
            thomthom
            last edited by 3 Dec 2008, 07:53

            Yes! I've tested it out after tweaking it to copy from front face to back face. Just got to make it work on nested groups/components and add menu item and we're gold. ๐Ÿ˜„

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

            1 Reply Last reply Reply Quote 0
            • B Offline
              BillW
              last edited by 3 Dec 2008, 19:14

              Thomthom

              Feel free to parcel up the code.

              Regards

              Bill Wood

              1 Reply Last reply Reply Quote 0
              • T Offline
                thomthom
                last edited by 3 Dec 2008, 19:29

                Complete Ruby here: http://www.sketchucation.com/forums/scf/viewtopic.php?f=180&t=14684 ๐Ÿ˜„

                So, from what I understand of the plugin, it takes the real world co-ordinates of four point and their UV mapping, which then is transferred directly to the other side? And it doesn't require the face to have four vertices because you sample four points out of the total points and that's enough to place the texture correct?

                It looks much more simple now that I see the working code. But I couldn't make any sense out of the data I got from the UVHelper object.

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

                1 Reply Last reply Reply Quote 0
                • B Offline
                  BillW
                  last edited by 3 Dec 2008, 19:42

                  So, from what I understand of the plugin, it takes the real world co-ordinates of four point and their >>UV mapping, which then is transferred directly to the other side? And it doesn't require the face to >>have four vertices because you sample four points out of the total points and that's enough to place >>the texture correct?

                  Exactly how it works. However, I think it may fail with a face of only 3 vertices though. I didint check the UVHelper data - it just worked.

                  Bill Wood

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    thomthom
                    last edited by 3 Dec 2008, 19:50

                    Yea. I didn't test it myself. Thought of it when I made the post. Might have to test that out and make some modification for triangle faces.

                    Once again Bill, thank you very much. I have 5 DVD sets of XFrog trees which was of no good due to the messed up backfaces.

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

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      thomthom
                      last edited by 4 Dec 2008, 08:46

                      I just ran it one a tree where the leaf face was split into two triangles and the texture didn't turn out right. The entity info reports that the material is on the backface, but in the viewport it's just a clear transparent colour.

                      So I will have to made amendment for triangles. but the good thing is that it didn't bugsplat SU.

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

                      1 Reply Last reply Reply Quote 0
                      • D Offline
                        davide.skp
                        last edited by 4 Dec 2008, 10:35

                        beautiful bill! excellent work!
                        I tested your code ... work work work ... so I am very happy ...

                        I have done tests with the attachment of free agent: texture to fix- and with some of my models of plants and point out these problems:

                        1] Unfortunately, the code works perfectly from the face below the one above [ent.material = ent.back_material]

                        2] I proceeded to change the code, of course, follow your footsteps,
                        "get_back_UVQ to get_front_UVQ
                        ent.material = ent.back_material to ent.back_material = ent.material "the ruby turns ... no errors but no results ... boh!

                        3] also on some files (small) I go in BUG Splat!

                        attack:
                        1] ruby with changes according to your advice
                        2] bill's ruby
                        3] some SKP trees


                        [1] ruby with changes according to your advice](/uploads/imported_attachments/n75v_BILLW_011.rb)


                        [2] bill's ruby](/uploads/imported_attachments/1FRl_BILLW_010.rb)

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          thomthom
                          last edited by 4 Dec 2008, 11:13

                          I did notice that if the faces have only tree points the ruby doesn't handle that. But I've not experienced any bugsplats.
                          I did run into bugsplat when I tried to transfer material from a face that didn't have an material applied. Solved that by adding a check.

                          Just to make sure David, the problem you're experiencing is that you can transfer from back to front, but not from front to back? And some times you get bug plats? Does this happen with Bill's code or with mine? Both?

                          Does that faces have less then four corners?

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

                          1 Reply Last reply Reply Quote 0
                          • D Offline
                            davide.skp
                            last edited by 4 Dec 2008, 11:35

                            TomTom, the bug come only with BILLW_010.rb.
                            I test your ... don't splat but don't work
                            can you test with my plant? ๐Ÿ˜Ž

                            CIAO!!!


                            [3] some SKP trees](/uploads/imported_attachments/z05o_vivaio.zip)

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              thomthom
                              last edited by 4 Dec 2008, 11:45

                              Didn't seem to have any problems. Attached is your model with the result.
                              vivaio.zip

                              Did you click on "Frontface to Backface" or "Backface to Frontface"?

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

                              1 Reply Last reply Reply Quote 0
                              • D Offline
                                davide.skp
                                last edited by 4 Dec 2008, 12:06

                                sorry sorry sorry ... probably I click bkface to front ...
                                now work ....
                                ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰

                                i'm very happy

                                1 Reply Last reply Reply Quote 0
                                • T Offline
                                  thomthom
                                  last edited by 4 Dec 2008, 12:51

                                  ๐Ÿ‘

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

                                  1 Reply Last reply Reply Quote 0
                                  • N Offline
                                    numerobis
                                    last edited by 31 Jan 2009, 19:17

                                    WOW! VERY cool plug! Thank You so much! i have to import a lot of trees into sketchup these days - without this nice tool it would be nearly impossible to get the textures right! ๐Ÿ‘

                                    one question: would it be possible to write a ruby that can center a texture to the face it has been applied - some of the trees i import have many of their leaf textures not centered on both sides... any idea how this could be fixed โ“

                                    1 Reply Last reply Reply Quote 0
                                    • T Offline
                                      thomthom
                                      last edited by 31 Jan 2009, 19:19

                                      Can you post a screenshot? And what trees is it? XFrog?

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

                                      1 Reply Last reply Reply Quote 0
                                      • free agentF Offline
                                        free agent
                                        last edited by 1 Feb 2009, 18:58

                                        ooo that would be quite interesting, not just centering but conforming to the quad it is applied to, like a square texture image will stretch itself to fit a retangle face, that would help for remapping leaf textures in sketchup, althought sketchups new export to photoshop option kinda does that already, it should have extra handy uses... is that possible, that would be an awesome plugin

                                        http://i167.photobucket.com/albums/u143/FreeAgent84/bug.gif

                                        1 Reply Last reply Reply Quote 0
                                        • N Offline
                                          numerobis
                                          last edited by 3 Feb 2009, 00:06

                                          sorry for the delay...

                                          the trees are xfrog - but i have problems with decentered textures with other models too...

                                          i've done some testing with the xfrog trees - there is a difference if i apply the "front to back" tool to the component (containing all leaves) or open the component to select all faces
                                          to correct the textures...
                                          at the moment i open the the component all textures get messed up forever. no way to restore the original coordinates.
                                          correcting the coordinates of the component works! but if i open it after correcting... ๐Ÿ˜ฎ no way to go back - only reloading the file can fix it
                                          here's an example:

                                          http://img34.picoodle.com/img/img34/3/2/2/f_beforeafterm_6e83bf5.jpg

                                          would it be possible to write a ruby that centers and resizes the textures?

                                          i was really hoping for better texturing tools in v7...
                                          ...and for high poly + x64 + multi core support...
                                          ๐Ÿ˜ข

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

                                          Advertisement