Hi.
If IComponentData can’t have NativeArrays, and burst enabled jobs should(?) be passed nativearrays, how exactly is the common way to solve this?
Some context, as I’m hoping for some kick start help to get me rolling:
I’m trying to create my first System. The job is to create many 2d images, and merge them to a final procedural image of given size x,y. The final image will then be used for several purposes, like mesh verticies, texture, normals, etc.
Any pointers to how you would build such a system? Or is it best to keep this one job-only without using system and entities, and just assign to entity as the job(s) is done? I have working PoC job ready, where the array is copied before and after the job is modifying it.
public void Mod_addPerlinNoise(ModificationData modData, ref Vector3[] data)
{
NativeArray<float3> jobdata = new NativeArray<float3>(data.Length, Allocator.TempJob);
for (int i = 0; i < data.Length; i++ )
{
jobdata[i] = data[i];
}
AddPerlinNoiseJob addPerlinNoiseJob = new AddPerlinNoiseJob
{
data = jobdata,
};
JobHandle jobHandle = addPerlinNoiseJob.Schedule(data.Length, 128);
jobHandle.Complete();
for (int i = 0; i < data.Length; i++)
{
data[i] = jobdata[i];
}
jobdata.Dispose();
}
[BurstCompile(FloatPrecision.Low, FloatMode.Fast)] public struct AddPerlinNoiseJob : IJobParallelFor
{
public NativeArray<float3> data;
public void Execute(int i)
{
data[i] += new float3(0f,
100 * noise.cnoise (new float2(0.0008f * data[i].x, 0.0008f * data[i].z ))
+ 10 * noise.cnoise (new float2 ( 0.008f * data[i].x, 0.008f * data[i].z ))
+ 1 * noise.cnoise (new float2 ( 0.08f * data[i].x, 0.08f * data[i].z ))
, 0f);
}
}