diff --git a/index.html b/index.html index 9d8c7f8..590bbe3 100644 --- a/index.html +++ b/index.html @@ -25,7 +25,7 @@ import { Region, Kernel } from "./region.js"; let r = Region.Create(); let filler = (x, y, z)=> { - r.filled.push(Region.I(x, y, z)); + r.voxels[Region.I(x, y, z)] = true; }; filler(1, 1, 1); Kernel.Loop(Kernel.Corners, [1, 1, 1], filler); diff --git a/region.js b/region.js index 511da41..7eef695 100644 --- a/region.js +++ b/region.js @@ -36,7 +36,7 @@ export const Region = { Create() { - return {filled:[]}; + return {voxels:[]}; }, I(inX, inY, inZ) { @@ -53,23 +53,22 @@ export const Region = Surface(inRegion) { let surface = []; - inRegion.filled.forEach(inIndex => + inRegion.voxels.forEach((inValue, inIndex) => { - let coords = Region.XYZ(inIndex); - Kernel.Loop(Kernel.Corners, coords, (inX, inY, inZ)=> + if(inValue) { - let index = Region.I(inX, inY, inZ); - if(inRegion.filled[index] === undefined) + let coords = Region.XYZ(inIndex); + Kernel.Loop(Kernel.Corners, coords, (inX, inY, inZ)=> { - console.log(inX, inY, inZ, "surface"); - surface.push(inIndex); - return true; - } - else - { - console.log(inX, inY, inZ, "filled"); - } - }); + let kernel = Region.I(inX, inY, inZ); + if(!inRegion.voxels[kernel]) + { + console.log(coords, "surface"); + surface.push(inIndex); + return true; + } + }); + } }); return surface; }