|
@@ -1,11 +1,12 @@
|
|
-import { Pos } from "@/utils/math";
|
|
|
|
|
|
+import { Pos, Size } from "@/utils/math";
|
|
import { extractConnectedSegments } from "@/utils/polygon";
|
|
import { extractConnectedSegments } from "@/utils/polygon";
|
|
import { validNum } from "@/utils/shared";
|
|
import { validNum } from "@/utils/shared";
|
|
|
|
+import { aiIconMap, iconGroups } from "../constant";
|
|
|
|
|
|
export enum SCENE_TYPE {
|
|
export enum SCENE_TYPE {
|
|
- fuse,
|
|
|
|
- mesh,
|
|
|
|
- cloud,
|
|
|
|
|
|
+ fuse = "fuse",
|
|
|
|
+ mesh = "mesh",
|
|
|
|
+ cloud = "cloud",
|
|
}
|
|
}
|
|
export type Scene = {
|
|
export type Scene = {
|
|
type: SCENE_TYPE;
|
|
type: SCENE_TYPE;
|
|
@@ -14,30 +15,49 @@ export type Scene = {
|
|
id: string;
|
|
id: string;
|
|
};
|
|
};
|
|
|
|
|
|
-export const SceneTypeNames = {
|
|
|
|
- [SCENE_TYPE.fuse]: "融合场景",
|
|
|
|
- [SCENE_TYPE.mesh]: "Mesh场景",
|
|
|
|
- [SCENE_TYPE.cloud]: "点云场景",
|
|
|
|
|
|
+export type SceneFloor = {
|
|
|
|
+ name: string;
|
|
|
|
+ subgroup?: number,
|
|
|
|
+ geos: (Pos & { z: number })[][];
|
|
|
|
+ thumb?: string;
|
|
|
|
+ box?: {
|
|
|
|
+ bound: {
|
|
|
|
+ x_min: number;
|
|
|
|
+ x_max: number;
|
|
|
|
+ y_min: number;
|
|
|
|
+ y_max: number;
|
|
|
|
+ z_min: number;
|
|
|
|
+ z_max: number;
|
|
|
|
+ };
|
|
|
|
+ rotate: number;
|
|
|
|
+ scale: number;
|
|
|
|
+ };
|
|
|
|
+ compass?: number;
|
|
};
|
|
};
|
|
|
|
|
|
-export const SceneTypeTempUrls = {
|
|
|
|
- [SCENE_TYPE.fuse]: import.meta.env.VITE_FUSE_TEMP_URL,
|
|
|
|
- [SCENE_TYPE.mesh]: import.meta.env.VITE_MESH_TEMP_URL,
|
|
|
|
- [SCENE_TYPE.cloud]: import.meta.env.VITE_CLOUD_TEMP_URL,
|
|
|
|
|
|
+export type SceneFloors = SceneFloor[];
|
|
|
|
+
|
|
|
|
+export type Taging = {
|
|
|
|
+ url: string;
|
|
|
|
+ position: Pos & { z: number };
|
|
|
|
+ size?: Size;
|
|
|
|
+ name?: string
|
|
|
|
+ pixel?: boolean;
|
|
|
|
+ subgroup?: string;
|
|
};
|
|
};
|
|
|
|
|
|
-export const SceneTypeApiUrls = {
|
|
|
|
- [SCENE_TYPE.fuse]: import.meta.env.VITE_FUSE_API_URL,
|
|
|
|
- [SCENE_TYPE.mesh]: import.meta.env.VITE_MESH_OSS_URL,
|
|
|
|
- [SCENE_TYPE.cloud]: import.meta.env.VITE_CLOUD_API_URL,
|
|
|
|
|
|
+export const SceneTypeNames = {
|
|
|
|
+ [SCENE_TYPE.fuse]: "融合场景",
|
|
|
|
+ [SCENE_TYPE.mesh]: "Mesh场景",
|
|
|
|
+ [SCENE_TYPE.cloud]: "点云场景",
|
|
};
|
|
};
|
|
|
|
|
|
-export const getSceneApi = async (sceneType: SCENE_TYPE, url: string) => {
|
|
|
|
|
|
+export const getSceneApi = async (type: string, url: string) => {
|
|
let uri: string;
|
|
let uri: string;
|
|
try {
|
|
try {
|
|
- uri = new URL(url, SceneTypeApiUrls[sceneType]).toString();
|
|
|
|
|
|
+ uri = new URL(url, window.platform.resourceURLS[type]).toString();
|
|
} catch {
|
|
} catch {
|
|
- uri = SceneTypeApiUrls[sceneType] + url;
|
|
|
|
|
|
+ uri = window.platform.resourceURLS[type] + url;
|
|
}
|
|
}
|
|
const res = await fetch(uri, { method: "HEAD" });
|
|
const res = await fetch(uri, { method: "HEAD" });
|
|
if (res.status !== 200) {
|
|
if (res.status !== 200) {
|
|
@@ -46,11 +66,6 @@ export const getSceneApi = async (sceneType: SCENE_TYPE, url: string) => {
|
|
return uri;
|
|
return uri;
|
|
};
|
|
};
|
|
|
|
|
|
-export type Taging = {
|
|
|
|
- url: string;
|
|
|
|
- position: Pos & { z: number };
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
export type Tagings = Taging[];
|
|
export type Tagings = Taging[];
|
|
|
|
|
|
export const compassGets = {
|
|
export const compassGets = {
|
|
@@ -58,19 +73,24 @@ export const compassGets = {
|
|
[SCENE_TYPE.cloud]: () => void 0,
|
|
[SCENE_TYPE.cloud]: () => void 0,
|
|
[SCENE_TYPE.mesh]: async (scene: Scene) => {
|
|
[SCENE_TYPE.mesh]: async (scene: Scene) => {
|
|
const prev = `/scene_view_data/${scene.m}`;
|
|
const prev = `/scene_view_data/${scene.m}`;
|
|
- const config = await getSceneApi(scene.type, `${prev}/data/scene.json`)
|
|
|
|
|
|
+ const config = await getSceneApi("oss", `${prev}/data/scene.json`)
|
|
.then((url) => fetch(url))
|
|
.then((url) => fetch(url))
|
|
.then((res) => res.json())
|
|
.then((res) => res.json())
|
|
.catch(() => ({ version: 0, billboards: 0, tags: 0, orientation: 0 }));
|
|
.catch(() => ({ version: 0, billboards: 0, tags: 0, orientation: 0 }));
|
|
|
|
|
|
- const floorpanCompass = await getSceneApi(scene.type, `${prev}/user/floorplan.json?_=${config.version}`)
|
|
|
|
- .then(url => fetch(url))
|
|
|
|
- .then(res => res.json())
|
|
|
|
- .then(data => data.compass)
|
|
|
|
- .catch(() => null)
|
|
|
|
- return (typeof floorpanCompass === 'number' ? floorpanCompass : config.orientation)
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+ const floorpanCompass = await getSceneApi(
|
|
|
|
+ "oss",
|
|
|
|
+ `${prev}/user/floorplan.json?_=${config.version}`
|
|
|
|
+ )
|
|
|
|
+ .then((url) => fetch(url))
|
|
|
|
+ .then((res) => res.json())
|
|
|
|
+ .then((data) => data.compass)
|
|
|
|
+ .catch(() => null);
|
|
|
|
+ return typeof floorpanCompass === "number"
|
|
|
|
+ ? floorpanCompass
|
|
|
|
+ : Number(config.orientation);
|
|
|
|
+ },
|
|
|
|
+};
|
|
|
|
|
|
export const taggingGets = {
|
|
export const taggingGets = {
|
|
[SCENE_TYPE.fuse]: async (scene: Scene, options: string[]) => {
|
|
[SCENE_TYPE.fuse]: async (scene: Scene, options: string[]) => {
|
|
@@ -141,14 +161,14 @@ export const taggingGets = {
|
|
[SCENE_TYPE.mesh]: async (scene: Scene, options: string[]) => {
|
|
[SCENE_TYPE.mesh]: async (scene: Scene, options: string[]) => {
|
|
const tags: Tagings = [];
|
|
const tags: Tagings = [];
|
|
const prev = `/scene_view_data/${scene.m}`;
|
|
const prev = `/scene_view_data/${scene.m}`;
|
|
- const config = await getSceneApi(scene.type, `${prev}/data/scene.json`)
|
|
|
|
|
|
+ const config = await getSceneApi("oss", `${prev}/data/scene.json`)
|
|
.then((url) => fetch(url))
|
|
.then((url) => fetch(url))
|
|
.then((res) => res.json())
|
|
.then((res) => res.json())
|
|
.catch(() => ({ version: 0, billboards: 0, tags: 0, orientation: 0 }));
|
|
.catch(() => ({ version: 0, billboards: 0, tags: 0, orientation: 0 }));
|
|
|
|
|
|
if (options.includes("hot") && config.tags) {
|
|
if (options.includes("hot") && config.tags) {
|
|
const medias = await getSceneApi(
|
|
const medias = await getSceneApi(
|
|
- scene.type,
|
|
|
|
|
|
+ "oss",
|
|
`${prev}/user/hot.json?_=${config.version}`
|
|
`${prev}/user/hot.json?_=${config.version}`
|
|
)
|
|
)
|
|
.then((url) => fetch(url))
|
|
.then((url) => fetch(url))
|
|
@@ -157,7 +177,7 @@ export const taggingGets = {
|
|
|
|
|
|
const reqs = medias.map((media: any) => {
|
|
const reqs = medias.map((media: any) => {
|
|
if (!validNum(media.position.x) || !validNum(media.position.y)) return;
|
|
if (!validNum(media.position.x) || !validNum(media.position.y)) return;
|
|
- return getSceneApi(scene.type, `${prev}/user/${media.icon}`)
|
|
|
|
|
|
+ return getSceneApi("oss", `${prev}/user/${media.icon}`)
|
|
.then((url) => {
|
|
.then((url) => {
|
|
tags.push({ url, position: media.position });
|
|
tags.push({ url, position: media.position });
|
|
})
|
|
})
|
|
@@ -169,7 +189,7 @@ export const taggingGets = {
|
|
|
|
|
|
if (options.includes("signage") && config.billboards) {
|
|
if (options.includes("signage") && config.billboards) {
|
|
const signages = await getSceneApi(
|
|
const signages = await getSceneApi(
|
|
- scene.type,
|
|
|
|
|
|
+ "oss",
|
|
`${prev}/user/billboards.json?_=${config.version}`
|
|
`${prev}/user/billboards.json?_=${config.version}`
|
|
)
|
|
)
|
|
.then((url) => fetch(url))
|
|
.then((url) => fetch(url))
|
|
@@ -178,46 +198,75 @@ export const taggingGets = {
|
|
|
|
|
|
signages.forEach((signage: any) => {
|
|
signages.forEach((signage: any) => {
|
|
if (!validNum(signage.pos.x) || !validNum(signage.pos.y)) return;
|
|
if (!validNum(signage.pos.x) || !validNum(signage.pos.y)) return;
|
|
- return getSceneApi(scene.type, `${prev}/user/${signage.icon}.png`)
|
|
|
|
|
|
+ return getSceneApi("oss", `${prev}/user/${signage.icon}.png`)
|
|
.then((url) => {
|
|
.then((url) => {
|
|
tags.push({ url, position: signage.pos });
|
|
tags.push({ url, position: signage.pos });
|
|
})
|
|
})
|
|
.catch(() => {});
|
|
.catch(() => {});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
- return tags
|
|
|
|
- },
|
|
|
|
-};
|
|
|
|
|
|
|
|
-export type SceneFloor = {
|
|
|
|
- name: string;
|
|
|
|
- geos: (Pos & { z: number })[][];
|
|
|
|
- thumb?: string;
|
|
|
|
- box?: {
|
|
|
|
- bound: {
|
|
|
|
- x_min: number;
|
|
|
|
- x_max: number;
|
|
|
|
- y_min: number;
|
|
|
|
- y_max: number;
|
|
|
|
- z_min: number;
|
|
|
|
- z_max: number;
|
|
|
|
- };
|
|
|
|
- rotate: number;
|
|
|
|
- scale: number;
|
|
|
|
- };
|
|
|
|
- compass?: number
|
|
|
|
-};
|
|
|
|
|
|
+ await getSceneApi(
|
|
|
|
+ "oss",
|
|
|
|
+ `${prev}/data/floorplan/ai.json?_=${config.version}`
|
|
|
|
+ )
|
|
|
|
+ .then((url) => fetch(url))
|
|
|
|
+ .then((res) => res.json())
|
|
|
|
+ .then((datas) => {
|
|
|
|
+ for (const data of datas) {
|
|
|
|
+ const reg = data.imagePath.match(/floor_(\d)\.png/);
|
|
|
|
+ const subgroup = reg ? Number(reg[1]) : undefined;
|
|
|
|
+ for (const shape of data.shapes) {
|
|
|
|
+ const pos = {
|
|
|
|
+ x: ((shape.bbox[0] + shape.bbox[2]) / 2) / data.imageWidth,
|
|
|
|
+ y: ((shape.bbox[1] + shape.bbox[3]) / 2) / data.imageHeight,
|
|
|
|
+ z: 0,
|
|
|
|
+ };
|
|
|
|
+ const size = {
|
|
|
|
+ width: (shape.bbox[2] - shape.bbox[0]) / data.imageWidth,
|
|
|
|
+ height: (shape.bbox[3] - shape.bbox[1]) / data.imageHeight,
|
|
|
|
+ };
|
|
|
|
+ const icon = shape.category in aiIconMap ? (aiIconMap as any)[shape.category] : shape.category
|
|
|
|
+ let name = ''
|
|
|
|
+ for (const group of iconGroups) {
|
|
|
|
+ for (const itemGroup of group.children) {
|
|
|
|
+ for (const item of itemGroup.children) {
|
|
|
|
+ if (item.icon === icon) {
|
|
|
|
+ name = item.name
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
-export type SceneFloors = SceneFloor[];
|
|
|
|
|
|
+ tags.push({
|
|
|
|
+ position: pos,
|
|
|
|
+ url: `/icons/${icon ? icon : 'circle'}.svg`,
|
|
|
|
+ name,
|
|
|
|
+ pixel: true,
|
|
|
|
+ size,
|
|
|
|
+ subgroup,
|
|
|
|
+ } as any);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .catch((e) => {
|
|
|
|
+ console.error(e);
|
|
|
|
+ });
|
|
|
|
+ return tags;
|
|
|
|
+ },
|
|
|
|
+};
|
|
|
|
|
|
export const getFloors = {
|
|
export const getFloors = {
|
|
[SCENE_TYPE.mesh]: async (scene: Scene) => {
|
|
[SCENE_TYPE.mesh]: async (scene: Scene) => {
|
|
- return getSceneApi(scene.type, `/scene_view_data/${scene.m}/data/floorplan_cad.json?_=${Date.now()}`)
|
|
|
|
|
|
+ return getSceneApi(
|
|
|
|
+ "oss",
|
|
|
|
+ `/scene_view_data/${scene.m}/data/floorplan_cad.json?_=${Date.now()}`
|
|
|
|
+ )
|
|
.then((url) => fetch(url))
|
|
.then((url) => fetch(url))
|
|
.then((res) => res.json())
|
|
.then((res) => res.json())
|
|
- .catch(() => ({ floors: [] }))
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+ .catch(() => ({ floors: [] }));
|
|
|
|
+ },
|
|
|
|
+};
|
|
|
|
|
|
export const lineGets = {
|
|
export const lineGets = {
|
|
[SCENE_TYPE.fuse]: async (scene: Scene) => {
|
|
[SCENE_TYPE.fuse]: async (scene: Scene) => {
|
|
@@ -228,7 +277,7 @@ export const lineGets = {
|
|
const prev = `/scene_view_data/${scene.m}/data/`;
|
|
const prev = `/scene_view_data/${scene.m}/data/`;
|
|
const [{ floors }, bounds] = await Promise.all([
|
|
const [{ floors }, bounds] = await Promise.all([
|
|
getFloors[SCENE_TYPE.mesh](scene),
|
|
getFloors[SCENE_TYPE.mesh](scene),
|
|
- getSceneApi(scene.type, `${prev}floorplan/info.json`)
|
|
|
|
|
|
+ getSceneApi("oss", `${prev}floorplan/info.json`)
|
|
.then((url) => fetch(url))
|
|
.then((url) => fetch(url))
|
|
.then((res) => res.json())
|
|
.then((res) => res.json())
|
|
.then((data) => data.floors)
|
|
.then((data) => data.floors)
|
|
@@ -239,19 +288,27 @@ export const lineGets = {
|
|
|
|
|
|
const reqs = floors
|
|
const reqs = floors
|
|
.filter((item: any) => !floorName || item.name === floorName)
|
|
.filter((item: any) => !floorName || item.name === floorName)
|
|
- .map((floor: any, ndx: number) => {
|
|
|
|
|
|
+ .map((floor: any) => {
|
|
|
|
+ console.log(
|
|
|
|
+ floor,
|
|
|
|
+ bounds.find((i: any) => i.subgroup === floor.subgroup)
|
|
|
|
+ );
|
|
const bound = {
|
|
const bound = {
|
|
...(floor.cadInfo.cadBoundingBox || {}),
|
|
...(floor.cadInfo.cadBoundingBox || {}),
|
|
- ...(bounds[ndx]?.bound || {}),
|
|
|
|
|
|
+ ...(bounds.find((i: any) => i.subgroup === floor.subgroup)?.bound ||
|
|
|
|
+ {}),
|
|
};
|
|
};
|
|
const item: any = {
|
|
const item: any = {
|
|
name: floor.name,
|
|
name: floor.name,
|
|
|
|
+ subgroup: floor.subgroup,
|
|
thumb: "",
|
|
thumb: "",
|
|
box: {
|
|
box: {
|
|
bound: {
|
|
bound: {
|
|
...bound,
|
|
...bound,
|
|
y_min: -bound.y_max,
|
|
y_min: -bound.y_max,
|
|
y_max: -bound.y_min,
|
|
y_max: -bound.y_min,
|
|
|
|
+ z_max: bound.z_max ? Number(bound.z_max) : bound.z_max,
|
|
|
|
+ z_min: bound.z_min ? Number(bound.z_min) : bound.z_min,
|
|
},
|
|
},
|
|
rotate: floor.cadInfo.res,
|
|
rotate: floor.cadInfo.res,
|
|
scale: floor.cadInfo.currentScale,
|
|
scale: floor.cadInfo.currentScale,
|
|
@@ -265,7 +322,7 @@ export const lineGets = {
|
|
};
|
|
};
|
|
data.push(item);
|
|
data.push(item);
|
|
return getSceneApi(
|
|
return getSceneApi(
|
|
- scene.type,
|
|
|
|
|
|
+ "oss",
|
|
`${prev}floorplan/floor_${floor.subgroup}.png`
|
|
`${prev}floorplan/floor_${floor.subgroup}.png`
|
|
)
|
|
)
|
|
.then((url) => (item.thumb = url))
|
|
.then((url) => (item.thumb = url))
|