-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add flying text, add fallback, update test
- Loading branch information
Showing
6 changed files
with
149 additions
and
49 deletions.
There are no files selected for viewing
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
136 changes: 106 additions & 30 deletions
136
src/contentComponents/canvasComponents/CityText/CityText.tsx
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,45 +1,121 @@ | ||
import { FC, useRef } from "react" | ||
import { FC, useRef, Fragment, useMemo } from "react" | ||
import { useFrame } from "@react-three/fiber" | ||
import assetsPath from "../../../data/assetsPath.json" | ||
import { Text, Line } from "@react-three/drei" | ||
import * as THREE from "three" | ||
import { BigNameValue } from "../canvasComponents.types" | ||
|
||
const CityText: FC = () => { | ||
console.log("CITY TEXT") | ||
const textRef = useRef<THREE.Mesh>(null) | ||
|
||
const schoolRef = useRef<THREE.Mesh>(null) | ||
const footballRef = useRef<THREE.Mesh>(null) | ||
const jeruzalemRef = useRef<THREE.Mesh>(null) | ||
const betlehemRef = useRef<THREE.Mesh>(null) | ||
const kindergartenRef = useRef<THREE.Mesh>(null) | ||
const doctorRef = useRef<THREE.Mesh>(null) | ||
const churchRef = useRef<THREE.Mesh>(null) | ||
|
||
useFrame(({ camera }) => { | ||
if (textRef.current) { | ||
// Make the text follow the camera's rotation | ||
textRef.current.quaternion.copy(camera.quaternion) | ||
} | ||
}) | ||
const refs = [ | ||
schoolRef, | ||
footballRef, | ||
jeruzalemRef, | ||
betlehemRef, | ||
kindergartenRef, | ||
doctorRef, | ||
churchRef, | ||
] | ||
|
||
return ( | ||
<> | ||
<Text | ||
ref={textRef} | ||
font={assetsPath.cityFonts} | ||
fontSize={10} | ||
// material-toneMapped={false} | ||
position={[-200, 45, 208]} | ||
rotation={[0, -0.55, 0]} // Rotate 45 degrees around the Y-axis | ||
refs.forEach((ref) => { | ||
if (ref.current) { | ||
ref.current.quaternion.copy(camera.quaternion) | ||
} | ||
}) | ||
}) | ||
|
||
/* {...textOptions} */ | ||
> | ||
Hello world! | ||
<meshBasicMaterial side={THREE.DoubleSide} color={"red"} /> | ||
</Text> | ||
<Line | ||
points={[ | ||
[-200, 40, 205], // Start point of the line (slightly below the text) | ||
[-200, 5, 205], // End point of the line (further down) | ||
]} | ||
color="black" | ||
lineWidth={1} | ||
/> | ||
</> | ||
const defaultValues: BigNameValue[] = useMemo( | ||
() => [ | ||
{ | ||
text: "OŠ Braće Radić", | ||
ref: schoolRef, | ||
textPosition: [-30, 45, 100], | ||
lineStart: [-30, 40, 100], | ||
lineEnd: [-30, 15, 100], | ||
}, | ||
{ | ||
text: "NK Botinec", | ||
ref: footballRef, | ||
textPosition: [-315, 45, 290], | ||
lineStart: [-315, 40, 290], | ||
lineEnd: [-315, 10, 290], | ||
}, | ||
{ | ||
text: "Park Jeruzalem", | ||
ref: jeruzalemRef, | ||
textPosition: [-225, 45, 310], | ||
lineStart: [-225, 40, 310], | ||
lineEnd: [-225, 10, 310], | ||
}, | ||
{ | ||
text: "Park Betlehem", | ||
ref: betlehemRef, | ||
textPosition: [140, 45, -150], | ||
lineStart: [140, 40, -150], | ||
lineEnd: [140, 10, -150], | ||
}, | ||
{ | ||
text: "Dječji vrtić Botinec", | ||
ref: kindergartenRef, | ||
textPosition: [290, 45, 250], | ||
lineStart: [290, 40, 250], | ||
lineEnd: [290, 15, 250], | ||
}, | ||
{ | ||
text: "Dom zdravlja", | ||
ref: doctorRef, | ||
textPosition: [330, 45, 155], | ||
lineStart: [330, 40, 155], | ||
lineEnd: [330, 15, 155], | ||
}, | ||
{ | ||
text: "Crkva sv.Stjepan", | ||
ref: churchRef, | ||
textPosition: [145, 45, 220], | ||
lineStart: [145, 40, 220], | ||
lineEnd: [145, 15, 220], | ||
}, | ||
], | ||
[], | ||
) | ||
|
||
const renderBigNames = () => { | ||
return defaultValues.map((value, index) => ( | ||
<Fragment key={index}> | ||
<Text | ||
ref={value.ref} | ||
font={assetsPath.cityFonts} | ||
fontSize={8} | ||
position={value.textPosition} | ||
rotation={[0, 0, 0]} | ||
outlineWidth={0.4} | ||
outlineColor={new THREE.Color("#000000")} | ||
> | ||
{value.text} | ||
<meshBasicMaterial side={THREE.DoubleSide} color={"#FFD700"} /> | ||
</Text> | ||
<Line | ||
points={[ | ||
value.lineStart, // Start point of the line (slightly below the text) | ||
value.lineEnd, // End point of the line (further down) | ||
]} | ||
color="black" | ||
lineWidth={1.2} | ||
/> | ||
</Fragment> | ||
)) | ||
} | ||
return <>{renderBigNames()}</> | ||
} | ||
|
||
export default CityText |
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
20 changes: 16 additions & 4 deletions
20
src/contentComponents/canvasComponents/fallback/Fallback.tsx
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,10 +1,22 @@ | ||
import { useRef } from "react" | ||
import { useFrame } from "@react-three/fiber" | ||
import * as THREE from "three" | ||
|
||
const Fallback = () => { | ||
const meshRef = useRef<THREE.Mesh>(null) | ||
|
||
// This function updates every frame, rotating the mesh | ||
useFrame(() => { | ||
if (meshRef.current) { | ||
meshRef.current.rotation.x += 0.1 // Spin on the x-axis | ||
} | ||
}) | ||
|
||
return ( | ||
<mesh> | ||
<sphereGeometry /> | ||
<meshStandardMaterial color="white" /> | ||
<mesh ref={meshRef} scale={[20, 20, 20]} position={[27, -120, 0]}> | ||
<torusGeometry args={[1, 0.3, 16, 100]} /> | ||
<meshStandardMaterial color="#A8B99F" /> | ||
</mesh> | ||
) | ||
} | ||
|
||
export default Fallback |