123 lines
3.0 KiB
HTML
123 lines
3.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>meshoptimizer - demo</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
|
<style>
|
|
body {
|
|
font-family: Monospace;
|
|
background-color: #000;
|
|
color: #fff;
|
|
margin: 0px;
|
|
overflow: hidden;
|
|
}
|
|
#info {
|
|
color: #fff;
|
|
position: absolute;
|
|
top: 10px;
|
|
width: 100%;
|
|
text-align: center;
|
|
z-index: 100;
|
|
display:block;
|
|
}
|
|
#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="info">
|
|
<a href="https://github.com/zeux/meshoptimizer" target="_blank" rel="noopener">meshoptimizer</a>
|
|
</div>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/99/three.min.js"></script>
|
|
|
|
<script src="../js/decoder.js"></script>
|
|
<script src="../tools/OptMeshLoader.js"></script>
|
|
|
|
<script>
|
|
var container;
|
|
|
|
var camera, scene, renderer;
|
|
|
|
var windowHalfX = window.innerWidth / 2;
|
|
var windowHalfY = window.innerHeight / 2;
|
|
|
|
var timers = {};
|
|
|
|
console.time = function(label) {
|
|
timers[label] = performance.now();
|
|
};
|
|
|
|
console.timeEnd = function(label) {
|
|
var time = performance.now() - timers[label];
|
|
document.getElementById('info').append(label + " took " + time.toFixed(2) + " ms");
|
|
};
|
|
|
|
init();
|
|
animate();
|
|
|
|
function init()
|
|
{
|
|
container = document.createElement('div');
|
|
document.body.appendChild(container);
|
|
|
|
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.01, 100);
|
|
camera.position.y = 1.0;
|
|
camera.position.z = 3.0;
|
|
|
|
scene = new THREE.Scene();
|
|
|
|
var ambientLight = new THREE.AmbientLight(0xcccccc, 0.2);
|
|
scene.add(ambientLight);
|
|
|
|
var pointLight = new THREE.PointLight(0xffffff, 0.8);
|
|
pointLight.position.set(3, 3, 0);
|
|
camera.add(pointLight);
|
|
scene.add(camera);
|
|
|
|
var onProgress = function (xhr) {};
|
|
var onError = function () {};
|
|
|
|
new THREE.OptMeshLoader()
|
|
.setDecoder(MeshoptDecoder)
|
|
.setMaterials(null) // materials can be fetched using MTLLoader
|
|
.setPath('./')
|
|
.load('pirate.optmesh', function (object)
|
|
{
|
|
scene.add(object);
|
|
}, onProgress, onError);
|
|
|
|
renderer = new THREE.WebGLRenderer();
|
|
renderer.setPixelRatio(window.devicePixelRatio);
|
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
container.appendChild(renderer.domElement);
|
|
|
|
window.addEventListener('resize', onWindowResize, false);
|
|
}
|
|
|
|
function onWindowResize()
|
|
{
|
|
windowHalfX = window.innerWidth / 2;
|
|
windowHalfY = window.innerHeight / 2;
|
|
|
|
camera.aspect = window.innerWidth / window.innerHeight;
|
|
camera.updateProjectionMatrix();
|
|
|
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
}
|
|
|
|
function animate()
|
|
{
|
|
requestAnimationFrame(animate);
|
|
render();
|
|
}
|
|
|
|
function render()
|
|
{
|
|
renderer.render(scene, camera);
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|