Skip to content

Commit

Permalink
支持了前后移动
Browse files Browse the repository at this point in the history
  • Loading branch information
boybook committed Dec 26, 2024
1 parent ab7252f commit d76f93f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const App: React.FC = () => {
size: 10,
depth: 5,
y: 8,
z: 0,
rotY: 0,
materials: materialGradientMediumYellow,
outlineWidth: 0.4,
Expand All @@ -80,6 +81,7 @@ const App: React.FC = () => {
size: 5,
depth: 3,
y: -4,
z: 0,
rotY: 0,
materials: materialGradientLightBlue,
outlineWidth: 0.5,
Expand Down Expand Up @@ -127,6 +129,12 @@ const App: React.FC = () => {
const workspaceStr = localStorage.getItem('workspace');
if (workspaceStr) {
const workspace: WorkspaceData = JSON.parse(workspaceStr);
// 修复一些缺失的数据(兼容旧版数据)
workspace.texts.forEach((text) => {
if (!text.opts.z) {
text.opts.z = 0;
}
});
setLastWorkshop(workspace);
}
}, []);
Expand Down Expand Up @@ -243,6 +251,7 @@ const App: React.FC = () => {
size: 5,
depth: 3,
y: texts.length * -6,
z: 0,
rotY: 0,
materials: materialGradientLightBlue,
outlineWidth: 0.5,
Expand Down
9 changes: 9 additions & 0 deletions src/components/TextSettingsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ const TextSettingsPanel: React.FC<TextSettingsPanelProps> = ({
onChange={(val) => onTextOptionsChange({ ...textOptions, y: val })}
/>
</Form.Item>
<Form.Item label={`${gLang('frontBackPosition')} (${textOptions.z.toFixed(1)})`}>
<Slider
min={-20}
max={20}
step={0.1}
value={textOptions.z}
onChange={(val) => onTextOptionsChange({ ...textOptions, z: val })}
/>
</Form.Item>
<Form.Item label={`${gLang('upDownRotate')} (${textOptions.rotY.toFixed(1)})`}>
<Slider
min={-90}
Expand Down
13 changes: 1 addition & 12 deletions src/components/ThreeScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,9 @@ const ThreeScene = forwardRef<ThreeSceneHandle, ThreeSceneProps>(({ texts, fontU
}));

const { gLang } = useLanguage();

const text1Ref = useRef<THREE.Group>(null);
const text2Ref = useRef<THREE.Group>(null);

const messageApi = useMessage();


const [, setSelectedObjects] = useState<THREE.Object3D[]>([]);
const [font, setFont] = useState<Font | null>(null);

useEffect(() => {
Expand Down Expand Up @@ -99,12 +94,6 @@ const ThreeScene = forwardRef<ThreeSceneHandle, ThreeSceneProps>(({ texts, fontU
scene.background = null;
}, [scene]);

useEffect(() => {
if (text1Ref.current && text2Ref.current) {
setSelectedObjects([text1Ref.current, text2Ref.current]);
}
}, [text1Ref, text2Ref]);

return (
<>
{/* 添加光源 */}
Expand All @@ -126,7 +115,7 @@ const ThreeScene = forwardRef<ThreeSceneHandle, ThreeSceneProps>(({ texts, fontU
opts={text.opts}
globalTextureYOffset={globalTextureYOffset}
font={font}
position={[0, text.opts.y, 0]}
position={[0, text.opts.y, text.opts.z]}
rotation={[text.opts.rotY * (Math.PI / 180), 0, 0]}
/>
))}
Expand Down
3 changes: 3 additions & 0 deletions src/language.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const languageConfig: Readonly<LanguageConfig> = {
fontSize: "字体大小",
upDownRotate: "上下旋转",
upDownPosition: "上下位置",
frontBackPosition: "前后位置",
content: "文本内容",
texture: "纹理",
fontSuccess: "字体加载完成!",
Expand Down Expand Up @@ -123,6 +124,7 @@ export const languageConfig: Readonly<LanguageConfig> = {
fontSize: "Font Size",
upDownRotate: "Up Down Rotate",
upDownPosition: "Up Down Position",
frontBackPosition: "Front Back Position",
content: "Content",
texture: "Texture",
fontSuccess: "Font loaded successfully!",
Expand Down Expand Up @@ -189,6 +191,7 @@ export const languageConfig: Readonly<LanguageConfig> = {
fontSize: "フォントサイズ",
upDownRotate: "上下回転",
upDownPosition: "上下位置",
frontBackPosition: "前後位置",
content: "テキスト",
texture: "テクスチャ",
fontSuccess: "フォントが読み込まれました!",
Expand Down
1 change: 1 addition & 0 deletions src/types/text.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface TextOptions {
size: number;
depth: number;
y: number;
z: number;
rotY: number
materials: TextMaterials;
outlineWidth: number;
Expand Down

0 comments on commit d76f93f

Please sign in to comment.