|
@@ -3,6 +3,7 @@ import { extractConnectedSegments } from "@/utils/polygon";
|
|
|
import { validNum } from "@/utils/shared";
|
|
|
import { aiIconMap, iconGroups } from "../constant";
|
|
|
import { Euler, MathUtils, Object3D, Quaternion, Vector3 } from "three";
|
|
|
+import { getSvgContent, parseSvgContent } from "@/utils/resource";
|
|
|
|
|
|
export enum SCENE_TYPE {
|
|
|
fuse = "fuse",
|
|
@@ -42,7 +43,7 @@ export type Taging = {
|
|
|
url: string;
|
|
|
position: Pos & { z: number };
|
|
|
size?: Size;
|
|
|
- fixed?: boolean
|
|
|
+ fixed?: boolean;
|
|
|
rotate?: number;
|
|
|
name?: string;
|
|
|
pixel?: boolean;
|
|
@@ -92,7 +93,9 @@ const getBillYaw = (bill: any) => {
|
|
|
let billboard = new Object3D();
|
|
|
let plane = new Object3D();
|
|
|
billboard.add(plane);
|
|
|
- billboard.quaternion.copy({x: bill.qua[0], y: bill.qua[1], z: bill.qua[2], w: bill.qua[3]}).normalize(); //qua数据里的
|
|
|
+ billboard.quaternion
|
|
|
+ .copy({ x: bill.qua[0], y: bill.qua[1], z: bill.qua[2], w: bill.qua[3] })
|
|
|
+ .normalize(); //qua数据里的
|
|
|
plane.quaternion.setFromAxisAngle(
|
|
|
new Vector3(0, 0, 1),
|
|
|
MathUtils.degToRad(-bill.faceAngle)
|
|
@@ -102,7 +105,7 @@ const getBillYaw = (bill: any) => {
|
|
|
const right = new Vector3(1, 0, 0); //令躺倒时的旋转轴
|
|
|
|
|
|
let qua = plane.getWorldQuaternion(new Quaternion());
|
|
|
- const ld = isLieDown(billboard.quaternion)
|
|
|
+ const ld = isLieDown(billboard.quaternion);
|
|
|
if (!ld) {
|
|
|
//使朝其后方躺倒后再求angle
|
|
|
let rotAxis = right.clone().applyQuaternion(qua); //旋转轴
|
|
@@ -257,9 +260,9 @@ export const taggingGets = {
|
|
|
})
|
|
|
: getSceneApi("oss", `${prev}/user/${signage.icon}`);
|
|
|
|
|
|
- const yRotate = getBillYaw(signage)
|
|
|
+ const yRotate = getBillYaw(signage);
|
|
|
|
|
|
- console.log(signage)
|
|
|
+ console.log(signage);
|
|
|
return getIcon
|
|
|
.then((url) => {
|
|
|
tags.push({
|
|
@@ -276,7 +279,7 @@ export const taggingGets = {
|
|
|
size: {
|
|
|
// width: signage.width * (signage.scaleRatio / 100),
|
|
|
// height: signage.height * (signage.scaleRatio / 100),
|
|
|
- width: signage.width ,
|
|
|
+ width: signage.width,
|
|
|
height: signage.height,
|
|
|
},
|
|
|
});
|
|
@@ -294,6 +297,7 @@ export const taggingGets = {
|
|
|
.then((url) => fetch(url))
|
|
|
.then((res) => res.json())
|
|
|
.then((datas) => {
|
|
|
+ const loadPromises: Promise<void>[] = [];
|
|
|
for (const data of datas) {
|
|
|
const reg = data.imagePath.match(/floor_(\d)\.png/);
|
|
|
const subgroup = reg ? Number(reg[1]) : undefined;
|
|
@@ -312,13 +316,13 @@ export const taggingGets = {
|
|
|
? (aiIconMap as any)[shape.category]
|
|
|
: shape.category;
|
|
|
let name = "";
|
|
|
- let isWall = false
|
|
|
+ let isWall = false;
|
|
|
for (const group of iconGroups) {
|
|
|
for (const itemGroup of group.children) {
|
|
|
for (const item of itemGroup.children) {
|
|
|
if (item.icon === icon) {
|
|
|
name = item.name;
|
|
|
- isWall = 'wall' in item && item.wall
|
|
|
+ isWall = "wall" in item && item.wall;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -328,6 +332,7 @@ export const taggingGets = {
|
|
|
const item = {
|
|
|
isText: isTag,
|
|
|
position: pos,
|
|
|
+ rotate: 0,
|
|
|
url: isTag
|
|
|
? shape.name
|
|
|
: `./icons/${icon ? icon : "circle"}.svg`,
|
|
@@ -335,11 +340,22 @@ export const taggingGets = {
|
|
|
pixel: true,
|
|
|
size,
|
|
|
subgroup,
|
|
|
- }
|
|
|
+ };
|
|
|
if (isWall) {
|
|
|
- const wh = Math.max(item.size.width, item.size.height)
|
|
|
- item.size.width = wh
|
|
|
- item.size.height = wh
|
|
|
+ const wh = Math.max(item.size.width, item.size.height);
|
|
|
+ if (wh === item.size.width) {
|
|
|
+ item.position.y -= wh / 2;
|
|
|
+ } else {
|
|
|
+ item.rotate = Math.PI / 2;
|
|
|
+ loadPromises.push(
|
|
|
+ getSvgContent(item.url).then((svgContent) => {
|
|
|
+ const content = parseSvgContent(svgContent);
|
|
|
+ item.position.x += (content.height / content.width * wh) / 2;
|
|
|
+ }).catch(() => {})
|
|
|
+ );
|
|
|
+ }
|
|
|
+ item.size.width = wh;
|
|
|
+ item.size.height = wh;
|
|
|
}
|
|
|
tags.push(item as any);
|
|
|
} else {
|
|
@@ -347,6 +363,7 @@ export const taggingGets = {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ return Promise.all(loadPromises)
|
|
|
})
|
|
|
.catch((e) => {
|
|
|
console.error(e);
|