Mr.doob пре 12 година
родитељ
комит
86f9ba0037
2 измењених фајлова са 64 додато и 26 уклоњено
  1. 4 4
      src/materials/ShaderMaterial.js
  2. 60 22
      src/renderers/WebGLRenderer.js

+ 4 - 4
src/materials/ShaderMaterial.js

@@ -57,16 +57,16 @@ THREE.ShaderMaterial = function ( parameters ) {
 	this.morphTargets = false; // set to use morph targets
 	this.morphNormals = false; // set to use morph normals
 
-	//When rendered geometry doesn't include these attributes but the material does,
-	//use these default values in WebGL. This avoids errors when buffer data is missing.
+	// When rendered geometry doesn't include these attributes but the material does,
+	// use these default values in WebGL. This avoids errors when buffer data is missing.
 	this.defaultAttributeValues = {
 		"color" : [ 1, 1, 1],
 		"uv" : [ 0, 0 ],
 		"uv2" : [ 0, 0 ]
 	};
 
-	//By default, bind position to attribute index 0. In WebGL, attribute 0
-	//should always be used to avoid potentially expensive emulation.
+	// By default, bind position to attribute index 0. In WebGL, attribute 0
+	// should always be used to avoid potentially expensive emulation.
 	this.index0AttributeName = "position";
 
 	this.setValues( parameters );

+ 60 - 22
src/renderers/WebGLRenderer.js

@@ -2769,18 +2769,24 @@ THREE.WebGLRenderer = function ( parameters ) {
 							if ( attributePointer >= 0 ) {
 
 								if ( attributeItem ) {
+
 									attributeSize = attributeItem.itemSize;
 									_gl.bindBuffer( _gl.ARRAY_BUFFER, attributeItem.buffer );
 									enableAttribute( attributePointer );
 									_gl.vertexAttribPointer( attributePointer, attributeSize, _gl.FLOAT, false, 0, startIndex * attributeSize * 4 ); // 4 bytes per Float32
-								}
-								else if ( material.defaultAttributeValues ) {
+
+								} else if ( material.defaultAttributeValues ) {
+
 									if ( material.defaultAttributeValues[ attributeName ].length === 2 ) {
+
 										_gl.vertexAttrib2fv( attributePointer, material.defaultAttributeValues[ attributeName ] );
-									}
-									else if ( material.defaultAttributeValues[ attributeName ].length === 3 ) {
+
+									} else if ( material.defaultAttributeValues[ attributeName ].length === 3 ) {
+
 										_gl.vertexAttrib3fv( attributePointer, material.defaultAttributeValues[ attributeName ] );
+
 									}
+
 								}
 
 							}
@@ -2819,18 +2825,24 @@ THREE.WebGLRenderer = function ( parameters ) {
 						if ( attributePointer >= 0 ) {
 
 							if ( attributeItem ) {
+
 								attributeSize = attributeItem.itemSize;
 								_gl.bindBuffer( _gl.ARRAY_BUFFER, attributeItem.buffer );
 								enableAttribute( attributePointer );
 								_gl.vertexAttribPointer( attributePointer, attributeSize, _gl.FLOAT, false, 0, 0 );
-							}
-							else if ( material.defaultAttributeValues && material.defaultAttributeValues[ attributeName ] ) {
+
+							} else if ( material.defaultAttributeValues && material.defaultAttributeValues[ attributeName ] ) {
+
 								if ( material.defaultAttributeValues[ attributeName ].length === 2 ) {
+
 									_gl.vertexAttrib2fv( attributePointer, material.defaultAttributeValues[ attributeName ] );
-								}
-								else if ( material.defaultAttributeValues[ attributeName ].length === 3 ) {
+
+								} else if ( material.defaultAttributeValues[ attributeName ].length === 3 ) {
+
 									_gl.vertexAttrib3fv( attributePointer, material.defaultAttributeValues[ attributeName ] );
+
 								}
+
 							}
 
 						}
@@ -2865,19 +2877,26 @@ THREE.WebGLRenderer = function ( parameters ) {
 					if ( attributePointer >= 0 ) {
 
 						if ( attributeItem ) {
+
 							attributeSize = attributeItem.itemSize;
 							_gl.bindBuffer( _gl.ARRAY_BUFFER, attributeItem.buffer );
 							enableAttribute( attributePointer );
 							_gl.vertexAttribPointer( attributePointer, attributeSize, _gl.FLOAT, false, 0, 0 );
-						}
-						else if ( material.defaultAttributeValues && material.defaultAttributeValues[ attributeName ] ) {
+
+						} else if ( material.defaultAttributeValues && material.defaultAttributeValues[ attributeName ] ) {
+
 							if ( material.defaultAttributeValues[ attributeName ].length === 2 ) {
+
 								_gl.vertexAttrib2fv( attributePointer, material.defaultAttributeValues[ attributeName ] );
-							}
-							else if ( material.defaultAttributeValues[ attributeName ].length === 3 ) {
+
+							} else if ( material.defaultAttributeValues[ attributeName ].length === 3 ) {
+
 								_gl.vertexAttrib3fv( attributePointer, material.defaultAttributeValues[ attributeName ] );
+
 							}
+
 						}
+
 					}
 
 				}
@@ -2905,18 +2924,24 @@ THREE.WebGLRenderer = function ( parameters ) {
 					if ( attributePointer >= 0 ) {
 
 						if ( attributeItem ) {
+
 							attributeSize = attributeItem.itemSize;
 							_gl.bindBuffer( _gl.ARRAY_BUFFER, attributeItem.buffer );
 							enableAttribute( attributePointer );
 							_gl.vertexAttribPointer( attributePointer, attributeSize, _gl.FLOAT, false, 0, 0 );
-						}
-						else if ( material.defaultAttributeValues && material.defaultAttributeValues[ attributeName ] ) {
+
+						} else if ( material.defaultAttributeValues && material.defaultAttributeValues[ attributeName ] ) {
+
 							if ( material.defaultAttributeValues[ attributeName ].length === 2 ) {
+
 								_gl.vertexAttrib2fv( attributePointer, material.defaultAttributeValues[ attributeName ] );
-							}
-							else if ( material.defaultAttributeValues[ attributeName ].length === 3 ) {
+
+							} else if ( material.defaultAttributeValues[ attributeName ].length === 3 ) {
+
 								_gl.vertexAttrib3fv( attributePointer, material.defaultAttributeValues[ attributeName ] );
+
 							}
+
 						}
 
 					}
@@ -3023,13 +3048,18 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 				if ( object.geometry.faces.length && object.geometry.faces[0].vertexColors.length > 0 ||
 					object.geometry.__webglColorBuffer ) {
+
 					_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglColorBuffer );
 					enableAttribute( attributes.color );
 					_gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
-				}
-				else if ( material.defaultAttributeValues ) {
+
+				} else if ( material.defaultAttributeValues ) {
+
+
 					_gl.vertexAttrib3fv( attributes.color, material.defaultAttributeValues.color );
+
 				}
+
 			}
 
 			// normals
@@ -3057,12 +3087,16 @@ THREE.WebGLRenderer = function ( parameters ) {
 			if ( attributes.uv >= 0 ) {
 
 				if ( object.geometry.faceVertexUvs[0] ) {
+
 					_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglUVBuffer );
 					enableAttribute( attributes.uv );
 					_gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
-				}
-				else if ( material.defaultAttributeValues ) {
+
+				} else if ( material.defaultAttributeValues ) {
+
+
 					_gl.vertexAttrib2fv( attributes.uv, material.defaultAttributeValues.uv );
+
 				}
 
 			}
@@ -3070,12 +3104,16 @@ THREE.WebGLRenderer = function ( parameters ) {
 			if ( attributes.uv2 >= 0 ) {
 
 				if ( object.geometry.faceVertexUvs[1] ) {
+
 					_gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglUV2Buffer );
 					enableAttribute( attributes.uv2 );
 					_gl.vertexAttribPointer( attributes.uv2, 2, _gl.FLOAT, false, 0, 0 );
-				}
-				else if ( material.defaultAttributeValues ) {
+
+				} else if ( material.defaultAttributeValues ) {
+
+
 					_gl.vertexAttrib2fv( attributes.uv2, material.defaultAttributeValues.uv2 );
+
 				}
 
 			}