Beginner questions



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

    On 12/07/2008 at 02:34, xxxxxxxx wrote:

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

    ---------
    Hi,

    I am currently starting to develop a Cinema4D addon and got some questions, which might sound naive, sorry in advance ;)

    Interface:

    I was able to create a simple user interface using the Cinema4D 8.5 resource editor plugin. Although this is outdated it seems to work quite well (except for one resize/scale for the top containter I had to add in manually). Plugin hooks into plugin menu and shows correctly. Is there a recent version of ResEdit for 10.5?

    SDK:

    I have been searching the 10.5 SDK but found the structure quite confusing. Using the index helped a little. The things I would want to do:

    - Load and display several pictures
    As I understand it I can use a BaseBitmap object to store the image and Init() to load it from a file. I created a UserArea in my interface where I would want to display these images. Right way to do it?

    - Use a file open dialog
    Is there a way to display a file open dialog from within my plugin? ResEdit does this, so I am guessing it's possible somehow?

    - create scene objects
    Is it possible to create scene objects, camera paths, timelines from within the plugin? Could you give me some pointers as to where to look in the SDK to find the correct functions for this?

    Also general pointers to specific pages in the SDK/Tutorials would be greatly appreciated, I am guessing I'm just looking in the wrong places.

    Many thanks in advance

    Markus



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

    On 12/07/2008 at 05:25, xxxxxxxx wrote:

    UserArea / Images:
    I'm not sure how you intend to display these bitmaps, but I have a dialog with two UserAreas on it that display static images.  I created a 'LogoBmp' class, derived from the GeUserArea class, like so...

        
        
        
        
        #include "c4d.h"  
        class LogoBmp : public GeUserArea  
        {  
        private:  
        #ifdef _V7SDK_  
            BaseBitmap *m_pBmp;  
        #else  
            AutoAlloc<BaseBitmap> m_pBmp;  
        #endif
        
        
        
        
        public:  
            Bool Logoname(char *szName);  
        #ifdef _R10p1_SDK_  
            virtual void DrawMsg(LONG x1,LONG y1,LONG x2,LONG y2,const BaseContainer &msg);  
        #else  
            virtual void Draw(LONG x1, LONG y1, LONG x2, LONG y2);  
        #endif  
        };  
        
    

    ...and here is the code part...

        
        
        
        
        #include "logo.h"
        
        
        
        
        Bool LogoBmp::Logoname(char *szName)  
        {  
        #ifdef _V7SDK_  
            m_pBmp = AllocBaseBitmap();  
        #endif
        
        
        
        
            if( !m_pBmp || m_pBmp->Init(GeGetPluginPath()+String("res")+String(szName))!=IMAGE_OK )  
                return false;
        
        
        
        
            return true;  
        }
        
        
        
        
        #ifdef _R10p1_SDK_  
        void LogoBmp::DrawMsg(LONG x1, LONG y1, LONG x2, LONG y2,const BaseContainer &msg)  
        {  
            LONG wid = x2-x1;  
            LONG hgt = y2-y1;
        
        
        
        
            if( m_pBmp )  
                DrawBitmap(m_pBmp, x1, y1, wid, hgt, 0, 0, m_pBmp->GetBw(), m_pBmp->GetBh(), BMP_NORMALSCALED | BMP_ALLOWALPHA);  
        }
        
        
        
        
        #else
        
        
        
        
        void LogoBmp::Draw(LONG x1, LONG y1, LONG x2, LONG y2)  
        {  
            LONG wid = x2-x1;  
            LONG hgt = y2-y1;
        
        
        
        
            if( m_pBmp )  
                DrawBitmap(m_pBmp, x1, y1, wid, hgt, 0, 0, m_pBmp->GetBw(), m_pBmp->GetBh(), BMP_NORMALSCALED | BMP_ALLOWALPHA);  
        }
        
        
        
        
        #endif
        
        
        
    

    ...I then derive my options dialog class from a GeModalDialog, and use the above class to get my two images displayed...

        
        
          
        // my options dialog class  
        class LoadOptsDialog : public GeModalDialog  
        {  
        private:  
            LogoBmp m_riplogo;  
            LogoBmp m_tidelogo;  
            ObjLoader *ppbj;  
            Bool m_presetsAdded;
        
        
        
        
            void AddPresets(void);  
            void GetDlgValues(void);  
            void SetDlgValues(void);
        
        
        
        
        public:  
            LoadOptsDialog(ObjLoader *pbj);  
            virtual Bool CreateLayout(void);  
            virtual Bool InitValues(void);  
            virtual Bool Command(LONG id, const BaseContainer &msg);  
            virtual Bool AskClose(void);  
        };
        
        
        
        
        // Constructor  
        LoadOptsDialog::LoadOptsDialog(ObjLoader *pbj)  
        {   
            m_presetsAdded = false;  
            m_riplogo.Logoname("redilogo.tif");  
            m_tidelogo.Logoname("riptide.tif");  
            ppbj = pbj;   
        }
        
        
        
        
        Bool LoadOptsDialog::CreateLayout(void)  
        {  
            if( !(GeModalDialog::CreateLayout() && LoadDialogResource(DLG_IMPFILE,NULL,0)))  
                return FALSE;
        
        
        
        
            AttachUserArea(m_riplogo, IDC_MPLOGO);  
            AttachUserArea(m_tidelogo, IDC_MPRTLOGO);
        
        
        
        
            AddPresets();
        
        
        
        
            return TRUE;  
        }  
        
    

    ...I hadn't tried changing the images, but you might be able to do that later just by calling the Logoname() routine again (which calls Init() ) with new filenames and refreshing the display - but I'd look up the GeUserArea docs to see what it says about this.
    File Open Dialog:
    This is pretty straight-forward, just create a Filename variable and call it's FileSelect() method.  Like so...

        
        
          
            Filename fName;  
            String titleStr = String("Import .obj File");  
            if( !fName.FileSelect(FSTYPE_SCENES,0,&titleStr) )  
                return false;  
        
    

    Create Scene Objects / Tips:
    Yes, you can create scene objects and such... the best 'tutorial' is to compile the SDK example plugins, play with them to see what they do and if one does something you need, go look at it's source to see how it does it (ie. add some object/deformer/shader/whatever).  Then use the SDK docs to look up various classes and topics.
    Cheers,
    Keith



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

    On 12/07/2008 at 05:33, xxxxxxxx wrote:

    ...on that last point... there really aren't any "How to write a plugin" tutorials... instead, you have multiple example plugins that demonstrate the basics of each type of plugin.



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

    On 15/07/2008 at 06:57, xxxxxxxx wrote:

    Hi Giblet,

    many thanks for your answers.

    I was able to create scene objects, use the file open dialog etc.

    I tried to load and draw a Bitmap onto the UserArea but no success until now...it just won't show. Will try again though and report back.



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

    On 15/07/2008 at 10:05, xxxxxxxx wrote:

    Here you go... I've simplified things a bit (should work with R8 or so, but you'd have to add that _R10p1_SDK_ #define if you're compiling with R10.1 or later).
    Here's a header file I call "logo.h"...

        
        
          
        #include "c4d.h"
        
        
        
        
        class LogoBmp : public GeUserArea  
        {  
        private:  
            BaseBitmap *m_pBmp;
        
        
        
        
        public:  
            // Constructor  
            LogoBmp(void) { m_pBmp = BaseBitmap::Alloc(); }
        
        
        
        
            // Destructor  
            ~LogoBmp(void) { if( m_pBmp ) BaseBitmap::Free(m_pBmp); }
        
        
        
        
            // Initialize bitmap with filename (looks in plugin's res folder, as implemented)  
            Bool LogoBmp::Logoname(String szName)  
            {  
                if( !m_pBmp || m_pBmp->Init(GeGetPluginPath()+String("res")+szName)!=IMAGE_OK )  
                    return false;  
                return true;  
            }
        
        
        
        
            // Overloaded draw routine  
        #ifdef _R10p1_SDK_  
            virtual void LogoBmp::DrawMsg(LONG x1, LONG y1, LONG x2, LONG y2,const BaseContainer &msg)  
        #else  
            virtual void LogoBmp::Draw(LONG x1, LONG y1, LONG x2, LONG y2)  
        #endif  
            {  
                if( m_pBmp ) DrawBitmap(m_pBmp, x1, y1, x2-x1, y2-y1, 0, 0, m_pBmp->GetBw(), m_pBmp->GetBh(), BMP_NORMALSCALED | BMP_ALLOWALPHA);  
            }  
        };
        
        
        
    

    ...just #include that wherever needed, then create one, call the Logoname() method with a filename (if you plan to pass the full path, you'll need to edit that method) and attach it to some UserArea (AttachUserArea()).  Note that normally you don't need to do anything else - C4D will call the overloaded Draw() routine when the UserArea needs updating, but if you swap out the image, you'll probably need to call the ie. myLogo.Redraw() method (inherited from the GeUserArea class), or some function that causes your interface to be updated/refreshed.



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

    On 18/07/2008 at 05:24, xxxxxxxx wrote:

    Sorry if I am being a nuisance with this but shouldn't this work for a simple UserArea used as a canvas:

    > \> GeUserArea m_DisplayArea; \>

    In my CreateLayout() :

    > \> GadgetPtr ptr = GadgetPtr(IDC_USER1); \> . \> . \> . \> AttachUserArea(m_DisplayArea,ptr); \>

    somewhere else:

    > \> m_DisplayArea.DrawBitmap(SplashScreen,1,1,100,100,1,1,100,100,BMP_NORMALSCALED); \> m_DisplayArea.DrawBorder(BORDER_THIN_IN,10,10,200,200); \> m_DisplayArea.Redraw(); \>

    what am I missing? Please help...



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

    On 18/07/2008 at 11:07, xxxxxxxx wrote:

    My off-hand guess is...
    You need to override the Draw() (or DrawMsg(), depending on the version) method, with all of your drawing code.  Then when you call m_DisplayArea.Redraw();, that will force your overridden Draw() method to be called, which would in turn call DrawBitmap(), etc.
    If you're not overriding the Draw/DrawMsg() method, then it's probably clearing out anything you did when you call Redraw().
    EDIT: ...in other words, I've never tried using a GeUserArea without deriving my own class from it.  You might need to.



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

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

    Thanks Giblet,

    overriding the draw functions works now. Another problem I had was, that the BaseBitmap doesn't seem to read as many image formats than I thought...I should have checked that object ;)

    Markus



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

    On 18/08/2008 at 07:05, xxxxxxxx wrote:

    Quote: _Another problem I had was, that the BaseBitmap doesn't seem to read as many image formats than I thought...I should have checked that object ;)
    >
    > * * *
    _


    Which image formats where not working?

    cheers,
    Matthias


Log in to reply