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

Canvas export button, minor GUI fixes #58

Merged
merged 4 commits into from
Jun 30, 2023
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
6 changes: 3 additions & 3 deletions viser/client/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"files": {
"main.css": "/static/css/main.82973013.css",
"main.js": "/static/js/main.c81f69e2.js",
"main.js": "/static/js/main.ffcb6b00.js",
"index.html": "/index.html",
"main.82973013.css.map": "/static/css/main.82973013.css.map",
"main.c81f69e2.js.map": "/static/js/main.c81f69e2.js.map"
"main.ffcb6b00.js.map": "/static/js/main.ffcb6b00.js.map"
},
"entrypoints": [
"static/css/main.82973013.css",
"static/js/main.c81f69e2.js"
"static/js/main.ffcb6b00.js"
]
}
2 changes: 1 addition & 1 deletion viser/client/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.svg"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Viser</title><script defer="defer" src="/static/js/main.c81f69e2.js"></script><link href="/static/css/main.82973013.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.svg"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Viser</title><script defer="defer" src="/static/js/main.ffcb6b00.js"></script><link href="/static/css/main.82973013.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
22 changes: 0 additions & 22 deletions viser/client/build/static/js/main.c81f69e2.js

This file was deleted.

22 changes: 22 additions & 0 deletions viser/client/build/static/js/main.ffcb6b00.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions viser/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"devDependencies": {
"@redux-devtools/core": "^3.13.1",
"@types/msgpack": "0.0.31",
"@types/wicg-file-system-access": "^2020.9.6",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"eslint": "^8.38.0",
Expand Down
2 changes: 2 additions & 0 deletions viser/client/src/ControlPanel/Generated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ function VectorInput(
step={props.step}
min={props.min === null ? undefined : props.min[i]}
max={props.max === null ? undefined : props.max[i]}
stepHoldDelay={500}
stepHoldInterval={(t) => Math.max(1000 / t ** 2, 25)}
disabled={props.disabled}
/>
))}
Expand Down
9 changes: 4 additions & 5 deletions viser/client/src/ControlPanel/SceneTreeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ export default function SceneTreeTable(props: { compact: boolean }) {
(state) => state.setLabelVisibility
);
function setVisible(name: string, visible: boolean) {
const attrs = viewer.nodeAttributesFromName.current[name];
if (attrs !== undefined) {
attrs.visibility = visible;
rerenderTable();
}
const attr = viewer.nodeAttributesFromName.current;
if (attr[name] === undefined) attr[name] = {};
attr[name]!.visibility = visible;
rerenderTable();
}

// For performance, scene node visibility is stored in a ref instead of the
Expand Down
43 changes: 27 additions & 16 deletions viser/client/src/ControlPanel/Server.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ViewerContext } from "..";
import { isTexture } from "../WebsocketInterface";
import { Button, Stack, Switch, TextInput } from "@mantine/core";
import { Stats } from "@react-three/drei";
import { IconPhoto } from "@tabler/icons-react";
Expand Down Expand Up @@ -36,26 +35,38 @@ export default function ServerControls() {
onKeyDown={triggerBlur}
/>
<Button
onClick={() => {
if (!isTexture(viewer.sceneRef.current?.background)) {
// This should never happen.
alert("No background to download!");
return;
}
onClick={async () => {
viewer.canvasRef.current?.toBlob(async (blob) => {
if (blob === null) {
console.error("Render failed!");
return;
}

const data = viewer.sceneRef.current?.background.image.src;
const link = document.createElement("a");
link.download = "background";
link.href = data;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
let handle = null;
try {
handle = await showSaveFilePicker({
suggestedName: "render.png",
types: [
{
accept: { "image/png": [".png"] },
},
],
});
} catch (e) {
console.log(e);
}

if (handle) {
const writableStream = await handle.createWritable();
await writableStream.write(blob);
await writableStream.close();
}
});
}}
fullWidth
disabled={!viewer.useGui((state) => state.backgroundAvailable)}
leftIcon={<IconPhoto size="1rem" />}
>
Download Background
Export Canvas
</Button>
<Switch
label="WebGL Statistics"
Expand Down
5 changes: 5 additions & 0 deletions viser/client/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type ViewerContextContents = {
useSceneTree: UseSceneTree;
useGui: UseGui;
websocketRef: React.MutableRefObject<WebSocket | null>;
canvasRef: React.MutableRefObject<HTMLCanvasElement | null>;
sceneRef: React.MutableRefObject<THREE.Scene | null>;
cameraRef: React.MutableRefObject<THREE.PerspectiveCamera | null>;
cameraControlRef: React.MutableRefObject<CameraControls | null>;
Expand Down Expand Up @@ -79,6 +80,7 @@ function SingleViewer() {
useSceneTree: useSceneTreeState(),
useGui: useGuiState(initialServer),
websocketRef: React.useRef(null),
canvasRef: React.useRef(null),
sceneRef: React.useRef(null),
cameraRef: React.useRef(null),
cameraControlRef: React.useRef(null),
Expand Down Expand Up @@ -160,16 +162,19 @@ function SingleViewer() {
}

function ViewerCanvas() {
const viewer = React.useContext(ViewerContext)!;
return (
<Canvas
camera={{ position: [3.0, 3.0, -3.0] }}
gl={{ preserveDrawingBuffer: true }}
style={{
position: "relative",
zIndex: 0,
width: "100%",
height: "100%",
}}
performance={{ min: 0.95 }}
ref={viewer.canvasRef}
>
<AdaptiveDpr pixelated />
<AdaptiveEvents />
Expand Down
5 changes: 5 additions & 0 deletions viser/client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2771,6 +2771,11 @@
resolved "https://registry.yarnpkg.com/@types/webxr/-/webxr-0.5.2.tgz#5d9627b0ffe223aa3b166de7112ac8a9460dc54f"
integrity sha512-szL74BnIcok9m7QwYtVmQ+EdIKwbjPANudfuvDrAF8Cljg9MKUlIoc1w5tjj9PMpeSH3U1Xnx//czQybJ0EfSw==

"@types/wicg-file-system-access@^2020.9.6":
version "2020.9.6"
resolved "https://registry.yarnpkg.com/@types/wicg-file-system-access/-/wicg-file-system-access-2020.9.6.tgz#da34476b1e29451c8b7aa1a6db86b185647cd970"
integrity sha512-6hogE75Hl2Ov/jgp8ZhDaGmIF/q3J07GtXf8nCJCwKTHq7971po5+DId7grft09zG7plBwpF6ZU0yx9Du4/e1A==

"@types/ws@^8.5.5":
version "8.5.5"
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.5.tgz#af587964aa06682702ee6dcbc7be41a80e4b28eb"
Expand Down