3d-interface/js/l3d/apps/stream-demo/main.js

92 lines
2.5 KiB
JavaScript
Raw Normal View History

var meshNumber = 25;
2015-06-15 16:04:19 +01:00
var renderer, scene, controls, cube, container, plane, mouse= {x:0, y:0}, sphere, sphereLoader;
2015-04-07 15:05:43 +01:00
var bigmesh;
var raycaster;
var objects = [];
var spheres = new Array(meshNumber);
2015-04-07 15:05:43 +01:00
var visible = 0;
2015-06-09 16:36:21 +01:00
var previousTime;
2015-04-07 15:05:43 +01:00
var loader;
var containerSize = {width: 1067, height: 600};
2015-04-07 15:05:43 +01:00
init();
animate();
function init() {
// on initialise le moteur de rendu
container = document.getElementById('container');
container.style.height = containerSize.height + 'px';
container.style.width = containerSize.width + 'px';
2015-04-07 15:05:43 +01:00
renderer = new THREE.WebGLRenderer({alpha:"true"});
renderer.setSize(containerSize.width, containerSize.height);
2015-04-07 15:05:43 +01:00
renderer.shadowMapEnabled = true;
// renderer.setClearColor(0x000000);
document.getElementById('container').appendChild(renderer.domElement);
// on initialise la scène
scene = new THREE.Scene();
raycaster = new THREE.Raycaster();
// init light
var directionalLight = new THREE.DirectionalLight(0x999999);
directionalLight.position.set(1, 0.5, 1).normalize();
directionalLight.castShadow = true;
scene.add(directionalLight);
2015-04-07 15:05:43 +01:00
var ambientLight = new THREE.AmbientLight(0x333333);
scene.add(ambientLight);
2015-04-07 15:05:43 +01:00
// on initialise la camera que lon place ensuite sur la scène
camera = new L3D.Camera(50, containerSize.width / containerSize.height, 1, 100000);
2015-04-07 15:05:43 +01:00
scene.add(camera);
window.addEventListener('resize', onWindowResize, false);
// Load the scene
2015-06-09 16:36:21 +01:00
// loader = new THREE.OBJLoader();
sphereLoader = new L3D.ProgressiveLoader('/static/data/spheres/' + params.get.res + '.obj', scene, null);
2015-06-15 16:04:19 +01:00
sphereLoader.load();
sphere = sphereLoader.obj;
2015-04-07 15:05:43 +01:00
2015-07-01 15:31:43 +01:00
plane = new L3D.Plane(1000,1000);
2015-04-07 15:05:43 +01:00
plane.translate(0,0,-100);
plane.addToScene(scene);
2015-06-30 13:21:51 +01:00
setInterval(animate, 20);
2015-04-07 15:05:43 +01:00
}
function animate() {
2015-06-30 13:21:51 +01:00
// requestAnimationFrame(animate);
2015-04-07 15:05:43 +01:00
2015-06-09 16:36:21 +01:00
var currentTime = Date.now() - previousTime;
camera.update(isNaN(currentTime) ? 20 : currentTime);
previousTime = Date.now();
2015-04-07 15:05:43 +01:00
camera.look();
2015-06-09 16:36:21 +01:00
// sphere.addFace();
2015-04-07 15:05:43 +01:00
renderer.render(scene, camera);
}
function onWindowResize() {
camera.aspect = container.offsetWidth / container.offsetHeight;
camera.updateProjectionMatrix();
renderer.setSize(container.offsetWidth, container.offsetHeight);
renderer.render(scene, camera);
}
function hide(object) {
object.traverse(function(object) {object.visible = false;});
}
function show(object) {
object.traverse(function(object) {object.visible = true;});
}
function click(event) {
// Nope
}