public Color[] FinalizeJob() { if (jobs.Count > 0) { MTNormalBakeJob job = jobs.Dequeue(); Color[] result = job.GetResultColor(); job.DisposeData(); return(result); } return(null); }
public JobHandle NextJob() { if (jobs.Count < 2) { throw new System.Exception("NextJob need 2 jobs"); } MTNormalBakeJob job = jobs.Dequeue(); Vector3[] result = job.result.ToArray(); job.DisposeData(); MTNormalBakeJob nextJob = jobs.Peek(); nextJob.baseLayer.CopyFrom(result); return(nextJob.Schedule()); }
private MTNormalBakeJob CreateNormalTexBakeJob(Terrain t, int resultSize, int layerStart, Color[][] colorData, Color[] ctrlData, int startU, int startV) { MTNormalBakeJob jobData = new MTNormalBakeJob(); int[] layerTexSize = new int[] { 0, 0, 0, 0 }; Vector3[] vecDefault = new Vector3[resultSize * resultSize]; for (int i = 0; i < vecDefault.Length; ++i) { vecDefault[i] = Vector3.zero; } jobData.terrainDataSize = t.terrainData.size; jobData.baseLayer = new NativeArray <Vector3>(vecDefault, Allocator.TempJob); jobData.result = new NativeArray <Vector3>(vecDefault, Allocator.TempJob); if (colorData.Length > layerStart && colorData[layerStart] != null) { Color[] data = colorData[layerStart]; jobData.layer0 = new NativeArray <Color>(data, Allocator.TempJob); layerTexSize[0] = (int)Mathf.Sqrt(data.Length); } else { jobData.layer0 = new NativeArray <Color>(new Color[0], Allocator.TempJob); } if (colorData.Length > layerStart + 1 && colorData[layerStart + 1] != null) { Color[] data = colorData[layerStart + 1]; jobData.layer1 = new NativeArray <Color>(data, Allocator.TempJob); layerTexSize[1] = (int)Mathf.Sqrt(data.Length); } else { jobData.layer1 = new NativeArray <Color>(new Color[0], Allocator.TempJob); } if (colorData.Length > layerStart + 2 && colorData[layerStart + 2] != null) { Color[] data = colorData[layerStart + 2]; jobData.layer2 = new NativeArray <Color>(data, Allocator.TempJob); layerTexSize[2] = (int)Mathf.Sqrt(data.Length); } else { jobData.layer2 = new NativeArray <Color>(new Color[0], Allocator.TempJob); } if (colorData.Length > layerStart + 3 && colorData[layerStart + 3] != null) { Color[] data = colorData[layerStart + 3]; jobData.layer3 = new NativeArray <Color>(data, Allocator.TempJob); layerTexSize[3] = (int)Mathf.Sqrt(data.Length); } else { jobData.layer3 = new NativeArray <Color>(new Color[0], Allocator.TempJob); } Vector2[] tileOffset = new Vector2[] { Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero }; Vector2[] tileSize = new Vector2[] { Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero }; float[] normScales = new float[] { 0, 0, 0, 0 }; for (int i = 0; i < 4; ++i) { if (t.terrainData.terrainLayers.Length > layerStart + i) { tileOffset[i] = t.terrainData.terrainLayers[layerStart + i].tileOffset; tileSize[i] = t.terrainData.terrainLayers[layerStart + i].tileSize; normScales[i] = t.terrainData.terrainLayers[layerStart + i].normalScale; } } jobData.layerSize = new NativeArray <int>(layerTexSize, Allocator.TempJob); jobData.tileOffset = new NativeArray <Vector2>(tileOffset, Allocator.TempJob); jobData.tileSize = new NativeArray <Vector2>(tileSize, Allocator.TempJob); jobData.normalScale = new NativeArray <float>(normScales, Allocator.TempJob); jobData.ctrlMap = new NativeArray <Color>(ctrlData, Allocator.TempJob); jobData.ctrlRes = t.terrainData.alphamapResolution; jobData.sliceTexRes = resultSize; jobData.startU = startU; jobData.startV = startV; return(jobData); }
public void Enqueue(MTNormalBakeJob job) { Normal.jobs.Enqueue(job); }