![]() Note: normals will be calculated later in RecalculateNormals. The first vertex buffer data stream is just positions New VertexAttributeDescriptor( VertexAttribute.Normal, stream: 1)) New VertexAttributeDescriptor( VertexAttribute.Position), don't share the vertices since normals have to be 4 faces with 3 unique vertices in each - the faces Tetrahedron vertices with positions and normals. Var dataArray = Mesh.AllocateWritableMeshData(1) Public class ExampleScript : MonoBehaviour When you have populated the writeable MeshData struct with your data, use Mesh.ApplyAndDisposeWritableMeshData to apply the data to Mesh objects and automatically dispose of the MeshDataArray. Write to to set the number of sub meshes, and then use to set sub mesh data. Use to set the index buffer size and format, and then write to the array returned by to set the indices. Use to set the vertex buffer size and layout, and then write to the array returned by to set the vertices. You can populate writeable MeshData structs with data to create new Meshes. Creating a MeshDataArray has some overhead for memory tracking and safety reasons, so it is more efficient to make a single call to Mesh.AllocateWritableMeshData and request multiple MeshData structs in the same MeshDataArray than it is to make multiple calls to Mesh.AllocateWritableMeshData. You can access the resulting MeshDataArray and MeshData structs from any thread. Use Mesh.AllocateWritableMeshData to obtain a MeshDataArray of writeable MeshData structs. Use Dispose to dispose of the MeshDataArray, or use the C# using pattern to do this automatically: In addition to this, if you call Mesh.AcquireReadOnlyMeshData and then modify the Mesh, your modifications are not reflected in the MeshData structs. However, if you call Mesh.AcquireReadOnlyMeshData and then modify the Mesh while the MeshDataArray exists, Unity must copy the MeshDataArray into a new memory allocation. Calling Mesh.AcquireReadOnlyMeshData does not cause any memory allocations or data copies by default, as long as you dispose of the MeshDataArray before modifying the Mesh. You must dispose of the MeshDataArray once you have finished working with it. For example, if the read-only MeshData struct uses VertexAttributeFormat.Float16 normals and you call GetNormals, the normals will be converted into Vector3 normals in the destination array. These methods also perform data format conversions if needed. You can use GetColors, GetIndices, GetNormals, GetTangents, GetUVs, and GetVertices to copy the read-only Mesh data into pre-existing arrays. You need to know the exact Mesh data layout to do this: for instance, the presence and formats of all the mesh vertex attributes. You can use GetIndexData and GetVertexData to access the raw read-only Mesh data without any memory allocations, data copies or format conversions. Creating a MeshDataArray has some overhead for memory tracking and safety reasons, so it is more efficient to make a single call to Mesh.AcquireReadOnlyMeshData and request multiple MeshData structs in the same MeshDataArray than it is to make multiple calls to Mesh.AcquireReadOnlyMeshData.Įach MeshData struct contains a read-only snapshot of data for a given Mesh. When you pass one or more Meshes to Mesh.AcquireReadOnlyMeshData, Unity returns a MeshDataArray of read-only MeshData structs. There are two types of MeshData struct: read-only MeshData structs that allow read-only access to Mesh data from the C# Job System, and writeable MeshData structs that allow you to create Meshes from the C# Job System. Use a MeshData struct to access, process and create Meshes in the C# Job System.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |