Jelajahi Sumber

Serialize name in BufferGeometry.toJSON()

Takahiro 6 tahun lalu
induk
melakukan
d06ece0767
2 mengubah file dengan 8 tambahan dan 2 penghapusan
  1. 5 1
      src/core/BufferGeometry.js
  2. 3 1
      src/loaders/BufferGeometryLoader.js

+ 5 - 1
src/core/BufferGeometry.js

@@ -1003,13 +1003,17 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 			var array = Array.prototype.slice.call( attribute.array );
 
-			data.data.attributes[ key ] = {
+			var attributeData = {
 				itemSize: attribute.itemSize,
 				type: attribute.array.constructor.name,
 				array: array,
 				normalized: attribute.normalized
 			};
 
+			if ( attribute.name !== '' ) attributeData.name = attribute.name;
+
+			data.data.attributes[ key ] = attributeData;
+
 		}
 
 		var morphAttributes = {};

+ 3 - 1
src/loaders/BufferGeometryLoader.js

@@ -51,7 +51,9 @@ Object.assign( BufferGeometryLoader.prototype, {
 			var attribute = attributes[ key ];
 			var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
 
-			geometry.addAttribute( key, new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ) );
+			var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
+			if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
+			geometry.addAttribute( key, bufferAttribute );
 
 		}