import"./rolldown-runtime-DIIn1E2Q.js";import{Yt as e,r as t,y as n}from"./api-Cw7jP9TY.js";import{o as r}from"./i18n-CF_88JEG.js";import{i}from"./dialogService-CfgsFapJ.js";import{r as a}from"./load3dService-CDqzlPgU.js";var o=[{label:`GLB`,value:`glb`},{label:`OBJ`,value:`obj`},{label:`STL`,value:`stl`}];function createExportMenuItems(t){return[null,{content:`Save`,has_submenu:!0,callback:(i,a,s,c)=>{let l=o.map(n=>({content:n.label,callback:()=>{(async()=>{try{await t.exportModel(n.value),e().add({severity:`success`,summary:r(`toastMessages.exportSuccess`,{format:n.label})})}catch(t){console.error(`Export failed:`,t),e().addAlert(r(`toastMessages.failedToExportModel`,{format:n.label}))}})()}}));new n.ContextMenu(l,{event:s,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:i().get(`Comfy.Load3D.ShowGrid`),backgroundColor:`#`+i().get(`Comfy.Load3D.BackgroundColor`),backgroundImage:``}}loadCameraConfig(){return this.properties&&`Camera Config`in this.properties?this.properties[`Camera Config`]:{cameraType:i().get(`Comfy.Load3D.CameraType`),fov:35}}loadLightConfig(){return this.properties&&`Light Config`in this.properties?this.properties[`Light Config`]:{intensity:i().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,n){let r=!0;return async i=>{if(!i)return;let o=i;this.setResourceFolder(o);let s=t.apiURL(a.getResourceURL(...a.splitFilePath(o),e));await this.load3d.loadModel(s,o);let c=this.loadModelConfig();if(this.applyModelConfig(c),r&&n){try{this.load3d.setCameraState(n)}catch(e){console.warn(`Failed to restore camera state:`,e)}r=!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)}};export{createExportMenuItems as n,Load3DConfiguration as t};
//# sourceMappingURL=Load3DConfiguration-BOVSiJ3-.js.map