Exporting UVs for Groups via PolygonMesh
-
Hi, I have trouble exporting UVs from groups in my Ruby plugin.
When creating a group and then assigning a material to the whole group there seem to be a problem with generating UVs. Textures show up correctly in sketchup but when iterating through all faces in the group, and converting them to polygon meshes, UVs are incorrect.
It's easily fixed by exploding the group and then group it again, but that shouldn't be necessary. Also the UVs are slightly changed when exploding. I haven't tried using the UVHelpers in the script though, might get correct UVs then. Nonetheless I think it ought to be fixed in future versions of sketchup.
Have anyone noticed the this problem?
-
I think this is because a texture has to be applied directly to a face to contain any uv information.
thats why you can't right click a group and choose the texture position options - SketchUp has no idea which of all the faces within the group you are refering to. neither is it possible to select several faces at once to position a texture. -
@plot-paris said:
I think this is because a texture has to be applied directly to a face to contain any uv information.
thats why you can't right click a group and choose the texture position options - SketchUp has no idea which of all the faces within the group you are refering to. neither is it possible to select several faces at once to position a texture.But still you can texture a whole group and sketchup generates some UVs for its internal use. And I suspect there's no way to get these coordinates from a ruby script?
-
eczkchtl, your name, how to keep it in mind? makes me real nervous to read and typing
-
try and apply a 1m x 1m texture on :
- a face 1m x 1m
- a face 1m x 1m inside a group
- on a group that contains a default 1m x 1m face
you can check your code on this and see what is wrong (usually inside a group there is wrong units).
I use also http://bgdm.katorlegaz.com/lscm_tute/Tute_Images/UV.jpg as test texture to see when it has wrong direction -
@unknownuser said:
try and apply a 1m x 1m texture on :
- a face 1m x 1m
- a face 1m x 1m inside a group
- on a group that contains a default 1m x 1m face
...
Yes, if you group the face, set material, move the group and then explode it, the texture will be offset to the coordinates of the new position. I don't mind this behavior. Maybe there are other grouping "quirks" also.
However, this has little to do with my problem
At least the groups have some UVs which are visible in sketchup and the artist may be fine with these if they look OK. Then when exporting they get mashed. When you get the UVs with PolygonMesh from a script they are just random large numbers (i.e. not initialized) in the group-before-material case. -
I didn't say anything about exploding. if you will do that test you will be able to see what the problem is and code accordingly.
@unknownuser said:
group-before-setting-material-case they are just random large numbers
if a face exists in a group there are two possibilities:
- default material -> will use the group material with simple planar UV if exists, otherwise default front/back color
- has material -> will use the material with it's UV data
if you have a group with all faces default and no group material (or parent if it is nested) then ignore the UV
-
@unknownuser said:
- default material -> will use the group material with simple planar UV if exists, otherwise default front/back color
It is this case which is a little torublesome, with a default material for the group and no material for the faces in the group. So how do I get these "simple planar UV" coordinates? And do I need to do some conversion to get the UVs which in the end are used for rendering?
What I do now:
for each face in group; mesh = face.mesh(5) # Get points, normals and UVs for front faces for each vertex; uv = mesh.uv_at(index,1)
EDIT:
I think i've got it now. The UVs from PolygonMesh are in the case above not rendering UVs but instead need to be divided by the width and height of the material. Me getting uninitialized values was just an error in the importer-program which read the files I've exported. It's still peculiar that getting UVs with PolygonMesh for ungrouped faces gives actual rendering UVs while with a group material they need to be converted. We end up with some extra (unnecessary?) special cases.
-
@eczkchtl said:
We end up with some extra (unnecessary?) special cases.
I am glad you have found the solution. What about projected \ photomatched textures? Have you tried exporting them? We end up with a lot of extra very special cases There is no built-in method, I am aware of, that would give you an answer if a face is being painted with projected texture or not!
Advertisement