Setting texture coordinates of face(s) explicitly


#1

Referring to the image above, I want the result as seen in the left but I get result as seen on right in SketchUp after translating.

To the best of my knowledge, considering functions exposed in the current SketchUp SDK, there doesn’t seem to be a way to specify texture coordinates of a face explicitly. As you can see in the documentation of classes (see below) which deals with texture coordinates of faces, there is a better control over reading texture coordinates but not necessarily in setting texture coordinates.

  1. Texture Writer: There are SUTextureWriterGetBackFaceUVCoords and SUTextureWriterGetBackFaceUVCoords functions but no equivalent ‘set’ functions.
  2. UV helper: There are SUUVHelperGetFrontUVQ and SUUVHelperGetBackUVQ functions but no equivalent ‘set’ functions.
  3. Face: There is SUFaceGetUVHelper function but no equivalent ‘set’ function.

Am I missing something? If not, I hope this functionality will be added in next version of SketchUp SDK. Thanks!


#2

http://www.sketchup.com/intl/en/developer/su-api/struct_s_u_material_input.html


#3

Ah! I remember bumping into material_input. Problem is it works with faces with up to 4 vertices. Generally the faces we generate have more than 4 vertices and to maintain maximum level of inter-exchangeability between our format and SketchUp, breaking faces down to triangles or quads is something we don’t want to do.


#4

hm… I need to look into that one. I’m more familiar with the Ruby API. @bugra? @Paul?
In the Ruby API you provide a set of UV and Point3d objects - it’s not tied to the vertices. The Point3ds only have to be on the plane of the face. I’m not sure why the C API require vertices…


#5

Any progress on this issue?


#6

Is anyone looking into it? @tt_su @bugra


#7

Is anyone looking into it? @Paul


#8

Hi,

I admit I hadn’t looked into it until now, but thanks for the ping.

I think the problem is that Face has set front/back material functions, but don’t have vertices and uvcoords as a parameter, so perhaps we need a new function for Face so that it can properly map the texture.

I’m no expert on UV coordinate mapping, so I may not have this right. I come to this conclusion because our C++ API has these methods for Face:
SetFrontMaterial(material, numpoints, vertices[], uvcoords[]);
SetBackMaterial(material, numpoints, vertices[], uvcoords[]);

Do you think that would solve the issue you’re having?

Thanks,
Paul


#9

SUGeometryInput is currently the only way to map textures on faces.

This is not accurate. You can create faces with arbitrary number of vertices. However, you can use up to 4 vertices to map a texture on the face. I am not sure how you could have more than 4 uv points on a mapping anyway. Do you need that?


#10

Hi Paul,

Thank you for getting back to me.

Current versions are as follows:

SU_RESULT SUFaceSetFrontMaterial(SUFaceRef face, SUMaterialRef material);
SU_RESULT SUFaceSetBackMaterial(SUFaceRef face, SUMaterialRef material);

So adding numpoints, vertices[], and uvcoords[] parameters as you suggested will be helpful.

I would also like to point out that I can specify texture coordinates for faces with up to 4 vertices using SUMaterialInput. However, we need to be able to specify them for faces with more than 4 vertices. Can something be done about it too?

Thanks!
-Prasad


#11

Just saw @bugra 's post : “You can create faces with arbitrary number of vertices. However, you can use up to 4 vertices to map a texture on the face. I am not sure how you could have more than 4 uv points on a mapping anyway. Do you need that?”

I was under the impression that each uv coordinate corresponds to a face coordinate. Since, uv coordinates has limitation of 4, I thought it will work with faces up to 4 vertices. Apparently that was an incorrect assumption. Hopefully, 4 uv points will suffice. I will experiment a little and get back to you.

Thanks for the pointer!


#12

I´d prefer to match the Ruby API which maps 3dpoint to UVs instead of vertices to UVs. Gives much greater flexibility.
http://www.sketchup.com/intl/en/developer/docs/ourdoc/face#position_material


#13

I personally prefer what @tt_su is suggesting.


#14

Yeah, for any new API we add for this purpose, we should use points instead of vertices. Alas, the current stuff works with vertices and it works fine for most cases.


#15

Any idea when it might be incorporated in the new API? We have a release of an update of our application coming up in a month. It will be great if we could offer the correction to our SketchUp translators.

In our application we allow users to define texture origin. It seems @tt_su’s suggestion will allow for more flexible way to implement it.

Thank you!
-Prasad


#16

Prasad, we can’t really put a timeline on the implementation but this is an issue we’ve been talking about recently. Please keep checking with us and thanks for using the SDK.


#17

Sounds good, Burga! I am looking forward to it. Thanks.


#18

Hi Prasad,

Given that it’s a C API and we can’t overload functions, we would likely add new functions with the additional parameters. We do all we can to avoid breaking existing code using the API.

Regarding supporting using more vertices, that would imply shearing of the texture. As I said, I’m not the expert on this, but I don’t think we support shearing. Can you elaborate on what you’re trying to do, and how you would use the SketchUp UI or Ruby to do that?

Thanks,
Paul


#19

Hi Paul.

I simply want to specify texture coordinates for each face vertex explicitly. It is required for our SketchUp translators which use C++ SDK. There is no SketchUp GUI or Ruby API involved.

I still have problems understanding how I can explicitly specify texture coordinates for vertices of faces with more than 4 vertices using SUMaterialInput. Our translator generates one texture coordinate per face vertex and I want to use those texture coordinates for applying texture to the face.

If I understand correctly it is possible using Ruby API but not with C++ SDK. If a function equivalent to Ruby API is exposed to C++ SDK then it will be very useful.

Thanks!
-Prasad


#20

You only need up to 4 vertices to define any mapping that can be defined in SketchUp. Just use UVs from any 4 non-collinear vertices.

Here’s an example C++ project that maps a texture to a face with 6 vertices. Note that I’m using only 3 UV coordinates.
TextureMapping.zip (89.8 KB)
You can extract this into the SDK package under samples/C++ and it should compile.

Here’s the face it generates:

Let me know if you have questions on the code.


Vertices and Indices with SketchUp C API
Question about material input