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

feat: add instance view for 3D models #445

Merged
merged 1 commit into from
Nov 16, 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
18 changes: 18 additions & 0 deletions frontend/src/lib/instance-views/elements/ThreeD.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script lang="ts">
export let data: string;
</script>

<svelte:head>
<script
type="module"
src="https://ajax.googleapis.com/ajax/libs/model-viewer/3.0.1/model-viewer.min.js"
></script>
</svelte:head>

<model-viewer
alt="3D model for instance {data}"
src={data}
shadow-intensity="1"
camera-controls
touch-action="pan-y"
></model-viewer>
4 changes: 3 additions & 1 deletion frontend/src/lib/instance-views/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Markdown from './elements/Markdown.svelte';
import Message from './elements/Message.svelte';
import SeparatedValues from './elements/SeparatedValues.svelte';
import Text from './elements/Text.svelte';
import ThreeD from './elements/ThreeD.svelte';
import VStack from './elements/VStack.svelte';

export const elementMap: Record<string, ComponentType> = {
Expand All @@ -20,7 +21,8 @@ export const elementMap: Record<string, ComponentType> = {
[ViewType.audio]: Audio,
[ViewType.code]: Code,
[ViewType.message]: Message,
[ViewType.separatedValues]: SeparatedValues
[ViewType.separatedValues]: SeparatedValues,
[ViewType['3D']]: ThreeD
};

export function isComplexElement(type: string) {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/instance-views/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
"audio",
"code",
"markdown",
"3D",
"list",
"vstack",
"message",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/instance-views/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum ViewType {
'audio' = 'audio',
'code' = 'code',
'markdown' = 'markdown',
'3D' = '3D',
// data containers
'list' = 'list',
'vstack' = 'vstack',
Expand Down
20 changes: 20 additions & 0 deletions frontend/src/routes/playground/samples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,5 +319,25 @@ export const samples: Record<string, { spec: string; data: string }> = {
null,
2
)
},
'3D-object-classification': {
spec: JSON.stringify(
{
data: { type: '3D' },
label: { type: 'text' },
output: { type: 'text' }
},
null,
2
),
data: JSON.stringify(
{
data: 'https://raw.githubusercontent.com/google/model-viewer/master/packages/shared-assets/models/NeilArmstrong.glb',
label: 'astronaut',
output: 'astronaut'
},
null,
2
)
}
};
Loading