I’m coding an Sketchup exporter to gltf.
and I got trouble when i’m exporting texture from a none-parallel texture ( sorry its not clear, let me explain with image)
I do an extraction of the code. its seams that the distorsion of the texture isn’t export as expected by uv_at when they is distorsion.
I previsous code I was oblige to make uniq each texture, but its time coming, and I need to understand that
# grep the selected face
face = Sketchup.active_model.selection[0]
# grep the polygon ( here only a single triangle
polygon = face.mesh.polygon_at(1)
# grep the uv of the 3 vertices
uvw0 =face. mesh.uv_at(1,true)
uvw1 =face. mesh.uv_at(2,true)
uvw2 =face. mesh.uv_at(3,true)
If someone can explain me how to export the correct texture UV whith distorsion in Sketchup, thanks.
Many applications and file formats only use UV information fixed on each vertex to define UV mapping.
SketchUp actually have a transformation per face, that allow for these non-affine UV mappings. You’ll notice that our APIs report UVQ (not just UV). When the Q value is not 1.0 then there is a challenge to transfer the UV mapping to applications/format that only support UVs.
You have two options:
Use TextureWriter to generate a unique texture for each face with non-affine materials. (You will have to use UVHelper to get correct UV values.) This will yield an accurate visual representation of what you see in SketchUp. But the down side is that you might end up with a lot of unique textures, slowing down export. Also, it will mean the exported file will have a lot of unique materials. Whether any of these side effects is acceptable depend on your context.
“Normalize” the UVQ values into UV values:
uv = [uvq.x / uvq.z, uvq.y / uvq.z]
This will produce an approximation of the UV mapping. It won’t be visually identical, but in many cases close enough. It depends on the geometry. The upside is that you don’t need to generate unique materials.