支持模型库向主程序导入模型
This commit is contained in:
@@ -64,6 +64,14 @@ export type PreviewImportScenePayload = {
|
|||||||
selectedCraftPlayData: P_OPERATION | null;
|
selectedCraftPlayData: P_OPERATION | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type ParentImportScenePayload = {
|
||||||
|
model: Pick<ModelItem, "id" | "name" | "original_filename" | "file_url">;
|
||||||
|
modelUrl: string;
|
||||||
|
basePointEnabled: boolean;
|
||||||
|
basePoint: PreviewResolvedBasePoint;
|
||||||
|
rawOperationTree: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type ModelPreviewOptions = {
|
export type ModelPreviewOptions = {
|
||||||
onImportScene?: (payload: PreviewImportScenePayload) => Promise<void> | void;
|
onImportScene?: (payload: PreviewImportScenePayload) => Promise<void> | void;
|
||||||
};
|
};
|
||||||
@@ -214,6 +222,43 @@ export function createImportScenePayload(options: {
|
|||||||
|
|
||||||
export function emitImportScenePayload(payload: PreviewImportScenePayload) {
|
export function emitImportScenePayload(payload: PreviewImportScenePayload) {
|
||||||
window.dispatchEvent(new CustomEvent<PreviewImportScenePayload>("dmt:import-scene", { detail: payload }));
|
window.dispatchEvent(new CustomEvent<PreviewImportScenePayload>("dmt:import-scene", { detail: payload }));
|
||||||
|
if (window.parent && window.parent !== window) {
|
||||||
|
try {
|
||||||
|
window.parent.postMessage({
|
||||||
|
type: "DMT_MODEL_LIBRARY_IMPORT_SCENE",
|
||||||
|
payload: buildParentImportScenePayload(payload)
|
||||||
|
}, resolveParentOrigin());
|
||||||
|
} catch (error) {
|
||||||
|
notifyError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildParentImportScenePayload(payload: PreviewImportScenePayload): ParentImportScenePayload {
|
||||||
|
return {
|
||||||
|
model: {
|
||||||
|
id: payload.model.id,
|
||||||
|
name: payload.model.name,
|
||||||
|
original_filename: payload.model.original_filename,
|
||||||
|
file_url: payload.model.file_url
|
||||||
|
},
|
||||||
|
modelUrl: payload.modelUrl,
|
||||||
|
basePointEnabled: payload.basePointEnabled,
|
||||||
|
basePoint: payload.basePoint,
|
||||||
|
rawOperationTree: payload.rawOperationTree
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveParentOrigin() {
|
||||||
|
try {
|
||||||
|
const meta = import.meta as ImportMeta & { env?: Record<string, string | undefined> };
|
||||||
|
const configuredOrigin = meta.env?.VITE_DMT_PARENT_ORIGIN;
|
||||||
|
if (configuredOrigin) return configuredOrigin;
|
||||||
|
if (document.referrer) return new URL(document.referrer).origin;
|
||||||
|
} catch {
|
||||||
|
return "*";
|
||||||
|
}
|
||||||
|
return "*";
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseModelOperations(value: string): PreviewOperation[] {
|
function parseModelOperations(value: string): PreviewOperation[] {
|
||||||
|
|||||||
Reference in New Issue
Block a user