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

    Sampling color at vertexes

    SDK Help
    0
    53
    39.7k
    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 07/08/2014 at 12:12, xxxxxxxx wrote:

      It kind of sounds like the problem of trying to grab an object that isn't ready to be grabbed yet.
      What kind of plugin are you making Rui?

      So far I've only used the code like a script in a CommanData() plugin, on the active object. And it works fine (except for the ProjectPoint() method stuff).

      -ScottA

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

        On 07/08/2014 at 13:15, xxxxxxxx wrote:

        It is a ToolPlugin.
        It shows a Link field in the Attribute Manager and it would sample all the colors of the vertexes of the object to store them inside a database.
        The Message method, as I have it right now is this one:

          
        Bool polypaintfrommaterial::Message(BaseDocument* doc, BaseContainer& data, LONG type, void* t_data)   
        {   
             if (type==MSG_DESCRIPTION_COMMAND)   
             {   
                  DescriptionCommand *dc = static_cast<DescriptionCommand*>(t_data);             
                  LONG button = dc->id[0].id;   
                     
                  if (button == PPT_TRANSFER)   
                  {   
                       BaseObject* b_source = (BaseObject* ) data.GetObjectLink(PPT_SOURCE,doc,Obase);   
          
                       if (b_source==NULL) return TRUE;     // no source   
                       SampleColorAtVertices(b_source);   
                  }   
             }   
                     
        return TRUE;   
        }
        

        The Link field only accepts polygonal objects. And the object I drag into it, has a material tag.
        But, as soon as I press the button, it crashes.

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

          On 07/08/2014 at 14:42, xxxxxxxx wrote:

          I could be completely off base here. But humor me anyway.😉
          You might not be grabbing the object.
          The tool AM is really a subdialog. Which is different from the AM in Tag or Object plugins.
          So it might be that you're using the Linkfield code for Node plugins instead of the Linkfield code for GeDialog and subdialogs.

          Here's some code I ripped out of a tool plugin

            
          //The subdialog class for the tool plugin  
          class ToolDialog: public SubDialog  
          {  
            private:  
                LinkBoxGui *myLink;  
            
            public:  
                BaseContainer    *toolData;  //A container we'll save the dialog values in so they don't constantly re-set  
             
                virtual          Bool CreateLayout(void);  
                virtual          Bool InitValues(void);  
                virtual          LONG Message(const BaseContainer& msg, BaseContainer& result);  
                virtual          Bool Command(LONG id,const BaseContainer &msg);  
          };  
            
          // ....the other subdialog methods here .....  
            
          LONG ToolDialog::Message(const BaseContainer &msg, BaseContainer &result)  
          {  
            LONG mid = msg.GetId();  
            
            //Use one of the BFM messages to get the link  
            //Because BFM messages are intended to be used with dialogs  
            if(mid == BFM_SYNC_MESSAGE)  
            {  
                BaseObject *lop = (BaseObject* )myLink->GetLink(GetActiveDocument());  
                if(!lop) GePrint("empty");  
                else GePrint(lop->GetName());  
            }  
              
            return GeDialog::Message(msg, result);  
          }  
            
          // ....the other subdialog methods here .....  
            
            
            
          //The actual Tool plugin class where the tool does it's thing based on the subdialog settings above  
          class MyTool : public ToolData  
          {  
            public:  
                ToolDialog *dlg;   
                virtual SubDialog           *AllocSubDialog(BaseContainer *bc);  
                MyTool() :ToolData(), dlg(nullptr){ }  
            
                virtual LONG                GetToolPluginId() { return PLUGIN_ID; }  
                virtual Bool                InitTool(BaseDocument* doc, BaseContainer& data, BaseThread* bt);  
                virtual const String        GetResourceSymbol() { return String("mytool"); }  //The name of the .res file  
                virtual Bool                GetCursorInfo(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, Real x, Real y, BaseContainer &bc);  
                virtual Bool                MouseInput(BaseDocument *doc, BaseContainer &data, BaseDraw *bd, EditorWindow *win, const BaseContainer &msg);      
                virtual void                FreeTool(BaseDocument *doc, BaseContainer &data);  
          };  
            
          //etc....
          

          What I'm saying is...Are you 100% sure you're really grabbing the linked object correctly?
          Have you tested it by asking for the object's name, or something like that before trying to run Remo's code on it?

          -ScottA

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

            On 07/08/2014 at 14:46, xxxxxxxx wrote:

            Well, the code I'm using is from another plugin that I coded and it is working perfectly. The other plugin even includes two fields to link to two different objects (it is a transfer function) and it all works perfectly.
            The basic functionality of this new plugin is, mainly the same (in the way that it works, not in what it does), so I'm re-using the code.

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

              On 07/08/2014 at 14:50, xxxxxxxx wrote:

              I tried replacing the call to SampleColorAtVertices with GePrint(b_source->GetName()); and it printed out the name perfectly.

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

                On 07/08/2014 at 15:14, xxxxxxxx wrote:

                OK. Then I'm out of ideas.
                I usually run code that I'm new to in a CommandData() plugin first as a sort of script. Before implementing it in an actual plugin.
                That way I know that the code is working before I attempt to add it to some other plugin.

                I haven't used his code in anything else yet.

                -ScottA

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

                  On 07/08/2014 at 15:33, xxxxxxxx wrote:

                  Well, I may have not adjusted the code from Remo correctly.
                  Would it be possible to see your adjustments to compare them with mine?

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

                    On 07/08/2014 at 15:51, xxxxxxxx wrote:

                    Sure. I can send you my CD plugin if you want.
                    What's your e-mail again?

                    -ScottA

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

                      On 07/08/2014 at 15:58, xxxxxxxx wrote:

                      Thank you very much in advance, Scott.
                      My mail is [email protected]

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

                        On 08/08/2014 at 04:39, xxxxxxxx wrote:

                        I had to fire it up on Parallels to check it out (I'm on a Mac 😉 )
                        It works.
                        But as I used your code in my plugin, it crashes the same way 😞

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

                          On 08/08/2014 at 07:11, xxxxxxxx wrote:

                          Then the problem has to be in your plugin.
                          Do you know how to use the debugger?
                          The error you get from it might help you figure it out.

                          -ScottA

                          Edit-- FYI
                          I have to correct myself a bit.
                          That stuff I was saying about the subdialog is for the older type of ToolData plugins.
                          I think you're using the newer DescriptionToolData plugin. Which uses the .res file. And is a bit different from the older ToolData plugin.
                          I forgot that there was two different versions of the tool plugin.

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

                            On 08/08/2014 at 07:35, xxxxxxxx wrote:

                            No, unfortunately I don't know how to use the debugger 😞

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

                              On 08/08/2014 at 09:06, xxxxxxxx wrote:

                              I don't have the Remo code in my plugin, like you have.
                              It is in a separate file that I include at the start of my source code, like this:

                              #include "c4d.h"
                              #include "c4d_symbols.h"
                              #include "tpolypaintfrommaterial.h"
                              #include "c4d_helpers.h"
                              #include "remo_sampler.h"

                              Could it be because of this?

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

                                On 08/08/2014 at 09:18, xxxxxxxx wrote:

                                Doing some simple detective work I found out that what is causing the crash in SampleColorAtVertices is the line:

                                Sampler smpl;

                                If I place a return INIT_SAMPLER_RESULT_OK; before this line, no crash occurs.
                                If I place a return INIT_SAMPLER_RESULT_OK; after this line, the crash occurs.

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

                                  On 08/08/2014 at 11:41, xxxxxxxx wrote:

                                  Hi
                                  This seems to be a problem in the constructor.
                                  Sampler::Sampler() { ... }

                                  But it is imposible to say exactly what causes this crash without knowing what was changed in the code.

                                  Have you changes something in this code section ?

                                    
                                  	AutoAlloc<VolumeData> vd; //Owning ptr 	  
                                  AutoAlloc<TexData>	 tex; //Owning ptr  
                                  

                                  Because this will auto alloc vd and tex.

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

                                    On 08/08/2014 at 12:03, xxxxxxxx wrote:

                                    This is what I have:

                                      
                                    //=================================================================================================   
                                    class Sampler   
                                    //=================================================================================================   
                                    {   
                                    public:   
                                         Sampler();   
                                         ~Sampler();   
                                            
                                         //init this sampler, always call one of this before everything else.   
                                         INIT_SAMPLER_RESULT Init(BaseObject *obj,LONG chnr=CHANNEL_COLOR,Real time=0.0);   
                                         INIT_SAMPLER_RESULT Init(BaseMaterial *mat ,LONG chnr,Real time,BaseDocument *doc,BaseObject *op=nullptr);   
                                         INIT_SAMPLER_RESULT Init(TextureTag *textag,LONG chnr,Real time,BaseDocument *doc,BaseObject *op=nullptr);   
                                            
                                         //return true if Init was called before.   
                                         inline Bool IsInit(){ return TexInit; };   
                                            
                                         //return color at UVW coordinates.   
                                         Vector     SampleUV(const Vector &uv;, Real time=0.0);   
                                            
                                         //return color at 3D coordinates p, if shader is not 3D then uv will be used.   
                                         Vector     Sample3D(const Vector &pos3d;, const Vector &uv; = Vector(0.0), Real time=0.0);   
                                            
                                         //return average color of the shader   
                                         Vector AverageColor(LONG num_samples = 128);   
                                            
                                         void Free();   
                                    private:   
                                         BaseShader                *texShader; //NON owning ptr   
                                         AutoAlloc<VolumeData> vd; //Owning ptr   
                                         AutoAlloc<TexData>      tex; //Owning ptr   
                                         RayObject                *rop; //Owning ptr   
                                            
                                         InitRenderStruct     irs;   
                                         ChannelData               cd;   
                                            
                                         Matrix               omg;   
                                         Real               offsetX;   
                                         Real               offsetY;   
                                         Real               lenX;   
                                         Real               lenY;   
                                         Bool               TexInit;   
                                    };   
                                    
                                    1 Reply Last reply Reply Quote 0
                                    • H
                                      Helper
                                      last edited by

                                      On 08/08/2014 at 12:06, xxxxxxxx wrote:

                                      Well then it will be cause by some changes in the constructor.
                                      Sampler::Sampler()

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

                                        On 08/08/2014 at 12:15, xxxxxxxx wrote:

                                        Well, the listing is a bit long. Should I paste it here or should I send it over through e-mail? (if I can, of course... I don't want to be imposing).

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

                                          On 08/08/2014 at 12:18, xxxxxxxx wrote:

                                          Should I paste it here or should I send it over through e-mail?
                                          Of course you can send it over e-mail.
                                          Even better just place it on github.com

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

                                            On 08/08/2014 at 12:25, xxxxxxxx wrote:

                                            Mustn't I have an account in github.com to place something there?
                                            And, if I send you the listing over e-mail, can I use the mail I used when I bought some of your plugins? 🙂

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