1 /** 2 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.arraymesh; 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.mesh; 24 import godot.material; 25 import godot.resource; 26 import godot.reference; 27 /** 28 The `ArrayMesh` is used to construct a $(D Mesh) by specifying the attributes as arrays. The most basic example is the creation of a single triangle 29 30 31 var vertices = PoolVector3Array() 32 vertices.push_back(Vector3(0,1,0)) 33 vertices.push_back(Vector3(1,0,0)) 34 vertices.push_back(Vector3(0,0,1)) 35 # Initialize the ArrayMesh. 36 var arr_mesh = ArrayMesh.new() 37 var arrays = [] 38 arrays.resize(ArrayMesh.ARRAY_MAX) 39 arrays$(D ArrayMesh.ARRAY_VERTEX) = vertices 40 # Create the Mesh. 41 arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays) 42 var m = MeshInstance.new() 43 m.mesh = arr_mesh 44 45 46 The `MeshInstance` is ready to be added to the SceneTree to be shown. 47 */ 48 @GodotBaseClass struct ArrayMesh 49 { 50 enum string _GODOT_internal_name = "ArrayMesh"; 51 public: 52 @nogc nothrow: 53 union { godot_object _godot_object; Mesh _GODOT_base; } 54 alias _GODOT_base this; 55 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 56 package(godot) __gshared bool _classBindingInitialized = false; 57 package(godot) static struct _classBinding 58 { 59 __gshared: 60 @GodotName("add_blend_shape") GodotMethod!(void, String) addBlendShape; 61 @GodotName("get_blend_shape_count") GodotMethod!(long) getBlendShapeCount; 62 @GodotName("get_blend_shape_name") GodotMethod!(String, long) getBlendShapeName; 63 @GodotName("clear_blend_shapes") GodotMethod!(void) clearBlendShapes; 64 @GodotName("set_blend_shape_mode") GodotMethod!(void, long) setBlendShapeMode; 65 @GodotName("get_blend_shape_mode") GodotMethod!(Mesh.BlendShapeMode) getBlendShapeMode; 66 @GodotName("add_surface_from_arrays") GodotMethod!(void, long, Array, Array, long) addSurfaceFromArrays; 67 @GodotName("surface_remove") GodotMethod!(void, long) surfaceRemove; 68 @GodotName("surface_update_region") GodotMethod!(void, long, long, PoolByteArray) surfaceUpdateRegion; 69 @GodotName("surface_get_array_len") GodotMethod!(long, long) surfaceGetArrayLen; 70 @GodotName("surface_get_array_index_len") GodotMethod!(long, long) surfaceGetArrayIndexLen; 71 @GodotName("surface_get_format") GodotMethod!(long, long) surfaceGetFormat; 72 @GodotName("surface_get_primitive_type") GodotMethod!(Mesh.PrimitiveType, long) surfaceGetPrimitiveType; 73 @GodotName("surface_set_material") GodotMethod!(void, long, Material) surfaceSetMaterial; 74 @GodotName("surface_find_by_name") GodotMethod!(long, String) surfaceFindByName; 75 @GodotName("surface_set_name") GodotMethod!(void, long, String) surfaceSetName; 76 @GodotName("surface_get_name") GodotMethod!(String, long) surfaceGetName; 77 @GodotName("center_geometry") GodotMethod!(void) centerGeometry; 78 @GodotName("regen_normalmaps") GodotMethod!(void) regenNormalmaps; 79 @GodotName("lightmap_unwrap") GodotMethod!(GodotError, Transform, double) lightmapUnwrap; 80 @GodotName("set_custom_aabb") GodotMethod!(void, AABB) setCustomAabb; 81 @GodotName("get_custom_aabb") GodotMethod!(AABB) getCustomAabb; 82 } 83 bool opEquals(in ArrayMesh other) const { return _godot_object.ptr is other._godot_object.ptr; } 84 ArrayMesh opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 85 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 86 mixin baseCasts; 87 static ArrayMesh _new() 88 { 89 static godot_class_constructor constructor; 90 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("ArrayMesh"); 91 if(constructor is null) return typeof(this).init; 92 return cast(ArrayMesh)(constructor()); 93 } 94 @disable new(size_t s); 95 /// 96 enum ArrayFormat : int 97 { 98 /** 99 Array format will include vertices (mandatory). 100 */ 101 arrayFormatVertex = 1, 102 /** 103 Array format will include normals 104 */ 105 arrayFormatNormal = 2, 106 /** 107 Array format will include tangents 108 */ 109 arrayFormatTangent = 4, 110 /** 111 Array format will include a color array. 112 */ 113 arrayFormatColor = 8, 114 /** 115 Array format will include UVs. 116 */ 117 arrayFormatTexUv = 16, 118 /** 119 Array format will include another set of UVs. 120 */ 121 arrayFormatTexUv2 = 32, 122 /** 123 Array format will include bone indices. 124 */ 125 arrayFormatBones = 64, 126 /** 127 Array format will include bone weights. 128 */ 129 arrayFormatWeights = 128, 130 /** 131 Index array will be used. 132 */ 133 arrayFormatIndex = 256, 134 } 135 /// 136 enum ArrayType : int 137 { 138 /** 139 Vertex array (array of $(D Vector3) vertices). 140 */ 141 arrayVertex = 0, 142 /** 143 Normal array (array of $(D Vector3) normals). 144 */ 145 arrayNormal = 1, 146 /** 147 Tangent array, array of groups of 4 floats. first 3 floats determine the tangent, and the last the binormal direction as -1 or 1. 148 */ 149 arrayTangent = 2, 150 /** 151 Vertex array (array of $(D Color) colors). 152 */ 153 arrayColor = 3, 154 /** 155 UV array (array of $(D Vector3) UVs or float array of groups of 2 floats (u,v)). 156 */ 157 arrayTexUv = 4, 158 /** 159 Second UV array (array of $(D Vector3) UVs or float array of groups of 2 floats (u,v)). 160 */ 161 arrayTexUv2 = 5, 162 /** 163 Array of bone indices, as a float array. Each element in groups of 4 floats. 164 */ 165 arrayBones = 6, 166 /** 167 Array of bone weights, as a float array. Each element in groups of 4 floats. 168 */ 169 arrayWeights = 7, 170 /** 171 $(D Array) of integers used as indices referencing vertices, colors, normals, tangents, and textures. All of those arrays must have the same number of elements as the vertex array. No index can be beyond the vertex array size. When this index array is present, it puts the function into "index mode," where the index selects the *i*'th vertex, normal, tangent, color, UV, etc. This means if you want to have different normals or colors along an edge, you have to duplicate the vertices. 172 For triangles, the index array is interpreted as triples, referring to the vertices of each triangle. For lines, the index array is in pairs indicating the start and end of each line. 173 */ 174 arrayIndex = 8, 175 /** 176 177 */ 178 arrayMax = 9, 179 } 180 /// 181 enum Constants : int 182 { 183 /** 184 Default value used for index_array_len when no indices are present. 185 */ 186 noIndexArray = -1, 187 arrayVertex = 0, 188 arrayNormal = 1, 189 arrayFormatVertex = 1, 190 arrayFormatNormal = 2, 191 arrayTangent = 2, 192 arrayColor = 3, 193 /** 194 Amount of weights/bone indices per vertex (always 4). 195 */ 196 arrayWeightsSize = 4, 197 arrayTexUv = 4, 198 arrayFormatTangent = 4, 199 arrayTexUv2 = 5, 200 arrayBones = 6, 201 arrayWeights = 7, 202 arrayFormatColor = 8, 203 arrayIndex = 8, 204 arrayMax = 9, 205 arrayFormatTexUv = 16, 206 arrayFormatTexUv2 = 32, 207 arrayFormatBones = 64, 208 arrayFormatWeights = 128, 209 arrayFormatIndex = 256, 210 } 211 /** 212 213 */ 214 void addBlendShape(StringArg0)(in StringArg0 name) 215 { 216 checkClassBinding!(typeof(this))(); 217 ptrcall!(void)(_classBinding.addBlendShape, _godot_object, name); 218 } 219 /** 220 Returns the number of blend shapes that the `ArrayMesh` holds. 221 */ 222 long getBlendShapeCount() const 223 { 224 checkClassBinding!(typeof(this))(); 225 return ptrcall!(long)(_classBinding.getBlendShapeCount, _godot_object); 226 } 227 /** 228 Returns the name of the blend shape at this index. 229 */ 230 String getBlendShapeName(in long index) const 231 { 232 checkClassBinding!(typeof(this))(); 233 return ptrcall!(String)(_classBinding.getBlendShapeName, _godot_object, index); 234 } 235 /** 236 Remove all blend shapes from this `ArrayMesh`. 237 */ 238 void clearBlendShapes() 239 { 240 checkClassBinding!(typeof(this))(); 241 ptrcall!(void)(_classBinding.clearBlendShapes, _godot_object); 242 } 243 /** 244 245 */ 246 void setBlendShapeMode(in long mode) 247 { 248 checkClassBinding!(typeof(this))(); 249 ptrcall!(void)(_classBinding.setBlendShapeMode, _godot_object, mode); 250 } 251 /** 252 253 */ 254 Mesh.BlendShapeMode getBlendShapeMode() const 255 { 256 checkClassBinding!(typeof(this))(); 257 return ptrcall!(Mesh.BlendShapeMode)(_classBinding.getBlendShapeMode, _godot_object); 258 } 259 /** 260 Creates a new surface. 261 Surfaces are created to be rendered using a "primitive", which may be PRIMITIVE_POINTS, PRIMITIVE_LINES, PRIMITIVE_LINE_STRIP, PRIMITIVE_LINE_LOOP, PRIMITIVE_TRIANGLES, PRIMITIVE_TRIANGLE_STRIP, PRIMITIVE_TRIANGLE_FAN. See $(D Mesh) for details. (As a note, when using indices, it is recommended to only use points, lines or triangles). $(D Mesh.getSurfaceCount) will become the `surf_idx` for this new surface. 262 The `arrays` argument is an array of arrays. See $(D arraytype) for the values used in this array. For example, `arrays$(D 0)` is the array of vertices. That first vertex sub-array is always required; the others are optional. Adding an index array puts this function into "index mode" where the vertex and other arrays become the sources of data and the index array defines the vertex order. All sub-arrays must have the same length as the vertex array or be empty, except for `ARRAY_INDEX` if it is used. 263 Adding an index array puts this function into "index mode" where the vertex and other arrays become the sources of data, and the index array defines the order of the vertices. 264 Godot uses clockwise winding order for front faces of triangle primitive modes. 265 */ 266 void addSurfaceFromArrays(in long primitive, in Array arrays, in Array blend_shapes = Array.empty_array, in long compress_flags = 97280) 267 { 268 checkClassBinding!(typeof(this))(); 269 ptrcall!(void)(_classBinding.addSurfaceFromArrays, _godot_object, primitive, arrays, blend_shapes, compress_flags); 270 } 271 /** 272 Remove a surface at position surf_idx, shifting greater surfaces one surf_idx slot down. 273 */ 274 void surfaceRemove(in long surf_idx) 275 { 276 checkClassBinding!(typeof(this))(); 277 ptrcall!(void)(_classBinding.surfaceRemove, _godot_object, surf_idx); 278 } 279 /** 280 281 */ 282 void surfaceUpdateRegion(in long surf_idx, in long offset, in PoolByteArray data) 283 { 284 checkClassBinding!(typeof(this))(); 285 ptrcall!(void)(_classBinding.surfaceUpdateRegion, _godot_object, surf_idx, offset, data); 286 } 287 /** 288 Return the length in vertices of the vertex array in the requested surface (see $(D addSurfaceFromArrays)). 289 */ 290 long surfaceGetArrayLen(in long surf_idx) const 291 { 292 checkClassBinding!(typeof(this))(); 293 return ptrcall!(long)(_classBinding.surfaceGetArrayLen, _godot_object, surf_idx); 294 } 295 /** 296 Return the length in indices of the index array in the requested surface (see $(D addSurfaceFromArrays)). 297 */ 298 long surfaceGetArrayIndexLen(in long surf_idx) const 299 { 300 checkClassBinding!(typeof(this))(); 301 return ptrcall!(long)(_classBinding.surfaceGetArrayIndexLen, _godot_object, surf_idx); 302 } 303 /** 304 Return the format mask of the requested surface (see $(D addSurfaceFromArrays)). 305 */ 306 long surfaceGetFormat(in long surf_idx) const 307 { 308 checkClassBinding!(typeof(this))(); 309 return ptrcall!(long)(_classBinding.surfaceGetFormat, _godot_object, surf_idx); 310 } 311 /** 312 Return the primitive type of the requested surface (see $(D addSurfaceFromArrays)). 313 */ 314 Mesh.PrimitiveType surfaceGetPrimitiveType(in long surf_idx) const 315 { 316 checkClassBinding!(typeof(this))(); 317 return ptrcall!(Mesh.PrimitiveType)(_classBinding.surfaceGetPrimitiveType, _godot_object, surf_idx); 318 } 319 /** 320 Set a $(D Material) for a given surface. Surface will be rendered using this material. 321 */ 322 void surfaceSetMaterial(in long surf_idx, Material material) 323 { 324 checkClassBinding!(typeof(this))(); 325 ptrcall!(void)(_classBinding.surfaceSetMaterial, _godot_object, surf_idx, material); 326 } 327 /** 328 Return the index of the first surface with this name held within this `ArrayMesh`. If none are found -1 is returned. 329 */ 330 long surfaceFindByName(StringArg0)(in StringArg0 name) const 331 { 332 checkClassBinding!(typeof(this))(); 333 return ptrcall!(long)(_classBinding.surfaceFindByName, _godot_object, name); 334 } 335 /** 336 Set a name for a given surface. 337 */ 338 void surfaceSetName(StringArg1)(in long surf_idx, in StringArg1 name) 339 { 340 checkClassBinding!(typeof(this))(); 341 ptrcall!(void)(_classBinding.surfaceSetName, _godot_object, surf_idx, name); 342 } 343 /** 344 Get the name assigned to this surface. 345 */ 346 String surfaceGetName(in long surf_idx) const 347 { 348 checkClassBinding!(typeof(this))(); 349 return ptrcall!(String)(_classBinding.surfaceGetName, _godot_object, surf_idx); 350 } 351 /** 352 Centers the geometry. 353 */ 354 void centerGeometry() 355 { 356 checkClassBinding!(typeof(this))(); 357 ptrcall!(void)(_classBinding.centerGeometry, _godot_object); 358 } 359 /** 360 Will regenerate normal maps for the `ArrayMesh`. 361 */ 362 void regenNormalmaps() 363 { 364 checkClassBinding!(typeof(this))(); 365 ptrcall!(void)(_classBinding.regenNormalmaps, _godot_object); 366 } 367 /** 368 Will perform a UV unwrap on the `ArrayMesh` to prepare the mesh for lightmapping. 369 */ 370 GodotError lightmapUnwrap(in Transform transform, in double texel_size) 371 { 372 checkClassBinding!(typeof(this))(); 373 return ptrcall!(GodotError)(_classBinding.lightmapUnwrap, _godot_object, transform, texel_size); 374 } 375 /** 376 377 */ 378 void setCustomAabb(in AABB aabb) 379 { 380 checkClassBinding!(typeof(this))(); 381 ptrcall!(void)(_classBinding.setCustomAabb, _godot_object, aabb); 382 } 383 /** 384 385 */ 386 AABB getCustomAabb() const 387 { 388 checkClassBinding!(typeof(this))(); 389 return ptrcall!(AABB)(_classBinding.getCustomAabb, _godot_object); 390 } 391 /** 392 393 */ 394 @property Mesh.BlendShapeMode blendShapeMode() 395 { 396 return getBlendShapeMode(); 397 } 398 /// ditto 399 @property void blendShapeMode(long v) 400 { 401 setBlendShapeMode(v); 402 } 403 /** 404 An overriding bounding box for this mesh. 405 */ 406 @property AABB customAabb() 407 { 408 return getCustomAabb(); 409 } 410 /// ditto 411 @property void customAabb(AABB v) 412 { 413 setCustomAabb(v); 414 } 415 }