1 /** 2 Draws simple geometry from code. 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.immediategeometry; 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.geometryinstance; 25 import godot.visualinstance; 26 import godot.texture; 27 /** 28 Draws simple geometry from code. 29 30 Uses a drawing mode similar to OpenGL 1.x. 31 See also $(D ArrayMesh), $(D MeshDataTool) and $(D SurfaceTool) for procedural geometry generation. 32 $(B Note:) ImmediateGeometry3D is best suited to small amounts of mesh data that change every frame. It will be slow when handling large amounts of mesh data. If mesh data doesn't change often, use $(D ArrayMesh), $(D MeshDataTool) or $(D SurfaceTool) instead. 33 $(B Note:) Godot uses clockwise $(D url=https://learnopengl.com/Advanced-OpenGL/Face-culling)winding order$(D /url) for front faces of triangle primitive modes. 34 $(B Note:) In case of missing points when handling large amounts of mesh data, try increasing its buffer size limit under $(D ProjectSettings.rendering/limits/buffers/immediateBufferSizeKb). 35 */ 36 @GodotBaseClass struct ImmediateGeometry 37 { 38 package(godot) enum string _GODOT_internal_name = "ImmediateGeometry"; 39 public: 40 @nogc nothrow: 41 union { /** */ godot_object _godot_object; /** */ GeometryInstance _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("add_sphere") GodotMethod!(void, long, long, double, bool) addSphere; 49 @GodotName("add_vertex") GodotMethod!(void, Vector3) addVertex; 50 @GodotName("begin") GodotMethod!(void, long, Texture) begin; 51 @GodotName("clear") GodotMethod!(void) clear; 52 @GodotName("end") GodotMethod!(void) end; 53 @GodotName("set_color") GodotMethod!(void, Color) setColor; 54 @GodotName("set_normal") GodotMethod!(void, Vector3) setNormal; 55 @GodotName("set_tangent") GodotMethod!(void, Plane) setTangent; 56 @GodotName("set_uv") GodotMethod!(void, Vector2) setUv; 57 @GodotName("set_uv2") GodotMethod!(void, Vector2) setUv2; 58 } 59 /// 60 pragma(inline, true) bool opEquals(in ImmediateGeometry other) const 61 { return _godot_object.ptr is other._godot_object.ptr; } 62 /// 63 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 64 { _godot_object.ptr = n; return null; } 65 /// 66 pragma(inline, true) bool opEquals(typeof(null) n) const 67 { return _godot_object.ptr is n; } 68 /// 69 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 70 mixin baseCasts; 71 /// Construct a new instance of ImmediateGeometry. 72 /// Note: use `memnew!ImmediateGeometry` instead. 73 static ImmediateGeometry _new() 74 { 75 static godot_class_constructor constructor; 76 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("ImmediateGeometry"); 77 if(constructor is null) return typeof(this).init; 78 return cast(ImmediateGeometry)(constructor()); 79 } 80 @disable new(size_t s); 81 /** 82 Simple helper to draw an UV sphere with given latitude, longitude and radius. 83 */ 84 void addSphere(in long lats, in long lons, in double radius, in bool add_uv = true) 85 { 86 checkClassBinding!(typeof(this))(); 87 ptrcall!(void)(GDNativeClassBinding.addSphere, _godot_object, lats, lons, radius, add_uv); 88 } 89 /** 90 Adds a vertex in local coordinate space with the currently set color/uv/etc. 91 */ 92 void addVertex(in Vector3 position) 93 { 94 checkClassBinding!(typeof(this))(); 95 ptrcall!(void)(GDNativeClassBinding.addVertex, _godot_object, position); 96 } 97 /** 98 Begin drawing (and optionally pass a texture override). When done call $(D end). For more information on how this works, search for `glBegin()` and `glEnd()` references. 99 For the type of primitive, see the $(D Mesh.primitivetype) enum. 100 */ 101 void begin(in long primitive, Texture texture = Texture.init) 102 { 103 checkClassBinding!(typeof(this))(); 104 ptrcall!(void)(GDNativeClassBinding.begin, _godot_object, primitive, texture); 105 } 106 /** 107 Clears everything that was drawn using begin/end. 108 */ 109 void clear() 110 { 111 checkClassBinding!(typeof(this))(); 112 ptrcall!(void)(GDNativeClassBinding.clear, _godot_object); 113 } 114 /** 115 Ends a drawing context and displays the results. 116 */ 117 void end() 118 { 119 checkClassBinding!(typeof(this))(); 120 ptrcall!(void)(GDNativeClassBinding.end, _godot_object); 121 } 122 /** 123 The current drawing color. 124 */ 125 void setColor(in Color color) 126 { 127 checkClassBinding!(typeof(this))(); 128 ptrcall!(void)(GDNativeClassBinding.setColor, _godot_object, color); 129 } 130 /** 131 The next vertex's normal. 132 */ 133 void setNormal(in Vector3 normal) 134 { 135 checkClassBinding!(typeof(this))(); 136 ptrcall!(void)(GDNativeClassBinding.setNormal, _godot_object, normal); 137 } 138 /** 139 The next vertex's tangent (and binormal facing). 140 */ 141 void setTangent(in Plane tangent) 142 { 143 checkClassBinding!(typeof(this))(); 144 ptrcall!(void)(GDNativeClassBinding.setTangent, _godot_object, tangent); 145 } 146 /** 147 The next vertex's UV. 148 */ 149 void setUv(in Vector2 uv) 150 { 151 checkClassBinding!(typeof(this))(); 152 ptrcall!(void)(GDNativeClassBinding.setUv, _godot_object, uv); 153 } 154 /** 155 The next vertex's second layer UV. 156 */ 157 void setUv2(in Vector2 uv) 158 { 159 checkClassBinding!(typeof(this))(); 160 ptrcall!(void)(GDNativeClassBinding.setUv2, _godot_object, uv); 161 } 162 }