-
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.
- Loading branch information
Showing
28 changed files
with
527 additions
and
33 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,4 @@ | ||
import { createForceUpdateContext } from "@/hooks/useForceUpdate"; | ||
|
||
export const [FaceLayoutContext, useUpdateFaceLayout] = | ||
createForceUpdateContext(); |
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,13 @@ | ||
import { FC } from "react"; | ||
import { SVG3D } from "./SVG3D"; | ||
import { Text3D, Text3DProps } from "./Text3D"; | ||
|
||
export interface FaceTextProps extends Omit<Text3DProps, "text"> { | ||
text: string | number; | ||
} | ||
|
||
export const FaceText: FC<FaceTextProps> = ({ text, ...props }) => { | ||
if (typeof text === "number") return <SVG3D id={text} />; | ||
|
||
return <Text3D text={text} {...props} />; | ||
}; |
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,47 @@ | ||
import { useUpdateCSG } from "@/components/three/csg/CSGContext"; | ||
import { FONT_MATERIAL } from "@/materials"; | ||
import { useFontSettings, useFontsStore } from "@/stores/FontSettingsStore"; | ||
import { getBoundingBox } from "@/utils/alignObject"; | ||
import { getSVGGeometry } from "@/utils/fonts/getSVGGeometry"; | ||
import { FC, memo, useMemo } from "react"; | ||
import { Vector3 } from "three"; | ||
import { useUpdateFaceLayout } from "./FaceLayoutContext"; | ||
|
||
export interface SVG3DProps { | ||
id: number; | ||
} | ||
|
||
export const SVG3D: FC<SVG3DProps> = memo(({ id }) => { | ||
useUpdateFaceLayout(); | ||
useUpdateCSG(); | ||
|
||
const svgs = useFontsStore((state) => state.svgs); | ||
const segments = useFontSettings((state) => state.segments); | ||
const fontScale = useFontSettings((state) => state.fontScale); | ||
const svgScale = useFontSettings((state) => state.svgScale); | ||
|
||
const svg = useMemo(() => { | ||
return svgs.find((svg) => svg.id === id) ?? null; | ||
}, [id, svgs]); | ||
|
||
const geometry = useMemo(() => { | ||
if (!svg) return null; | ||
|
||
return getSVGGeometry(svg, segments); | ||
}, [segments, svg]); | ||
|
||
if (geometry === null) return null; | ||
|
||
const bounds = getBoundingBox(geometry); | ||
const size = bounds.getSize(new Vector3()); | ||
|
||
const viewboxScale = svg?.scaleByViewbox ? svg.viewboxScale : null; | ||
const boxScale = viewboxScale ?? 1 / Math.max(size.x, size.y); | ||
const scale = (boxScale * svgScale) / fontScale; | ||
|
||
return ( | ||
<group scale-x={scale} scale-y={-scale}> | ||
<brush geometry={geometry} material={FONT_MATERIAL} /> | ||
</group> | ||
); | ||
}); |
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,66 @@ | ||
import { Input } from "@/shadcn/components/ui/input"; | ||
import { | ||
Select, | ||
SelectContent, | ||
SelectItem, | ||
SelectTrigger, | ||
} from "@/shadcn/components/ui/select"; | ||
import { useFontsStore } from "@/stores/FontSettingsStore"; | ||
import { FC, useId, useMemo } from "react"; | ||
import { SettingsRow } from "./SettingsRow"; | ||
|
||
export interface SettingsSVGSelectProps { | ||
label: string; | ||
value: string | number; | ||
onChange: (value: string | number) => void; | ||
} | ||
|
||
export const SettingsSVGSelect: FC<SettingsSVGSelectProps> = ({ | ||
label, | ||
value, | ||
onChange, | ||
}) => { | ||
const id = useId(); | ||
|
||
const svgs = useFontsStore((state) => state.svgs); | ||
|
||
const placeholder = useMemo(() => { | ||
if (typeof value === "string") return "Enter text"; | ||
|
||
return svgs.find((svg) => svg.id === value)?.name ?? "SVG selected"; | ||
}, [svgs, value]); | ||
|
||
return ( | ||
<SettingsRow label={label} id={id}> | ||
<Input | ||
className="col-span-6 h-8" | ||
id={id} | ||
type="text" | ||
value={typeof value === "number" ? "" : value} | ||
placeholder={placeholder} | ||
onChange={(e) => onChange(e.currentTarget.value)} | ||
/> | ||
|
||
<Select | ||
value={typeof value === "number" ? value.toString() : "-1"} | ||
onValueChange={(value) => onChange(parseInt(value))} | ||
> | ||
<SelectTrigger className="col-span-2 h-8" /> | ||
|
||
<SelectContent> | ||
{svgs.length === 0 ? ( | ||
<SelectItem value="None" disabled> | ||
No SVGs loaded | ||
</SelectItem> | ||
) : ( | ||
svgs.map((item, i) => ( | ||
<SelectItem key={i} value={item.id.toString()}> | ||
{item.name} | ||
</SelectItem> | ||
)) | ||
)} | ||
</SelectContent> | ||
</Select> | ||
</SettingsRow> | ||
); | ||
}; |
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
Oops, something went wrong.