ai_nodes.h
Go to the documentation of this file.
1// Copyright 2023 Autodesk, Inc. All rights reserved.
2//
3// Use of this software is subject to the terms of the Autodesk license
4// agreement provided at the time of installation or download, or which
5// otherwise accompanies this software in either electronic or hard copy form.
6
12#pragma once
13#include "ai_node_entry.h"
14#include "ai_params.h"
15#include "ai_api.h"
16#include "ai_string.h"
17
18// forward declarations
19class AtUniverse;
20struct AtList;
21struct AtNodeEntry;
22struct AtUserParamEntry;
23struct AtUserParamIterator;
24
63struct AtNode;
64
71#define node_parameters \
72static void Parameters(AtList* params, AtNodeEntry* nentry)
73
75#define node_plugin_initialize \
76static bool PluginInitialize(void** plugin_data); \
77AI_OPTIONAL_METHOD_INSTALL(ai_common_mtds, PluginInitialize) \
78static bool PluginInitialize(void** plugin_data)
79
81#define node_plugin_cleanup \
82static void PluginCleanup(void* plugin_data); \
83AI_OPTIONAL_METHOD_INSTALL(ai_common_mtds, PluginCleanup) \
84static void PluginCleanup(void* plugin_data)
85
87#define node_initialize \
88static void Initialize(AtRenderSession* render_session, AtNode* node)
89
91#define node_update \
92static void Update(AtRenderSession* render_session, AtNode* node)
93
95#define node_finish \
96static void Finish(AtNode* node)
97
99#define node_loader \
100AI_EXPORT_LIB bool NodeLoader(int i, AtNodeLib* node)
101/* \}*/
102
104#define AI_INSTANCE_COMMON_METHODS \
105node_parameters; \
106node_initialize; \
107node_update; \
108node_finish; \
109static AtCommonMethods ai_common_mtds = { \
110 NULL, \
111 NULL, \
112 Parameters, \
113 Initialize, \
114 Update, \
115 Finish \
116};
117
119#define AI_INSTANCE_COMMON_SHAPE_METHODS \
120node_parameters; \
121static AtCommonMethods ai_common_mtds = { \
122 NULL, \
123 NULL, \
124 Parameters, \
125 NULL, \
126 NULL, \
127 NULL \
128};
129
134AI_API AtNode* AiNode (AtUniverse* universe, const AtString nentry_name, const AtString name = AtString(), const AtNode* parent = NULL);
135AI_API AI_PURE AtNode* AiNodeLookUpByName (const AtUniverse* universe, const AtString name, const AtNode* parent = NULL);
136AI_API bool AiNodeDeclare (AtNode* node, const AtString param, const char* declaration);
137AI_API AI_PURE const AtUserParamEntry* AiNodeLookUpUserParameter (const AtNode* node, const AtString param);
138AI_API AI_PURE bool AiNodeIs (const AtNode* node, AtString str);
139AI_API void AiNodeReset (AtNode* node);
140AI_API void AiNodeResetParameter (AtNode* node, const char* param);
141AI_API AtNode* AiNodeClone (const AtNode* node, const AtString new_name = AtString(), const AtNode* parent = NULL);
142AI_API bool AiNodeDestroy (AtNode* node);
143AI_API void AiNodeReplace (AtNode* old_node, AtNode* new_node, bool remove);
144AI_API bool AiNodeLink (AtNode* src, const char* input, AtNode* target);
145AI_API bool AiNodeLinkOutput (AtNode* src, const char* output, AtNode* target, const char* input);
146AI_API bool AiNodeUnlink (AtNode* node, const char* input);
147AI_API AI_PURE bool AiNodeIsLinked (const AtNode* node, const char* input);
148AI_API AtNode* AiNodeGetLink (const AtNode* node, const char* input, int* comp = NULL);
149AI_API AtNode* AiNodeGetLinkOutput (const AtNode* node, const char* input, int& output_param, int& output_comp);
150AI_API AI_PURE const char* AiNodeGetName (const AtNode* node);
151AI_API AI_PURE const AtNodeEntry* AiNodeGetNodeEntry (const AtNode* node);
152AI_API AI_PURE void* AiNodeGetLocalData (const AtNode* node);
153AI_API void AiNodeSetLocalData (AtNode* node, void* data);
154AI_API AI_PURE void* AiNodeGetPluginData (const AtNode* node);
155AI_API void AiNodeSetDisabled (AtNode* node, bool disabled);
156AI_API AI_PURE bool AiNodeIsDisabled (const AtNode* node);
157AI_API AI_PURE AtNode* AiNodeGetParent (const AtNode* node);
158AI_API AI_PURE AtUniverse* AiNodeGetUniverse (const AtNode* node);
159AI_API AtUserParamIterator* AiNodeGetUserParamIterator(const AtNode* node);
160
161#ifdef AI_CPU_COMPILER
162
163// these are slower than the AtString versions
164inline AI_DEPRECATED AtNode* AiNode (AtUniverse* universe, const char* nentry_name, const char* name = "", const AtNode* parent = NULL) { return AiNode(universe, AtString(nentry_name), AtString(name), parent); }
165inline AI_DEPRECATED AtNode* AiNodeLookUpByName (const AtUniverse* universe, const char* name, const AtNode* parent = NULL) { return AiNodeLookUpByName(universe, AtString(name), parent); }
166inline AI_DEPRECATED bool AiNodeDeclare (AtNode* node, const char* param, const char* declaration) { return AiNodeDeclare(node, AtString(param), declaration); }
167inline AI_DEPRECATED const AtUserParamEntry* AiNodeLookUpUserParameter (const AtNode* node, const char* param) { return AiNodeLookUpUserParameter(node, AtString(param)); }
168#endif
169/* \}*/
170
175AI_API void AiUserParamIteratorDestroy(AtUserParamIterator* iter);
176AI_API const AtUserParamEntry* AiUserParamIteratorGetNext(AtUserParamIterator* iter);
177AI_API bool AiUserParamIteratorFinished(const AtUserParamIterator* iter);
178/* \}*/
179
184AI_API void AiNodeSetByte (AtNode* node, const AtString param, uint8_t val);
185AI_API void AiNodeSetInt (AtNode* node, const AtString param, int val);
186AI_API void AiNodeSetUInt (AtNode* node, const AtString param, unsigned int val);
187AI_API void AiNodeSetBool (AtNode* node, const AtString param, bool val);
188AI_API void AiNodeSetFlt (AtNode* node, const AtString param, float val);
189AI_API void AiNodeSetPtr (AtNode* node, const AtString param, void* val);
190AI_API void AiNodeSetArray (AtNode* node, const AtString param, AtArray* val);
191AI_API void AiNodeSetMatrix(AtNode* node, const AtString param, AtMatrix val);
192AI_API void AiNodeSetStr (AtNode* node, const AtString param, const AtString str);
193AI_API void AiNodeSetRGB (AtNode* node, const AtString param, float r, float g, float b);
194AI_API void AiNodeSetRGBA (AtNode* node, const AtString param, float r, float g, float b, float a);
195AI_API void AiNodeSetVec (AtNode* node, const AtString param, float x, float y, float z);
196AI_API void AiNodeSetVec2 (AtNode* node, const AtString param, float x, float y);
197
198#ifdef AI_CPU_COMPILER
199// these are slower than the AtString versions
200inline AI_DEPRECATED void AiNodeSetByte (AtNode* node, const char* param, uint8_t val) { AiNodeSetByte (node, AtString(param), val); }
201inline AI_DEPRECATED void AiNodeSetInt (AtNode* node, const char* param, int val) { AiNodeSetInt (node, AtString(param), val); }
202inline AI_DEPRECATED void AiNodeSetUInt (AtNode* node, const char* param, unsigned int val) { AiNodeSetUInt (node, AtString(param), val); }
203inline AI_DEPRECATED void AiNodeSetBool (AtNode* node, const char* param, bool val) { AiNodeSetBool (node, AtString(param), val); }
204inline AI_DEPRECATED void AiNodeSetFlt (AtNode* node, const char* param, float val) { AiNodeSetFlt (node, AtString(param), val); }
205inline AI_DEPRECATED void AiNodeSetPtr (AtNode* node, const char* param, void* val) { AiNodeSetPtr (node, AtString(param), val); }
206inline AI_DEPRECATED void AiNodeSetArray (AtNode* node, const char* param, AtArray* val) { AiNodeSetArray (node, AtString(param), val); }
207inline AI_DEPRECATED void AiNodeSetMatrix(AtNode* node, const char* param, AtMatrix val) { AiNodeSetMatrix(node, AtString(param), val); }
208inline AI_DEPRECATED void AiNodeSetStr (AtNode* node, const char* param, const char* str) { AiNodeSetStr (node, AtString(param), AtString(str)); }
209inline AI_DEPRECATED void AiNodeSetRGB (AtNode* node, const char* param, float r, float g, float b) { AiNodeSetRGB (node, AtString(param), r, g, b); }
210inline AI_DEPRECATED void AiNodeSetRGBA (AtNode* node, const char* param, float r, float g, float b, float a) { AiNodeSetRGBA (node, AtString(param), r, g, b, a); }
211inline AI_DEPRECATED void AiNodeSetVec (AtNode* node, const char* param, float x, float y, float z) { AiNodeSetVec (node, AtString(param), x, y, z); }
212inline AI_DEPRECATED void AiNodeSetVec2 (AtNode* node, const char* param, float x, float y) { AiNodeSetVec2 (node, AtString(param), x, y); }
213#endif
214
215AI_API void AiNodeSetAttributes(AtNode *node, const char* attributes);
216/* \}*/
217
222AI_API uint8_t AiNodeGetByte (const AtNode* node, const AtString param);
223AI_API int AiNodeGetInt (const AtNode* node, const AtString param);
224AI_API unsigned int AiNodeGetUInt (const AtNode* node, const AtString param);
225AI_API bool AiNodeGetBool (const AtNode* node, const AtString param);
226AI_API float AiNodeGetFlt (const AtNode* node, const AtString param);
227AI_API AtRGB AiNodeGetRGB (const AtNode* node, const AtString param);
228AI_API AtRGBA AiNodeGetRGBA (const AtNode* node, const AtString param);
229AI_API AtVector AiNodeGetVec (const AtNode* node, const AtString param);
230AI_API AtVector2 AiNodeGetVec2 (const AtNode* node, const AtString param);
231AI_API AtString AiNodeGetStr (const AtNode* node, const AtString param);
232AI_API void* AiNodeGetPtr (const AtNode* node, const AtString param);
233AI_API AtArray* AiNodeGetArray (const AtNode* node, const AtString param);
234AI_API AtMatrix AiNodeGetMatrix(const AtNode* node, const AtString param);
235
236#ifdef AI_CPU_COMPILER
237// these are slower than the AtString versions
238inline AI_DEPRECATED uint8_t AiNodeGetByte (const AtNode* node, const char* param) { return AiNodeGetByte (node, AtString(param)); }
239inline AI_DEPRECATED int AiNodeGetInt (const AtNode* node, const char* param) { return AiNodeGetInt (node, AtString(param)); }
240inline AI_DEPRECATED unsigned int AiNodeGetUInt (const AtNode* node, const char* param) { return AiNodeGetUInt (node, AtString(param)); }
241inline AI_DEPRECATED bool AiNodeGetBool (const AtNode* node, const char* param) { return AiNodeGetBool (node, AtString(param)); }
242inline AI_DEPRECATED float AiNodeGetFlt (const AtNode* node, const char* param) { return AiNodeGetFlt (node, AtString(param)); }
243inline AI_DEPRECATED AtRGB AiNodeGetRGB (const AtNode* node, const char* param) { return AiNodeGetRGB (node, AtString(param)); }
244inline AI_DEPRECATED AtRGBA AiNodeGetRGBA (const AtNode* node, const char* param) { return AiNodeGetRGBA (node, AtString(param)); }
245inline AI_DEPRECATED AtVector AiNodeGetVec (const AtNode* node, const char* param) { return AiNodeGetVec (node, AtString(param)); }
246inline AI_DEPRECATED AtVector2 AiNodeGetVec2 (const AtNode* node, const char* param) { return AiNodeGetVec2 (node, AtString(param)); }
247inline AI_DEPRECATED AtString AiNodeGetStr (const AtNode* node, const char* param) { return AiNodeGetStr (node, AtString(param)); }
248inline AI_DEPRECATED void* AiNodeGetPtr (const AtNode* node, const char* param) { return AiNodeGetPtr (node, AtString(param)); }
249inline AI_DEPRECATED AtArray* AiNodeGetArray (const AtNode* node, const char* param) { return AiNodeGetArray (node, AtString(param)); }
250inline AI_DEPRECATED AtMatrix AiNodeGetMatrix(const AtNode* node, const char* param) { return AiNodeGetMatrix(node, AtString(param)); }
251
252/* \}*/
253
254/*\}*/
255
256#define AiNodeDeclareGPULocalData(type) namespace {}
257#endif
DLL export prefix for API functions (necessary for multi-platform development)
AtNodeEntry type and methods.
Node parameters.
AtString class for fast comparisons.
Arnold String allows for fast string comparisons.
Definition: ai_string.h:46
AI_API AtNode * AiNode(AtUniverse *universe, const AtString nentry_name, const AtString name=AtString(), const AtNode *parent=NULL)
Create a fresh instantiation of a node in a specific Arnold universe.
Definition: ai_nodes.cpp:317
AI_API void AiNodeSetLocalData(AtNode *node, void *data)
Sets local data pointer in the node.
Definition: ai_nodes.cpp:268
AI_API AtNode * AiNodeGetLinkOutput(const AtNode *node, const char *input, int &output_param, int &output_comp)
Returns the node, node output, and output component connected to a given node input parameter.
Definition: ai_nodes.cpp:551
AI_API AI_PURE AtNode * AiNodeGetParent(const AtNode *node)
Returns the procedural parent of a node.
Definition: ai_nodes.cpp:1028
AI_API bool AiNodeUnlink(AtNode *node, const char *input)
Removes a connection from a node input parameter.
Definition: ai_nodes.cpp:469
AI_API AI_PURE const char * AiNodeGetName(const AtNode *node)
Return the node's name.
Definition: ai_nodes.cpp:227
AI_API const AtUserParamEntry * AiUserParamIteratorGetNext(AtUserParamIterator *iter)
Returns current user param entry and points user param iterator to the next one.
Definition: ai_nodes.cpp:200
AI_API AI_PURE bool AiNodeIs(const AtNode *node, AtString str)
Compare the node type against a string.
Definition: ai_nodes.cpp:578
AI_API bool AiNodeLink(AtNode *src, const char *input, AtNode *target)
Creates a connection between two shader nodes.
Definition: ai_nodes.cpp:385
AI_API AtNode * AiNodeGetLink(const AtNode *node, const char *input, int *comp=NULL)
Returns the node connected to a given node input parameter.
Definition: ai_nodes.cpp:521
AI_API AI_PURE bool AiNodeIsDisabled(const AtNode *node)
Check if a node has been disabled or not.
Definition: ai_nodes.cpp:1009
AI_API bool AiUserParamIteratorFinished(const AtUserParamIterator *iter)
Returns true if there are no more user parameters to iterate over.
Definition: ai_nodes.cpp:211
AI_API AI_PURE bool AiNodeIsLinked(const AtNode *node, const char *input)
Returns true if the input parameter is linked.
Definition: ai_nodes.cpp:496
AI_API AtUserParamIterator * AiNodeGetUserParamIterator(const AtNode *node)
Creates and returns a new AtUserParamIterator for this node.
Definition: ai_nodes.cpp:159
AI_API AI_PURE AtUniverse * AiNodeGetUniverse(const AtNode *node)
Returns the universe a node belongs to.
Definition: ai_nodes.cpp:1041
AI_API void AiNodeSetArray(AtNode *node, const AtString param, AtArray *val)
Set the value of an array parameter.
Definition: ai_nodes.cpp:913
AI_API void AiNodeSetAttributes(AtNode *node, const char *attributes)
Set the parameters of a node through an attributes string.
Definition: ai_nodes.cpp:977
AI_API void AiNodeReplace(AtNode *old_node, AtNode *new_node, bool remove)
Replace an existing node with another, updating all references to that node.
Definition: ai_nodes.cpp:700
AI_API AI_PURE AtNode * AiNodeLookUpByName(const AtUniverse *universe, const AtString name, const AtNode *parent=NULL)
Search for a specific node in the given universe using the specified name string (which can be a simp...
Definition: ai_nodes.cpp:92
AI_API int AiNodeGetInt(const AtNode *node, const AtString param)
Return the value of an integer parameter.
Definition: ai_nodes.cpp:794
AI_API void AiUserParamIteratorDestroy(AtUserParamIterator *iter)
Destroys a user param iterator when it is no longer needed.
Definition: ai_nodes.cpp:169
AI_API AI_PURE void * AiNodeGetLocalData(const AtNode *node)
Returns a pointer to the local data in the node.
Definition: ai_nodes.cpp:249
AI_API AI_PURE const AtUserParamEntry * AiNodeLookUpUserParameter(const AtNode *node, const AtString param)
Return the user-defined parameter entry that matches a given name.
Definition: ai_nodes.cpp:147
AI_API AtNode * AiNodeClone(const AtNode *node, const AtString new_name=AtString(), const AtNode *parent=NULL)
Return an exact clone of a source node.
Definition: ai_nodes.cpp:652
AI_API AI_PURE void * AiNodeGetPluginData(const AtNode *node)
Returns a pointer to the per plugin data for the node type, as created in the node_plugin_initialize ...
Definition: ai_nodes.cpp:286
AI_API bool AiNodeDeclare(AtNode *node, const AtString param, const char *declaration)
Declare a user-defined parameter for this node.
Definition: ai_nodes.cpp:756
AI_API bool AiNodeDestroy(AtNode *node)
Destroy an existing node.
Definition: ai_nodes.cpp:676
AI_API AI_PURE const AtNodeEntry * AiNodeGetNodeEntry(const AtNode *node)
Return the node entry for this node.
Definition: ai_nodes.cpp:238
AI_API void AiNodeResetParameter(AtNode *node, const char *param)
Reset a node parameter to its default value and remove any links to that parameter.
Definition: ai_nodes.cpp:614
AI_API bool AiNodeLinkOutput(AtNode *src, const char *output, AtNode *target, const char *input)
Creates a connection between two shader nodes.
Definition: ai_nodes.cpp:444
AI_API void AiNodeReset(AtNode *node)
Reset all node parameters to their default values and remove any input links.
Definition: ai_nodes.cpp:593
AI_API void AiNodeSetDisabled(AtNode *node, bool disabled)
Disable or enable any node in the scene.
Definition: ai_nodes.cpp:997
AI_API void AiNodeSetInt(AtNode *node, const AtString param, int val)
Set the value of an integer parameter.
Definition: ai_nodes.cpp:782
Definition: ai_matrix.h:30
This represents a node type in Arnold.
This represents a node in Arnold.
RGB color + alpha.
Definition: ai_color.h:267
RGB color.
Definition: ai_color.h:32
This represents a universe in Arnold.
2D point
Definition: ai_vector.h:255
3D point (single precision)
Definition: ai_vector.h:30

© 2022 Autodesk, Inc. · All rights reserved · www.arnoldrenderer.com