PackedVector3Array
Un array empaquetado de Vector3s.
Descripción
Un array diseñado específicamente para contener Vector3. Empaqueta los datos de forma compacta, por lo que ahorra memoria para arrays de gran tamaño.
Diferencias entre arrays empaquetados, tipados y no tipados: Los arrays empaquetados son generalmente más rápidos de iterar y modificar en comparación con un array tipado del mismo tipo (por ejemplo, PackedVector3Array frente a Array[Vector3]). Además, los arrays empaquetados consumen menos memoria. Como desventaja, los arrays empaquetados son menos flexibles, ya que no ofrecen tantos métodos de conveniencia como Array.map(). Los arrays tipados son a su vez más rápidos de iterar y modificar que los arrays no tipados.
Nota: Los arrays empaquetados siempre se pasan por referencia. Para obtener una copia de un array que se pueda modificar independientemente del original, utiliza duplicate(). Este no es el caso de las propiedades y métodos incorporados. En estos casos, el array empaquetado devuelto es una copia, y su modificación no afectará al valor original. Para actualizar una propiedad incorporada de este tipo, modifica el array devuelto y luego asígnalo de nuevo a la propiedad.
Nota
Hay diferencias notables cuando usa esta API con C#. Véase Diferencias de la API de C# con GDScript para más información.
Constructores
PackedVector3Array(from: Array) |
Métodos
void |
append_array(array: PackedVector3Array) |
void |
clear() |
void |
|
is_empty() const |
|
void |
|
void |
reverse() |
void |
|
size() const |
|
void |
sort() |
to_byte_array() const |
Operadores
operator !=(right: PackedVector3Array) |
|
operator *(right: Transform3D) |
|
operator +(right: PackedVector3Array) |
|
operator ==(right: PackedVector3Array) |
|
operator [](index: int) |
Descripciones de Constructores
PackedVector3Array PackedVector3Array() 🔗
Construye un PackedVector3Array vacío.
PackedVector3Array PackedVector3Array(from: PackedVector3Array)
Construye un PackedVector3Array como una copia del PackedVector3Array dado.
PackedVector3Array PackedVector3Array(from: Array)
Construye un nuevo PackedVector3Array. Opcionalmente, puedes pasar un Array genérico que será convertido.
Nota: Al inicializar un PackedVector3Array con elementos, debe ser inicializado con un Array de valores Vector3:
var array = PackedVector3Array([Vector3(12, 34, 56), Vector3(78, 90, 12)])
Descripciones de Métodos
Concatena un elemento al final del array (alias de push_back()).
void append_array(array: PackedVector3Array) 🔗
Añade un PackedVector3Array al final de este array.
int bsearch(value: Vector3, before: bool = true) 🔗
Finds the index of an existing value (or the insertion index that maintains sorting order, if the value is not yet present in the array) using binary search. Optionally, a before specifier can be passed. If false, the returned index comes after all existing entries of the value in the array.
Note: Calling bsearch() on an unsorted array results in unexpected behavior.
Note: Vectors with @GDScript.NAN elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.
void clear() 🔗
Limpia el array. Esto es equivalente a usar resize() con un tamaño de 0.
int count(value: Vector3) const 🔗
Returns the number of times an element is in the array.
Note: Vectors with @GDScript.NAN elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.
PackedVector3Array duplicate() 🔗
Creates a copy of the array, and returns it.
Removes the first occurrence of a value from the array and returns true. If the value does not exist in the array, nothing happens and false is returned. To remove an element by index, use remove_at() instead.
Note: Vectors with @GDScript.NAN elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.
Asigna el valor dado a todos los elementos del array. Esto normalmente se puede usar junto con resize() para crear un array con un tamaño dado y elementos inicializados.
int find(value: Vector3, from: int = 0) const 🔗
Searches the array for a value and returns its index or -1 if not found. Optionally, the initial search index can be passed.
Note: Vectors with @GDScript.NAN elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.
Vector3 get(index: int) const 🔗
Devuelve el Vector3 en el index dado en el array. Si index está fuera de los límites o es negativo, este método falla y devuelve Vector3(0, 0, 0).
Este método es similar (pero no idéntico) al operador []. En particular, cuando este método falla, no pausa la ejecución del proyecto si se ejecuta desde el editor.
bool has(value: Vector3) const 🔗
Returns true if the array contains value.
Note: Vectors with @GDScript.NAN elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.
int insert(at_index: int, value: Vector3) 🔗
Inserta un nuevo elemento en una posición determinada del array. La posición debe ser válida, o al final del array (idx == size()).
Devuelve true si el array es vacio.
bool push_back(value: Vector3) 🔗
Inserta un Vector3 al final.
Elimina un elemento del array por indice.
Sets the size of the array. If the array is grown, reserves elements at the end of the array. If the array is shrunk, truncates the array to the new size. Calling resize() once and assigning the new values is faster than adding new elements one by one.
Returns @GlobalScope.OK on success, or one of the following Error constants if this method fails: @GlobalScope.ERR_INVALID_PARAMETER if the size is negative, or @GlobalScope.ERR_OUT_OF_MEMORY if allocations fail. Use size() to find the actual size of the array after resize.
void reverse() 🔗
Invierte el orden de los elementos en el array.
int rfind(value: Vector3, from: int = -1) const 🔗
Searches the array in reverse order. Optionally, a start search index can be passed. If negative, the start index is considered relative to the end of the array.
Note: Vectors with @GDScript.NAN elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.
void set(index: int, value: Vector3) 🔗
Cambia el Vector3 en el índice dado.
Devuelve el numer de elementos en el array.
PackedVector3Array slice(begin: int, end: int = 2147483647) const 🔗
Devuelve la porción del PackedVector3Array, desde begin (inclusivo) hasta end (exclusivo), como un nuevo PackedVector3Array.
El valor absoluto de begin y end se ajustará al tamaño del array, por lo que el valor por defecto de end hace que se corte hasta el final del array por defecto (es decir, arr.slice(1) es una abreviatura de arr.slice(1, arr.size())).
Si begin o end son negativos, serán relativos al final del array (es decir, arr.slice(0, -2) es una abreviatura de arr.slice(0, arr.size() - 2)).
void sort() 🔗
Sorts the elements of the array in ascending order.
Note: Vectors with @GDScript.NAN elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included.
PackedByteArray to_byte_array() const 🔗
Returns a PackedByteArray with each vector encoded as bytes.
Descripciones de Operadores
bool operator !=(right: PackedVector3Array) 🔗
Returns true if contents of the arrays differ.
PackedVector3Array operator *(right: Transform3D) 🔗
Devuelve un nuevo PackedVector3Array con todos los vectores de este array transformados inversamente (multiplicados) por la matriz de transformación Transform3D dada, bajo la suposición de que la base de la transformación es ortonormal (es decir, la rotación/reflexión está bien, pero el escalado/sesgado no).
array * transform es equivalente a transform.inverse() * array. Véase Transform3D.inverse().
Para transformar por la inversa de una transformación afín (p. ej. con escalado) se puede usar en su lugar transform.affine_inverse() * array. Véase Transform3D.affine_inverse().
PackedVector3Array operator +(right: PackedVector3Array) 🔗
Devuelve un nuevo PackedVector3Array con el contenido de right añadido al final de este array. Para un mejor rendimiento, considera usar append_array() en su lugar.
bool operator ==(right: PackedVector3Array) 🔗
Devuelve true si el contenido de ambos arrays es el mismo, es decir, tienen todos los Vector3s iguales en los índices correspondientes.
Vector3 operator [](index: int) 🔗
Devuelve el Vector3 en el índice index. Se pueden usar índices negativos para acceder a los elementos desde el final. Usar un índice fuera de los límites del array resultará en un error.