1 /** 2 Base class for all primitive meshes. Handles applying a $(D Material) to a primitive mesh. 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.primitivemesh; 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.mesh; 24 import godot.resource; 25 import godot.material; 26 /** 27 Base class for all primitive meshes. Handles applying a $(D Material) to a primitive mesh. 28 29 Examples include $(D CapsuleMesh), $(D CubeMesh), $(D CylinderMesh), $(D PlaneMesh), $(D PrismMesh), $(D QuadMesh), and $(D SphereMesh). 30 */ 31 @GodotBaseClass struct PrimitiveMesh 32 { 33 package(godot) enum string _GODOT_internal_name = "PrimitiveMesh"; 34 public: 35 @nogc nothrow: 36 union { /** */ godot_object _godot_object; /** */ Mesh _GODOT_base; } 37 alias _GODOT_base this; 38 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 39 package(godot) __gshared bool _classBindingInitialized = false; 40 package(godot) static struct GDNativeClassBinding 41 { 42 __gshared: 43 @GodotName("_update") GodotMethod!(void) _update; 44 @GodotName("get_custom_aabb") GodotMethod!(AABB) getCustomAabb; 45 @GodotName("get_flip_faces") GodotMethod!(bool) getFlipFaces; 46 @GodotName("get_material") GodotMethod!(Material) getMaterial; 47 @GodotName("get_mesh_arrays") GodotMethod!(Array) getMeshArrays; 48 @GodotName("set_custom_aabb") GodotMethod!(void, AABB) setCustomAabb; 49 @GodotName("set_flip_faces") GodotMethod!(void, bool) setFlipFaces; 50 @GodotName("set_material") GodotMethod!(void, Material) setMaterial; 51 } 52 /// 53 pragma(inline, true) bool opEquals(in PrimitiveMesh other) const 54 { return _godot_object.ptr is other._godot_object.ptr; } 55 /// 56 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 57 { _godot_object.ptr = n; return null; } 58 /// 59 pragma(inline, true) bool opEquals(typeof(null) n) const 60 { return _godot_object.ptr is n; } 61 /// 62 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 63 mixin baseCasts; 64 /// Construct a new instance of PrimitiveMesh. 65 /// Note: use `memnew!PrimitiveMesh` instead. 66 static PrimitiveMesh _new() 67 { 68 static godot_class_constructor constructor; 69 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("PrimitiveMesh"); 70 if(constructor is null) return typeof(this).init; 71 return cast(PrimitiveMesh)(constructor()); 72 } 73 @disable new(size_t s); 74 /** 75 76 */ 77 void _update() const 78 { 79 Array _GODOT_args = Array.make(); 80 String _GODOT_method_name = String("_update"); 81 this.callv(_GODOT_method_name, _GODOT_args); 82 } 83 /** 84 85 */ 86 AABB getCustomAabb() const 87 { 88 checkClassBinding!(typeof(this))(); 89 return ptrcall!(AABB)(GDNativeClassBinding.getCustomAabb, _godot_object); 90 } 91 /** 92 93 */ 94 bool getFlipFaces() const 95 { 96 checkClassBinding!(typeof(this))(); 97 return ptrcall!(bool)(GDNativeClassBinding.getFlipFaces, _godot_object); 98 } 99 /** 100 101 */ 102 Ref!Material getMaterial() const 103 { 104 checkClassBinding!(typeof(this))(); 105 return ptrcall!(Material)(GDNativeClassBinding.getMaterial, _godot_object); 106 } 107 /** 108 Returns mesh arrays used to constitute surface of $(D Mesh). The result can be passed to $(D ArrayMesh.addSurfaceFromArrays) to create a new surface. For example: 109 110 111 var c := CylinderMesh.new() 112 var arr_mesh := ArrayMesh.new() 113 arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, c.get_mesh_arrays()) 114 115 116 */ 117 Array getMeshArrays() const 118 { 119 checkClassBinding!(typeof(this))(); 120 return ptrcall!(Array)(GDNativeClassBinding.getMeshArrays, _godot_object); 121 } 122 /** 123 124 */ 125 void setCustomAabb(in AABB aabb) 126 { 127 checkClassBinding!(typeof(this))(); 128 ptrcall!(void)(GDNativeClassBinding.setCustomAabb, _godot_object, aabb); 129 } 130 /** 131 132 */ 133 void setFlipFaces(in bool flip_faces) 134 { 135 checkClassBinding!(typeof(this))(); 136 ptrcall!(void)(GDNativeClassBinding.setFlipFaces, _godot_object, flip_faces); 137 } 138 /** 139 140 */ 141 void setMaterial(Material material) 142 { 143 checkClassBinding!(typeof(this))(); 144 ptrcall!(void)(GDNativeClassBinding.setMaterial, _godot_object, material); 145 } 146 /** 147 Overrides the $(D AABB) with one defined by user for use with frustum culling. Especially useful to avoid unexpected culling when using a shader to offset vertices. 148 */ 149 @property AABB customAabb() 150 { 151 return getCustomAabb(); 152 } 153 /// ditto 154 @property void customAabb(AABB v) 155 { 156 setCustomAabb(v); 157 } 158 /** 159 If set, the order of the vertices in each triangle are reversed resulting in the backside of the mesh being drawn. 160 This gives the same result as using $(D constant SpatialMaterial.CULL_BACK) in $(D SpatialMaterial.paramsCullMode). 161 */ 162 @property bool flipFaces() 163 { 164 return getFlipFaces(); 165 } 166 /// ditto 167 @property void flipFaces(bool v) 168 { 169 setFlipFaces(v); 170 } 171 }