face and neighbor creation

This commit is contained in:
TreetopFlyer 2021-07-10 11:27:44 -04:00
parent 72e33a6256
commit 13b0384c54
2 changed files with 50 additions and 10 deletions

View File

@ -19,7 +19,16 @@
</head>
<body>
<canvas></canvas>
<script type="module">
import { Region } from "./region.js";
let voxels = [];
voxels[Region.I(2, 2, 2)] = true;
voxels[Region.I(3, 2, 2)] = true;
console.log(Region.Surface(voxels));
</script>
<!--
<script type="module">
import { Scene, THREE } from './scene.js';
@ -134,7 +143,7 @@
];
/*
Scene(
{
DOM:"canvas",
@ -149,6 +158,7 @@
}
}
);
*/
</script>

View File

@ -54,27 +54,55 @@ export const Region =
let yPart = zPart % 16;
return [yPart, yWhole, zWhole];
},
Update(inVoxels)
Surface(inVoxels)
{
function Vert(a)
{
var vertPointer = voxPointVert[a]
if(vertPointer === undefined)
{
let vert = Region.XYZ(a);
vertPointer = vertices.length;
voxPointVert[a] = vertPointer;
vertPointNeighbors.push([]);
vertices.push(vert);
}
return vertPointer;
}
function Face(a, b, c, d)
{
Edge(a, b);
Edge(b, c);
Edge(c, d);
Edge(d, a);
}
function Edge(a, b)
{
let p1 = Vert(a);
let p2 = Vert(b);
let p3 = Vert(c);
let p4 = Vert(d);
triPointVert.push(p1, p2, p3, p3, p4, p1);
vertPointNeighbors[p1].push(p2);
vertPointNeighbors[p2].push(p1);
vertPointNeighbors[p2].push(p3);
vertPointNeighbors[p3].push(p2);
vertPointNeighbors[p3].push(p4);
vertPointNeighbors[p4].push(p3);
vertPointNeighbors[p4].push(p1);
vertPointNeighbors[p1].push(p2);
}
var vertices = [];
var voxPointVert = [];
var triPointVert = [];
var vertPointNeighbors = [];
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 [x, y, z] = Region.IndexToCoords(i);
let [x, y, z] = Region.XYZ(i);
// bottom: at, "up", corner, right
BA = i;
@ -102,5 +130,7 @@ export const Region =
if(!inVoxels[CB]){ Face(BA, BU, BC, BR); }
}
}
return {vertices, voxPointVert, triPointVert, vertPointNeighbors};
}
};