You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functiondistance2(x1,y1,x2,y2){varxd=(x1-x2)*(x1-x2);varyd=(y1-y2)*(y1-y2);returnMath.sqrt(xd+yd);}LineMesh.prototype.update=function(path,closed){path=path||[];varnormals=getNormals(path,closed);if(closed){path=path.slice();path.push(path[0]);normals.push(normals[0]);}varattrPosition=this.getAttribute('position');varattrNormal=this.getAttribute('lineNormal');varattrMiter=this.getAttribute('lineMiter');varattrDistance=this.getAttribute('lineDistance');varattrIndex=typeofthis.getIndex==='function' ? this.getIndex() : this.getAttribute('index');varindexCount=Math.max(0,(path.length-1)*6);if(!attrPosition.array||(path.length!==attrPosition.array.length/3/VERTS_PER_POINT)){varcount=path.length*VERTS_PER_POINT;attrPosition.array=newFloat32Array(count*3);attrNormal.array=newFloat32Array(count*2);attrMiter.array=newFloat32Array(count);attrIndex.array=newUint16Array(indexCount);if(attrDistance){attrDistance.array=newFloat32Array(count);}}if(undefined!==attrPosition.count){attrPosition.count=count;}attrPosition.needsUpdate=true;if(undefined!==attrNormal.count){attrNormal.count=count;}attrNormal.needsUpdate=true;if(undefined!==attrMiter.count){attrMiter.count=count;}attrMiter.needsUpdate=true;if(undefined!==attrIndex.count){attrIndex.count=indexCount;}attrIndex.needsUpdate=true;if(attrDistance){if(undefined!==attrDistance.count){attrDistance.count=count;}attrDistance.needsUpdate=true;}varindex=0;varc=0;vardIndex=0;varindexArray=attrIndex.array;varpathLength=0,lastPt=undefined;// Determine path lengthpath.forEach(function(point,pointIndex,list){if(lastPt!==undefined){vard=distance2(point[0],point[1],lastPt[0],lastPt[1]);pathLength+=d;}lastPt=point;});// Determine normalized position of each vertice along pathlastPt=undefined;varpos=0;path.forEach(function(point,pointIndex,list){vari=index;indexArray[c++]=i+0;indexArray[c++]=i+1;indexArray[c++]=i+2;indexArray[c++]=i+2;indexArray[c++]=i+1;indexArray[c++]=i+3;vardist=0;if(lastPt!==undefined){dist=distance2(point[0],point[1],lastPt[0],lastPt[1]);}lastPt=point;attrPosition.setXYZ(index++,point[0],point[1],0);attrPosition.setXYZ(index++,point[0],point[1],0);if(attrDistance){pos+=dist/pathLength;attrDistance.setX(dIndex++,pos);attrDistance.setX(dIndex++,pos);}});varnIndex=0;varmIndex=0;normals.forEach(function(n){varnorm=n[0];varmiter=n[1];attrNormal.setXY(nIndex++,norm[0],norm[1]);attrNormal.setXY(nIndex++,norm[0],norm[1]);attrMiter.setX(mIndex++,-miter);attrMiter.setX(mIndex++,miter);});};
The text was updated successfully, but these errors were encountered:
Just in case someone comes across this...
The original code assumes the distance between the points on the line is equal. This update allows varied distances.
The text was updated successfully, but these errors were encountered: