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 15:01:21 -04:00
|
|
|
let average = (inArray, inPointInd, ...inOthersInd) =>
|
2021-07-05 20:51:08 -04:00
|
|
|
{
|
2021-07-07 15:01:21 -04:00
|
|
|
let pointX = inPointInd*3 + 0;
|
|
|
|
let pointY = inPointInd*3 + 1;
|
|
|
|
let pointZ = inPointInd*3 + 2;
|
2021-07-07 07:00:50 -04:00
|
|
|
|
2021-07-07 15:01:21 -04:00
|
|
|
let centerX = Math.round(inArray[pointX]);
|
|
|
|
let centerY = Math.round(inArray[pointY]);
|
|
|
|
let centerZ = Math.round(inArray[pointZ]);
|
|
|
|
|
|
|
|
for(let i=0; i<inOthersInd.length; i++)
|
2021-07-07 07:00:50 -04:00
|
|
|
{
|
2021-07-07 15:01:21 -04:00
|
|
|
let otherInd = inOthersInd[i]*3;
|
|
|
|
inArray[pointX] += inArray[otherInd+0];
|
|
|
|
inArray[pointY] += inArray[otherInd+1];
|
|
|
|
inArray[pointZ] += inArray[otherInd+2];
|
2021-07-07 07:00:50 -04:00
|
|
|
}
|
|
|
|
|
2021-07-07 15:01:21 -04:00
|
|
|
let reducer = inOthersInd.length+1;
|
2021-07-07 12:09:52 -04:00
|
|
|
let limit = (inCenter, inPoint) =>
|
2021-07-07 07:00:50 -04:00
|
|
|
{
|
2021-07-07 12:09:52 -04:00
|
|
|
var limit;
|
2021-07-07 15:01:21 -04:00
|
|
|
limit = inCenter-0.49;
|
|
|
|
if(inPoint <= limit)
|
|
|
|
{
|
|
|
|
return limit;
|
|
|
|
}
|
|
|
|
limit = inCenter + 0.49;
|
|
|
|
if(inPoint >= limit)
|
|
|
|
{
|
|
|
|
return limit;
|
|
|
|
}
|
2021-07-07 12:09:52 -04:00
|
|
|
|
2021-07-07 07:26:21 -04:00
|
|
|
return inPoint;
|
2021-07-07 07:00:50 -04:00
|
|
|
}
|
2021-07-07 12:09:52 -04:00
|
|
|
|
2021-07-07 15:01:21 -04:00
|
|
|
inArray[pointX] = limit(centerX, inArray[pointX]/reducer);
|
|
|
|
inArray[pointY] = limit(centerY, inArray[pointY]/reducer);
|
|
|
|
inArray[pointZ] = limit(centerZ, inArray[pointZ]/reducer);
|
2021-07-07 07:00:50 -04:00
|
|
|
};
|
2021-07-07 12:09:52 -04:00
|
|
|
let smooth = (inArray, inTimes) =>
|
2021-07-07 07:26:21 -04:00
|
|
|
{
|
2021-07-07 15:01:21 -04:00
|
|
|
let count = inArray.length/3;
|
2021-07-07 12:09:52 -04:00
|
|
|
for(let t=0; t<inTimes; t++)
|
2021-07-07 07:26:21 -04:00
|
|
|
{
|
2021-07-07 12:09:52 -04:00
|
|
|
for(let i=0; i<count; i++)
|
|
|
|
{
|
|
|
|
if(i==0)
|
|
|
|
{
|
2021-07-07 15:01:21 -04:00
|
|
|
average(inArray, i, count-1, i+1);
|
2021-07-07 12:09:52 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(i==count-1)
|
|
|
|
{
|
2021-07-07 15:01:21 -04:00
|
|
|
average(inArray, i, i-1, 0);
|
2021-07-07 12:09:52 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-07 15:01:21 -04:00
|
|
|
average(inArray, i, i-1, i+1);
|
2021-07-07 12:09:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-07 07:26:21 -04:00
|
|
|
}
|
|
|
|
}
|
2021-07-07 15:01:21 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
let testPoints =
|
|
|
|
[
|
|
|
|
0, 0, 0,
|
|
|
|
0, 1, 0,
|
|
|
|
1, 1, 0
|
|
|
|
];
|
|
|
|
console.log(testPoints);
|
|
|
|
average(testPoints, 1, 0, 2);
|
|
|
|
console.log(testPoints);
|
|
|
|
*/
|
|
|
|
|
2021-07-07 12:09:52 -04:00
|
|
|
let path = (inPoints, inSmoothing, inColor) =>
|
2021-07-07 07:26:21 -04:00
|
|
|
{
|
2021-07-07 15:01:21 -04:00
|
|
|
let clone = [...inPoints];
|
|
|
|
smooth(clone, inSmoothing);
|
2021-07-07 07:26:21 -04:00
|
|
|
const geometry = new THREE.BufferGeometry();
|
2021-07-07 15:01:21 -04:00
|
|
|
geometry.setAttribute('position', new THREE.Float32BufferAttribute( clone, 3 ));
|
2021-07-07 12:09:52 -04:00
|
|
|
const materialLine = new THREE.LineBasicMaterial( { color: inColor, linewidth: 3 } );
|
|
|
|
const materialPoint = new THREE.PointsMaterial( { color:inColor, size: 0.05 } );
|
|
|
|
const output = new THREE.Group();
|
|
|
|
|
|
|
|
output.add( new THREE.Line( geometry, materialLine ) );
|
|
|
|
output.add( new THREE.Points( geometry, materialPoint ) );
|
|
|
|
return output;
|
2021-07-07 07:26:21 -04:00
|
|
|
}
|
2021-07-07 07:00:50 -04:00
|
|
|
|
|
|
|
const points =
|
|
|
|
[
|
2021-07-07 12:09:52 -04:00
|
|
|
4, 0, 0,
|
|
|
|
3, 0, 0,
|
|
|
|
2, 0, 0,
|
|
|
|
1, 0, 0,
|
|
|
|
//
|
2021-07-07 07:00:50 -04:00
|
|
|
0, 0, 0,
|
|
|
|
0, 1, 0,
|
|
|
|
1, 1, 0,
|
|
|
|
2, 1, 0,
|
2021-07-07 12:09:52 -04:00
|
|
|
2, 2, 0,
|
|
|
|
3, 2, 0,
|
|
|
|
4, 2, 0,
|
|
|
|
4, 3, 0,
|
|
|
|
//
|
|
|
|
5, 3, 0,
|
|
|
|
5, 2, 0,
|
|
|
|
5, 1, 0,
|
|
|
|
5, 0, 0,
|
2021-07-07 07:00:50 -04:00
|
|
|
];
|
2021-07-07 07:26:21 -04:00
|
|
|
|
|
|
|
|
2021-07-07 07:00:50 -04:00
|
|
|
|
|
|
|
Scene(
|
|
|
|
{
|
|
|
|
DOM:"canvas",
|
|
|
|
Init(inScene)
|
|
|
|
{
|
2021-07-07 12:09:52 -04:00
|
|
|
inScene.add(path(points, 0, 0xFF0000));
|
2021-07-07 15:01:21 -04:00
|
|
|
inScene.add(path(points, 50, 0x00ff00));
|
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>
|