-
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.
Render solution to canvas - clean up
- Loading branch information
1 parent
205f769
commit ed80d49
Showing
6 changed files
with
55 additions
and
39 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
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,35 @@ | ||
import { useLoader } from '@react-three/fiber'; | ||
import { TextureLoader } from 'three'; | ||
|
||
function InfoPanel({ text, font, position }) { | ||
const texture = useLoader(TextureLoader, createTextCanvas(text, font).toDataURL()); | ||
|
||
return ( | ||
<mesh position={[position.x, position.y, 0]} > | ||
<planeGeometry args={[4, 2]} /> | ||
<meshStandardMaterial map={texture} transparent={true} opacity="1" /> | ||
</mesh> | ||
); | ||
} | ||
|
||
|
||
function createTextCanvas(text, font = '48px sans-serif') { | ||
const canvas = document.createElement('canvas'); | ||
const context = canvas.getContext('2d'); | ||
|
||
// Set canvas size | ||
canvas.width = 1024; | ||
canvas.height = 512; | ||
|
||
// Draw text | ||
context.font = font; | ||
context.fillStyle = '#ddf4ff'; | ||
context.textAlign = 'center'; | ||
context.textBaseline = 'middle'; | ||
context.fillText(text, canvas.width / 2, canvas.height / 2); | ||
|
||
return canvas; | ||
} | ||
|
||
|
||
export default InfoPanel; |
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