Getting BaseMaterial from BaseObject



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 12/03/2008 at 02:01, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   10.5 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hello,

    I am currently writing an export plugin for C4D Version
    10.5. So far its working fine, however I am somehow
    stuck with the following:

    - I can iterate through all BaseObjects and I can access
    the mesh data as well as the texture coordinates as
    well as normals (if a phong tag is attached)

    - However I do not know how I can get the BaseMaterial
    of a BaseObject. I can do the following:
        
        BaseObject *op;
        TextureTag *ttag = op->GetTag( Ttexture );
        BaseMaterial *mat = ttag->GetMaterial();

    But this only works if the object has a texture
    assigned, which is not always the case for the objects
    we model.

    My question is: How do I get the BaseMaterial of a
    given BaseObject?

    Regards,
    Mark



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 12/03/2008 at 10:07, xxxxxxxx wrote:

    The Material is only linked to the Object through the Texture tag (or some similar tag). How else are you getting materials assigned otherwise?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 12/03/2008 at 10:18, xxxxxxxx wrote:

    Hello Robert,

    thanks for the quick reply.

    I can create a new material in C4D without a texture.
    I can then assign this material to an object.
    So the object has a material but the texture tag
    will return zero.

    We use this for example for objects with no texture,
    that have only a single color or a transparency.

    That's where I am confused.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 12/03/2008 at 11:29, xxxxxxxx wrote:

    You are doing this via the Material:Assign tab? I don't think there is any connection the other way though - it is only connecting the Material to the Object, the Object doesn't know what Materials to which it is assigned otherwise. Therefore you'll need to work the other direction and get the Objects assigned to each Material.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 13/03/2008 at 02:18, xxxxxxxx wrote:

    Sorry, to ask you further questions.

    So if I have assigned a material to lets say a simple sphere and this material has no texture assigned to it, then I cannot get the material this object is using from the sphere object itself?

    How then would I get all the objects a certain BaseMaterial is assigned to? I have the following loop:

    ------------------
    for (BaseMaterial *mat=doc->GetFirstMaterial(); mat!=0; mat=mat->GetNext() )
    {
    // what to do here to find out what objects this material uses?
    }
    ------------------

    I would appreciate any hint. Maybe I am still not understanding an important point of how Cinema 4D works?!



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 13/03/2008 at 04:39, xxxxxxxx wrote:

    You have to use the MatAssignData class. Here a little example how to use it.

    mat is a BaseMaterial

    > \> GeData d; \> if(mat->GetParameter(DescLevel(ID_MATERIALASSIGNMENTS),d,0)) \> { \>      MatAssignData \*mad = (MatAssignData\* )d.GetCustomDataType(CUSTOMDATATYPE_MATASSIGN); \>      if(mad)     GePrint("found it"); \>      GePrint(LongToString(mad->GetObjectCount())+" objects"); \> } \>

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 14/03/2008 at 01:25, xxxxxxxx wrote:

    Hello Matthias,
    thank you for this information. This gives me the information I was looking for.

    I would like to make one more comment here. The BaseList2D pointer I get from ObjectFromIndex is not the object I am looking for. I have to use GetMain() then I am finally getting the object I am looking for. The code snippet below shows this:

    > `

      
    \>  GeData d;  
    \>  if (mat->GetParameter(DescLevel(ID_MATERIALASSIGNMENTS),d,0))  
    \>  {  
    \>      MatAssignData *mad = (MatAssignData* )d.GetCustomDataType(CUSTOMDATATYPE_MATASSIGN);  
    \>      if (mad)  
    \>      {  
    \>        if ( mad->GetObjectCount()>0 )  
    \>        {  
    \>          for (int i=0; i<mad->GetObjectCount(); i=i+1)  
    \>          {  
    \>            BaseList2D *bl2d = mad->ObjectFromIndex( stl.doc, i);  
    \>            bl2d = bl2d->GetMain();  
    \>            // bl2d is finally the object this material is assigned to  
    \>          }  
    \>        }  
    \>      }  
    \>  }  
    \>  
    

    `

    For some reason the

    command don't show the + sign in my browser.  
      
    regards,  
    Mark  
    

Log in to reply