C4DtoA offers a render command for third-party developers to use a custom driver for rendering or the IPR to display the result in an external viewer.

The command id is 1038578 (ARNOLD_RENDER_COMMAND in c4dtoa_symbols.h) and has the following sub ids:

  • 1: start an IPR session.
  • 2: stop the IPR session.
  • 3: pause / unpause the IPR.
  • 4: update the IPR (if there are any changes in the scene).
  • 5: start a normal render (still or animation).

 

The render settings have to be passed via the document settings (see the example code below) where the following ids are available (see arnold_renderer.h):

IDNameTypeDescription
1000C4DTOA_RENDEROVERRIDE_DRIVER LinkThe custom driver object.
1001C4DTOA_RENDEROVERRIDE_ONLY_BEAUTY BoolIf true then no AOVs of the display driver are exported. Default is true.
1002C4DTOA_RENDEROVERRIDE_EXPORT_ALL_DRIVERS BoolIf false then only the display driver is exported. Default is true. 
1003C4DTOA_RENDEROVERRIDE_CAMERA LinkThe camera object used for rendering. The active camera is used when does not set.
1004C4DTOA_RENDEROVERRIDE_XRES Int32Render resolution width.
1005C4DTOA_RENDEROVERRIDE_YRESInt32Render resolution height.
1006C4DTOA_RENDEROVERRIDE_USE_REGIONBoolIf true then a region is rendered.
1007C4DTOA_RENDEROVERRIDE_REGION_X1Int32Left border of the render region.
1008C4DTOA_RENDEROVERRIDE_REGION_X2Int32Right border of the render region.
1009C4DTOA_RENDEROVERRIDE_REGION_Y1Int32Top border of the render region.
1010C4DTOA_RENDEROVERRIDE_REGION_Y2Int32Bottom border of the render region.
1011C4DTOA_RENDEROVERRIDE_AA_SAMPLESInt32Override of the camera AA samples.
1012C4DTOA_RENDEROVERRIDE_IGNORE_MOTION_BLURBoolOverride of the Ignore motion blur flag.
1013C4DTOA_RENDEROVERRIDE_IGNORE_SUBDIVBoolOverride of the Ignore subdivision flag.
1014C4DTOA_RENDEROVERRIDE_IGNORE_DISPLACEMENTBoolOverride of the Ignore displacement flag.
1015C4DTOA_RENDEROVERRIDE_IGNORE_BUMPBoolOverride of the Ignore bump flag.
1016C4DTOA_RENDEROVERRIDE_IGNORE_SSSBoolOverride of the Ignore SSS flag.
1017C4DTOA_RENDEROVERRIDE_FRAME_STARTInt32Start frame when rendering an animation. Used only in a normal render session (id 5).
1018C4DTOA_RENDEROVERRIDE_FRAME_ENDInt32End frame when rendering an animation. Used only in a normal render session (id 5).
1019C4DTOA_RENDEROVERRIDE_FRAME_STEPInt32Frame step when rendering an animation. Used only in a normal render session (id 5).
1020C4DTOA_RENDEROVERRIDE_PROGRESSIVE_REFINEMENTBoolEnable / disable progressive refinement in the IPR.
1021C4DTOA_RENDEROVERRIDE_PROGRESSIVE_SAMPLESInt32Initial level of progressive refinement (e.g. -3).
1022C4DTOA_RENDEROVERRIDE_PROGRESSIVE_RENDERBoolEnable / disable progressive rendering.
1023C4DTOA_RENDEROVERRIDE_RENDER_TO_BUFFERBool

Render to a memory buffer instead of the UI. Works only with a c4dtoa_display_driver. See Display driver memory buffer | API.

 

This is a simple example how to use the API:

#include "c4d.h"
#include "c4dtoa_symbols.h"
#include "arnold_renderer.h"
 
void StartIPR(BaseDocument* doc)
{
    // look for our custom driver object
    BaseObject* driver = doc->SearchObject("My Driver");
    if (driver == nullptr)
        return;

    // setup render settings
    BaseContainer settings;
    settings.SetLink(C4DTOA_RENDEROVERRIDE_DRIVER, driver);
    settings.SetInt32(C4DTOA_RENDEROVERRIDE_XRES, 400);
    settings.SetInt32(C4DTOA_RENDEROVERRIDE_YRES, 300);
    settings.SetBool(C4DTOA_RENDEROVERRIDE_PROGRESSIVE_REFINEMENT, FALSE);
    BaseObject* camera = doc->SearchObject("Camera");
    if (camera)
       settings.SetLink(C4DTOA_RENDEROVERRIDE_CAMERA, camera);

    // store the settings in the document
    doc->GetSettingsInstance(DOCUMENTSETTINGS_DOCUMENT)->SetContainer(ARNOLD_RENDER_OVERRIDES, settings);


    // start the IPR
    CallCommand(ARNOLD_RENDER_COMMAND, 1);
}
    
void StopIPR()
{
    CallCommand(ARNOLD_RENDER_COMMAND, 2);
}

void UpdateIPR(BaseDocument* doc)
{
    // get the current settings
    BaseContainer settings = doc->GetSettingsInstance(DOCUMENTSETTINGS_DOCUMENT)->GetContainer(ARNOLD_RENDER_OVERRIDES);
    
    // setup the new settings
    settings.SetInt32(C4DTOA_RENDEROVERRIDE_XRES, 640);
    settings.SetInt32(C4DTOA_RENDEROVERRIDE_YRES, 480);
    settings.RemoveData(C4DTOA_RENDEROVERRIDE_CAMERA);

    // store the new settings
    doc->GetSettingsInstance(DOCUMENTSETTINGS_DOCUMENT)->SetContainer(ARNOLD_RENDER_OVERRIDES, settings);

    // trigger the update
    CallCommand(ARNOLD_RENDER_COMMAND, 4);
    // NOTE You can call EventAdd() as well, but it has a limitation
    // that the IPR does not update until the mouse button is down
    // (e.g. while changing a numeric or color slider).
}

void Render(BaseDocument* doc)
{
    // look for our custom driver object
    BaseObject* driver = doc->SearchObject("My Driver");
    if (driver == nullptr)
        return;

    // setup render settings
    BaseContainer settings;
    settings.SetLink(C4DTOA_RENDEROVERRIDE_DRIVER, driver);
    settings.SetInt32(C4DTOA_RENDEROVERRIDE_XRES, 400);
    settings.SetInt32(C4DTOA_RENDEROVERRIDE_YRES, 300);
    settings.SetInt32(C4DTOA_RENDEROVERRIDE_FRAME_START, 10);
    settings.SetInt32(C4DTOA_RENDEROVERRIDE_FRAME_END, 15);
    settings.SetInt32(C4DTOA_RENDEROVERRIDE_FRAME_STEP, 1);
    
    // store the settings in the document
    doc->GetSettingsInstance(DOCUMENTSETTINGS_DOCUMENT)->SetContainer(ARNOLD_RENDER_OVERRIDES, settings);

    // start the render
    CallCommand(ARNOLD_RENDER_COMMAND, 4);
}

Python

The command can be called from a python script as well. See this example: render_with_custom_driver.py.

 

  • No labels
© 2020-2021 Autodesk. All Rights Reserved / website terms / privacy/cookies / ccpa settings