public void Start(VCPaintJobHandle.Args args) { meshFilter = args.meshFilter; Mesh mesh = args.meshFilter.mesh; if (mesh.colors.Length != mesh.vertexCount) { mesh.colors = new Color[mesh.vertexCount]; } colors = mesh.colors; ScheduleJobs(args); isRunning = true; }
public void PaintMesh(MeshFilter meshFilter) { Mesh mesh = meshFilter.mesh; if (mesh == null || Mathf.Approximately(outerRadius, 0.0f)) return; if (mode == Mode.SingleCPU) { System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); Transform meshTransform = meshFilter.transform; Vector3[] vertices = mesh.vertices; Color[] colors = new Color[vertices.Length]; for (int i = 0; i < vertices.Length; ++i) { float verticeDistance = Vector3.Distance(this.transform.position, meshTransform.TransformPoint(vertices[i])); float colorWeight = (verticeDistance - innerRadius) / (outerRadius - innerRadius); colors[i] = Color.Lerp(paintColor, outRadiusColor, colorWeight); } mesh.colors = colors; stopWatch.Stop(); //Debug.LogFormat("Mesh {0} done in {1} ms", meshFilter.gameObject.name, stopWatch.ElapsedMilliseconds); } else // if (mode == Mode.JobSystem) { //Debug.LogFormat("Queue new job for mesh {0}...", meshFilter.gameObject.name); VCPaintJobHandle.Args args = new VCPaintJobHandle.Args(); args.innerColor = paintColor; args.outerColor = outRadiusColor; args.meshFilter = meshFilter; args.innerRadius = innerRadius; args.outerRadius = outerRadius; args.brushPosition = this.transform.position; VCPaintJobHandle newJobHandle = new VCPaintJobHandle(); newJobHandle.OnJobCompleted += OnJobCompleted; paintJobHandles.Add(newJobHandle); newJobHandle.Start(args); } }
void ScheduleJobs(VCPaintJobHandle.Args args) { VCPaintJob paintJob = new VCPaintJob() { innerColor = args.innerColor, outerColor = args.outerColor, innerRadiusSqr = args.innerRadius * args.innerRadius, outerRadiusSqr = args.outerRadius * args.outerRadius, brushPosition = args.brushPosition, meshTransformMatrix = args.meshFilter.transform.localToWorldMatrix, }; Mesh mesh = args.meshFilter.mesh; paintJob.Initialize(mesh, ref colors); paintJobHandles = new List <JobHandle>(); int numCores = 1; //SystemInfo.processorCount; int numVerticesPerCore = mesh.vertexCount / numCores; int remainingNumVerticesPerCore = mesh.vertexCount % numCores; for (int coreId = 0; coreId < numCores; ++coreId) { paintJob.indexStart = coreId * numVerticesPerCore; paintJob.indexEnd = coreId * numVerticesPerCore + numVerticesPerCore; if (coreId + 1 >= numCores) { paintJob.indexEnd += remainingNumVerticesPerCore; } paintJobHandles.Add(paintJob.Schedule()); } }