Index · Object → RefCounted → Resource → ImporterMesh

ImporterMesh

A Resource that contains vertex array-based geometry during the import process.

Class Description

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.

Properties

Inherited from Resource (4)

Methods

func add_blend_shape(name: String) -> void

Adds name for a blend shape that will be added with add_surface(). Must be called before surface is added.

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

Creates a new surface. Mesh.get_surface_count() will become the surf_idx for this new surface.

Surfaces are created to be rendered using a primitive, which may be any of the values defined in Mesh.PrimitiveType.

The arrays argument is an array of arrays. Each of the Mesh.ARRAY_MAX elements contains an array with some of the mesh data for this surface as described by the corresponding member of Mesh.ArrayType or null if it is not used by the surface. For example, arrays[0] is the array of vertices. That first vertex sub-array is always required; the others are optional. Adding an index array puts this surface into "index mode" where the vertex and other arrays become the sources of data and the index array defines the vertex order. All sub-arrays must have the same length as the vertex array (or be an exact multiple of the vertex array's length, when multiple elements of a sub-array correspond to a single vertex) or be empty, except for Mesh.ARRAY_INDEX if it is used.

The blend_shapes argument is an array of vertex data for each blend shape. Each element is an array of the same structure as arrays, but Mesh.ARRAY_VERTEX, Mesh.ARRAY_NORMAL, and Mesh.ARRAY_TANGENT are set if and only if they are set in arrays and all other entries are null.

The lods argument is a dictionary with float keys and PackedInt32Array values. Each entry in the dictionary represents an LOD level of the surface, where the value is the Mesh.ARRAY_INDEX array to use for the LOD level and the key is roughly proportional to the distance at which the LOD stats being used. I.e., increasing the key of an LOD also increases the distance that the objects has to be from the camera before the LOD is used.

The flags argument is the bitwise OR of, as required: One value of Mesh.ArrayCustomFormat left shifted by ARRAY_FORMAT_CUSTOMn_SHIFT for each custom channel in use, Mesh.ARRAY_FLAG_USE_DYNAMIC_UPDATE, Mesh.ARRAY_FLAG_USE_8_BONE_WEIGHTS, or Mesh.ARRAY_FLAG_USES_EMPTY_VERTEX_ARRAY.

Note: When using indices, it is recommended to only use points, lines, or triangles.

func clear() -> void

Removes all surfaces and blend shapes from this ImporterMesh.

func from_mesh(mesh: Mesh) -> ImporterMesh

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

func generate_lods(normal_merge_angle: float, normal_split_angle: float, bone_transform_array: Array) -> void

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.

func get_blend_shape_count() -> int

Returns the number of blend shapes that the mesh holds.

func get_blend_shape_mode() -> Mesh.BlendShapeMode

Returns the blend shape mode for this Mesh.

func get_blend_shape_name(blend_shape_idx: int) -> String

Returns the name of the blend shape at this index.

func get_lightmap_size_hint() -> Vector2i

Returns the size hint of this mesh for lightmap-unwrapping in UV-space.

func get_mesh(base_mesh: ArrayMesh = null) -> ArrayMesh

Returns the mesh data represented by this ImporterMesh as a usable ArrayMesh.

This method caches the returned mesh, and subsequent calls will return the cached data until clear() is called.

If not yet cached and base_mesh is provided, base_mesh will be used and mutated.

func get_surface_arrays(surface_idx: int) -> Array

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

func get_surface_blend_shape_arrays(surface_idx: int, blend_shape_idx: int) -> Array

Returns a single set of blend shape arrays for the requested blend shape index for a surface.

func get_surface_count() -> int

Returns the number of surfaces that the mesh holds.

func get_surface_format(surface_idx: int) -> int

Returns the format of the surface that the mesh holds.

func get_surface_lod_count(surface_idx: int) -> int

Returns the number of lods that the mesh holds on a given surface.

func get_surface_lod_indices(surface_idx: int, lod_idx: int) -> PackedInt32Array

Returns the index buffer of a lod for a surface.

func get_surface_lod_size(surface_idx: int, lod_idx: int) -> float

Returns the screen ratio which activates a lod for a surface.

func get_surface_material(surface_idx: int) -> Material

Returns a Material in a given surface. Surface is rendered using this material.

func get_surface_name(surface_idx: int) -> String

Gets the name assigned to this surface.

func get_surface_primitive_type(surface_idx: int) -> Mesh.PrimitiveType

Returns the primitive type of the requested surface (see add_surface()).

func merge_importer_meshes(importer_meshes: ImporterMesh[], relative_transforms: Transform3D[], deduplicate_surfaces: bool = true) -> ImporterMesh

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.

func set_blend_shape_mode(mode: Mesh.BlendShapeMode) -> void

Sets the blend shape mode.

func set_lightmap_size_hint(size: Vector2i) -> void

Sets the size hint of this mesh for lightmap-unwrapping in UV-space.

func set_surface_material(surface_idx: int, material: Material) -> void

Sets a Material for a given surface. Surface will be rendered using this material.

func set_surface_name(surface_idx: int, name: String) -> void

Sets a name for a given surface.

Inherited from Resource (18)
func _get_rid() -> RID
func _reset_state() -> void
func _set_path_cache(path: String) -> void
func _setup_local_to_scene() -> void
func copy_from_resource(resource: Resource) -> Error
func duplicate(deep: bool = false) -> Resource
func duplicate_deep(deep_subresources_mode: Resource.DeepDuplicateMode = 1) -> Resource
func emit_changed() -> void
func get_rid() -> RID
func is_built_in() -> bool
func reset_state() -> void
func set_id_for_path(path: String, id: String) -> void
func set_path_cache(path: String) -> void
func setup_local_to_scene() -> void
func take_over_path(path: String) -> void
Inherited from RefCounted (4)
func init_ref() -> bool
func reference() -> bool
func unreference() -> bool
Inherited from Object (62)
func _get(property: StringName) -> Variant
func _get_property_list() -> Dictionary[]
func _init() -> void
func _iter_get(iter: Variant) -> Variant
func _iter_init(iter: Array) -> bool
func _iter_next(iter: Array) -> bool
func _notification(what: int) -> void
func _set(property: StringName, value: Variant) -> bool
func _to_string() -> String
func _validate_property(property: Dictionary) -> void
func add_user_signal(signal: String, arguments: Array = []) -> void
func call(method: StringName) -> Variant
func callv(method: StringName, arg_array: Array) -> Variant
func cancel_free() -> void
func connect(signal: StringName, callable: Callable, flags: int = 0) -> Error
func disconnect(signal: StringName, callable: Callable) -> void
func emit_signal(signal: StringName) -> Error
func free() -> void
func get(property: StringName) -> Variant
func get_class() -> String
func get_incoming_connections() -> Dictionary[]
func get_indexed(property_path: NodePath) -> Variant
func get_meta(name: StringName, default: Variant = null) -> Variant
func get_meta_list() -> StringName[]
func get_method_list() -> Dictionary[]
func get_property_list() -> Dictionary[]
func get_signal_connection_list(signal: StringName) -> Dictionary[]
func get_signal_list() -> Dictionary[]
func has_meta(name: StringName) -> bool
func has_method(method: StringName) -> bool
func has_signal(signal: StringName) -> bool
func is_class(class: StringName) -> bool
func is_connected(signal: StringName, callable: Callable) -> bool
func notification(what: int, reversed: bool = false) -> void
func remove_meta(name: StringName) -> void
func remove_user_signal(signal: StringName) -> void
func set(property: StringName, value: Variant) -> void
func set_block_signals(enable: bool) -> void
func set_deferred(property: StringName, value: Variant) -> void
func set_indexed(property_path: NodePath, value: Variant) -> void
func set_message_translation(enable: bool) -> void
func set_meta(name: StringName, value: Variant) -> void
func set_script(script: Variant) -> void
func set_translation_domain(domain: StringName) -> void
func to_string() -> String
func tr(message: StringName, context: StringName = &"") -> String
func tr_n(message: StringName, plural_message: StringName, n: int, context: StringName = &"") -> String

Signals

Inherited from Resource (2)
signal changed()
Inherited from Object (2)