瀏覽代碼

Merge pull request #11915 from twittmann/GLTF2_Material_Extras

Gltf2 material extras
Mr.doob 8 年之前
父節點
當前提交
d4af29e838
共有 3 個文件被更改,包括 13 次插入2 次删除
  1. 6 1
      docs/api/materials/Material.html
  2. 3 1
      examples/js/loaders/GLTF2Loader.js
  3. 4 0
      src/materials/Material.js

+ 6 - 1
docs/api/materials/Material.html

@@ -252,7 +252,12 @@
 		<div>
 		<div>
 		Defines whether this material is visible. Default is *true*.
 		Defines whether this material is visible. Default is *true*.
 		</div>
 		</div>
-
+		
+		<h3>[property:object userData]</h3>
+		<div>
+		An object that can be used to store custom data about the Material. It should not hold
+		references to functions as these will not be cloned.
+		</div>
 
 
 		<h2>Methods</h2>
 		<h2>Methods</h2>
 
 

+ 3 - 1
examples/js/loaders/GLTF2Loader.js

@@ -2226,7 +2226,9 @@ THREE.GLTF2Loader = ( function () {
 				// Normal map textures use OpenGL conventions:
 				// Normal map textures use OpenGL conventions:
 				// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#materialnormaltexture
 				// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#materialnormaltexture
 				_material.normalScale.x = -1;
 				_material.normalScale.x = -1;
-
+				
+				_material.userData = material.extras;
+				
 				return _material;
 				return _material;
 
 
 			} );
 			} );

+ 4 - 0
src/materials/Material.js

@@ -62,6 +62,8 @@ function Material() {
 	this.visible = true;
 	this.visible = true;
 
 
 	this.needsUpdate = true;
 	this.needsUpdate = true;
+	
+	this.userData = {};
 
 
 }
 }
 
 
@@ -153,6 +155,7 @@ Object.assign( Material.prototype, EventDispatcher.prototype, {
 		data.type = this.type;
 		data.type = this.type;
 
 
 		if ( this.name !== '' ) data.name = this.name;
 		if ( this.name !== '' ) data.name = this.name;
+		if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
 
 
 		if ( this.color && this.color.isColor ) data.color = this.color.getHex();
 		if ( this.color && this.color.isColor ) data.color = this.color.getHex();
 
 
@@ -331,6 +334,7 @@ Object.assign( Material.prototype, EventDispatcher.prototype, {
 		}
 		}
 
 
 		this.clippingPlanes = dstPlanes;
 		this.clippingPlanes = dstPlanes;
+		this.userData = JSON.parse( JSON.stringify( source.userData ) );
 
 
 		return this;
 		return this;