Store picture pixel information 2


    On 19/11/2006 at 11:56, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   9.6 
    Platform:    Mac  ;  
    Language(s) :   C.O.F.F.E.E  ;  C++  ;  XPRESSO  ;


    I already asked here, but i am stuck again.

    Here is my last "question":

    I want to store the information of each pixel of the picture in an array for example. So that it is possible to read out these information (out of an array, not again out of the picture) at any time, from "everywhere" in cinema 4d.

    Read in a picture once and use these information to change any kind of object. Like using the color-value of a pixel to rotate an object.

    And here is the answer from Robert:

    Bitmaps are nothing more than arrays (?). Although they represent 2D images, the usual storage is a 3D array (width x height x depth). Depth depends upon the color space and other information (RGBA is a depth of four). Width elements are usually Byte-size (but can be larger) and store a color component at each depth level:

            (A)(A)(A)(A) ... (optional)
           B B B B ...
          G G G G ...
         R R R R ...

    The upper left is the upper-left pixel. Each pixel is desribed with three or four depth values (planes).

    That should be all the information you'll ever need - why duplicate it? The C++ and COFFEE SDKs have a BaseBitmap class that will let you get and set the pixel information. Just store your own BaseBitmap pointer for the image and make it available to all of your plugin. Not certain about what you mean by "'everywhere' in Cinema 4D", but you can use your plugin to direct the bitmap information to the Cinema 4D facilities if they are accessible to the SDK (COFFEE is very limited in this respect).

    Consider that images can take up oodles of memory space (1024x1024 RGBA = 4MB). In low memory situations, all of that duplication may become critical.

    I hope you guys can help me again.
    Here are my question:

    Are there any examples how such a COFFEE script look like?
    How is it possible to make a BitMapPointer avaiable to other plugins/scipts?
    What means "accessible to the SDK"?
    And the last one: Is it possible to run a COFFEE script only one time? (When i create an object with my COFFEE script, every time I click in the window, another object is created. And again and again.)

    Best regards


    On 19/11/2006 at 13:12, xxxxxxxx wrote:

    COFFEE scripts attached to COFFEE tags are run 'continuously' for lack of a quicker description. You could set up a variable to have it only run once (start it equal to FALSE, set to TRUE after the first run, and check it to avoid further runs:

    var mycheck;     // class member or global
    mycheck = FALSE; // somewhere during initialization
    // Where the meat of the operation occurs
    if (mycheck) return; // don't do anything
    // do whatever it is the script does
    mycheck = TRUE;

    It is also possible to set up COFFEE as a plugin of some sort in its own right. Here, the code isn't added into a tag or XPresso node, but into a .cof text file that is placed into Cinema 4D's Plugins folder. A CommandPlugin can be run once, but it is not object-specific. Or you can make a TagPlugin to replace the COFFEE tag script and there you have more control.


    What I mean by "accessible to the SDK" is that plugin developers don't have complete and total access to every part of Cinema 4D. There are areas that are inaccessible for one reason or another (Maxon doesn't want you to have access or they have not yet provided such access). For instance, you cannot do things directly to the Object Manager - there is no SDK access to how it operates in general, but there are some general accesses to the interface that can let you do simple things to it and you can access the objects and tags added to it indirectly by way of the BaseDocument that represents the scene graph.


    You can't make a Bitmap* available to other plugins/scripts - unless they are your own plugins/scripts. The other plugins/scripts don't know about your plugin and Maxon provides no interface to 'know' about your internal variables and structures. Cinema 4D won't know much about it either.


    Examples do abound. The COFFEE documentation PDF/HTML has tons of embedded and linked examples. There are some here and Rui Batista has been doing COFFEE example articles in 3D Attack online magazine for some time. I'm not a big COFFEE developer - mainly C++ plugins. You will probably get more detailed information from the COFFEE experts.

Log in to reply