Skip to content

Commit

Permalink
add dynamic sculpture component
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloose committed Nov 20, 2024
1 parent 889fdbe commit 6b2fe38
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
40 changes: 40 additions & 0 deletions app/src/pages/Gallery3D/components/gallery/DynamicSculpture.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useRef } from "react";
import { useGLTF } from "@react-three/drei";
import { useFrame } from "@react-three/fiber";
import * as THREE from "three";

interface DynamicSculptureProps {
glbUrl: string;
position: [number, number, number];
rotation: [number, number, number];
scale?: [number, number, number];
rotate?: boolean;
}

export function DynamicSculpture({
glbUrl,
position,
rotation,
scale = [1, 1, 1],
rotate = false,
}: DynamicSculptureProps) {
const { scene: model } = useGLTF(glbUrl);
const groupRef = useRef<THREE.Group>(null);

useFrame(() => {
if (rotate && groupRef.current) {
groupRef.current.rotation.y += 0.005;
}
});

return (
<group
ref={groupRef}
position={position}
rotation={rotation}
scale={scale}
>
<primitive object={model} />
</group>
);
}
11 changes: 9 additions & 2 deletions app/src/pages/Gallery3D/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { Ground } from './components/gallery/Ground';
import { FPV } from './components/gallery/FPV';
import { Scene } from './components/gallery/Scene';
import { Loader } from '@mantine/core';
import { DynamicPainting } from './components/gallery/Painting';
import { DynamicPainting } from './components/gallery/DynamicPainting';
import { DynamicSculpture } from './components/gallery/DynamicSculpture';

export const Gallery3D = ({ gallery }: { gallery: string }) => {
const { data, isLoading } = useApi<Array<UserContentFileElement>>(`gallery/${gallery}`);
Expand All @@ -19,7 +20,6 @@ export const Gallery3D = ({ gallery }: { gallery: string }) => {
[-2.190091, 1.010420, 1.957159], // Vertex 2
[-3.686093, 2.930418, 1.957160], // Vertex 3
[-3.686091, 1.010419, 1.957160], // Vertex 4

];

if (isLoading) {
Expand All @@ -44,6 +44,13 @@ export const Gallery3D = ({ gallery }: { gallery: string }) => {
imageUrl="https://upload.wikimedia.org/wikipedia/commons/thumb/3/3c/Tux_Droid_1.jpg/1200px-Tux_Droid_1.jpg"
vertices={paintingVertices}
/>
<DynamicSculpture
glbUrl="/assets/3d/chihiro.glb"
position={[2, 0, 0]}
rotation={[0, Math.PI / 4, 0]}
scale={[1, 1, 1]}
rotate={true}
/>
<Physics>
<FPV />
<Ground />
Expand Down

0 comments on commit 6b2fe38

Please sign in to comment.