-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAvatar.tsx
105 lines (95 loc) · 3.59 KB
/
Avatar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Avatar.tsx
"use client";
import React, { FC, useEffect, useRef } from "react";
import { useAnimations, useFBX, useGLTF } from "@react-three/drei";
import { GroupProps } from "@react-three/fiber";
const Avatar: FC<GroupProps> = (props) => {
const { nodes, materials } = useGLTF("/avatar.glb");
// adding ref for group to add animation
const groupRef = useRef();
// loading you animation
const { animations: avatarAnimation } = useFBX("/avatar-animation.fbx");
// updating you animation name (optional)
avatarAnimation[0].name = "avatar-animation";
// creating actions based on the animation
const { actions } = useAnimations(avatarAnimation, groupRef);
// playing the animation
useEffect(() => {
if (actions?.["avatar-animation"])
actions["avatar-animation"].reset().play();
}, [actions]);
return (
<group {...props} ref={groupRef as any} dispose={null}>
<group>
<primitive object={nodes.Hips} />
<skinnedMesh
name="EyeLeft"
geometry={(nodes.EyeLeft as any).geometry}
material={materials.Wolf3D_Eye}
skeleton={(nodes.EyeLeft as any).skeleton}
morphTargetDictionary={(nodes.EyeLeft as any).morphTargetDictionary}
morphTargetInfluences={(nodes.EyeLeft as any).morphTargetInfluences}
/>
<skinnedMesh
name="EyeRight"
geometry={(nodes.EyeRight as any).geometry}
material={materials.Wolf3D_Eye}
skeleton={(nodes.EyeRight as any).skeleton}
morphTargetDictionary={(nodes.EyeRight as any).morphTargetDictionary}
morphTargetInfluences={(nodes.EyeRight as any).morphTargetInfluences}
/>
<skinnedMesh
name="Wolf3D_Head"
geometry={(nodes.Wolf3D_Head as any).geometry}
material={materials.Wolf3D_Skin}
skeleton={(nodes.Wolf3D_Head as any).skeleton}
morphTargetDictionary={
(nodes.Wolf3D_Head as any).morphTargetDictionary
}
morphTargetInfluences={
(nodes.Wolf3D_Head as any).morphTargetInfluences
}
/>
<skinnedMesh
name="Wolf3D_Teeth"
geometry={(nodes.Wolf3D_Teeth as any).geometry}
material={materials.Wolf3D_Teeth}
skeleton={(nodes.Wolf3D_Teeth as any).skeleton}
morphTargetDictionary={
(nodes.Wolf3D_Teeth as any).morphTargetDictionary
}
morphTargetInfluences={
(nodes.Wolf3D_Teeth as any).morphTargetInfluences
}
/>
<skinnedMesh
geometry={(nodes.Wolf3D_Hair as any).geometry}
material={materials.Wolf3D_Hair}
skeleton={(nodes.Wolf3D_Hair as any).skeleton}
/>
<skinnedMesh
geometry={(nodes.Wolf3D_Body as any).geometry}
material={materials.Wolf3D_Body}
skeleton={(nodes.Wolf3D_Body as any).skeleton}
/>
<skinnedMesh
geometry={(nodes.Wolf3D_Outfit_Bottom as any).geometry}
material={materials.Wolf3D_Outfit_Bottom}
skeleton={(nodes.Wolf3D_Outfit_Bottom as any).skeleton}
/>
<skinnedMesh
geometry={(nodes.Wolf3D_Outfit_Footwear as any).geometry}
material={materials.Wolf3D_Outfit_Footwear}
skeleton={(nodes.Wolf3D_Outfit_Footwear as any).skeleton}
/>
<skinnedMesh
geometry={(nodes.Wolf3D_Outfit_Top as any).geometry}
material={materials.Wolf3D_Outfit_Top}
skeleton={(nodes.Wolf3D_Outfit_Top as any).skeleton}
/>
</group>
</group>
);
};
useGLTF.preload("/avatar.glb");
export default Avatar;