# Not all faces are mapping texture

**URL:** <https://forums.sketchup.com/t/not-all-faces-are-mapping-texture/11156>\
**Category:** SketchUp SDK\
**Created:** [May 12, 2015, 3:37pm UTC](https://forums.sketchup.com/t/not-all-faces-are-mapping-texture/11156 "2015-05-12T15:37:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ecw](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@ecw](https://forums.sketchup.com/u/ecw)\
**Post date:** [May 12, 2015, 3:37pm UTC](https://forums.sketchup.com/t/not-all-faces-are-mapping-texture/11156/1 "2015-05-12T15:37:54Z")

</div>

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;
}

```

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [May 12, 2015, 5:49pm UTC](https://forums.sketchup.com/t/not-all-faces-are-mapping-texture/11156/2 "2015-05-12T17:49:06Z")

</div>

> [@ecw](#):
>
> Some of my points are smaller than 0.005

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.

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [May 12, 2015, 5:52pm UTC](https://forums.sketchup.com/t/not-all-faces-are-mapping-texture/11156/3 "2015-05-12T17:52:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ecw](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@ecw](https://forums.sketchup.com/u/ecw)\
**Post date:** [May 13, 2015, 6:35pm UTC](https://forums.sketchup.com/t/not-all-faces-are-mapping-texture/11156/4 "2015-05-13T18:35:27Z")

</div>

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 - #16 by igor\_sadchenko](http://forums.sketchup.com/t/create-faces-with-new-sketchup-sdk-c-api/5811/16)

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [May 15, 2015, 1:34pm UTC](https://forums.sketchup.com/t/not-all-faces-are-mapping-texture/11156/5 "2015-05-15T13:34:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ecw](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@ecw](https://forums.sketchup.com/u/ecw)\
**Post date:** [May 19, 2015, 7:11pm UTC](https://forums.sketchup.com/t/not-all-faces-are-mapping-texture/11156/6 "2015-05-19T19:11:40Z")

</div>

Thanks I will change that

---

<div class="post-metadata">

**Author:** ![ecw](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@ecw](https://forums.sketchup.com/u/ecw)\
**Post date:** [May 20, 2015, 6:18pm UTC](https://forums.sketchup.com/t/not-all-faces-are-mapping-texture/11156/7 "2015-05-20T18:18:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![tt\_su](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/tt_su/32/17_2.png) [@tt\_su](https://forums.sketchup.com/u/tt_su)\
**Post date:** [May 21, 2015, 9:26am UTC](https://forums.sketchup.com/t/not-all-faces-are-mapping-texture/11156/8 "2015-05-21T09:26:13Z")

</div>

Have you checked the return value from the functions?
