On 20/04/2015 at 08:48, xxxxxxxx wrote:
Hello and welcome,
in Cinema 4D materials are assigned to objects. When a material is assigned to an object a tag of the type "TextureTag" is created and added to the object. This tag stores the link to the used material.
If one wants to limit a material to certain polygons on an object two things are necessary. First a polygon selection is needed to define which polygons are selected. This selection is stored in a SelectionTag that is added the object. This SelectionTag has a name (like "Selection 1"). In a TextureTag this name can be used to reference that SelectionTag.
So to get the material of a given polygon index you have to first find out if a material is assigned to the given (polygon) object. To get that material, you have to find out if there is none, one or more TextureTags. To get one tag you can use GetTag(). But to get all tags you have to get the first tag (GetFirstTag()) and then loop through all tags using GetNext() on the current tag. To find out if the current tag is a TextureTag use GetType() to check if it is Ttexture.
When you have found a TextureTag you can access it's TEXTURETAG_RESTRICTION parameter to find out if it is only applied to a certain selection. The String returned is the name of a SelectionTag So again you have to check all tags on your object to find a SelectionTag (Type Tpolygonselection) and check if the name of a found SelectionTag is the name used in the TextureTag. If so you can access the selection stored in the SelectionTag with GetBaseSelect().
With that BaseSelect object you can now check for every polygon if it is selected (using IsSelected()) – and thus is using the material in question.
Please also notice that it is possible to add multiple materials (TextureTags) to an object and only the topmost material may be visible.
Best wishes,
Sebastian