SUFaceIsFrontMaterialAffine is false, SketchupAPI how to obtain correct texturecoord

I am dealing with a sketchup file.
The right result:
pastedImage (1)
but, I have a error result:
pastedImage

A texture is is stretched onto mesh, but in my application, this is repeated on the mesh.

I find SUFaceIsFrontMaterialAffine is false, use SUUVHelperGetFrontUVQ to find textureCoord,but textureCoord is not correct.

so, How to obtain correct texcoord?

Check for open issues in the GitHub tracker …
https://github.com/SketchUp/api-issue-tracker/issues?q=is%3Aissue+is%3Aopen+UV

Did you check texture scale for this material?
You’ll need to multiply UVs with texture scale.
(more or less something like that):

SUMaterialGetTexture(matRef, &textureRef);
SUTextureGetDimensions(textureRef, &width, &height, &scaleU, &scaleV)
(...)    		

// Load uvs.
uvs.reserve(numberOfVertices * 2);
for (int i = 0; i < numberOfVertices; i++)
{
   // Affine correction - approximation
   float q = (float)frontUVQ[i].z;

   // Texture scale.
   uvs.push_back((float)frontUVQ[i].x / (scaleU * q));
   uvs.push_back((float)frontUVQ[i].y / (scaleV * q));
}

Thanks for your reply.
but, I didn’t find an effective solution from this GitHub tracker.

Thanks for your reply.
The advice you give is important, but it is not the main reason.
this model has eight meshs and one material,the texture coordinate range of each face is 0 ~ 1。If it has a scaling factor,expected display effect is that the repeated texture of this mesh is more or partial.

Could you share the model? (or at least the affected part of it?)

ok.2015.skp (4.1 MB)
look forward to your reply.

Hmm, actually, everything works as expected for me.

Exported DAE file:
mesh.zip (169.1 KB)

SDK2017+

	SUMeshHelperRef polyMesh = SU_INVALID;
	SUMeshHelperCreate(&polyMesh, faceRef);

	size_t result;
	size_t nVertices = 0;
	size_t nIndices = 0;
	
	if (SUIsValid(polyMesh))
	{
		SUMeshHelperGetNumVertices(polyMesh, &nVertices);

		std::vector<SUPoint3D> points(nVertices);
		std::vector<SUPoint3D> uvs(nVertices);
		std::vector<SUVector3D> normals(nVertices);

		SUMeshHelperGetVertices(polyMesh, nVertices, &points[0], &result);
		SUMeshHelperGetNormals(polyMesh, nVertices, &normals[0], &result);
		SUMeshHelperGetFrontSTQCoords(polyMesh, nVertices, &uvs[0], &result);

		SUMeshHelperGetNumTriangles(polyMesh, &nIndices);

		nIndices = nIndices * 3;
		std::vector<size_t> indices(nIndices);

		SUMeshHelperGetVertexIndices(polyMesh, nIndices, &indices[0], &result);

		// Release polyMesh
		SUMeshHelperRelease(&polyMesh);

        (...)

Dumped data:

[Geometry: faces(16) points(32) uvSets(1)]

Tri #1:
   3: V(  0.013,   0.245,   0.054) N( -0.865,   0.000,  -0.501)  UV(  0.746,   0.984)
   0: V(  0.013,   0.292,   0.054) N( -0.866,   0.000,  -0.500)  UV(  0.746,   0.010)
   1: V(  0.024,   0.244,   0.039) N( -0.705,   0.000,  -0.709)  UV(  0.878,   0.985)

Tri #2:
   2: V(  0.024,   0.292,   0.039) N( -0.707,   0.007,  -0.707)  UV(  0.878,   0.010)
   1: V(  0.024,   0.244,   0.039) N( -0.705,   0.000,  -0.709)  UV(  0.878,   0.985)
   0: V(  0.013,   0.292,   0.054) N( -0.866,   0.000,  -0.500)  UV(  0.746,   0.010)

Tri #3:
   7: V(  0.024,   0.292,   0.039) N( -0.707,   0.007,  -0.707)  UV(  0.878,   0.010)
   4: V(  0.038,   0.292,   0.029) N( -0.303,   0.859,  -0.412)  UV(  0.981,   0.015)
   5: V(  0.024,   0.244,   0.039) N( -0.705,   0.000,  -0.709)  UV(  0.878,   0.985)

Tri #4:
   6: V(  0.038,   0.243,   0.029) N( -0.609,   0.000,  -0.793)  UV(  0.980,   0.986)
   5: V(  0.024,   0.244,   0.039) N( -0.705,   0.000,  -0.709)  UV(  0.878,   0.985)
   4: V(  0.038,   0.292,   0.029) N( -0.303,   0.859,  -0.412)  UV(  0.981,   0.015)

Tri #5:
  11: V(  0.006,   0.244,   0.105) N( -0.966,   0.000,   0.260)  UV(  0.286,   0.989)
   8: V(  0.006,   0.292,   0.105) N( -0.966,   0.000,   0.259)  UV(  0.286,   0.010)
   9: V(  0.004,   0.245,   0.088) N( -1.000,   0.000,   0.001)  UV(  0.438,   0.989)

Tri #6:
  10: V(  0.004,   0.292,   0.088) N( -1.000,   0.000,   0.000)  UV(  0.438,   0.010)
   9: V(  0.004,   0.245,   0.088) N( -1.000,   0.000,   0.001)  UV(  0.438,   0.989)
   8: V(  0.006,   0.292,   0.105) N( -0.966,   0.000,   0.259)  UV(  0.286,   0.010)

Tri #7:
  15: V(  0.024,   0.292,   0.136) N( -0.707,   0.000,   0.707)  UV(  0.046,   0.010)
  12: V(  0.024,   0.244,   0.136) N( -0.705,   0.000,   0.709)  UV(  0.047,   0.986)
  13: V(  0.030,   0.292,   0.141) N( -0.609,   0.000,   0.793)  UV(  0.016,   0.010)

Tri #8:
  14: V(  0.030,   0.243,   0.141) N( -0.609,   0.000,   0.793)  UV(  0.017,   0.987)
  13: V(  0.030,   0.292,   0.141) N( -0.609,   0.000,   0.793)  UV(  0.016,   0.010)
  12: V(  0.024,   0.244,   0.136) N( -0.705,   0.000,   0.709)  UV(  0.047,   0.986)

Tri #9:
  19: V(  0.004,   0.245,   0.088) N( -1.000,   0.000,   0.001)  UV(  0.438,   0.989)
  16: V(  0.004,   0.292,   0.088) N( -1.000,   0.000,   0.000)  UV(  0.438,   0.010)
  17: V(  0.006,   0.245,   0.070) N( -0.966,   0.000,  -0.259)  UV(  0.596,   0.988)

Tri #10:
  18: V(  0.006,   0.292,   0.070) N( -0.966,   0.000,  -0.259)  UV(  0.596,   0.010)
  17: V(  0.006,   0.245,   0.070) N( -0.966,   0.000,  -0.259)  UV(  0.596,   0.988)
  16: V(  0.004,   0.292,   0.088) N( -1.000,   0.000,   0.000)  UV(  0.438,   0.010)

Tri #11:
  23: V(  0.013,   0.244,   0.122) N( -0.865,   0.000,   0.502)  UV(  0.152,   0.987)
  20: V(  0.013,   0.292,   0.122) N( -0.866,   0.000,   0.500)  UV(  0.152,   0.010)
  21: V(  0.006,   0.244,   0.105) N( -0.966,   0.000,   0.260)  UV(  0.286,   0.989)

Tri #12:
  22: V(  0.006,   0.292,   0.105) N( -0.966,   0.000,   0.259)  UV(  0.286,   0.010)
  21: V(  0.006,   0.244,   0.105) N( -0.966,   0.000,   0.260)  UV(  0.286,   0.989)
  20: V(  0.013,   0.292,   0.122) N( -0.866,   0.000,   0.500)  UV(  0.152,   0.010)

Tri #13:
  27: V(  0.006,   0.245,   0.070) N( -0.966,   0.000,  -0.259)  UV(  0.596,   0.988)
  24: V(  0.006,   0.292,   0.070) N( -0.966,   0.000,  -0.259)  UV(  0.596,   0.010)
  25: V(  0.013,   0.245,   0.054) N( -0.865,   0.000,  -0.501)  UV(  0.746,   0.984)

Tri #14:
  26: V(  0.013,   0.292,   0.054) N( -0.866,   0.000,  -0.500)  UV(  0.746,   0.010)
  25: V(  0.013,   0.245,   0.054) N( -0.865,   0.000,  -0.501)  UV(  0.746,   0.984)
  24: V(  0.006,   0.292,   0.070) N( -0.966,   0.000,  -0.259)  UV(  0.596,   0.010)

Tri #15:
  31: V(  0.024,   0.244,   0.136) N( -0.705,   0.000,   0.709)  UV(  0.047,   0.986)
  28: V(  0.024,   0.292,   0.136) N( -0.707,   0.000,   0.707)  UV(  0.046,   0.010)
  29: V(  0.013,   0.244,   0.122) N( -0.865,   0.000,   0.502)  UV(  0.152,   0.987)

Tri #16:
  30: V(  0.013,   0.292,   0.122) N( -0.866,   0.000,   0.500)  UV(  0.152,   0.010)
  29: V(  0.013,   0.244,   0.122) N( -0.865,   0.000,   0.502)  UV(  0.152,   0.987)
  28: V(  0.024,   0.292,   0.136) N( -0.707,   0.000,   0.707)  UV(  0.046,   0.010)

Thank you very much.
In your way, I did get the right result。
when SUFaceIsFrontMaterialAffine is false, we need SUMeshHelperCreate to create mesh and Calculate vetex, normal,texture coordinates。
If possible,can you help me to see what else I haven’t noticed?
this is the part of code.GSkpMeshImporterImpler.txt (26.4 KB)

Once again, thank you!

CRenderable* CSkpMeshImporterImpler::LoadMesh(const std::vector<SUFaceRef>& faces, bool isAffine)

(..)
    for (size_t i=0; i<faces.size(); ++i)
    {
		if (isAffine)
		{

(...)
			// Front Texture Coordinates
			std::vector<SUPoint2D> textureCoords(vertexCount);
			res = SUTextureWriterGetFrontFaceUVCoords(m_textureWriter, faces[i], vertexCount, &vertices[0], &textureCoords[0]);
			assert(res == SU_ERROR_NONE);
			for (size_t j = 0; j < vertexCount; ++j)
			{
				CVector2d texCoord(textureCoords[j].x / scaleU , textureCoords[j].y / scaleV);
				texCoordArr.push_back(texCoord.Vec2f());
			}

You need to apply texture scale for affine textures too. (div by scaleU and scaleV).

@649750084 Please stop double posting. It causes double notifications for members participating in this topic or category. Also please delete the 2 unneeded double posts above.


Thank you for your advice! :slightly_smiling_face:

I’m sorry for the trouble!
Thanks for your remind, I will pay attention next time.

1 Like