-
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.
Showing
17 changed files
with
143 additions
and
105 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,84 @@ | ||
import { useRef } from 'react'; | ||
import { useFrame } from '@react-three/fiber'; | ||
import { useGLTF } from '@react-three/drei'; | ||
import * as THREE from 'three'; | ||
import { SENTIMENT_MODEL } from '@constants'; | ||
|
||
interface SnowProps { | ||
centerPosition: THREE.Vector3; | ||
rangeRadius: number; | ||
sentiment: string; | ||
} | ||
|
||
const randomizePosition = ( | ||
target: THREE.Mesh, | ||
centerPosition: THREE.Vector3, | ||
radius: number | ||
) => { | ||
//변경필요 | ||
target.position.set( | ||
centerPosition.x - 3 + Math.random() * 6, | ||
centerPosition.y + radius + Math.random() * radius * 2, | ||
centerPosition.z - 3 + Math.random() * 6 | ||
); | ||
}; | ||
|
||
const fallingAnimate = ( | ||
target: THREE.Mesh, | ||
speed: number, | ||
centerPosition: THREE.Vector3, | ||
radius: number | ||
) => { | ||
if (target.position.y <= -1) { | ||
randomizePosition(target, centerPosition, radius); | ||
//const newScale = 0.2 + Math.random() * 0.5; | ||
//target.scale.set(newScale, newScale, newScale); | ||
} | ||
target.position.y -= speed; | ||
}; | ||
|
||
const rotateAnimate = (target: THREE.Mesh, speed: number) => { | ||
target.rotation.y += speed; | ||
}; | ||
|
||
const visibleInRange = ( | ||
target: THREE.Mesh, | ||
centerPosition: THREE.Vector3, | ||
radius: number | ||
) => { | ||
target.visible = | ||
target.position.distanceTo(centerPosition) > radius ? false : true; | ||
}; | ||
|
||
const Emoji: React.FC<SnowProps> = ({ | ||
centerPosition, | ||
rangeRadius, | ||
sentiment | ||
}) => { | ||
const snowRef = useRef<THREE.Mesh>(null); | ||
const position = new THREE.Vector3( | ||
centerPosition.x - rangeRadius + Math.random() * rangeRadius * 2, | ||
centerPosition.y + rangeRadius + Math.random() * rangeRadius * 2, | ||
centerPosition.z - rangeRadius + Math.random() * rangeRadius * 2 | ||
); | ||
const index = sentiment === 'positive' ? 1 : sentiment === 'neutral' ? 2 : 3; | ||
const snow = useGLTF(SENTIMENT_MODEL[index].fileName).scene.clone(); | ||
|
||
snow.scale.set(0.7, 0.7, 0.7); | ||
snow.position.set(position.x, position.y, position.z); | ||
snow.rotation.y = Math.random(); | ||
|
||
useFrame((_, delta) => { | ||
const snow = snowRef.current; | ||
const speed = 2 * delta; | ||
if (snow) { | ||
fallingAnimate(snow, speed, centerPosition, rangeRadius); | ||
rotateAnimate(snow, speed); | ||
visibleInRange(snow, centerPosition, rangeRadius - 1); | ||
} | ||
}); | ||
|
||
return <primitive object={snow} ref={snowRef} />; | ||
}; | ||
|
||
export default Emoji; |
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 |
---|---|---|
@@ -1 +1 @@ | ||
export { DECO, MAIN, MSG_COLOR, BOTTOM } from './deco'; | ||
export { SENTIMENT_MODEL, DECO, MAIN, MSG_COLOR, BOTTOM } from './deco'; |
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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export { default as IsLogin } from './IsLogin'; | ||
export { default as IsSnowballData } from './IsSnowballData'; |