UV coordinates fail to write into skp file

Hello Experts,

I am meeting an issue about writing the material texture. When I set the UV data into SUMaterialInput, I can see the UV coordinates are correct. When reading back the save sketchup file, I find some uv coordinates are lost.

So I did some code changes and tried to reproduce this issue in the sample project “TextureMapping”. There are two issues reported:

  1. when saving the files, save fails;
  2. Open the saved skp files, the texture is wrong.

Please see the modified the main.cpp file attached. Could you please help me take a look at where the problem is?main.zip (1.4 KB)

PS: For us, each face has its own uv coordinates; We can’t let two faces share the uv coordinates.
Appreciate for your help.

The texture file “SU_Logo_Color.png” used in main.cpp is
SU_Logo_Color

Thanks
Phenix

I just tried your example. (Btw, please include all related files in examples - such as textures or any other assets the example might try to load. Also, it would be good to know how you read back the UVs and more details in what you where observing. Makes it easier and faster to jump in to research the issues.)

Upon opening the generated file I get:

2019-08-13_14h27_23

2019-08-13_14h27_33

2019-08-13_14h27_39

This indicates an issue with the UV mapping of the second face mapped in the source.

However, I’m not seeing any obvious reason to why this is happening. The input data looks correct to me.

image

And when I inspect the UV data from the model if I don’t repair it - they look correct as well.

image

I think I have to step through the debugger and see what the validation is complaining about.

By the way, did you see the warnings when opening the model? Or have you set SketchUp to Ignore or Auto-repair?

@tt_su I attached the texture file used in main.cpp in the first post. Please get it.

The file “textured_face.skp” saved by me seems to be different from yours. textured_face.skp (48.6 KB)

The attached “textured_face.skp” is saved based on my modified TextureMapping project. When opening it in Sketchup Pro 2019 Version 19.0.685 64-bit, I get the same warning message as below:
image

If I click “Fix now”, the texture looks like:

If I click “Fix later”, the texture looks like:

When I read the skp file back, and the uv data I get are:


The uv data are wrong. Expect result should be like:

I modified main.cpp of the sample project “ReadingFromAskpFile” and please refer to the attached file in ReadingFromAskpFile.zip (44.9 KB)

You can add breakpoint at the end of main function, then you will see the output information about UV data when reading the skp file back:

The UV data of the second face is wrong.

Hmm… it looks like you observe the opposite of what I get. For me it looks correct before Fix Model. For you it appear to look correct after…

What version of the SDK are you using?

Have you tried with the latest SU2019.2? Any difference then?

No matter before fixing model or after fixing, both of result are wrong. The correct result should be

The SDK version is 19.0.753.0

After updating to the latest SU2019.2, I get the same result. I double compare my results to your results, your results are the same as mine.

For me, there are two issues:

  1. The saved skp file has wrong uv data.
  2. Due to the issue #1, when reading back, the uv data is also wrong. Do you observe the same UV data issue when reading the skp file back?

Could you please confirm if it is SKP SDK bug?

Hm… I wouldn’t expect that result. Your UVs look like this:

image

You have a UV point of V=0.5 and V=1.0.

That will produce this:

image

To get what you describe there you need V=1.0 for both the points.

I’ll be trying to figure out what’s causing the Fix Model issue.

Yes, you are right.

Thanks. May I think the fix model issue is causing the wrong uv data during reading the skp file back?

We found that the Fix Model errors are a bug in the validation itself. The UV mapping matrix created by your example is valid in both cases. If Fix Model is run then it will reset the coordinates for that face.

I am able to reproduce the same issue in the Ruby API:

model = Sketchup.active_model
face = model.selection.first

p face.outer_loop.vertices.map(&:position)

uvs = [
  Geom::Point3d.new(0.5, 0.0, 0),
  Geom::Point3d.new(1.0, 0.0, 0),
  Geom::Point3d.new(1.0, 1.0, 0),
  Geom::Point3d.new(0.5, 0.5, 0),
]

points = [
  Geom::Point3d.new( 57.5,   0.0, 0),
  Geom::Point3d.new(115.0,   0.0, 0),
  Geom::Point3d.new(115.0,  25.0, 0),
  Geom::Point3d.new( 57.5,  25.0, 0),
]

mapping = [
  points[0],
  uvs[0],

  points[1],
  uvs[1],

  points[2],
  uvs[2],

  points[3],
  uvs[3],
]

face.position_material(face.material, mapping, true)

I also found that just a slight noise in the UV data would avoid the validation error:

model = Sketchup.active_model
face = model.selection.first

p face.outer_loop.vertices.map(&:position)

uvs = [
  Geom::Point3d.new(0.5, 0.0, 0),
  Geom::Point3d.new(1.0, 0.0, 0),
  Geom::Point3d.new(1.0, 0.9999, 0),
  Geom::Point3d.new(0.5, 0.5, 0),
]

points = [
  Geom::Point3d.new( 57.5,   0.0, 0),
  Geom::Point3d.new(115.0,   0.0, 0),
  Geom::Point3d.new(115.0,  25.0, 0),
  Geom::Point3d.new( 57.5,  25.0, 0),
]

mapping = [
  points[0],
  uvs[0],

  points[1],
  uvs[1],

  points[2],
  uvs[2],

  points[3],
  uvs[3],
]

face.position_material(face.material, mapping, true)

However, if you are looking to produce this:

Then you won’t be affected by the validation error as that only happen with perspective UV mapping and in very particular edge case like in the right face of this test model.

These UV coordinates will produce the result as the above screenshot shows, and will not trigger any validation errors:

SUPoint2D uv_coords[4] = { { 0, 0 }, { 0.5, 0 }, { 0.5, 1.0 }, { 0, 1 } };
// ...
SUPoint2D uv_coords1[4] = { { 0.5, 0 }, { 1, 0 }, { 1, 1 }, { 0.5, 1.0 } };