1 /**
2 The CSG base class.
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.csgshape;
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.geometryinstance;
24 /**
25 The CSG base class.
26 
27 This is the CSG base class that provides CSG operation support to the various CSG nodes in Godot.
28 */
29 @GodotBaseClass struct CSGShape
30 {
31 	package(godot) enum string _GODOT_internal_name = "CSGShape";
32 public:
33 @nogc nothrow:
34 	union { /** */ godot_object _godot_object; /** */ GeometryInstance _GODOT_base; }
35 	alias _GODOT_base this;
36 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
37 	package(godot) __gshared bool _classBindingInitialized = false;
38 	package(godot) static struct GDNativeClassBinding
39 	{
40 		__gshared:
41 		@GodotName("_update_shape") GodotMethod!(void) _updateShape;
42 		@GodotName("get_collision_layer") GodotMethod!(long) getCollisionLayer;
43 		@GodotName("get_collision_layer_bit") GodotMethod!(bool, long) getCollisionLayerBit;
44 		@GodotName("get_collision_mask") GodotMethod!(long) getCollisionMask;
45 		@GodotName("get_collision_mask_bit") GodotMethod!(bool, long) getCollisionMaskBit;
46 		@GodotName("get_meshes") GodotMethod!(Array) getMeshes;
47 		@GodotName("get_operation") GodotMethod!(CSGShape.Operation) getOperation;
48 		@GodotName("get_snap") GodotMethod!(double) getSnap;
49 		@GodotName("is_calculating_tangents") GodotMethod!(bool) isCalculatingTangents;
50 		@GodotName("is_root_shape") GodotMethod!(bool) isRootShape;
51 		@GodotName("is_using_collision") GodotMethod!(bool) isUsingCollision;
52 		@GodotName("set_calculate_tangents") GodotMethod!(void, bool) setCalculateTangents;
53 		@GodotName("set_collision_layer") GodotMethod!(void, long) setCollisionLayer;
54 		@GodotName("set_collision_layer_bit") GodotMethod!(void, long, bool) setCollisionLayerBit;
55 		@GodotName("set_collision_mask") GodotMethod!(void, long) setCollisionMask;
56 		@GodotName("set_collision_mask_bit") GodotMethod!(void, long, bool) setCollisionMaskBit;
57 		@GodotName("set_operation") GodotMethod!(void, long) setOperation;
58 		@GodotName("set_snap") GodotMethod!(void, double) setSnap;
59 		@GodotName("set_use_collision") GodotMethod!(void, bool) setUseCollision;
60 	}
61 	/// 
62 	pragma(inline, true) bool opEquals(in CSGShape other) const
63 	{ return _godot_object.ptr is other._godot_object.ptr; }
64 	/// 
65 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
66 	{ _godot_object.ptr = n; return null; }
67 	/// 
68 	pragma(inline, true) bool opEquals(typeof(null) n) const
69 	{ return _godot_object.ptr is n; }
70 	/// 
71 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
72 	mixin baseCasts;
73 	/// Construct a new instance of CSGShape.
74 	/// Note: use `memnew!CSGShape` instead.
75 	static CSGShape _new()
76 	{
77 		static godot_class_constructor constructor;
78 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("CSGShape");
79 		if(constructor is null) return typeof(this).init;
80 		return cast(CSGShape)(constructor());
81 	}
82 	@disable new(size_t s);
83 	/// 
84 	enum Operation : int
85 	{
86 		/**
87 		Geometry of both primitives is merged, intersecting geometry is removed.
88 		*/
89 		operationUnion = 0,
90 		/**
91 		Only intersecting geometry remains, the rest is removed.
92 		*/
93 		operationIntersection = 1,
94 		/**
95 		The second shape is subtracted from the first, leaving a dent with its shape.
96 		*/
97 		operationSubtraction = 2,
98 	}
99 	/// 
100 	enum Constants : int
101 	{
102 		operationUnion = 0,
103 		operationIntersection = 1,
104 		operationSubtraction = 2,
105 	}
106 	/**
107 	
108 	*/
109 	void _updateShape()
110 	{
111 		Array _GODOT_args = Array.make();
112 		String _GODOT_method_name = String("_update_shape");
113 		this.callv(_GODOT_method_name, _GODOT_args);
114 	}
115 	/**
116 	
117 	*/
118 	long getCollisionLayer() const
119 	{
120 		checkClassBinding!(typeof(this))();
121 		return ptrcall!(long)(GDNativeClassBinding.getCollisionLayer, _godot_object);
122 	}
123 	/**
124 	Returns an individual bit on the collision mask.
125 	*/
126 	bool getCollisionLayerBit(in long bit) const
127 	{
128 		checkClassBinding!(typeof(this))();
129 		return ptrcall!(bool)(GDNativeClassBinding.getCollisionLayerBit, _godot_object, bit);
130 	}
131 	/**
132 	
133 	*/
134 	long getCollisionMask() const
135 	{
136 		checkClassBinding!(typeof(this))();
137 		return ptrcall!(long)(GDNativeClassBinding.getCollisionMask, _godot_object);
138 	}
139 	/**
140 	Returns an individual bit on the collision mask.
141 	*/
142 	bool getCollisionMaskBit(in long bit) const
143 	{
144 		checkClassBinding!(typeof(this))();
145 		return ptrcall!(bool)(GDNativeClassBinding.getCollisionMaskBit, _godot_object, bit);
146 	}
147 	/**
148 	Returns an $(D Array) with two elements, the first is the $(D Transform) of this node and the second is the root $(D Mesh) of this node. Only works when this node is the root shape.
149 	*/
150 	Array getMeshes() const
151 	{
152 		checkClassBinding!(typeof(this))();
153 		return ptrcall!(Array)(GDNativeClassBinding.getMeshes, _godot_object);
154 	}
155 	/**
156 	
157 	*/
158 	CSGShape.Operation getOperation() const
159 	{
160 		checkClassBinding!(typeof(this))();
161 		return ptrcall!(CSGShape.Operation)(GDNativeClassBinding.getOperation, _godot_object);
162 	}
163 	/**
164 	
165 	*/
166 	double getSnap() const
167 	{
168 		checkClassBinding!(typeof(this))();
169 		return ptrcall!(double)(GDNativeClassBinding.getSnap, _godot_object);
170 	}
171 	/**
172 	
173 	*/
174 	bool isCalculatingTangents() const
175 	{
176 		checkClassBinding!(typeof(this))();
177 		return ptrcall!(bool)(GDNativeClassBinding.isCalculatingTangents, _godot_object);
178 	}
179 	/**
180 	Returns `true` if this is a root shape and is thus the object that is rendered.
181 	*/
182 	bool isRootShape() const
183 	{
184 		checkClassBinding!(typeof(this))();
185 		return ptrcall!(bool)(GDNativeClassBinding.isRootShape, _godot_object);
186 	}
187 	/**
188 	
189 	*/
190 	bool isUsingCollision() const
191 	{
192 		checkClassBinding!(typeof(this))();
193 		return ptrcall!(bool)(GDNativeClassBinding.isUsingCollision, _godot_object);
194 	}
195 	/**
196 	
197 	*/
198 	void setCalculateTangents(in bool enabled)
199 	{
200 		checkClassBinding!(typeof(this))();
201 		ptrcall!(void)(GDNativeClassBinding.setCalculateTangents, _godot_object, enabled);
202 	}
203 	/**
204 	
205 	*/
206 	void setCollisionLayer(in long layer)
207 	{
208 		checkClassBinding!(typeof(this))();
209 		ptrcall!(void)(GDNativeClassBinding.setCollisionLayer, _godot_object, layer);
210 	}
211 	/**
212 	Sets individual bits on the layer mask. Use this if you only need to change one layer's value.
213 	*/
214 	void setCollisionLayerBit(in long bit, in bool value)
215 	{
216 		checkClassBinding!(typeof(this))();
217 		ptrcall!(void)(GDNativeClassBinding.setCollisionLayerBit, _godot_object, bit, value);
218 	}
219 	/**
220 	
221 	*/
222 	void setCollisionMask(in long mask)
223 	{
224 		checkClassBinding!(typeof(this))();
225 		ptrcall!(void)(GDNativeClassBinding.setCollisionMask, _godot_object, mask);
226 	}
227 	/**
228 	Sets individual bits on the collision mask. Use this if you only need to change one layer's value.
229 	*/
230 	void setCollisionMaskBit(in long bit, in bool value)
231 	{
232 		checkClassBinding!(typeof(this))();
233 		ptrcall!(void)(GDNativeClassBinding.setCollisionMaskBit, _godot_object, bit, value);
234 	}
235 	/**
236 	
237 	*/
238 	void setOperation(in long operation)
239 	{
240 		checkClassBinding!(typeof(this))();
241 		ptrcall!(void)(GDNativeClassBinding.setOperation, _godot_object, operation);
242 	}
243 	/**
244 	
245 	*/
246 	void setSnap(in double snap)
247 	{
248 		checkClassBinding!(typeof(this))();
249 		ptrcall!(void)(GDNativeClassBinding.setSnap, _godot_object, snap);
250 	}
251 	/**
252 	
253 	*/
254 	void setUseCollision(in bool operation)
255 	{
256 		checkClassBinding!(typeof(this))();
257 		ptrcall!(void)(GDNativeClassBinding.setUseCollision, _godot_object, operation);
258 	}
259 	/**
260 	Calculate tangents for the CSG shape which allows the use of normal maps. This is only applied on the root shape, this setting is ignored on any child.
261 	*/
262 	@property bool calculateTangents()
263 	{
264 		return isCalculatingTangents();
265 	}
266 	/// ditto
267 	@property void calculateTangents(bool v)
268 	{
269 		setCalculateTangents(v);
270 	}
271 	/**
272 	The physics layers this area is in.
273 	Collidable objects can exist in any of 32 different layers. These layers work like a tagging system, and are not visual. A collidable can use these layers to select with which objects it can collide, using the collision_mask property.
274 	A contact is detected if object A is in any of the layers that object B scans, or object B is in any layer scanned by object A. See $(D url=https://docs.godotengine.org/en/3.3/tutorials/physics/physics_introduction.html#collision-layers-and-masks)Collision layers and masks$(D /url) in the documentation for more information.
275 	*/
276 	@property long collisionLayer()
277 	{
278 		return getCollisionLayer();
279 	}
280 	/// ditto
281 	@property void collisionLayer(long v)
282 	{
283 		setCollisionLayer(v);
284 	}
285 	/**
286 	The physics layers this CSG shape scans for collisions. See $(D url=https://docs.godotengine.org/en/3.3/tutorials/physics/physics_introduction.html#collision-layers-and-masks)Collision layers and masks$(D /url) in the documentation for more information.
287 	*/
288 	@property long collisionMask()
289 	{
290 		return getCollisionMask();
291 	}
292 	/// ditto
293 	@property void collisionMask(long v)
294 	{
295 		setCollisionMask(v);
296 	}
297 	/**
298 	The operation that is performed on this shape. This is ignored for the first CSG child node as the operation is between this node and the previous child of this nodes parent.
299 	*/
300 	@property CSGShape.Operation operation()
301 	{
302 		return getOperation();
303 	}
304 	/// ditto
305 	@property void operation(long v)
306 	{
307 		setOperation(v);
308 	}
309 	/**
310 	Snap makes the mesh snap to a given distance so that the faces of two meshes can be perfectly aligned. A lower value results in greater precision but may be harder to adjust.
311 	*/
312 	@property double snap()
313 	{
314 		return getSnap();
315 	}
316 	/// ditto
317 	@property void snap(double v)
318 	{
319 		setSnap(v);
320 	}
321 	/**
322 	Adds a collision shape to the physics engine for our CSG shape. This will always act like a static body. Note that the collision shape is still active even if the CSG shape itself is hidden.
323 	*/
324 	@property bool useCollision()
325 	{
326 		return isUsingCollision();
327 	}
328 	/// ditto
329 	@property void useCollision(bool v)
330 	{
331 		setUseCollision(v);
332 	}
333 }