1 /**
2 Node for 3D tile-based maps.
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.gridmap;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.classdb;
23 import godot.spatial;
24 import godot.meshlibrary;
25 import godot.resource;
26 import godot.node;
27 /**
28 Node for 3D tile-based maps.
29 
30 GridMap lets you place meshes on a grid interactively. It works both from the editor and can help you create in-game level editors.
31 GridMaps use a $(D MeshLibrary) which contain a list of tiles: meshes with materials plus optional collisions and extra elements.
32 A GridMap contains a collection of cells. Each grid cell refers to a $(D MeshLibrary) item. All cells in the map have the same dimensions.
33 A GridMap is split into a sparse collection of octants for efficient rendering and physics processing. Every octant has the same dimensions and can contain several cells.
34 */
35 @GodotBaseClass struct GridMap
36 {
37 	enum string _GODOT_internal_name = "GridMap";
38 public:
39 @nogc nothrow:
40 	union { godot_object _godot_object; Spatial _GODOT_base; }
41 	alias _GODOT_base this;
42 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
43 	package(godot) __gshared bool _classBindingInitialized = false;
44 	package(godot) static struct _classBinding
45 	{
46 		__gshared:
47 		@GodotName("set_collision_layer") GodotMethod!(void, long) setCollisionLayer;
48 		@GodotName("get_collision_layer") GodotMethod!(long) getCollisionLayer;
49 		@GodotName("set_collision_mask") GodotMethod!(void, long) setCollisionMask;
50 		@GodotName("get_collision_mask") GodotMethod!(long) getCollisionMask;
51 		@GodotName("set_collision_mask_bit") GodotMethod!(void, long, bool) setCollisionMaskBit;
52 		@GodotName("get_collision_mask_bit") GodotMethod!(bool, long) getCollisionMaskBit;
53 		@GodotName("set_collision_layer_bit") GodotMethod!(void, long, bool) setCollisionLayerBit;
54 		@GodotName("get_collision_layer_bit") GodotMethod!(bool, long) getCollisionLayerBit;
55 		@GodotName("set_theme") GodotMethod!(void, MeshLibrary) setTheme;
56 		@GodotName("get_theme") GodotMethod!(MeshLibrary) getTheme;
57 		@GodotName("set_mesh_library") GodotMethod!(void, MeshLibrary) setMeshLibrary;
58 		@GodotName("get_mesh_library") GodotMethod!(MeshLibrary) getMeshLibrary;
59 		@GodotName("set_cell_size") GodotMethod!(void, Vector3) setCellSize;
60 		@GodotName("get_cell_size") GodotMethod!(Vector3) getCellSize;
61 		@GodotName("set_cell_scale") GodotMethod!(void, double) setCellScale;
62 		@GodotName("get_cell_scale") GodotMethod!(double) getCellScale;
63 		@GodotName("set_octant_size") GodotMethod!(void, long) setOctantSize;
64 		@GodotName("get_octant_size") GodotMethod!(long) getOctantSize;
65 		@GodotName("set_cell_item") GodotMethod!(void, long, long, long, long, long) setCellItem;
66 		@GodotName("get_cell_item") GodotMethod!(long, long, long, long) getCellItem;
67 		@GodotName("get_cell_item_orientation") GodotMethod!(long, long, long, long) getCellItemOrientation;
68 		@GodotName("world_to_map") GodotMethod!(Vector3, Vector3) worldToMap;
69 		@GodotName("map_to_world") GodotMethod!(Vector3, long, long, long) mapToWorld;
70 		@GodotName("_update_octants_callback") GodotMethod!(void) _updateOctantsCallback;
71 		@GodotName("resource_changed") GodotMethod!(void, Resource) resourceChanged;
72 		@GodotName("set_center_x") GodotMethod!(void, bool) setCenterX;
73 		@GodotName("get_center_x") GodotMethod!(bool) getCenterX;
74 		@GodotName("set_center_y") GodotMethod!(void, bool) setCenterY;
75 		@GodotName("get_center_y") GodotMethod!(bool) getCenterY;
76 		@GodotName("set_center_z") GodotMethod!(void, bool) setCenterZ;
77 		@GodotName("get_center_z") GodotMethod!(bool) getCenterZ;
78 		@GodotName("set_clip") GodotMethod!(void, bool, bool, long, long) setClip;
79 		@GodotName("clear") GodotMethod!(void) clear;
80 		@GodotName("get_used_cells") GodotMethod!(Array) getUsedCells;
81 		@GodotName("get_meshes") GodotMethod!(Array) getMeshes;
82 		@GodotName("get_bake_meshes") GodotMethod!(Array) getBakeMeshes;
83 		@GodotName("get_bake_mesh_instance") GodotMethod!(RID, long) getBakeMeshInstance;
84 		@GodotName("clear_baked_meshes") GodotMethod!(void) clearBakedMeshes;
85 		@GodotName("make_baked_meshes") GodotMethod!(void, bool, double) makeBakedMeshes;
86 	}
87 	bool opEquals(in GridMap other) const { return _godot_object.ptr is other._godot_object.ptr; }
88 	GridMap opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
89 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
90 	mixin baseCasts;
91 	static GridMap _new()
92 	{
93 		static godot_class_constructor constructor;
94 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("GridMap");
95 		if(constructor is null) return typeof(this).init;
96 		return cast(GridMap)(constructor());
97 	}
98 	@disable new(size_t s);
99 	/// 
100 	enum Constants : int
101 	{
102 		/**
103 		Invalid cell item that can be used in $(D setCellItem) to clear cells (or represent an empty cell in $(D getCellItem)).
104 		*/
105 		invalidCellItem = -1,
106 	}
107 	/**
108 	
109 	*/
110 	void setCollisionLayer(in long layer)
111 	{
112 		checkClassBinding!(typeof(this))();
113 		ptrcall!(void)(_classBinding.setCollisionLayer, _godot_object, layer);
114 	}
115 	/**
116 	
117 	*/
118 	long getCollisionLayer() const
119 	{
120 		checkClassBinding!(typeof(this))();
121 		return ptrcall!(long)(_classBinding.getCollisionLayer, _godot_object);
122 	}
123 	/**
124 	
125 	*/
126 	void setCollisionMask(in long mask)
127 	{
128 		checkClassBinding!(typeof(this))();
129 		ptrcall!(void)(_classBinding.setCollisionMask, _godot_object, mask);
130 	}
131 	/**
132 	
133 	*/
134 	long getCollisionMask() const
135 	{
136 		checkClassBinding!(typeof(this))();
137 		return ptrcall!(long)(_classBinding.getCollisionMask, _godot_object);
138 	}
139 	/**
140 	
141 	*/
142 	void setCollisionMaskBit(in long bit, in bool value)
143 	{
144 		checkClassBinding!(typeof(this))();
145 		ptrcall!(void)(_classBinding.setCollisionMaskBit, _godot_object, bit, value);
146 	}
147 	/**
148 	
149 	*/
150 	bool getCollisionMaskBit(in long bit) const
151 	{
152 		checkClassBinding!(typeof(this))();
153 		return ptrcall!(bool)(_classBinding.getCollisionMaskBit, _godot_object, bit);
154 	}
155 	/**
156 	
157 	*/
158 	void setCollisionLayerBit(in long bit, in bool value)
159 	{
160 		checkClassBinding!(typeof(this))();
161 		ptrcall!(void)(_classBinding.setCollisionLayerBit, _godot_object, bit, value);
162 	}
163 	/**
164 	
165 	*/
166 	bool getCollisionLayerBit(in long bit) const
167 	{
168 		checkClassBinding!(typeof(this))();
169 		return ptrcall!(bool)(_classBinding.getCollisionLayerBit, _godot_object, bit);
170 	}
171 	/**
172 	
173 	*/
174 	void setTheme(MeshLibrary theme)
175 	{
176 		checkClassBinding!(typeof(this))();
177 		ptrcall!(void)(_classBinding.setTheme, _godot_object, theme);
178 	}
179 	/**
180 	
181 	*/
182 	Ref!MeshLibrary getTheme() const
183 	{
184 		checkClassBinding!(typeof(this))();
185 		return ptrcall!(MeshLibrary)(_classBinding.getTheme, _godot_object);
186 	}
187 	/**
188 	
189 	*/
190 	void setMeshLibrary(MeshLibrary mesh_library)
191 	{
192 		checkClassBinding!(typeof(this))();
193 		ptrcall!(void)(_classBinding.setMeshLibrary, _godot_object, mesh_library);
194 	}
195 	/**
196 	
197 	*/
198 	Ref!MeshLibrary getMeshLibrary() const
199 	{
200 		checkClassBinding!(typeof(this))();
201 		return ptrcall!(MeshLibrary)(_classBinding.getMeshLibrary, _godot_object);
202 	}
203 	/**
204 	
205 	*/
206 	void setCellSize(in Vector3 size)
207 	{
208 		checkClassBinding!(typeof(this))();
209 		ptrcall!(void)(_classBinding.setCellSize, _godot_object, size);
210 	}
211 	/**
212 	
213 	*/
214 	Vector3 getCellSize() const
215 	{
216 		checkClassBinding!(typeof(this))();
217 		return ptrcall!(Vector3)(_classBinding.getCellSize, _godot_object);
218 	}
219 	/**
220 	
221 	*/
222 	void setCellScale(in double scale)
223 	{
224 		checkClassBinding!(typeof(this))();
225 		ptrcall!(void)(_classBinding.setCellScale, _godot_object, scale);
226 	}
227 	/**
228 	
229 	*/
230 	double getCellScale() const
231 	{
232 		checkClassBinding!(typeof(this))();
233 		return ptrcall!(double)(_classBinding.getCellScale, _godot_object);
234 	}
235 	/**
236 	
237 	*/
238 	void setOctantSize(in long size)
239 	{
240 		checkClassBinding!(typeof(this))();
241 		ptrcall!(void)(_classBinding.setOctantSize, _godot_object, size);
242 	}
243 	/**
244 	
245 	*/
246 	long getOctantSize() const
247 	{
248 		checkClassBinding!(typeof(this))();
249 		return ptrcall!(long)(_classBinding.getOctantSize, _godot_object);
250 	}
251 	/**
252 	Set the mesh index for the cell referenced by its grid-based X, Y and Z coordinates.
253 	A negative item index will clear the cell.
254 	Optionally, the item's orientation can be passed.
255 	*/
256 	void setCellItem(in long x, in long y, in long z, in long item, in long orientation = 0)
257 	{
258 		checkClassBinding!(typeof(this))();
259 		ptrcall!(void)(_classBinding.setCellItem, _godot_object, x, y, z, item, orientation);
260 	}
261 	/**
262 	The $(D MeshLibrary) item index located at the grid-based X, Y and Z coordinates. If the cell is empty, $(D INVALID_CELL_ITEM) will be returned.
263 	*/
264 	long getCellItem(in long x, in long y, in long z) const
265 	{
266 		checkClassBinding!(typeof(this))();
267 		return ptrcall!(long)(_classBinding.getCellItem, _godot_object, x, y, z);
268 	}
269 	/**
270 	The orientation of the cell at the grid-based X, Y and Z coordinates. -1 is returned if the cell is empty.
271 	*/
272 	long getCellItemOrientation(in long x, in long y, in long z) const
273 	{
274 		checkClassBinding!(typeof(this))();
275 		return ptrcall!(long)(_classBinding.getCellItemOrientation, _godot_object, x, y, z);
276 	}
277 	/**
278 	
279 	*/
280 	Vector3 worldToMap(in Vector3 pos) const
281 	{
282 		checkClassBinding!(typeof(this))();
283 		return ptrcall!(Vector3)(_classBinding.worldToMap, _godot_object, pos);
284 	}
285 	/**
286 	
287 	*/
288 	Vector3 mapToWorld(in long x, in long y, in long z) const
289 	{
290 		checkClassBinding!(typeof(this))();
291 		return ptrcall!(Vector3)(_classBinding.mapToWorld, _godot_object, x, y, z);
292 	}
293 	/**
294 	
295 	*/
296 	void _updateOctantsCallback()
297 	{
298 		Array _GODOT_args = Array.empty_array;
299 		String _GODOT_method_name = String("_update_octants_callback");
300 		this.callv(_GODOT_method_name, _GODOT_args);
301 	}
302 	/**
303 	
304 	*/
305 	void resourceChanged(Resource resource)
306 	{
307 		checkClassBinding!(typeof(this))();
308 		ptrcall!(void)(_classBinding.resourceChanged, _godot_object, resource);
309 	}
310 	/**
311 	
312 	*/
313 	void setCenterX(in bool enable)
314 	{
315 		checkClassBinding!(typeof(this))();
316 		ptrcall!(void)(_classBinding.setCenterX, _godot_object, enable);
317 	}
318 	/**
319 	
320 	*/
321 	bool getCenterX() const
322 	{
323 		checkClassBinding!(typeof(this))();
324 		return ptrcall!(bool)(_classBinding.getCenterX, _godot_object);
325 	}
326 	/**
327 	
328 	*/
329 	void setCenterY(in bool enable)
330 	{
331 		checkClassBinding!(typeof(this))();
332 		ptrcall!(void)(_classBinding.setCenterY, _godot_object, enable);
333 	}
334 	/**
335 	
336 	*/
337 	bool getCenterY() const
338 	{
339 		checkClassBinding!(typeof(this))();
340 		return ptrcall!(bool)(_classBinding.getCenterY, _godot_object);
341 	}
342 	/**
343 	
344 	*/
345 	void setCenterZ(in bool enable)
346 	{
347 		checkClassBinding!(typeof(this))();
348 		ptrcall!(void)(_classBinding.setCenterZ, _godot_object, enable);
349 	}
350 	/**
351 	
352 	*/
353 	bool getCenterZ() const
354 	{
355 		checkClassBinding!(typeof(this))();
356 		return ptrcall!(bool)(_classBinding.getCenterZ, _godot_object);
357 	}
358 	/**
359 	
360 	*/
361 	void setClip(in bool enabled, in bool clipabove = true, in long floor = 0, in long axis = 0)
362 	{
363 		checkClassBinding!(typeof(this))();
364 		ptrcall!(void)(_classBinding.setClip, _godot_object, enabled, clipabove, floor, axis);
365 	}
366 	/**
367 	Clear all cells.
368 	*/
369 	void clear()
370 	{
371 		checkClassBinding!(typeof(this))();
372 		ptrcall!(void)(_classBinding.clear, _godot_object);
373 	}
374 	/**
375 	Array of $(D Vector3) with the non empty cell coordinates in the grid map.
376 	*/
377 	Array getUsedCells() const
378 	{
379 		checkClassBinding!(typeof(this))();
380 		return ptrcall!(Array)(_classBinding.getUsedCells, _godot_object);
381 	}
382 	/**
383 	Array of $(D Transform) and $(D Mesh) references corresponding to the non empty cells in the grid. The transforms are specified in world space.
384 	*/
385 	Array getMeshes()
386 	{
387 		checkClassBinding!(typeof(this))();
388 		return ptrcall!(Array)(_classBinding.getMeshes, _godot_object);
389 	}
390 	/**
391 	
392 	*/
393 	Array getBakeMeshes()
394 	{
395 		checkClassBinding!(typeof(this))();
396 		return ptrcall!(Array)(_classBinding.getBakeMeshes, _godot_object);
397 	}
398 	/**
399 	
400 	*/
401 	RID getBakeMeshInstance(in long idx)
402 	{
403 		checkClassBinding!(typeof(this))();
404 		return ptrcall!(RID)(_classBinding.getBakeMeshInstance, _godot_object, idx);
405 	}
406 	/**
407 	
408 	*/
409 	void clearBakedMeshes()
410 	{
411 		checkClassBinding!(typeof(this))();
412 		ptrcall!(void)(_classBinding.clearBakedMeshes, _godot_object);
413 	}
414 	/**
415 	
416 	*/
417 	void makeBakedMeshes(in bool gen_lightmap_uv = false, in double lightmap_uv_texel_size = 0.1)
418 	{
419 		checkClassBinding!(typeof(this))();
420 		ptrcall!(void)(_classBinding.makeBakedMeshes, _godot_object, gen_lightmap_uv, lightmap_uv_texel_size);
421 	}
422 	/**
423 	Deprecated, use $(D meshLibrary) instead.
424 	*/
425 	@property MeshLibrary theme()
426 	{
427 		return getTheme();
428 	}
429 	/// ditto
430 	@property void theme(MeshLibrary v)
431 	{
432 		setTheme(v);
433 	}
434 	/**
435 	The assigned $(D MeshLibrary).
436 	*/
437 	@property MeshLibrary meshLibrary()
438 	{
439 		return getMeshLibrary();
440 	}
441 	/// ditto
442 	@property void meshLibrary(MeshLibrary v)
443 	{
444 		setMeshLibrary(v);
445 	}
446 	/**
447 	The dimensions of the grid's cells.
448 	*/
449 	@property Vector3 cellSize()
450 	{
451 		return getCellSize();
452 	}
453 	/// ditto
454 	@property void cellSize(Vector3 v)
455 	{
456 		setCellSize(v);
457 	}
458 	/**
459 	The size of each octant measured in number of cells. This applies to all three axis.
460 	*/
461 	@property long cellOctantSize()
462 	{
463 		return getOctantSize();
464 	}
465 	/// ditto
466 	@property void cellOctantSize(long v)
467 	{
468 		setOctantSize(v);
469 	}
470 	/**
471 	If `true` grid items are centered on the X axis.
472 	*/
473 	@property bool cellCenterX()
474 	{
475 		return getCenterX();
476 	}
477 	/// ditto
478 	@property void cellCenterX(bool v)
479 	{
480 		setCenterX(v);
481 	}
482 	/**
483 	If `true` grid items are centered on the Y axis.
484 	*/
485 	@property bool cellCenterY()
486 	{
487 		return getCenterY();
488 	}
489 	/// ditto
490 	@property void cellCenterY(bool v)
491 	{
492 		setCenterY(v);
493 	}
494 	/**
495 	If `true` grid items are centered on the Z axis.
496 	*/
497 	@property bool cellCenterZ()
498 	{
499 		return getCenterZ();
500 	}
501 	/// ditto
502 	@property void cellCenterZ(bool v)
503 	{
504 		setCenterZ(v);
505 	}
506 	/**
507 	
508 	*/
509 	@property double cellScale()
510 	{
511 		return getCellScale();
512 	}
513 	/// ditto
514 	@property void cellScale(double v)
515 	{
516 		setCellScale(v);
517 	}
518 	/**
519 	
520 	*/
521 	@property long collisionLayer()
522 	{
523 		return getCollisionLayer();
524 	}
525 	/// ditto
526 	@property void collisionLayer(long v)
527 	{
528 		setCollisionLayer(v);
529 	}
530 	/**
531 	
532 	*/
533 	@property long collisionMask()
534 	{
535 		return getCollisionMask();
536 	}
537 	/// ditto
538 	@property void collisionMask(long v)
539 	{
540 		setCollisionMask(v);
541 	}
542 }