orientation groups started
This commit is contained in:
parent
b630e26cfd
commit
bded36b307
20
index.html
20
index.html
@ -43,7 +43,7 @@ let surfaceTest = () =>
|
||||
if(absDeltaY > max){ max = absDeltaY; }
|
||||
if(absDeltaZ > max){ max = absDeltaZ; }
|
||||
|
||||
let lerp = 0.49/max;
|
||||
let lerp = 0.45/max;
|
||||
|
||||
if(lerp <= 1)
|
||||
{
|
||||
@ -58,7 +58,7 @@ let surfaceTest = () =>
|
||||
return [ax, ay, az];
|
||||
}
|
||||
}
|
||||
let average = (inArray, inPointInd, inOthersIndArray) =>
|
||||
let average = (inArray, inPointInd, inOthersIndArray, inOriginals) =>
|
||||
{
|
||||
let sum = [0, 0, 0];
|
||||
for(let i=0; i<inOthersIndArray.length; i++)
|
||||
@ -74,7 +74,7 @@ let surfaceTest = () =>
|
||||
let pointZ = inPointInd*3 + 2;
|
||||
let reducer = inOthersIndArray.length;
|
||||
|
||||
let limited = limit(inArray[pointX], inArray[pointY], inArray[pointZ], sum[0]/reducer, sum[1]/reducer, sum[2]/reducer);
|
||||
let limited = limit(inOriginals[pointX], inOriginals[pointY], inOriginals[pointZ], sum[0]/reducer, sum[1]/reducer, sum[2]/reducer);
|
||||
|
||||
inArray[pointX] = limited[0];
|
||||
inArray[pointY] = limited[1];
|
||||
@ -83,11 +83,12 @@ let surfaceTest = () =>
|
||||
let smooth = (inVertsArray, inNeighborsArray, inTimes) =>
|
||||
{
|
||||
let count = inVertsArray.length/3;
|
||||
let originals = [...inVertsArray];
|
||||
for(let t=0; t<inTimes; t++)
|
||||
{
|
||||
for(let i=0; i<count; i++)
|
||||
{
|
||||
average(inVertsArray, i, inNeighborsArray[i]);
|
||||
average(inVertsArray, i, inNeighborsArray[i][0], originals);
|
||||
}
|
||||
}
|
||||
return inVertsArray;
|
||||
@ -96,10 +97,12 @@ let surfaceTest = () =>
|
||||
let voxels = [];
|
||||
voxels[Region.I(0, 0, 0)] = true;
|
||||
voxels[Region.I(1, 0, 0)] = true;
|
||||
/*
|
||||
voxels[Region.I(2, 0, 0)] = true;
|
||||
voxels[Region.I(0, 1, 0)] = true;
|
||||
voxels[Region.I(1, 1, 0)] = true;
|
||||
voxels[Region.I(0, 2, 0)] = true;
|
||||
*/
|
||||
|
||||
/*
|
||||
voxels[Region.I(0, 0, 1)] = true;
|
||||
@ -121,8 +124,11 @@ let surfaceTest = () =>
|
||||
voxels[Region.I(2, 0, 3)] = true;
|
||||
voxels[Region.I(0, 1, 3)] = true;
|
||||
voxels[Region.I(1, 1, 3)] = true;
|
||||
voxels[Region.I(2, 1, 3)] = true;
|
||||
voxels[Region.I(0, 2, 3)] = true;
|
||||
*/
|
||||
voxels[Region.I(1, 2, 3)] = true;
|
||||
voxels[Region.I(2, 2, 3)] = true;
|
||||
*/
|
||||
|
||||
|
||||
let surface = Region.Surface(voxels);
|
||||
@ -137,14 +143,14 @@ let surfaceTest = () =>
|
||||
);
|
||||
|
||||
|
||||
let vertsSmooth = new Float32Array(smooth(surface.vertices.flat(), surface.vertPointNeighbors, 10));
|
||||
let vertsSmooth = new Float32Array(smooth(surface.vertices.flat(), surface.vertPointNeighbors, 5));
|
||||
let surfaceSmoothGeometry = new THREE.BufferGeometry();
|
||||
surfaceSmoothGeometry.setAttribute('position', new THREE.BufferAttribute(vertsSmooth, 3) );
|
||||
surfaceSmoothGeometry.setIndex(surface.triPointVert);
|
||||
surfaceSmoothGeometry.computeVertexNormals(true);
|
||||
let surfaceSmoothObject = new THREE.Mesh(
|
||||
surfaceSmoothGeometry,
|
||||
new THREE.MeshBasicMaterial({color:0xffffff, wireframe:true, side:THREE.DoubleSide, flatShading:true})
|
||||
new THREE.MeshPhongMaterial({color:0xffffff, side:THREE.DoubleSide, flatShading:true})
|
||||
);
|
||||
|
||||
|
||||
|
38
region.js
38
region.js
@ -36,7 +36,7 @@ export const Region =
|
||||
let vert = Region.XYZ(inVoxIndex);
|
||||
vertPointer = vertices.length;
|
||||
voxPointVert[inVoxIndex] = vertPointer;
|
||||
vertPointNeighbors.push([]);
|
||||
vertPointNeighbors.push([[], [], [], []]);
|
||||
vertices.push(vert);
|
||||
|
||||
return [vertPointer, false];
|
||||
@ -46,7 +46,7 @@ export const Region =
|
||||
return [vertPointer, true];
|
||||
}
|
||||
}
|
||||
function Edge(vert1, vert1WasFull, vert2, vert2WasFull)
|
||||
function Edge(vert1, vert1WasFull, vert2, vert2WasFull, inOrientationGroup)
|
||||
{
|
||||
/*
|
||||
Sets up neighbor relationships between vert1 and vert2.
|
||||
@ -58,21 +58,27 @@ export const Region =
|
||||
let p1Neighbors = vertPointNeighbors[vert1];
|
||||
let p2Neighbors = vertPointNeighbors[vert2];
|
||||
|
||||
|
||||
// if the two verts were already filled
|
||||
if((vert1WasFull && vert2WasFull))
|
||||
{
|
||||
// it's possible that they are already connected
|
||||
if(p1Neighbors.indexOf(vert2) !== -1)
|
||||
if(p1Neighbors[0].indexOf(vert2) !== -1)
|
||||
{
|
||||
// quit if they are
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
p1Neighbors.push(vert2);
|
||||
p2Neighbors.push(vert1);
|
||||
p1Neighbors[0].push(vert2);
|
||||
p2Neighbors[0].push(vert1);
|
||||
|
||||
|
||||
p1Neighbors[inOrientationGroup+1].push(vert2);
|
||||
p2Neighbors[inOrientationGroup+1].push(vert1);
|
||||
|
||||
}
|
||||
function Face(a, b, c, d /* vox indices */)
|
||||
function Face(a, b, c, d /* vox indices */, inOrientationGroup)
|
||||
{
|
||||
let [p1, p1WasFull] = Vert(a);
|
||||
let [p2, p2WasFull] = Vert(b);
|
||||
@ -81,10 +87,10 @@ export const Region =
|
||||
|
||||
triPointVert.push(p1, p2, p3, p3, p4, p1);
|
||||
|
||||
Edge(p1, p1WasFull, p2, p2WasFull);
|
||||
Edge(p2, p2WasFull, p3, p3WasFull);
|
||||
Edge(p3, p3WasFull, p4, p4WasFull);
|
||||
Edge(p4, p4WasFull, p1, p1WasFull);
|
||||
Edge(p1, p1WasFull, p2, p2WasFull, inOrientationGroup);
|
||||
Edge(p2, p2WasFull, p3, p3WasFull, inOrientationGroup);
|
||||
Edge(p3, p3WasFull, p4, p4WasFull, inOrientationGroup);
|
||||
Edge(p4, p4WasFull, p1, p1WasFull, inOrientationGroup);
|
||||
}
|
||||
|
||||
var i;
|
||||
@ -113,13 +119,13 @@ export const Region =
|
||||
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[BU]){ Face(BU, BC, TC, TU, 0); }
|
||||
if(!inVoxels[BR]){ Face(BC, BR, TR, TC, 1); }
|
||||
if(!inVoxels[TA]){ Face(TA, TU, TC, TR, 2); }
|
||||
|
||||
if(!inVoxels[CL]){ Face(BA, BU, TU, TA); }
|
||||
if(!inVoxels[CD]){ Face(BR, BA, TA, TR); }
|
||||
if(!inVoxels[CB]){ Face(BA, BU, BC, BR); }
|
||||
if(!inVoxels[CL]){ Face(BA, BU, TU, TA, 1); }
|
||||
if(!inVoxels[CD]){ Face(BR, BA, TA, TR, 0); }
|
||||
if(!inVoxels[CB]){ Face(BA, BU, BC, BR, 2); }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user