Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scene node edge cases #338

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading