Some questions about Textured material and ColorizedTexture material

Hi Experts,

I am trying to export SketchUp material. In the file …\SketchUpAPI\model\material.h, there is enum SUMaterialType with three material types.

/**
@enum SUMaterialType
@brief Indicates material type.
*/
enum SUMaterialType {
  SUMaterialType_Colored = 0,     ///< Colored material
  SUMaterialType_Textured,        ///< Textured material
  SUMaterialType_ColorizedTexture ///< Colored and textured material
};

For the material type “SUMaterialType_Textured”, we only assign a texture onto a face. However, we still get color information from the function “SUMaterialGetColor()”. My question is what the color is? Is it calculated from the pixel of texture image file?

For the material type “SUMaterialType_ColorizedTexture”, we can assign a color and a texture onto a face. When calling the function “SUTextureWriteToFile()” to save the texture file, the color is also applied onto the image file. My question is: material has carried color information, why the color is applied to the image file during writing texture into disk file?

I have the same questions. Who can answer the question?

A search of the developer categories on this subject:

… finds …

Hi Dan,

For Colorized texture, I have no questions.

For the material type “SUMaterialType_Textured”, we only assign a texture onto a face. However, we still get color information from the function “SUMaterialGetColor()”. The question is what the color is? Is it calculated from the pixel of texture image file?

Do you know what the color is for the material type “SUMaterialType_Textured”?

According to Ruby API document, the answer is yes. Please see the link:

I assume the C API should be the same.

And the Ruby API doc says …

If it uses a Texture, this will return the average color.

So yes, there is some calculation going on.

I can say that API “parity” is a public stated goal of the Extensibility Team of the SketchUp Development group.

In the thread I referenced (you should read it in it’s entirety,) Thomas gives pseudo code and refers to the Ruby API method …

He also talks about the C API lacking some functions in this regard back in September of 2017, just before the 2018 version came out.

But then in the "version.txt"of the C API SDK is listed a new function for ver 6 (2018,) released in November of 2017, we have listed …

  • SUTextureGetAverageColor()

So it appears that it did make it into the 2018 C SDK release (C API ver 6.)

Hi Dan,

Thanks for your detailed explanation. I am using the 2018 C SDK release (C API ver 6). I have no question about the function SUTextureGetAverageColor().

My question is:
For the material type “SUMaterialType_Textured”, we only assign a texture onto a face. However, we still get color information from the function “SUMaterialGetColor(), not from SUTextureGetAverageColor()”. My question is what the color got from SUMaterialGetColor() is? Is it calculated from the pixel of texture image file?

Thanks

Hi,
I can’t see a reason for SUMaterialGetColor to return the average color for a textured-only material. Can you post a minimal code example that duplicates the issue?

I think I see what’s happening. When you set the texture on a material using SUMaterialSetTexture, the average texture color is applied to the material. So when you call SUMaterialGetColor, you get this average texture color back.

2 Likes

Yup, you’ll also see the colour change in the UI.

1 Like

So the question that follows is, is this expected behavior or is it a bug ?

@bugra @DanRathbun and @tt_su Have any conclusion for the question “Is this expected behavior or is it a bug”?

I don’t believe this is a bug. You can see this behavior in SketchUp’s UI as well. If you apply a textured material to a surface and edit that in-model material, you’ll see that it assumes the average texture color. So even if you remove the texture (i.e. check off ‘Use texture image’), the material color will remain somewhat close to the texture color. At least that’s what I believe was the rationale.

2 Likes

Hi @bugra,

Thanks for your information. I agree with your point.
Maybe we can add some comments on the API SUMaterialGetColor() to tell SKP clients that what the color is when texture type is pure textured.

Thanks a lot again for your (@bugra @DanRathbun @tt_su) help. I have no questions about texture and materials.

1 Like