Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
MeshInstance3D
继承: GeometryInstance3D < VisualInstance3D < Node3D < Node < Object
派生: SoftBody3D
网格实例与场景相结合的节点。
描述
MeshInstance3D 节点接受 Mesh 资源,会为该网格创建一个实例,将其添加到当前的场景中。这是渲染 3D 几何体时最常用的类,可以将单个 Mesh 在不同的地方实例化。这样就能够实现几何体的复用,节省资源。如果需要在比较集中的区域内将某个 Mesh 实例化超过几千次,请考虑改为在 MultiMeshInstance3D 中使用 MultiMesh。
教程
属性
|
||
方法
bake_mesh_from_current_blend_shape_mix(existing: ArrayMesh = null) |
|
bake_mesh_from_current_skeleton_pose(existing: ArrayMesh = null) |
|
void |
create_convex_collision(clean: bool = true, simplify: bool = false) |
void |
|
void |
create_multiple_convex_collisions(settings: MeshConvexDecompositionSettings = null) |
void |
|
get_active_material(surface: int) const |
|
get_blend_shape_count() const |
|
get_blend_shape_value(blend_shape_idx: int) const |
|
get_skin_reference() const |
|
get_surface_override_material(surface: int) const |
|
void |
set_blend_shape_value(blend_shape_idx: int, value: float) |
void |
set_surface_override_material(surface: int, material: Material) |
属性说明
该实例的 Mesh 资源。
NodePath skeleton = NodePath("..")
🔗
到与此实例关联的 Skeleton3D 的 NodePath。
该实例要使用的 Skin。
方法说明
ArrayMesh bake_mesh_from_current_blend_shape_mix(existing: ArrayMesh = null) 🔗
根据当前权重从当前 ArrayMesh 中获取所有混合形状的快照,并将其烘焙到提供的 existing
网格中。如果未提供 existing
网格,则将创建一个新的 ArrayMesh,然后烘焙并返回。不会复制网格表面材质。
性能:需要从 GPU 接收 Mesh 数据,从而在该过程中拖延了 RenderingServer。
ArrayMesh bake_mesh_from_current_skeleton_pose(existing: ArrayMesh = null) 🔗
对蒙皮网格的当前动画骨架姿势进行快照,将其烘焙至已有的 existing
网格。如果未提供 existing
网格,则会新建一个 ArrayMesh 进行烘焙并返回。骨架需要注册皮肤才能正常工作。会忽略混合形状。不会复制网格表面材质。
性能:Mesh 数据需要从 GPU 获取,过程中会让 RenderingServer 产生停顿。
void create_convex_collision(clean: bool = true, simplify: bool = false) 🔗
该助手创建一个 StaticBody3D 子节点,该子节点具有根据网格几何计算的 ConvexPolygonShape3D 碰撞形状。它主要用于测试。
如果 clean
为 true
(默认值),则重复的顶点和内部顶点会被自动移除。如果不需要,可以将其设置为 false
,以加快处理速度。
如果 simplify
为 true
,则该几何体可以进一步被简化以减少顶点的数量。默认情况下是禁用的。
void create_debug_tangents() 🔗
创建 MeshInstance3D 子节点的辅助函数,会根据网格几何体计算出各个顶点的小工具。主要用于测试。
void create_multiple_convex_collisions(settings: MeshConvexDecompositionSettings = null) 🔗
创建 StaticBody3D 子节点的辅助函数,会根据网格几何体使用凸分解计算出多个 ConvexPolygonShape3D 碰撞形状。凸分解操作可以通过可选的 settings
参数控制。
void create_trimesh_collision() 🔗
该助手创建一个 StaticBody3D 子节点,该子节点具有一个 ConcavePolygonShape3D 碰撞形状,该形状是根据网格几何体计算出来的。它主要用于测试。
int find_blend_shape_by_name(name: StringName) 🔗
返回具有给定 name
的混合形状的索引。如果不存在具有该名称的混合形状,以及当 mesh 为 null
时,则返回 -1
。
Material get_active_material(surface: int) const 🔗
返回 Mesh 在绘制时将使用的 Material。这可以返回 GeometryInstance3D.material_override、在该 MeshInstance3D 中定义的表面覆盖 Material 或 mesh 中定义的表面 Material。例如,如果使用 GeometryInstance3D.material_override,则所有表面都将返回该覆盖材质。
如果没有材质处于活动状态,包括当 mesh 为 null
时,则返回 null
。
int get_blend_shape_count() const 🔗
返回可用混合形状的数量。如果 mesh 为 null
则会报错。
float get_blend_shape_value(blend_shape_idx: int) const 🔗
返回给定 blend_shape_idx
处的混合形状的值。如果 mesh 为 null
,或在该索引处没有混合形状,则返回 0.0
并产生一个错误。
SkinReference get_skin_reference() const 🔗
返回包含附加到该 RID 的骨架的 RID 的内部 SkinReference。另见 Resource.get_rid()、SkinReference.get_skeleton() 和 RenderingServer.instance_attach_skeleton()。
Material get_surface_override_material(surface: int) 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(blend_shape_idx: int, value: float) 🔗
将 blend_shape_idx
处的混合形状的值设置为 value
。如果 mesh 为 null
,或在该索引处没有混合形状,则会产生一个错误。
void set_surface_override_material(surface: int, material: Material) 🔗
设置 Mesh 资源的指定 surface
的覆盖 material
。该材质与该 MeshInstance3D 关联,而不是与 mesh 关联。
注意:这将分配与 MeshInstance3D 的表面材质覆盖属性关联的 Material,而不是 Mesh 资源内的材质。要在 Mesh 资源中设置材质,请改用 Mesh.surface_set_material()。