Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    InsertMaterial in ObjectData plugin [SOLVED]

    SDK Help
    0
    27
    15.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            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

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              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

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                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.

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  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

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    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

                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      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.

                      1 Reply Last reply Reply Quote 0
                      • H
                        Helper
                        last edited by

                        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

                        1 Reply Last reply Reply Quote 0
                        • H
                          Helper
                          last edited by

                          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

                          1 Reply Last reply Reply Quote 0
                          • H
                            Helper
                            last edited by

                            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

                            1 Reply Last reply Reply Quote 0
                            • H
                              Helper
                              last edited by

                              On 07/05/2015 at 10:05, xxxxxxxx wrote:

                              Hi Casimir,
                              can you give us an example of the code you used in MSG_DESCRIPTION_POSTSETPARAMETER?

                              1 Reply Last reply Reply Quote 0
                              • H
                                Helper
                                last edited by

                                On 08/05/2015 at 01:18, xxxxxxxx wrote:

                                Hi Andreas,

                                I've used this code:

                                  
                                BaseMaterial* myMaterial = doc->SearchMaterial("My_Material");  
                                if (!myMaterial)  
                                  return nullptr;  
                                BaseContainer* myMaterialData = myMaterial->GetDataInstance();  
                                if (!myMaterialData)  
                                  return nullptr;  
                                myMaterialData->SetParameter(MATERIAL_COLOR_COLOR, bc->GetData(MYMATERIAL_DIFFUSE_COLOR));  
                                myMaterial->Update(true, true);  
                                

                                I also recently found out that I do not need to do this inside Message. I can simply use this in GetVirtualObjects and everything works fine.

                                Still thanks for your help and time! 🙂
                                Greetings,
                                Casimir Smets

                                1 Reply Last reply Reply Quote 0
                                • H
                                  Helper
                                  last edited by

                                  On 08/05/2015 at 01:22, xxxxxxxx wrote:

                                  1. Make sure this does not result in recursion (due to the SetParameter call)
                                  2. You shouldn't change the active scene from within GetVirtualObjects. See threading information in the docs.

                                  1 Reply Last reply Reply Quote 0
                                  • H
                                    Helper
                                    last edited by

                                    On 08/05/2015 at 02:40, xxxxxxxx wrote:

                                    Hi Katachi,

                                    What do you mean by recursion? I've translated it and I know it means repetition, but what repetition?

                                    And secondly, I know I shouldn't change materials in a threaded-function, but because it didn't work in ANY message, I had to do it somewhere else. Besides, it seems to have no problem with it..   although it could give a bigger problem that I do not know about.

                                    If you would know another way how I could do this, I would greatly appreciate it!
                                    Thanks for your help and time!
                                    Greetings,
                                    Casimir Smets

                                    1 Reply Last reply Reply Quote 0
                                    • H
                                      Helper
                                      last edited by

                                      On 08/05/2015 at 03:50, xxxxxxxx wrote:

                                      1. MSG_DESCRIPTION_POSTSETPARAMETER is triggered after SetParameter has been called (hence its name). As you use SetParameter it may result in recursion (and maybe that's why the crash happens? At which code line does the crash exactly happen? You should debug your code.). It's worth checking out VALIDATE message for example or other description messages.

                                      2. Well, it may crash unexpectedly depending on threading. That's why it is so unsafe.

                                      1 Reply Last reply Reply Quote 0
                                      • H
                                        Helper
                                        last edited by

                                        On 08/05/2015 at 05:04, xxxxxxxx wrote:

                                        Hi Katachi,

                                        Thank you very much for your input!
                                        I will definately look into it!
                                        And... I have tried it in every MSG, even in the ones I was sure it would not work 😛

                                        Thanks for your help and time!
                                        Greetings,
                                        Casimir Smets

                                        1 Reply Last reply Reply Quote 0
                                        • H
                                          Helper
                                          last edited by

                                          On 11/06/2015 at 01:32, xxxxxxxx wrote:

                                          Hi,

                                          For the people wondering, the final solution can be found here:
                                          https://developers.maxon.net/forum/topic/8792/11595_change-material-color-in-objectdata-pluginsolved

                                          With kind regards,
                                          Casimir Smets

                                          1 Reply Last reply Reply Quote 0
                                          • First post
                                            Last post