|
@@ -273,73 +273,79 @@ THREE.WebGLRenderer3 = function ( parameters ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
- this.render = function ( scene, camera ) {
|
|
|
+ var currentBuffer, currentProgram;
|
|
|
+ var locations = {};
|
|
|
|
|
|
- if ( this.autoClear === true ) this.clear();
|
|
|
+ var renderObject = function ( object, camera ) {
|
|
|
|
|
|
- scene.updateMatrixWorld();
|
|
|
+ if ( object.visible === false ) return;
|
|
|
|
|
|
- if ( camera.parent === undefined ) camera.updateMatrixWorld();
|
|
|
+ if ( object instanceof THREE.Mesh && frustum.intersectsObject( object ) === true ) {
|
|
|
|
|
|
- camera.matrixWorldInverse.getInverse( camera.matrixWorld );
|
|
|
+ var program = getProgram( object.material );
|
|
|
|
|
|
- modelViewProjectionMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
|
|
|
- frustum.setFromMatrix( modelViewProjectionMatrix );
|
|
|
+ if ( program !== currentProgram ) {
|
|
|
+
|
|
|
+ gl.useProgram( program );
|
|
|
+
|
|
|
+ locations.modelViewMatrix = gl.getUniformLocation( program, 'modelViewMatrix' );
|
|
|
+ locations.projectionMatrix = gl.getUniformLocation( program, 'projectionMatrix' );
|
|
|
|
|
|
- var currentBuffer, currentProgram;
|
|
|
- var locations = {};
|
|
|
+ locations.position = gl.getAttribLocation( program, 'position' );
|
|
|
+ locations.color = gl.getAttribLocation( program, 'color' );
|
|
|
|
|
|
- for ( var i = 0, l = scene.children.length; i < l; i ++ ) {
|
|
|
+ gl.uniformMatrix4fv( locations.projectionMatrix, false, camera.projectionMatrix.elements );
|
|
|
|
|
|
- var object = scene.children[ i ];
|
|
|
+ currentProgram = program;
|
|
|
|
|
|
- if ( object.visible === false ) continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ var buffer = getBuffer( object.geometry );
|
|
|
|
|
|
- if ( object instanceof THREE.Mesh && frustum.intersectsObject( object ) === true ) {
|
|
|
+ if ( buffer !== currentBuffer ) {
|
|
|
|
|
|
- var program = getProgram( object.material );
|
|
|
+ gl.bindBuffer( gl.ARRAY_BUFFER, buffer.positions );
|
|
|
+ gl.enableVertexAttribArray( locations.position );
|
|
|
+ gl.vertexAttribPointer( locations.position, 3, gl.FLOAT, false, 0, 0 );
|
|
|
|
|
|
- if ( program !== currentProgram ) {
|
|
|
+ gl.bindBuffer( gl.ARRAY_BUFFER, buffer.colors );
|
|
|
+ gl.enableVertexAttribArray( locations.color );
|
|
|
+ gl.vertexAttribPointer( locations.color, 3, gl.FLOAT, false, 0, 0 );
|
|
|
|
|
|
- gl.useProgram( program );
|
|
|
+ currentBuffer = buffer;
|
|
|
|
|
|
- locations.modelViewMatrix = gl.getUniformLocation( program, 'modelViewMatrix' );
|
|
|
- locations.projectionMatrix = gl.getUniformLocation( program, 'projectionMatrix' );
|
|
|
+ }
|
|
|
|
|
|
- locations.position = gl.getAttribLocation( program, 'position' );
|
|
|
- locations.color = gl.getAttribLocation( program, 'color' );
|
|
|
+ modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
|
|
|
|
|
|
- gl.uniformMatrix4fv( locations.projectionMatrix, false, camera.projectionMatrix.elements );
|
|
|
+ gl.uniformMatrix4fv( locations.modelViewMatrix, false, modelViewMatrix.elements );
|
|
|
|
|
|
- currentProgram = program;
|
|
|
+ gl.drawArrays( gl.TRIANGLES, 0, buffer.count );
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- var buffer = getBuffer( object.geometry );
|
|
|
+ for ( var i = 0, l = object.children.length; i < l; i ++ ) {
|
|
|
|
|
|
- if ( buffer !== currentBuffer ) {
|
|
|
+ renderObject( object.children[ i ], camera );
|
|
|
|
|
|
- gl.bindBuffer( gl.ARRAY_BUFFER, buffer.positions );
|
|
|
- gl.enableVertexAttribArray( locations.position );
|
|
|
- gl.vertexAttribPointer( locations.position, 3, gl.FLOAT, false, 0, 0 );
|
|
|
+ }
|
|
|
|
|
|
- gl.bindBuffer( gl.ARRAY_BUFFER, buffer.colors );
|
|
|
- gl.enableVertexAttribArray( locations.color );
|
|
|
- gl.vertexAttribPointer( locations.color, 3, gl.FLOAT, false, 0, 0 );
|
|
|
+ };
|
|
|
|
|
|
- currentBuffer = buffer;
|
|
|
+ this.render = function ( scene, camera ) {
|
|
|
|
|
|
- }
|
|
|
+ if ( this.autoClear === true ) this.clear();
|
|
|
|
|
|
- modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
|
|
|
+ scene.updateMatrixWorld();
|
|
|
|
|
|
- gl.uniformMatrix4fv( locations.modelViewMatrix, false, modelViewMatrix.elements );
|
|
|
+ if ( camera.parent === undefined ) camera.updateMatrixWorld();
|
|
|
|
|
|
- gl.drawArrays( gl.TRIANGLES, 0, buffer.count );
|
|
|
+ camera.matrixWorldInverse.getInverse( camera.matrixWorld );
|
|
|
|
|
|
- }
|
|
|
+ modelViewProjectionMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
|
|
|
+ frustum.setFromMatrix( modelViewProjectionMatrix );
|
|
|
|
|
|
- }
|
|
|
+ renderObject( scene, camera );
|
|
|
|
|
|
};
|
|
|
|