Object creation



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

    On 12/10/2007 at 05:52, xxxxxxxx wrote:

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

    ---------
    Hello,

    I am trying to write a plugin which, among other things, inserts a camera into a scene. Here is my code for the insertion of a camera object as a child object of the current active object:

    > _AddCameraObject()
    > {
    > CameraObject* camera = (CameraObject* )BaseObject::Alloc(Ocamera);
    >
    > if ( !camera ) {
    >     GePrint("CameraObject creation failed!");
    > } else {
    >     GePrint("CameraObject creation success!");
    > }
    >
    > BaseDocument *actdoc = GetActiveDocument();
    > BaseObject *actobj = actdoc->GetActiveObject();
    >
    > actdoc->InsertObject(camera, actobj, NULL, TRUE);
    > }
    > _

    The problem is that I have no idea where to call my function.
    I tried to write an tag plugin and call my function in Execute() or in Init() but obviously those funtions are evaluated multiple times so more and more cameras were inserted. Also the SDK states that no InsertObject() should be called in those functions.

    The next thing I tried was to write an object plugin with the same functionality. I tried to set my camera as the return value of GetVirtualObjects() with the result that no camera was inserted at all.

    So my question is where to call AddCameraObject() or more explicitly InsertObject(camera,...) so that the plugin stops creating hundreds of cameras? Or am I using a wrong plugin type?

    Thanks in advance for your help,
    mfranke



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

    On 12/10/2007 at 11:13, xxxxxxxx wrote:

    Why not write a Command Plugin? That is what it is for - performing a set of operations as a command - once.

    Object and Tag plugins are for adding your own Object and Tag types. If you are just needing to add a camera, why bulk things up with a spurious Object or Tag?

    As you've noticed, Init() is called everytime the object or tag is created (which includes copies for cache building and rendering).

    Execute() is called FOREVER - it is for Expressions that are evaluated constantly. A camera would then be created everytime expressions are evaluated (whenever something in the document changes, during animation scrub, rendering).

    GetVirtualObjects() is for Generator-type Object plugins. That is, objects that modify their children such as HyperNURBS. The result returned is the modified result of the HyperNURBS to be displayed - not just any object. Thus 'Virtual' objects.

    Now, if your plugin is going to act like an object or tag, then you should consider it this way. There are no direct methods in the ObjectData or TagData (and NodeData parent) classes that can be used directly for this without the noticed consequences. You'll want to set up a button (say, "Add Camera") as a description resource and use Message() to get the MSG_DESCRIPTION_COMMAND and see if the id matches your button. Then create a camera when the user clicks the button.

    The Command plugin works something like that button but instead is a plugin in its own right. These are stored in the Plugins menu - but note that they can be docked in the layout as buttons as well. So someone could select an object and click the button - voila, a childed camera. And so on.


Log in to reply