Skip to content

Instantly share code, notes, and snippets.

@addam
Created December 4, 2018 14:42
Show Gist options
  • Save addam/6065b324a60f3a7c0a1d15913fbfbaad to your computer and use it in GitHub Desktop.
Save addam/6065b324a60f3a7c0a1d15913fbfbaad to your computer and use it in GitHub Desktop.
A minimalist x3d viewer (useful for debugging postgis queries)
<html>
<head>
<title>X3D Viewer</title>
<script type='text/javascript' src='http://www.x3dom.org/download/x3dom.js'> </script>
<style>
canvas {
border: 1px solid gray;
}
</style>
</head>
<body>
Select a .x3d file: <input type="file" accept="model/x3d+xml" onchange="handleFiles(this.files)"><br>
<x3d width='600px' height='400px' id='dropArea'>
<scene>
<shape id='myShape'>
<appearance>
<material diffuseColor='1 0 0'></material>
</appearance>
<box></box>
</shape>
</scene>
</x3d>
</body>
<script>
function handleFiles(files) {
var reader = new FileReader();
reader.onload = ((e) => {
var shape = document.getElementById("myShape");
shape.removeChild(shape.lastElementChild);
shape.innerHTML += e.target.result;
});
reader.readAsText(files[0]);
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment