Skip to content

Commit 37451cd

Browse files
committed
C++ SDK: Release 2025.2.0
1 parent 01580c5 commit 37451cd

34 files changed

Lines changed: 1356 additions & 255 deletions

plugins/example.assets/source/asset_api_examples/examples_assets.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ maxon::Result<void> LinkMediaAssets(
316316
return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION, "Could not allocate shader."_s);
317317

318318
material->InsertShader(shader);
319-
if (!material->SetParameter(ConstDescID(DescLevel(MATERIAL_COLOR_SHADER)), shader, DESCFLAGS_SET::NONE))
319+
if (!material->SetParameter(ConstDescIDLevel(MATERIAL_COLOR_SHADER), shader, DESCFLAGS_SET::NONE))
320320
return maxon::IllegalStateError(MAXON_SOURCE_LOCATION, "Could not link shader."_s);
321321

322322
// Get the asset url and check if it is empty.
@@ -326,7 +326,7 @@ maxon::Result<void> LinkMediaAssets(
326326
const Filename file = MaxonConvert(url);
327327

328328
// Set the asset url as the filename parameter of the bitmap shader.
329-
if (!shader->SetParameter(ConstDescID(DescLevel(BITMAPSHADER_FILENAME)), file, DESCFLAGS_SET::NONE))
329+
if (!shader->SetParameter(ConstDescIDLevel(BITMAPSHADER_FILENAME), file, DESCFLAGS_SET::NONE))
330330
return maxon::IllegalArgumentError(MAXON_SOURCE_LOCATION, "Could not set texture file."_s);
331331

332332
// Name the material after the asset and insert it into the document.

plugins/example.assets/source/asset_api_examples/examples_contexts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ maxon::Result<void> RunLoadMaterialAssets()
891891
iferr_scope;
892892

893893
// Skip over asset that is not matching the search criteria.
894-
maxon::AssetMetaData assetMetadata = assetDescription.GetMetaData();
894+
const maxon::AssetMetaData& assetMetadata = assetDescription.GetMetaData();
895895
maxon::Id assetSubtype = assetMetadata.Get(
896896
maxon::ASSETMETADATA::SubType, maxon::Id()) iferr_return;
897897

plugins/example.assets/source/asset_api_examples/examples_databases.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ maxon::Result<void> FilteredAssetSerach(const maxon::AssetRepositoryRef& reposit
563563

564564
// Retrieve the asset subtype of the currently yielded asset. See the metadata examples for
565565
// details on the asset metadata model.
566-
maxon::AssetMetaData assetMetadata = asset.GetMetaData();
566+
const maxon::AssetMetaData& assetMetadata = asset.GetMetaData();
567567
maxon::Id assetSubtype = assetMetadata.Get(
568568
maxon::ASSETMETADATA::SubType, maxon::Id()) iferr_return;
569569

plugins/example.assets/source/asset_api_examples/examples_metadata.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ maxon::Result<void> AccessAssetDescriptionData(const maxon::AssetDescription& as
8080
// contains most of the descriptive and administrative metadata associated with an asset.
8181
const maxon::AssetRepositoryRef assetRepository = assetDescription.GetRepository();
8282
const maxon::Id assetRepositoryId = assetDescription.GetRepositoryId();
83-
const maxon::AssetMetaData assetMetadata = assetDescription.GetMetaData();
83+
const maxon::AssetMetaData& assetMetadata = assetDescription.GetMetaData();
8484
ApplicationOutput("\tAsset Repository Id: @", assetRepositoryId);
8585
ApplicationOutput("\tAsset Metadata: @", assetMetadata);
8686

@@ -133,7 +133,7 @@ maxon::Result<maxon::AssetDescription> AddAssetVersion(
133133
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION,
134134
"The repository the asset is attached to is read-only."_s);
135135

136-
const maxon::AssetMetaData metadata = asset.GetMetaData();
136+
const maxon::AssetMetaData& metadata = asset.GetMetaData();
137137
const maxon::Id subtype = metadata.Get<
138138
decltype(maxon::ASSETMETADATA::SubType)>().GetOrDefault() iferr_return;
139139

@@ -416,7 +416,7 @@ maxon::Result<void> IterateAssetMetadata(const maxon::AssetDescription& assetDes
416416
iferr_scope;
417417

418418
// Get the metadata.
419-
const maxon::AssetMetaData metadata = assetDescription.GetMetaData();
419+
const maxon::AssetMetaData& metadata = assetDescription.GetMetaData();
420420

421421
// Access all existing entries and iterate over them.
422422
using MetaDataTuple = maxon::Tuple<maxon::InternedId, maxon::AssetMetaData::KIND>;
@@ -444,7 +444,7 @@ maxon::Result<void> ReadAssetMetadata(const maxon::AssetDescription& assetDescri
444444
ApplicationOutput("Reading Asset Metadata for: @\n", assetDescription);
445445

446446
// Get the metadata from the asset description.
447-
const maxon::AssetMetaData metadata = assetDescription.GetMetaData();
447+
const maxon::AssetMetaData& metadata = assetDescription.GetMetaData();
448448
// Get the language Cinema 4D is currently running in.
449449
const maxon::LanguageRef currentLanguage = maxon::Resource::GetCurrentLanguage();
450450

plugins/example.assets/source/dots_preset_asset_impl/dots_preset_asset.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,11 @@ MAXON_METHOD maxon::Result<maxon::Url> DotsPresetAssetImpl::GeneratePreview(maxo
174174

175175
// Get the asset description and metadata.
176176
maxon::AssetDescription asset = super.GetDescription() iferr_return;
177-
maxon::AssetMetaData metadata = asset.GetMetaData();
177+
const maxon::AssetMetaData& metadata = asset.GetMetaData();
178178

179179
// Access the custom metadata attribute for the the dot scale or return a default value of 0.025
180180
// when that entry has not been populated.
181-
maxon::Float32 dotScale = metadata.Get(
182-
maxon::ASSETMETADATA::DOTSPRESET::DOT_SCALE, 0.025F) iferr_return;
181+
maxon::Float32 dotScale = metadata.Get(maxon::ASSETMETADATA::DOTSPRESET::DOT_SCALE, 0.025F) iferr_return;
183182

184183
// Core implementation
185184
// Initialize a drawing canvas and render the thumbnail in the requested size.

plugins/example.assets/source/dots_preset_asset_impl/examples_dots.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ maxon::Result<void> UpdatePreviewThumbnail(
124124
// Get the asset metadata and the existing or default entry of 0.025F for the dot scale. This
125125
// custom metadata attribute has been defined in the dots preset asset implementation and will
126126
// only be carried by that asset type.
127-
maxon::AssetMetaData metadata = assetDescription.GetMetaData();
128-
maxon::Float32 oldValue = metadata.Get(
129-
maxon::ASSETMETADATA::DOTSPRESET::DOT_SCALE, 0.025F) iferr_return;
127+
const maxon::AssetMetaData& metadata = assetDescription.GetMetaData();
128+
maxon::Float32 oldValue = metadata.Get(maxon::ASSETMETADATA::DOTSPRESET::DOT_SCALE, 0.025F) iferr_return;
130129

131130
// The new value clamped to the interval [0.025, 0.1].
132131
maxon::Float32 newValue = maxon::ClampValue(oldValue + difference, 0.025F, 0.1F);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# example.hello_world
2+
3+
Contains a bare-bones example of a Cinema 4D module with a singular command plugin that opens a "Hello World" dialog when invoked.
4+
5+
| Filename | Description |
6+
|---|---|
7+
| `project\projectdefinition.txt` | Contains the build configuration of the module. |
8+
| `source\main.cpp` | Contains all the source code of the module. |
9+
10+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// The platforms this project is targeting - can be [Win64;OSX;Linux].
2+
Platform=Win64;OSX;Linux
3+
4+
// Type of project - can be [Lib;DLL;App], DLL is for (plugin) modules, lib for static libraries,
5+
// effectively frameworks, and App for standalone applications (not possible for plugins).
6+
Type=DLL
7+
8+
// The frameworks dependencies of this module. One can only include header files from frameworks
9+
// which are listed here. The selection here is a good starting point for most projects.
10+
APIS=\
11+
asset.framework;\
12+
cinema.framework;\
13+
cinema_hybrid.framework;\
14+
core.framework
15+
16+
// Enable Cinema API features for this module, and then reenable style checks again (because
17+
// C4D=true disables them).
18+
C4D=true
19+
stylecheck.level=3
20+
21+
// The ID of the module which is being compiled. One should use the reversed domain notation, derived
22+
// from a domain name you own, followed by plugin qualifiers, e.g, "net.mycompany.mymodule" or
23+
// "net.mycompany.mysuite.mymodule". It is important that this ID is unique, as Cinema 4D will
24+
// not load two modules with the same ID. Please note that Cinema 4D will also not load modules
25+
// with a "net.maxon" domain, as this domain is reserved for Maxon modules.
26+
ModuleId=net.maxonexample.hello_world
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/* Hello World Command Plugin
2+
(C) MAXON Computer GmbH, 2025
3+
4+
Author: Ferdinand Hoppe
5+
Date: 27/03/2025
6+
7+
Realizes a simple command plugin that opens a message dialog with the text "Hello World!" once it
8+
has been invoked.
9+
10+
The main focus of this example is to get the plugin message infrastructure up and running that is
11+
required to register all Cinema API plugins.
12+
*/
13+
14+
// -------------------------------------------------------------------------------------------------
15+
// This section contains the code that is usually placed in the main.cpp file of a project. It is
16+
// custom to separate a project into a main.cpp file - which handles all the module messages
17+
// for its plugins - and one or multiple files which realize the actual plugins.
18+
// -------------------------------------------------------------------------------------------------
19+
#include "c4d_plugin.h"
20+
#include "c4d_resource.h"
21+
22+
// Forward declaration of the the #RegisterMyPlugin() function we implement below, so we can use
23+
// the function in #PluginStart below.
24+
bool RegisterMyPlugin();
25+
26+
// Called by Cinema 4D in its boot sequence when this module is being loaded. This is the entry
27+
// point to register Cinema API plugins. A plugin which does not register itself or whose
28+
// registration fails will not be accessible to users.
29+
cinema::Bool cinema::PluginStart()
30+
{
31+
// Attempt to register our plugin.
32+
if (!RegisterMyPlugin())
33+
return false;
34+
return true;
35+
}
36+
37+
// Called by Cinema 4D in its shutdown sequence when this module is about to be unloaded. Most
38+
// plugins use the empty implementation shown here as they do not have to free resources.
39+
void cinema::PluginEnd()
40+
{
41+
}
42+
43+
// Called by Cinema 4D when a plugin message is sent to this module. There are several messages but
44+
// all modules must implement at least C4DPL_INIT_SYS as shown below. Otherwise the module and its
45+
// plugins will not work.
46+
cinema::Bool cinema::PluginMessage(cinema::Int32 id, void* data)
47+
{
48+
switch (id)
49+
{
50+
// g_resource is a global variable that is used to manage resources in Cinema 4D. It is
51+
// defined in the c4d_resource.h file which we include above. We cannot start our module
52+
// if the resource management has not been initialized.
53+
case C4DPL_INIT_SYS:
54+
{
55+
if (!cinema::g_resource.Init())
56+
return false;
57+
return true;
58+
}
59+
}
60+
return false;
61+
}
62+
63+
// -------------------------------------------------------------------------------------------------
64+
// This section contains the code that is usually placed in a myplugin.cpp and/or myplugin.h file.
65+
// It contains the actual plugin implementation and usually also the registration function for the
66+
// plugin as these functions must have access to the plugin class.
67+
// -------------------------------------------------------------------------------------------------
68+
69+
#include "c4d.h"
70+
#include "c4d_gui.h"
71+
72+
// Realizes the most basic plugin possible, a command that opens a message dialog with the text
73+
// "Hello World!" once it has been invoked.
74+
class MyPluginCommand : public cinema::CommandData
75+
{
76+
public:
77+
78+
// Called by Cinema 4D when this command is being invoked, either by a user pressing a menu item,
79+
// a button, or by a CallCommand() call made from C++ or Python code.
80+
virtual cinema::Bool Execute(cinema::BaseDocument* doc, cinema::GeDialog* parentManager)
81+
{
82+
cinema::MessageDialog("Hello World!"_s);
83+
return true;
84+
}
85+
};
86+
87+
// The ID to register the plugin with. This ID must be unique to this registration call and new IDs
88+
// must be obtained from https://developers.maxon.net/forum/pid .
89+
const cinema::Int32 g_plugin_id = 1063013;
90+
91+
// Calls the registration function for a CommandData plugin with an instance of our command class.
92+
cinema::Bool RegisterMyPlugin()
93+
{
94+
return cinema::RegisterCommandPlugin(
95+
g_plugin_id, "Hello World Command"_s, 0, nullptr, "Hello World Tooltip"_s,
96+
NewObjClear(MyPluginCommand));
97+
}

0 commit comments

Comments
 (0)