Skip to content

Commit

Permalink
feat: add landscape && fix shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
kcwww committed Sep 24, 2024
1 parent c5797a8 commit 053126e
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 8 deletions.
File renamed without changes.
File renamed without changes.
Binary file added public/assets/grounds/winter.glb
Binary file not shown.
2 changes: 2 additions & 0 deletions shared/components/3dModels/Bottom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const Bottom = () => {

bottom.scale.set(1, 1, 1);
bottom.position.set(0, 0, 0);
bottom.receiveShadow = true;
bottom.castShadow = true;
return <primitive object={bottom} />;
};

Expand Down
2 changes: 1 addition & 1 deletion shared/components/canvas/Base.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useGLTF } from '@react-three/drei';

const Base = () => {
const base = useGLTF('/assets/bases/ground1.glb').scene.clone();
const base = useGLTF('/assets/bases/base1.glb').scene.clone();

base.scale.set(1, 1, 1);
base.position.set(0, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion shared/components/canvas/Decoration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const Decoration = ({
child.userData.color = color;
child.userData.letterColor = MSG_COLOR[letterID].color;
child.userData.messageID = messageID;
child.castShadow = true;
child.castShadow = false;
if (child.name === 'Main') {
child.material = makeColorChangedMaterial(child, color);
}
Expand Down
11 changes: 8 additions & 3 deletions shared/components/canvas/Glass.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Sphere } from '@react-three/drei';
import { Color, Vector3 } from 'three';

const Glass = () => {
Expand All @@ -6,16 +7,20 @@ const Glass = () => {
const position = new Vector3(0, radius / 2, 0);

return (
<mesh position={position} name={'glass'}>
<sphereGeometry args={[radius, 36, 32]} />
<Sphere
args={[radius, 36, 32]}
position={position}
castShadow={true}
receiveShadow={true}
>
<meshStandardMaterial
transparent={true}
color={color}
opacity={0.1}
roughness={0}
metalness={1}
/>
</mesh>
</Sphere>
);
};

Expand Down
16 changes: 16 additions & 0 deletions shared/components/canvas/Ground.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useGLTF } from '@react-three/drei';

const Ground = () => {
const ground = useGLTF('/assets/grounds/winter.glb').scene.clone();

ground.scale.set(20, 20, 20);
ground.position.set(0, -5, 0);
ground.children.forEach((e) => (e.receiveShadow = true));
ground.castShadow = true;
ground.receiveShadow = true;
ground.name = 'Ground';

return <primitive object={ground} />;
};

export default Ground;
2 changes: 1 addition & 1 deletion shared/components/canvas/MainDecoration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const MainDecoration = () => {
deco.name = 'MainDeco';
deco.scale.set(1, 1, 1);
deco.position.set(0, 10, 0);
deco.children.forEach((mesh) => (mesh.castShadow = true));
deco.children.forEach((mesh) => (mesh.castShadow = false));

useFrame((_, delta) => {
if (delta > 1) {
Expand Down
14 changes: 12 additions & 2 deletions shared/components/canvas/SnowGlobeCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import MainDecoration from './MainDecoration';
import Glass from './Glass';
import Decorations from './Decorations';
import Snowflake from './Snowflake';
import Ground from './Ground';

const SnowGlobeCanvas = () => {
return (
Expand All @@ -29,10 +30,18 @@ const SnowGlobeCanvas = () => {
<OrbitControls target={[0, 0, 0]} enablePan={false} />
<ambientLight intensity={1} color={'#ffffff'} />
<directionalLight
position={[10, 10, 10]}
position={[10, 20, 10]}
intensity={2}
color={'#ffffff'}
castShadow
castShadow={true}
shadow-mapSize-width={2048} // shadow resolution
shadow-mapSize-height={2048}
shadow-camera-far={50} // default is 50
shadow-camera-near={1}
shadow-camera-left={-15}
shadow-camera-right={15}
shadow-camera-top={15}
shadow-camera-bottom={-15}
/>
<Glass />
{Array.from({ length: 100 }, (_, i) => (
Expand All @@ -42,6 +51,7 @@ const SnowGlobeCanvas = () => {
<MainDecoration />
<Base />
<Bottom />
<Ground />
</Canvas>
</section>
);
Expand Down

0 comments on commit 053126e

Please sign in to comment.