Offscreen canvas and multithreading

I saw significant improvements to the overall runtime (5-8 times faster) with using function getClosestFacetAtCoordinates instead of my own function. For each position in the discretized grid, I find the “anchor”, i.e. a point on the mesh from which the connector line emanates, by getting the closest point on the mesh. I stumbled upon FacetData and enabled it on the meshes. I encountered an issue with it (found in post: getClosestFacetAtCoordinates returning null most of the time), but this looks very promising.

Including the previous function:

/**
 * Finds the point that is closest to the part's mesh. 
 * @param {Vector3} point
 * @return {Vector3} Closest point on the Part Mesh
 */
closestPointOnPartMeshTo(point) {
    var positions = this._partMesh.getVerticesData(BABYLON.VertexBuffer.PositionKind);
    var minSquaredDistance = Math.pow(10, 9);
    var closestVertex = BABYLON.Vector3.Zero;
    var numberOfVertices = positions.length / 3;	

    for (var i = 0; i < numberOfVertices; i = i + 1) {
        var vertPosition = new BABYLON.Vector3(positions[i*3], positions[i*3+1], positions[i*3+2]);
        var dsq = BABYLON.Vector3.DistanceSquared(point, vertPosition);

        if (minSquaredDistance > dsq)  {
            minSquaredDistance = dsq;
            closestVertex = vertPosition;
        }
    }    
    return closestVertex;
}