1 /** 2 Node that instances meshes into a scenario. 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.meshinstance; 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.material; 27 import godot.mesh; 28 import godot.skin; 29 /** 30 Node that instances meshes into a scenario. 31 32 MeshInstance is a node that takes a $(D Mesh) resource and adds it to the current scenario by creating an instance of it. This is the class most often used to get 3D geometry rendered and can be used to instance a single $(D Mesh) in many places. This allows to reuse geometry and save on resources. When a $(D Mesh) has to be instanced more than thousands of times at close proximity, consider using a $(D MultiMesh) in a $(D MultiMeshInstance) instead. 33 */ 34 @GodotBaseClass struct MeshInstance 35 { 36 package(godot) enum string _GODOT_internal_name = "MeshInstance"; 37 public: 38 @nogc nothrow: 39 union { /** */ godot_object _godot_object; /** */ GeometryInstance _GODOT_base; } 40 alias _GODOT_base this; 41 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 42 package(godot) __gshared bool _classBindingInitialized = false; 43 package(godot) static struct GDNativeClassBinding 44 { 45 __gshared: 46 @GodotName("_mesh_changed") GodotMethod!(void) _meshChanged; 47 @GodotName("_update_skinning") GodotMethod!(void) _updateSkinning; 48 @GodotName("create_convex_collision") GodotMethod!(void) createConvexCollision; 49 @GodotName("create_debug_tangents") GodotMethod!(void) createDebugTangents; 50 @GodotName("create_trimesh_collision") GodotMethod!(void) createTrimeshCollision; 51 @GodotName("get_active_material") GodotMethod!(Material, long) getActiveMaterial; 52 @GodotName("get_mesh") GodotMethod!(Mesh) getMesh; 53 @GodotName("get_skeleton_path") GodotMethod!(NodePath) getSkeletonPath; 54 @GodotName("get_skin") GodotMethod!(Skin) getSkin; 55 @GodotName("get_surface_material") GodotMethod!(Material, long) getSurfaceMaterial; 56 @GodotName("get_surface_material_count") GodotMethod!(long) getSurfaceMaterialCount; 57 @GodotName("is_software_skinning_transform_normals_enabled") GodotMethod!(bool) isSoftwareSkinningTransformNormalsEnabled; 58 @GodotName("set_mesh") GodotMethod!(void, Mesh) setMesh; 59 @GodotName("set_skeleton_path") GodotMethod!(void, NodePath) setSkeletonPath; 60 @GodotName("set_skin") GodotMethod!(void, Skin) setSkin; 61 @GodotName("set_software_skinning_transform_normals") GodotMethod!(void, bool) setSoftwareSkinningTransformNormals; 62 @GodotName("set_surface_material") GodotMethod!(void, long, Material) setSurfaceMaterial; 63 } 64 /// 65 pragma(inline, true) bool opEquals(in MeshInstance other) const 66 { return _godot_object.ptr is other._godot_object.ptr; } 67 /// 68 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 69 { _godot_object.ptr = n; return null; } 70 /// 71 pragma(inline, true) bool opEquals(typeof(null) n) const 72 { return _godot_object.ptr is n; } 73 /// 74 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 75 mixin baseCasts; 76 /// Construct a new instance of MeshInstance. 77 /// Note: use `memnew!MeshInstance` instead. 78 static MeshInstance _new() 79 { 80 static godot_class_constructor constructor; 81 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("MeshInstance"); 82 if(constructor is null) return typeof(this).init; 83 return cast(MeshInstance)(constructor()); 84 } 85 @disable new(size_t s); 86 /** 87 88 */ 89 void _meshChanged() 90 { 91 Array _GODOT_args = Array.make(); 92 String _GODOT_method_name = String("_mesh_changed"); 93 this.callv(_GODOT_method_name, _GODOT_args); 94 } 95 /** 96 97 */ 98 void _updateSkinning() 99 { 100 Array _GODOT_args = Array.make(); 101 String _GODOT_method_name = String("_update_skinning"); 102 this.callv(_GODOT_method_name, _GODOT_args); 103 } 104 /** 105 This helper creates a $(D StaticBody) child node with a $(D ConvexPolygonShape) collision shape calculated from the mesh geometry. It's mainly used for testing. 106 */ 107 void createConvexCollision() 108 { 109 checkClassBinding!(typeof(this))(); 110 ptrcall!(void)(GDNativeClassBinding.createConvexCollision, _godot_object); 111 } 112 /** 113 This helper creates a $(D MeshInstance) child node with gizmos at every vertex calculated from the mesh geometry. It's mainly used for testing. 114 */ 115 void createDebugTangents() 116 { 117 checkClassBinding!(typeof(this))(); 118 ptrcall!(void)(GDNativeClassBinding.createDebugTangents, _godot_object); 119 } 120 /** 121 This helper creates a $(D StaticBody) child node with a $(D ConcavePolygonShape) collision shape calculated from the mesh geometry. It's mainly used for testing. 122 */ 123 void createTrimeshCollision() 124 { 125 checkClassBinding!(typeof(this))(); 126 ptrcall!(void)(GDNativeClassBinding.createTrimeshCollision, _godot_object); 127 } 128 /** 129 Returns the $(D Material) that will be used by the $(D Mesh) when drawing. This can return the $(D GeometryInstance.materialOverride), the surface override $(D Material) defined in this $(D MeshInstance), or the surface $(D Material) defined in the $(D Mesh). For example, if $(D GeometryInstance.materialOverride) is used, all surfaces will return the override material. 130 */ 131 Ref!Material getActiveMaterial(in long surface) const 132 { 133 checkClassBinding!(typeof(this))(); 134 return ptrcall!(Material)(GDNativeClassBinding.getActiveMaterial, _godot_object, surface); 135 } 136 /** 137 138 */ 139 Ref!Mesh getMesh() const 140 { 141 checkClassBinding!(typeof(this))(); 142 return ptrcall!(Mesh)(GDNativeClassBinding.getMesh, _godot_object); 143 } 144 /** 145 146 */ 147 NodePath getSkeletonPath() 148 { 149 checkClassBinding!(typeof(this))(); 150 return ptrcall!(NodePath)(GDNativeClassBinding.getSkeletonPath, _godot_object); 151 } 152 /** 153 154 */ 155 Ref!Skin getSkin() const 156 { 157 checkClassBinding!(typeof(this))(); 158 return ptrcall!(Skin)(GDNativeClassBinding.getSkin, _godot_object); 159 } 160 /** 161 Returns the $(D Material) for a surface of the $(D Mesh) resource. 162 */ 163 Ref!Material getSurfaceMaterial(in long surface) const 164 { 165 checkClassBinding!(typeof(this))(); 166 return ptrcall!(Material)(GDNativeClassBinding.getSurfaceMaterial, _godot_object, surface); 167 } 168 /** 169 Returns the number of surface materials. 170 */ 171 long getSurfaceMaterialCount() const 172 { 173 checkClassBinding!(typeof(this))(); 174 return ptrcall!(long)(GDNativeClassBinding.getSurfaceMaterialCount, _godot_object); 175 } 176 /** 177 178 */ 179 bool isSoftwareSkinningTransformNormalsEnabled() const 180 { 181 checkClassBinding!(typeof(this))(); 182 return ptrcall!(bool)(GDNativeClassBinding.isSoftwareSkinningTransformNormalsEnabled, _godot_object); 183 } 184 /** 185 186 */ 187 void setMesh(Mesh mesh) 188 { 189 checkClassBinding!(typeof(this))(); 190 ptrcall!(void)(GDNativeClassBinding.setMesh, _godot_object, mesh); 191 } 192 /** 193 194 */ 195 void setSkeletonPath(NodePathArg0)(in NodePathArg0 skeleton_path) 196 { 197 checkClassBinding!(typeof(this))(); 198 ptrcall!(void)(GDNativeClassBinding.setSkeletonPath, _godot_object, skeleton_path); 199 } 200 /** 201 202 */ 203 void setSkin(Skin skin) 204 { 205 checkClassBinding!(typeof(this))(); 206 ptrcall!(void)(GDNativeClassBinding.setSkin, _godot_object, skin); 207 } 208 /** 209 210 */ 211 void setSoftwareSkinningTransformNormals(in bool enabled) 212 { 213 checkClassBinding!(typeof(this))(); 214 ptrcall!(void)(GDNativeClassBinding.setSoftwareSkinningTransformNormals, _godot_object, enabled); 215 } 216 /** 217 Sets the $(D Material) for a surface of the $(D Mesh) resource. 218 */ 219 void setSurfaceMaterial(in long surface, Material material) 220 { 221 checkClassBinding!(typeof(this))(); 222 ptrcall!(void)(GDNativeClassBinding.setSurfaceMaterial, _godot_object, surface, material); 223 } 224 /** 225 The $(D Mesh) resource for the instance. 226 */ 227 @property Mesh mesh() 228 { 229 return getMesh(); 230 } 231 /// ditto 232 @property void mesh(Mesh v) 233 { 234 setMesh(v); 235 } 236 /** 237 $(D NodePath) to the $(D Skeleton) associated with the instance. 238 */ 239 @property NodePath skeleton() 240 { 241 return getSkeletonPath(); 242 } 243 /// ditto 244 @property void skeleton(NodePath v) 245 { 246 setSkeletonPath(v); 247 } 248 /** 249 Sets the skin to be used by this instance. 250 */ 251 @property Skin skin() 252 { 253 return getSkin(); 254 } 255 /// ditto 256 @property void skin(Skin v) 257 { 258 setSkin(v); 259 } 260 /** 261 If `true`, normals are transformed when software skinning is used. Set to `false` when normals are not needed for better performance. 262 See $(D ProjectSettings.rendering/quality/skinning/softwareSkinningFallback) for details about how software skinning is enabled. 263 */ 264 @property bool softwareSkinningTransformNormals() 265 { 266 return isSoftwareSkinningTransformNormalsEnabled(); 267 } 268 /// ditto 269 @property void softwareSkinningTransformNormals(bool v) 270 { 271 setSoftwareSkinningTransformNormals(v); 272 } 273 }