提交 1fd80171 编写于 作者: A alteredq

Added option to have flat shading for renderBufferImmediate.

上级 5c943cab
因为 它太大了无法显示 source diff 。你可以改为 查看blob
此差异已折叠。
<html>
<head>
<title>threej.s webgl - intersection: ray with box</title>
<title>three.js webgl - intersection: ray with box</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style type="text/css">
......@@ -72,29 +71,34 @@ function init() {
sun.position = camera.position.clone();
scene.addLight( sun );
createCube(200, new THREE.Vector3(0,0,0) );
createCube( 200, new THREE.Vector3( 0,0,0 ) );
container.onmousemove = onDocumentMouseMove;
animate();
}
function createCube(s, p) {
function createCube( s, p ) {
cube = new THREE.Mesh (
new Cube(s,s,s,1,1,1),
new Cube( s,s,s, 1,1,1 ),
new THREE.MeshLambertMaterial( { color: 0x003300 })
);
cube.position = p;
scene.addObject( cube );
THREE.Collisions.colliders.push( THREE.CollisionUtils.MeshOBB(cube) );
THREE.Collisions.colliders.push( THREE.CollisionUtils.MeshOBB( cube ) );
}
function onDocumentMouseMove( event ) {
event.preventDefault();
mouse2d.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse2d.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
mouse2d.z = 1;
}
function animate() {
......
......@@ -2,19 +2,19 @@
* @author drojdjou / http://everyday3d.com/
*/
THREE.PlaneCollider = function( pt, nor ) {
THREE.PlaneCollider = function( point, normal ) {
this.point = pt;
this.normal = nor;
this.point = point;
this.normal = normal;
};
THREE.SphereCollider = function( cen, rad ) {
THREE.SphereCollider = function( center, radius ) {
this.center = cen;
this.radius = rad;
this.radiusSq = rad * rad;
this.center = center;
this.radius = radius;
this.radiusSq = radius * radius;
};
......
......@@ -2606,7 +2606,7 @@ THREE.WebGLRenderer = function ( parameters ) {
}
function renderBufferImmediate( object, program ) {
function renderBufferImmediate( object, program, shading ) {
if ( ! object.__webglVertexBuffer ) object.__webglVertexBuffer = _gl.createBuffer();
if ( ! object.__webglNormalBuffer ) object.__webglNormalBuffer = _gl.createBuffer();
......@@ -2623,6 +2623,50 @@ THREE.WebGLRenderer = function ( parameters ) {
if ( object.hasNormal ) {
_gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglNormalBuffer );
if ( shading == THREE.FlatShading ) {
var nx, ny, nz,
nax, nbx, ncx, nay, nby, ncy, naz, nbz, ncz,
normalArray,
i, il = object.count * 3;
for( i = 0; i < il; i += 9 ) {
normalArray = object.normalArray;
nax = normalArray[ i ];
nay = normalArray[ i + 1 ];
naz = normalArray[ i + 2 ];
nbx = normalArray[ i + 3 ];
nby = normalArray[ i + 4 ];
nbz = normalArray[ i + 5 ];
ncx = normalArray[ i + 6 ];
ncy = normalArray[ i + 7 ];
ncz = normalArray[ i + 8 ];
nx = ( nax + nbx + ncx ) / 3;
ny = ( nay + nby + ncy ) / 3;
nz = ( naz + nbz + ncz ) / 3;
normalArray[ i ] = nx;
normalArray[ i + 1 ] = ny;
normalArray[ i + 2 ] = nz;
normalArray[ i + 3 ] = nx;
normalArray[ i + 4 ] = ny;
normalArray[ i + 5 ] = nz;
normalArray[ i + 6 ] = nx;
normalArray[ i + 7 ] = ny;
normalArray[ i + 8 ] = nz;
}
}
_gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
_gl.enableVertexAttribArray( program.attributes.normal );
_gl.vertexAttribPointer( program.attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
......@@ -2944,7 +2988,7 @@ THREE.WebGLRenderer = function ( parameters ) {
setDepthTest( material.depthTest );
program = setProgram( camera, lights, fog, material, object );
object.render( function( object ) { renderBufferImmediate( object, program ); } );
object.render( function( object ) { renderBufferImmediate( object, program, material.shading ); } );
}
......@@ -3002,7 +3046,7 @@ THREE.WebGLRenderer = function ( parameters ) {
setDepthTest( material.depthTest );
program = setProgram( camera, lights, fog, material, object );
object.render( function( object ) { renderBufferImmediate( object, program ); } );
object.render( function( object ) { renderBufferImmediate( object, program, material.shading ); } );
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册