39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import type { Object3D } from "three";
|
|
|
|
export const UIPANEL_TYPES = new Set(["UIPanel", "UIPanelBlock", "UIPanelText", "UIPanelInline", "UIPanelInlineBlock"]);
|
|
|
|
/**
|
|
* 判断是否是UIPanel 3D对象
|
|
*/
|
|
export function isUIPanelObject(object:Object3D | null){
|
|
return object && object.type === "UIPanel" && object.options;
|
|
}
|
|
|
|
export function isUIPanelRelatedObject(object: Object3D | null) {
|
|
if (!object) return false;
|
|
if (UIPANEL_TYPES.has(object.type)) return true;
|
|
// return Boolean(findUIPanelNodeId(object));
|
|
|
|
if (object.metadata?.__uiPanelRootId || object.metadata?.__uiPanelNodeId) return true;
|
|
return false;
|
|
}
|
|
|
|
export function findUIPanelRoot(object: Object3D | null) {
|
|
let current: Object3D | null = object;
|
|
while (current) {
|
|
if (isUIPanelObject(current)) return current;
|
|
current = current.parent;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function findUIPanelNodeId(object: Object3D | null) {
|
|
let current: any = object;
|
|
while (current) {
|
|
const nodeId = current.metadata?.__uiPanelNodeId;
|
|
if (nodeId) return nodeId as string;
|
|
current = current.parent;
|
|
}
|
|
return null;
|
|
}
|