1 /** 2 Virtual class to define custom $(D VisualShaderNode)s for use in the Visual Shader Editor. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.visualshadernodecustom; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.visualshadernode; 25 import godot.resource; 26 import godot.reference; 27 /** 28 Virtual class to define custom $(D VisualShaderNode)s for use in the Visual Shader Editor. 29 30 By inheriting this class you can create a custom $(D VisualShader) script addon which will be automatically added to the Visual Shader Editor. The $(D VisualShaderNode)'s behavior is defined by overriding the provided virtual methods. 31 In order for the node to be registered as an editor addon, you must use the `tool` keyword and provide a `class_name` for your custom script. For example: 32 33 34 tool 35 extends VisualShaderNodeCustom 36 class_name VisualShaderNodeNoise 37 38 39 */ 40 @GodotBaseClass struct VisualShaderNodeCustom 41 { 42 package(godot) enum string _GODOT_internal_name = "VisualShaderNodeCustom"; 43 public: 44 @nogc nothrow: 45 union { /** */ godot_object _godot_object; /** */ VisualShaderNode _GODOT_base; } 46 alias _GODOT_base this; 47 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 48 package(godot) __gshared bool _classBindingInitialized = false; 49 package(godot) static struct GDNativeClassBinding 50 { 51 __gshared: 52 @GodotName("_get_category") GodotMethod!(String) _getCategory; 53 @GodotName("_get_code") GodotMethod!(String, Array, Array, long, long) _getCode; 54 @GodotName("_get_description") GodotMethod!(String) _getDescription; 55 @GodotName("_get_global_code") GodotMethod!(String, long) _getGlobalCode; 56 @GodotName("_get_input_port_count") GodotMethod!(long) _getInputPortCount; 57 @GodotName("_get_input_port_name") GodotMethod!(String, long) _getInputPortName; 58 @GodotName("_get_input_port_type") GodotMethod!(long, long) _getInputPortType; 59 @GodotName("_get_name") GodotMethod!(String) _getName; 60 @GodotName("_get_output_port_count") GodotMethod!(long) _getOutputPortCount; 61 @GodotName("_get_output_port_name") GodotMethod!(String, long) _getOutputPortName; 62 @GodotName("_get_output_port_type") GodotMethod!(long, long) _getOutputPortType; 63 @GodotName("_get_return_icon_type") GodotMethod!(long) _getReturnIconType; 64 @GodotName("_get_subcategory") GodotMethod!(String) _getSubcategory; 65 @GodotName("_is_initialized") GodotMethod!(bool) _isInitialized; 66 @GodotName("_set_initialized") GodotMethod!(void, bool) _setInitialized; 67 @GodotName("_set_input_port_default_value") GodotMethod!(void, long, Variant) _setInputPortDefaultValue; 68 } 69 /// 70 pragma(inline, true) bool opEquals(in VisualShaderNodeCustom other) const 71 { return _godot_object.ptr is other._godot_object.ptr; } 72 /// 73 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 74 { _godot_object.ptr = n; return null; } 75 /// 76 pragma(inline, true) bool opEquals(typeof(null) n) const 77 { return _godot_object.ptr is n; } 78 /// 79 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 80 mixin baseCasts; 81 /// Construct a new instance of VisualShaderNodeCustom. 82 /// Note: use `memnew!VisualShaderNodeCustom` instead. 83 static VisualShaderNodeCustom _new() 84 { 85 static godot_class_constructor constructor; 86 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("VisualShaderNodeCustom"); 87 if(constructor is null) return typeof(this).init; 88 return cast(VisualShaderNodeCustom)(constructor()); 89 } 90 @disable new(size_t s); 91 /** 92 Override this method to define the category of the associated custom node in the Visual Shader Editor's members dialog. The path may look like `"MyGame/MyFunctions/Noise"`. 93 Defining this method is $(B optional). If not overridden, the node will be filed under the "Custom" category. 94 */ 95 String _getCategory() 96 { 97 Array _GODOT_args = Array.make(); 98 String _GODOT_method_name = String("_get_category"); 99 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 100 } 101 /** 102 Override this method to define the actual shader code of the associated custom node. The shader code should be returned as a string, which can have multiple lines (the `"""` multiline string construct can be used for convenience). 103 The `input_vars` and `output_vars` arrays contain the string names of the various input and output variables, as defined by `_get_input_*` and `_get_output_*` virtual methods in this class. 104 The output ports can be assigned values in the shader code. For example, `return output_vars$(D 0) + " = " + input_vars$(D 0) + ";"`. 105 You can customize the generated code based on the shader `mode` (see $(D Shader.mode)) and/or `type` (see $(D VisualShader.type)). 106 Defining this method is $(B required). 107 */ 108 String _getCode(in Array input_vars, in Array output_vars, in long mode, in long type) 109 { 110 Array _GODOT_args = Array.make(); 111 _GODOT_args.append(input_vars); 112 _GODOT_args.append(output_vars); 113 _GODOT_args.append(mode); 114 _GODOT_args.append(type); 115 String _GODOT_method_name = String("_get_code"); 116 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 117 } 118 /** 119 Override this method to define the description of the associated custom node in the Visual Shader Editor's members dialog. 120 Defining this method is $(B optional). 121 */ 122 String _getDescription() 123 { 124 Array _GODOT_args = Array.make(); 125 String _GODOT_method_name = String("_get_description"); 126 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 127 } 128 /** 129 Override this method to add shader code on top of the global shader, to define your own standard library of reusable methods, varyings, constants, uniforms, etc. The shader code should be returned as a string, which can have multiple lines (the `"""` multiline string construct can be used for convenience). 130 Be careful with this functionality as it can cause name conflicts with other custom nodes, so be sure to give the defined entities unique names. 131 You can customize the generated code based on the shader `mode` (see $(D Shader.mode)). 132 Defining this method is $(B optional). 133 */ 134 String _getGlobalCode(in long mode) 135 { 136 Array _GODOT_args = Array.make(); 137 _GODOT_args.append(mode); 138 String _GODOT_method_name = String("_get_global_code"); 139 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 140 } 141 /** 142 Override this method to define the amount of input ports of the associated custom node. 143 Defining this method is $(B required). If not overridden, the node has no input ports. 144 */ 145 long _getInputPortCount() 146 { 147 Array _GODOT_args = Array.make(); 148 String _GODOT_method_name = String("_get_input_port_count"); 149 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!long); 150 } 151 /** 152 Override this method to define the names of input ports of the associated custom node. The names are used both for the input slots in the editor and as identifiers in the shader code, and are passed in the `input_vars` array in $(D _getCode). 153 Defining this method is $(B optional), but recommended. If not overridden, input ports are named as `"in" + str(port)`. 154 */ 155 String _getInputPortName(in long port) 156 { 157 Array _GODOT_args = Array.make(); 158 _GODOT_args.append(port); 159 String _GODOT_method_name = String("_get_input_port_name"); 160 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 161 } 162 /** 163 Override this method to define the returned type of each input port of the associated custom node (see $(D VisualShaderNode.porttype) for possible types). 164 Defining this method is $(B optional), but recommended. If not overridden, input ports will return the $(D constant VisualShaderNode.PORT_TYPE_SCALAR) type. 165 */ 166 long _getInputPortType(in long port) 167 { 168 Array _GODOT_args = Array.make(); 169 _GODOT_args.append(port); 170 String _GODOT_method_name = String("_get_input_port_type"); 171 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!long); 172 } 173 /** 174 Override this method to define the name of the associated custom node in the Visual Shader Editor's members dialog and graph. 175 Defining this method is $(B optional), but recommended. If not overridden, the node will be named as "Unnamed". 176 */ 177 String _getName() 178 { 179 Array _GODOT_args = Array.make(); 180 String _GODOT_method_name = String("_get_name"); 181 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 182 } 183 /** 184 Override this method to define the amount of output ports of the associated custom node. 185 Defining this method is $(B required). If not overridden, the node has no output ports. 186 */ 187 long _getOutputPortCount() 188 { 189 Array _GODOT_args = Array.make(); 190 String _GODOT_method_name = String("_get_output_port_count"); 191 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!long); 192 } 193 /** 194 Override this method to define the names of output ports of the associated custom node. The names are used both for the output slots in the editor and as identifiers in the shader code, and are passed in the `output_vars` array in $(D _getCode). 195 Defining this method is $(B optional), but recommended. If not overridden, output ports are named as `"out" + str(port)`. 196 */ 197 String _getOutputPortName(in long port) 198 { 199 Array _GODOT_args = Array.make(); 200 _GODOT_args.append(port); 201 String _GODOT_method_name = String("_get_output_port_name"); 202 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 203 } 204 /** 205 Override this method to define the returned type of each output port of the associated custom node (see $(D VisualShaderNode.porttype) for possible types). 206 Defining this method is $(B optional), but recommended. If not overridden, output ports will return the $(D constant VisualShaderNode.PORT_TYPE_SCALAR) type. 207 */ 208 long _getOutputPortType(in long port) 209 { 210 Array _GODOT_args = Array.make(); 211 _GODOT_args.append(port); 212 String _GODOT_method_name = String("_get_output_port_type"); 213 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!long); 214 } 215 /** 216 Override this method to define the return icon of the associated custom node in the Visual Shader Editor's members dialog. 217 Defining this method is $(B optional). If not overridden, no return icon is shown. 218 */ 219 long _getReturnIconType() 220 { 221 Array _GODOT_args = Array.make(); 222 String _GODOT_method_name = String("_get_return_icon_type"); 223 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!long); 224 } 225 /** 226 Override this method to define the subcategory of the associated custom node in the Visual Shader Editor's members dialog. 227 Defining this method is $(B optional). If not overridden, the node will be filed under the root of the main category (see $(D _getCategory)). 228 */ 229 String _getSubcategory() 230 { 231 Array _GODOT_args = Array.make(); 232 String _GODOT_method_name = String("_get_subcategory"); 233 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 234 } 235 /** 236 237 */ 238 bool _isInitialized() 239 { 240 Array _GODOT_args = Array.make(); 241 String _GODOT_method_name = String("_is_initialized"); 242 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool); 243 } 244 /** 245 246 */ 247 void _setInitialized(in bool enabled) 248 { 249 Array _GODOT_args = Array.make(); 250 _GODOT_args.append(enabled); 251 String _GODOT_method_name = String("_set_initialized"); 252 this.callv(_GODOT_method_name, _GODOT_args); 253 } 254 /** 255 256 */ 257 void _setInputPortDefaultValue(VariantArg1)(in long port, in VariantArg1 value) 258 { 259 Array _GODOT_args = Array.make(); 260 _GODOT_args.append(port); 261 _GODOT_args.append(value); 262 String _GODOT_method_name = String("_set_input_port_default_value"); 263 this.callv(_GODOT_method_name, _GODOT_args); 264 } 265 /** 266 267 */ 268 @property bool initialized() 269 { 270 return _isInitialized(); 271 } 272 /// ditto 273 @property void initialized(bool v) 274 { 275 _setInitialized(v); 276 } 277 }