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。
注意:該屬性的預設值在 Godot 4.6 中已更改。如果需要舊版行為以確保相容性,請啟用 ProjectSettings.animation/compatibility/default_parent_skeleton_in_mesh_instance_3d。
該實例要使用的 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()。