1 /** 2 Describes a Bezier curve in 3D space. 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.curve3d; 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.resource; 24 import godot.reference; 25 /** 26 Describes a Bezier curve in 3D space. 27 28 This class describes a Bezier curve in 3D space. It is mainly used to give a shape to a $(D Path), but can be manually sampled for other purposes. 29 It keeps a cache of precalculated points along the curve, to speed further calculations up. 30 */ 31 @GodotBaseClass struct Curve3D 32 { 33 enum string _GODOT_internal_name = "Curve3D"; 34 public: 35 @nogc nothrow: 36 union { godot_object _godot_object; Resource _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 _classBinding 41 { 42 __gshared: 43 @GodotName("get_point_count") GodotMethod!(long) getPointCount; 44 @GodotName("add_point") GodotMethod!(void, Vector3, Vector3, Vector3, long) addPoint; 45 @GodotName("set_point_position") GodotMethod!(void, long, Vector3) setPointPosition; 46 @GodotName("get_point_position") GodotMethod!(Vector3, long) getPointPosition; 47 @GodotName("set_point_tilt") GodotMethod!(void, long, double) setPointTilt; 48 @GodotName("get_point_tilt") GodotMethod!(double, long) getPointTilt; 49 @GodotName("set_point_in") GodotMethod!(void, long, Vector3) setPointIn; 50 @GodotName("get_point_in") GodotMethod!(Vector3, long) getPointIn; 51 @GodotName("set_point_out") GodotMethod!(void, long, Vector3) setPointOut; 52 @GodotName("get_point_out") GodotMethod!(Vector3, long) getPointOut; 53 @GodotName("remove_point") GodotMethod!(void, long) removePoint; 54 @GodotName("clear_points") GodotMethod!(void) clearPoints; 55 @GodotName("interpolate") GodotMethod!(Vector3, long, double) interpolate; 56 @GodotName("interpolatef") GodotMethod!(Vector3, double) interpolatef; 57 @GodotName("set_bake_interval") GodotMethod!(void, double) setBakeInterval; 58 @GodotName("get_bake_interval") GodotMethod!(double) getBakeInterval; 59 @GodotName("set_up_vector_enabled") GodotMethod!(void, bool) setUpVectorEnabled; 60 @GodotName("is_up_vector_enabled") GodotMethod!(bool) isUpVectorEnabled; 61 @GodotName("get_baked_length") GodotMethod!(double) getBakedLength; 62 @GodotName("interpolate_baked") GodotMethod!(Vector3, double, bool) interpolateBaked; 63 @GodotName("interpolate_baked_up_vector") GodotMethod!(Vector3, double, bool) interpolateBakedUpVector; 64 @GodotName("get_baked_points") GodotMethod!(PoolVector3Array) getBakedPoints; 65 @GodotName("get_baked_tilts") GodotMethod!(PoolRealArray) getBakedTilts; 66 @GodotName("get_baked_up_vectors") GodotMethod!(PoolVector3Array) getBakedUpVectors; 67 @GodotName("get_closest_point") GodotMethod!(Vector3, Vector3) getClosestPoint; 68 @GodotName("get_closest_offset") GodotMethod!(double, Vector3) getClosestOffset; 69 @GodotName("tessellate") GodotMethod!(PoolVector3Array, long, double) tessellate; 70 @GodotName("_get_data") GodotMethod!(Dictionary) _getData; 71 @GodotName("_set_data") GodotMethod!(void, Dictionary) _setData; 72 } 73 bool opEquals(in Curve3D other) const { return _godot_object.ptr is other._godot_object.ptr; } 74 Curve3D opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 75 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 76 mixin baseCasts; 77 static Curve3D _new() 78 { 79 static godot_class_constructor constructor; 80 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Curve3D"); 81 if(constructor is null) return typeof(this).init; 82 return cast(Curve3D)(constructor()); 83 } 84 @disable new(size_t s); 85 /** 86 Returns the number of points describing the curve. 87 */ 88 long getPointCount() const 89 { 90 checkClassBinding!(typeof(this))(); 91 return ptrcall!(long)(_classBinding.getPointCount, _godot_object); 92 } 93 /** 94 Adds a point to a curve, at "position", with control points "in" and "out". 95 If "at_position" is given, the point is inserted before the point number "at_position", moving that point (and every point after) after the inserted point. If "at_position" is not given, or is an illegal value (at_position <0 or at_position >= $(D getPointCount)), the point will be appended at the end of the point list. 96 */ 97 void addPoint(in Vector3 position, in Vector3 _in = Vector3(0, 0, 0), in Vector3 _out = Vector3(0, 0, 0), in long at_position = -1) 98 { 99 checkClassBinding!(typeof(this))(); 100 ptrcall!(void)(_classBinding.addPoint, _godot_object, position, _in, _out, at_position); 101 } 102 /** 103 Sets the position for the vertex "idx". If the index is out of bounds, the function sends an error to the console. 104 */ 105 void setPointPosition(in long idx, in Vector3 position) 106 { 107 checkClassBinding!(typeof(this))(); 108 ptrcall!(void)(_classBinding.setPointPosition, _godot_object, idx, position); 109 } 110 /** 111 Returns the position of the vertex "idx". If the index is out of bounds, the function sends an error to the console, and returns (0, 0, 0). 112 */ 113 Vector3 getPointPosition(in long idx) const 114 { 115 checkClassBinding!(typeof(this))(); 116 return ptrcall!(Vector3)(_classBinding.getPointPosition, _godot_object, idx); 117 } 118 /** 119 Sets the tilt angle in radians for the point "idx". If the index is out of bounds, the function sends an error to the console. 120 The tilt controls the rotation along the look-at axis an object traveling the path would have. In the case of a curve controlling a $(D PathFollow) or $(D OrientedPathFollow), this tilt is an offset over the natural tilt the $(D PathFollow) or $(D OrientedPathFollow) calculates. 121 */ 122 void setPointTilt(in long idx, in double tilt) 123 { 124 checkClassBinding!(typeof(this))(); 125 ptrcall!(void)(_classBinding.setPointTilt, _godot_object, idx, tilt); 126 } 127 /** 128 Returns the tilt angle in radians for the point "idx". If the index is out of bounds, the function sends an error to the console, and returns 0. 129 */ 130 double getPointTilt(in long idx) const 131 { 132 checkClassBinding!(typeof(this))(); 133 return ptrcall!(double)(_classBinding.getPointTilt, _godot_object, idx); 134 } 135 /** 136 Sets the position of the control point leading to the vertex "idx". If the index is out of bounds, the function sends an error to the console. 137 */ 138 void setPointIn(in long idx, in Vector3 position) 139 { 140 checkClassBinding!(typeof(this))(); 141 ptrcall!(void)(_classBinding.setPointIn, _godot_object, idx, position); 142 } 143 /** 144 Returns the position of the control point leading to the vertex "idx". If the index is out of bounds, the function sends an error to the console, and returns (0, 0, 0). 145 */ 146 Vector3 getPointIn(in long idx) const 147 { 148 checkClassBinding!(typeof(this))(); 149 return ptrcall!(Vector3)(_classBinding.getPointIn, _godot_object, idx); 150 } 151 /** 152 Sets the position of the control point leading out of the vertex "idx". If the index is out of bounds, the function sends an error to the console. 153 */ 154 void setPointOut(in long idx, in Vector3 position) 155 { 156 checkClassBinding!(typeof(this))(); 157 ptrcall!(void)(_classBinding.setPointOut, _godot_object, idx, position); 158 } 159 /** 160 Returns the position of the control point leading out of the vertex "idx". If the index is out of bounds, the function sends an error to the console, and returns (0, 0, 0). 161 */ 162 Vector3 getPointOut(in long idx) const 163 { 164 checkClassBinding!(typeof(this))(); 165 return ptrcall!(Vector3)(_classBinding.getPointOut, _godot_object, idx); 166 } 167 /** 168 Deletes the point "idx" from the curve. Sends an error to the console if "idx" is out of bounds. 169 */ 170 void removePoint(in long idx) 171 { 172 checkClassBinding!(typeof(this))(); 173 ptrcall!(void)(_classBinding.removePoint, _godot_object, idx); 174 } 175 /** 176 Removes all points from the curve. 177 */ 178 void clearPoints() 179 { 180 checkClassBinding!(typeof(this))(); 181 ptrcall!(void)(_classBinding.clearPoints, _godot_object); 182 } 183 /** 184 Returns the position between the vertex "idx" and the vertex "idx"+1, where "t" controls if the point is the first vertex (t = 0.0), the last vertex (t = 1.0), or in between. Values of "t" outside the range (0.0 >= t <=1) give strange, but predictable results. 185 If "idx" is out of bounds it is truncated to the first or last vertex, and "t" is ignored. If the curve has no points, the function sends an error to the console, and returns (0, 0, 0). 186 */ 187 Vector3 interpolate(in long idx, in double t) const 188 { 189 checkClassBinding!(typeof(this))(); 190 return ptrcall!(Vector3)(_classBinding.interpolate, _godot_object, idx, t); 191 } 192 /** 193 Returns the position at the vertex "fofs". It calls $(D interpolate) using the integer part of fofs as "idx", and its fractional part as "t". 194 */ 195 Vector3 interpolatef(in double fofs) const 196 { 197 checkClassBinding!(typeof(this))(); 198 return ptrcall!(Vector3)(_classBinding.interpolatef, _godot_object, fofs); 199 } 200 /** 201 202 */ 203 void setBakeInterval(in double distance) 204 { 205 checkClassBinding!(typeof(this))(); 206 ptrcall!(void)(_classBinding.setBakeInterval, _godot_object, distance); 207 } 208 /** 209 210 */ 211 double getBakeInterval() const 212 { 213 checkClassBinding!(typeof(this))(); 214 return ptrcall!(double)(_classBinding.getBakeInterval, _godot_object); 215 } 216 /** 217 218 */ 219 void setUpVectorEnabled(in bool enable) 220 { 221 checkClassBinding!(typeof(this))(); 222 ptrcall!(void)(_classBinding.setUpVectorEnabled, _godot_object, enable); 223 } 224 /** 225 226 */ 227 bool isUpVectorEnabled() const 228 { 229 checkClassBinding!(typeof(this))(); 230 return ptrcall!(bool)(_classBinding.isUpVectorEnabled, _godot_object); 231 } 232 /** 233 Returns the total length of the curve, based on the cached points. Given enough density (see $(D setBakeInterval)), it should be approximate enough. 234 */ 235 double getBakedLength() const 236 { 237 checkClassBinding!(typeof(this))(); 238 return ptrcall!(double)(_classBinding.getBakedLength, _godot_object); 239 } 240 /** 241 Returns a point within the curve at position "offset", where "offset" is measured as a distance in 3D units along the curve. 242 To do that, it finds the two cached points where the "offset" lies between, then interpolates the values. This interpolation is cubic if "cubic" is set to true, or linear if set to false. 243 Cubic interpolation tends to follow the curves better, but linear is faster (and often, precise enough). 244 */ 245 Vector3 interpolateBaked(in double offset, in bool cubic = false) const 246 { 247 checkClassBinding!(typeof(this))(); 248 return ptrcall!(Vector3)(_classBinding.interpolateBaked, _godot_object, offset, cubic); 249 } 250 /** 251 Returns an up vector within the curve at position `offset`, where `offset` is measured as a distance in 3D units along the curve. 252 To do that, it finds the two cached up vectors where the `offset` lies between, then interpolates the values. If `apply_tilt` is `true`, an interpolated tilt is applied to the interpolated up vector. 253 If the curve has no up vectors, the function sends an error to the console, and returns (0, 1, 0). 254 */ 255 Vector3 interpolateBakedUpVector(in double offset, in bool apply_tilt = false) const 256 { 257 checkClassBinding!(typeof(this))(); 258 return ptrcall!(Vector3)(_classBinding.interpolateBakedUpVector, _godot_object, offset, apply_tilt); 259 } 260 /** 261 Returns the cache of points as a $(D PoolVector3Array). 262 */ 263 PoolVector3Array getBakedPoints() const 264 { 265 checkClassBinding!(typeof(this))(); 266 return ptrcall!(PoolVector3Array)(_classBinding.getBakedPoints, _godot_object); 267 } 268 /** 269 Returns the cache of tilts as a $(D RealArray). 270 */ 271 PoolRealArray getBakedTilts() const 272 { 273 checkClassBinding!(typeof(this))(); 274 return ptrcall!(PoolRealArray)(_classBinding.getBakedTilts, _godot_object); 275 } 276 /** 277 Returns the cache of up vectors as a $(D PoolVector3Array). 278 If $(D upVectorEnabled) is `false`, the cache will be empty. 279 */ 280 PoolVector3Array getBakedUpVectors() const 281 { 282 checkClassBinding!(typeof(this))(); 283 return ptrcall!(PoolVector3Array)(_classBinding.getBakedUpVectors, _godot_object); 284 } 285 /** 286 Returns the closest point (in curve's local space) to `to_point`. 287 `to_point` must be in this curve's local space. 288 */ 289 Vector3 getClosestPoint(in Vector3 to_point) const 290 { 291 checkClassBinding!(typeof(this))(); 292 return ptrcall!(Vector3)(_classBinding.getClosestPoint, _godot_object, to_point); 293 } 294 /** 295 Returns the closest offset to `to_point`. This offset is meant to be used in one of the interpolate_baked* methods. 296 `to_point` must be in this curve's local space. 297 */ 298 double getClosestOffset(in Vector3 to_point) const 299 { 300 checkClassBinding!(typeof(this))(); 301 return ptrcall!(double)(_classBinding.getClosestOffset, _godot_object, to_point); 302 } 303 /** 304 Returns a list of points along the curve, with a curvature controlled point density. That is, the curvier parts will have more points than the straighter parts. 305 This approximation makes straight segments between each point, then subdivides those segments until the resulting shape is similar enough. 306 "max_stages" controls how many subdivisions a curve segment may face before it is considered approximate enough. Each subdivision splits the segment in half, so the default 5 stages may mean up to 32 subdivisions per curve segment. Increase with care! 307 "tolerance_degrees" controls how many degrees the midpoint of a segment may deviate from the real curve, before the segment has to be subdivided. 308 */ 309 PoolVector3Array tessellate(in long max_stages = 5, in double tolerance_degrees = 4) const 310 { 311 checkClassBinding!(typeof(this))(); 312 return ptrcall!(PoolVector3Array)(_classBinding.tessellate, _godot_object, max_stages, tolerance_degrees); 313 } 314 /** 315 316 */ 317 Dictionary _getData() const 318 { 319 Array _GODOT_args = Array.empty_array; 320 String _GODOT_method_name = String("_get_data"); 321 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Dictionary); 322 } 323 /** 324 325 */ 326 void _setData(in Dictionary arg0) 327 { 328 Array _GODOT_args = Array.empty_array; 329 _GODOT_args.append(arg0); 330 String _GODOT_method_name = String("_set_data"); 331 this.callv(_GODOT_method_name, _GODOT_args); 332 } 333 /** 334 The distance in meters between two adjacent cached points. Changing it forces the cache to be recomputed the next time the $(D getBakedPoints) or $(D getBakedLength) function is called. The smaller the distance, the more points in the cache and the more memory it will consume, so use with care. 335 */ 336 @property double bakeInterval() 337 { 338 return getBakeInterval(); 339 } 340 /// ditto 341 @property void bakeInterval(double v) 342 { 343 setBakeInterval(v); 344 } 345 /** 346 347 */ 348 @property Dictionary _data() 349 { 350 return _getData(); 351 } 352 /// ditto 353 @property void _data(Dictionary v) 354 { 355 _setData(v); 356 } 357 /** 358 If `true`, the curve will bake up vectors used for orientation. See $(D OrientedPathFollow). Changing it forces the cache to be recomputed. 359 */ 360 @property bool upVectorEnabled() 361 { 362 return isUpVectorEnabled(); 363 } 364 /// ditto 365 @property void upVectorEnabled(bool v) 366 { 367 setUpVectorEnabled(v); 368 } 369 }