|
<!doctype HTML> |
|
<html lang="en"> |
|
<head> |
|
<title>PointCloud Example</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 { |
|
color: #cccccc; |
|
font-family:Monospace; |
|
font-size:13px; |
|
text-align:center; |
|
|
|
background-color: #050505; |
|
margin: 0px; |
|
overflow: hidden; |
|
} |
|
|
|
#info { |
|
position: absolute; |
|
top: 0px; width: 100%; |
|
padding: 5px; |
|
} |
|
|
|
a { |
|
color: #0080ff; |
|
} |
|
</style> |
|
|
|
<script type="text/javascript"> |
|
|
|
var woker = new Worker('/static/doWork.js'); |
|
woker.addEventListener('message', function(e){ |
|
addPointCloud(e.data.vertices,e.data.colors); |
|
},false); |
|
|
|
window.onload = function () { |
|
var conn; |
|
var msg = document.getElementById("msg"); |
|
|
|
//var isUpdate = false; |
|
|
|
if (window["WebSocket"]) { |
|
conn = new WebSocket("ws://localhost:8080/ws"); |
|
conn.binaryType = 'arraybuffer'; |
|
conn.onclose = function (evt) { |
|
console.log("Connection closed"); |
|
}; |
|
conn.onmessage = function (evt) { |
|
var data = evt.data; |
|
if (data.byteLength > 2000){ |
|
woker.postMessage(data); |
|
} |
|
}; |
|
} else { |
|
var item = document.createElement("div"); |
|
item.innerHTML = "<b>Your browser does not support WebSockets.</b>"; |
|
appendLog(item); |
|
} |
|
}; |
|
</script> |
|
</head> |
|
<body> |
|
<div id="container"></div> |
|
<script src="/static/three.js"></script> |
|
<script src="/static/js/Detector.js"></script> |
|
<script src="/static/js/libs/stats.min.js"></script> |
|
|
|
<script> |
|
init(); |
|
animate(); |
|
|
|
if ( ! Detector.webgl ) Detector.addGetWebGLMessage(); |
|
|
|
var container, stats; |
|
|
|
var camera, scene, renderer; |
|
|
|
var points, material, geometry; |
|
|
|
var animationID; |
|
|
|
function init() { |
|
|
|
isRun = true; |
|
container = document.getElementById( 'container' ); |
|
//camera = new THREE.PerspectiveCamera( 27, window.innerWidth / window.innerHeight, 5, 1000 ); |
|
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 0.3, 1000 ); |
|
camera.position.z = -1; |
|
camera.lookAt(new THREE.Vector3(0, 0, 0)); |
|
|
|
scene = new THREE.Scene(); |
|
scene.background = new THREE.Color( 0x050505 ); |
|
scene.fog = new THREE.Fog( 0x050505, 2000, 3500 ); |
|
|
|
renderer = new THREE.WebGLRenderer(); |
|
renderer.setPixelRatio( window.devicePixelRatio ); |
|
renderer.setSize( window.innerWidth, window.innerHeight ); |
|
|
|
renderer.context.canvas.addEventListener("webglcontextlost", function(event) { |
|
isRun = false; |
|
event.preventDefault(); |
|
var cancelAnimationFrame = |
|
window.cancelAnimationFrame || |
|
window.mozCancelAnimationFrame; |
|
cancelAnimationFrame(animationID); |
|
|
|
}, false); |
|
|
|
renderer.context.canvas.addEventListener("webglcontextrestored", function(event) { |
|
isRun = true; |
|
}, false); |
|
|
|
container.appendChild( renderer.domElement ); |
|
|
|
material = new THREE.PointsMaterial( { size: 0.010, vertexColors: THREE.VertexColors } ); |
|
|
|
stats = new Stats(); |
|
container.appendChild( stats.dom ); |
|
window.addEventListener( 'resize', onWindowResize, false ); |
|
} |
|
|
|
function onWindowResize() { |
|
camera.aspect = window.innerWidth / window.innerHeight; |
|
camera.updateProjectionMatrix(); |
|
renderer.setSize( window.innerWidth, window.innerHeight ); |
|
} |
|
|
|
function addPointCloud(vertices, colors){ |
|
if (!isRun) return; |
|
if (geometry != null) |
|
geometry.dispose(); |
|
geometry = new THREE.BufferGeometry(); |
|
geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) ); |
|
geometry.addAttribute( 'color', new THREE.Float32BufferAttribute( colors, 3 ) ); |
|
geometry.computeBoundingSphere(); |
|
|
|
scene.remove(points); |
|
points = new THREE.Points( geometry, material ); |
|
scene.add(points); |
|
} |
|
|
|
function animate() { |
|
animationID = requestAnimationFrame( animate ); |
|
render(); |
|
stats.update(); |
|
} |
|
|
|
function render() { |
|
renderer.render( scene, camera ); |
|
} |
|
|
|
</script> |
|
</body> |
|
</html> |