private void UpdateMesh(MeshFilter aF) { if (tDict.ContainsKey(aF.transform.name)) { position = tDict[aF.transform.name]; } else { position = new NativeArray <Vector3>(aF.mesh.vertices, Allocator.Persistent); tDict.Add(aF.transform.name, position); } NativeArray <float> colorVals = new NativeArray <float>(vals, Allocator.TempJob); //Vector3[] verts = aF.mesh.vertices; // position.CopyFrom(verts); //colorVals.CopyFrom(vals); //var byteArr = new NativeArray<Color32>(matTex.GetRawTextureData<Color32>().Length, Allocator.Persistent); //byteArr.CopyFrom(matTex.GetRawTextureData<Color32>()); //SampleMesh(); //SampleMesh(filterB); //SampleMesh(filterC); var job = new ApplyNoiseJob() { verts = position, colors = colorVals, min = highTerrainTransform.InverseTransformPoint(this.min), max = highTerrainTransform.InverseTransformPoint(this.max), maxHeight = this.maxHeight, size = this.size }; JobHandle jobHandle = job.Schedule(aF.mesh.vertexCount, 10); jobHandle.Complete(); //Vector3[] filteredVerts = new Vector3[aF.mesh.vertexCount]; //filteredVerts = position.ToArray(); //position.CopyTo(aF.mesh.vertices); aF.mesh.vertices = position.ToArray(); //Don't need to be done every frame lol aF.mesh.RecalculateBounds(); aF.mesh.RecalculateNormals(); colorVals.Dispose(); }
private void UpdatePermMesh(MeshFilter aF, float[] vals) { Debug.Log(this.transform.name); var position = new NativeArray <Vector3>(aF.sharedMesh.vertexCount, Allocator.TempJob); Vector3[] verts = aF.sharedMesh.vertices; position.CopyFrom(verts); var colorVals = new NativeArray <float>(size * size, Allocator.TempJob); colorVals.CopyFrom(vals); //var byteArr = new NativeArray<Color32>(matTex.GetRawTextureData<Color32>().Length, Allocator.Persistent); //byteArr.CopyFrom(matTex.GetRawTextureData<Color32>()); //SampleMesh(); //SampleMesh(filterB); //SampleMesh(filterC); var job = new ApplyNoiseJob() { verts = position, colors = colorVals, min = highTerrainTransform.InverseTransformPoint(this.min), max = highTerrainTransform.InverseTransformPoint(this.max), maxHeight = this.maxHeight, size = this.size }; JobHandle jobHandle = job.Schedule(aF.sharedMesh.vertexCount, 128); jobHandle.Complete(); colorVals.Dispose(); Vector3[] filteredVerts = new Vector3[aF.sharedMesh.vertexCount]; filteredVerts = position.ToArray(); for (int c = 0; c < filteredVerts.Length; c++) { filteredVerts[c] = (filteredVerts[c]); } aF.sharedMesh.vertices = filteredVerts; aF.sharedMesh.RecalculateBounds(); aF.sharedMesh.RecalculateNormals(); // position.Dispose(); }