How should I get vertex uv texture?

Hi Experts,

In SketchUp SDK, it provides two ways to get vertex UV texture. One is to call the function SUTextureWriterGetFrontFaceUVCoords(); another is to call SUFaceGetHelperWithTextureHandler() and SUVHelperGetFrontUVQ(). I found we get different UV values.

Could someone please tell me what are the differences of UV from these two ways? If I want to handle the material from polymesh or layer or component, should i call which function to get UV coords?

I can get the scale factor for s, t from the function SUTextureGetDimensions(). How should I let vertex UV Coords and s,t scale work well together?

Appreciate for your help.

Thanks
Phenix

SketchUp use UVQ mapping, which allow for perspective distortion of textures. However, some applications doesn’t support UVQ and instead require only UV.

I’m not that familiar with the C API yet, and you didn’t mention what kind of data you got from the different methods, but I can explain how things work in the Ruby API and I expect it should translate to the C API:

In the Ruby API we have the UVHelper class. You get an instance by calling get_UVHelper without a TextureWriter and you can then query for UVQ data given a point on the plane of the face. (Usually one picks points from the vertex positions.)

One can get UV from UVQ by:

u = u / q
v = v / q
q = 1.0

Now, if you do feed the UVHelper a TextureWriter object which has been loaded with the face you query from it will return UV values. This is because when TextureWriter is given a face with a non-affine texture mapping and you then write out the texture for that face you get a new unique texture. Texture writer then return a new set of affine UV data the correspond to the generated texture. This was written specifically for exporters etc that doesn’t support non-affine texture mapping.

Back to the C API I expect the differences you see is related to this. I’ll have to dig more into exactly what each of the C API functions does though. (I’m relatively new to the team and haven’t done much with the C API.)

Hi Thomas,

Thanks for your quick response and detailed information.Here are detailed information of my issues.

I created a cylinder in SketchUp and only assigned material to face and didn’t assign the layer material to cylinder model. Then I imported it into my application by calling UVHelper plus TextureScale in S,T, then the material displayed as the left one in the snapshot. You will find the left one imported which is different from the original one in SketchUp in right picture.

Picture is attached for your reference.

I dumped some UV coords by calling these two ways for the same material
vertex_texture.zip (1.7 KB)

We will find the UV coords got by the above two ways are completely different. Detailed information please refer to the zip package.

I tried to use the UV coords got from SUTextureWriterGetFrontFaceUVCoords() plus the texture scale which is const value(1/25.4) in S, T, the material display in my application is correct and it matches to the origin in SketchUp. However, I don’t think it is correct behavior though the result seems to be correct.

Till now, I am talking the material attached on polymesh. If polymesh’s material is from Layer, then I must query UV coords from the function SUTextureWriterGetFrontFaceUVCoords() plus the texture scale got from SUTextureGetDimensions(). Otherwise, the result is wrong.

If polymesh has material; meanwhile a layer’s material is also assigned to polymesh, then the situation is another behavior. So I am confused now. How should I query UV Coords to handle different situations: material only from polymesh, Or material only from Layer, Or material from both?

Appreciate for your help.

Thanks
Phenix

Hi Thomas,

I compared the UV coords from the above two ways and parse some comparison result for your reference.

The texture scale is [S, T] : [0.038462, 0.055556].

Appreciate for your help.

Thanks
Phenix

Hi Experts,

Could someone please help me looking at my issue? @tt_su @bugra @Paul

I don’t know why the two different methods would return different values. They end up in the same code internally. Can you send a working sample code with a model? We’d be speculating otherwise.

Thanks,
Bugra