Skip to content

Commit

Permalink
Fix various scene node edge cases (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi authored Nov 21, 2024
1 parent 9096d19 commit 1585949
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/viser/_scene_handles.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ def remove_click_callback(
self._impl.click_cb.clear()
else:
self._impl.click_cb = [cb for cb in self._impl.click_cb if cb != callback]
if len(self._impl.click_cb) == 0:
self._impl.api._websock_interface.queue_message(
_messages.SetSceneNodeClickableMessage(self._impl.name, False)
)


class CameraFrustumHandle(
Expand Down
4 changes: 2 additions & 2 deletions src/viser/client/src/MessageHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,15 @@ function useMessageHandler() {
const attr = viewer.nodeAttributesFromName.current;
if (attr[message.name] === undefined) attr[message.name] = {};
attr[message.name]!.wxyz = message.wxyz;
if (attr[message.name]!.poseUpdateState == "updated")
if (attr[message.name]!.poseUpdateState != "waitForMakeObject")
attr[message.name]!.poseUpdateState = "needsUpdate";
break;
}
case "SetPositionMessage": {
const attr = viewer.nodeAttributesFromName.current;
if (attr[message.name] === undefined) attr[message.name] = {};
attr[message.name]!.position = message.position;
if (attr[message.name]!.poseUpdateState == "updated")
if (attr[message.name]!.poseUpdateState != "waitForMakeObject")
attr[message.name]!.poseUpdateState = "needsUpdate";
break;
}
Expand Down
12 changes: 4 additions & 8 deletions src/viser/client/src/SceneTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -735,14 +735,10 @@ export function SceneNodeThreeObject(props: {

if (attrs.poseUpdateState == "needsUpdate") {
attrs.poseUpdateState = "updated";
const wxyz = attrs.wxyz;
if (wxyz !== undefined) {
obj.quaternion.set(wxyz[1], wxyz[2], wxyz[3], wxyz[0]);
}
const position = attrs.position;
if (position !== undefined) {
obj.position.set(position[0], position[1], position[2]);
}
const wxyz = attrs.wxyz ?? [1, 0, 0, 0];
obj.quaternion.set(wxyz[1], wxyz[2], wxyz[3], wxyz[0]);
const position = attrs.position ?? [0, 0, 0];
obj.position.set(position[0], position[1], position[2]);

// Update matrices if necessary. This is necessary for PivotControls.
if (!obj.matrixAutoUpdate) obj.updateMatrix();
Expand Down
7 changes: 7 additions & 0 deletions src/viser/client/src/SceneTreeState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ export function useSceneTreeState(
}),
updateSceneNode: (name, updates) =>
set((state) => {
if (state.nodeFromName[name] === undefined) {
console.error(
`Attempted to update non-existent node ${name} with updates:`,
updates,
);
return;
}
state.nodeFromName[name]!.message.props = {
...state.nodeFromName[name]!.message.props,
...updates,
Expand Down

0 comments on commit 1585949

Please sign in to comment.