Skip to content

Commit abb61cf

Browse files
committed
Improve UI layout and optimize camera rendering logic.
1 parent c5d6128 commit abb61cf

3 files changed

Lines changed: 50 additions & 23 deletions

File tree

client/src/components/CameraFeeds.jsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@ const CameraFeed = ({ feedData, name }) => {
2525

2626

2727
return (
28-
<div>
28+
<div
29+
style={{
30+
display: 'flex',
31+
flexDirection: 'column',
32+
alignItems: 'start',
33+
justifyContent: 'start',
34+
}}
35+
>
2936
<Text style={{
3037
margin: '0 0 5px 0',
3138
fontSize: '10px', color: '#fff', background: 'rgba(0,0,0,0.6)', padding: '4px', borderRadius: '4px', width: 'auto', textTransform: 'uppercase', display: 'inline-block'
@@ -34,9 +41,15 @@ const CameraFeed = ({ feedData, name }) => {
3441
{name}
3542
</Text>
3643
<canvas
37-
ref={canvasRef}
38-
width="120"
39-
height="90" style={{ border: '1px solid #555', borderRadius: '4px', width: '120px' }} />
44+
ref={canvasRef}
45+
width="120"
46+
height="90"
47+
style={{
48+
border: '1px solid #555', borderRadius: '4px',
49+
width: '120px',
50+
background: 'rgba(0,0,0,0.6)',
51+
}}
52+
/>
4053
</div>
4154
);
4255
};
@@ -51,15 +64,15 @@ const CameraFeeds = ({ cameraFeedData }) => {
5164
<div
5265
style={{
5366
position: 'absolute',
54-
top: '150px',
67+
top: '180px',
5568
left: '10px',
56-
width: '450px',
69+
width: '260px',
5770
color: '#fff',
5871
display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: '8px'
5972
}}
6073
>
6174
{Object.entries(cameraFeedData).map(([name, data]) => (
62-
<CameraFeed key={name} name={name} feedData={data} />
75+
<CameraFeed key={name} name={name.replace(/^\d+-/, '')} feedData={data} />
6376
))}
6477
</div>
6578
);

client/src/components/InfoPanel.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default function InfoPanel({ chartState, logs }) {
3636
<div
3737
style={{
3838
height: '180px',
39-
background: 'rgba(255,255,255,0.05)',
39+
background: 'rgba(0,0,0,0.6)',
4040
padding: 4,
4141
borderRadius: '8px',
4242
border: '1px solid rgba(255,255,255,0.2)',

client/src/examples/SelfDrivingCar.jsx

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import Lidar, { LIDAR_LAYER } from '../components/Lidar.jsx';
1616

1717
const WS_URL = `${config.WS_BASE_URL}/ws/self_driving_car`;
1818

19+
const TRAINING_FRAME_RENDER_INTERVAL = 100;
20+
1921
const Agent = ({ agent, coordinateTransformer, onCamerasCreated }) => {
2022
const { pos, color, id, heading, pitch } = agent;
2123
const groupRef = useRef();
@@ -30,20 +32,22 @@ const Agent = ({ agent, coordinateTransformer, onCamerasCreated }) => {
3032
'Left': new THREE.PerspectiveCamera(75, 4 / 3, 1, 1000),
3133
'Right': new THREE.PerspectiveCamera(75, 4 / 3, 1, 1000),
3234
'Rear': new THREE.PerspectiveCamera(120, 4 / 3, 1, 1000),
33-
'Lidar (Top-Down)': new THREE.OrthographicCamera(-500, 500, 500, -500, 1, 2000)
35+
'Lidar': new THREE.OrthographicCamera(-500, 500, 500, -500, 1, 2000)
3436
};
3537

36-
cameras['Front (Wide)'].position.set(0, 10, 20);
37-
cameras['Front (Narrow)'].position.set(0, 10, 20);
38-
cameras['Left'].position.set(-10, 10, 0);
39-
cameras['Left'].rotateY(THREE.MathUtils.degToRad(-90));
40-
cameras['Right'].position.set(10, 10, 0);
41-
cameras['Right'].rotateY(THREE.MathUtils.degToRad(90));
42-
cameras['Rear'].position.set(0, 10, -20);
43-
cameras['Rear'].rotateY(THREE.MathUtils.degToRad(180));
44-
cameras['Lidar (Top-Down)'].position.set(0, 1000, 0);
45-
cameras['Lidar (Top-Down)'].lookAt(0, 0, 0);
46-
cameras['Lidar (Top-Down)'].layers.enable(LIDAR_LAYER);
38+
const y = 15;
39+
cameras['Front (Wide)'].position.set(0, y, 21);
40+
cameras['Front (Wide)'].rotateY(Math.PI);
41+
cameras['Front (Narrow)'].position.set(0, y, 21);
42+
cameras['Front (Narrow)'].rotateY(Math.PI);
43+
cameras['Left'].position.set(-11, y, 0);
44+
cameras['Left'].rotateY(Math.PI / 2);
45+
cameras['Right'].position.set(11, y, 0);
46+
cameras['Right'].rotateY(-Math.PI / 2);
47+
cameras['Rear'].position.set(0, y, -21);
48+
cameras['Lidar'].position.set(0, 1000, 0);
49+
cameras['Lidar'].lookAt(0, 0, 0);
50+
cameras['Lidar'].layers.enable(LIDAR_LAYER);
4751

4852
camerasRef.current = cameras;
4953
onCamerasCreated(id, cameras);
@@ -233,11 +237,11 @@ const MessagePanel = ({ messages }) => {
233237
ref={containerRef}
234238
style={{
235239
position: 'absolute', bottom: '10px', left: '10px', width: '450px',
236-
maxHeight: '40vh', overflowY: 'auto', background: 'rgba(0,0,0,0.6)',
240+
maxHeight: '30vh', overflowY: 'auto', background: 'rgba(0,0,0,0.6)',
237241
color: '#fff', border: '1px solid #444',
238242
}}
239243
>
240-
{messages.length === 0 && <Text p style={{ margin: 0, fontSize: '12px' }}>[No messages]</Text>}
244+
{messages.length === 0 && <Text p style={{ margin: 0, fontSize: '12px' }}>[No interpretability messages yet.]</Text>}
241245
{messages.map((msg, i) => (
242246
<div key={i} style={{ marginBottom: '12px', padding: '8px', background: 'rgba(255,255,255,0.05)', borderRadius: '4px', fontSize: '12px' }}>
243247
<Text p style={{ margin: 0, fontWeight: 'bold' }}>
@@ -394,6 +398,7 @@ export default function SelfDrivingCarExample() {
394398
agentCamerasRef={agentCamerasRef}
395399
cameraTargetsRef={cameraTargetsRef}
396400
setCameraFeedData={setCameraFeedData}
401+
training={training}
397402
/>
398403
</Canvas>
399404

@@ -434,12 +439,21 @@ const SceneContent = ({
434439
setCoordinateTransformer,
435440
agentCamerasRef,
436441
cameraTargetsRef,
437-
setCameraFeedData
442+
setCameraFeedData,
443+
training,
438444
}) => {
439445
const { scene } = useThree();
446+
const frameCountRef = useRef(0);
440447

441448
useFrame(({ gl, scene }) => {
442449
gl.autoClear = true;
450+
451+
frameCountRef.current++;
452+
if (training && (frameCountRef.current % TRAINING_FRAME_RENDER_INTERVAL !== 1)) {
453+
// During training, only render camera feeds intermittently to save performance
454+
return;
455+
}
456+
443457
const newFeedData = {};
444458
const renderWidth = 400;
445459
const renderHeight = 300;

0 commit comments

Comments
 (0)