API 过渡
Cinema 4D R20 introduced significant changes of the C++ API. The new MAXON API was introduced, which is fundamentally different that the previous, classic, API. The classic API is still available in the cinema.framework , but several components of the classic API have been replaced with new MAXON API components.
Any plugin that was written for an earlier SDK (R19 or older) must be adapted and re-compiled to work with Cinema 4D R20.
由于 Cinema 4D R20 the SDK does no longer contain any project files. The project files for frameworks, plugins and solutions must be created using the project Tool. See 工程工具 .
The source processor is part of the tool chain to build a plugin (see 源处理器 ). This source processor checks the source code and creates automatically additional code. The processor also checks the code style according to the level that is set in the project's projectdefinition.txt file (see 工程工具 ).
The naming scheme of string resource folders was changed. The resource folder that was named "strings_us" is now named "strings_en-US". See 插件资源 .
The complete MAXON API is defined in the maxon namespace. In contrast, the classic API is defined in the global namespace. To avoid collisions and ambiguity it might be necessary to use fully qualified names.
// This example uses explicit namespaces to use new and classic components.// creating a maxon::String maxon::String helloWorld { "Hello World" };
// creating a classic String ::String fooBar { "FooBar" };
Wherever possible unneeded includes and umbrella includes were removed. It might be necessary to add additional includes to include specific header files explicitly.
The global resources instances has been renamed to g_resource .
// This example loads the plugin's resources when // C4DPL_INIT_SYS is sent to PluginMessage(). case C4DPL_INIT_SYS : { // don't start plugin without resource if ( g_resource . Init () == false ) return false ; return true ; }Simple enumerations were reformatted as enumeration classes. Since "0" is not a valid enumeration value name it has been replaced with "NONE".
The macro ENUM_END_FLAGS() has been removed. If you have a custom enumeration you have to use MAXON_ENUM_LIST() or MAXON_ENUM_FLAGS() .
// This example uses the enumeration value DESCFLAGS_GET::NONE to use GetParameter(). // In previous versions of Cinema 4D this was DESCFLAGS_GET_0. GeData data; // access the parameter if (cubeObject->GetParameter( PRIM_CUBE_LEN , data, DESCFLAGS_GET::NONE ) == false ) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION );// get the value const 向量 size = data. GetVector (); DiagnosticOutput ( "Cube Size: @" , size);
The MAXON API introduces new data types and replaces or extends classic data types:
// set the name of the new sphere using a maxon::String sphere-> SetName ( "New Sphere" _s); doc-> InsertObject (sphere, nullptr , nullptr );
The MAXON API error system allows functions to return an explicit error state. Several functions of the classic API have been replaced with new functions that do return such an error state e.g. NewObj() or maxon::BaseArray::Append() . It is needed to handle this error state. See Error Handling .
The error system also allows to re-write functions so they return error states. This is extremely helpful to find the source of any error and to write stable code.
// This example shows how errors returned with "iferr_return" can be handled.// catch any error iferr_scope_handler { // print error to console err.DiagOutput(); // debug stop err.DbgStop(); };
// create and fill array maxon::BaseArray<maxon::Int> intValues; intValues. Append (100) iferr_return ; intValues. Append (200) iferr_return ;
// allocate memory maxon::AutoMem<maxon::Char> buffer = NewMemClear ( maxon::Char , 100) iferr_return ; // access memory buffer[0] = 0;
Several functions have been renamed to follow a consistent terminology. Functions like "Content()" that check if a given instance has any content have been renamed to "IsPopulated()" and "IsEmpty()".
// This example uses IsPopulated() and IsEmpty() to check the string.// create string const maxon::String someText { "some text" };
// check if populated if (someText.IsPopulated()) DiagnosticOutput ( "String is not empty" );
// check if empty if (someText.IsEmpty()) DiagnosticOutput ( "String is empty" );
Cinema 4D R20 introduced a new, complex and adaptable logger system. The standard console is just one of many available loggers now. One can write messages to the standard console using ApplicationOutput() 而不是 GePrint() 。见 LoggerInterface Manual .
// This example prints the given message to both the IDE console and the application console window.// define message const maxon::String someMessage { "some message" };
// print the message to the console DiagnosticOutput (someMessage);
// print the message to the application console window ApplicationOutput (someMessage);