ai_params.h
Go to the documentation of this file.
1// Copyright 2021 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_array.h"
14#include "ai_closure.h"
15#include "ai_color.h"
16#include "ai_enum.h"
17#include "ai_math.h"
18#include "ai_matrix.h"
19#include "ai_vector.h"
20#include "ai_api.h"
21#include <stdint.h> // uint32_t etc
22
23#ifdef _WIN32
24# ifndef WIN32_LEAN_AND_MEAN
25# define WIN32_LEAN_AND_MEAN
26# endif
27# ifndef VC_EXTRALEAN
28# define VC_EXTRALEAN
29# endif
30# ifndef NOMINMAX
31# define NOMINMAX
32# endif
33// Force an include of windows.h to make sure it can't be included after this header
34// (thanks to its own internal include guard) and the RGB() macro is not defined again
35# include <windows.h>
36# ifdef RGB
37# undef RGB
38// The RGB() macro in WinGDI.h returns a COLORREF, which we know to be a DWORD, which
39// in turn is an unsigned long, see:
40// https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx
41// Let's recreate this as a function instead of as a macro.
42inline constexpr unsigned long RGB(unsigned long r, unsigned long g, unsigned long b)
43{
44 return r | g << 8 | b << 16;
45}
46# endif
47#endif
48
49// forward declaration
50struct AtList;
51struct AtNode;
52
70#define AI_TYPE_BYTE 0x00
71#define AI_TYPE_INT 0x01
72#define AI_TYPE_UINT 0x02
73#define AI_TYPE_BOOLEAN 0x03
74#define AI_TYPE_FLOAT 0x04
75#define AI_TYPE_RGB 0x05
76#define AI_TYPE_RGBA 0x06
77#define AI_TYPE_VECTOR 0x07
78#define AI_TYPE_VECTOR2 0x09
79#define AI_TYPE_STRING 0x0A
80#define AI_TYPE_POINTER 0x0B
81#define AI_TYPE_NODE 0x0C
82#define AI_TYPE_ARRAY 0x0D
83#define AI_TYPE_MATRIX 0x0E
84#define AI_TYPE_ENUM 0x0F
85#define AI_TYPE_CLOSURE 0x10
86#define AI_TYPE_USHORT 0x11
87#define AI_TYPE_HALF 0x12
88#define AI_TYPE_UNDEFINED 0xFF
89#define AI_TYPE_NONE 0xFF
90/* \}*/
91
95#define AI_USERDEF_UNDEFINED 0
96#define AI_USERDEF_CONSTANT 1
97#define AI_USERDEF_UNIFORM 2
98#define AI_USERDEF_VARYING 3
99#define AI_USERDEF_INDEXED 4
100/* \}*/
101
106{
107public:
108 AI_DEVICE bool const& BOOL() const{ return *reinterpret_type<bool const*> (&data); }
109 AI_DEVICE uint8_t const& BYTE() const{ return *reinterpret_type<uint8_t const*> (&data); }
110 AI_DEVICE int const& INT() const{ return *reinterpret_type<int const*> (&data); }
111 AI_DEVICE unsigned const& UINT() const{ return *reinterpret_type<unsigned const*> (&data); }
112 AI_DEVICE float const& FLT() const{ return *reinterpret_type<float const*> (&data); }
113 AI_DEVICE AtRGB const& RGB() const{ return *reinterpret_type<AtRGB const*> (&data); }
114 AI_DEVICE AtRGBA const& RGBA() const{ return *reinterpret_type<AtRGBA const*> (&data); }
115 AI_DEVICE AtVector const& VEC() const{ return *reinterpret_type<AtVector const*> (&data); }
116 AI_DEVICE AtVector2 const& VEC2() const{ return *reinterpret_type<AtVector2 const*> (&data); }
117 AI_DEVICE AtString const& STR() const{ return *reinterpret_type<AtString const*> (&data); }
118 AI_DEVICE void* const& PTR() const{ return *reinterpret_type<void* const*> (&data); }
119 AtMatrix* const& pMTX() const{ return *reinterpret_type<AtMatrix* const*> (&data); }
120 AtArray* const& ARRAY() const{ return *reinterpret_type<AtArray* const*> (&data); }
121 AI_DEVICE AtClosureList const& CLOSURE() const{ return *reinterpret_type<AtClosureList const*>(&data); }
122
123 AI_DEVICE bool & BOOL() { return *reinterpret_type<bool *> (&data); }
124 AI_DEVICE uint8_t & BYTE() { return *reinterpret_type<uint8_t *> (&data); }
125 AI_DEVICE int & INT() { return *reinterpret_type<int *> (&data); }
126 AI_DEVICE unsigned & UINT() { return *reinterpret_type<unsigned *> (&data); }
127 AI_DEVICE float & FLT() { return *reinterpret_type<float *> (&data); }
128 AI_DEVICE AtRGB & RGB() { return *reinterpret_type<AtRGB *> (&data); }
129 AI_DEVICE AtRGBA & RGBA() { return *reinterpret_type<AtRGBA *> (&data); }
130 AI_DEVICE AtVector & VEC() { return *reinterpret_type<AtVector *> (&data); }
131 AI_DEVICE AtVector2 & VEC2() { return *reinterpret_type<AtVector2*> (&data); }
132 AI_DEVICE AtString & STR() { return *reinterpret_type<AtString *> (&data); }
133 AI_DEVICE void* & PTR() { return *reinterpret_type<void* *> (&data); }
134 AtMatrix* & pMTX() { return *reinterpret_type<AtMatrix**> (&data); }
135 AtArray* & ARRAY() { return *reinterpret_type<AtArray* *> (&data); }
136 AI_DEVICE AtClosureList & CLOSURE(){ return *reinterpret_type<AtClosureList*>(&data); }
137
138private:
139 // 128 bits of raw data, naturally aligned to 64 bit so it properly works
140 // with pointers. This is big enough to hold up to four floats, as needed
141 // by AtRGBA.
142 uint64_t data[2];
143};
144
151struct AtParamEntry;
152
157AI_API AI_PURE AtString AiParamGetName (const AtParamEntry* pentry);
158AI_API AI_PURE uint8_t AiParamGetType (const AtParamEntry* pentry);
159AI_API AI_PURE uint8_t AiParamGetSubType (const AtParamEntry* pentry);
160AI_API AI_PURE const AtParamValue* AiParamGetDefault (const AtParamEntry* pentry);
161AI_API AI_PURE AtEnum AiParamGetEnum (const AtParamEntry* pentry);
162AI_API AI_PURE const char* AiParamGetTypeName(uint8_t type);
163AI_API AI_DEVICE AI_CONST int AiParamGetTypeSize(uint8_t type);
164/* \}*/
165
172struct AtUserParamEntry;
173
178AI_API AI_DEVICE AI_PURE const char* AiUserParamGetName (const AtUserParamEntry* upentry);
179AI_API AI_DEVICE AI_PURE uint8_t AiUserParamGetType (const AtUserParamEntry* upentry);
180AI_API AI_DEVICE AI_PURE uint8_t AiUserParamGetArrayType(const AtUserParamEntry* upentry);
181AI_API AI_DEVICE AI_PURE uint8_t AiUserParamGetCategory (const AtUserParamEntry* upentry);
182/* \}*/
183
195AI_API AI_CONST bool AiParamTypeConvertible(uint8_t dst_type, uint8_t src_type);
196
222#define AiParameterByte(n,c) AiNodeParamByte (params,-1,n,c);
223#define AiParameterInt(n,c) AiNodeParamInt (params,-1,n,c);
224#define AiParameterUInt(n,c) AiNodeParamUInt (params,-1,n,c);
225#define AiParameterBool(n,c) AiNodeParamBool (params,-1,n,c);
226#define AiParameterFlt(n,c) AiNodeParamFlt (params,-1,n,c);
227#define AiParameterRGB(n,r,g,b) AiNodeParamRGB (params,-1,n,r,g,b);
228#define AiParameterRGBA(n,r,g,b,a) AiNodeParamRGBA (params,-1,n,r,g,b,a);
229#define AiParameterVec(n,x,y,z) AiNodeParamVec (params,-1,n,x,y,z);
230#define AiParameterVec2(n,x,y) AiNodeParamVec2 (params,-1,n,x,y);
231#define AiParameterStr(n,c) AiNodeParamStr (params,-1,n,c);
232#define AiParameterPtr(n,c) AiNodeParamPtr (params,-1,n,c);
233#define AiParameterNode(n,c) AiNodeParamNode (params,-1,n,c);
234#define AiParameterArray(n,c) AiNodeParamArray (params,-1,n,c);
235#define AiParameterMtx(n,c) AiNodeParamMtx (params,-1,n,c);
236#define AiParameterEnum(n,c,e) AiNodeParamEnum (params,-1,n,c,e);
237#define AiParameterClosure(n) AiNodeParamClosure(params,-1,n);
238
239#define AiOutputByte(n) AiNodeOutputByte (params,n);
240#define AiOutputInt(n) AiNodeOutputInt (params,n);
241#define AiOutputUInt(n) AiNodeOutputUInt (params,n);
242#define AiOutputBool(n) AiNodeOutputBool (params,n);
243#define AiOutputFlt(n) AiNodeOutputFlt (params,n);
244#define AiOutputRGB(n) AiNodeOutputRGB (params,n);
245#define AiOutputRGBA(n) AiNodeOutputRGBA (params,n);
246#define AiOutputVec(n) AiNodeOutputVec (params,n);
247#define AiOutputVec2(n) AiNodeOutputVec2 (params,n);
248#define AiOutputStr(n) AiNodeOutputStr (params,n);
249#define AiOutputPtr(n) AiNodeOutputPtr (params,n);
250#define AiOutputNode(n) AiNodeOutputNode (params,n);
251#define AiOutputArray(n,t) AiNodeOutputArray (params,n,t);
252#define AiOutputMtx(n) AiNodeOutputMtx (params,n);
253#define AiOutputEnum(n,t) AiNodeOutputEnum (params,n,t);
254#define AiOutputClosure(n) AiNodeOutputClosure(params,n);
255/* \}*/
256
257/*\}*/
258
259/* for convenience, the macros above call these functions */
260AI_API void AiNodeParamByte (AtList* params, int varoffset, const char* pname, uint8_t pdefault);
261AI_API void AiNodeParamInt (AtList* params, int varoffset, const char* pname, int pdefault);
262AI_API void AiNodeParamUInt (AtList* params, int varoffset, const char* pname, unsigned int pdefault);
263AI_API void AiNodeParamBool (AtList* params, int varoffset, const char* pname, bool pdefault);
264AI_API void AiNodeParamFlt (AtList* params, int varoffset, const char* pname, float pdefault);
265AI_API void AiNodeParamRGB (AtList* params, int varoffset, const char* pname, float r, float g, float b);
266AI_API void AiNodeParamRGBA (AtList* params, int varoffset, const char* pname, float r, float g, float b, float a);
267AI_API void AiNodeParamVec (AtList* params, int varoffset, const char* pname, float x, float y, float z);
268AI_API void AiNodeParamVec2 (AtList* params, int varoffset, const char* pname, float x, float y);
269AI_API void AiNodeParamStr (AtList* params, int varoffset, const char* pname, const char* pdefault);
270AI_API void AiNodeParamPtr (AtList* params, int varoffset, const char* pname, void* pdefault);
271AI_API void AiNodeParamNode (AtList* params, int varoffset, const char* pname, AtNode* pdefault);
272AI_API void AiNodeParamArray (AtList* params, int varoffset, const char* pname, AtArray* pdefault);
273AI_API void AiNodeParamMtx (AtList* params, int varoffset, const char* pname, AtMatrix matrix);
274AI_API void AiNodeParamEnum (AtList* params, int varoffset, const char* pname, int pdefault, AtEnum enum_type);
275AI_API void AiNodeParamClosure(AtList* params, int varoffset, const char* pname);
276
277AI_API void AiNodeOutputByte (AtList* params, const char* pname);
278AI_API void AiNodeOutputInt (AtList* params, const char* pname);
279AI_API void AiNodeOutputUInt (AtList* params, const char* pname);
280AI_API void AiNodeOutputBool (AtList* params, const char* pname);
281AI_API void AiNodeOutputFlt (AtList* params, const char* pname);
282AI_API void AiNodeOutputRGB (AtList* params, const char* pname);
283AI_API void AiNodeOutputRGBA (AtList* params, const char* pname);
284AI_API void AiNodeOutputVec (AtList* params, const char* pname);
285AI_API void AiNodeOutputVec2 (AtList* params, const char* pname);
286AI_API void AiNodeOutputStr (AtList* params, const char* pname);
287AI_API void AiNodeOutputPtr (AtList* params, const char* pname);
288AI_API void AiNodeOutputNode (AtList* params, const char* pname);
289AI_API void AiNodeOutputArray (AtList* params, const char* pname, int array_type);
290AI_API void AiNodeOutputMtx (AtList* params, const char* pname);
291AI_API void AiNodeOutputEnum (AtList* params, const char* pname, AtEnum enum_type);
292AI_API void AiNodeOutputClosure(AtList* params, const char* pname);
DLL export prefix for API functions (necessary for multi-platform development)
Generic array data type and methods.
Closure type and utilities.
Color types and utilities.
Enum data type and utility functions.
Math operations.
Matrix math type and methods.
Vector math types, operators and utilities.
Actual parameter value for each supported type.
Definition: ai_params.h:106
Arnold String allows for fast string comparisons.
Definition: ai_string.h:46
const char ** AtEnum
String-based enumerated data type.
Definition: ai_enum.h:31
AI_API AI_DEVICE AI_CONST int AiParamGetTypeSize(uint8_t type)
Return the size of an Arnold data type.
Definition: ai_paramentry.cpp:163
AI_API AI_DEVICE AI_PURE uint8_t AiUserParamGetType(const AtUserParamEntry *upentry)
Look-up user-declared parameter type (int, float, etc...)
Definition: ai_userdefs.cpp:24
AI_API AI_DEVICE AI_PURE uint8_t AiUserParamGetCategory(const AtUserParamEntry *upentry)
Look-up user-declared parameter category (constant, uniform, varying)
Definition: ai_userdefs.cpp:46
AI_API AI_PURE const AtParamValue * AiParamGetDefault(const AtParamEntry *pentry)
Return the default value of a given parameter.
Definition: ai_paramentry.cpp:201
AI_API AI_PURE const char * AiParamGetTypeName(uint8_t type)
Return the name of an Arnold data type.
Definition: ai_paramentry.cpp:140
AI_API AI_DEVICE AI_PURE const char * AiUserParamGetName(const AtUserParamEntry *upentry)
Look-up user-declared parameter name.
Definition: ai_userdefs.cpp:12
AI_API AI_PURE uint8_t AiParamGetType(const AtParamEntry *pentry)
Return the type of a given parameter.
Definition: ai_paramentry.cpp:102
AI_API AI_CONST bool AiParamTypeConvertible(uint8_t dst_type, uint8_t src_type)
Returns whether an AtParamValue of type src_type can be converted to dst_type.
Definition: ai_paramentry.cpp:780
AI_API AI_PURE AtString AiParamGetName(const AtParamEntry *pentry)
Return the name of a given parameter.
Definition: ai_paramentry.cpp:86
AI_API AI_PURE AtEnum AiParamGetEnum(const AtParamEntry *pentry)
Return the enum type of a given enum parameter.
Definition: ai_paramentry.cpp:217
AI_API AI_PURE uint8_t AiParamGetSubType(const AtParamEntry *pentry)
Return the sub-type of a given array parameter.
Definition: ai_paramentry.cpp:118
AI_API AI_DEVICE AI_PURE uint8_t AiUserParamGetArrayType(const AtUserParamEntry *upentry)
Look-up user-declared parameter array-type (int, float, etc...)
Definition: ai_userdefs.cpp:35
Definition: ai_closure.h:85
Definition: ai_matrix.h:30
This represents a node in Arnold.
RGB color + alpha.
Definition: ai_color.h:267
RGB color.
Definition: ai_color.h:32
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