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

Artifact Playground #563

Merged
merged 19 commits into from
Nov 10, 2024
Merged
260 changes: 250 additions & 10 deletions frontend/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"tailwind-merge": "^2.5.2",
"tailwindcss-animate": "^1.0.7",
"three": "^0.167.1",
"tsd-jsdoc": "^2.5.0",
"urdf-loader": "^0.12.2",
"zod": "^3.23.8",
"zxcvbn": "^4.4.2"
Expand Down
16 changes: 5 additions & 11 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import Logout from "@/components/pages/Logout";
import NotFound from "@/components/pages/NotFound";
import OrderSuccess from "@/components/pages/OrderSuccess";
import OrdersPage from "@/components/pages/Orders";
import Playground from "@/components/pages/Playground";
import PrivacyPolicy from "@/components/pages/PrivacyPolicy";
import Profile from "@/components/pages/Profile";
import ResearchPage from "@/components/pages/ResearchPage";
Expand Down Expand Up @@ -57,12 +56,6 @@ const App = () => {
<Routes>
<Route path={ROUTES.HOME.path} element={<Home />} />

{/* Playground */}
<Route
path={ROUTES.PLAYGROUND.path}
element={<Playground />}
/>

{/* General pages */}
<Route path={ROUTES.ABOUT.path} element={<About />} />
<Route
Expand Down Expand Up @@ -114,10 +107,11 @@ const App = () => {
/>

{/* Seller */}
<Route
path={ROUTES.SELL.path}
element={<SellerDashboard />}
>
<Route path={ROUTES.SELL.path}>
<Route
path={ROUTES.SELL.$.DASHBOARD.relativePath}
element={<SellerDashboard />}
/>
<Route
path={ROUTES.SELL.$.ONBOARDING.relativePath}
element={<SellerOnboarding />}
Expand Down
34 changes: 30 additions & 4 deletions frontend/src/components/files/FileRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,48 @@
import STLRenderer from "./STLRenderer";
import { UntarredFile } from "./Tarfile";
import URDFRenderer from "./URDFRenderer";
import MJCFRenderer from "@/components/files/MJCFRenderer";
import STLRenderer from "@/components/files/STLRenderer";
import URDFRenderer from "@/components/files/URDFRenderer";
import { UntarredFile } from "@/components/files/untar";

const isMJCFFile = (content: string, filename: string): boolean => {
const extension = filename.split(".").pop()?.toLowerCase();
if (extension !== "xml" && extension !== "mjcf") {
return false;
}

return content.includes("<mujoco") && content.includes("</mujoco>");
};

const FileRenderer: React.FC<{
file: UntarredFile;
allFiles: UntarredFile[];
}> = ({ file, allFiles }) => {
const fileExtension = file.name.split(".").pop()?.toLowerCase();
const fileContent = new TextDecoder().decode(file.content);

switch (fileExtension) {
case "urdf":
return (
<URDFRenderer
urdfContent={new TextDecoder().decode(file.content)}
urdfContent={fileContent}
files={allFiles}
supportedThemes={["light", "dark"]}
/>
);
case "xml":
case "mjcf":
if (isMJCFFile(fileContent, file.name)) {
// For now, just render the default humanoid, since there is something
// funky about the way the MJCF files are being generated by the
// K-Scale Onshape Library that isn't working well with the current
// renderer.
return <MJCFRenderer mjcfContent={fileContent} files={allFiles} />;
} else {
return (
<div className="h-full w-full flex items-center justify-center">
<p>Invalid MJCF file format</p>
</div>
);
}
case "stl":
return <STLRenderer stlContent={file.content.buffer} />;
default:
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/files/FileTreeViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from "react";
import { FaFile, FaFolder, FaFolderOpen } from "react-icons/fa";

import { UntarredFile } from "./Tarfile";
import { UntarredFile } from "@/components/files/untar";

interface FileTreeNode {
name: string;
Expand Down
Loading
Loading