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.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.geometryinstance; 24 import godot.texture; 25 import godot.visualinstance; 26 import godot.spatial; 27 import godot.node; 28 /** 29 Draws simple geometry from code. 30 31 Uses a drawing mode similar to OpenGL 1.x. 32 */ 33 @GodotBaseClass struct ImmediateGeometry 34 { 35 enum string _GODOT_internal_name = "ImmediateGeometry"; 36 public: 37 @nogc nothrow: 38 union { godot_object _godot_object; GeometryInstance _GODOT_base; } 39 alias _GODOT_base this; 40 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 41 package(godot) __gshared bool _classBindingInitialized = false; 42 package(godot) static struct _classBinding 43 { 44 __gshared: 45 @GodotName("begin") GodotMethod!(void, long, Texture) begin; 46 @GodotName("set_normal") GodotMethod!(void, Vector3) setNormal; 47 @GodotName("set_tangent") GodotMethod!(void, Plane) setTangent; 48 @GodotName("set_color") GodotMethod!(void, Color) setColor; 49 @GodotName("set_uv") GodotMethod!(void, Vector2) setUv; 50 @GodotName("set_uv2") GodotMethod!(void, Vector2) setUv2; 51 @GodotName("add_vertex") GodotMethod!(void, Vector3) addVertex; 52 @GodotName("add_sphere") GodotMethod!(void, long, long, double, bool) addSphere; 53 @GodotName("end") GodotMethod!(void) end; 54 @GodotName("clear") GodotMethod!(void) clear; 55 } 56 bool opEquals(in ImmediateGeometry other) const { return _godot_object.ptr is other._godot_object.ptr; } 57 ImmediateGeometry opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 58 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 59 mixin baseCasts; 60 static ImmediateGeometry _new() 61 { 62 static godot_class_constructor constructor; 63 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("ImmediateGeometry"); 64 if(constructor is null) return typeof(this).init; 65 return cast(ImmediateGeometry)(constructor()); 66 } 67 @disable new(size_t s); 68 /** 69 Begin drawing (And optionally pass a texture override). When done call end(). For more information on how this works, search for glBegin() glEnd() references. 70 For the type of primitive, use the $(D Mesh).PRIMITIVE_* enumerations. 71 */ 72 void begin(in long primitive, Texture texture = Texture.init) 73 { 74 checkClassBinding!(typeof(this))(); 75 ptrcall!(void)(_classBinding.begin, _godot_object, primitive, texture); 76 } 77 /** 78 The next vertex's normal. 79 */ 80 void setNormal(in Vector3 normal) 81 { 82 checkClassBinding!(typeof(this))(); 83 ptrcall!(void)(_classBinding.setNormal, _godot_object, normal); 84 } 85 /** 86 The next vertex's tangent (and binormal facing). 87 */ 88 void setTangent(in Plane tangent) 89 { 90 checkClassBinding!(typeof(this))(); 91 ptrcall!(void)(_classBinding.setTangent, _godot_object, tangent); 92 } 93 /** 94 The current drawing color. 95 */ 96 void setColor(in Color color) 97 { 98 checkClassBinding!(typeof(this))(); 99 ptrcall!(void)(_classBinding.setColor, _godot_object, color); 100 } 101 /** 102 The next vertex's UV. 103 */ 104 void setUv(in Vector2 uv) 105 { 106 checkClassBinding!(typeof(this))(); 107 ptrcall!(void)(_classBinding.setUv, _godot_object, uv); 108 } 109 /** 110 The next vertex's second layer UV. 111 */ 112 void setUv2(in Vector2 uv) 113 { 114 checkClassBinding!(typeof(this))(); 115 ptrcall!(void)(_classBinding.setUv2, _godot_object, uv); 116 } 117 /** 118 Adds a vertex with the currently set color/uv/etc. 119 */ 120 void addVertex(in Vector3 position) 121 { 122 checkClassBinding!(typeof(this))(); 123 ptrcall!(void)(_classBinding.addVertex, _godot_object, position); 124 } 125 /** 126 Simple helper to draw a uvsphere, with given latitudes, longitude and radius. 127 */ 128 void addSphere(in long lats, in long lons, in double radius, in bool add_uv = true) 129 { 130 checkClassBinding!(typeof(this))(); 131 ptrcall!(void)(_classBinding.addSphere, _godot_object, lats, lons, radius, add_uv); 132 } 133 /** 134 Ends a drawing context and displays the results. 135 */ 136 void end() 137 { 138 checkClassBinding!(typeof(this))(); 139 ptrcall!(void)(_classBinding.end, _godot_object); 140 } 141 /** 142 Clears everything that was drawn using begin/end. 143 */ 144 void clear() 145 { 146 checkClassBinding!(typeof(this))(); 147 ptrcall!(void)(_classBinding.clear, _godot_object); 148 } 149 }