Accessing built-in textures?


#1

Hi all,

I can’t find anywhere in the documentation how you can access built-in textures (e.g. Metal_Aluminum_Anodized). I know that colors have plenty of pre-defined that can be accessed from the API, but how about textures?


#2

You can access materials in model, but currently the API does not allow to access materials in libraries that are not yet used in the model.
The “predefined” colors are not material objects from these libraries outside of the model, but they are just shorthands instead of writing the color code (r,g,b or #ff8800). When you use these names, a new color object is created, and you would create a new material object using this color object.

You can however access the currently selected material in the material browser even if it is not yet used in the model. You could ask the user to select the material, or you use only materials that the user already used in the model, or you import the materials you need (by creating new materials from provided texture images or by loading an skp component with the needed materials).

If your tool depends on specific materials, it would be safer to provide them with your tool instead of having external dependencies that maybe cannot be fulfilled (missing).


#3

A workaround is to create a component that has the needed material(s) in it. And load this component definition into the model using DefinitionList#load().
Then immediately afterward DefinitionList#purge_unused().


This approach requires you to distribute this material component with your plugin.