Browse Source

Changed *Library approach.
This will avoid ending up with arrays full of nulls.

Mr.doob 13 years ago
parent
commit
5365e0c512
4 changed files with 20 additions and 12 deletions
  1. 5 3
      src/core/Geometry.js
  2. 5 3
      src/core/Object3D.js
  3. 5 3
      src/materials/Material.js
  4. 5 3
      src/textures/Texture.js

+ 5 - 3
src/core/Geometry.js

@@ -8,10 +8,10 @@
 
 
 THREE.Geometry = function () {
 THREE.Geometry = function () {
 
 
-	this.id = THREE.GeometryLibrary.length;
-
 	THREE.GeometryLibrary.push( this );
 	THREE.GeometryLibrary.push( this );
 
 
+	this.id = THREE.GeometryIdCount ++;
+
 	this.name = '';
 	this.name = '';
 
 
 	this.vertices = [];
 	this.vertices = [];
@@ -677,10 +677,12 @@ THREE.Geometry.prototype = {
 
 
 	deallocate: function () {
 	deallocate: function () {
 
 
-		THREE.GeometryLibrary[ this.id ] = null;
+		var index = THREE.GeometryLibrary.indexOf( this );
+		if ( index !== -1 ) THREE.GeometryLibrary.splice( index, 1 );
 
 
 	}
 	}
 
 
 };
 };
 
 
+THREE.GeometryIdCount = 0;
 THREE.GeometryLibrary = [];
 THREE.GeometryLibrary = [];

+ 5 - 3
src/core/Object3D.js

@@ -6,10 +6,10 @@
 
 
 THREE.Object3D = function () {
 THREE.Object3D = function () {
 
 
-	this.id = THREE.Object3DLibrary.length;
-
 	THREE.Object3DLibrary.push( this );
 	THREE.Object3DLibrary.push( this );
 
 
+	this.id = THREE.Object3DIdCount ++;
+
 	this.name = '';
 	this.name = '';
 	this.properties = {};
 	this.properties = {};
 
 
@@ -347,7 +347,8 @@ THREE.Object3D.prototype = {
 
 
 	deallocate: function () {
 	deallocate: function () {
 
 
-		THREE.Object3DLibrary[ this.id ] = null;
+		var index = THREE.Object3DLibrary.indexOf( this );
+		if ( index !== -1 ) THREE.Object3DLibrary.splice( index, 1 );
 
 
 	}
 	}
 
 
@@ -356,4 +357,5 @@ THREE.Object3D.prototype = {
 THREE.Object3D.__m1 = new THREE.Matrix4();
 THREE.Object3D.__m1 = new THREE.Matrix4();
 THREE.Object3D.defaultEulerOrder = 'XYZ',
 THREE.Object3D.defaultEulerOrder = 'XYZ',
 
 
+THREE.Object3DIdCount = 0;
 THREE.Object3DLibrary = [];
 THREE.Object3DLibrary = [];

+ 5 - 3
src/materials/Material.js

@@ -5,10 +5,10 @@
 
 
 THREE.Material = function () {
 THREE.Material = function () {
 
 
-	this.id = THREE.MaterialLibrary.length;
-
 	THREE.MaterialLibrary.push( this );
 	THREE.MaterialLibrary.push( this );
 
 
+	this.id = THREE.MaterialIdCount ++;
+
 	this.name = '';
 	this.name = '';
 
 
 	this.side = THREE.FrontSide;
 	this.side = THREE.FrontSide;
@@ -118,8 +118,10 @@ THREE.Material.prototype.clone = function ( material ) {
 
 
 THREE.Material.prototype.deallocate = function () {
 THREE.Material.prototype.deallocate = function () {
 
 
-	THREE.MaterialLibrary[ this.id ] = null;
+	var index = THREE.MaterialLibrary.indexOf( this );
+	if ( index !== -1 ) THREE.MaterialLibrary.splice( index, 1 );
 
 
 };
 };
 
 
+THREE.MaterialIdCount = 0;
 THREE.MaterialLibrary = [];
 THREE.MaterialLibrary = [];

+ 5 - 3
src/textures/Texture.js

@@ -6,10 +6,10 @@
 
 
 THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
 THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
 
 
-	this.id = THREE.TextureLibrary.length;
-
 	THREE.TextureLibrary.push( this );
 	THREE.TextureLibrary.push( this );
 
 
+	this.id = THREE.TextureIdCount ++;
+
 	this.image = image;
 	this.image = image;
 
 
 	this.mapping = mapping !== undefined ? mapping : new THREE.UVMapping();
 	this.mapping = mapping !== undefined ? mapping : new THREE.UVMapping();
@@ -73,10 +73,12 @@ THREE.Texture.prototype = {
 
 
 	deallocate: function () {
 	deallocate: function () {
 
 
-		THREE.TextureLibrary[ this.id ] = null;
+		var index = THREE.TextureLibrary.indexOf( this );
+		if ( index !== -1 ) THREE.TextureLibrary.splice( index, 1 );
 
 
 	}
 	}
 
 
 };
 };
 
 
+THREE.TextureIdCount = 0;
 THREE.TextureLibrary = [];
 THREE.TextureLibrary = [];