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.

ImporterMesh

繼承: Resource < RefCounted < Object

在匯入過程中,包含基於頂點陣列的幾何體的 Resource

說明

ImporterMesh is a type of Resource analogous to ArrayMesh. It contains vertex array-based geometry, divided in surfaces. Each surface contains a completely separate array and a material used to draw it. Design wise, a mesh with multiple surfaces is preferred to a single surface, because objects created in 3D editing software commonly contain multiple materials.

Unlike its runtime counterpart, ImporterMesh contains mesh data before various import steps, such as LOD and shadow mesh generation, have taken place. Modify surface data by calling clear(), followed by add_surface() for each surface.

方法

void

add_blend_shape(name: String)

void

add_surface(primitive: PrimitiveType, arrays: Array, blend_shapes: Array[Array] = [], lods: Dictionary = {}, material: Material = null, name: String = "", flags: int = 0)

void

clear()

ImporterMesh

from_mesh(mesh: Mesh) static

void

generate_lods(normal_merge_angle: float, normal_split_angle: float, bone_transform_array: Array)

int

get_blend_shape_count() const

BlendShapeMode

get_blend_shape_mode() const

String

get_blend_shape_name(blend_shape_idx: int) const

Vector2i

get_lightmap_size_hint() const

ArrayMesh

get_mesh(base_mesh: ArrayMesh = null)

Array

get_surface_arrays(surface_idx: int) const

Array

get_surface_blend_shape_arrays(surface_idx: int, blend_shape_idx: int) const

int

get_surface_count() const

int

get_surface_format(surface_idx: int) const

int

get_surface_lod_count(surface_idx: int) const

PackedInt32Array

get_surface_lod_indices(surface_idx: int, lod_idx: int) const

float

get_surface_lod_size(surface_idx: int, lod_idx: int) const

Material

get_surface_material(surface_idx: int) const

String

get_surface_name(surface_idx: int) const

PrimitiveType

get_surface_primitive_type(surface_idx: int)

ImporterMesh

merge_importer_meshes(importer_meshes: Array[ImporterMesh], relative_transforms: Array[Transform3D], deduplicate_surfaces: bool = true) static

void

set_blend_shape_mode(mode: BlendShapeMode)

void

set_lightmap_size_hint(size: Vector2i)

void

set_surface_material(surface_idx: int, material: Material)

void

set_surface_name(surface_idx: int, name: String)


方法說明

void add_blend_shape(name: String) 🔗

為將使用 add_surface() 新增的混合形狀新增名稱。必須在表面被新增之前調用。


void add_surface(primitive: PrimitiveType, arrays: Array, blend_shapes: Array[Array] = [], lods: Dictionary = {}, material: Material = null, name: String = "", flags: int = 0) 🔗

建立新的曲面。Mesh.get_surface_count() 的返回值將成為此曲面的 surf_idx

曲面會以 primitive 指定的圖元型別進行繪製,可為 PrimitiveType 中的任一值。

arrays 是「陣列的陣列」。在 Mesh.ARRAY_MAX 個元素中,每個元素要嘛包含由 ArrayType 相對應成員所描述的曲面資料,要嘛為未使用時的 null。例如,arrays[0] 為頂點陣列;此子陣列為必填,其餘則為可選。若加上索引陣列,即會進入「索引模式」,此時頂點與其他陣列成為資料來源,而索引陣列決定頂點次序。除非使用 Mesh.ARRAY_INDEX,否則所有子陣列長度必須等於頂點陣列長度(或為其整數倍,當一個頂點對應多個子陣列元素時),或保持空陣列。

blend_shapes 是每個混合形狀的頂點資料陣列。其結構與 arrays 相同,但僅當 arrays 內有設定 Mesh.ARRAY_VERTEXMesh.ARRAY_NORMALMesh.ARRAY_TANGENT 時,對應項目才會被設定;其餘皆為 null

lods 為字典,鍵值為 float、內容為 PackedInt32Array。每一項代表此曲面的一級 LOD,其中值為該 LOD 使用的 Mesh.ARRAY_INDEX 陣列,鍵值大致對應開始啟用該 LOD 的距離;鍵越大,啟用距離亦越遠。

flags 為多個旗標的位元 OR:對於每個使用中的自訂通道,將 ArrayCustomFormat 的值左移 ARRAY_FORMAT_CUSTOMn_SHIFT;亦可加入 Mesh.ARRAY_FLAG_USE_DYNAMIC_UPDATEMesh.ARRAY_FLAG_USE_8_BONE_WEIGHTSMesh.ARRAY_FLAG_USES_EMPTY_VERTEX_ARRAY

注意:使用索引時建議僅使用點、線或三角形圖元。


void clear() 🔗

從該 ImporterMesh 中,移除所有表面和混合形狀。


ImporterMesh from_mesh(mesh: Mesh) static 🔗

Converts the given Mesh into an ImporterMesh by copying all its surfaces, blend shapes, materials, and metadata into a new ImporterMesh object.


void generate_lods(normal_merge_angle: float, normal_split_angle: float, bone_transform_array: Array) 🔗

Generates all lods for this ImporterMesh.

normal_merge_angle is in degrees and used in the same way as the importer settings in lods.

normal_split_angle is not used and only remains for compatibility with older versions of the API.

The number of generated lods can be accessed using get_surface_lod_count(), and each LOD is available in get_surface_lod_size() and get_surface_lod_indices().

bone_transform_array is an Array which can be either empty or contain Transform3Ds which, for each of the mesh's bone IDs, will apply mesh skinning when generating the LOD mesh variations. This is usually used to account for discrepancies in scale between the mesh itself and its skinning data.


int get_blend_shape_count() const 🔗

返回該網格包含的混合形狀的數量。


BlendShapeMode get_blend_shape_mode() const 🔗

返回該網格的混合形狀模式。


String get_blend_shape_name(blend_shape_idx: int) const 🔗

回傳此索引處混合形狀的名稱。


Vector2i get_lightmap_size_hint() const 🔗

返回該網格的大小提示,用於在 UV 空間中展開光照貼圖。


ArrayMesh get_mesh(base_mesh: ArrayMesh = null) 🔗

將該 ImporterMesh 表示的網格資料作為一個可用的 ArrayMesh 返回。

這個方法快取了返回的網格,後續的呼叫將返回快取的資料,直到 clear() 被呼叫。

如果還沒有快取並且提供了 base_mesh,則 base_mesh 將被使用並被改變。


Array get_surface_arrays(surface_idx: int) const 🔗

Returns the arrays for the vertices, normals, UVs, etc. that make up the requested surface. See add_surface().


Array get_surface_blend_shape_arrays(surface_idx: int, blend_shape_idx: int) const 🔗

為一個表面請求的混合形狀索引,返回一組混合形狀陣列。


int get_surface_count() const 🔗

返回該網格擁有的表面數。


int get_surface_format(surface_idx: int) const 🔗

返回該網格擁有的表面的格式。


int get_surface_lod_count(surface_idx: int) const 🔗

返回該網格在給定表面上保留的 lod 數。


PackedInt32Array get_surface_lod_indices(surface_idx: int, lod_idx: int) const 🔗

返回表面的 lod 的索引緩衝區。


float get_surface_lod_size(surface_idx: int, lod_idx: int) const 🔗

返回為一個表面啟動 lod 的螢幕比率。


Material get_surface_material(surface_idx: int) const 🔗

返回給定面的 Material 材質。面將由該材質來算繪。


String get_surface_name(surface_idx: int) const 🔗

取得此曲面設定的名稱。


PrimitiveType get_surface_primitive_type(surface_idx: int) 🔗

返回所請求表面的基元型別(參見 add_surface())。


ImporterMesh merge_importer_meshes(importer_meshes: Array[ImporterMesh], relative_transforms: Array[Transform3D], deduplicate_surfaces: bool = true) static 🔗

Merges multiple ImporterMeshes into a single ImporterMesh. Each input mesh is transformed by the corresponding Transform3D in the relative_transforms array, which must be the same size as importer_meshes. Negative scales are supported, and the winding order in the mesh data will be corrected to account for this.

If deduplicate_surfaces is true and multiple meshes have surfaces with the same names and formats, the surfaces will be merged together when the meshes are merged, and will use the material from the first matching surface. This is useful for reducing the number of surfaces in the resulting mesh, and avoids duplicating materials. Surfaces with bone weights will never be deduplicated. If deduplicate_surfaces is false, the surfaces will always be kept separate, and will be given unique names.

Warning: Blend shapes and LODs are not supported and will be discarded. Do not use this function to discard blend shapes and LODs, as support for these may be added in the future.


void set_blend_shape_mode(mode: BlendShapeMode) 🔗

Sets the blend shape mode.


void set_lightmap_size_hint(size: Vector2i) 🔗

設定該網格的大小提示,以便在 UV 空間中展開光照貼圖。


void set_surface_material(surface_idx: int, material: Material) 🔗

設定給定面的 Material 材質。該面將會使用此材質算繪。


void set_surface_name(surface_idx: int, name: String) 🔗

為指定曲面設定名稱。