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>
|
|
|
|
<script type="module">
|
|
|
|
import { Region, Kernel } from "./region.js";
|
|
|
|
|
|
|
|
let r = Region.Create();
|
|
|
|
let filler = (x, y, z)=>
|
|
|
|
{
|
2021-07-05 21:36:52 -04:00
|
|
|
r.voxels[Region.I(x, y, z)] = true;
|
2021-07-05 20:51:08 -04:00
|
|
|
};
|
|
|
|
filler(1, 1, 1);
|
|
|
|
Kernel.Loop(Kernel.Corners, [1, 1, 1], filler);
|
|
|
|
Kernel.Loop(Kernel.Cardinal, [1, 1, 1], filler);
|
|
|
|
|
|
|
|
Region.Surface(r);
|
|
|
|
</script>
|
|
|
|
<script type="module">
|
|
|
|
|
|
|
|
import * as T from 'http://esm.sh/three';
|
|
|
|
import { OrbitControls } from 'http://esm.sh/three/examples/jsm/controls/OrbitControls.js';
|
|
|
|
|
|
|
|
const renderer = new T.WebGLRenderer({canvas:document.querySelector("canvas")});
|
|
|
|
const scene = new T.Scene();
|
|
|
|
const camera = new T.PerspectiveCamera(80, 2, 0.1, 10);
|
|
|
|
const light = new T.DirectionalLight(0xFFFFFF, 1);
|
|
|
|
const geometry = new T.BoxGeometry(1, 1, 1);
|
|
|
|
const shader = new T.MeshPhongMaterial({color:0xFFCC00});
|
|
|
|
const object = new T.Mesh(geometry, shader);
|
|
|
|
|
|
|
|
const controls = new OrbitControls(camera, renderer.domElement);
|
|
|
|
controls.update();
|
|
|
|
|
|
|
|
scene.add(light);
|
|
|
|
scene.add(object);
|
|
|
|
|
|
|
|
light.position.set(-1, 2, 4);
|
|
|
|
camera.position.set(0, 0, 2);
|
|
|
|
|
|
|
|
let dirty = false;
|
|
|
|
const update = inTime =>
|
|
|
|
{
|
|
|
|
let timeNew = new Date();
|
|
|
|
let timeDelta = timeNew - inTime;
|
|
|
|
|
|
|
|
let delta = timeDelta * 0.001;
|
|
|
|
object.rotation.x += delta;
|
|
|
|
|
|
|
|
controls.update();
|
|
|
|
|
|
|
|
dirty = true;
|
|
|
|
|
|
|
|
setTimeout(()=>update(timeNew), 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
const render = inTime =>
|
|
|
|
{
|
|
|
|
if(dirty)
|
|
|
|
{
|
|
|
|
renderer.render(scene, camera);
|
|
|
|
dirty = false;
|
|
|
|
}
|
|
|
|
requestAnimationFrame(render);
|
|
|
|
}
|
|
|
|
|
|
|
|
const resize = () =>
|
|
|
|
{
|
|
|
|
let canvas = renderer.domElement;
|
|
|
|
camera.aspect = canvas.clientWidth / canvas.clientHeight;
|
|
|
|
camera.updateProjectionMatrix();
|
|
|
|
renderer.setSize(canvas.clientWidth, canvas.clientHeight, false);
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener("resize", resize);
|
|
|
|
resize();
|
|
|
|
render(0);
|
|
|
|
update(new Date());
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|