1 /** 2 A $(D Resource) that contains vertex array-based geometry. 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.mesh; 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.resource; 24 import godot.shape; 25 import godot.trianglemesh; 26 import godot.material; 27 /** 28 A $(D Resource) that contains vertex array-based geometry. 29 30 Mesh is a type of $(D Resource) that contains vertex array-based geometry, divided in $(I surfaces). Each surface contains a completely separate array and a material used to draw it. Design wise, a mesh with multiple surfaces is preferred to a single surface, because objects created in 3D editing software commonly contain multiple materials. 31 */ 32 @GodotBaseClass struct Mesh 33 { 34 package(godot) enum string _GODOT_internal_name = "Mesh"; 35 public: 36 @nogc nothrow: 37 union { /** */ godot_object _godot_object; /** */ Resource _GODOT_base; } 38 alias _GODOT_base this; 39 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 40 package(godot) __gshared bool _classBindingInitialized = false; 41 package(godot) static struct GDNativeClassBinding 42 { 43 __gshared: 44 @GodotName("create_convex_shape") GodotMethod!(Shape) createConvexShape; 45 @GodotName("create_outline") GodotMethod!(Mesh, double) createOutline; 46 @GodotName("create_trimesh_shape") GodotMethod!(Shape) createTrimeshShape; 47 @GodotName("generate_triangle_mesh") GodotMethod!(TriangleMesh) generateTriangleMesh; 48 @GodotName("get_aabb") GodotMethod!(AABB) getAabb; 49 @GodotName("get_faces") GodotMethod!(PoolVector3Array) getFaces; 50 @GodotName("get_lightmap_size_hint") GodotMethod!(Vector2) getLightmapSizeHint; 51 @GodotName("get_surface_count") GodotMethod!(long) getSurfaceCount; 52 @GodotName("set_lightmap_size_hint") GodotMethod!(void, Vector2) setLightmapSizeHint; 53 @GodotName("surface_get_arrays") GodotMethod!(Array, long) surfaceGetArrays; 54 @GodotName("surface_get_blend_shape_arrays") GodotMethod!(Array, long) surfaceGetBlendShapeArrays; 55 @GodotName("surface_get_material") GodotMethod!(Material, long) surfaceGetMaterial; 56 @GodotName("surface_set_material") GodotMethod!(void, long, Material) surfaceSetMaterial; 57 } 58 /// 59 pragma(inline, true) bool opEquals(in Mesh other) const 60 { return _godot_object.ptr is other._godot_object.ptr; } 61 /// 62 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 63 { _godot_object.ptr = n; return null; } 64 /// 65 pragma(inline, true) bool opEquals(typeof(null) n) const 66 { return _godot_object.ptr is n; } 67 /// 68 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 69 mixin baseCasts; 70 /// Construct a new instance of Mesh. 71 /// Note: use `memnew!Mesh` instead. 72 static Mesh _new() 73 { 74 static godot_class_constructor constructor; 75 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Mesh"); 76 if(constructor is null) return typeof(this).init; 77 return cast(Mesh)(constructor()); 78 } 79 @disable new(size_t s); 80 /// 81 enum BlendShapeMode : int 82 { 83 /** 84 Blend shapes are normalized. 85 */ 86 blendShapeModeNormalized = 0, 87 /** 88 Blend shapes are relative to base weight. 89 */ 90 blendShapeModeRelative = 1, 91 } 92 /// 93 enum PrimitiveType : int 94 { 95 /** 96 Render array as points (one vertex equals one point). 97 */ 98 primitivePoints = 0, 99 /** 100 Render array as lines (every two vertices a line is created). 101 */ 102 primitiveLines = 1, 103 /** 104 Render array as line strip. 105 */ 106 primitiveLineStrip = 2, 107 /** 108 Render array as line loop (like line strip, but closed). 109 */ 110 primitiveLineLoop = 3, 111 /** 112 Render array as triangles (every three vertices a triangle is created). 113 */ 114 primitiveTriangles = 4, 115 /** 116 Render array as triangle strips. 117 */ 118 primitiveTriangleStrip = 5, 119 /** 120 Render array as triangle fans. 121 */ 122 primitiveTriangleFan = 6, 123 } 124 /// 125 enum ArrayFormat : int 126 { 127 /** 128 Mesh array contains vertices. All meshes require a vertex array so this should always be present. 129 */ 130 arrayFormatVertex = 1, 131 /** 132 Mesh array contains normals. 133 */ 134 arrayFormatNormal = 2, 135 /** 136 Mesh array contains tangents. 137 */ 138 arrayFormatTangent = 4, 139 /** 140 Mesh array contains colors. 141 */ 142 arrayFormatColor = 8, 143 /** 144 Used internally to calculate other `ARRAY_COMPRESS_*` enum values. Do not use. 145 */ 146 arrayCompressBase = 9, 147 /** 148 Mesh array contains UVs. 149 */ 150 arrayFormatTexUv = 16, 151 /** 152 Mesh array contains second UV. 153 */ 154 arrayFormatTexUv2 = 32, 155 /** 156 Mesh array contains bones. 157 */ 158 arrayFormatBones = 64, 159 /** 160 Mesh array contains bone weights. 161 */ 162 arrayFormatWeights = 128, 163 /** 164 Mesh array uses indices. 165 */ 166 arrayFormatIndex = 256, 167 /** 168 Flag used to mark a compressed (half float) vertex array. 169 */ 170 arrayCompressVertex = 512, 171 /** 172 Flag used to mark a compressed (half float) normal array. 173 */ 174 arrayCompressNormal = 1024, 175 /** 176 Flag used to mark a compressed (half float) tangent array. 177 */ 178 arrayCompressTangent = 2048, 179 /** 180 Flag used to mark a compressed (half float) color array. 181 */ 182 arrayCompressColor = 4096, 183 /** 184 Flag used to mark a compressed (half float) UV coordinates array. 185 */ 186 arrayCompressTexUv = 8192, 187 /** 188 Flag used to mark a compressed (half float) UV coordinates array for the second UV coordinates. 189 */ 190 arrayCompressTexUv2 = 16384, 191 /** 192 Flag used to mark a compressed bone array. 193 */ 194 arrayCompressBones = 32768, 195 /** 196 Flag used to mark a compressed (half float) weight array. 197 */ 198 arrayCompressWeights = 65536, 199 /** 200 Used to set flags $(D constant ARRAY_COMPRESS_VERTEX), $(D constant ARRAY_COMPRESS_NORMAL), $(D constant ARRAY_COMPRESS_TANGENT), $(D constant ARRAY_COMPRESS_COLOR), $(D constant ARRAY_COMPRESS_TEX_UV), $(D constant ARRAY_COMPRESS_TEX_UV2) and $(D constant ARRAY_COMPRESS_WEIGHTS) quickly. 201 */ 202 arrayCompressDefault = 97280, 203 /** 204 Flag used to mark a compressed index array. 205 */ 206 arrayCompressIndex = 131072, 207 /** 208 Flag used to mark that the array contains 2D vertices. 209 */ 210 arrayFlagUse2dVertices = 262144, 211 /** 212 Flag used to mark that the array uses 16-bit bones instead of 8-bit. 213 */ 214 arrayFlagUse16BitBones = 524288, 215 } 216 /// 217 enum ArrayType : int 218 { 219 /** 220 Array of vertices. 221 */ 222 arrayVertex = 0, 223 /** 224 Array of normals. 225 */ 226 arrayNormal = 1, 227 /** 228 Array of tangents as an array of floats, 4 floats per tangent. 229 */ 230 arrayTangent = 2, 231 /** 232 Array of colors. 233 */ 234 arrayColor = 3, 235 /** 236 Array of UV coordinates. 237 */ 238 arrayTexUv = 4, 239 /** 240 Array of second set of UV coordinates. 241 */ 242 arrayTexUv2 = 5, 243 /** 244 Array of bone data. 245 */ 246 arrayBones = 6, 247 /** 248 Array of weights. 249 */ 250 arrayWeights = 7, 251 /** 252 Array of indices. 253 */ 254 arrayIndex = 8, 255 /** 256 Represents the size of the $(D arraytype) enum. 257 */ 258 arrayMax = 9, 259 } 260 /// 261 enum Constants : int 262 { 263 blendShapeModeNormalized = 0, 264 arrayVertex = 0, 265 primitivePoints = 0, 266 arrayFormatVertex = 1, 267 blendShapeModeRelative = 1, 268 primitiveLines = 1, 269 arrayNormal = 1, 270 arrayTangent = 2, 271 arrayFormatNormal = 2, 272 primitiveLineStrip = 2, 273 primitiveLineLoop = 3, 274 arrayColor = 3, 275 arrayTexUv = 4, 276 arrayFormatTangent = 4, 277 primitiveTriangles = 4, 278 arrayTexUv2 = 5, 279 primitiveTriangleStrip = 5, 280 primitiveTriangleFan = 6, 281 arrayBones = 6, 282 arrayWeights = 7, 283 arrayIndex = 8, 284 arrayFormatColor = 8, 285 arrayCompressBase = 9, 286 arrayMax = 9, 287 arrayFormatTexUv = 16, 288 arrayFormatTexUv2 = 32, 289 arrayFormatBones = 64, 290 arrayFormatWeights = 128, 291 arrayFormatIndex = 256, 292 arrayCompressVertex = 512, 293 arrayCompressNormal = 1024, 294 arrayCompressTangent = 2048, 295 arrayCompressColor = 4096, 296 arrayCompressTexUv = 8192, 297 arrayCompressTexUv2 = 16384, 298 arrayCompressBones = 32768, 299 arrayCompressWeights = 65536, 300 arrayCompressDefault = 97280, 301 arrayCompressIndex = 131072, 302 arrayFlagUse2dVertices = 262144, 303 arrayFlagUse16BitBones = 524288, 304 } 305 /** 306 Calculate a $(D ConvexPolygonShape) from the mesh. 307 */ 308 Ref!Shape createConvexShape() const 309 { 310 checkClassBinding!(typeof(this))(); 311 return ptrcall!(Shape)(GDNativeClassBinding.createConvexShape, _godot_object); 312 } 313 /** 314 Calculate an outline mesh at a defined offset (margin) from the original mesh. 315 $(B Note:) This method typically returns the vertices in reverse order (e.g. clockwise to counterclockwise). 316 */ 317 Ref!Mesh createOutline(in double margin) const 318 { 319 checkClassBinding!(typeof(this))(); 320 return ptrcall!(Mesh)(GDNativeClassBinding.createOutline, _godot_object, margin); 321 } 322 /** 323 Calculate a $(D ConcavePolygonShape) from the mesh. 324 */ 325 Ref!Shape createTrimeshShape() const 326 { 327 checkClassBinding!(typeof(this))(); 328 return ptrcall!(Shape)(GDNativeClassBinding.createTrimeshShape, _godot_object); 329 } 330 /** 331 Generate a $(D TriangleMesh) from the mesh. 332 */ 333 Ref!TriangleMesh generateTriangleMesh() const 334 { 335 checkClassBinding!(typeof(this))(); 336 return ptrcall!(TriangleMesh)(GDNativeClassBinding.generateTriangleMesh, _godot_object); 337 } 338 /** 339 Returns the smallest $(D AABB) enclosing this mesh in local space. Not affected by `custom_aabb`. See also $(D VisualInstance.getTransformedAabb). 340 $(B Note:) This is only implemented for $(D ArrayMesh) and $(D PrimitiveMesh). 341 */ 342 AABB getAabb() const 343 { 344 checkClassBinding!(typeof(this))(); 345 return ptrcall!(AABB)(GDNativeClassBinding.getAabb, _godot_object); 346 } 347 /** 348 Returns all the vertices that make up the faces of the mesh. Each three vertices represent one triangle. 349 */ 350 PoolVector3Array getFaces() const 351 { 352 checkClassBinding!(typeof(this))(); 353 return ptrcall!(PoolVector3Array)(GDNativeClassBinding.getFaces, _godot_object); 354 } 355 /** 356 357 */ 358 Vector2 getLightmapSizeHint() const 359 { 360 checkClassBinding!(typeof(this))(); 361 return ptrcall!(Vector2)(GDNativeClassBinding.getLightmapSizeHint, _godot_object); 362 } 363 /** 364 Returns the amount of surfaces that the $(D Mesh) holds. 365 */ 366 long getSurfaceCount() const 367 { 368 checkClassBinding!(typeof(this))(); 369 return ptrcall!(long)(GDNativeClassBinding.getSurfaceCount, _godot_object); 370 } 371 /** 372 373 */ 374 void setLightmapSizeHint(in Vector2 size) 375 { 376 checkClassBinding!(typeof(this))(); 377 ptrcall!(void)(GDNativeClassBinding.setLightmapSizeHint, _godot_object, size); 378 } 379 /** 380 Returns the arrays for the vertices, normals, uvs, etc. that make up the requested surface (see $(D ArrayMesh.addSurfaceFromArrays)). 381 */ 382 Array surfaceGetArrays(in long surf_idx) const 383 { 384 checkClassBinding!(typeof(this))(); 385 return ptrcall!(Array)(GDNativeClassBinding.surfaceGetArrays, _godot_object, surf_idx); 386 } 387 /** 388 Returns the blend shape arrays for the requested surface. 389 */ 390 Array surfaceGetBlendShapeArrays(in long surf_idx) const 391 { 392 checkClassBinding!(typeof(this))(); 393 return ptrcall!(Array)(GDNativeClassBinding.surfaceGetBlendShapeArrays, _godot_object, surf_idx); 394 } 395 /** 396 Returns a $(D Material) in a given surface. Surface is rendered using this material. 397 */ 398 Ref!Material surfaceGetMaterial(in long surf_idx) const 399 { 400 checkClassBinding!(typeof(this))(); 401 return ptrcall!(Material)(GDNativeClassBinding.surfaceGetMaterial, _godot_object, surf_idx); 402 } 403 /** 404 Sets a $(D Material) for a given surface. Surface will be rendered using this material. 405 */ 406 void surfaceSetMaterial(in long surf_idx, Material material) 407 { 408 checkClassBinding!(typeof(this))(); 409 ptrcall!(void)(GDNativeClassBinding.surfaceSetMaterial, _godot_object, surf_idx, material); 410 } 411 /** 412 Sets a hint to be used for lightmap resolution in $(D BakedLightmap). Overrides $(D BakedLightmap.defaultTexelsPerUnit). 413 */ 414 @property Vector2 lightmapSizeHint() 415 { 416 return getLightmapSizeHint(); 417 } 418 /// ditto 419 @property void lightmapSizeHint(Vector2 v) 420 { 421 setLightmapSizeHint(v); 422 } 423 }