Class MeshInstance3D
- Namespace
- Godot
- Assembly
- GodotSharp.dll
MeshInstance3D is a node that takes a Mesh resource and adds it to the current scenario by creating an instance of it. This is the class most often used render 3D geometry and can be used to instance a single Mesh in many places. This allows reusing geometry, which can save on resources. When a Mesh has to be instantiated more than thousands of times at close proximity, consider using a MultiMesh in a MultiMeshInstance3D instead.
public class MeshInstance3D : GeometryInstance3D, IDisposable
- Inheritance
-
MeshInstance3D
- Implements
- Derived
- Inherited Members
Constructors
MeshInstance3D()
public MeshInstance3D()
Properties
Mesh
The Mesh resource for the instance.
public Mesh Mesh { get; set; }
Property Value
Skeleton
NodePath to the Skeleton3D associated with the instance.
public NodePath Skeleton { get; set; }
Property Value
Skin
The Skin to be used by this instance.
public Skin Skin { get; set; }
Property Value
Methods
CreateConvexCollision(bool, bool)
This helper creates a StaticBody3D child node with a ConvexPolygonShape3D collision shape calculated from the mesh geometry. It's mainly used for testing.
If clean
is true
(default), duplicate and interior vertices are removed automatically. You can set it to false
to make the process faster if not needed.
If simplify
is true
, the geometry can be further simplified to reduce the number of vertices. Disabled by default.
public void CreateConvexCollision(bool clean = true, bool simplify = false)
Parameters
CreateDebugTangents()
This helper creates a MeshInstance3D child node with gizmos at every vertex calculated from the mesh geometry. It's mainly used for testing.
public void CreateDebugTangents()
CreateMultipleConvexCollisions(MeshConvexDecompositionSettings)
This helper creates a StaticBody3D child node with multiple ConvexPolygonShape3D collision shapes calculated from the mesh geometry via convex decomposition. The convex decomposition operation can be controlled with parameters from the optional settings
.
public void CreateMultipleConvexCollisions(MeshConvexDecompositionSettings settings = null)
Parameters
settings
MeshConvexDecompositionSettings
CreateTrimeshCollision()
This helper creates a StaticBody3D child node with a ConcavePolygonShape3D collision shape calculated from the mesh geometry. It's mainly used for testing.
public void CreateTrimeshCollision()
FindBlendShapeByName(StringName)
Returns the index of the blend shape with the given name
. Returns -1
if no blend shape with this name exists, including when Mesh is null
.
public int FindBlendShapeByName(StringName name)
Parameters
name
StringName
Returns
GetActiveMaterial(int)
Returns the Material that will be used by the Mesh when drawing. This can return the MaterialOverride, the surface override Material defined in this MeshInstance3D, or the surface Material defined in the Mesh. For example, if MaterialOverride is used, all surfaces will return the override material.
Returns null
if no material is active, including when Mesh is null
.
public Material GetActiveMaterial(int surface)
Parameters
surface
int
Returns
GetBlendShapeCount()
Returns the number of blend shapes available. Produces an error if Mesh is null
.
public int GetBlendShapeCount()
Returns
GetBlendShapeValue(int)
Returns the value of the blend shape at the given blendShapeIdx
. Returns 0.0
and produces an error if Mesh is null
or doesn't have a blend shape at that index.
public float GetBlendShapeValue(int blendShapeIdx)
Parameters
blendShapeIdx
int
Returns
GetSurfaceOverrideMaterial(int)
Returns the override Material for the specified surface
of the Mesh resource. See also GetSurfaceOverrideMaterialCount().
Note: This returns the Material associated to the MeshInstance3D's Surface Material Override properties, not the material within the Mesh resource. To get the material within the Mesh resource, use SurfaceGetMaterial(int) instead.
public Material GetSurfaceOverrideMaterial(int surface)
Parameters
surface
int
Returns
GetSurfaceOverrideMaterialCount()
Returns the number of surface override materials. This is equivalent to GetSurfaceCount(). See also GetSurfaceOverrideMaterial(int).
public int GetSurfaceOverrideMaterialCount()
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
SetBlendShapeValue(int, float)
Sets the value of the blend shape at blendShapeIdx
to value
. Produces an error if Mesh is null
or doesn't have a blend shape at that index.
public void SetBlendShapeValue(int blendShapeIdx, float value)
Parameters
SetSurfaceOverrideMaterial(int, Material)
Sets the override material
for the specified surface
of the Mesh resource. This material is associated with this MeshInstance3D rather than with Mesh.
Note: This assigns the Material associated to the MeshInstance3D's Surface Material Override properties, not the material within the Mesh resource. To set the material within the Mesh resource, use SurfaceGetMaterial(int) instead.
public void SetSurfaceOverrideMaterial(int surface, Material material)