Compare commits

..

No commits in common. "master" and "6225a1af135b0faeb3005a2efb8f556b1778419f" have entirely different histories.

2 changed files with 36 additions and 85 deletions

View File

@ -20,17 +20,30 @@
<body>
<canvas></canvas>
<script type="module">
import { Region, Kernel } from "./region.js";
let r = Region.Create();
let filler = (x, y, z)=>
{
r.voxels[Region.I(x, y, z)] = true;
};
filler(1, 1, 1);
Kernel.Loop(Kernel.Corners, [1, 1, 1], filler);
Kernel.Loop(Kernel.Cardinal, [1, 1, 1], filler);
Region.Surface(r);
</script>
<script type="module">
import * as T from 'http://esm.sh/three';
import { OrbitControls } from 'http://esm.sh/three/examples/jsm/controls/OrbitControls.js';
import { Region, Kernel } from "./region.js";
const renderer = new T.WebGLRenderer({canvas:document.querySelector("canvas")});
const scene = new T.Scene();
const camera = new T.PerspectiveCamera(80, 2, 0.1, 10);
const light = new T.DirectionalLight(0xFFFFFF, 1);
const geometry = new T.BoxGeometry(0.8, 0.8, 0.8);
const geometry = new T.BoxGeometry(1, 1, 1);
const shader = new T.MeshPhongMaterial({color:0xFFCC00});
const shaderBlue = new T.MeshPhongMaterial({color:0x0033FF});
const object = new T.Mesh(geometry, shader);
const controls = new OrbitControls(camera, renderer.domElement);
@ -38,61 +51,6 @@ controls.update();
scene.add(light);
scene.add(object);
scene.add(new T.GridHelper(10, 10));
const geoBuff = new T.BufferGeometry();
geoBuff.setAttribute("position", new T.BufferAttribute(new Float32Array(
[
0, 0, 0,
1, 0, 0,
1, 1, 0,
0, 1, 0,
2, 0, 1,
2, 1, 1
]
), 3));
geoBuff.setIndex(
[
0, 1, 2,
2, 3, 0,
1, 4, 5,
5, 2, 1
]
);
geoBuff.computeVertexNormals();
const geoObj = new T.Mesh(geoBuff, shader);
shader.shading = T.FlatShading;
scene.add(geoObj);
/*
let r = Region.Create();
let filler = (x, y, z) =>
{
r.Voxels[Region.CoordsToIndex(x, y, z)] = true;
};
filler(1, 1, 1);
Kernel.Loop(Kernel.Corners, [1, 1, 1], filler);
Kernel.Loop(Kernel.Cardinal, [1, 1, 1], filler);
Region.Update(r);
r.Filled.forEach((inIndexMap) =>
{
let coords = Region.IndexToCoords(inIndexMap);
let cube = new T.Mesh(geometry, shader);
cube.position.set(...coords);
scene.add(cube);
});
r.Surface.forEach((inIndexMap) =>
{
let coords = Region.IndexToCoords(inIndexMap);
let cube = new T.Mesh(geometry, shaderBlue);
cube.position.set(...coords);
scene.add(cube);
});
*/
light.position.set(-1, 2, 4);
camera.position.set(0, 0, 2);
@ -136,6 +94,5 @@ resize();
render(0);
update(new Date());
</script>
</body>
</html>

View File

@ -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++)
@ -37,45 +36,40 @@ export const Region =
{
Create()
{
return {
Voxels:[],
Filled:[],
Surface:[]
};
return {voxels:[]};
},
CoordsToIndex(inX, inY, inZ)
I(inX, inY, inZ)
{
return inX + inY*16 + inZ*256;
return inX + inY*32 + inZ*1024;
},
IndexToCoords(inI)
XYZ(inI)
{
let zWhole = Math.floor(inI / 256);
let zPart = inI % 256;
let yWhole = Math.floor(zPart / 16);
let yPart = zPart % 16;
let zWhole = Math.floor(inI / 1024);
let zPart = inI % 1024;
let yWhole = Math.floor(zPart / 32);
let yPart = zPart % 32;
return [yPart, yWhole, zWhole];
},
Update(inRegion)
Surface(inRegion)
{
inRegion.Filled = [];
inRegion.Surface = [];
var i;
for(i=0; i<inRegion.Voxels.length; i++)
let surface = [];
inRegion.voxels.forEach((inValue, inIndex) =>
{
if(inRegion.Voxels[i])
if(inValue)
{
let coords = Region.IndexToCoords(i);
let coords = Region.XYZ(inIndex);
Kernel.Loop(Kernel.Corners, coords, (inX, inY, inZ)=>
{
let offsetIndex = Region.CoordsToIndex(inX, inY, inZ);
if(!inRegion.Voxels[offsetIndex])
let kernel = Region.I(inX, inY, inZ);
if(!inRegion.voxels[kernel])
{
inRegion.Surface.push(i);
console.log(coords, "surface");
surface.push(inIndex);
return true;
}
});
}
}
console.log("looped over", i);
});
return surface;
}
};