InsertMaterial in ObjectData plugin [SOLVED]



  • On 27/04/2015 at 07:44, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R16 
    Platform:      Mac OSX  ; 
    Language(s) :     C++  ;

    ---------
    Hi,

    I've been looking for days to find some information on how to add a material inside an ObjectData plugin, with no results. Also I have searched the SDK for InsertMaterial, which I found once, inside particlevolume.cpp, which is a MaterialData plugin.

    Is it possible to add materials inside an ObjectData plugin?
    And if so, where should I start looking to get it done? (Methods or examples).

    Thanks for your help and time!
    Greetings,
    Casimir Smets



  • On 28/04/2015 at 06:22, xxxxxxxx wrote:

    Hi Casimir,

    actually I'm not sure about your actual intent, whether you are trying to create a new material and assign it to your generated object, or if you simply want to assign an existing material.

    In the first case the answer is, you can't do that in GetVirtualObjects(). As discussed in another thread, you are not allowed to change the scene from within GetVirtualObjects(). And inserting a new material obviously is a change to the current scene. So in this case you'd probably have to create a button in your interface and do the material creation in response to the button press.

    The case of an already existing material is much simpler. You'd simply create a TextureTag, set the material and assign the tag to your object via InsertTag().



  • On 29/04/2015 at 05:24, xxxxxxxx wrote:

    Hi Andreas,

    I want to create a new material and assign it to my generated objects.
    Ideally, I want my materials to be allready loaded (created) when my plugin starts.
    If that is possible, I can simply assign my materials to my objects in GetVirtualObjects, otherwise I should do it in another method.

    Is there no way to send a message which makes my materials?
    In the worst case even working together with another plugin which creates my materials?

    Thanks in advance for your help and time!
    Greetings,
    Casimir Smets



  • On 30/04/2015 at 02:44, xxxxxxxx wrote:

    Hi,

    Is it also not possible to load materials in GetVirtualObjects, or could this action be done?
    Thanks for your help and time!

    Greetings,
    Casimir Smets



  • On 30/04/2015 at 02:49, xxxxxxxx wrote:

    Hi,

    in order to use materials they need to be inserted into the scene. You can't do that from inside GVO.
    Instead you can do this inside Message() function. MSG_MENUPREPARE is the one you'll want to use. This message is send, when your plugin is called from the menu, so basically at the moment your object gets created. The corresponding data is the current BaseDocument.



  • On 30/04/2015 at 03:19, xxxxxxxx wrote:

    Hi Andreas,

    I was allready testing inside MSG_MENUPREPARE.
    My problem is, when I start my plugin, I get a bugreport.
    Here is the code I use:

      
    Bool MyPluginData::Message(GeListNode* node, Int32 type, void* data)  
    {  
      if (type == MSG_MENUPREPARE)  
      {  
          BaseDocument* doc = node->GetDocument();  
          BaseMaterial* myMaterial = BaseMaterial::Alloc(Mbase);  
          doc->InsertMaterial(myMaterial);  
      }  
      return true;  
    }  
    

    Does anybody see the problem here?
    Thanks in advance for your help and time!
    Greetings,
    Casimir Smets



  • On 30/04/2015 at 03:38, xxxxxxxx wrote:

    Hi Casimir,

    did you try to use the document provided by the message? The corresponding data is the current BaseDocument.



  • On 30/04/2015 at 05:52, xxxxxxxx wrote:

    Hi Andreas,

    If I put BaseDocument* doc inside my parameters of Message, I get no error when using my plugin, but the material doesn't show either in the material manager.
    Could this be because of some missing elements, or probably something else?
    Thanks in advance for your help and time!
    Greetings,
    Casimir Smets



  • On 30/04/2015 at 05:59, xxxxxxxx wrote:

    Hi Casimir,

    what do you mean by putting "BaseDocument* doc inside my parameters of Message"?
    Do you mean, you are changing the prototype of Message? That cannot work.
    Instead cast the data parameter (void* type) into a BaseDocument pointer. Like so:

    BaseDocument* doc = static_cast<BaseDocument*>data;
    

    Of course only in the case of MSG_MENUPREPARE.



  • On 30/04/2015 at 06:28, xxxxxxxx wrote:

    Hi Andreas,

    Yes, I was wrong, I changed the prototype of Message, which I shouldn't do.
    However, if I do it your way, with the static cast, I have the same result: no errors but nothing happens in the material editor...

    Does anybody see the problem here?
    Thanks in advance for your help and time!
    Greetings,
    Casimir Smets



  • On 30/04/2015 at 06:30, xxxxxxxx wrote:

    Hi,

    Also, as soon as I add: myMaterial->SetName("myMaterial"); the program crashes.

    Greetings,
    Casimir Smets



  • On 30/04/2015 at 06:44, xxxxxxxx wrote:

    Hi,
    Well, after some testing with GePrint I found out that

      
    BaseMaterial* myMaterial = BaseMaterial::Alloc(Mbase);   
    

    does nothing.
    Does somebody know how this could come?

    Greetings,
    Casimir Smets



  • On 30/04/2015 at 06:50, xxxxxxxx wrote:

    Hi,

    I guess I've found the problem and I think that it is a bug:
    If I replace:

      
    BaseMaterial* myMaterial = BaseMaterial::Alloc(Mbase);  
    

    with:

      
    BaseMaterial* myMaterial = BaseMaterial::Alloc(Mmaterial);  
    

    everything works fine.

    Greetings,
    Casimir Smets



  • On 30/04/2015 at 08:35, xxxxxxxx wrote:

    Hi,

    glad you got it working.
    As explained in this thread Possible bug with Mbase (material) this is no bug.



  • On 30/04/2015 at 11:08, xxxxxxxx wrote:

    Hi,

    Ok, that makes sense.
    But why is Mbase listed in Material Types?
    I think that's what confused me.
    Also, this thread my be marked as solved.

    Greetings,
    Casimir Smets



  • On 04/05/2015 at 05:11, xxxxxxxx wrote:

    Hi,

    Yet another question, related to this context.
    I've got my material working inside my plugin. My next problem is, how do I change the material's color if the user changes the color slider? I've tried inside MSG_CHANGE, but that doesn't work.

    Does somebody have any ideas on how to do this?
    Thanks in advance for your help and time!
    Greetings,
    Casimir Smets



  • On 04/05/2015 at 19:40, xxxxxxxx wrote:

    Assuming that you mean the basic color of the material, you need to get the Color channel and set its value where r, g, b are float values between 0.0 and 1.0:

    BaseChannel* bchan = mat->GetChannel(CHANNEL_COLOR);
    if (bchan)
    	mat->SetParameter(DescID(MATERIAL_COLOR_COLOR), GeData(Vector(r, g, b)), DESCFLAGS_SET_DONTCHECKMINMAX);
    

    This is probably a bit long in the tooth (from an older plugin) so be aware that constant ids may be different.



  • On 05/05/2015 at 02:39, xxxxxxxx wrote:

    Hi,

    Thanks for your answer, but I allready found that out.
    My question is, inside which method should I do this?
    I probably wasn't clear enough in my previous post.
    I've tried allready inside a few messages, with no results, mostly c4d crashing.

    Does anybody know where to do it?
    Thanks for your help and time!
    Greetings,
    Casimir Smets



  • On 05/05/2015 at 12:55, xxxxxxxx wrote:

    Hello,

    if you want to react to the (manual) change of a parameter you could listen to the MSG_DESCRIPTION_POSTSETPARAMETER message in your object.

    For questions no longer related to this thread's original topic please open a new thread. Thanks

    best wishes,
    Sebastian



  • On 06/05/2015 at 03:38, xxxxxxxx wrote:

    Hi Sebastian!

    I've allready tried it inside MSG_DESCRIPTION_POSTSETPARAMETER, but then c4d crashes...
    I guess it should be possible.. somewhere.

    Does anybody know where to do this?
    Thanks in advance for your help and time!
    Greetings,
    Casimir Smets


Log in to reply