Параметры
attr | Атрибут данных вершины для проверки. |
Возвращает
int Байтовое смещение в потоке атрибута данных или -1, если оно отсутствует.
Описание
Получить смещение в потоке буфера вершин определенного атрибута данных вершины в этой сетке.
Сети обычно используют один поток буфера вершин, но можно настроить компоновку вершин, в которой атрибуты используют разные буферы вершин (см. SetVertexBufferParams). При использовании такого макета используйте эту функцию, чтобы запросить, где находится данный атрибут в потоке.
Обратите внимание, что эта функция возвращает смещение в байтах внутри потока, не указывая, какой поток. Чтобы определить поток, содержащий заданный атрибут, используйте GetVertexAttributeStream.
using UnityEngine;
using UnityEngine.Rendering;
public class ExampleScript : MonoBehaviour
{
void Start()
{
// Create a Mesh with custom vertex data layout:
// position and normal go into stream 0,
// color goes into stream 1.
var mesh = new Mesh();
mesh.SetVertexBufferParams(10,
new VertexAttributeDescriptor(VertexAttribute.Position, VertexAttributeFormat.Float32, 3, stream:0),
new VertexAttributeDescriptor(VertexAttribute.Normal, VertexAttributeFormat.Float32, 3, stream:0),
new VertexAttributeDescriptor(VertexAttribute.Color, VertexAttributeFormat.UNorm8, 4, stream:1));
// Prints offsets: 0, 12, 0
Debug.Log($"Position offset {mesh.GetVertexAttributeOffset(VertexAttribute.Position)}");
Debug.Log($"Normal offset {mesh.GetVertexAttributeOffset(VertexAttribute.Normal)}");
Debug.Log($"Color offset {mesh.GetVertexAttributeOffset(VertexAttribute.Color)}");
// Cleanup
Object.DestroyImmediate(mesh);
}
}
Смотрите так же: VertexAttribute, HasVertexAttribute, GetVertexAttributeStream, vertexBufferCount, GetVertexBufferStride.