SUTextureGetDimensions scale issue

Hi all,

I am using SUTextureGetDimensions to retrieve the size and scale of a texture. But I have a scale problem.

For example, if I use the Sketchup material “Antique Brick”, the Sketchup GUI says it is 1.47 meters wide and 0.94 meters high, but when getting the scales with the SDK I get values such as 0.0172 and 0.027.

Some of your told me to multiply those values by a factor to be able to get from inch to meters and, from a visual point of view it looks OK even if the scales in meters are not the same as the ones in the Sketchup GUI. But for internal reasons, I really have to get the same value as the ones in the GUI.

(I hope I am clear in my explanation :wink: )

Does someone have an idea of how I can compute the GUI values from the values I get from the SDK function ?

Have a good day :slight_smile:

The GUI displays the dimensional values in the current model units. This will vary to how the user set the units. Internally the values are still in inches.

No, I told you to multiply the dimensional values by a conversion factor (0.0254 meters per inch) to get from inches to meters.

Scaling factors are not in any units ! They are just a scalar value (ie, a ratio.)

However, the GUI does not display the scale factor(s), it displays the dimensional values.

The width of the texture is 58.0 inches. Multiplied by 0.0254 (meters per inch) equals 1.4732 meters.
The height of the texture is 37.0 inches. Multiplied by 0.0254 (meters per inch) equals 0.9398 meters.
(This is exactly what the GUI is doing for it’s display in the Edit panel of the Materials inspector.)

Now … normally the scale factors for X (width) and Y (height) are the same if the aspect ratio between them is the same. (Ie, the chain symbol in the GUI is unbroken. If the chain symbol is broken then the texture is not uniformly scaled.)

Please be specific about what are the exact return values from calling the SUTextureGetDimensions function for the "Brick Antique 01" material’s texture.

And … whether the material is applied to the face directly or applied to the parent (group or component instance.)

Also whether the face (or parent) has been scaled.

Note that this function (according to the documentation) returns the texture dimensions in pixels not inches.

Be aware that there are issues in the API tracker …

Hi all,

Thank you Dan for your answer and for setting me straight: it seems I had not understood everything (and may be still do not).

So now I get that the GUI displays value based on the internal texture dimensions in inches. And also that the SUTextureGetDimensions gives me the size in pixels and also scales.

So in my case, the texture is directly applied to the face, no inheritance. The parent of the face is a component without any material.

When examining the material “Brick Antique 01” I get a pixel size of 384 x 256, a s_scale of 0.01724138 and a t_scale of 0.027 (I rounded the values). What I don’t understand is how I get the inch dimensions from those dimensions.

I am really puzzled.

Thanks again and have a good day :slight_smile:

According to the docs, the scaling values are not used when a textured material is directly applied to a face. So I don’t know why these values are what they are instead of 1.00 (for example.)

Yes, I agree this is a good question, so I added it to the C API Issue …
Issue 783 : C API missing ability to set the material size and referenced this topic thread.

The Ruby API has Sketchup::Texture#height() and Sketchup::Texture#width(), but the C API appears to lack these getters (to get the sizes in inches) and a setter method.

Hi all,

And thank you Dan, I think I understood this time. I hope this will be fixed because for the moment my converters are incorrect but I guess everybody wants their issues fixed right away :wink:

Thanks again and have a good day :slight_smile:

1 Like

Ordinarily we think of a scaling factor as a ratio.

For the “Brick Antique 01” material, we want to get 58.0 inches.

The image is 384 pixels wide and the scaling s_scale of 0.01724138. The product of these values is 6.62068992.
If we then divide the pixel width by this product we get 58.0. This seems weird.

It really reduces to the the width (with a bit of floating point error) equals the reciprocal of the scale values:

               pixel_width            1
inch_width = ----------------  =  ---------
          pixel_width * s_scale    s_scale

Hi all,

Wow it sems to work :slight_smile: I’ll try to code that.

Thanks for investigating that :slight_smile:

Have a good day

1 Like