After creating a 3D Object using Three.js examples, I noticed that it works perfectly in Chrome and IE 11, but for some reason, it's not loading on Firefox. I am currently using the latest version of Firefox (FF 27.0).
When I tested the code on Firefox in my application, I encountered this error specifically in Firefox:
Below is the code snippet: HTML
<div id="container"></div>
JS
// revolutions per second
var angularSpeed = 0.2;
var lastTime = 0;
// animation function
function animate() {
// update
var time = (new Date()).getTime();
var timeDiff = time - lastTime;
var angleChange = angularSpeed * timeDiff * 2 * Math.PI / 1000;
cylinder.rotation.x += angleChange;
cylinder.rotation.z += angleChange;
lastTime = time;
// render
renderer.render(scene, camera);
// request new frame
requestAnimationFrame(function () {
animate();
});
}
// create renderer
var container = document.getElementById("container");
var renderer = new THREE.WebGLRenderer();
renderer.setSize(container.offsetWidth, container.offsetHeight);
container.appendChild(renderer.domElement);
// setup camera
var camera = new THREE.PerspectiveCamera(55, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.z = 700;
// scene
var scene = new THREE.Scene();
// add cylinder to scene
var cylinder = new THREE.Mesh(new THREE.CylinderGeometry(150, 150, 400, 100, 100, false), new THREE.MeshPhongMaterial({
specular: '#cccccc',
color: '#666666',
emissive: '#444444',
shininess: 100
}));
cylinder.overdraw = true;
cylinder.rotation.x = Math.PI * 0.2;
scene.add(cylinder);
// add ambient lighting
var ambientLight = new THREE.AmbientLight(0x222222);
scene.add(ambientLight);
// directional lighting
var directionalLight = new THREE.DirectionalLight(0xffffff);
directionalLight.position.set(1, 1, 1).normalize();
scene.add(directionalLight);
// start animation loop
animate();
FIDDLE link for reference: http://jsfiddle.net/Mvz2b/1/
If you require additional information or have any suggestions, feel free to let me know.
Please advise accordingly.