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

[REQ] Lock texture coordinates

Scheduled Pinned Locked Moved Plugins
28 Posts 7 Posters 3.5k 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.
  • W Offline
    Whaat
    last edited by 3 Jun 2009, 14:58

    Here are some methods to load and save UV sets. If someone wants to use them to create a 'lock texture' plugin, that's fine with me. ๐Ÿ˜„

    def store_uvs(ents,uvset)
    
    face=0
    case uvset
    	when 0
    		key="uv0"
    	when 1
    		key="uv1"
    	when 2
    		key="uv2"
    	when 3
    		key="uv3"
    end
    
    Sketchup.active_model.start_operation "Save UV set"
    
    for e in ents
    	
    	if (e.valid?) and (e.class==Sketchup;;Face)
    		
    		polymesh=e.mesh 5
    		uvs=polymesh.uvs 5
    		for i in (0..uvs.length-1)
    			uvs[i]=uvs[i].to_a  #converts the Point 3D objects to arrays so they won't be transformed
    		end
    		e.set_attribute 'uvs',key,uvs
    	
    	face=face+1
    	Sketchup.set_status_text("Stored uvs for #{face} faces.")
    	end
    		
    end
    
    UI.messagebox "UVs saved for #{face} faces."
    
    Sketchup.active_model.commit_operation
    
    end #function
    
    ###################position a texture on a material from a stored UV set
    def position_map(entities,set)
    
    face=0
    failed=0
    return if set=="SU"  
    key="uv"+set.to_s
    p "positioning map"
    p entities
    for e in entities
    	p e
    	if (e.valid?) and (e.class==Sketchup;;Face)
    		
    		uvs=e.get_attribute 'uvs',key    #gets the stored array of uv coordinates for this face for the given uv set
    		p uvs
    		if uvs
    			pos=[]
    			polymesh=e.mesh 5   #get a polygon mesh representation of the face
    			polygons=polymesh.polygons  
    			poly_index=0
    			begin
    				for p in polygons[poly_index]
    					point=polymesh.point_at(p.abs)
    					if point
    						pos.push(point) 
    						pos.push(uvs[p.abs-1])
    					end
    				end
    
    				e.position_material e.material, pos, true
    				face=face+1
    				Sketchup.set_status_text("Loaded uvs for #{face} faces")
    			rescue  #this is required because SketchUp sometimes fails to position the texture properly
    				poly_index=poly_index+1
    				if polygons[poly_index]
    					pos=[]
    					retry  #try to postion texture again using next polygon in the face
    				else
    					failed=failed+1
    				end
    			end
    	
    			
    		end
    	end
    end
    
    if failed>0
    	stext="Unable to load
    	UVs for #{failed} faces.  Loaded UVs for #{face} faces."
    else
    	stext="Loaded UVs for #{face} faces."
    end
    
    #UI.messagebox (stext)
    
    
    end  #end position map
    

    SketchUp Plugins for Professionals

    1 Reply Last reply Reply Quote 0
    • D Offline
      dacad
      last edited by 3 Jun 2009, 17:41

      WOW, thanks Whaat. Has always you're great!:)
      My knowledge in ruby is very limited so can anyone help with this? (or change the name of this topic to "[Request]Lock texture coordinates")
      Thanks in advance

      1 Reply Last reply Reply Quote 0
      • R Offline
        remus
        last edited by 12 Jun 2009, 12:51

        Unfortunately it isnt quite as easy as that. Ruby has it's own separate commands that dont necessarily match those that you see in the SU UI.

        I suppose you could think of it as ruby seeing a different UI to what the user sees: sometimes the stuff we see matches up with what ruby sees, sometimes ruby sees extra stuff we dont see and sometimes we see stuff ruby doesnt see.

        http://remusrendering.wordpress.com/

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jackson
          last edited by 12 Jun 2009, 12:52

          I was going to post a request/enquiry regarding this precise issue when I found this post. What baffles me is that this can already be done per individual face via the left click texture position editor (Right click on face>Texture>Position>Enter) which is fine for cuboids, but is pretty much useless when working on large triangulated meshes.

          As it's already possible on a per face basis in SU is it not relatively simple to write a ruby which simply repeats this action on all selected faces? Easy for me to say seeing as am and most likely always will be completely useless at programming, but Matthieu Noblet's "Components to Groups" script got me thinking. In principle it does almost exactly what we want- allows you to select geometry/groups/components, then performs a series of right click actions upon it/them. In that case it is:

          Select Component>Explode>Group>Deselect>Select Next Component>Explode, Group,... etc.

          Could the same principle (or even some of the same code) not be applied to this problem so you select a mesh, and the ruby then starts the sequence: Select Face>Texture (i.e. Open Texture Editor)> Position>Enter>Select Next Face,... etc?

          I've had a look in Matthieu's C2G code, but like I said, even basic ruby is beyond me. Matthieu's a very generous guy who I'm sure if requested would be willing to allow someone to edit and redistribute parts of it for a good cause. This ability, combined with all the recent "organic" modelling ruby scripts would be incredibly useful for SU users like myself who would rather keep 3D Max and Rhino OUT of their workflow!

          I understand of course (or at least I think I do) that SU has major UV mapping shortfalls- as I understand it, if you stretch/deform a face in SU elasticly, there's no way for SU to stretch the texture accordingly so edges still tile with adjacent faces (though that does make me wonder how Whaat's UV Spherical Mapping tool works?), but even an automation of the current Texture>Position>Enter would be of enormous benefit.

          p.s. guess who just spent 2 days texturing a tree! ๐Ÿ˜ข

          Jackson

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by 12 Jun 2009, 12:53

            @jackson said:

            I was going to post a request/enquiry regarding this precise issue when I found this post. What baffles me is that this can already be done per individual face via the left click texture position editor (Right click on face>Texture>Position>Enter) which is fine for cuboids,

            That doesn't lock anything. If you map a texture to a face (quad - or whatever - doesn't matter) and do the Position trick - then when you move an edge or vertex the texture doesn't stick with it.

            I wonder if you're asking for something else..?

            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
              Jackson
              last edited by 12 Jun 2009, 13:23

              Tom,

              That's what I said at the end- it doesn't stick the texture to the vertices or edges, but it does stick the texture to the face. Once you've hit Enter you can move or rotate the unedited face about as much as you want and the texture will stay in place- i.e. SU seems to create a new UV coordinates plane which is fixed coplanar to the face. In this way the texture stays fixed until you edit the vertices or edges at which point the texture "moves" or rather the texture actually stays fixed on the face's UV plane while the faces geometry floats around on it. Like I said, it wouldn't be SU's answer to pelt or shrink mapping, but each face having its own UV coordinates plane would still be an enormous help in SU.

              Jackson

              1 Reply Last reply Reply Quote 0
              • R Offline
                remus
                last edited by 12 Jun 2009, 13:49

                Doesnt that happen anyway? i.e. without the right click->position texture thing.

                http://remusrendering.wordpress.com/

                1 Reply Last reply Reply Quote 0
                • GaieusG Offline
                  Gaieus
                  last edited by 12 Jun 2009, 13:57

                  If you don't position the texture on the face,it will be positioned to the world axes. If you start moving the face around, you can see the texture "move" relative to the face but "stick" absolute to the WAxes. This can be "fixed" by positioning the texture on the face but it won't get really stuck to it but as Jackson says, it will stick to another "plane" that is "positioned" to the face itself, not the WAxes.

                  Still if you start editing any vertex (say just start moving an edge), the texture won't follow but remain on this "invisible plane".

                  Hard to explain something hat only virtually exists ๐Ÿ˜ฎ and maybe is not even so just I make up these "synonyms" to explain what I experience. ๐Ÿ˜ฒ

                  Gai...

                  1 Reply Last reply Reply Quote 0
                  • R Offline
                    remus
                    last edited by 12 Jun 2009, 14:42

                    I see what you mean, i'd never noticed that before, for some reason ๐Ÿ˜•

                    http://remusrendering.wordpress.com/

                    1 Reply Last reply Reply Quote 0
                    • GaieusG Offline
                      Gaieus
                      last edited by 12 Jun 2009, 14:47

                      Well, it's not apparent until you encounter a certain case...

                      Gai...

                      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