From 9908299a06ba0b3622452fefd127264dd31f60cb Mon Sep 17 00:00:00 2001 From: ranbuch Date: Tue, 25 Jun 2019 20:47:05 +0300 Subject: [PATCH 1/5] ready for review --- src/renderers/WebGLRenderer.js | 16 +++++++++++++++- src/renderers/webgl/WebGLRenderLists.js | 6 +++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 3b1db85a076be4..96c691723029f1 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -253,6 +253,8 @@ function WebGLRenderer( parameters ) { var background, morphtargets, bufferRenderer, indexedBufferRenderer; + var opaqueSort, transparentSort; + var utils; function initGLContext() { @@ -505,6 +507,18 @@ function WebGLRenderer( parameters ) { }; + this.setOpaqueSort = function ( method ) { + + opaqueSort = method; + + }; + + this.setTransparentSort = function ( method ) { + + transparentSort = method; + + }; + // Clearing this.getClearColor = function () { @@ -1154,7 +1168,7 @@ function WebGLRenderer( parameters ) { if ( _this.sortObjects === true ) { - currentRenderList.sort(); + currentRenderList.sort( opaqueSort, transparentSort ); } diff --git a/src/renderers/webgl/WebGLRenderLists.js b/src/renderers/webgl/WebGLRenderLists.js index d48262cd838bae..5f09e1b48abd99 100644 --- a/src/renderers/webgl/WebGLRenderLists.js +++ b/src/renderers/webgl/WebGLRenderLists.js @@ -130,10 +130,10 @@ function WebGLRenderList() { } - function sort() { + function sort( costumeOpaqueSort, costumeTransparentSort ) { - if ( opaque.length > 1 ) opaque.sort( painterSortStable ); - if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable ); + if ( opaque.length > 1 ) opaque.sort( typeof costumeOpaqueSort === 'function' ? costumeOpaqueSort : painterSortStable ); + if ( transparent.length > 1 ) transparent.sort( typeof costumeTransparentSort === 'function' ? costumeTransparentSort : reversePainterSortStable ); } From f70a3e4efb1c5e8b124649ad2cbe0c538dd65b17 Mon Sep 17 00:00:00 2001 From: ranbuch Date: Fri, 28 Jun 2019 05:42:46 +0300 Subject: [PATCH 2/5] fix misspelled and typeof only once --- src/renderers/WebGLRenderer.js | 4 ++-- src/renderers/webgl/WebGLRenderLists.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 96c691723029f1..5ead6446057223 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -509,13 +509,13 @@ function WebGLRenderer( parameters ) { this.setOpaqueSort = function ( method ) { - opaqueSort = method; + opaqueSort = typeof method === 'function' ? method : null; }; this.setTransparentSort = function ( method ) { - transparentSort = method; + transparentSort = typeof method === 'function' ? method : null; }; diff --git a/src/renderers/webgl/WebGLRenderLists.js b/src/renderers/webgl/WebGLRenderLists.js index 5f09e1b48abd99..87fea7a6f14ae9 100644 --- a/src/renderers/webgl/WebGLRenderLists.js +++ b/src/renderers/webgl/WebGLRenderLists.js @@ -130,10 +130,10 @@ function WebGLRenderList() { } - function sort( costumeOpaqueSort, costumeTransparentSort ) { + function sort( costumOpaqueSort, costumTransparentSort ) { - if ( opaque.length > 1 ) opaque.sort( typeof costumeOpaqueSort === 'function' ? costumeOpaqueSort : painterSortStable ); - if ( transparent.length > 1 ) transparent.sort( typeof costumeTransparentSort === 'function' ? costumeTransparentSort : reversePainterSortStable ); + if ( opaque.length > 1 ) opaque.sort( costumOpaqueSort || painterSortStable ); + if ( transparent.length > 1 ) transparent.sort( costumTransparentSort || reversePainterSortStable ); } From 41503489364059e61f8d9a5865527132cd7ccedd Mon Sep 17 00:00:00 2001 From: ranbuch Date: Sat, 12 Oct 2019 00:02:22 +0300 Subject: [PATCH 3/5] provide documentation --- docs/api/en/renderers/WebGLRenderer.html | 10 ++++++++++ src/renderers/WebGLRenderer.d.ts | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/docs/api/en/renderers/WebGLRenderer.html b/docs/api/en/renderers/WebGLRenderer.html index fa6d70613dab36..737162f6797fee 100644 --- a/docs/api/en/renderers/WebGLRenderer.html +++ b/docs/api/en/renderers/WebGLRenderer.html @@ -471,6 +471,16 @@

[method:null setScissorTest]( [param:Boolean boolean] )

scissor area will be affected by further renderer actions.

+

[method:null setOpaqueSort]( [param:Function method] )

+

+ Sets the costum opaque sort function for the WebGLRenderLists. Pass null to use the default painterSortStable function. +

+ +

[method:null setTransparentSort]( [param:Function method] )

+

+ Sets the costum transparent sort function for the WebGLRenderLists. Pass null to use the default reversePainterSortStable function. In some cases the transparent materials sort may get rendered in the wrong order. This issue may cause materials to rendere behind other materials instead of the front of them and vice versa. +

+

[method:null setSize]( [param:Integer width], [param:Integer height], [param:Boolean updateStyle] )

Resizes the output canvas to (width, height) with device pixel ratio taken into account, diff --git a/src/renderers/WebGLRenderer.d.ts b/src/renderers/WebGLRenderer.d.ts index 1a032a2edcee3e..60e3122119f8e8 100644 --- a/src/renderers/WebGLRenderer.d.ts +++ b/src/renderers/WebGLRenderer.d.ts @@ -258,6 +258,16 @@ export class WebGLRenderer implements Renderer { */ setScissorTest( enable: boolean ): void; + /** + * Sets the costum opaque sort function for the WebGLRenderLists. Pass null to use the default painterSortStable function. + */ + setOpaqueSort( method: Function ): void; + + /** + * Sets the costum transparent sort function for the WebGLRenderLists. Pass null to use the default reversePainterSortStable function. + */ + setTransparentSort( method: Function ): void; + /** * Returns a THREE.Color instance with the current clear color. */ From 78398149bf84a21d381b4c14677c17bb6806c7a2 Mon Sep 17 00:00:00 2001 From: ranbuch Date: Wed, 27 Nov 2019 21:50:15 +0200 Subject: [PATCH 4/5] fix spelling and remove typeof #2 --- docs/api/en/renderers/WebGLRenderer.html | 4 ++-- src/renderers/WebGLRenderer.d.ts | 4 ++-- src/renderers/WebGLRenderer.js | 10 +++++----- src/renderers/webgl/WebGLRenderLists.js | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/api/en/renderers/WebGLRenderer.html b/docs/api/en/renderers/WebGLRenderer.html index 737162f6797fee..a00f2fe9ab1f5f 100644 --- a/docs/api/en/renderers/WebGLRenderer.html +++ b/docs/api/en/renderers/WebGLRenderer.html @@ -473,12 +473,12 @@

[method:null setScissorTest]( [param:Boolean boolean] )

[method:null setOpaqueSort]( [param:Function method] )

- Sets the costum opaque sort function for the WebGLRenderLists. Pass null to use the default painterSortStable function. + Sets the custom opaque sort function for the WebGLRenderLists. Pass null to use the default painterSortStable function.

[method:null setTransparentSort]( [param:Function method] )

- Sets the costum transparent sort function for the WebGLRenderLists. Pass null to use the default reversePainterSortStable function. In some cases the transparent materials sort may get rendered in the wrong order. This issue may cause materials to rendere behind other materials instead of the front of them and vice versa. + Sets the custom transparent sort function for the WebGLRenderLists. Pass null to use the default reversePainterSortStable function. In some cases the transparent materials sort may get rendered in the wrong order. This issue may cause materials to rendere behind other materials instead of the front of them and vice versa.

[method:null setSize]( [param:Integer width], [param:Integer height], [param:Boolean updateStyle] )

diff --git a/src/renderers/WebGLRenderer.d.ts b/src/renderers/WebGLRenderer.d.ts index 60e3122119f8e8..807c1b4cecb9ae 100644 --- a/src/renderers/WebGLRenderer.d.ts +++ b/src/renderers/WebGLRenderer.d.ts @@ -259,12 +259,12 @@ export class WebGLRenderer implements Renderer { setScissorTest( enable: boolean ): void; /** - * Sets the costum opaque sort function for the WebGLRenderLists. Pass null to use the default painterSortStable function. + * Sets the custom opaque sort function for the WebGLRenderLists. Pass null to use the default painterSortStable function. */ setOpaqueSort( method: Function ): void; /** - * Sets the costum transparent sort function for the WebGLRenderLists. Pass null to use the default reversePainterSortStable function. + * Sets the custom transparent sort function for the WebGLRenderLists. Pass null to use the default reversePainterSortStable function. */ setTransparentSort( method: Function ): void; diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 5ead6446057223..8fdc4e7223f854 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -162,6 +162,8 @@ function WebGLRenderer( parameters ) { _height = _canvas.height, _pixelRatio = 1, + _opaqueSort = null, + _transparentSort = null, _viewport = new Vector4( 0, 0, _width, _height ), _scissor = new Vector4( 0, 0, _width, _height ), @@ -253,8 +255,6 @@ function WebGLRenderer( parameters ) { var background, morphtargets, bufferRenderer, indexedBufferRenderer; - var opaqueSort, transparentSort; - var utils; function initGLContext() { @@ -509,13 +509,13 @@ function WebGLRenderer( parameters ) { this.setOpaqueSort = function ( method ) { - opaqueSort = typeof method === 'function' ? method : null; + _opaqueSort = method; }; this.setTransparentSort = function ( method ) { - transparentSort = typeof method === 'function' ? method : null; + _transparentSort = method; }; @@ -1168,7 +1168,7 @@ function WebGLRenderer( parameters ) { if ( _this.sortObjects === true ) { - currentRenderList.sort( opaqueSort, transparentSort ); + currentRenderList.sort( _opaqueSort, _transparentSort ); } diff --git a/src/renderers/webgl/WebGLRenderLists.js b/src/renderers/webgl/WebGLRenderLists.js index 87fea7a6f14ae9..f12376f3c2f0e5 100644 --- a/src/renderers/webgl/WebGLRenderLists.js +++ b/src/renderers/webgl/WebGLRenderLists.js @@ -130,10 +130,10 @@ function WebGLRenderList() { } - function sort( costumOpaqueSort, costumTransparentSort ) { + function sort( customOpaqueSort, customTransparentSort ) { - if ( opaque.length > 1 ) opaque.sort( costumOpaqueSort || painterSortStable ); - if ( transparent.length > 1 ) transparent.sort( costumTransparentSort || reversePainterSortStable ); + if ( opaque.length > 1 ) opaque.sort( customOpaqueSort || painterSortStable ); + if ( transparent.length > 1 ) transparent.sort( customTransparentSort || reversePainterSortStable ); } From 99e80892df567fbeabaedc3664aca786f55e27a9 Mon Sep 17 00:00:00 2001 From: ranbuch Date: Tue, 17 Dec 2019 03:20:17 +0200 Subject: [PATCH 5/5] remove two sentences --- docs/api/en/renderers/WebGLRenderer.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/en/renderers/WebGLRenderer.html b/docs/api/en/renderers/WebGLRenderer.html index a00f2fe9ab1f5f..f9927c33389660 100644 --- a/docs/api/en/renderers/WebGLRenderer.html +++ b/docs/api/en/renderers/WebGLRenderer.html @@ -478,7 +478,7 @@

[method:null setOpaqueSort]( [param:Function method] )

[method:null setTransparentSort]( [param:Function method] )

- Sets the custom transparent sort function for the WebGLRenderLists. Pass null to use the default reversePainterSortStable function. In some cases the transparent materials sort may get rendered in the wrong order. This issue may cause materials to rendere behind other materials instead of the front of them and vice versa. + Sets the custom transparent sort function for the WebGLRenderLists. Pass null to use the default reversePainterSortStable function.

[method:null setSize]( [param:Integer width], [param:Integer height], [param:Boolean updateStyle] )