Getting Started With Melange



  • On 07/09/2016 at 11:22, xxxxxxxx wrote:

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

    ---------
    Hi,
    I'm trying to get started with melange. And I'm having a very rough time just getting started with it.
    I can't figure out how to set up the VS project settings. And I don't even know what the minimum file structure requirements are (.res, .str, .c4d.h, etc...).

    I am using:
      Win7+ SP1
      VS2013
      Melange: 16.012
      C4D R13

    The Quickstart.pdf has lots of useful info in it. But it's useless if you can't even set up your first project.
    I have successfully compiled the renderconnection example in the melange sdk. And when I run it it asks me for a server. What the heck is a server?
    I tried using the CINEMA 4D 64 Bit.exe for this. And it works when I use the "Create and render and new melange scene" option. But when I try to load a file saved from C4D. It either doesn't work at all. Or only render part way before stopping. 😢

    Also.
    They use this in the example: using namespace melange;
    But the Quickstart says to use this: using namespace _melange_;
    And I cannot get either one to work in my own project.

    Also.
    MD & MT. Which one do we use, and why?

    This is all way too vague and way to painful for someone just trying to get started.
    Can we please have a guide on how to set up your first melange project?
    Or even just a very basic example with the minimum amount of files in it needed to get started.

    Thanks,
    -ScottA



  • On 07/09/2016 at 15:18, xxxxxxxx wrote:

    This is how I am installing the SDK and setting up the VS properties.

    -Unzip the files to: C:\Melange 16.012  
      
    -Create a new Debug x64 project in the Melange 16.012 folder  
      
      
    -Set up the VS properties like this:  
      
    Configuration Debug  x64  
      
    General  
      Target Extension & Configuration Type  
       set to: .exe  
      
      Character Set: Use Unicode Character Set  
      
    C++  
      General  
      Additional Include Directories  
        add this: C:\Melange 16.012\includes  
      
    Linker  
      General  
      Additional Dependencies  
        add this (add more lib files if needed) :  melangelib_debug.lib  
      
      Input  
       Additional Library Directories  
       add this: C:\Melange 16.012\libraries\win\melangelib_2013   
      
      System  
        SubSystem  
          Windows (/SUBSYSTEM:WINDOWS) or Console (/SUBSYSTEM:CONSOLE)
    

    And here the very simple program I'm trying to run

      
    #include "c4d_reflection.h"  
    #include "c4d_all.h"  
    #include "c4d_file.h"  
    #include "default_alien_overloads.h"  
      
    using namespace melange;  
      
    // overload this function and fill in your own unique data  
    void GetWriterInfo(Int32 &id, String &appname)  
    {  
      // register your own pluginid once for your exporter and enter it here under id  
      // this id must be used for your own unique ids  
      //     Bool AddUniqueID(Int32 appid, const Char *const mem, Int32 bytes);  
      //     Bool FindUniqueID(Int32 appid, const Char *&mem, Int32 &bytes) const;  
      //     Bool GetUniqueIDIndex(Int32 idx, Int32 &id, const Char *&mem, Int32 &bytes) const;  
      //     Int32 GetUniqueIDCount() const;  
      
      id = 1234567; //Temporary ID ONLY!!!  
      appname = "My Melange Example";  
    }  
      
    int main(int argc, Char* argv[])  
    {  
      Char *versionStr = GetLibraryVersion().GetCStringCopy();  
      printf("\n ___________________________________\n");  
      printf("\n   %s Commandline Tool", versionStr);  
      printf("\n ___________________________________\n");  
      DeleteMem(versionStr);   
    } 
    

    After looking at the commandline example. It seems like I have the correct settings in VS.
    I've used these same types of settings in many C++ libraries. And they work just fine.
    But I'm getting loads of symbol errors from the compiler.

    -ScottA



  • On 08/09/2016 at 08:29, xxxxxxxx wrote:

    Found the problem.
    For some reason. Melange requires using file paths in the Additional Dependencies list! 😲
    I have used dozens of third party libraries. And I can't recall anyone ever using files paths in there.

    The typical way people set up external libraries in VS is like this:
    -includes get pointed to from here: Additional Include Directories option
    -libs get pointed to from here: Additional Library Directories
    -libs (just their names...not their file paths) get posted in: Additional Dependencies
    Sticking to this structure keeps things nice and organized. And makes it simple to build other peoples libraries. Because it is a standard that most everyone uses.
    IMHO. Forcing people to use file paths in the Additional Dependencies is a terrible idea.
    It made me spend several hours trying to figure out why my project would not compile.

    Here is how I finally got my own Melange project from scratch to compile:

    This is how to install melange and set up the VS properties  
     **NOTE: They used file paths in the Additional Dependencies list which is very unusual  
        ...Watch out for that. Don't let it trip you up!!!**  
      
      
    -Unzip the files to: C:\Melange 16.012  
      
    -Create a new Debug x64 project in the Melange 16.012 folder  
      
      
    -Set up the VS properties like this:  
      
    **WARNING!!!!  
    *Make sure you are using Configuration Debug  x64  
      
    General  
      
      Target Extension & Configuration Type  
       set to: .exe  
      
      Character Set: Use Unicode Character Set  
      
      
    C++  
      
      General  
      Additional Include Directories  
        add this: C:\Melange 16.012\includes  
      
      
    Linker  
      
      General  
      Additional Library Directories      
      add this: C:\Melange 16.012\libraries\win\melangelib_2013  
      
      
      Input  
       Additional Dependencies  
       add these:  
          C:\Melange 16.012\libraries\win\melangelib_2013\melangelib_debug.lib  
          C:\Melange 16.012\libraries\win\jpeglib_2013\jpeglib_debug.lib  
          ws2_32.lib  
          winmm.lib   
      
      System  
        SubSystem  
          Windows (/SUBSYSTEM:WINDOWS) or Console (/SUBSYSTEM:CONSOLE)
    

    -ScottA



  • On 08/09/2016 at 08:46, xxxxxxxx wrote:

    Hi Scott,

    actually I create my Melange projects in the same way I do create plugin projects, by cloning a example project.

    Then I'm wondering why you seem to be mixing Melange R16 with C4D R13? I'd suggest to use the Melange version for R13.

    Regarding the namespace, just stick with the naming from the example code. Currently I assume the quickstart pdf needs an update. I'll check that and we'll update accordingly.

    And what's so bad about the command line example project?

    You say you get symbol errors. Can you please post the errors (at least a few), so I can get an idea what's happening?



  • On 08/09/2016 at 10:09, xxxxxxxx wrote:

    The namespace problem was just me not knowing what the heck I was doing. And being totally naive about how to use the SDK.
    I didn't know which SDK to use with R13. Or if it even mattered. So I tried the newest one first.
    It seems like it works. The commandline example seems to work fine with R13 files. But the renderconnection one is not rendering the R13 file properly. I didn't even know if using the .exe was the right thing to use. There's no explanation in the code what a "server" is.
    I might try an earlier version of Melange next. But I'd prefer to use the latest version if possible.

    I never clone to create a new project. I always build from scratch. Mostly out of habit.
    I prefer to know how to set up VS myself from scratch. I feel more secure knowing how to do it myself. That way I don't get burned later on having to depend on someone else's setup.

    I'm glad you brought up the commandline example.
    That example is almost 3000 lines of code. And every time I tried to chop it down to something easier to follow. I would get compiler errors.
    So I had to start from the bottom of the file. And one-by-one delete the various functions. Being careful to make sure it still compiles as I go.
    At the same time. I had to do the same thing with the alien_def.h file's code.
    It took me over an hour to chop it down to a simple example that did not rely on a separate .h file. And still compile. 😠

    Every time I dive into a new SDK. I go through the same 3 processes: crawl, walk, run.
    At the crawl stage I need to have a very simple example. With little or no dependency files.
    At the walk stage. I start looking for examples that use other files ( .h files)
    At the run stage. I use complex examples like the commandline example. That has everything dumped into it. In one massive code dump to pull from.
    The Melange SDK has no crawl or walk examples in it. Only big massive complex examples.
    So I had a very hard time getting started with it. And I had a very hard time making a simple learning type example.

    After hours of head banging. And finally being able to create a very simple project. It's getting more clear. But still very new and "alien" me. Get it......alien. 😂
    Now I'm  going to try to transition from crawl to walk. By pasting some of the code from the commandline example into my project. To learn how to use them.
    I've never used an SDK that uses aliens before. 🙂

    -ScottA



  • On 08/09/2016 at 16:45, xxxxxxxx wrote:

    Hit another snag.
    I'm trying to render a .c4d file using the Quick start.pdf. But I don't know how to set the value for the the rgba_data in the Callback() function?

    void MyUpdateImage(void *userdata, Int32 xpos, Int32 ypos, Int32 xcnt, ColorResolution bpp, UChar *rgba_data)  
    {  
      xpos = 0;  
      ypos = 0;  
      xcnt = 1024;   
      bpp = COLORRESOLUTION_CHAR;  //<---Is this correct?  
      rgba_data = ?                //<---what do I use here?  
    }
    

    -ScottA



  • On 12/09/2016 at 09:00, xxxxxxxx wrote:

    Hi Scott,
    in your UpdateImage callhback (MyUpdateImage), you shouldn't assign any values at all. And why would you? You are are getting passed parameters to your callback. The color resolution gets passed to your callback, so you know, what to do with the rgba_data array.
    A bit more detail:
    When this callback is called, you are being informed, that a certain part of your requested image is ready and you are being passed the data. The start coordinates of the pixels in the rgba_data array. The number and the color depth of those pixels. Then you treat the incoming rgba_data as exactly this, an array of pixels with the given color depth. You are supposed to read these pixels and do what ever you want to do with them. You are not supposed to write into that array.

    Regarding your MD or MT question: The example projects are setup having targets for both options. So the answer is quite simple: You choose the option that is appropriate for the project you want to do.



  • On 12/09/2016 at 09:05, xxxxxxxx wrote:

    One more thing: For Melange there is a counterpart inside of Cinema 4D. That's the reason, Melange gets released for each major version of Cinema 4D.



  • On 12/09/2016 at 09:43, xxxxxxxx wrote:

    What I'm trying to do is render the .c4d file. Then get the image data from it so that I can use it to write the image with Win32 or Qt code.

    The renderconnection example sets data values to the callback's parameters. So that's why I'm doing it in my code. I'm probably doing it wrong though.
    Maybe I need to use pointer variables outside of the callback?
    I'm not sure about that. Still trying to figure out how it works.

    The UChar *rgba_data parameter is the only one that I have absolutely no idea how to use.

    -ScottA



  • On 13/09/2016 at 00:17, xxxxxxxx wrote:

    Hi Scott,

    I think, you are misreading something. I see only one location in the render connection example, where WinImageUpdate() is being used, when it is passed to GetImageUpdate() in renderconnection.cpp:ActionThread1::Main(). It is never called directly, nor do I see any code setting data values to the callback's parameters. Of course GetImageUpdate() will set the parameters, when calling WinImageUpdate() internally. And inside WinImageUpdate() implementation there's no write access to any of the parameters. They are just used as I described in my previous post.  And by the way, there is also demonstrated how to access the rgba_data pixel array.

    And what do you mean by "Maybe I need to use pointer variables outside of the callback?"?



  • On 13/09/2016 at 08:23, xxxxxxxx wrote:

    There is a custom class called "WinBitmap" in there that has member variables.
    Those member variables are being used by the WinImageUpdate() callback. They are talking to each other.
    It looks like the WinImageUpdate() callback is feeding the WinBitmap class the image color values that I want. But I'm still trying to decipher it.

    There's tons of extra stuff in that example that have nothing to do with rendering the .c4d scene and getting the color values (building scene files, file reading, material reading, file saving, Win32 dialog code, etc...) So I'm have a devil of a time stripping all that stuff out without breaking the program.
    I appreciate all that code (it will come in handy eventually) . But right now it's all in way and preventing me from learning basic scene rendering, and color value capturing.

    I also tried using the render connection code in the QuickStartGuide.
    But I'm not getting the proper values from the thread. The percent_done is returning zero.
    So in a nut shell:
    -The renderconnection example has too much extra code stuff in it.
    -The QuickStartGuide doesn't have enough code in it

    I'll keep banging away at it.

    -ScottA


Log in to reply