Get Material from a PolygonObject [SOLVED]
-
On 18/04/2015 at 09:52, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R16
Platform: Windows ;
Language(s) : C++ ;---------
Hi all,I'm writing a simple export-plugin for a game I'm coding. The exportformat is simliar to the wavefront (*.obj)-format. The plugin can get all verticies, polygons and normals but I also want to save the color in the exported file. To be clear, I'm only using lowpoly models and they have only colors in rgba so this shouldn't be so complicated. But I have no idea how to get the materials per polygon from my object.
Is there any simple hint you know?
Here's my Code: http://pastebin.com/bRAegJPdRegards,
HumpaLumpa007 -
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 -
On 20/04/2015 at 17:37, xxxxxxxx wrote:
Sebastian explained it better than I was going to. I spent some time yesterday considering a response to this but realized that saving the 'color per polygon' by material was going to be a crapshoot and thought better of it. If you are using a bitmap image on the color channel, the complexity is already growing (as you then need to determine what the *average* color is on the polygon by sampling the image texture in the UV space of the polygon).
To add to Sebastian's response, I'd say that you should consider, qualify, and determine what you need to export in this regard under the various possible circumstances. For instance, if a single color per polygon is the only requirement, you might want to go through the color channels and UV space and compute each polygon's 'color' prior to export using either the designated color or the aforementioned image sampling technique). Then the export process will be just a matter of accessing these precomputed values and writing them to the export file.
-
On 24/04/2015 at 15:30, xxxxxxxx wrote:
First thanks for your help Sebastion and kuroyume!
I finished this Plugin and it's working as it's supposed to do!