-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ddbb590
commit 85ef5b6
Showing
7 changed files
with
289 additions
and
136 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"use client"; | ||
|
||
import { useEffect, useRef } from "react"; | ||
import { SkinViewer, SkinViewerOptions } from "skinview3d"; | ||
|
||
interface ViewerProps extends React.HTMLAttributes<HTMLCanvasElement> { | ||
viewerConfig?: ConfigTypes, | ||
} | ||
|
||
interface ConfigTypes extends SkinViewerOptions { | ||
skin: string; | ||
} | ||
|
||
export default function MinecraftViewer({ viewerConfig, ...props }: ViewerProps) { | ||
const viewerRef = useRef<HTMLCanvasElement>(null); | ||
|
||
useEffect(() => { | ||
const processSkin = async (skin: string): Promise<string | null> => { | ||
try { | ||
const skinUrl = await fetch(`/api/data/misc/minecraftSkin/${skin}`);; | ||
return await skinUrl.json(); | ||
} catch (error) { | ||
console.error("Failed to fetch skin URL:", error); | ||
} | ||
return null; | ||
}; | ||
|
||
const loadSkinViewer = async () => { | ||
const { current } = viewerRef; | ||
console.log("test") | ||
if (current && viewerConfig) { | ||
const skinUrl = await processSkin(viewerConfig.skin); | ||
|
||
if (skinUrl) { | ||
console.log(skinUrl) | ||
const processedConfig = { | ||
...viewerConfig, | ||
skin: skinUrl | ||
}; | ||
|
||
const skinViewer = new SkinViewer({ | ||
canvas: current, | ||
width: 300, | ||
height: 400, | ||
...processedConfig | ||
}); | ||
skinViewer.autoRotate = true; | ||
} | ||
} | ||
}; | ||
|
||
loadSkinViewer(); | ||
}, [viewerConfig]); | ||
|
||
return ( | ||
<canvas ref={viewerRef} {...props}></canvas> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"use client"; | ||
|
||
import { useEffect, useRef } from "react"; | ||
import VanillaTilt from "vanilla-tilt"; | ||
|
||
interface TiltProps extends React.HTMLAttributes<HTMLDivElement> { | ||
children: React.ReactNode; | ||
} | ||
|
||
export default function Tilt({ children, ...props }: TiltProps) { | ||
const tiltRef = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
const { current } = tiltRef; | ||
if (current) { | ||
VanillaTilt.init(current, { | ||
max: 25, | ||
speed: 400, | ||
scale: 1.1 | ||
}); | ||
} | ||
|
||
return () => { | ||
// have to tsignore because javascript | ||
// @ts-ignore | ||
if (current && current.vanillaTilt) { | ||
// @ts-ignore | ||
current.vanillaTilt.destroy(); | ||
} | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div ref={tiltRef} {...props}> | ||
{children} | ||
</div> | ||
); | ||
} |