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...
ImporterMesh
继承: Resource < RefCounted < Object
在导入过程中,包含基于顶点数组的几何体的 Resource。
描述
ImporterMesh 是一种 Resource(资源),类似于 ArrayMesh。它包含基于顶点数组的几何体,并被划分为若干个 表面(surfaces)。每个表面都包含一个完全独立的数组,以及一个用于绘制它的材质。从设计角度来看,拥有多个表面的网格优于单个表面的网格,因为在 3D 编辑软件中创建的对象通常包含多种材质。
与其运行时对应的 ArrayMesh 不同,ImporterMesh 包含的是在经历各种导入步骤(例如 LOD 和阴影网格生成)之前的原始网格数据。若要修改表面数据,可以调用 clear(),然后为每个表面调用 add_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() |
void |
generate_lods(normal_merge_angle: float, normal_split_angle: float, bone_transform_array: Array) |
get_blend_shape_count() const |
|
get_blend_shape_mode() const |
|
get_blend_shape_name(blend_shape_idx: int) const |
|
get_lightmap_size_hint() const |
|
get_surface_arrays(surface_idx: int) const |
|
get_surface_blend_shape_arrays(surface_idx: int, blend_shape_idx: int) const |
|
get_surface_count() const |
|
get_surface_format(surface_idx: int) const |
|
get_surface_lod_count(surface_idx: int) const |
|
get_surface_lod_indices(surface_idx: int, lod_idx: int) const |
|
get_surface_lod_size(surface_idx: int, lod_idx: int) const |
|
get_surface_material(surface_idx: int) const |
|
get_surface_name(surface_idx: int) const |
|
get_surface_primitive_type(surface_idx: int) |
|
merge_importer_meshes(importer_meshes: Array[ImporterMesh], relative_transforms: Array[Transform3D], deduplicate_surfaces: bool = true) static |
|
void |
|
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 具有相同结构的数组,但是 Mesh.ARRAY_VERTEX、Mesh.ARRAY_NORMAL 和 Mesh.ARRAY_TANGENT 这些条目,当且仅当在 arrays 被设置且所有其他条目都是 null 时,会被设置。
lods 参数是一个带有 float 键和 PackedInt32Array 值的字典。字典中的每个条目代表了表面的一个 LOD 级别,其中值是用于 LOD 级别的 Mesh.ARRAY_INDEX 数组,键大致与使用 LOD 统计信息的距离成正比。即,增加 LOD 的关键点也会增加在使用 LOD 之前对象必须与相机的距离。
flags 参数是根据需要按位或的:ArrayCustomFormat 的一个值左移 ARRAY_FORMAT_CUSTOMn_SHIFT,用于每个正在使用的自定义通道,Mesh.ARRAY_FLAG_USE_DYNAMIC_UPDATE、Mesh.ARRAY_FLAG_USE_8_BONE_WEIGHTS 或 Mesh.ARRAY_FLAG_USES_EMPTY_VERTEX_ARRAY。
注意:使用索引时,建议只使用点、线或三角形。
void clear() 🔗
从该 ImporterMesh 中,移除所有表面和混合形状。
ImporterMesh from_mesh(mesh: Mesh) static 🔗
通过将给定 Mesh 的所有表面、混合形状、材质和元数据复制到一个新的 ImporterMesh 对象中,将其转换为 ImporterMesh 对象。
void generate_lods(normal_merge_angle: float, normal_split_angle: float, bone_transform_array: Array) 🔗
为这个 ImporterMesh 生成所有 LOD。
normal_merge_angle 和 normal_split_angle 以度为单位,用法与 lods 的导入器设置相同。
normal_split_angle 未使用,仅为兼容旧版本 API 而保留。
生成的 LOD 的数量可以使用 get_surface_lod_count() 访问,每个 LOD 在 get_surface_lod_size() 和 get_surface_lod_indices() 中可用。
bone_transform_array 是一个 Array,可以是空的,也可以包含 Transform3D,每个网格的骨骼 ID 在生成 LOD 网格变化时将应用网格蒙皮。这通常用于解释网格本身与其蒙皮数据之间的缩放差异。
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 🔗
返回构成请求表面的顶点、法线、UV 等的数组。参见 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 🔗
将多个 ImporterMesh 合并为单个 ImporterMesh。每个输入网格将由 relative_transforms 数组中对应的 Transform3D 进行变换,该数组的大小必须与 importer_meshes 相同。支持负缩放,并且网格数据中的缠绕顺序将被修正以适应此情况。
如果 deduplicate_surfaces 为 true 且多个网格具有同名且格式相同的表面,则在合并网格时这些表面将被合并在一起,并使用第一个匹配表面的材质。这有助于减少生成网格中的表面数量,并避免材质重复。包含骨骼权重的表面将永远不会被去重。如果 deduplicate_surfaces 为 false,表面将始终被保持分离,并被赋予唯一的名称。
警告: 混合形状(Blend shapes)和细节层次(LODs)不受支持,将会被丢弃。请勿使用此函数来丢弃混合形状和 LOD,因为未来可能会增加对它们的支持。
void set_blend_shape_mode(mode: BlendShapeMode) 🔗
设置混合形状模式。
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) 🔗
设置给定曲面的名称。