I’m really confused on how to use this properly.
I have a NativeList that I need to read from as well as APPEND to (I do not need to change anything mid list, just append new things to the end in the job) and I just can’t figure it out. If I declare a variable for the list AsParallelWriter then I seem to lose all ability to read from said list.
Here is the method, it will be called as part of Execute() in a JobParallelFor (hopefully!) The vertices list needs to be both read from and appended to.
private int GetCenterPointIndex(int polyIndex)
{
if (polyIndex > polygons.Length) return -1;
// Check if we previously created this point
if (centerPointCache.ContainsKey(polyIndex))
{
return centerPointCache[polyIndex];
}
// if not, then calculate and create it
var poly = polygons[polyIndex];
var p1 = vertices[poly.A];
var p2 = vertices[poly.B];
var p3 = vertices[poly.C];
var x = p1.x + p2.x + p3.x;
var y = p1.y + p2.y + p3.y;
var z = p1.z + p2.z + p3.z;
// todo need to normalize this
var centerPoint = new float3(x / 3f, y / 3f, z / 3f);
var ret = vertices.Length;
vertices.Add(centerPoint);
midPointCache.Add(polyIndex, ret);
return ret;
}