Hi!
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
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.
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?
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.
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.