Skip to content

Commit

Permalink
fix selection reset
Browse files Browse the repository at this point in the history
  • Loading branch information
PythonFZ committed Nov 18, 2024
1 parent d86770b commit 77a4645
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ export default function App() {

// reduce selection, if selected points is reduced
useEffect(() => {
if (currentFrame.positions.length === 0) {
// this is not ideal, but we want to prohibit changes when loading
// one consequence is that the selection is not updated when the frame is empty
return;
}
if (selectedIds.size > 0) {
const newSelectedIds = new Set(
Array.from(selectedIds).filter(
Expand Down
6 changes: 5 additions & 1 deletion app/src/components/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,12 @@ export function setupSelection(
selectedIds: Set<number>,
) {
const conInterfaceRef = useRef<any>(undefined);
const updateByRefreshRef = useRef(false);
const updateByRefreshRef = useRef(true);

useEffect(() => {
if (token === "") {
return;
}
console.log("setting up selection");
const con = new znsocket.Dict({
client: client,
Expand All @@ -134,6 +137,7 @@ export function setupSelection(
con.get("grp-0").then((items: any) => {
updateByRefreshRef.current = true;
setSelectedIds(new Set(items));
console.log("initial selection update to", items);
});

// External updates handler
Expand Down
4 changes: 3 additions & 1 deletion app/src/components/particles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ export const ParticleInstances = ({

// Mark instance matrices and colors for update
meshRef.current.instanceMatrix.needsUpdate = true;
meshRef.current.instanceColor.needsUpdate = true;
if (meshRef.current.instanceColor) {
meshRef.current.instanceColor.needsUpdate = true;
}
}
}, [
positions,
Expand Down
3 changes: 3 additions & 0 deletions app/src/components/particlesEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { socket } from "../socket";

export const getCentroid = (positions: Vector3[], selection: Set<number>) => {
const centroid = new Vector3();
if (!positions || positions.length === 0) {
return centroid;
}
if (selection.size > 0) {
selection.forEach((i) => {
centroid.add(positions[i]);
Expand Down

0 comments on commit 77a4645

Please sign in to comment.