Skip to content

Commit 2cecaad

Browse files
authored
Web Viewer UI Improvements (#2798)
- Add FPS timer. Toggles via T / t(imer). ( SHIFT-f / F already used for frame-grab so don't want to mix things up ). - Make UI consistent for font, and color - Make menus not be file names but try and parse out useful words. Remove extensions. - Prevent UI from overlapping and wrapping when page is narrow (mobile and desktop).
1 parent 2caab7a commit 2cecaad

2 files changed

Lines changed: 109 additions & 13 deletions

File tree

javascript/MaterialXView/index.ejs

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,43 @@
88
<style>
99
body {
1010
margin: 0;
11-
font-family: Arial
11+
font-family: "Segoe UI", Roboto, Arial, sans-serif;
12+
font-size: 12px;
1213
}
1314
15+
/* Responsive select menus */
16+
select {
17+
max-width: 40vw;
18+
width: 100%;
19+
box-sizing: border-box;
20+
white-space: normal;
21+
overflow-wrap: break-word;
22+
word-break: break-word;
23+
background: #000;
24+
color: #fff;
25+
border: 1px solid #444;
26+
font-family: inherit;
27+
font-size: inherit;
28+
}
29+
30+
select option {
31+
background: #000;
32+
color: #fff;
33+
font-family: inherit;
34+
font-size: inherit;
35+
}
36+
37+
.select-row {
38+
color: rgb(255, 255, 255);
39+
background: rgba(0,0,0,0.4);
40+
position: absolute;
41+
margin: 1em;
42+
display: flex;
43+
align-items: center;
44+
gap: 0.5em;
45+
}
46+
47+
1448
/* Property editor item color */
1549
.peditoritem {
1650
background-color: #334444;
@@ -20,32 +54,51 @@
2054
background-color: #333333;
2155
}
2256
57+
/* Move property editor down to align with Material row */
58+
.lil-gui {
59+
top: 1.0em !important;
60+
}
61+
2362
.peditor_material_assigned {
2463
background-color: #006cb8;
2564
}
2665
.peditor_material_assigned:hover {
2766
background-color: #32adff;
2867
}
68+
69+
.fps-overlay {
70+
position: fixed;
71+
left: 10px;
72+
bottom: 10px;
73+
padding: 4px 10px;
74+
background: rgba(0,0,0,0.4);
75+
color: rgb(255, 255, 255);
76+
font-family: inherit;
77+
font-size: inherit;
78+
z-index: 1000;
79+
pointer-events: none;
80+
}
81+
2982
</style>
3083
</head>
3184
<body style="margin: 0px; overflow: hidden;">
3285
<div id="container">
33-
<div style="color:white; position: absolute; top: 0em; margin: 1em">
34-
<label for="materials">Material:</label>
35-
<select name="materials" id="materials">
86+
<div class="select-row" style="top: 0em;">
87+
<label for="materials" style="margin: 0; padding: 0 0.2em; font-family: inherit; font-size: inherit;">Material:</label>
88+
<select name="materials" id="materials" style="flex: 1 1 0; min-width: 0;">
3689
<% materials.forEach(function(m){ %>
3790
<option value="<%-m.value%>">
38-
<%-m.name%>
91+
<%- m.name.replace(/_/g, ' ').replace(/\.(mtlx|glb)$/, '').replace(/\w\S*/g, function(txt){return ' ' + txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}) %>
3992
</option>
4093
<% }); %>
4194
</select>
4295
</div>
43-
<div style="color:white; position: absolute; top: 1.5em; margin: 1em">
44-
<label for="geometry">Geometry:</label>
45-
<select name="geometry" id="geometry">
96+
<div class="select-row" style="top: 1.5em;">
97+
<label for="geometry" style="margin: 0; padding: 0 0.2em; font-family: inherit; font-size: inherit;">Geometry:</label>
98+
<select name="geometry" id="geometry" style="flex: 1 1 0; min-width: 0;">
4699
<% geometry.forEach(function(m){ %>
47100
<option value="<%-m.value%>">
48-
<%-m.name%>
101+
<%- m.name.replace(/_/g, ' ').replace(/\.(mtlx|glb)$/, '').replace(/\w\S*/g, function(txt){return ' ' + txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}) %>
49102
</option>
50103
<% }); %>
51104
</select>

javascript/MaterialXView/source/index.js

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import { dropHandler, dragOverHandler, setLoadingCallback, setSceneLoadingCallba
1010

1111
let renderer, orbitControls;
1212

13+
// FPS overlay state
14+
let fpsOverlay = null;
15+
let showFPS = true;
16+
let lastFrameTime = performance.now();
17+
let frameCount = 0;
18+
let fps = 0;
19+
1320
// Turntable option. For now the step size is fixed.
1421
let turntableEnabled = false;
1522
let turntableSteps = 360;
@@ -25,6 +32,24 @@ if (!materialFilename)
2532
}
2633

2734
let viewer = Viewer.create();
35+
36+
// Create FPS overlay
37+
function createFPSOverlay() {
38+
fpsOverlay = document.createElement('div');
39+
fpsOverlay.className = 'fps-overlay';
40+
fpsOverlay.innerText = 'FPS: 0';
41+
document.body.appendChild(fpsOverlay);
42+
}
43+
44+
function setFPSOverlayVisible(visible) {
45+
if (fpsOverlay) {
46+
fpsOverlay.style.display = visible ? 'block' : 'none';
47+
}
48+
}
49+
50+
createFPSOverlay();
51+
setFPSOverlayVisible(showFPS);
52+
2853
init();
2954
viewer.getEditor().updateProperties(0.9);
3055

@@ -81,10 +106,16 @@ function init()
81106

82107
// Add hotkey 'f' to capture the current frame and save an image file.
83108
// See check inside the render loop when a capture can be performed.
84-
document.addEventListener('keydown', (event) =>
85-
{
86-
if (event.key === 'f')
87-
{
109+
110+
document.addEventListener('keydown', (event) => {
111+
// Toggle FPS timer with T key
112+
if (event.key === 't' || event.key === 'T') {
113+
showFPS = !showFPS;
114+
setFPSOverlayVisible(showFPS);
115+
event.preventDefault();
116+
}
117+
// Capture frame with Shift+F
118+
else if ((event.key === 'f' || event.key === 'F') && event.shiftKey) {
88119
captureRequested = true;
89120
}
90121
});
@@ -165,6 +196,18 @@ function animate()
165196
requestAnimationFrame(animate);
166197
const scene = viewer.getScene();
167198

199+
// Compute FPS and update overlay every 1/2 second.
200+
const now = performance.now();
201+
frameCount++;
202+
if (now - lastFrameTime >= 500) {
203+
fps = Math.round((frameCount * 1000) / (now - lastFrameTime));
204+
if (fpsOverlay && showFPS) {
205+
fpsOverlay.innerText = `FPS: ${fps}`;
206+
}
207+
lastFrameTime = now;
208+
frameCount = 0;
209+
}
210+
168211
if (turntableEnabled)
169212
{
170213
turntableStep = (turntableStep + 1) % 360;

0 commit comments

Comments
 (0)