Many Lights Problem
pucks as point lights
by chuby0307
HTML
<div id="info">Many Lights?! Solution!</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 pucks = [];
var which = 1;
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(0xffffff, 0.3);
};
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 newPuck() {
var puck = new Puck();
puck.pos = new THREE.Vector3(0, 1, 0);
puck.vel = new THREE.Vector3(150 * (Math.random() * 2 - 1), 0, 170 * (Math.random() * 2 - 1));
puck.pColor = new THREE.Color(0xff0000);
puck.mesh = new THREE.Mesh(new THREE.CylinderGeometry(5, 5, 2, 20),
new THREE.MeshBasicMaterial());
puck.mesh.material.color = puck.pColor;
scene.add(puck.mesh);
scene.add(puck.pointLight);
return puck;
}
function init() {
scene...