编程建议

内容表

SDK 安装

The Cinema 4D C++ SDK can be installed in any location on the file system. It is not recommended to install it into any of the OS application-referred folders (e.g. "Program Files" or "Applications")

处理 API 函数和类

  • Include OS headers before Cinema 4D headers.
  • Keep code with shared OS and Cinema 4D calls as small as possible and gathered in one place (better portability and less data type conflicts).
  • When handling the classic API, only use the actual routines. Never use the C4DOS structure directly.
  • Do not use global static classes of complex types. Elementary data types (Int32, Float, Char etc.) are allowed, see Primitive Data Types Manual (Classic) .

使用本机 Cinema 4D 工作流

  • Make use of Cinema 4D 's concepts of writing data to files. See HyperFile Manual and DescribeIO Manual .
  • Deliver a functionality-complete integration of the plugins to support all Cinema 4D features and grant a consistent user's experience across plugins' use (e.g. see Undo System Manual ).

防御性编程

  • Always do "defensive programming". Check pointers and results everywhere.
  • Any API function may fail. Check for everything, even if it seems obvious e.g. NewMem() .
  • Any division needs to be checked for 0.0.
  • Not every element of Cinema 4D is implemented as a plugin, so GeListNode::GetNodeData() might return nullptr.
  • The order of evaluation depends on the compiler and platform. Make sure that operations are always called in the desired order. For example the functions of a pseudorandom number generator must be called explicitly in the correct order.

可移植性和兼容性

  • Only use Cinema 4D data types to ensure easy porting to other platforms. See 数据 & 算法 .
  • Make use of external resource files. Do not hardcode descriptions, dialogs and strings. See 资源文件手册 .
  • Always use constants to avoid compatibility problems.
  • Provide different binary versions of your plugins to support older versions of Cinema 4D .
  • Plugins compiled with a newer API will not load in an older version of Cinema 4D .
  • Information about previous Cinema 4D versions is only available for convenience. Only the latest API version can be supported. To maximize compatibility with a certain Cinema 4D version use the corresponding API.
  • Plugins compiled with older API will not automatically load in Cinema 4D R20 or newer versions. See 插件迁移 .

内存

关键性插件挂钩

延伸阅读