only neighbors

This commit is contained in:
TreetopFlyer 2021-07-07 15:12:39 -04:00
parent 7611192683
commit 5351ec84cb

View File

@ -25,23 +25,19 @@
let average = (inArray, inPointInd, ...inOthersInd) => let average = (inArray, inPointInd, ...inOthersInd) =>
{ {
let pointX = inPointInd*3 + 0; let sum = [0, 0, 0];
let pointY = inPointInd*3 + 1;
let pointZ = inPointInd*3 + 2;
let centerX = Math.round(inArray[pointX]);
let centerY = Math.round(inArray[pointY]);
let centerZ = Math.round(inArray[pointZ]);
for(let i=0; i<inOthersInd.length; i++) for(let i=0; i<inOthersInd.length; i++)
{ {
let otherInd = inOthersInd[i]*3; let otherInd = inOthersInd[i]*3;
inArray[pointX] += inArray[otherInd+0]; sum[0] += inArray[otherInd+0];
inArray[pointY] += inArray[otherInd+1]; sum[1] += inArray[otherInd+1];
inArray[pointZ] += inArray[otherInd+2]; sum[2] += inArray[otherInd+2];
} }
let reducer = inOthersInd.length+1; let pointX = inPointInd*3 + 0;
let pointY = inPointInd*3 + 1;
let pointZ = inPointInd*3 + 2;
let reducer = inOthersInd.length;
let limit = (inCenter, inPoint) => let limit = (inCenter, inPoint) =>
{ {
var limit; var limit;
@ -58,10 +54,9 @@
return inPoint; return inPoint;
} }
inArray[pointX] = limit(Math.round(inArray[pointX]), sum[0]/reducer);
inArray[pointX] = limit(centerX, inArray[pointX]/reducer); inArray[pointY] = limit(Math.round(inArray[pointY]), sum[1]/reducer);
inArray[pointY] = limit(centerY, inArray[pointY]/reducer); inArray[pointZ] = limit(Math.round(inArray[pointZ]), sum[2]/reducer);
inArray[pointZ] = limit(centerZ, inArray[pointZ]/reducer);
}; };
let smooth = (inArray, inTimes) => let smooth = (inArray, inTimes) =>
{ {
@ -146,7 +141,7 @@
Init(inScene) Init(inScene)
{ {
inScene.add(path(points, 0, 0xFF0000)); inScene.add(path(points, 0, 0xFF0000));
inScene.add(path(points, 50, 0x00ff00)); inScene.add(path(points, 10, 0x00ff00));
}, },
Update(scene, delta) Update(scene, delta)
{ {