Skip to content

Commit 70bc8f5

Browse files
committed
flashing
1 parent 316cca5 commit 70bc8f5

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

src/editor/components/layout/StatusBar.tsx

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,27 @@ export const StatusBar: React.FC<IStatusBarProps> = ({
7676
const [isMobile, setIsMobile] = React.useState(false);
7777
const selectedIds = useEditorStore((state) => state.selectedIds);
7878

79+
// Detect if mobile (only once on mount)
7980
React.useEffect(() => {
80-
// Detect if mobile
8181
const checkMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
8282
navigator.userAgent,
8383
);
8484
setIsMobile(checkMobile);
85+
}, []);
8586

87+
// Triangle counting with startup delay (only once on mount)
88+
React.useEffect(() => {
8689
const countTriangles = () => {
8790
try {
8891
const scene = (window as any).__r3fScene;
8992
if (!scene) return { total: 0, selected: 0 };
9093

9194
let totalCount = 0;
9295
let selectedCount = 0;
93-
const selectedIdsSet = new Set(selectedIds);
96+
97+
// Get latest selectedIds from store
98+
const currentSelectedIds = useEditorStore.getState().selectedIds;
99+
const selectedIdsSet = new Set(currentSelectedIds);
94100

95101
scene.traverse((obj: any) => {
96102
if (obj.geometry) {
@@ -106,7 +112,17 @@ export const StatusBar: React.FC<IStatusBarProps> = ({
106112
totalCount += triangles;
107113

108114
// Count triangles for selected entities
109-
if (obj.userData?.entityId && selectedIdsSet.has(obj.userData.entityId)) {
115+
// Check this object and traverse up parent hierarchy for entityId
116+
let entityId = obj.userData?.entityId;
117+
if (!entityId) {
118+
let parent = obj.parent;
119+
while (parent && !entityId) {
120+
entityId = parent.userData?.entityId;
121+
parent = parent.parent;
122+
}
123+
}
124+
125+
if (entityId && selectedIdsSet.has(entityId)) {
110126
selectedCount += triangles;
111127
}
112128
}
@@ -118,14 +134,29 @@ export const StatusBar: React.FC<IStatusBarProps> = ({
118134
}
119135
};
120136

121-
const interval = setInterval(() => {
137+
// Wait 500ms for initial geometry to stabilize (terrain async loading, etc.)
138+
const startupDelay = setTimeout(() => {
139+
// Do initial count
122140
const { total, selected } = countTriangles();
123141
setTriangleCount(total);
124142
setSelectedTriangleCount(selected);
125-
}, 1000);
126143

127-
return () => clearInterval(interval);
128-
}, [selectedIds]);
144+
// Then start interval - reads latest selectedIds on each tick
145+
const interval = setInterval(() => {
146+
const { total, selected } = countTriangles();
147+
setTriangleCount(total);
148+
setSelectedTriangleCount(selected);
149+
}, 1000);
150+
151+
// Cleanup function returned from timeout
152+
return () => clearInterval(interval);
153+
}, 500);
154+
155+
// Cleanup: clear the timeout and its returned interval cleanup
156+
return () => {
157+
clearTimeout(startupDelay);
158+
};
159+
}, []); // Only run once on mount
129160

130161
// Calculate budget status
131162
const mobileBudget = 500000; // 500k triangles for mobile

src/editor/components/panels/ViewportPanel/GizmoControls.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ export const GizmoControls: React.FC<IGizmoControlsProps> = React.memo(
448448
ref={transformRef as any}
449449
mode={mode}
450450
size={0.75}
451-
translationSnap={0.25}
451+
translationSnap={0.1}
452452
rotationSnap={Math.PI / 24}
453453
scaleSnap={0.1}
454454
onObjectChange={handleTransformUpdate}

src/editor/components/panels/ViewportPanel/GroupGizmoControls.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export const GroupGizmoControls: React.FC<IGroupGizmoControlsProps> = React.memo
285285
object={gizmoObject}
286286
mode={mode}
287287
size={0.75}
288-
translationSnap={0.25}
288+
translationSnap={0.1}
289289
rotationSnap={Math.PI / 24}
290290
scaleSnap={0.1}
291291
onObjectChange={handleTransformUpdate}

src/editor/components/panels/ViewportPanel/hooks/useEntitySelection.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ export const useEntitySelection = ({
121121
outline.position.copy(mesh.position);
122122
outline.rotation.copy(mesh.rotation);
123123
outline.scale.copy(mesh.scale);
124-
outline.scale.addScalar(0.05);
125124
}
126125
}, [selected, meshRef]);
127126

@@ -141,7 +140,6 @@ export const useEntitySelection = ({
141140
outline.position.copy(mesh.position);
142141
outline.rotation.copy(mesh.rotation);
143142
outline.scale.copy(mesh.scale);
144-
outline.scale.addScalar(0.05);
145143
}
146144
animationId = requestAnimationFrame(updateOutline);
147145
};

0 commit comments

Comments
 (0)