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.

ArrayMesh

Eredita: Mesh < Resource < RefCounted < Object

Un tipo di Mesh che fornisce utilità per la costruzione di una superficie da più array.

Descrizione

Un ArrayMesh serve per costruire una Mesh specificando gli attributi come più array.

L'esempio più basilare è la creazione di un unico triangolo:

var vertices = PackedVector3Array()
vertices.push_back(Vector3(0, 1, 0))
vertices.push_back(Vector3(1, 0, 0))
vertices.push_back(Vector3(0, 0, 1))

# Inizializza l'ArrayMesh.
var arr_mesh = ArrayMesh.new()
var arrays = []
arrays.resize(Mesh.ARRAY_MAX)
arrays[Mesh.ARRAY_VERTEX] = vertices

# Crea la Mesh.
arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)
var m = MeshInstance3D.new()
m.mesh = arr_mesh

Il MeshInstance3D è pronto per essere aggiunto al SceneTree per essere mostrato.

Vedi anche ImmediateMesh, MeshDataTool, e SurfaceTool per la generazione di geometria procedurale.

Nota: Godot utilizza l'ordine di avvolgimento in senso orario per le facce anteriori delle modalità di triangolo primitivo.

Tutorial

Proprietà

BlendShapeMode

blend_shape_mode

1

AABB

custom_aabb

AABB(0, 0, 0, 0, 0, 0)

ArrayMesh

shadow_mesh

Metodi

void

add_blend_shape(name: StringName)

void

add_surface_from_arrays(primitive: PrimitiveType, arrays: Array, blend_shapes: Array[Array] = [], lods: Dictionary = {}, flags: BitField[ArrayFormat] = 0)

void

clear_blend_shapes()

void

clear_surfaces()

int

get_blend_shape_count() const

StringName

get_blend_shape_name(index: int) const

Error

lightmap_unwrap(transform: Transform3D, texel_size: float)

void

regen_normal_maps()

void

set_blend_shape_name(index: int, name: StringName)

int

surface_find_by_name(name: String) const

int

surface_get_array_index_len(surf_idx: int) const

int

surface_get_array_len(surf_idx: int) const

BitField[ArrayFormat]

surface_get_format(surf_idx: int) const

String

surface_get_name(surf_idx: int) const

PrimitiveType

surface_get_primitive_type(surf_idx: int) const

void

surface_remove(surf_idx: int)

void

surface_set_name(surf_idx: int, name: String)

void

surface_update_attribute_region(surf_idx: int, offset: int, data: PackedByteArray)

void

surface_update_skin_region(surf_idx: int, offset: int, data: PackedByteArray)

void

surface_update_vertex_region(surf_idx: int, offset: int, data: PackedByteArray)


Descrizioni delle proprietà

BlendShapeMode blend_shape_mode = 1 🔗

La modalità delle forme di fusione.


AABB custom_aabb = AABB(0, 0, 0, 0, 0, 0) 🔗

  • void set_custom_aabb(value: AABB)

  • AABB get_custom_aabb()

Sovrascrive l'AABB con uno definito dall'utente per l'uso con il frustum culling. Particolarmente utile per evitare culling inaspettato quando si utilizza uno shader per scostare i vertici.


ArrayMesh shadow_mesh 🔗

Una mesh facoltativa che può essere utilizzata per renderizzare ombre e per il pre-passaggio di profondità. Può essere utilizzato per aumentare le prestazioni fornendo una mesh con vertici fusi e con solo i dati di posizione dei vertici (senza normali, UV, colori, ecc).

Nota: Questa mesh deve avere esattamente le stesse posizioni dei vertici della mesh di origine (compresi i LOD della mesh di origine, se presenti). Se le posizioni dei vertici differiscono, la mesh non verrà disegnata correttamente.


Descrizioni dei metodi

void add_blend_shape(name: StringName) 🔗

Aggiunge il nome per una forma di fusione che sarà aggiunta con add_surface_from_arrays(). Deve essere chiamato prima che la superficie sia aggiunta.


void add_surface_from_arrays(primitive: PrimitiveType, arrays: Array, blend_shapes: Array[Array] = [], lods: Dictionary = {}, flags: BitField[ArrayFormat] = 0) 🔗

Crea una nuova superficie. Mesh.get_surface_count() diventerà il surf_idx per questa nuova superficie.

Le superfici sono renderizzate tramite un primitive, che può essere uno qualsiasi dei valori definiti in PrimitiveType.

L'argomento arrays è un array di array. Ciascuno degli elementi Mesh.ARRAY_MAX contiene un array con alcuni dei dati della mesh per questa superficie, come descritto dal membro corrispondente di ArrayType o null se non è utilizzato dalla superficie. Ad esempio, arrays[0] è l'array dei vertici. Il primo sottoarray di vertici è sempre obbligatorio; gli altri sono facoltativi. L'aggiunta di un array di indici mette questa superficie in "modalità indice", dove i vertici e gli altri array diventano le sorgenti di dati e l'array di indici definisce l'ordine dei vertici. Tutti i sottoarray devono avere la stessa lunghezza dell'array dei vertici (o essere un multiplo esatto della lunghezza dell'array dei vertici, quando più elementi di un sottoarray corrispondono a un singolo vertice) oppure essere vuoti, ad eccezione di Mesh.ARRAY_INDEX, se utilizzato.

L'argomento blend_shapes è un array di dati dei vertici per ogni forma di fusione. Ogni elemento è un array con la stessa struttura di arrays, ma Mesh.ARRAY_VERTEX, Mesh.ARRAY_NORMAL e Mesh.ARRAY_TANGENT sono impostati solo se sono impostati in arrays e tutte le altre voci sono null.

L'argomento lods è un dizionario con chiavi float e valori PackedInt32Array. Ogni voce nel dizionario rappresenta un livello LOD della superficie, dove il valore è l'array Mesh.ARRAY_INDEX da utilizzare per il livello LOD e la chiave è approssimativamente proporzionale alla distanza a cui vengono utilizzate le statistiche LOD. Ad esempio, aumentando la chiave di un LOD aumenta anche la distanza che gli oggetti devono avere dalla telecamera prima che il LOD venga utilizzato.

L'argomento flags è l'OR bit a bit di, a seconda delle esigenze: un valore di ArrayCustomFormat spostato a sinistra di ARRAY_FORMAT_CUSTOMn_SHIFT per ogni canale personalizzato in uso, Mesh.ARRAY_FLAG_USE_DYNAMIC_UPDATE, Mesh.ARRAY_FLAG_USE_8_BONE_WEIGHTS o Mesh.ARRAY_FLAG_USES_EMPTY_VERTEX_ARRAY.

Nota: Quando si utilizzano indici, si consiglia di usare solo punti, linee o triangoli.


void clear_blend_shapes() 🔗

Rimuove tutte le forme di fusione da questo ArrayMesh.


void clear_surfaces() 🔗

Rimuove tutte le superfici da questo ArrayMesh.


int get_blend_shape_count() const 🔗

Restituisce il numero di forme di fusione contenute nel ArrayMesh.


StringName get_blend_shape_name(index: int) const 🔗

Restituisce il nome della forma di fusione a questo indice.


Error lightmap_unwrap(transform: Transform3D, texel_size: float) 🔗

Effettua un unwrap degli UV sull'ArrayMesh per preparare la mesh per il lightmapping.


void regen_normal_maps() 🔗

Rigenera le tangenti per ciascuna delle superfici di ArrayMesh.


void set_blend_shape_name(index: int, name: StringName) 🔗

Imposta il nome della forma di fusione in questo indice.


int surface_find_by_name(name: String) const 🔗

Restituisce l'indice della prima superficie con questo nome contenuta in questo ArrayMesh. Se non viene trovato, viene restituito -1.


int surface_get_array_index_len(surf_idx: int) const 🔗

Restituisce la lunghezza in indici dell'array di indici nella superficie richiesta (vedi add_surface_from_arrays()).


int surface_get_array_len(surf_idx: int) const 🔗

Restituisce la lunghezza in vertici dell'array di vertici nella superficie richiesta (vedi add_surface_from_arrays()).


BitField[ArrayFormat] surface_get_format(surf_idx: int) const 🔗

Restituisce la maschera di formato della superficie richiesta (vedi add_surface_from_arrays()).


String surface_get_name(surf_idx: int) const 🔗

Ottiene il nome assegnato a questa superficie.


PrimitiveType surface_get_primitive_type(surf_idx: int) const 🔗

Restituisce il tipo di primitiva della superficie richiesta (vedi add_surface_from_arrays()).


void surface_remove(surf_idx: int) 🔗

Rimuove la superficie con l'indice specificato dalla mesh, spostando le superfici con gli indici maggiori verso il basso di uno.


void surface_set_name(surf_idx: int, name: String) 🔗

Imposta un nome per una determinata superficie.


void surface_update_attribute_region(surf_idx: int, offset: int, data: PackedByteArray) 🔗

Updates the attribute buffer of this mesh's surface with the given data. The expected data per attribute is 12 or 8 bytes (4 bytes per float, 2 floats per Vector2, and 3 floats per Vector3) depending on if the mesh is using Vector3 or Vector2 vertices. This value can be determined with RenderingServer.mesh_surface_get_format_attribute_stride().

The starting point of the updates can be changed with offset. The value of offset should be a multiple of 12 bytes in most cases to align to each attribute.

A PackedVector3Array of attribute locations can be converted into a PackedByteArray using PackedVector3Array.to_byte_array() for use in data.


void surface_update_skin_region(surf_idx: int, offset: int, data: PackedByteArray) 🔗

Updates the skin buffer of this mesh's surface with the given data. The expected data per skin is 12 or 8 bytes (4 bytes per float, 2 floats per Vector2, and 3 floats per Vector3) depending on if the mesh is using Vector3 or Vector2 vertices. This value can be determined with RenderingServer.mesh_surface_get_format_skin_stride().

The starting point of the updates can be changed with offset. The value of offset should be a multiple of 12 bytes in most cases to align to each skin.

A PackedVector3Array of skin locations can be converted into a PackedByteArray using PackedVector3Array.to_byte_array() for use in data.


void surface_update_vertex_region(surf_idx: int, offset: int, data: PackedByteArray) 🔗

Updates the vertex buffer of this mesh's surface with the given data. The expected data per vertex is 12 or 8 bytes (4 bytes per float, 2 floats per Vector2, and 3 floats per Vector3) depending on if the mesh is using Vector3 or Vector2 vertices. This value can be determined with RenderingServer.mesh_surface_get_format_vertex_stride().

The starting point of the updates can be changed with offset. The value of offset should be a multiple of 12 bytes in most cases to align to each vertex.

A PackedVector3Array of vertex locations can be converted into a PackedByteArray using PackedVector3Array.to_byte_array() for use in data.