2
0
Эх сурвалжийг харах

Reverted to uint vased ids. Added uuid property.
Pheww... Glad that I figured this out in time.

Mr.doob 12 жил өмнө
parent
commit
72f94e88dd

+ 11 - 11
editor/js/Sidebar.Object3D.js

@@ -11,20 +11,20 @@ Sidebar.Object3D = function ( signals ) {
 
 	// id
 
-	var objectIdRow = new UI.Panel();
-	var objectId = new UI.Input().setWidth( '115px' ).setColor( '#444' ).setFontSize( '12px' ).setDisabled( true );
-	var objectIdRenew = new UI.Button( '⟳' ).setMarginLeft( '7px' ).onClick( function () {
+	var objectUUIDRow = new UI.Panel();
+	var objectUUID = new UI.Input().setWidth( '115px' ).setColor( '#444' ).setFontSize( '12px' ).setDisabled( true );
+	var objectUUIDRenew = new UI.Button( '⟳' ).setMarginLeft( '7px' ).onClick( function () {
 
-		objectId.setValue( THREE.Math.generateUUID() );
+		objectUUID.setValue( THREE.Math.generateUUID() );
 		update();
 
 	} );
 
-	objectIdRow.add( new UI.Text( 'Id' ).setWidth( '90px' ).setColor( '#666' ) );
-	objectIdRow.add( objectId );
-	objectIdRow.add( objectIdRenew );
+	objectUUIDRow.add( new UI.Text( 'Id' ).setWidth( '90px' ).setColor( '#666' ) );
+	objectUUIDRow.add( objectUUID );
+	objectUUIDRow.add( objectUUIDRenew );
 
-	container.add( objectIdRow );
+	container.add( objectUUIDRow );
 
 	// name
 
@@ -266,12 +266,12 @@ Sidebar.Object3D = function ( signals ) {
 
 		if ( selected ) {
 
-			selected.id = objectId.getValue();
+			selected.uuid = objectUUID.getValue();
 			selected.name = objectName.getValue();
 
 			if ( selected.parent !== undefined ) {
 
-				var newParentId = objectParent.getValue();
+				var newParentId = parseInt( objectParent.getValue() );
 
 				if ( selected.parent.id !== newParentId && selected.id !== newParentId ) {
 
@@ -488,7 +488,7 @@ Sidebar.Object3D = function ( signals ) {
 
 		objectType.setValue( getObjectInstanceName( object ) );
 
-		objectId.setValue( object.id );
+		objectUUID.setValue( object.uuid );
 		objectName.setValue( object.name );
 
 		if ( object.parent !== undefined ) {

+ 1 - 1
editor/js/Sidebar.Scene.js

@@ -107,7 +107,7 @@ Sidebar.Scene = function ( signals ) {
 
 	function updateOutliner() {
 
-		var id = outliner.getValue();
+		var id = parseInt( outliner.getValue() );
 
 		scene.traverse( function ( node ) {
 

+ 9 - 21
editor/js/libs/ui.js

@@ -355,26 +355,6 @@ UI.FancySelect.prototype.setOptions = function ( options ) {
 
 	scope.options = [];
 
-	var generateOptionCallback = function ( element, value ) {
-
-		return function ( event ) {
-
-			for ( var i = 0; i < scope.options.length; i ++ ) {
-
-				scope.options[ i ].style.backgroundColor = '#f0f0f0';
-
-			}
-
-			element.style.backgroundColor = '#f0f0f0';
-
-			scope.selectedValue = value;
-
-			scope.dom.dispatchEvent( changeEvent );
-
-		}
-
-	};
-
 	for ( var key in options ) {
 
 		var option = document.createElement( 'div' );
@@ -385,7 +365,13 @@ UI.FancySelect.prototype.setOptions = function ( options ) {
 		scope.dom.appendChild( option );
 
 		scope.options.push( option );
-		option.addEventListener( 'click', generateOptionCallback( option, key ), false );
+
+		option.addEventListener( 'click', function ( event ) {
+
+			scope.setValue( this.value );
+			scope.dom.dispatchEvent( changeEvent );
+
+		}, false );
 
 	}
 
@@ -401,6 +387,8 @@ UI.FancySelect.prototype.getValue = function () {
 
 UI.FancySelect.prototype.setValue = function ( value ) {
 
+	if ( typeof value === 'number' ) value = value.toString();
+
 	for ( var i = 0; i < this.options.length; i ++ ) {
 
 		var element = this.options[ i ];

+ 1 - 1
examples/js/exporters/MaterialExporter.js

@@ -18,7 +18,7 @@ THREE.MaterialExporter.prototype = {
 			}
 		};
 
-		output.id = material.id;
+		output.uuid = material.uuid;
 
 		if ( material.name !== "" ) output.name = material.name;
 

+ 8 - 8
examples/js/exporters/ObjectExporter.js

@@ -33,11 +33,11 @@ THREE.ObjectExporter.prototype = {
 
 			}
 
-			if ( geometries[ geometry.id ] === undefined ) {
+			if ( geometries[ geometry.uuid ] === undefined ) {
 
 				var data = {};
 
-				data.id = geometry.id;
+				data.uuid = geometry.uuid;
 
 				if ( geometry.name !== "" ) data.name = geometry.name;
 
@@ -115,13 +115,13 @@ THREE.ObjectExporter.prototype = {
 
 				}
 
-				geometries[ geometry.id ] = data;
+				geometries[ geometry.uuid ] = data;
 
 				output.geometries.push( data );
 
 			}
 
-			return geometry.id;
+			return geometry.uuid;
 
 		};
 
@@ -138,19 +138,19 @@ THREE.ObjectExporter.prototype = {
 
 			}
 
-			if ( materials[ material.id ] === undefined ) {
+			if ( materials[ material.uuid ] === undefined ) {
 
 				var data = materialExporter.parse( material );
 
 				delete data.metadata;
 
-				materials[ material.id ] = data;
+				materials[ material.uuid ] = data;
 
 				output.materials.push( data );
 
 			}
 
-			return material.id;
+			return material.uuid;
 
 		};
 
@@ -160,7 +160,7 @@ THREE.ObjectExporter.prototype = {
 
 			var data = {};
 
-			data.id = object.id;
+			data.uuid = object.uuid;
 
 			if ( object.name !== '' ) data.name = object.name;
 			if ( JSON.stringify( object.userData ) !== '{}' ) data.userData = object.userData;

+ 2 - 1
src/core/BufferGeometry.js

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

+ 4 - 1
src/core/Geometry.js

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

+ 3 - 1
src/core/Object3D.js

@@ -7,7 +7,8 @@
 
 THREE.Object3D = function () {
 
-	this.id = THREE.Math.generateUUID();
+	this.id = THREE.Object3DIdCount ++;
+	this.uuid = THREE.Math.generateUUID();
 
 	this.name = '';
 
@@ -542,3 +543,4 @@ THREE.Object3D.prototype = {
 };
 
 THREE.Object3D.defaultEulerOrder = 'XYZ';
+THREE.Object3DIdCount = 0;

+ 9 - 6
src/loaders/ObjectLoader.js

@@ -151,10 +151,11 @@ THREE.ObjectLoader.prototype = {
 
 				}
 
-				if ( data.id !== undefined ) geometry.id = data.id;
+				geometry.uuid = data.uuid;
+
 				if ( data.name !== undefined ) geometry.name = data.name;
 
-				geometries[ data.id ] = geometry;
+				geometries[ data.uuid ] = geometry;
 
 			}
 
@@ -177,10 +178,11 @@ THREE.ObjectLoader.prototype = {
 				var data = json[ i ];
 				var material = loader.parse( data );
 
-				if ( data.id !== undefined ) material.id = data.id;
+				material.uuid = data.uuid;
+
 				if ( data.name !== undefined ) material.name = data.name;
 
-				materials[ data.id ] = material;
+				materials[ data.uuid ] = material;
 
 			}
 
@@ -275,6 +277,9 @@ THREE.ObjectLoader.prototype = {
 
 			}
 
+			object.uuid = data.uuid;
+
+			if ( data.name !== undefined ) object.name = data.name;
 			if ( data.matrix !== undefined ) {
 
 				matrix.fromArray( data.matrix );
@@ -288,8 +293,6 @@ THREE.ObjectLoader.prototype = {
 
 			}
 
-			if ( data.id !== undefined ) object.id = data.id;
-			if ( data.name !== undefined ) object.name = data.name;
 			if ( data.visible !== undefined ) object.visible = data.visible;
 			if ( data.userData !== undefined ) object.userData = data.userData;
 

+ 4 - 1
src/materials/Material.js

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

+ 4 - 1
src/textures/Texture.js

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