forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathViewport.Info.js
90 lines (55 loc) · 2.35 KB
/
Viewport.Info.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { UIPanel, UIBreak, UIText } from './libs/ui.js';
function ViewportInfo( editor ) {
const signals = editor.signals;
const strings = editor.strings;
const container = new UIPanel();
container.setId( 'info' );
container.setPosition( 'absolute' );
container.setLeft( '10px' );
container.setBottom( '20px' );
container.setFontSize( '12px' );
container.setColor( '#fff' );
container.setTextTransform( 'lowercase' );
const objectsText = new UIText( '0' ).setTextAlign( 'right' ).setWidth( '60px' ).setMarginRight( '6px' );
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' );
container.add( objectsText, new UIText( strings.getKey( 'viewport/info/objects' ) ), new UIBreak() );
container.add( verticesText, new UIText( strings.getKey( 'viewport/info/vertices' ) ), new UIBreak() );
container.add( trianglesText, new UIText( strings.getKey( 'viewport/info/triangles' ) ), new UIBreak() );
container.add( frametimeText, new UIText( strings.getKey( 'viewport/info/rendertime' ) ), new UIBreak() );
signals.objectAdded.add( update );
signals.objectRemoved.add( update );
signals.geometryChanged.add( update );
signals.sceneRendered.add( updateFrametime );
//
function update() {
const scene = editor.scene;
let objects = 0, vertices = 0, triangles = 0;
for ( let i = 0, l = scene.children.length; i < l; i ++ ) {
const object = scene.children[ i ];
object.traverseVisible( function ( object ) {
objects ++;
if ( object.isMesh || object.isPoints ) {
const geometry = object.geometry;
vertices += geometry.attributes.position.count;
if ( object.isMesh ) {
if ( geometry.index !== null ) {
triangles += geometry.index.count / 3;
} else {
triangles += geometry.attributes.position.count / 3;
}
}
}
} );
}
objectsText.setValue( objects.format() );
verticesText.setValue( vertices.format() );
trianglesText.setValue( triangles.format() );
}
function updateFrametime( frametime ) {
frametimeText.setValue( Number( frametime ).toFixed( 2 ) );
}
return container;
}
export { ViewportInfo };