瀏覽代碼

Using RFC4122, version 4 for ids instead of incremental number.

Mr.doob 12 年之前
父節點
當前提交
76f65d7fdb
共有 6 個文件被更改,包括 42 次插入14 次删除
  1. 1 1
      src/core/BufferGeometry.js
  2. 1 3
      src/core/Geometry.js
  3. 2 4
      src/core/Object3D.js
  4. 1 3
      src/materials/Material.js
  5. 36 0
      src/math/Math.js
  6. 1 3
      src/textures/Texture.js

+ 1 - 1
src/core/BufferGeometry.js

@@ -4,7 +4,7 @@
 
 THREE.BufferGeometry = function () {
 
-	this.id = THREE.GeometryIdCount ++;
+	this.id = THREE.Math.uuid();
 
 	// attributes
 

+ 1 - 3
src/core/Geometry.js

@@ -9,7 +9,7 @@
 
 THREE.Geometry = function () {
 
-	this.id = THREE.GeometryIdCount ++;
+	this.id = THREE.Math.uuid();
 
 	this.name = '';
 	this.uuid = '';
@@ -803,5 +803,3 @@ THREE.Geometry.prototype = {
 	}
 
 };
-
-THREE.GeometryIdCount = 0;

+ 2 - 4
src/core/Object3D.js

@@ -7,7 +7,7 @@
 
 THREE.Object3D = function () {
 
-	this.id = THREE.Object3DIdCount ++;
+	this.id = THREE.Math.uuid();
 
 	this.name = '';
 	this.uuid = '';
@@ -496,6 +496,4 @@ THREE.Object3D.prototype = {
 
 };
 
-THREE.Object3D.defaultEulerOrder = 'XYZ',
-
-THREE.Object3DIdCount = 0;
+THREE.Object3D.defaultEulerOrder = 'XYZ';

+ 1 - 3
src/materials/Material.js

@@ -5,7 +5,7 @@
 
 THREE.Material = function () {
 
-	this.id = THREE.MaterialIdCount ++;
+	this.id = THREE.Math.uuid();
 
 	this.name = '';
 	this.uuid = '';
@@ -132,5 +132,3 @@ THREE.Material.prototype = {
 	}
 
 };
-
-THREE.MaterialIdCount = 0;

+ 36 - 0
src/math/Math.js

@@ -4,6 +4,42 @@
 
 THREE.Math = {
 
+	uuid: function () {
+
+		// http://www.broofa.com/Tools/Math.uuid.htm
+		
+		var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
+		var uuid = new Array(36);
+		var rnd = 0, r;
+
+		return function () {
+
+			for ( var i = 0; i < 36; i ++ ) {
+
+				if ( i == 8 || i == 13 || i == 18 || i == 23 ) {
+			
+					uuid[ i ] = '-';
+			
+				} else if ( i == 14 ) {
+			
+					uuid[ i ] = '4';
+			
+				} else {
+			
+					if (rnd <= 0x02) rnd = 0x2000000 + (Math.random()*0x1000000)|0;
+					r = rnd & 0xf;
+					rnd = rnd >> 4;
+					uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
+
+				}
+			}
+			
+			return uuid.join('');
+
+		};
+
+	}(),
+
 	// Clamp value to range <a, b>
 
 	clamp: function ( x, a, b ) {

+ 1 - 3
src/textures/Texture.js

@@ -6,7 +6,7 @@
 
 THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
 
-	this.id = THREE.TextureIdCount ++;
+	this.id = THREE.Math.uuid();
 
 	this.name = '';
 	this.uuid = '';
@@ -88,5 +88,3 @@ THREE.Texture.prototype = {
 	}
 
 };
-
-THREE.TextureIdCount = 0;