Many Lights Problem
pucks as point lights
by jmchen
HTML
<div id="info">Many Lights?!</div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r70/three.min.js"></script>
<script src="https://dl.dropboxusercontent.com/u/3587259/Code/Threejs/OrbitControls.js">
</script>
CSS
#info {
position: absolute;
top: 0px;
width: 100%;
padding: 10px;
text-align: center;
color: #ffff00
}
body {
overflow: hidden;
}
JavaScript
var camera, scene, renderer, geometry, material, mesh, controls;
var clock = new THREE.Clock();
//var puck, puck2;
var pucks = [];
var Puck = function () {
this.vel = new THREE.Vector3();
this.pos = new THREE.Vector3();
this.pColor = new THREE.Color();
this.mesh = new THREE.Mesh();
this.pointLight = new THREE.PointLight();
};
Puck.prototype.update = function (dt) {
this.pos.add(this.vel.clone().multiplyScalar(dt));
this.mesh.position.copy(this.pos);
this.pointLight.position.set(this.pos.x, 10, this.pos.z);
this.pointLight.color = this.pColor;
this.mesh.material.color = this.pColor;
};
Puck.prototype.collision = function () {
// collision
if (this.pos.x > 100) {
this.pos.x = 100;
this.vel.set(-this.vel.x, 0, this.vel.z);
this.pColor.setHSL(Math.random(), Math.random(), Math.random() / 2 + 0.5);
} else if (this.pos.x < -100) {
this.pos.x = -100;
this.vel.set(-this.vel.x, 0, this.vel.z);
this.pColor.setHSL(Math.random(), Math.random(), Math.random() / 2 + 0.5);
}
if (this.pos.z > 100) {
this.pos.z = 100;
this.vel.set(this.vel.x, 0, -this.vel.z);
this.pColor.setHSL(Math.random(), Math.random(), Math.random() / 2 + 0.5);
} else if (this.pos.z < -100) {
this.pos.z = -100;
this.vel.set(this.vel.x, 0, -this.vel.z);
this.pColor.setHSL(Math.random(), Math.random(), Math.random() / 2 + 0.5);
}
}
init();
animate();
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.z = 500;
scene.add(camera);
geometry = new THREE.BoxGeometry(220, 30, 10);
material = new THREE.MeshBasicMaterial({
transparent: true,
color: 0xffffff,
opacity: 0.4
});
mesh = new THREE.Mesh(geometry, material);
mesh.position.set(0, 15, 105);
scene.add(mesh);
mesh2 =...