feat(all): 迁移扩展相关功能
This commit is contained in:
@@ -4,6 +4,7 @@ import App from "@/core/app/App";
|
||||
export * from "./material";
|
||||
export * from "./Stats";
|
||||
export * from "./controls";
|
||||
export * from "./uipanel";
|
||||
|
||||
/**
|
||||
* 获取对象到父对象的路径(结果不包含parentObject)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user