voxel/index.html

94 lines
2.0 KiB
HTML
Raw Normal View History

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:00:50 -04:00
let average = (inPoints, inCenter) =>
2021-07-05 20:51:08 -04:00
{
2021-07-07 07:00:50 -04:00
let output = [0, 0, 0];
for(let i=0; i<inPoints.length; i+=3)
{
output[0] += inPoints[i+0];
output[1] += inPoints[i+1];
output[2] += inPoints[i+2];
}
let scalar = inPoints.length/3;
output[0] /= scalar;
output[1] /= scalar;
output[2] /= scalar;
let limit = (inShifted) =>
{
if(inShifted < -0.5)
{
return -0.5;
}
if(inShifted > 0.5)
{
return 0.5;
}
return inShifted;
}
output[0] = limit(output[0] - inCenter[0]);
output[1] = limit(output[1] - inCenter[1]);
output[2] = limit(output[2] - inCenter[2]);
return output;
};
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
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.Float32BufferAttribute( points, 3 ));
const material = new THREE.LineBasicMaterial( { color: 0x0000ff, linewidth: 3 } );
const line = new THREE.Line( geometry, material );
Scene(
{
DOM:"canvas",
Init(inScene)
{
inScene.add( line );
},
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>