[REQ] Lock texture coordinates
-
@chris fullmer said:
I have no idea if something like this is possible in Ruby. Seems like it could be. I've never looked at textures because I rarely use them. But I do see how it would be nice if it worked the way you described in some instances.
Chris
Problem is: observers. In order for this to work you need to detect when the model changes. And that is a can of blood-thirsty angry spaceworms.
What I somewhat imagine a ruby would work: the selected face is set to "lock textures". The ruby then samples the UV coordinates from each vertex (or selected points required). When the geometry changes, the ruby would then reapply the texture co-ordinates.
Given the headache I've had with observers and UV mapping I'm not sure if I'd touch this with a 10' stick. ...at least not for now...Possible if it'd be acceptable to have a manual function to readjust the textures; might make things easier.
-
That idea of taking all the UV's and then re-applying them - is that fairly stable? I could incorporate it into shape bender, for eaxmple. So it wouldn't fix the problem outside of shape bender, but at least shape bender would be able to do it. AND I wouldn't have to touch any model observers.
Chris
-
When you set textures in SU you take a set of 3D points and specify some co-ordiates on the texture that should relate to them.
ie.
point1 -> 0.0, 0.0
point2 -> 0.5, 0.0
point3 -> 0.5, 0.5If point 1-3 was points in a rectangle face, then that would map the texture to tile half across the face.
So, what I imagine, is that applying the same UV co-ordinates to the same points when the points move, should make the texture 'lock'.
However, your Bender widget subdivides the mesh. So you'd have to sample the UV mapping after you subdivide, but before you apply the transformations.
-
Interesting, thats something I'll look into the next release of shape bender.
Chris
-
I'm listening guys, I'm listening...
(BTW Thom; this is one aspect I mentioned before)
-
Thanks for the explanation thomthom and Chris Fullmer.
I was hoping it would be possible but that's too bad.... Even if it were updated manually as thom said it would still be great because i think most people would just want the textured model for the final image and not while modeling, posing or whatever, it wouldn't work just for animations.
I'm starting to see ruby as a way for sketchup developers don't work to much...
-
I might be possible. It's just not very easy to do. At least not automatically. UV mapping is one of the areas in SU scripting that currently feel like a bit of black magic.
@unknownuser said:
I'm starting to see ruby as a way for sketchup developers don't work to much...
-
I mean that since ruby was introduced it was at the beggining a great way to add specific functions and automatize some actions, and then turn into part of sketchup develpment itself (every "new" stuff that it's presented it's a ruby plugin like DCs and sandbox, and this brings a dated engine to his knees) and the only hope to solve bugs and limitations of the software (we need a plugin to work as follow me was supost to, or just to draw a basic curve shape...) without google having to do nothing (the users work for advance features and solving bugs in the tools instead of the developers).
Keep in mind that we don't have any new modeling tool, animation tool or mapping/texture tool since follow me and sandbox in sketchup 4-5...but i believe that this develpment path was more a marketing decision then a development one, but still a (very) bad marketing decision
-
But back to topic, maybe the best way for this need is to export the mesh to other 3d package texture it there and import it again to set up the final scene, but the big problem here is that importers have big problems with keeping the textures in place with uvwarping or big meshs...But is there any better way to do this??
-
thanks thomthom.
That's what i suspected. with so many software i use to each task, i'm starting to mix up shortcuts keys lolol. -
A different application might be the way to go at the moment. SU isn't very ideal for rigging. And I'm a believer of using the right tool for the right job. I think that SU might not be the right tool for this.
-
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
-
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 -
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.
-
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 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..?
-
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.
-
Doesnt that happen anyway? i.e. without the right click->position texture thing.
-
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.
-
I see what you mean, i'd never noticed that before, for some reason
Advertisement