From 72e33a6256858bce2c7b74c8abc0627b510a2658 Mon Sep 17 00:00:00 2001 From: TreetopFlyer Date: Wed, 7 Jul 2021 15:12:39 -0400 Subject: [PATCH] only neighbors --- index.html | 29 ++++++++++-------------- region.js | 65 +++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 57 insertions(+), 37 deletions(-) diff --git a/index.html b/index.html index c6a82a8..c6c2502 100644 --- a/index.html +++ b/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 { 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) { diff --git a/region.js b/region.js index c3cccff..8291473 100644 --- a/region.js +++ b/region.js @@ -20,7 +20,6 @@ export const Kernel = [ 0, 0, 1], [ 0, 0, -1] ], - Loop(inList, inVector, inHandler) { for(let i=0; i - { - 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); } };