From 580b71811baa1975ae6b8e8a1f01d0432e222a28 Mon Sep 17 00:00:00 2001 From: astrodud Date: Thu, 20 Jan 2011 12:35:06 +0800 Subject: [PATCH 1/4] one fewer Matrix4 created in Projector.unProjectVector --- src/renderers/Projector.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/renderers/Projector.js b/src/renderers/Projector.js index 540d2bb4..2e7995f2 100644 --- a/src/renderers/Projector.js +++ b/src/renderers/Projector.js @@ -364,9 +364,10 @@ THREE.Projector = function() { this.unprojectVector = function ( vector, camera ) { - var matrix = new THREE.Matrix4(); + var matrix = THREE.Matrix4.makeInvert( camera.matrix ); + + matrix.multiplySelf( THREE.Matrix4.makeInvert( camera.projectionMatrix ) ); - matrix.multiply( THREE.Matrix4.makeInvert( camera.matrix ), THREE.Matrix4.makeInvert( camera.projectionMatrix ) ); matrix.multiplyVector3( vector ); return vector; From 7bdf079f83eaf09ebc0048baec3d146ab97ca171 Mon Sep 17 00:00:00 2001 From: astrodud Date: Thu, 20 Jan 2011 12:58:13 +0800 Subject: [PATCH 2/4] * memory and speed optimizations in Matrix4.flatten() * memory and speed optimizations in Matrix4.makeInvert3x3() (moved Matrix4.m33 to WebGLRenderer._m33 since it is only used there and only for a single Matrix4) --- src/core/Matrix4.js | 54 ++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/core/Matrix4.js b/src/core/Matrix4.js index 999e9666..b06ddefe 100644 --- a/src/core/Matrix4.js +++ b/src/core/Matrix4.js @@ -13,9 +13,6 @@ THREE.Matrix4 = function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33 this.n31 = n31 || 0; this.n32 = n32 || 0; this.n33 = n33 || 1; this.n34 = n34 || 0; this.n41 = n41 || 0; this.n42 = n42 || 0; this.n43 = n43 || 0; this.n44 = n44 || 1; - this.flat = new Array( 16 ); - this.m33 = new THREE.Matrix3(); - }; THREE.Matrix4.prototype = { @@ -270,27 +267,29 @@ THREE.Matrix4.prototype = { flatten: function() { - this.flat[ 0 ] = this.n11; - this.flat[ 1 ] = this.n21; - this.flat[ 2 ] = this.n31; - this.flat[ 3 ] = this.n41; + var flat = THREE.Matrix4.__flat; - this.flat[ 4 ] = this.n12; - this.flat[ 5 ] = this.n22; - this.flat[ 6 ] = this.n32; - this.flat[ 7 ] = this.n42; + flat[ 0 ] = this.n11; + flat[ 1 ] = this.n21; + flat[ 2 ] = this.n31; + flat[ 3 ] = this.n41; - this.flat[ 8 ] = this.n13; - this.flat[ 9 ] = this.n23; - this.flat[ 10 ] = this.n33; - this.flat[ 11 ] = this.n43; + flat[ 4 ] = this.n12; + flat[ 5 ] = this.n22; + flat[ 6 ] = this.n32; + flat[ 7 ] = this.n42; - this.flat[ 12 ] = this.n14; - this.flat[ 13 ] = this.n24; - this.flat[ 14 ] = this.n34; - this.flat[ 15 ] = this.n44; + flat[ 8 ] = this.n13; + flat[ 9 ] = this.n23; + flat[ 10 ] = this.n33; + flat[ 11 ] = this.n43; - return this.flat; + flat[ 12 ] = this.n14; + flat[ 13 ] = this.n24; + flat[ 14 ] = this.n34; + flat[ 15 ] = this.n44; + + return flat; }, @@ -478,13 +477,13 @@ THREE.Matrix4.makeInvert = function ( m1 ) { }; -THREE.Matrix4.makeInvert3x3 = function ( m1 ) { +THREE.Matrix4.makeInvert3x3 = function ( m1, m2 ) { - // input: THREE.Matrix4, output: THREE.Matrix3 + // input: m1: THREE.Matrix4, m2: THREE.Matrix3; output: THREE.Matrix3 (m2) // ( based on http://code.google.com/p/webgl-mjs/ ) - var m = m1.flatten(), - m2 = m1.m33, + var m = m1.flatten(), + m2m = m2.m, a11 = m[ 10 ] * m[ 5 ] - m[ 6 ] * m[ 9 ], a21 = - m[ 10 ] * m[ 1 ] + m[ 2 ] * m[ 9 ], @@ -503,9 +502,9 @@ THREE.Matrix4.makeInvert3x3 = function ( m1 ) { idet = 1.0 / det; - m2.m[ 0 ] = idet * a11; m2.m[ 1 ] = idet * a21; m2.m[ 2 ] = idet * a31; - m2.m[ 3 ] = idet * a12; m2.m[ 4 ] = idet * a22; m2.m[ 5 ] = idet * a32; - m2.m[ 6 ] = idet * a13; m2.m[ 7 ] = idet * a23; m2.m[ 8 ] = idet * a33; + m2m[ 0 ] = idet * a11; m2m[ 1 ] = idet * a21; m2m[ 2 ] = idet * a31; + m2m[ 3 ] = idet * a12; m2m[ 4 ] = idet * a22; m2m[ 5 ] = idet * a32; + m2m[ 6 ] = idet * a13; m2m[ 7 ] = idet * a23; m2m[ 8 ] = idet * a33; return m2; @@ -569,3 +568,4 @@ THREE.Matrix4.makeOrtho = function ( left, right, top, bottom, near, far ) { THREE.Matrix4.__tmpVec1 = new THREE.Vector3(); THREE.Matrix4.__tmpVec2 = new THREE.Vector3(); THREE.Matrix4.__tmpVec3 = new THREE.Vector3(); +THREE.Matrix4.__flat = new Array( 16 ); From c62db7e43d5995b819b263a012550d8e038cd4d7 Mon Sep 17 00:00:00 2001 From: astrodud Date: Thu, 20 Jan 2011 12:59:48 +0800 Subject: [PATCH 3/4] removed object lookups in transpose() --- src/core/Matrix3.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/Matrix3.js b/src/core/Matrix3.js index bdd685d9..9ee75bd5 100644 --- a/src/core/Matrix3.js +++ b/src/core/Matrix3.js @@ -8,11 +8,11 @@ THREE.Matrix3.prototype = { transpose: function () { - var tmp; + var tmp, m = this.m; - tmp = this.m[1]; this.m[1] = this.m[3]; this.m[3] = tmp; - tmp = this.m[2]; this.m[2] = this.m[6]; this.m[6] = tmp; - tmp = this.m[5]; this.m[5] = this.m[7]; this.m[7] = tmp; + 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; return this; From 50dc834a0acd67c1040223a71fb1bfb6eccdbaa1 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Sun, 23 Jan 2011 17:53:40 +0000 Subject: [PATCH 4/4] Updated years in LICENSE. Removed Flattr button from README. --- LICENSE | 2 +- README.md | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index 52670a64..aa453f47 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License -Copyright (c) 2010 Three.js Authors. All rights reserved. +Copyright (c) 2010-2011 Three.js Authors. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index e5c5e044..de334622 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ three.js #### Javascript 3D Engine #### -[![Flattr this](http://api.flattr.com/button/button-compact-static-100x17.png)](http://flattr.com/thing/287/three-js) - The aim of this project is to create a lightweight 3D engine with a very low level of abstraction (aka for dummies). Currently the examples are the documentation. Be aware that the API may change from revision to revision breaking backwards compatibility. The engine can render using <canvas>, <svg> and WebGL.