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