decal
This commit is contained in:
@ -2,7 +2,7 @@ import { create } from "zustand";
|
||||
import { models } from "@/constant/models.ts";
|
||||
import { Vector3 } from "three";
|
||||
import { devtools } from "zustand/middleware";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
// import { v4 as uuidv4 } from "uuid";
|
||||
export enum StickerType {
|
||||
text,
|
||||
logo,
|
||||
@ -13,6 +13,7 @@ export interface DecalSticker {
|
||||
postion: Vector3;
|
||||
text?: string;
|
||||
url: string;
|
||||
scale: number;
|
||||
type: StickerType;
|
||||
}
|
||||
|
||||
@ -32,10 +33,14 @@ interface ModelState {
|
||||
decalDragging: boolean;
|
||||
setDecalDragging: (enable: boolean) => void;
|
||||
|
||||
decalZooming: boolean;
|
||||
setDecalZooming: (enable: boolean) => void;
|
||||
|
||||
decals: DecalSticker[];
|
||||
activeDecal?: string;
|
||||
setDecalPositon: (id: string, postion: Vector3) => void;
|
||||
setDecals: (decals: DecalSticker[]) => void;
|
||||
setDecalScale: (id: string, scale: number) => void;
|
||||
setActiveDecal: (decalId: string) => void;
|
||||
}
|
||||
|
||||
@ -44,7 +49,18 @@ const useModelStore = create<ModelState>()(
|
||||
modelLoading: 0,
|
||||
setModelLoading: (progress: number) =>
|
||||
set(() => ({ modelLoading: progress })),
|
||||
|
||||
setDecalScale: (id: string, scale: number) =>
|
||||
set((state) => {
|
||||
const _decals = state.decals.map((el) => {
|
||||
if (el.id === id) {
|
||||
el.scale = scale;
|
||||
}
|
||||
return el;
|
||||
});
|
||||
return {
|
||||
decals: _decals,
|
||||
};
|
||||
}),
|
||||
activeModel: 0,
|
||||
setActiveModel: (index: number) =>
|
||||
set(() => ({
|
||||
@ -71,14 +87,11 @@ const useModelStore = create<ModelState>()(
|
||||
setDecalDragging: (enable: boolean) =>
|
||||
set(() => ({ decalDragging: enable })),
|
||||
|
||||
decals: [
|
||||
{
|
||||
id: uuidv4(),
|
||||
url: "/textures/archlogo.png",
|
||||
postion: new Vector3(0, 0, 0),
|
||||
type: StickerType.logo,
|
||||
},
|
||||
],
|
||||
// 是否正在缩放sticker
|
||||
decalZooming: false,
|
||||
setDecalZooming: (enable: boolean) => set(() => ({ decalZooming: enable })),
|
||||
|
||||
decals: [],
|
||||
activeDecal: undefined,
|
||||
setDecalPositon: (id: string, postion: Vector3) =>
|
||||
set((state) => {
|
||||
@ -100,10 +113,17 @@ const useModelStore = create<ModelState>()(
|
||||
set(() => ({
|
||||
decals,
|
||||
})),
|
||||
|
||||
setActiveDecal: (decalId: string) =>
|
||||
set(() => ({
|
||||
activeDecal: decalId,
|
||||
})),
|
||||
|
||||
// // @ts-ignore
|
||||
// setDecalScale: (id: string, scale: number) =>
|
||||
// set(() => ({
|
||||
// activeArea: 0
|
||||
// })),
|
||||
})),
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user