Browse Source

Merge pull request #13921 from takahirox/BufferGeometryUserData

Add userData to BufferGeometry
Mr.doob 7 years ago
parent
commit
a24fe06a50
3 changed files with 14 additions and 0 deletions
  1. 6 0
      docs/api/core/BufferGeometry.html
  2. 7 0
      src/core/BufferGeometry.js
  3. 1 0
      src/loaders/ObjectLoader.js

+ 6 - 0
docs/api/core/BufferGeometry.html

@@ -185,6 +185,12 @@
 		Optional name for this bufferGeometry instance. Default is an empty string.
 		</p>
 
+		<h3>[property:Object userData]</h3>
+		<p>
+		An object that can be used to store custom data about the BufferGeometry. It should not hold
+		references to functions as these will not be cloned.
+		</p>
+
 		<h3>[property:String uuid]</h3>
 		<p>
 		[link:http://en.wikipedia.org/wiki/Universally_unique_identifier UUID] of this object instance.

+ 7 - 0
src/core/BufferGeometry.js

@@ -38,6 +38,8 @@ function BufferGeometry() {
 
 	this.drawRange = { start: 0, count: Infinity };
 
+	this.userData = {};
+
 }
 
 BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
@@ -928,6 +930,7 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 		data.uuid = this.uuid;
 		data.type = this.type;
 		if ( this.name !== '' ) data.name = this.name;
+		if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
 
 		if ( this.parameters !== undefined ) {
 
@@ -1121,6 +1124,10 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 		this.drawRange.start = source.drawRange.start;
 		this.drawRange.count = source.drawRange.count;
 
+		// user data
+
+		this.userData = source.userData;
+
 		return this;
 
 	},

+ 1 - 0
src/loaders/ObjectLoader.js

@@ -400,6 +400,7 @@ Object.assign( ObjectLoader.prototype, {
 				geometry.uuid = data.uuid;
 
 				if ( data.name !== undefined ) geometry.name = data.name;
+				if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
 
 				geometries[ data.uuid ] = geometry;