only neighbors
This commit is contained in:
parent
7611192683
commit
72e33a6256
29
index.html
29
index.html
@ -25,23 +25,19 @@
|
||||
|
||||
let average = (inArray, inPointInd, ...inOthersInd) =>
|
||||
{
|
||||
let pointX = inPointInd*3 + 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]);
|
||||
|
||||
let sum = [0, 0, 0];
|
||||
for(let i=0; i<inOthersInd.length; i++)
|
||||
{
|
||||
let otherInd = inOthersInd[i]*3;
|
||||
inArray[pointX] += inArray[otherInd+0];
|
||||
inArray[pointY] += inArray[otherInd+1];
|
||||
inArray[pointZ] += inArray[otherInd+2];
|
||||
sum[0] += inArray[otherInd+0];
|
||||
sum[1] += inArray[otherInd+1];
|
||||
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) =>
|
||||
{
|
||||
var limit;
|
||||
@ -58,10 +54,9 @@
|
||||
|
||||
return inPoint;
|
||||
}
|
||||
|
||||
inArray[pointX] = limit(centerX, inArray[pointX]/reducer);
|
||||
inArray[pointY] = limit(centerY, inArray[pointY]/reducer);
|
||||
inArray[pointZ] = limit(centerZ, inArray[pointZ]/reducer);
|
||||
inArray[pointX] = limit(Math.round(inArray[pointX]), sum[0]/reducer);
|
||||
inArray[pointY] = limit(Math.round(inArray[pointY]), sum[1]/reducer);
|
||||
inArray[pointZ] = limit(Math.round(inArray[pointZ]), sum[2]/reducer);
|
||||
};
|
||||
let smooth = (inArray, inTimes) =>
|
||||
{
|
||||
@ -146,7 +141,7 @@
|
||||
Init(inScene)
|
||||
{
|
||||
inScene.add(path(points, 0, 0xFF0000));
|
||||
inScene.add(path(points, 50, 0x00ff00));
|
||||
inScene.add(path(points, 10, 0x00ff00));
|
||||
},
|
||||
Update(scene, delta)
|
||||
{
|
||||
|
65
region.js
65
region.js
@ -20,7 +20,6 @@ export const Kernel =
|
||||
[ 0, 0, 1],
|
||||
[ 0, 0, -1]
|
||||
],
|
||||
|
||||
Loop(inList, inVector, inHandler)
|
||||
{
|
||||
for(let i=0; i<inList.length; i++)
|
||||
@ -43,11 +42,11 @@ export const Region =
|
||||
Surface:[]
|
||||
};
|
||||
},
|
||||
CoordsToIndex(inX, inY, inZ)
|
||||
I(inX, inY, inZ)
|
||||
{
|
||||
return inX + inY*16 + inZ*256;
|
||||
},
|
||||
IndexToCoords(inI)
|
||||
XYZ(inI)
|
||||
{
|
||||
let zWhole = Math.floor(inI / 256);
|
||||
let zPart = inI % 256;
|
||||
@ -55,27 +54,53 @@ export const Region =
|
||||
let yPart = zPart % 16;
|
||||
return [yPart, yWhole, zWhole];
|
||||
},
|
||||
Update(inRegion)
|
||||
Update(inVoxels)
|
||||
{
|
||||
inRegion.Filled = [];
|
||||
inRegion.Surface = [];
|
||||
var i;
|
||||
for(i=0; i<inRegion.Voxels.length; i++)
|
||||
function Face(a, b, c, d)
|
||||
{
|
||||
if(inRegion.Voxels[i])
|
||||
Edge(a, b);
|
||||
Edge(b, c);
|
||||
Edge(c, d);
|
||||
Edge(d, a);
|
||||
}
|
||||
function Edge(a, b)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
var i;
|
||||
var BA, BU, BC, BR, TA, TU, TC, TR, CL, CD, CB;
|
||||
for(i=0; i<inVoxels.length; i++)
|
||||
{
|
||||
if(inVoxels[i])
|
||||
{
|
||||
let coords = Region.IndexToCoords(i);
|
||||
Kernel.Loop(Kernel.Corners, coords, (inX, inY, inZ)=>
|
||||
{
|
||||
let offsetIndex = Region.CoordsToIndex(inX, inY, inZ);
|
||||
if(!inRegion.Voxels[offsetIndex])
|
||||
{
|
||||
inRegion.Surface.push(i);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
let [x, y, z] = Region.IndexToCoords(i);
|
||||
|
||||
// bottom: at, "up", corner, right
|
||||
BA = i;
|
||||
BU = Region.I(x+1, y, z);
|
||||
BC = Region.I(x+1, y+1, z);
|
||||
BR = Region.I(x, y+1, z);
|
||||
|
||||
// top: at, "up" corner, right
|
||||
TA = Region.I(x, y, z+1);
|
||||
TU = Region.I(x+1, y, z+1);
|
||||
TC = Region.I(x+1, y+1, z+1);
|
||||
TR = Region.I(x, y+1, z+1);
|
||||
|
||||
// check: left, "down", below
|
||||
CL = Region.I(x-1, y, z);
|
||||
CD = Region.I(x, y-1, z);
|
||||
CB = Region.I(x, y, z-1);
|
||||
|
||||
if(!inVoxels[BU]){ Face(BU, BC, TC, TU); }
|
||||
if(!inVoxels[BR]){ Face(BC, BR, TR, TC); }
|
||||
if(!inVoxels[TA]){ Face(TA, TU, TC, TR); }
|
||||
|
||||
if(!inVoxels[CL]){ Face(BA, BU, TU, TA); }
|
||||
if(!inVoxels[CD]){ Face(BR, BA, TA, TR); }
|
||||
if(!inVoxels[CB]){ Face(BA, BU, BC, BR); }
|
||||
}
|
||||
}
|
||||
console.log("looped over", i);
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user