2
0
Jose Ferrao 6 жил өмнө
parent
commit
e05fadee7b

+ 6 - 15
index.html

@@ -22,15 +22,10 @@
 		canvas.height = 600;
 		canvas.height = 600;
 		document.body.appendChild(canvas);
 		document.body.appendChild(canvas);
 
 
-		//var m = matrix.elements;
-		///context.setTransform(m[0], m[3], m[1], m[4], m[2], m[5]);
-		
-		var a = new Matrix();
-		a.translate(100, 100);
-		a.rotate(1);
-		
-		var b = new Matrix();
-		b.translate(50, 20);
+
+		var o = new Object2D();
+		o.position.set(100, 100);
+		o.scale.set(1, 2);
 
 
 		var context = canvas.getContext("2d");
 		var context = canvas.getContext("2d");
 
 
@@ -39,17 +34,13 @@
 			context.setTransform(1, 0, 0, 1, 0, 0);
 			context.setTransform(1, 0, 0, 1, 0, 0);
 			context.clearRect(0, 0, canvas.width, canvas.height);
 			context.clearRect(0, 0, canvas.width, canvas.height);
 
 
-			a.rotate(0.02);
-			a.setContextTransform(context);
-			context.fillRect(0, 0, 40, 60);
+			o.rotation += 0.01;
+			o.draw(context, canvas);
 
 
 			requestAnimationFrame(loop);
 			requestAnimationFrame(loop);
 		}
 		}
 
 
 		loop();
 		loop();
-
-
-
 	</script>
 	</script>
 </body>
 </body>
 </html>
 </html>

+ 30 - 6
source/Object2D.js

@@ -48,15 +48,29 @@ function Object2D()
 	 * Local transformation matrix applied to the object. 
 	 * Local transformation matrix applied to the object. 
 	 */
 	 */
 	this.matrix = new Matrix();
 	this.matrix = new Matrix();
-
-	/**
-	 * Global transformation matrix used to project the object to screen space.
-	 */
-	this.globalMatrix = new Matrix();
 }
 }
 
 
+/**
+ * Traverse the object tree and run a function for all objects.
+ *
+ * @param callback Callback function that receives the object as parameter.
+ */
+Object2D.prototype.traverse = function(callback)
+{
+	callback(this);
+
+	var children = this.children;
+
+	for(var i = 0; i < children.length; i++)
+	{
+		children[i].traverse(callback);
+	}
+};
+
 /**
 /**
  * Attach a children to the object.
  * Attach a children to the object.
+ *
+ * @param object Object to attach to this object.
  */ 
  */ 
 Object2D.prototype.add = function(object)
 Object2D.prototype.add = function(object)
 {
 {
@@ -66,6 +80,8 @@ Object2D.prototype.add = function(object)
 
 
 /**
 /**
  * Remove object from the children list.
  * Remove object from the children list.
+ *
+ * @param object Object to be removed.
  */
  */
 Object2D.prototype.remove = function(object)
 Object2D.prototype.remove = function(object)
 {
 {
@@ -79,8 +95,16 @@ Object2D.prototype.remove = function(object)
 
 
 /**
 /**
  * Draw the object into the canvas.
  * Draw the object into the canvas.
+ *
+ * Has to be implemented by underlying classes.
+ *
+ * @param context Canvas 2d drawing context.
+ * @param canvas The canvas DOM element where its being drawn.
  */
  */
-Object2D.prototype.draw = function(context)
+Object2D.prototype.draw = function(context, canvas)
 {
 {
+	this.matrix.compose(this.position.x, this.position.y, this.scale.x, this.scale.y, this.rotation);
+	this.matrix.setContextTransform(context);
 
 
+	context.fillRect(-20, -20, 40, 40);
 };
 };

+ 31 - 0
source/Renderer.js

@@ -0,0 +1,31 @@
+"use strict";
+
+/**
+ * The renderer is resposible for drawing the structure into the canvas element.
+ *
+ * Its also resposible for managing the canvas state.
+ *
+ * @class
+ */
+function Renderer(canvas)
+{
+	this.canvas = canvas;
+}
+
+/**
+ * Render the object using the viewport into a canvas element.
+ */
+Renderer.render = function(object, viewport)
+{
+	// Update matrixes
+	this.object.traverse(function(child)
+	{
+
+	});
+
+	// Render into the canvas
+	this.object.traverse(function(child)
+	{
+
+	});
+};

+ 0 - 175
source/math/Box2.js

@@ -1,175 +0,0 @@
-"use strict";
-
-function Box2(min, max)
-{
-	this.min = (min !== undefined) ? min : new Vector2();
-	this.max = (max !== undefined) ? max : new Vector2();
-}
-
-Object.assign(Box2.prototype,
-{
-	set: function(min, max)
-	{
-		this.min.copy(min);
-		this.max.copy(max);
-
-		return this;
-	},
-
-	setFromPoints: function(points)
-	{
-		this.min = new Vector2(+Infinity, +Infinity);
-		this.max = new Vector2(-Infinity, -Infinity);
-
-		for(var i = 0, il = points.length; i < il; i++)
-		{
-			this.expandByPoint(points[i]);
-		}
-
-		return this;
-	},
-
-	setFromCenterAndSize: function()
-	{
-		var v1 = new Vector2();
-
-		return function setFromCenterAndSize(center, size)
-		{
-			var halfSize = v1.copy(size).multiplyScalar(0.5);
-			this.min.copy(center).sub(halfSize);
-			this.max.copy(center).add(halfSize);
-
-			return this;
-		};
-	}(),
-
-	clone: function()
-	{
-		var box = new Box2();
-		box.copy(this);
-		return box;
-	},
-
-	copy: function(box)
-	{
-		this.min.copy(box.min);
-		this.max.copy(box.max);
-
-		return this;
-	},
-
-
-	isEmpty: function()
-	{
-		// this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
-		return (this.max.x < this.min.x) || (this.max.y < this.min.y);
-	},
-
-	getCenter: function(target)
-	{
-		return this.isEmpty() ? target.set(0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5);
-	},
-
-	getSize: function(target)
-	{
-		return this.isEmpty() ? target.set(0, 0) : target.subVectors(this.max, this.min);
-	},
-
-	expandByPoint: function(point)
-	{
-		this.min.min(point);
-		this.max.max(point);
-
-		return this;
-	},
-
-	expandByVector: function(vector)
-	{
-		this.min.sub(vector);
-		this.max.add(vector);
-
-		return this;
-	},
-
-	expandByScalar: function(scalar)
-	{
-		this.min.addScalar(-scalar);
-		this.max.addScalar(scalar);
-
-		return this;
-	},
-
-	containsPoint: function(point)
-	{
-		return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y ? false : true;
-	},
-
-	containsBox: function(box)
-	{
-		return this.min.x <= box.min.x && box.max.x <= this.max.x && this.min.y <= box.min.y && box.max.y <= this.max.y;
-	},
-
-	getParameter: function(point, target)
-	{
-		// This can potentially have a divide by zero if the box
-		// has a size dimension of 0.
-
-		return target.set(
-			(point.x - this.min.x) / (this.max.x - this.min.x),
-			(point.y - this.min.y) / (this.max.y - this.min.y)
-		);
-	},
-
-	intersectsBox: function(box)
-	{
-		// using 4 splitting planes to rule out intersections
-		return box.max.x < this.min.x || box.min.x > this.max.x || box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
-	},
-
-	clampPoint: function(point, target)
-	{
-		return target.copy(point).clamp(this.min, this.max);
-	},
-
-	distanceToPoint: function()
-	{
-		var v1 = new Vector2();
-
-		return function distanceToPoint(point)
-		{
-			var clampedPoint = v1.copy(point).clamp(this.min, this.max);
-			return clampedPoint.sub(point).length();
-		};
-	}(),
-
-	intersect: function(box)
-	{
-		this.min.max(box.min);
-		this.max.min(box.max);
-
-		return this;
-	},
-
-	union: function(box)
-	{
-		this.min.min(box.min);
-		this.max.max(box.max);
-
-		return this;
-	},
-
-	translate: function(offset)
-	{
-		this.min.add(offset);
-		this.max.add(offset);
-
-		return this;
-	},
-
-	equals: function(box)
-	{
-		return box.min.equals(this.min) && box.max.equals(this.max);
-	}
-});
-
-//export {Box2};

+ 35 - 31
source/math/Matrix.js

@@ -7,7 +7,7 @@
  */
  */
 function Matrix(values)
 function Matrix(values)
 {
 {
-	if(value !== undefined)
+	if(values !== undefined)
 	{
 	{
 		this.m = values;
 		this.m = values;
 	}
 	}
@@ -28,6 +28,8 @@ Matrix.prototype.reset = function()
 
 
 /**
 /**
  * Multiply another matrix by this one and store the result.
  * Multiply another matrix by this one and store the result.
+ *
+ * @param mat Matrix array.
  */
  */
 Matrix.prototype.multiply = function(mat)
 Matrix.prototype.multiply = function(mat)
 {
 {
@@ -42,13 +44,35 @@ Matrix.prototype.multiply = function(mat)
 };
 };
 
 
 /**
 /**
- * Set position of the transformation matrix.
+ * Premultiply another matrix by this one and store the result.
+ *
+ * @param mat Matrix array to multiply.
  */
  */
-Matrix.prototype.setPosition = function(x, y)
+Matrix.prototype.premultiply = function(mat)
 {
 {
-	this.m[4] = x;
-	this.m[5] = y;
-}
+	var m0 = mat[0] * this.m[0] + mat[2] * this.m[1];
+	var m1 = mat[1] * this.m[0] + mat[3] * this.m[1];
+	var m2 = mat[0] * this.m[2] + mat[2] * this.m[3];
+	var m3 = mat[1] * this.m[2] + mat[3] * this.m[3];
+	var m4 = mat[0] * this.m[4] + mat[2] * this.m[5] + mat[4];
+	var m5 = mat[1] * this.m[4] + mat[3] * this.m[5] + mat[5];
+	
+	this.m = [m0, m1, m2, m3, m4, m5];
+};
+
+/**
+ * Compose this transformation matrix with position scale and rotation.
+ */
+Matrix.prototype.compose = function(px, py, sx, sy, a)
+{
+	this.m = [1, 0, 0, 1, px, py];
+
+	var c = Math.cos(a);
+	var s = Math.sin(a);
+	this.multiply([c, s, -s, c, 0, 0]);
+
+	this.scale(sx, sy);
+};
 
 
 /**
 /**
  * Apply translation to this matrix.
  * Apply translation to this matrix.
@@ -60,11 +84,13 @@ Matrix.prototype.translate = function(x, y)
 
 
 /**
 /**
  * Apply rotation to this matrix.
  * Apply rotation to this matrix.
+ *
+ * @param angle Angle in radians.
  */
  */
-Matrix.prototype.rotate = function(rAngle)
+Matrix.prototype.rotate = function(angle)
 {
 {
-	var c = Math.cos(rAngle);
-	var s = Math.sin(rAngle);
+	var c = Math.cos(angle);
+	var s = Math.sin(angle);
 	var mat = [c, s, -s, c, 0, 0];
 	var mat = [c, s, -s, c, 0, 0];
 
 
 	this.multiply(mat);
 	this.multiply(mat);
@@ -111,25 +137,3 @@ Matrix.prototype.setContextTransform = function(context)
 {
 {
 	context.setTransform(this.m[0], this.m[1], this.m[2], this.m[3], this.m[4], this.m[5]);
 	context.setTransform(this.m[0], this.m[1], this.m[2], this.m[3], this.m[4], this.m[5]);
 };
 };
-
-/*
-	var screenPoint=(transformedX, transformedY) =>
-	{
-		// invert
-		var d =1/(this.m[0] * this.m[3] - this.m[1] * this.m[2]);
-		var im = [m[3] * d, -m[1] * d, -m[2] * d, this.m[0] * d, d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]), d * (this.m[1] * this.m[4] - this.m[0] * this.m[5])];
-
-		// point
-		return(
-		{
-			x: transformedX * im[0] + transformedY * im[2] + im[4],
-			y: transformedX * im[1] + transformedY * im[3] + im[5]
-		});
-	};
-
-	var transformedPoint = (screenX, screenY) => (
-	{
-		x: screenX * this.m[0] + screenY * this.m[2] + this.m[4],
-		y: screenX * this.m[1] + screenY * this.m[3] + this.m[5]
-	});
-*/

+ 0 - 330
source/math/Matrix3.js

@@ -1,330 +0,0 @@
-"use strict";
-
-function Matrix3()
-{
-	this.elements = [
-		1, 0, 0,
-		0, 1, 0,
-		0, 0, 1
-	];
-}
-
-Object.assign(Matrix3.prototype,
-{
-	set: function(n11, n12, n13, n21, n22, n23, n31, n32, n33)
-	{
-		var te = this.elements;
-
-		te[0] = n11;
-		te[1] = n21;
-		te[2] = n31;
-		te[3] = n12;
-		te[4] = n22;
-		te[5] = n32;
-		te[6] = n13;
-		te[7] = n23;
-		te[8] = n33;
-	},
-
-	identity: function()
-	{
-		this.set(
-			1, 0, 0,
-			0, 1, 0,
-			0, 0, 1
-		);
-	},
-
-	clone: function()
-	{
-		var m = new Matrix3();
-		m.fromArray(this.elements);
-		return m;
-	},
-
-	copy: function(m)
-	{
-		var te = this.elements;
-		var me = m.elements;
-
-		te[0] = me[0];
-		te[1] = me[1];
-		te[2] = me[2];
-		te[3] = me[3];
-		te[4] = me[4];
-		te[5] = me[5];
-		te[6] = me[6];
-		te[7] = me[7];
-		te[8] = me[8];
-	},
-
-	multiply: function(m)
-	{
-		return this.multiplyMatrices(this, m);
-	},
-
-	premultiply: function(m)
-	{
-		return this.multiplyMatrices(m, this);
-	},
-
-	multiplyMatrices: function(a, b)
-	{
-		var ae = a.elements;
-		var be = b.elements;
-		var te = this.elements;
-
-		var a11 = ae[0],
-			a12 = ae[3],
-			a13 = ae[6];
-		var a21 = ae[1],
-			a22 = ae[4],
-			a23 = ae[7];
-		var a31 = ae[2],
-			a32 = ae[5],
-			a33 = ae[8];
-
-		var b11 = be[0],
-			b12 = be[3],
-			b13 = be[6];
-		var b21 = be[1],
-			b22 = be[4],
-			b23 = be[7];
-		var b31 = be[2],
-			b32 = be[5],
-			b33 = be[8];
-
-		te[0] = a11 * b11 + a12 * b21 + a13 * b31;
-		te[3] = a11 * b12 + a12 * b22 + a13 * b32;
-		te[6] = a11 * b13 + a12 * b23 + a13 * b33;
-
-		te[1] = a21 * b11 + a22 * b21 + a23 * b31;
-		te[4] = a21 * b12 + a22 * b22 + a23 * b32;
-		te[7] = a21 * b13 + a22 * b23 + a23 * b33;
-
-		te[2] = a31 * b11 + a32 * b21 + a33 * b31;
-		te[5] = a31 * b12 + a32 * b22 + a33 * b32;
-		te[8] = a31 * b13 + a32 * b23 + a33 * b33;
-	},
-
-	multiplyScalar: function(s)
-	{
-		var te = this.elements;
-
-		te[0] *= s;
-		te[3] *= s;
-		te[6] *= s;
-		te[1] *= s;
-		te[4] *= s;
-		te[7] *= s;
-		te[2] *= s;
-		te[5] *= s;
-		te[8] *= s;
-	},
-
-	determinant: function()
-	{
-		var te = this.elements;
-
-		var a = te[0],
-			b = te[1],
-			c = te[2],
-			d = te[3],
-			e = te[4],
-			f = te[5],
-			g = te[6],
-			h = te[7],
-			i = te[8];
-
-		return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
-	},
-
-	getInverse: function(matrix, throwOnDegenerate)
-	{
-		var me = matrix.elements,
-			te = this.elements,
-
-			n11 = me[0],
-			n21 = me[1],
-			n31 = me[2],
-			n12 = me[3],
-			n22 = me[4],
-			n32 = me[5],
-			n13 = me[6],
-			n23 = me[7],
-			n33 = me[8],
-
-			t11 = n33 * n22 - n32 * n23,
-			t12 = n32 * n13 - n33 * n12,
-			t13 = n23 * n12 - n22 * n13,
-
-			det = n11 * t11 + n21 * t12 + n31 * t13;
-
-		if(det === 0)
-		{
-			if(throwOnDegenerate === true)
-			{
-				throw new Error(".getInverse() cant invert matrix, determinant is 0");
-			}
-
-			return this.identity();
-		}
-
-		var detInv = 1 / det;
-
-		te[0] = t11 * detInv;
-		te[1] = (n31 * n23 - n33 * n21) * detInv;
-		te[2] = (n32 * n21 - n31 * n22) * detInv;
-
-		te[3] = t12 * detInv;
-		te[4] = (n33 * n11 - n31 * n13) * detInv;
-		te[5] = (n31 * n12 - n32 * n11) * detInv;
-
-		te[6] = t13 * detInv;
-		te[7] = (n21 * n13 - n23 * n11) * detInv;
-		te[8] = (n22 * n11 - n21 * n12) * detInv;
-	},
-
-	transpose: function()
-	{
-		var tmp, m = this.elements;
-
-		tmp = m[1];
-		m[1] = m[3];
-		m[3] = tmp;
-		tmp = m[2];
-		m[2] = m[6];
-		m[6] = tmp;
-		tmp = m[5];
-		m[5] = m[7];
-		m[7] = tmp;
-	},
-
-	getNormalMatrix: function(matrix4)
-	{
-		return this.setFromMatrix4(matrix4).getInverse(this).transpose();
-	},
-
-	transposeIntoArray: function(r)
-	{
-		var m = this.elements;
-
-		r[0] = m[0];
-		r[1] = m[3];
-		r[2] = m[6];
-		r[3] = m[1];
-		r[4] = m[4];
-		r[5] = m[7];
-		r[6] = m[2];
-		r[7] = m[5];
-		r[8] = m[8];
-	},
-
-	setUvTransform: function(tx, ty, sx, sy, rotation, cx, cy)
-	{
-		var c = Math.cos(rotation);
-		var s = Math.sin(rotation);
-
-		this.set(
-			sx * c, sx * s, -sx * (c * cx + s * cy) + cx + tx,
-			-sy * s, sy * c, -sy * (-s * cx + c * cy) + cy + ty,
-			0, 0, 1
-		);
-	},
-
-	scale: function(sx, sy)
-	{
-		var te = this.elements;
-
-		te[0] *= sx;
-		te[3] *= sx;
-		te[6] *= sx;
-		te[1] *= sy;
-		te[4] *= sy;
-		te[7] *= sy;
-	},
-
-	rotate: function(theta)
-	{
-		var c = Math.cos(theta);
-		var s = Math.sin(theta);
-
-		var te = this.elements;
-
-		var a11 = te[0],
-			a12 = te[3],
-			a13 = te[6];
-		var a21 = te[1],
-			a22 = te[4],
-			a23 = te[7];
-
-		te[0] = c * a11 + s * a21;
-		te[3] = c * a12 + s * a22;
-		te[6] = c * a13 + s * a23;
-
-		te[1] = -s * a11 + c * a21;
-		te[4] = -s * a12 + c * a22;
-		te[7] = -s * a13 + c * a23;
-	},
-
-	translate: function(tx, ty)
-	{
-		var te = this.elements;
-
-		te[0] += tx * te[2];
-		te[3] += tx * te[5];
-		te[6] += tx * te[8];
-		te[1] += ty * te[2];
-		te[4] += ty * te[5];
-		te[7] += ty * te[8];
-	},
-
-	equals: function(matrix)
-	{
-		var te = this.elements;
-		var me = matrix.elements;
-
-		for(var i = 0; i < 9; i++)
-		{
-
-			if(te[i] !== me[i]) return false;
-
-		}
-
-		return true;
-	},
-
-	fromArray: function(array, offset)
-	{
-		if(offset === undefined) offset = 0;
-
-		for(var i = 0; i < 9; i++)
-		{
-			this.elements[i] = array[i + offset];
-		}
-	},
-
-	toArray: function(array, offset)
-	{
-		if(array === undefined) array = [];
-		if(offset === undefined) offset = 0;
-
-		var te = this.elements;
-
-		array[offset] = te[0];
-		array[offset + 1] = te[1];
-		array[offset + 2] = te[2];
-
-		array[offset + 3] = te[3];
-		array[offset + 4] = te[4];
-		array[offset + 5] = te[5];
-
-		array[offset + 6] = te[6];
-		array[offset + 7] = te[7];
-		array[offset + 8] = te[8];
-
-		return array;
-	}
-});
-
-//export {Matrix3};

+ 1 - 1
source/math/UUID.js

@@ -27,6 +27,7 @@ UUID.generate = (function ()
 		var d1 = Math.random() * 0xffffffff | 0;
 		var d1 = Math.random() * 0xffffffff | 0;
 		var d2 = Math.random() * 0xffffffff | 0;
 		var d2 = Math.random() * 0xffffffff | 0;
 		var d3 = Math.random() * 0xffffffff | 0;
 		var d3 = Math.random() * 0xffffffff | 0;
+
 		var uuid = lut[ d0 & 0xff ] + lut[ d0 >> 8 & 0xff ] + lut[ d0 >> 16 & 0xff ] + lut[ d0 >> 24 & 0xff ] + "-" +
 		var uuid = lut[ d0 & 0xff ] + lut[ d0 >> 8 & 0xff ] + lut[ d0 >> 16 & 0xff ] + lut[ d0 >> 24 & 0xff ] + "-" +
 			lut[ d1 & 0xff ] + lut[ d1 >> 8 & 0xff ] + "-" + lut[ d1 >> 16 & 0x0f | 0x40 ] + lut[ d1 >> 24 & 0xff ] + "-" +
 			lut[ d1 & 0xff ] + lut[ d1 >> 8 & 0xff ] + "-" + lut[ d1 >> 16 & 0x0f | 0x40 ] + lut[ d1 >> 24 & 0xff ] + "-" +
 			lut[ d2 & 0x3f | 0x80 ] + lut[ d2 >> 8 & 0xff ] + "-" + lut[ d2 >> 16 & 0xff ] + lut[ d2 >> 24 & 0xff ] +
 			lut[ d2 & 0x3f | 0x80 ] + lut[ d2 >> 8 & 0xff ] + "-" + lut[ d2 >> 16 & 0xff ] + lut[ d2 >> 24 & 0xff ] +
@@ -34,7 +35,6 @@ UUID.generate = (function ()
 
 
 		return uuid.toUpperCase();
 		return uuid.toUpperCase();
 	};
 	};
-
 })();
 })();
 
 
 //export {UUID};
 //export {UUID};

+ 0 - 364
source/math/Vector3.js

@@ -1,364 +0,0 @@
-"use strict";
-
-function Vector3(x, y, z)
-{
-	this.x = x || 0;
-	this.y = y || 0;
-	this.z = z || 0;
-}
-
-Object.assign(Vector3.prototype,
-{
-	set: function(x, y, z)
-	{
-		this.x = x;
-		this.y = y;
-		this.z = z;
-	},
-
-	setScalar: function(scalar)
-	{
-		this.x = scalar;
-		this.y = scalar;
-		this.z = scalar;
-	},
-
-	clone: function()
-	{
-		return new Vector3(this.x, this.y, this.z);
-	},
-
-	copy: function(v)
-	{
-		this.x = v.x;
-		this.y = v.y;
-		this.z = v.z;
-	},
-
-	add: function(v, w)
-	{
-		this.x += v.x;
-		this.y += v.y;
-		this.z += v.z;
-	},
-
-	addScalar: function(s)
-	{
-		this.x += s;
-		this.y += s;
-		this.z += s;
-	},
-
-	addVectors: function(a, b)
-	{
-		this.x = a.x + b.x;
-		this.y = a.y + b.y;
-		this.z = a.z + b.z;
-	},
-
-	addScaledVector: function(v, s)
-	{
-		this.x += v.x * s;
-		this.y += v.y * s;
-		this.z += v.z * s;
-	},
-
-	sub: function(v, w)
-	{
-		this.x -= v.x;
-		this.y -= v.y;
-		this.z -= v.z;
-	},
-
-	subScalar: function(s)
-	{
-
-		this.x -= s;
-		this.y -= s;
-		this.z -= s;
-	},
-
-	subVectors: function(a, b)
-	{
-
-		this.x = a.x - b.x;
-		this.y = a.y - b.y;
-		this.z = a.z - b.z;
-	},
-
-	multiply: function(v, w)
-	{
-		this.x *= v.x;
-		this.y *= v.y;
-		this.z *= v.z;
-	},
-
-	multiplyScalar: function(scalar)
-	{
-		this.x *= scalar;
-		this.y *= scalar;
-		this.z *= scalar;
-	},
-
-	multiplyVectors: function(a, b)
-	{
-		this.x = a.x * b.x;
-		this.y = a.y * b.y;
-		this.z = a.z * b.z;
-	},
-
-	divide: function(v)
-	{
-		this.x /= v.x;
-		this.y /= v.y;
-		this.z /= v.z;
-	},
-
-	divideScalar: function(scalar)
-	{
-		return this.multiplyScalar(1 / scalar);
-	},
-
-	min: function(v)
-	{
-		this.x = Math.min(this.x, v.x);
-		this.y = Math.min(this.y, v.y);
-		this.z = Math.min(this.z, v.z);
-	},
-
-	max: function(v)
-	{
-		this.x = Math.max(this.x, v.x);
-		this.y = Math.max(this.y, v.y);
-		this.z = Math.max(this.z, v.z);
-	},
-
-	clamp: function(min, max)
-	{
-		// assumes min < max, componentwise
-
-		this.x = Math.max(min.x, Math.min(max.x, this.x));
-		this.y = Math.max(min.y, Math.min(max.y, this.y));
-		this.z = Math.max(min.z, Math.min(max.z, this.z));
-	},
-
-	clampScalar: function(minVal, maxVal)
-	{
-		this.x = Math.max(minVal, Math.min(maxVal, this.x));
-		this.y = Math.max(minVal, Math.min(maxVal, this.y));
-		this.z = Math.max(minVal, Math.min(maxVal, this.z));
-	},
-
-	clampLength: function(min, max)
-	{
-		var length = this.length();
-
-		return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
-	},
-
-	floor: function()
-	{
-		this.x = Math.floor(this.x);
-		this.y = Math.floor(this.y);
-		this.z = Math.floor(this.z);
-	},
-
-	ceil: function()
-	{
-		this.x = Math.ceil(this.x);
-		this.y = Math.ceil(this.y);
-		this.z = Math.ceil(this.z);
-	},
-
-	round: function()
-	{
-		this.x = Math.round(this.x);
-		this.y = Math.round(this.y);
-		this.z = Math.round(this.z);
-	},
-
-	roundToZero: function()
-	{
-		this.x = (this.x < 0) ? Math.ceil(this.x) : Math.floor(this.x);
-		this.y = (this.y < 0) ? Math.ceil(this.y) : Math.floor(this.y);
-		this.z = (this.z < 0) ? Math.ceil(this.z) : Math.floor(this.z);
-	},
-
-	negate: function()
-	{
-		this.x = -this.x;
-		this.y = -this.y;
-		this.z = -this.z;
-	},
-
-	dot: function(v)
-	{
-		return this.x * v.x + this.y * v.y + this.z * v.z;
-	},
-
-	lengthSquared: function()
-	{
-		return this.x * this.x + this.y * this.y + this.z * this.z;
-	},
-
-	length: function()
-	{
-		return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
-	},
-
-	manhattanLength: function()
-	{
-		return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
-	},
-
-	normalize: function()
-	{
-		return this.divideScalar(this.length() || 1);
-	},
-
-	setLength: function(length)
-	{
-		return this.normalize().multiplyScalar(length);
-	},
-
-	lerp: function(v, alpha)
-	{
-		this.x += (v.x - this.x) * alpha;
-		this.y += (v.y - this.y) * alpha;
-		this.z += (v.z - this.z) * alpha;
-	},
-
-	lerpVectors: function(v1, v2, alpha)
-	{
-		return this.subVectors(v2, v1).multiplyScalar(alpha).add(v1);
-	},
-
-	cross: function(v, w)
-	{
-		return this.crossVectors(this, v);
-	},
-
-	crossVectors: function(a, b)
-	{
-
-		var ax = a.x,
-			ay = a.y,
-			az = a.z;
-		var bx = b.x,
-			by = b.y,
-			bz = b.z;
-
-		this.x = ay * bz - az * by;
-		this.y = az * bx - ax * bz;
-		this.z = ax * by - ay * bx;
-	},
-
-	projectOnVector: function(vector)
-	{
-		var scalar = vector.dot(this) / vector.lengthSq();
-
-		return this.copy(vector).multiplyScalar(scalar);
-	},
-
-	/**
-	 * Reflect incident vector off plane orthogonal to normal, normal is assumed to have unit length.
-	 */
-	reflect: function()
-	{
-		var v1 = new Vector3();
-
-		return function reflect(normal)
-		{
-			return this.sub(v1.copy(normal).multiplyScalar(2 * this.dot(normal)));
-		};
-
-	}(),
-
-	angleTo: function(v)
-	{
-		var theta = this.dot(v) / (Math.sqrt(this.lengthSq() * v.lengthSq()));
-		return Math.acos(theta);
-	},
-
-	distanceTo: function(v)
-	{
-		return Math.sqrt(this.distanceToSquared(v));
-	},
-
-	distanceToSquared: function(v)
-	{
-		var dx = this.x - v.x,
-			dy = this.y - v.y,
-			dz = this.z - v.z;
-
-		return dx * dx + dy * dy + dz * dz;
-	},
-
-	manhattanDistanceTo: function(v)
-	{
-		return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
-	},
-
-	setFromSpherical: function(s)
-	{
-		return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
-	},
-
-	setFromSphericalCoords: function(radius, phi, theta)
-	{
-		var sinPhiRadius = Math.sin(phi) * radius;
-
-		this.x = sinPhiRadius * Math.sin(theta);
-		this.y = Math.cos(phi) * radius;
-		this.z = sinPhiRadius * Math.cos(theta);
-	},
-
-	setFromCylindrical: function(c)
-	{
-		return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
-	},
-
-	setFromCylindricalCoords: function(radius, theta, y)
-	{
-		this.x = radius * Math.sin(theta);
-		this.y = y;
-		this.z = radius * Math.cos(theta);
-	},
-
-	setFromMatrixPosition: function(m)
-	{
-		var e = m.elements;
-
-		this.x = e[12];
-		this.y = e[13];
-		this.z = e[14];
-	},
-
-	equals: function(v)
-	{
-		return ((v.x === this.x) && (v.y === this.y) && (v.z === this.z));
-	},
-
-	fromArray: function(array, offset)
-	{
-		if(offset === undefined) offset = 0;
-
-		this.x = array[offset];
-		this.y = array[offset + 1];
-		this.z = array[offset + 2];
-	},
-
-	toArray: function(array, offset)
-	{
-		if(array === undefined) array = [];
-		if(offset === undefined) offset = 0;
-
-		array[offset] = this.x;
-		array[offset + 1] = this.y;
-		array[offset + 2] = this.z;
-
-		return array;
-	}
-});
-
-//export {Vector3};