插件开发

内容表

SDK 安装

The C++ SDK is part of every distribution of Cinema 4D and is stored in the sdk.zip file. It can be installed in any location on the file system. For details see SDK 概述 .

警告
Do not change anything in the API, or the created plugins might be incompatible with Cinema 4D .

创建新插件工程

A new plugin module is created by adding a new folder to the SDK's "plugins" directory. This folder needs to have two sub-folders:

  • project: This folder contains the projectdefinition.txt file and all generated project files.
  • source: This folder contains the plugin's source code.
注意
The Project Tool will add all source code files found in the project folder to the project file. The Source Processor will only process source code files in the "source" folder.

The new project also has to be added to the solution's projectdefinition.txt file ("plugins/project"). The project files of the new project and the updated solution can be created by running the 工程工具 . The tool will create project files for the supported platforms which are currently Microsoft Windows and Apple macOS. See 微软 Windows 开发 , macOS 开发 and Linux 开发 .

警告
Beginning with Cinema 4D R20 the suffixes for plug-ins are respectively, for Windows and macOS, .xdl64 and .xlib. Plug-ins using the old suffixes (.cdl64 or .dylib) are simply skipped during the loading process. This is done to avoid issues with plug-ins from previous versions, which would not work in Cinema 4D R20+ anyway.
注意
If project files are created by any different tool than the 工程工具 , it is highly recommended to compare the custom-generated build settings and apply the needed changes in order to reflect the official settings. Please also note, MAXON's SDK Team only provides support for the official workflow and may not be able to help with issues arising from custom tool chains.

插件资源

A res folder can contain resources used by the plugin. Such resources are typically dialog and 描述 resource files. See 资源文件手册 . The plugin path can be obtained with GeGetPluginPath() .

The res folder typically has this structure:

  • within the res folder there might be a c4d_symbols.h header file which contains an enumeration for global symbol and string IDs.
  • a dialogs folder contains resource files for GeDialog based dialogs.
  • a description folder contains header and resource files for descriptions of NodeData based plugins. See Description Manual .
  • a strings_en-US folder contains string files for the default language (American English). The folder contains the sub-folders description and dialogs which include the string files for descriptions and dialogs. The folder may also contain a c4d_string.str file for global strings.

Further languages can be supported by creating new languages folders. Such a folder is constructed by using the language code (ISO 639-1) and a region ID. Please note that the region ID must be capitalized.

  • "ar-AE" - Arabic (U.A.E.)
  • "zh-CN" - Chinese (PRC)
  • "cs-CZ" - Czech
  • "de-DE" - German (Standard)
  • "it-IT" - Italian (Standard)
  • "ko-KR" - Korean (Republic of Korea)
  • "ja-JP" - Japanese
  • "pl-PL" - Polish
  • "ru-RU" - Russian
  • "es-ES" - Spanish (Standard)
  • "fr-FR" - French (Standard)
  • "en-US" - English (United States)

E.g. French language strings would be stored in a folder named "strings_fr-FR".

注意
Example resource files can be found in the cinema4dsdk example project.
MAXON API descriptions are based on new interfaces, see 数据描述 .

经典插件挂钩

Classic plugin hooks are built upon classes derived from BaseData . These classes define a set of virtual functions that are called by Cinema 4D . To create a plugin, simply derive a class from one of the data classes and implement the virtual functions. To register the derived class with Cinema 4D there is a specific "Register" function for each class.

一般插件信息手册 and 插件类型 .

MAXON API 插件

MAXON API plugins are based on interfaces. A plugin is created by implementing such interfaces and registering these implementations at public registries. See 接口基础 and Registries .

Specific functionality of the MAXON API is used by either directly using static functions or creating instances of specific classes. Such classes can either be standard C++ classes or reference classes that represent implementations of virtual interfaces. Such reference classes can also be obtained from extension points. See Entity Creation , 使用接口 and Registry Usage .

另请参阅 插件类型 .

自定义 ID

Every custom component - frameworks, plugins, interfaces, registries, implementations, etc. - must have a unique identifier. The MAXON API uses the reverse-domain notation to define such IDs. This means that third parties should use their company domain name to create the ID. E.g. if the company domain is "examplecompany.com" the reverse-domain name of a component would be "com.examplecompany.something".

If no custom domain is available one can construct a custom ID by using the developer's user name used in the support forum in the form of "example.doesnotexist.<forum_username>.something".

警告
Third parties cannot use "net.maxon" to name custom components.

插件、模块和依赖

模块和混合插件

Based on its content a plugin may be classified as a "module". Such a "module" is a plugin that only uses the frameworks of the new MAXON API and does not use the cinema.framework at all. Such a "module" must use the ".module" suffix in the folder name e.g. "example.module".

警告
A module must not reference or depend on the classic API (cinema.framework) in any way.

A plugin that uses the "classic" API of cinema.framework is typically described as a "hybrid" plugin (since it uses both "classic" and "new" API).

加载插件

Modules and "hybrid" plugins are loaded in this order:

  • First pure MAXON API modules are loaded.
  • Then "hybrid" plugins containing the string "config" are loaded.
  • Finally, all other "hybrid" plugins are loaded.

依赖

Typically the source processor manages the dependencies of modules and plugins. One can also define the dependencies of modules using the MAXON_DEPENDENCY_ON_MODULE() attribute in an arbitrary source code file of the dependent module.

E.g. if a module "net.example.module_b" depends on "net.example.module_a" a source code file of "module_b" can simply contain:

MAXON_DEPENDENCY_ON_MODULE ( "net.example.module_a" );

This makes sure that "com.examplecompany.module_a" is loaded before "module_b".

DLLs needed by a plugin can be placed in myplugin\res\libs\win64 ; DYLIBs can be placed in myplugin\res\libs\osx .

"config" Plugins

All "hybrid" plugin containing the string "config" in the name will be loaded before all other "hybrid" plugins. This allows such "config" plugins to modify the loading queue.

This is typically used to check the environment (library availability, keys, etc.) in order to enable or disable another plugin.

The plugin queue is edited by implementing a QueryStartupOrder() function:

extern "C" MAXON_ATTRIBUTE_DLL_PUBLIC void QueryStartupOrder ( maxon::BaseArray<maxon::Url> & dllsToLoad) { // check for some condition

for ( Int index = 0; index < dllsToLoad. GetCount (); index++) { maxon::String str = dllsToLoad[index].GetName().ToLower(); if (str.StartsWith( "someplugin" _s)) { MAXON_WARN_MUTE_UNUSED dllsToLoad. Erase (index); break ; } } }

执行插件

It is possible to install multiple versions of Cinema 4D and multiple versions of the SDK on the same system simultaneously. One has to define the plugin search path to make sure Cinema 4D will load custom plugins. The search path can be configured in the application's preferences or using a command line argument:

:: This example BATCH file starts Cinema 4D with two additional custom module paths "Cinema 4D.exe" g_additionalModulePath=C:\stable_plugins;C:\test_plugins

编程建议

For general advice on how to program Cinema 4D plugins and how to debug them see 编程建议 and 调试 .

延伸阅读

BATCH
BATCH
定义: corenodes_instances.h:24
Int
maxon::Int Int
定义: ge_sys_math.h:62
maxon::String
定义: string.h:1197
maxon::BaseArray
定义: basearray.h:366
maxon::BaseArray::GetCount
MAXON_ATTRIBUTE_FORCE_INLINE Int GetCount() const
定义: basearray.h:527
MAXON_ATTRIBUTE_DLL_PUBLIC
#define MAXON_ATTRIBUTE_DLL_PUBLIC
定义: apibase.h:89
maxon::QueryStartupOrder
void(*)(BaseArray< Url > &dllsToLoad) QueryStartupOrder
定义: dll.h:112
MAXON_WARN_MUTE_UNUSED
#define MAXON_WARN_MUTE_UNUSED
The MAXON_WARN_MUTE_UNUSED macro is deprecated. Please use iferr_ignore or iferr_cannot_fail and spec...
定义: compilerdetection.h:326
maxon::BaseArray::Erase
ResultPtr< T > Erase(Int position, Int eraseCnt=1)
定义: basearray.h:865
MAXON_DEPENDENCY_ON_MODULE
#define MAXON_DEPENDENCY_ON_MODULE(module)
定义: module.h:659

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1