|
@@ -2,90 +2,85 @@ import { sdk } from "@/sdk";
|
|
|
import { ref, Ref, UnwrapRef, watch, watchEffect } from "vue";
|
|
|
import { useViewStack } from "./viewStack";
|
|
|
|
|
|
-export const useCameraChange = <T>(change: () => T): Ref<UnwrapRef<T>> => {
|
|
|
- const data = ref(change())
|
|
|
+export const useCameraChange = <T>(change: () => T) => {
|
|
|
+ const data = ref(change());
|
|
|
+ let isPause = false
|
|
|
+ const update = () => {
|
|
|
+ if (isPause) return;
|
|
|
+ data.value = change() as UnwrapRef<T>;
|
|
|
+ };
|
|
|
useViewStack(() => {
|
|
|
- const update = () => {
|
|
|
- data.value = change() as UnwrapRef<T>
|
|
|
- }
|
|
|
sdk.sceneBus.on("cameraChange", update);
|
|
|
return () => {
|
|
|
sdk.sceneBus.off("cameraChange", update);
|
|
|
};
|
|
|
});
|
|
|
- return data
|
|
|
-}
|
|
|
+ return [data, () => isPause = true, () => {
|
|
|
+ isPause = false
|
|
|
+ update()
|
|
|
+}] as const;
|
|
|
+};
|
|
|
|
|
|
export const usePixel = (
|
|
|
- getter: () => ({ localPos: SceneLocalPos; modelId?: string } | undefined)
|
|
|
+ getter: () => { localPos: SceneLocalPos; modelId?: string } | undefined
|
|
|
) => {
|
|
|
- const pos = useCameraChange(getter)
|
|
|
- const pixel = ref<{ left: string; top: string }>();
|
|
|
- const updatePosStyle = () => {
|
|
|
- if (!pos.value) {
|
|
|
- pixel.value = void 0;
|
|
|
- return;
|
|
|
- }
|
|
|
+ const pos = ref(getter());
|
|
|
+ const getPosStyle = () => {
|
|
|
+ if (!pos.value) return void 0;
|
|
|
const screenPos = sdk.getScreenByPosition(
|
|
|
pos.value.localPos,
|
|
|
pos.value.modelId
|
|
|
);
|
|
|
- if (!screenPos) {
|
|
|
- pixel.value = void 0;
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (!screenPos) return void 0;
|
|
|
|
|
|
- pixel.value = {
|
|
|
+ return {
|
|
|
left: screenPos.pos.x + "px",
|
|
|
top: screenPos.pos.y + "px",
|
|
|
};
|
|
|
};
|
|
|
-
|
|
|
+ const [pixel, pause, recovery] = useCameraChange(getPosStyle);
|
|
|
|
|
|
useViewStack(() => {
|
|
|
- watch(getter, val => pos.value = val)
|
|
|
- const stop = watch(pos, updatePosStyle, {deep: true})
|
|
|
- return stop
|
|
|
+ watch(getter, (val) => (pos.value = val));
|
|
|
+ return watch(pos, () => {
|
|
|
+ pixel.value = getPosStyle()
|
|
|
+ }, { deep: true });
|
|
|
});
|
|
|
|
|
|
- return [pixel, pos] as const;
|
|
|
+ return [pixel, pos, pause, recovery] as const;
|
|
|
};
|
|
|
|
|
|
-
|
|
|
export const usePixels = (
|
|
|
- getter: () => ({ localPos: SceneLocalPos; modelId: string }[])
|
|
|
+ getter: () => { localPos: SceneLocalPos; modelId: string }[]
|
|
|
) => {
|
|
|
- const positions = ref(getter())
|
|
|
- watch(getter, val => {
|
|
|
- positions.value = val
|
|
|
- })
|
|
|
- const pixels = ref<({ left: string; top: string } | null)[]>();
|
|
|
- const updatePosStyle = () => {
|
|
|
- pixels.value = []
|
|
|
+ const positions = ref(getter());
|
|
|
+ watch(getter, (val) => {
|
|
|
+ positions.value = val;
|
|
|
+ });
|
|
|
+
|
|
|
+ const getPosStyle = () => {
|
|
|
+ const pixels: ({left: string, top: string} | null)[] = [];
|
|
|
for (let i = 0; i < positions.value.length; i++) {
|
|
|
- const pos = positions.value[i]
|
|
|
- const screenPos = sdk.getScreenByPosition(
|
|
|
- pos.localPos,
|
|
|
- pos.modelId
|
|
|
- );
|
|
|
+ const pos = positions.value[i];
|
|
|
+ const screenPos = sdk.getScreenByPosition(pos.localPos, pos.modelId);
|
|
|
if (screenPos) {
|
|
|
- pixels.value[i] = {
|
|
|
+ pixels[i] = {
|
|
|
left: screenPos.pos.x + "px",
|
|
|
top: screenPos.pos.y + "px",
|
|
|
};
|
|
|
} else {
|
|
|
- pixels.value[i] = screenPos
|
|
|
+ pixels[i] = null;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
- watch(positions, updatePosStyle, {deep: true})
|
|
|
+ const [pixels, pause, recovery] = useCameraChange(getPosStyle)
|
|
|
|
|
|
useViewStack(() => {
|
|
|
- sdk.sceneBus.on("cameraChange", updatePosStyle);
|
|
|
- return () => {
|
|
|
- sdk.sceneBus.off("cameraChange", updatePosStyle);
|
|
|
- };
|
|
|
+ watch(getter, (val) => (positions.value = val));
|
|
|
+ return watch(positions, () => {
|
|
|
+ pixels.value = getPosStyle()
|
|
|
+ }, { deep: true });
|
|
|
});
|
|
|
|
|
|
- return [pixels, positions] as const;
|
|
|
+ return [pixels, positions, pause, recovery] as const;
|
|
|
};
|