import{r as e}from"./rolldown-runtime-DCMCV6zW.js";import{Ot as t,f as n,r}from"./api-3C7_IVZO.js";import{o as i}from"./i18n-DjEVEIh2.js";import{r as a}from"./dialogService-BC0EXJA5.js";import{r as o}from"./load3dService-FyKs_L4c.js";var s=[{label:`GLB`,value:`glb`},{label:`OBJ`,value:`obj`},{label:`STL`,value:`stl`}];function createExportMenuItems(e){return[null,{content:`Save`,has_submenu:!0,callback:(r,a,o,c)=>{let l=s.map(n=>({content:n.label,callback:()=>{(async()=>{try{await e.exportModel(n.value),t().add({severity:`success`,summary:i(`toastMessages.exportSuccess`,{format:n.label})})}catch(e){console.error(`Export failed:`,e),t().addAlert(i(`toastMessages.failedToExportModel`,{format:n.label}))}})()}}));new n.ContextMenu(l,{event:o,parentMenu:c})}}]}window.comfyAPI=window.comfyAPI||{},window.comfyAPI.exportMenuHelper=window.comfyAPI.exportMenuHelper||{},window.comfyAPI.exportMenuHelper.createExportMenuItems=createExportMenuItems;var Load3DConfiguration=class{constructor(e,t){this.load3d=e,this.properties=t}configureForSaveMesh(e,t){this.setupModelHandlingForSaveMesh(t,e),this.setupDefaultProperties()}configure(e){this.setupModelHandling(e.modelWidget,e.loadFolder,e.cameraState),this.setupTargetSize(e.width,e.height),this.setupDefaultProperties(e.bgImagePath)}setupTargetSize(e,t){e&&t&&(this.load3d.setTargetSize(e.value,t.value),e.callback=e=>{this.load3d.setTargetSize(e,t.value)},t.callback=t=>{this.load3d.setTargetSize(e.value,t)})}setupModelHandlingForSaveMesh(e,t){let n=this.createModelUpdateHandler(t);e&&n(e)}setupModelHandling(e,t,n){let r=this.createModelUpdateHandler(t,n);e.value&&r(e.value);let i=e.callback,a=e.value;Object.defineProperty(e,`value`,{get(){return a},set(t){a=t,e.callback&&t!==void 0&&t!==``&&e.callback(t)},enumerable:!0,configurable:!0}),e.callback=e=>{r(e),i&&i(e)}}setupDefaultProperties(e){let t=this.loadSceneConfig();this.applySceneConfig(t,e);let n=this.loadCameraConfig();this.applyCameraConfig(n);let r=this.loadLightConfig();this.applyLightConfig(r)}loadSceneConfig(){return this.properties&&`Scene Config`in this.properties?this.properties[`Scene Config`]:{showGrid:a().get(`Comfy.Load3D.ShowGrid`),backgroundColor:`#`+a().get(`Comfy.Load3D.BackgroundColor`),backgroundImage:``}}loadCameraConfig(){return this.properties&&`Camera Config`in this.properties?this.properties[`Camera Config`]:{cameraType:a().get(`Comfy.Load3D.CameraType`),fov:35}}loadLightConfig(){return this.properties&&`Light Config`in this.properties?this.properties[`Light Config`]:{intensity:a().get(`Comfy.Load3D.LightIntensity`)}}loadModelConfig(){return this.properties&&`Model Config`in this.properties?this.properties[`Model Config`]:{upDirection:`original`,materialMode:`original`,showSkeleton:!1}}applySceneConfig(e,t){if(this.load3d.toggleGrid(e.showGrid),this.load3d.setBackgroundColor(e.backgroundColor),e.backgroundImage){if(t&&t!=e.backgroundImage)return;this.load3d.setBackgroundImage(e.backgroundImage),e.backgroundRenderMode&&this.load3d.setBackgroundRenderMode(e.backgroundRenderMode)}}applyCameraConfig(e){this.load3d.toggleCamera(e.cameraType),this.load3d.setFOV(e.fov),e.state&&this.load3d.setCameraState(e.state)}applyLightConfig(e){this.load3d.setLightIntensity(e.intensity)}applyModelConfig(e){this.load3d.setUpDirection(e.upDirection),this.load3d.setMaterialMode(e.materialMode)}createModelUpdateHandler(e,t){let n=!0;return async i=>{if(!i)return;let a=i;this.setResourceFolder(a);let s=r.apiURL(o.getResourceURL(...o.splitFilePath(a),e));await this.load3d.loadModel(s,a);let c=this.loadModelConfig();if(this.applyModelConfig(c),n&&t){try{this.load3d.setCameraState(t)}catch(e){console.warn(`Failed to restore camera state:`,e)}n=!1}}}setResourceFolder(e){let t=e.split(`/`).filter(e=>e.trim());if(t.length<=2)return;let n=t.slice(1,-1).join(`/`);n&&this.properties&&(this.properties[`Resource Folder`]=n)}},c=Load3DConfiguration;export{createExportMenuItems as n,c as t};
//# sourceMappingURL=Load3DConfiguration-EwGSMUPs.js.map