Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Sep 24, 2024
1 parent 918acf9 commit 5798a59
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.
5 changes: 4 additions & 1 deletion src/viser/_gui_handles.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ def __setattr__(self, name: str, value: Any) -> None:
handle = cast(_GuiInputHandle, self)
# Get the value of the T TypeVar.
if name in self._prop_hints:
if getattr(handle._impl.props, name) == value:
# Do nothing. Assumes equality is defined for the prop value.
return
setattr(handle._impl.props, name, value)
handle._impl.gui_api._websock_interface.queue_message(
_messages.GuiUpdateMessage(handle._impl.id, {name: value})
Expand Down Expand Up @@ -489,7 +492,7 @@ def add_tab(self, label: str, icon: IconName | None = None) -> GuiTabHandle:

self._tab_handles.append(out)
self._tab_labels = self._tab_labels + (label,)
self._icons_html = self._icons_html + (
self._tab_icons_html = self._tab_icons_html + (
None if icon is None else svg_from_icon(icon),
)
self._tab_container_ids = tuple(handle._id for handle in self._tab_handles)
Expand Down
2 changes: 1 addition & 1 deletion src/viser/_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from . import infra, theme


@dataclasses.dataclass
@dataclasses.dataclass(frozen=True)
class GuiSliderMark:
value: float
label: Optional[str]
Expand Down
4 changes: 4 additions & 0 deletions src/viser/_scene_handles.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def __setattr__(self, name: str, value: Any) -> None:
elif hint == onpt.NDArray[np.uint8] and "color" in name:
value = colors_to_uint8(value)

if getattr(handle._impl.props, name) == value:
# Do nothing. Assumes equality is defined for the prop value.
return

setattr(handle._impl.props, name, value)
handle._impl.api._websock_interface.queue_message(
_messages.SceneNodeUpdateMessage(handle.name, {name: value})
Expand Down
22 changes: 8 additions & 14 deletions src/viser/client/src/ThreeAssets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -601,24 +601,18 @@ export const ViserMesh = React.forwardRef<
const state = viewer.skinnedMeshState.current[message.name];
const bones = bonesRef.current;
if (bones !== undefined) {
bones.forEach((bone, i) => {
if (!state.initialized) {
if (!state.initialized) {
bones.forEach((bone) => {
parentNode.add(bone);
}
const wxyz = state.initialized
? state.poses[i].wxyz
: message.props.bone_wxyzs[i];
const position = state.initialized
? state.poses[i].position
: message.props.bone_positions[i];

});
state.initialized = true;
}
bones.forEach((bone, i) => {
const wxyz = state.poses[i].wxyz;
const position = state.poses[i].position;
bone.quaternion.set(wxyz[1], wxyz[2], wxyz[3], wxyz[0]);
bone.position.set(position[0], position[1], position[2]);
});

if (!state.initialized) {
state.initialized = true;
}
}
});

Expand Down
27 changes: 25 additions & 2 deletions src/viser/infra/_infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,36 @@ async def viser_http_server(

use_gzip = "gzip" in request_headers.get("Accept-Encoding", "")

mime_type = mimetypes.guess_type(relpath)[0]
# First, try some known MIME types. Using guess_type() can cause
# problems for Javascript on some Windows machines.
#
# Some references:
# https://github.com/nerfstudio-project/viser/issues/256#issuecomment-2369684252
# https://bugs.python.org/issue43975
# https://github.com/golang/go/issues/32350#issuecomment-525111557
#
# We're assuming UTF-8, this is mostly reasonable but might want to revisit.
mime_type = {
".css": "text/css; charset=utf-8",
".gif": "image/gif",
".htm": "text/html; charset=utf-8",
".html": "text/html; charset=utf-8",
".jpg": "image/jpeg",
".js": "application/javascript",
".wasm": "application/wasm",
".pdf": "application/pdf",
".png": "image/png",
".svg": "image/svg+xml",
".xml": "text/xml; charset=utf-8",
}.get(Path(path).suffix.lower(), None)
if mime_type is None:
mime_type = mimetypes.guess_type(relpath)[0]
if mime_type is None:
mime_type = "application/octet-stream"

response_headers = {
"Content-Type": mime_type,
}

if source_path not in file_cache:
file_cache[source_path] = source_path.read_bytes()
if use_gzip:
Expand Down

0 comments on commit 5798a59

Please sign in to comment.