2021-07-05 20:51:08 -04:00
|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<style>
|
|
|
|
html, body
|
|
|
|
{
|
|
|
|
margin:0;
|
|
|
|
}
|
|
|
|
canvas
|
|
|
|
{
|
|
|
|
position:absolute;
|
|
|
|
top:0;
|
|
|
|
left:0;
|
|
|
|
display:block;
|
|
|
|
width:100%;
|
|
|
|
height:100%;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<canvas></canvas>
|
|
|
|
|
2021-07-07 07:00:50 -04:00
|
|
|
<script type="module">
|
|
|
|
import { Scene, THREE } from './scene.js';
|
2021-07-05 20:51:08 -04:00
|
|
|
|
2021-07-07 07:26:21 -04:00
|
|
|
let average = (inArray, inCenterInd, ...inPointsInd) =>
|
2021-07-05 20:51:08 -04:00
|
|
|
{
|
2021-07-07 07:00:50 -04:00
|
|
|
let output = [0, 0, 0];
|
2021-07-07 07:26:21 -04:00
|
|
|
let centerInd = inCenterInd*3;
|
2021-07-07 07:00:50 -04:00
|
|
|
|
2021-07-07 07:26:21 -04:00
|
|
|
for(let i=0; i<inPointsInd.length; i++)
|
2021-07-07 07:00:50 -04:00
|
|
|
{
|
2021-07-07 07:26:21 -04:00
|
|
|
let pointInd = inPointsInd[i]*3;
|
|
|
|
output[0] += inArray[pointInd+0];
|
|
|
|
output[1] += inArray[pointInd+1];
|
|
|
|
output[2] += inArray[pointInd+2];
|
2021-07-07 07:00:50 -04:00
|
|
|
}
|
|
|
|
|
2021-07-07 07:26:21 -04:00
|
|
|
let scalar = inPointsInd.length;
|
2021-07-07 07:00:50 -04:00
|
|
|
output[0] /= scalar;
|
|
|
|
output[1] /= scalar;
|
|
|
|
output[2] /= scalar;
|
|
|
|
|
2021-07-07 07:26:21 -04:00
|
|
|
let limit = (inPoint, inCenter) =>
|
2021-07-07 07:00:50 -04:00
|
|
|
{
|
2021-07-07 07:26:21 -04:00
|
|
|
let limit = inCenter-0.5;
|
|
|
|
if(inPoint < limit)
|
2021-07-07 07:00:50 -04:00
|
|
|
{
|
2021-07-07 07:26:21 -04:00
|
|
|
return limit;
|
2021-07-07 07:00:50 -04:00
|
|
|
}
|
2021-07-07 07:26:21 -04:00
|
|
|
limit = inCenter+0.5;
|
|
|
|
if(inPoint > limit)
|
2021-07-07 07:00:50 -04:00
|
|
|
{
|
2021-07-07 07:26:21 -04:00
|
|
|
return limit;
|
2021-07-07 07:00:50 -04:00
|
|
|
}
|
2021-07-07 07:26:21 -04:00
|
|
|
return inPoint;
|
2021-07-07 07:00:50 -04:00
|
|
|
}
|
2021-07-07 07:26:21 -04:00
|
|
|
output[0] = limit(output[0], inArray[centerInd+0]);
|
|
|
|
output[1] = limit(output[1], inArray[centerInd+1]);
|
|
|
|
output[2] = limit(output[2], inArray[centerInd+2]);
|
2021-07-07 07:00:50 -04:00
|
|
|
|
|
|
|
return output;
|
|
|
|
};
|
2021-07-07 07:26:21 -04:00
|
|
|
let smooth = (inArray) =>
|
|
|
|
{
|
|
|
|
let output = [inArray[0], inArray[1], inArray[2] ];
|
|
|
|
for(let i=1; i < (inArray.length/3)-1; i++)
|
|
|
|
{
|
|
|
|
output.push( ...average(inArray, i, i-1, i, i+1) );
|
|
|
|
}
|
|
|
|
output.push(inArray[inArray.length-3], inArray[inArray.length-2], inArray[inArray.length-1]);
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
let path = (inPoints, inColor) =>
|
|
|
|
{
|
|
|
|
const geometry = new THREE.BufferGeometry();
|
|
|
|
geometry.setAttribute('position', new THREE.Float32BufferAttribute( inPoints, 3 ));
|
|
|
|
const material = new THREE.LineBasicMaterial( { color: inColor, linewidth: 3 } );
|
|
|
|
return new THREE.Line( geometry, material );
|
|
|
|
}
|
2021-07-07 07:00:50 -04:00
|
|
|
|
|
|
|
const points =
|
|
|
|
[
|
|
|
|
0, 0, 0,
|
|
|
|
0, 1, 0,
|
|
|
|
1, 1, 0,
|
|
|
|
2, 1, 0,
|
|
|
|
2, 0, 0,
|
|
|
|
3, 0, 0,
|
|
|
|
4, 0, 0,
|
|
|
|
4, 1, 0
|
|
|
|
];
|
2021-07-07 07:26:21 -04:00
|
|
|
|
|
|
|
console.log( smooth(points) );
|
|
|
|
|
|
|
|
let path0 = path(points, 0xFF0000);
|
|
|
|
let path1 = path(smooth(points), 0x009900);
|
|
|
|
let path2 = path(smooth(smooth(points)), 0x00AA00);
|
|
|
|
let path3 = path(smooth(smooth(smooth(points))), 0x00FF00);
|
|
|
|
|
2021-07-07 07:00:50 -04:00
|
|
|
|
|
|
|
Scene(
|
|
|
|
{
|
|
|
|
DOM:"canvas",
|
|
|
|
Init(inScene)
|
|
|
|
{
|
2021-07-07 07:26:21 -04:00
|
|
|
inScene.add( path0 );
|
|
|
|
inScene.add( path1 );
|
|
|
|
inScene.add( path2 );
|
|
|
|
inScene.add( path3 );
|
2021-07-07 07:00:50 -04:00
|
|
|
},
|
|
|
|
Update(scene, delta)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2021-07-05 20:51:08 -04:00
|
|
|
}
|
2021-07-07 07:00:50 -04:00
|
|
|
);
|
2021-07-05 20:51:08 -04:00
|
|
|
|
|
|
|
</script>
|
2021-07-06 16:50:26 -04:00
|
|
|
|
2021-07-05 20:51:08 -04:00
|
|
|
</body>
|
|
|
|
</html>
|