Skip to content

Commit

Permalink
Basic Channels implementation. See #5180 and #5931.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Oct 16, 2015
1 parent e1dc0bd commit d36df79
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 39 deletions.
45 changes: 45 additions & 0 deletions src/core/Channels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @author mrdoob / http://mrdoob.com/
*/

THREE.Channels = function () {

this.mask = 1;

};

THREE.Channels.prototype = {

constructor: THREE.Channels,

set: function ( channel ) {

this.mask = 1 << channel;

},

enable: function ( channel ) {

this.mask |= 1 << channel;

},

toggle: function ( channel ) {

this.mask ^= 1 << channel;

},

disable: function ( channel ) {

this.mask &= ~ ( 1 << channel );

},

clear: function () {

this.mask = 1;

}

};
1 change: 1 addition & 0 deletions src/core/Object3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ THREE.Object3D = function () {
this.type = 'Object3D';

this.parent = null;
this.channels = new THREE.Channels();
this.children = [];

this.up = THREE.Object3D.DefaultUp.clone();
Expand Down
82 changes: 43 additions & 39 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ THREE.WebGLRenderer = function ( parameters ) {
sprites.length = 0;
lensFlares.length = 0;

projectObject( scene );
projectObject( scene, camera );

opaqueObjects.length = opaqueObjectsLastIndex + 1;
transparentObjects.length = transparentObjectsLastIndex + 1;
Expand Down Expand Up @@ -1236,77 +1236,81 @@ THREE.WebGLRenderer = function ( parameters ) {

}

function projectObject( object ) {
function projectObject( object, camera ) {

if ( object.visible === false ) return;

if ( object instanceof THREE.Light ) {
if ( ( object.channels.mask & camera.channels.mask ) !== 0 ) {

lights.push( object );
if ( object instanceof THREE.Light ) {

} else if ( object instanceof THREE.Sprite ) {
lights.push( object );

sprites.push( object );
} else if ( object instanceof THREE.Sprite ) {

} else if ( object instanceof THREE.LensFlare ) {
sprites.push( object );

lensFlares.push( object );
} else if ( object instanceof THREE.LensFlare ) {

} else if ( object instanceof THREE.ImmediateRenderObject ) {
lensFlares.push( object );

if ( _this.sortObjects === true ) {
} else if ( object instanceof THREE.ImmediateRenderObject ) {

_vector3.setFromMatrixPosition( object.matrixWorld );
_vector3.applyProjection( _projScreenMatrix );
if ( _this.sortObjects === true ) {

}
_vector3.setFromMatrixPosition( object.matrixWorld );
_vector3.applyProjection( _projScreenMatrix );

pushRenderItem( object, null, object.material, _vector3.z, null );
}

} else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
pushRenderItem( object, null, object.material, _vector3.z, null );

if ( object instanceof THREE.SkinnedMesh ) {
} else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {

object.skeleton.update();
if ( object instanceof THREE.SkinnedMesh ) {

}
object.skeleton.update();

if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
}

var material = object.material;
if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {

if ( material.visible === true ) {
var material = object.material;

if ( _this.sortObjects === true ) {
if ( material.visible === true ) {

_vector3.setFromMatrixPosition( object.matrixWorld );
_vector3.applyProjection( _projScreenMatrix );
if ( _this.sortObjects === true ) {

}
_vector3.setFromMatrixPosition( object.matrixWorld );
_vector3.applyProjection( _projScreenMatrix );

}

var geometry = objects.update( object );
var geometry = objects.update( object );

if ( material instanceof THREE.MeshFaceMaterial ) {
if ( material instanceof THREE.MeshFaceMaterial ) {

var groups = geometry.groups;
var materials = material.materials;
var groups = geometry.groups;
var materials = material.materials;

for ( var i = 0, l = groups.length; i < l; i ++ ) {
for ( var i = 0, l = groups.length; i < l; i ++ ) {

var group = groups[ i ];
var groupMaterial = materials[ group.materialIndex ];
var group = groups[ i ];
var groupMaterial = materials[ group.materialIndex ];

if ( groupMaterial.visible === true ) {
if ( groupMaterial.visible === true ) {

pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );

}

}

}
} else {

} else {
pushRenderItem( object, geometry, material, _vector3.z, null );

pushRenderItem( object, geometry, material, _vector3.z, null );
}

}

Expand All @@ -1320,7 +1324,7 @@ THREE.WebGLRenderer = function ( parameters ) {

for ( var i = 0, l = children.length; i < l; i ++ ) {

projectObject( children[ i ] );
projectObject( children[ i ], camera );

}

Expand Down Expand Up @@ -2846,7 +2850,7 @@ THREE.WebGLRenderer = function ( parameters ) {
}

uploadTexture( textureProperties, texture, slot );

return;

}
Expand Down
1 change: 1 addition & 0 deletions utils/build/includes/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"src/math/Math.js",
"src/math/Spline.js",
"src/math/Triangle.js",
"src/core/Channels.js",
"src/core/Clock.js",
"src/core/EventDispatcher.js",
"src/core/Raycaster.js",
Expand Down

0 comments on commit d36df79

Please sign in to comment.