How to get a texture's size?

I created a textured material in sketchup 2014, and set its texture’s size to 0.4m*1.12m. Then I used SUTextureGetDimensions to get the texture’s size and t&s scale factors. I found that i couldn’t get the right size in meter by

width = pixelwidth * s_scale * 0.0254
height = pixelwidth * t_scale * 0.0254

I found these two formulas at the page How should i use s and t scale factor from SUTexture?.

My texture size is 109*304 pixels. The width and height properties in the Material Browser are 0.40m and 1.12m. The s&t scale factors I got are 0.06325 and 0.02268. So, how can I get 0.40m from 109 and 0.06325?

You used pixelwidth in your height calculation there.

However, SUTextureGetDimensions return the model width and height along with s&t scale. It looks like you are trying to compute what SUTextureGetDimensions already gives you. Where did you get the pixelwidth from? Did you mistake the width and height out params to be pixels instead of model size?
Note that SketchUp’s internal units are inches - you will not get the values in the model’s unit.

Sorry, it’s a clerical mistake. The second pixelwidth should be pixelheight.

Where did you get the pixelwidth from?

pixelwidth and pixelheight are SUTextureGetDimensions’s out params width and height. 0.0254 is for the convertion from inches to meter.

It looks like you are trying to compute what SUTextureGetDimensions already gives you.

I’m trying to calculate the model width and height by using SUTextureGetDimensions return values. Does SUTextureGetDimensions do return model size but not picture size? When i used SUTextureWriteToFile to save the texture to disk, its size is 109*304, so i think SUTextureGetDimensions return picture’s size. Am i wrong about this?

No - it’s pixel size. Sorry I confused the C API and the Ruby API.

If so, what’s wrong with this formula(width is the model width in meter)?
width = pixelwidth * s_scale * 0.0254
Is there any other way to calculate the texture’s size shown in the Material Browser? Please help.

Do you have a sample model with that material, and the snippet you use to get the values you use?
I wonder if there is something else in play here…

test.skp (27.5 KB)
This is my test model, it’s just a face.
Here is my code,

size_t picWidth = 0;
size_t picHeight = 0;
double sscale = 1.0;
double tscale = 1.0;
SUTextureGetDimensions(texture, &picWidth, &picHeight, &sscale, &tscale);

double modelWidth = picWidth * sscale * 0.0254;//Is modelWidth supposed to be 0.4?
double modelHeight = picHeight * tscale * 0.0254;

Ach! The API and docs aren’t very helpful here. I’m not sure what the original intent was. Need to look into that.

But to answer your question:

// This gives you the width and height of the texture in inches.
// This the same values that the Ruby API returns.
double model_width = 1.0 / scale_s;
double model_height = 1.0 / scale_t;

Thank you. I have figured out what scale_s and scale_t mean by trying several special textures. However, I also found that scale_s and scale_t can only be used when to calculate UVs on group objects and component objects. So, if one face is attached with group material, we should multiply the stq coordinates returned by SUMeshHelperGetSTQCoords or SUUVHelperGetUVQ by s&t scale to get the right UVs while we shouldn’t if the face is attached with its own material returned by SUFaceGet*Material. Do I mistake anything?


Just to underline that nifh80s gave the solution to this non trivial, non documented problem. It would be very smart if this information appeared somewhere in the official documentation.


how to multiply,can someone give me some advice,thanks.