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

Editor: Added samples info for REALISTIC shading #28432

Merged
merged 1 commit into from
May 22, 2024
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
2 changes: 2 additions & 0 deletions editor/js/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ function Editor() {

intersectionsDetected: new Signal(),

pathTracerUpdated: new Signal(),

};

this.config = new Config();
Expand Down
10 changes: 9 additions & 1 deletion editor/js/Strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,12 @@ function Strings( config ) {
'viewport/info/oneObject': 'Object',
'viewport/info/oneVertex': 'Vertex',
'viewport/info/oneTriangle': 'Triangle',
'viewport/info/oneSample': 'Sample',
'viewport/info/objects': 'Objects',
'viewport/info/vertices': 'Vertices',
'viewport/info/triangles': 'Triangles',
'viewport/info/rendertime': 'Render time'
'viewport/info/samples': 'Samples',
'viewport/info/rendertime': 'Render time',

},

Expand Down Expand Up @@ -771,9 +773,11 @@ function Strings( config ) {
'viewport/info/oneObject': 'Objet',
'viewport/info/oneVertex': 'Sommet',
'viewport/info/oneTriangle': 'Triangle',
'viewport/info/oneSample': 'Échantillon',
'viewport/info/objects': 'Objets',
'viewport/info/vertices': 'Sommets',
'viewport/info/triangles': 'Triangles',
'viewport/info/samples': 'Échantillons',
'viewport/info/rendertime': 'Temps de rendu'

},
Expand Down Expand Up @@ -1158,9 +1162,11 @@ function Strings( config ) {
'viewport/info/oneObject': '物体',
'viewport/info/oneVertex': '顶点',
'viewport/info/oneTriangle': '三角形',
'viewport/info/oneSample': '样本',
'viewport/info/objects': '物体',
'viewport/info/vertices': '顶点',
'viewport/info/triangles': '三角形',
'viewport/info/samples': '样本',
'viewport/info/rendertime': '渲染时间'

},
Expand Down Expand Up @@ -1545,9 +1551,11 @@ function Strings( config ) {
'viewport/info/oneObject': 'オブジェクト',
'viewport/info/oneVertex': '頂点',
'viewport/info/oneTriangle': '三角形',
'viewport/info/oneSample': 'サンプル',
'viewport/info/objects': 'オブジェクト',
'viewport/info/vertices': '頂点',
'viewport/info/triangles': '三角形',
'viewport/info/samples': 'サンプル',
'viewport/info/rendertime': 'レンダリング時間'

}
Expand Down
31 changes: 31 additions & 0 deletions editor/js/Viewport.Info.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ function ViewportInfo( editor ) {
const verticesText = new UIText( '0' ).setTextAlign( 'right' ).setWidth( '60px' ).setMarginRight( '6px' );
const trianglesText = new UIText( '0' ).setTextAlign( 'right' ).setWidth( '60px' ).setMarginRight( '6px' );
const frametimeText = new UIText( '0' ).setTextAlign( 'right' ).setWidth( '60px' ).setMarginRight( '6px' );
const samplesText = new UIText( '0' ).setTextAlign( 'right' ).setWidth( '60px' ).setMarginRight( '6px' ).setHidden( true );

const objectsUnitText = new UIText( strings.getKey( 'viewport/info/objects' ) );
const verticesUnitText = new UIText( strings.getKey( 'viewport/info/vertices' ) );
const trianglesUnitText = new UIText( strings.getKey( 'viewport/info/triangles' ) );
const samplesUnitText = new UIText( strings.getKey( 'viewport/info/samples' ) ).setHidden( true );

container.add( objectsText, objectsUnitText, new UIBreak() );
container.add( verticesText, verticesUnitText, new UIBreak() );
container.add( trianglesText, trianglesUnitText, new UIBreak() );
container.add( frametimeText, new UIText( strings.getKey( 'viewport/info/rendertime' ) ), new UIBreak() );
container.add( samplesText, samplesUnitText, new UIBreak() );

signals.objectAdded.add( update );
signals.objectRemoved.add( update );
Expand All @@ -35,6 +38,10 @@ function ViewportInfo( editor ) {

//

const pluralRules = new Intl.PluralRules( editor.config.getKey( 'language' ) );

//

function update() {

const scene = editor.scene;
Expand Down Expand Up @@ -98,6 +105,30 @@ function ViewportInfo( editor ) {

}

//

editor.signals.pathTracerUpdated.add( function ( samples ) {

samples = Math.floor( samples );

samplesText.setValue( samples );

const samplesStringKey = ( pluralRules.select( samples ) === 'one' ) ? 'viewport/info/oneSample' : 'viewport/info/samples';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reconsidering #28245.

Do we really need this distinction? Stuff like that creates an unnecessary complexity. Why not just using Sample(s)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vertex(ices) then ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we just always use the plural? I personally don't see 1 samples as an issue which should be fixed with a separate code path.

Copy link
Contributor Author

@ycw ycw May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue about using (s) for just 'Sample(s)' is that, that unit will be inconsistent with other units formatted in the same area:

1 object
1 vertex
0 triangles
1 sample(s)

The reason that we can't apply (s) for other units has been mentioned #28432 (comment)

If handling of plural rules causes readability problems, then I prefer taking them into a function: (update: this function is now implemented in 54a4957)

function setInfo( quantity, unit ) { // ... set UI text values with proper format ... }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I vote for always using plural (without brackets).

Copy link
Contributor Author

@ycw ycw May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the transition from 0 > 1 > 2 samples is noticeable in low-end devices, so 'always use plural' like 1samples will confuse users that the quantity is incorrect.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the plural logic is still in place though....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind leaving the plural refactoring for another PR?

^^^^^^^

:D

Copy link
Owner

@mrdoob mrdoob May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current plural code is fine (with the clean up).

The refactoring was over engineering.

samplesUnitText.setValue( strings.getKey( samplesStringKey ) );

} );

editor.signals.viewportShadingChanged.add( function () {

const isRealisticShading = ( editor.viewportShading === 'realistic' );

samplesText.setHidden( ! isRealisticShading );
samplesUnitText.setHidden( ! isRealisticShading );

container.setBottom( isRealisticShading ? '32px' : '20px' );

} );

return container;

}
Expand Down
11 changes: 10 additions & 1 deletion editor/js/Viewport.Pathtracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,23 @@ function ViewportPathtracer( renderer ) {

}

function getSamples() {

if ( pathTracer === null ) return;

return pathTracer.samples;

}

return {
init: init,
setSize: setSize,
setBackground: setBackground,
setEnvironment: setEnvironment,
updateMaterials: updateMaterials,
update: update,
reset: reset
reset: reset,
getSamples: getSamples
};

}
Expand Down
1 change: 1 addition & 0 deletions editor/js/Viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ function Viewport( editor ) {
if ( editor.viewportShading === 'realistic' ) {

pathtracer.update();
editor.signals.pathTracerUpdated.dispatch( pathtracer.getSamples() );

}

Expand Down
2 changes: 2 additions & 0 deletions editor/js/libs/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class UIElement {

this.dom.hidden = isHidden;

return this;

}

isHidden() {
Expand Down