瀏覽代碼

Differentiate between heightfields and normalmaps and treat each appropriately

Eric Burns 11 年之前
父節點
當前提交
ae02c24c4f
共有 1 個文件被更改,包括 27 次插入3 次删除
  1. 27 3
      examples/js/loaders/ColladaLoader.js

+ 27 - 3
examples/js/loaders/ColladaLoader.js

@@ -3370,11 +3370,33 @@ THREE.ColladaLoader = function () {
 				case 'diffuse':
 				case 'specular':
 				case 'transparent':
-				case 'bump':
 
 					this[ child.nodeName ] = ( new ColorOrTexture() ).parse( child );
 					break;
 
+				case 'bump':
+
+					// If 'bumptype' is 'heightfield', create a 'bump' property
+					// Else if 'bumptype' is 'normalmap', create a 'normal' property
+					// (Default to 'bump')
+					var bumpType = child.getAttribute( 'bumptype' );
+					if ( bumpType ) {
+						if ( bumpType.toLowerCase() === "heightfield" ) {
+							this[ 'bump' ] = ( new ColorOrTexture() ).parse( child );
+						} else if ( bumpType.toLowerCase() === "normalmap" ) {
+							this[ 'normal' ] = ( new ColorOrTexture() ).parse( child );
+						} else {
+							console.error( "Shader.prototype.parse: Invalid value for attribute 'bumptype' (" + bumpType + 
+								           ") - valid bumptypes are 'HEIGHTFIELD' and 'NORMALMAP' - defaulting to 'HEIGHTFIELD'" );
+							this[ 'bump' ] = ( new ColorOrTexture() ).parse( child );
+						}
+					} else {
+						console.warn( "Shader.prototype.parse: Attribute 'bumptype' missing from bump node - defaulting to 'HEIGHTFIELD'" );
+						this[ 'bump' ] = ( new ColorOrTexture() ).parse( child );
+					}
+
+					break;
+
 				case 'shininess':
 				case 'reflectivity':
 				case 'index_of_refraction':
@@ -3424,10 +3446,11 @@ THREE.ColladaLoader = function () {
 		
 		var keys = {
 			'diffuse':'map', 
-			'ambient':"lightMap" ,
+			'ambient':'lightMap' ,
 			'specular':'specularMap',
 			'emission':'emissionMap',
-			'bump':'normalMap'
+			'bump':'bumpMap',
+			'normal':'normalMap'
 			};
 		
 		for ( var prop in this ) {
@@ -3439,6 +3462,7 @@ THREE.ColladaLoader = function () {
 				case 'diffuse':
 				case 'specular':
 				case 'bump':
+				case 'normal':
 
 					var cot = this[ prop ];