Skip to content

Commit

Permalink
GLB liverender regression fix (#1688)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinnnnn authored Jul 11, 2023
1 parent 9350aa5 commit 63a46dc
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 24 deletions.
1 change: 0 additions & 1 deletion apps/web/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'src/scenes/WelcomeAnimation/intro.css';
import 'src/index.css';
import 'src/scenes/NftDetailPage/model-viewer.css';
import 'react-loading-skeleton/dist/skeleton.css';

import { Analytics } from '@vercel/analytics/react';
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/NftPreview/NftPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function NftPreview({
return <NftDetailGif onLoad={handleNftLoaded} tokenRef={token} />;
}
if (shouldLiverender && token.media?.__typename === 'GltfMedia') {
return <NftDetailModel onLoad={handleNftLoaded} mediaRef={token.media} />;
return <NftDetailModel onLoad={handleNftLoaded} mediaRef={token.media} fullHeight={false} />;
}
if (isIFrameLiveDisplay) {
return <NftDetailAnimation onLoad={handleNftLoaded} mediaRef={token} />;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/scenes/NftDetailPage/NftDetailAnimation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function NftDetailAnimation({ mediaRef, onLoad }: Props) {
}, [token.media]);

if (contentRenderURL.endsWith('.glb')) {
return <RawNftDetailModel onLoad={onLoad} url={contentRenderURL} />;
return <RawNftDetailModel onLoad={onLoad} url={contentRenderURL} fullHeight />;
}

return (
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/scenes/NftDetailPage/NftDetailAsset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function NftDetailAssetComponentWithouFallback({
/>
);
case 'GltfMedia':
return <NftDetailModel onLoad={onLoad} mediaRef={token.media} />;
return <NftDetailModel onLoad={onLoad} mediaRef={token.media} fullHeight />;
default:
return <NftDetailAnimation onLoad={onLoad} mediaRef={token} />;
}
Expand Down
49 changes: 36 additions & 13 deletions apps/web/src/scenes/NftDetailPage/NftDetailModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { ContentIsLoadedEvent } from '~/contexts/shimmer/ShimmerContext';
import { NftDetailModelFragment$key } from '~/generated/NftDetailModelFragment.graphql';
import { useThrowOnMediaFailure } from '~/hooks/useNftRetry';

type Props = {
mediaRef: NftDetailModelFragment$key;
onLoad: () => void;
};

// TODO: Clean this up once fixed
// https://github.com/google/model-viewer/issues/1502

interface ModelViewerJSX {
src: string;
poster?: string;
class: string;
}

declare global {
namespace JSX {
interface IntrinsicElements {
Expand All @@ -23,13 +24,14 @@ declare global {
}
}

interface ModelViewerJSX {
src: string;
poster?: string;
class: string;
}
type Props = {
mediaRef: NftDetailModelFragment$key;
onLoad: () => void;
// Prop that helps model fit to its parent container
fullHeight: boolean;
};

function NftDetailModel({ mediaRef, onLoad }: Props) {
function NftDetailModel({ mediaRef, onLoad, fullHeight }: Props) {
const { contentRenderURL } = useFragment(
graphql`
fragment NftDetailModelFragment on GltfMedia {
Expand All @@ -52,20 +54,41 @@ function NftDetailModel({ mediaRef, onLoad }: Props) {
auto-rotate
camera-controls
src={contentRenderURL}
style={{
width: '100%',
height: fullHeight ? '100%' : undefined,
}}
/>
</StyledNftDetailModel>
);
}

// stop-gap as the backend doesn't always categorize GltfMedia
export function RawNftDetailModel({ url, onLoad }: { url: string; onLoad: ContentIsLoadedEvent }) {
export function RawNftDetailModel({
url,
onLoad,
fullHeight,
}: {
url: string;
onLoad: ContentIsLoadedEvent;
fullHeight: boolean;
}) {
useEffect(() => {
onLoad();
}, [onLoad]);

return (
<StyledNftDetailModel>
<model-viewer class="model-viewer" auto-rotate camera-controls src={url} />
<model-viewer
class="model-viewer"
auto-rotate
camera-controls
src={url}
style={{
width: '100%',
height: fullHeight ? '100%' : undefined,
}}
/>
</StyledNftDetailModel>
);
}
Expand Down
7 changes: 0 additions & 7 deletions apps/web/src/scenes/NftDetailPage/model-viewer.css

This file was deleted.

1 comment on commit 63a46dc

@vercel
Copy link

@vercel vercel bot commented on 63a46dc Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.