最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Constructing a triangle array with respect to material without using nested containers - Stack Overflow

programmeradmin1浏览0评论

Using Unity C#, I needed to procedurally create a mesh that may have several submeshes. Normally, after creating my vertex array, I'd make an array of lists where X is the submesh index (submesh index) and Y are triangles. Then, when constructing the mesh I'd simply walk through it horizontally and do mesh.SetTriangles(subMeshTris[subMeshIndex], subMeshIndex); However, since job system forbids using nested arrays, I needed an alternative solution to represent which triangles belong to which submesh in a flat way.

I have two ideas so far:

  1. To keep a parallel array of size allTriangles.length / 6 that's gonna be a lookup for what submesh should those 6 triangles belong to, but I couldn't think of how to efficiently transform it into separate arrays so far

  2. To keep some sort of layout info struct and insert triangles in specific indices instead of appending at the end. So if my info reads Material 1 from 0 to 24, Material 2 from 24 to 36 and I need to insert another 6 triangles into material 1, I'd push them after element 23, then update the info struct so that it reads Material 1 from 0 to 30, Material 2 from 30 to 42 after which I should be able to copy the ranges

I'm currently working on idea #2 but decided to consult online in case I'm unaware of a more efficient approach.

发布评论

评论列表(0)

  1. 暂无评论