Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

MeshInstance3D

继承: GeometryInstance3D < VisualInstance3D < Node3D < Node < Object

派生: SoftBody3D

网格实例与场景相结合的节点。

描述

MeshInstance3D 节点接受 Mesh 资源,会为该网格创建一个实例,将其添加到当前的场景中。这是渲染 3D 几何体时最常用的类,可以将单个 Mesh 在不同的地方实例化。这样就能够实现几何体的复用,节省资源。如果需要在比较集中的区域内将某个 Mesh 实例化超过几千次,请考虑改为在 MultiMeshInstance3D 中使用 MultiMesh

教程

属性

Mesh

mesh

NodePath

skeleton

NodePath("..")

Skin

skin

方法

void

create_convex_collision ( bool clean=true, bool simplify=false )

void

create_debug_tangents ( )

void

create_multiple_convex_collisions ( MeshConvexDecompositionSettings settings=null )

void

create_trimesh_collision ( )

int

find_blend_shape_by_name ( StringName name )

Material

get_active_material ( int surface ) const

int

get_blend_shape_count ( ) const

float

get_blend_shape_value ( int blend_shape_idx ) const

Material

get_surface_override_material ( int surface ) const

int

get_surface_override_material_count ( ) const

void

set_blend_shape_value ( int blend_shape_idx, float value )

void

set_surface_override_material ( int surface, Material material )


属性说明

Mesh mesh

  • void set_mesh ( Mesh value )

  • Mesh get_mesh ( )

该实例的 Mesh 资源。


NodePath skeleton = NodePath("..")

到与此实例关联的 Skeleton3DNodePath


Skin skin

  • void set_skin ( Skin value )

  • Skin get_skin ( )

该实例要使用的 Skin


方法说明

void create_convex_collision ( bool clean=true, bool simplify=false )

该助手创建一个 StaticBody3D 子节点,该子节点具有根据网格几何计算的 ConvexPolygonShape3D 碰撞形状。它主要用于测试。

如果 cleantrue(默认值),则重复的顶点和内部顶点会被自动移除。如果不需要,可以将其设置为 false,以加快处理速度。

如果 simplifytrue,则该几何体可以进一步被简化以减少顶点的数量。默认情况下是禁用的。


void create_debug_tangents ( )

创建 MeshInstance3D 子节点的辅助函数,会根据网格几何体计算出各个顶点的小工具。主要用于测试。


void create_multiple_convex_collisions ( MeshConvexDecompositionSettings settings=null )

创建 StaticBody3D 子节点的辅助函数,会根据网格几何体使用凸分解计算出多个 ConvexPolygonShape3D 碰撞形状。凸分解操作可以通过可选的 settings 参数控制。


void create_trimesh_collision ( )

该助手创建一个 StaticBody3D 子节点,该子节点具有一个 ConcavePolygonShape3D 碰撞形状,该形状是根据网格几何体计算出来的。它主要用于测试。


int find_blend_shape_by_name ( StringName name )

返回具有给定 name 的混合形状的索引。如果不存在具有该名称的混合形状,以及当 meshnull 时,则返回 -1


Material get_active_material ( int surface ) const

返回 Mesh 在绘制时将使用的 Material。这可以返回 GeometryInstance3D.material_override、在该 MeshInstance3D 中定义的表面覆盖 Material、或 mesh 中定义的表面 Material。例如,如果使用 GeometryInstance3D.material_override,则所有表面都将返回该覆盖材质。

如果没有材质处于活动状态,包括当 meshnull 时,则返回 null


int get_blend_shape_count ( ) const

返回可用混合形状的数量。如果 meshnull 则会报错。


float get_blend_shape_value ( int blend_shape_idx ) const

返回给定 blend_shape_idx 处的混合形状的值。如果 meshnull,或在该索引处没有混合形状,则返回 0.0 并产生一个错误。


Material get_surface_override_material ( int surface ) const

返回 Mesh 资源的指定 surface 的覆盖 Material。另见 get_surface_override_material_count

注意:这将返回与 MeshInstance3D 的表面材质覆盖属性关联的 Material,而不是 Mesh 资源内的材质。要获取 Mesh 资源中的材质,请改用 Mesh.surface_get_material


int get_surface_override_material_count ( ) const

返回表面覆盖材质的数量。相当于 Mesh.get_surface_count。另见 get_surface_override_material


void set_blend_shape_value ( int blend_shape_idx, float value )

blend_shape_idx 处的混合形状的值设置为 value。如果 meshnull,或在该索引处没有混合形状,则会产生一个错误。


void set_surface_override_material ( int surface, Material material )

设置 Mesh 资源的指定 surface 的覆盖 material。该材质与该 MeshInstance3D 关联,而不是与 mesh 关联。

注意:这将分配与 MeshInstance3D 的表面材质覆盖属性关联的 Material,而不是 Mesh 资源内的材质。要在 Mesh 资源中设置材质,请改用 Mesh.surface_get_material