ソースを参照

Texture: Add userData. (#22698)

Michael Herzog 3 年 前
コミット
a8813be04a

+ 5 - 0
docs/api/en/textures/Texture.html

@@ -257,6 +257,11 @@
 		Set this to *true* to trigger an update next time the texture is used. Particularly important for setting the wrap mode.
 		</p>
 
+		<h3>[property:Object userData]</h3>
+		<p>
+		An object that can be used to store custom data about the texture. It should not hold
+		references to functions as these will not be cloned.
+		</p>
 
 		<h2>Methods</h2>
 

+ 5 - 0
docs/api/zh/textures/Texture.html

@@ -256,6 +256,11 @@
 			这对于设置包裹模式尤其重要。
 		</p>
 
+		<h3>[property:Object userData]</h3>
+		<p>
+		An object that can be used to store custom data about the texture. It should not hold
+		references to functions as these will not be cloned.
+		</p>
 
 		<h2>方法</h2>
 

+ 2 - 0
src/loaders/ObjectLoader.js

@@ -696,6 +696,8 @@ class ObjectLoader extends Loader {
 				if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
 				if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
 
+				if ( data.userData !== undefined ) texture.userData = data.userData;
+
 				textures[ data.uuid ] = texture;
 
 			}

+ 6 - 0
src/textures/Texture.js

@@ -65,6 +65,8 @@ class Texture extends EventDispatcher {
 		// update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
 		this.encoding = encoding;
 
+		this.userData = {};
+
 		this.version = 0;
 		this.onUpdate = null;
 
@@ -119,6 +121,8 @@ class Texture extends EventDispatcher {
 		this.unpackAlignment = source.unpackAlignment;
 		this.encoding = source.encoding;
 
+		this.userData = JSON.parse( JSON.stringify( source.userData ) );
+
 		return this;
 
 	}
@@ -225,6 +229,8 @@ class Texture extends EventDispatcher {
 
 		}
 
+		if ( JSON.stringify( this.userData ) !== '{}' ) output.userData = this.userData;
+
 		if ( ! isRootObject ) {
 
 			meta.textures[ this.uuid ] = output;