Skip to content

Commit

Permalink
Merge pull request #20460 from Mugen87/dev52
Browse files Browse the repository at this point in the history
OutlinePass: Exclude point cloud and lines.
  • Loading branch information
mrdoob committed Oct 5, 2020
2 parents aa0837a + e4955a5 commit afdaab3
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 16 deletions.
44 changes: 36 additions & 8 deletions examples/js/postprocessing/OutlinePass.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ THREE.OutlinePass = function ( resolution, scene, camera, selectedObjects ) {
this.downSampleRatio = 2;
this.pulsePeriod = 0;

this._visibilityCache = new Map();

THREE.Pass.call( this );

this.resolution = ( resolution !== undefined ) ? new THREE.Vector2( resolution.x, resolution.y ) : new THREE.Vector2( 256, 256 );
Expand Down Expand Up @@ -154,18 +156,19 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype

changeVisibilityOfSelectedObjects: function ( bVisible ) {

var cache = this._visibilityCache;

function gatherSelectedMeshesCallBack( object ) {

if ( object.isMesh ) {

if ( bVisible ) {
if ( bVisible === true ) {

object.visible = object.userData.oldVisible;
delete object.userData.oldVisible;
object.visible = cache.get( object );

} else {

object.userData.oldVisible = object.visible;
cache.set( object, object.visible );
object.visible = bVisible;

}
Expand All @@ -185,6 +188,7 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype

changeVisibilityOfNonSelectedObjects: function ( bVisible ) {

var cache = this._visibilityCache;
var selectedMeshes = [];

function gatherSelectedMeshesCallBack( object ) {
Expand All @@ -202,7 +206,9 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype

function VisibilityChangeCallBack( object ) {

if ( object.isMesh || object.isLine || object.isSprite ) {
if ( object.isMesh || object.isSprite ) {

// only meshes and sprites are supported by OutlinePass

var bFound = false;

Expand All @@ -219,13 +225,33 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype

}

if ( ! bFound ) {
if ( bFound === false ) {

var visibility = object.visible;

if ( ! bVisible || object.bVisible ) object.visible = bVisible;
if ( bVisible === false || cache.get( object ) === true ) {

object.visible = bVisible;

}

cache.set( object, visibility );

}

} else if ( object.isPoints || object.isLine ) {

// the visibilty of points and lines is always set to false in order to
// not affect the outline computation

if ( bVisible === true ) {

object.bVisible = visibility;
object.visible = cache.get( object ); // restore

} else {

cache.set( object, object.visible );
object.visible = bVisible;

}

Expand Down Expand Up @@ -276,6 +302,7 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype

// Make selected objects visible
this.changeVisibilityOfSelectedObjects( true );
this._visibilityCache.clear();

// Update Texture Matrix for Depth compare
this.updateTextureMatrix();
Expand All @@ -291,6 +318,7 @@ THREE.OutlinePass.prototype = Object.assign( Object.create( THREE.Pass.prototype
renderer.render( this.renderScene, this.renderCamera );
this.renderScene.overrideMaterial = null;
this.changeVisibilityOfNonSelectedObjects( true );
this._visibilityCache.clear();

this.renderScene.background = currentBackground;

Expand Down
44 changes: 36 additions & 8 deletions examples/jsm/postprocessing/OutlinePass.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ var OutlinePass = function ( resolution, scene, camera, selectedObjects ) {
this.downSampleRatio = 2;
this.pulsePeriod = 0;

this._visibilityCache = new Map();

Pass.call( this );

this.resolution = ( resolution !== undefined ) ? new Vector2( resolution.x, resolution.y ) : new Vector2( 256, 256 );
Expand Down Expand Up @@ -172,18 +174,19 @@ OutlinePass.prototype = Object.assign( Object.create( Pass.prototype ), {

changeVisibilityOfSelectedObjects: function ( bVisible ) {

var cache = this._visibilityCache;

function gatherSelectedMeshesCallBack( object ) {

if ( object.isMesh ) {

if ( bVisible ) {
if ( bVisible === true ) {

object.visible = object.userData.oldVisible;
delete object.userData.oldVisible;
object.visible = cache.get( object );

} else {

object.userData.oldVisible = object.visible;
cache.set( object, object.visible );
object.visible = bVisible;

}
Expand All @@ -203,6 +206,7 @@ OutlinePass.prototype = Object.assign( Object.create( Pass.prototype ), {

changeVisibilityOfNonSelectedObjects: function ( bVisible ) {

var cache = this._visibilityCache;
var selectedMeshes = [];

function gatherSelectedMeshesCallBack( object ) {
Expand All @@ -220,7 +224,9 @@ OutlinePass.prototype = Object.assign( Object.create( Pass.prototype ), {

function VisibilityChangeCallBack( object ) {

if ( object.isMesh || object.isLine || object.isSprite ) {
if ( object.isMesh || object.isSprite ) {

// only meshes and sprites are supported by OutlinePass

var bFound = false;

Expand All @@ -237,13 +243,33 @@ OutlinePass.prototype = Object.assign( Object.create( Pass.prototype ), {

}

if ( ! bFound ) {
if ( bFound === false ) {

var visibility = object.visible;

if ( ! bVisible || object.bVisible ) object.visible = bVisible;
if ( bVisible === false || cache.get( object ) === true ) {

object.visible = bVisible;

}

cache.set( object, visibility );

}

} else if ( object.isPoints || object.isLine ) {

// the visibilty of points and lines is always set to false in order to
// not affect the outline computation

if ( bVisible === true ) {

object.bVisible = visibility;
object.visible = cache.get( object ); // restore

} else {

cache.set( object, object.visible );
object.visible = bVisible;

}

Expand Down Expand Up @@ -294,6 +320,7 @@ OutlinePass.prototype = Object.assign( Object.create( Pass.prototype ), {

// Make selected objects visible
this.changeVisibilityOfSelectedObjects( true );
this._visibilityCache.clear();

// Update Texture Matrix for Depth compare
this.updateTextureMatrix();
Expand All @@ -309,6 +336,7 @@ OutlinePass.prototype = Object.assign( Object.create( Pass.prototype ), {
renderer.render( this.renderScene, this.renderCamera );
this.renderScene.overrideMaterial = null;
this.changeVisibilityOfNonSelectedObjects( true );
this._visibilityCache.clear();

this.renderScene.background = currentBackground;

Expand Down

0 comments on commit afdaab3

Please sign in to comment.