smoothing limiter exact clip
This commit is contained in:
parent
9dc5b911fa
commit
b630e26cfd
71
index.html
71
index.html
@ -25,6 +25,39 @@ import { Region } from "./region.js";
|
|||||||
|
|
||||||
let surfaceTest = () =>
|
let surfaceTest = () =>
|
||||||
{
|
{
|
||||||
|
let limit = (x, y, z, ax, ay, az) =>
|
||||||
|
{
|
||||||
|
let centerX = Math.round(x);
|
||||||
|
let centerY = Math.round(y);
|
||||||
|
let centerZ = Math.round(z);
|
||||||
|
|
||||||
|
let deltaX = ax-centerX;
|
||||||
|
let deltaY = ay-centerY;
|
||||||
|
let deltaZ = az-centerZ;
|
||||||
|
|
||||||
|
let absDeltaX = Math.abs(deltaX);
|
||||||
|
let absDeltaY = Math.abs(deltaY);
|
||||||
|
let absDeltaZ = Math.abs(deltaZ);
|
||||||
|
|
||||||
|
let max = absDeltaX;
|
||||||
|
if(absDeltaY > max){ max = absDeltaY; }
|
||||||
|
if(absDeltaZ > max){ max = absDeltaZ; }
|
||||||
|
|
||||||
|
let lerp = 0.49/max;
|
||||||
|
|
||||||
|
if(lerp <= 1)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
centerX + deltaX*lerp,
|
||||||
|
centerY + deltaY*lerp,
|
||||||
|
centerZ + deltaZ*lerp
|
||||||
|
];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return [ax, ay, az];
|
||||||
|
}
|
||||||
|
}
|
||||||
let average = (inArray, inPointInd, inOthersIndArray) =>
|
let average = (inArray, inPointInd, inOthersIndArray) =>
|
||||||
{
|
{
|
||||||
let sum = [0, 0, 0];
|
let sum = [0, 0, 0];
|
||||||
@ -40,26 +73,12 @@ let surfaceTest = () =>
|
|||||||
let pointY = inPointInd*3 + 1;
|
let pointY = inPointInd*3 + 1;
|
||||||
let pointZ = inPointInd*3 + 2;
|
let pointZ = inPointInd*3 + 2;
|
||||||
let reducer = inOthersIndArray.length;
|
let reducer = inOthersIndArray.length;
|
||||||
let limit = (inCenter, inPoint) =>
|
|
||||||
{
|
|
||||||
var size = 0.49999;
|
|
||||||
var limit;
|
|
||||||
limit = inCenter - size;
|
|
||||||
if(inPoint <= limit)
|
|
||||||
{
|
|
||||||
return limit;
|
|
||||||
}
|
|
||||||
limit = inCenter + size;
|
|
||||||
if(inPoint >= limit)
|
|
||||||
{
|
|
||||||
return limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
return inPoint;
|
let limited = limit(inArray[pointX], inArray[pointY], inArray[pointZ], sum[0]/reducer, sum[1]/reducer, sum[2]/reducer);
|
||||||
}
|
|
||||||
inArray[pointX] = limit(Math.round(inArray[pointX]), sum[0]/reducer);
|
inArray[pointX] = limited[0];
|
||||||
inArray[pointY] = limit(Math.round(inArray[pointY]), sum[1]/reducer);
|
inArray[pointY] = limited[1];
|
||||||
inArray[pointZ] = limit(Math.round(inArray[pointZ]), sum[2]/reducer);
|
inArray[pointZ] = limited[2];
|
||||||
};
|
};
|
||||||
let smooth = (inVertsArray, inNeighborsArray, inTimes) =>
|
let smooth = (inVertsArray, inNeighborsArray, inTimes) =>
|
||||||
{
|
{
|
||||||
@ -82,6 +101,7 @@ let surfaceTest = () =>
|
|||||||
voxels[Region.I(1, 1, 0)] = true;
|
voxels[Region.I(1, 1, 0)] = true;
|
||||||
voxels[Region.I(0, 2, 0)] = true;
|
voxels[Region.I(0, 2, 0)] = true;
|
||||||
|
|
||||||
|
/*
|
||||||
voxels[Region.I(0, 0, 1)] = true;
|
voxels[Region.I(0, 0, 1)] = true;
|
||||||
voxels[Region.I(1, 0, 1)] = true;
|
voxels[Region.I(1, 0, 1)] = true;
|
||||||
voxels[Region.I(2, 0, 1)] = true;
|
voxels[Region.I(2, 0, 1)] = true;
|
||||||
@ -102,6 +122,7 @@ let surfaceTest = () =>
|
|||||||
voxels[Region.I(0, 1, 3)] = true;
|
voxels[Region.I(0, 1, 3)] = true;
|
||||||
voxels[Region.I(1, 1, 3)] = true;
|
voxels[Region.I(1, 1, 3)] = true;
|
||||||
voxels[Region.I(0, 2, 3)] = true;
|
voxels[Region.I(0, 2, 3)] = true;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
let surface = Region.Surface(voxels);
|
let surface = Region.Surface(voxels);
|
||||||
@ -112,18 +133,18 @@ let surfaceTest = () =>
|
|||||||
surfaceCubeGeometry.computeVertexNormals(true);
|
surfaceCubeGeometry.computeVertexNormals(true);
|
||||||
let surfaceCubeObject = new THREE.Mesh(
|
let surfaceCubeObject = new THREE.Mesh(
|
||||||
surfaceCubeGeometry,
|
surfaceCubeGeometry,
|
||||||
new THREE.MeshBasicMaterial({color:0xaa9900, wireframe:true, side:THREE.DoubleSide, shading:THREE.FlatShading})
|
new THREE.MeshBasicMaterial({color:0x666666, wireframe:true, side:THREE.DoubleSide})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
let vertsSmooth = new Float32Array(smooth(surface.vertices.flat(), surface.vertPointNeighbors, 5));
|
let vertsSmooth = new Float32Array(smooth(surface.vertices.flat(), surface.vertPointNeighbors, 10));
|
||||||
let surfaceSmoothGeometry = new THREE.BufferGeometry();
|
let surfaceSmoothGeometry = new THREE.BufferGeometry();
|
||||||
surfaceSmoothGeometry.setAttribute('position', new THREE.BufferAttribute(vertsSmooth, 3) );
|
surfaceSmoothGeometry.setAttribute('position', new THREE.BufferAttribute(vertsSmooth, 3) );
|
||||||
surfaceSmoothGeometry.setIndex(surface.triPointVert);
|
surfaceSmoothGeometry.setIndex(surface.triPointVert);
|
||||||
surfaceSmoothGeometry.computeVertexNormals(true);
|
surfaceSmoothGeometry.computeVertexNormals(true);
|
||||||
let surfaceSmoothObject = new THREE.Mesh(
|
let surfaceSmoothObject = new THREE.Mesh(
|
||||||
surfaceSmoothGeometry,
|
surfaceSmoothGeometry,
|
||||||
new THREE.MeshPhongMaterial({color:0xffffff, side:THREE.DoubleSide, shading:THREE.FlatShading})
|
new THREE.MeshBasicMaterial({color:0xffffff, wireframe:true, side:THREE.DoubleSide, flatShading:true})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@ -133,13 +154,13 @@ let surfaceTest = () =>
|
|||||||
Init(inScene)
|
Init(inScene)
|
||||||
{
|
{
|
||||||
let light = new THREE.PointLight(0xffffff, 1, 100)
|
let light = new THREE.PointLight(0xffffff, 1, 100)
|
||||||
light.position.set(0, 2, -4);
|
light.position.set(5, 5, -5);
|
||||||
inScene.add(light)
|
inScene.add(light)
|
||||||
inScene.add(surfaceCubeObject);
|
inScene.add(surfaceCubeObject);
|
||||||
inScene.add(surfaceSmoothObject);
|
inScene.add(surfaceSmoothObject);
|
||||||
|
|
||||||
//inScene.add(new THREE.GridHelper(10, 10));
|
inScene.add(new THREE.GridHelper(10, 10));
|
||||||
//inScene.add(new THREE.AxesHelper( 5 ));
|
inScene.add(new THREE.AxesHelper( 5 ));
|
||||||
},
|
},
|
||||||
Update(inScene, inDelta){}
|
Update(inScene, inDelta){}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user