Not all faces are mapping texture


#1

I am mapping my texture onto my model. Some of the side faces are not mapping. The texture on them is the correct. I checked to see if sometimes it was maybe not sending correct uvPoints, but it is always sending the points. Some of my points are smaller than 0.005, so I tried change those to just 0, but it did the same thing. Any idea what is causing this?

void SKPModel::AddFace(point3d *pPoints, SUMaterialRef mat, point2d *uvPoints, int count, int numFaces)
{
	SUEntitiesRef entities = SU_INVALID;
	SUComponentDefinitionGetEntities(component, &entities);

	SUGeometryInputRef input = SU_INVALID;
	SUGeometryInputCreate(&input);

	SUPoint3D* vertices = new SUPoint3D[3];

	SUPoint2D* uvCoords = new SUPoint2D[3];
	
	for (int i=0; i < count; i++) {
		SUPoint3D t;
		t.x = pPoints[i].x;
		t.y = pPoints[i].y;
		t.z = pPoints[i].z;
		vertices[i] = t;
	}

	for (int p=0; p < count; p++) {
		SUPoint2D a;
		a.x = uvPoints[p].x;
		a.y = uvPoints[p].y;
		uvCoords[p] = a;
	}
	
	SUGeometryInputSetVertices(input, 3, vertices);

	if(count > 2){
		SULoopInputRef loop = SU_INVALID;
		SULoopInputCreate(&loop);

	
		for(size_t j=0; j < count; j++)
		{
			SULoopInputAddVertexIndex(loop, j);
		}

		size_t face_index0;
		SUGeometryInputAddFace(input, &loop, &face_index0);
		
		SUMaterialInput mat_input;
		mat_input.material = mat;
		mat_input.num_uv_coords = 3;
		
		for(int k=0; k < 3; k++)
		{
			mat_input.vertex_indices[k] = k;
			mat_input.uv_coords[k] = uvCoords[k];
		}

		SUGeometryInputFaceSetFrontMaterial(input, face_index0, &mat_input);
		SUGeometryInputFaceSetBackMaterial(input, face_index0, &mat_input);
		
		SUEntitiesFill(entities, input, true);
	}

	delete[] vertices;
}

#2

Your 3d points for the faces or the UV points? You mean they are closer than 0.005 apart?

Have you checked the return value of your function calls? I’d add some return value checks and break into the debugger upon failure so you can inspect the input value.

I recommend you post examples that are complete and self-contained - that one can just hit build and run. Then it’s possible to see the whole picture of what is going on. My suspicion is that it’s something to do with the input you use to generate the mesh, but this is opaque to the code example.


#3

Btw, where is the component variable in SKPModel::AddFace coming from? I don’t see it defined anywhere.

I see the function is named SKPModel::AddFace - which indicate it’s adding a single face, but it’s using SUEntitiesFill. Are you adding a single face in each Entities collection?

SUEntitiesFill would assume the entities you fill into is already empty.


#4

I do use SUEntitiesFill in my add face. I am looping through getting three vertices and three uv points at a time. Then I use those to add the face.

I followed this code: Create faces with new SketchUp SDK C API


#5

But are you using SUEntitiesFill per face?
SUEntitiesFill is intended to be used on an empty Entities collection with a single SUGeometryInput containing multiple faces.


#6

Thanks I will change that


#7

I changed some things in my code.

   SUGeometryInputSetVertices(input, lsize, &vertices[0]);
    
    SULoopInputRef loop = SU_INVALID;
    SULoopInputCreate(&loop);
    
    for(size_t j=0; j < lsize; j++)
    {
    	SULoopInputAddVertexIndex(loop, j);
    }
    
   size_t face_index;
   SUGeometryInputAddFace(input, &loop, &face_index);

lsize is the size of the vertices[]. It’s not creating the faces like my old code. When I debug, the set vertices is correct, but my add face says that the loop is NULL and the the face_index is zero? I guess my problem is with loop input. I’m not really sure what it is doing?


#8

Have you checked the return value from the functions?