Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OutlinePass: Exclude point cloud and lines. #20460

Merged
merged 1 commit into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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