@tomorrowevening/hermes 0.0.114 → 0.0.115
Sign up to get free protection for your applications and to get access to all the features.
package/dist/hermes.cjs.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("three"),S=require("react"),is=require("framer-motion"),ui=()=>{},Bs=()=>{};function dt(s){return s.substring(0,1).toUpperCase()+s.substring(1)}function ss(s){const e=JSON.stringify(s);return navigator.clipboard.writeText(e),e}function Te(s,e,t){return Math.min(e,Math.max(s,t))}function si(s,e,t){return(t-s)/(e-s)}function Pt(s,e,t){return s*(1-t)+e*t}function Ys(s,e){const t=s-e;return Math.sqrt(t*t)}function ns(){return Math.round(Math.random()*1e6).toString()}function as(s){return s.r!==void 0&&s.g!==void 0&&s.b!==void 0}function ni(s){const e=Math.round(s.r*255),t=Math.round(s.g*255),i=Math.round(s.b*255),n=h=>{const c=h.toString(16);return c.length===1?"0"+c:c},o=n(e),a=n(t),l=n(i);return"#"+o+a+l}function me(s,e=1){return Number(s.toFixed(e))}exports.totalThreeObjects=0;const ai=()=>{exports.totalThreeObjects=0},Dt=s=>{if(!s)return;let e=s.name.replaceAll(" ","").replaceAll("/",".");if(e.length===0&&(e=`obj_${exports.totalThreeObjects}`,exports.totalThreeObjects++),s.parent!==null&&s.parent.uuid.length>0&&(e=`${s.parent.uuid}.${e}`),s.uuid=e,s.isMesh!==void 0){const t=s;if(Array.isArray(t.material))t.material.forEach((i,n)=>{i.uuid=`${e}.material.${n}`});else{const i=t.material;i.uuid=`${e}.material`}}s.children.forEach(t=>Dt(t))},Gs=s=>{s?.dispose()},rs=s=>{s&&(Array.isArray(s)?s.forEach(e=>e.dispose()):s.dispose())},be=s=>{if(s){for(;s.children.length>0;){const e=s.children[0];e.type==="Audio"?(e.pause(),e.parent&&e.parent.remove(e)):be(e)}if(s.parent&&s.parent.remove(s),s.isMesh){const e=s;e.geometry?.dispose(),rs(e.material)}s.dispose!==void 0&&s.dispose()}};class ht{static renderer;static canvas;static context=null;static scene=null;static camera=null;static material=null;static inited=!1;static width=100;static height=100;static init(){this.inited||(this.canvas=document.createElement("canvas"),this.canvas.width=this.width,this.canvas.height=this.height,this.context=this.canvas.getContext("2d"),this.inited=!0)}static renderToBlob(e){this.init();const t=e.repeat.clone(),i=e.offset.clone();if(e.repeat.set(1,1),e.offset.set(0,0),this.context!==null){this.context.clearRect(0,0,this.width,this.height);const n=e.image;if(n!=null&&n.width>0){this.canvas.title=e.sourceFile;const o=this.canvas.width/n.width,a=this.renderToCanvas(e);this.context.drawImage(a,0,0,n.width*o,n.height*o)}}return e.repeat.copy(t),e.offset.copy(i),this.canvas.toDataURL("image/png")}static renderToCanvas(e){if(this.material===null){this.camera=new r.OrthographicCamera(-.5,.5,.5,-.5,0,100),this.scene=new r.Scene,this.material=new r.MeshBasicMaterial;const t=new r.BufferGeometry;t.setAttribute("position",new r.Float32BufferAttribute([-.5,-.5,0,1.5,-.5,0,-.5,1.5,0],3)),t.setAttribute("normal",new r.Float32BufferAttribute([0,0,1,0,0,1],3)),t.setAttribute("uv",new r.Float32BufferAttribute([0,0,2,0,0,2],2));const i=new r.Mesh(t,this.material);this.scene.add(i)}if(e.isRenderTargetTexture)this.material.map=e,this.renderer.render(this.scene,this.camera);else{const t=this.renderer.outputColorSpace,i=e.colorSpace;this.renderer.outputColorSpace=r.LinearSRGBColorSpace,e.colorSpace=r.LinearSRGBColorSpace,this.material.map=e,this.renderer.render(this.scene,this.camera),this.renderer.outputColorSpace=t,e.colorSpace=i}return this.renderer.domElement}}class Zs{components=new Map;listen;_appID="";_debugEnabled;_broadcastChannel=void 0;_webSocket=void 0;_mode="app";_connected=!1;_useBC=!1;constructor(e,t,i=!0){this._appID=e,this._debugEnabled=t,t&&(this._useBC=i,i?(this._broadcastChannel=new BroadcastChannel(e),this._broadcastChannel.addEventListener("message",this.messageHandler)):(this._webSocket=new WebSocket(e),this._webSocket.addEventListener("open",this.openHandler),this._webSocket.addEventListener("close",this.closeHandler),this._webSocket.addEventListener("message",this.messageHandler)))}addComponent(e,t){this.components.set(e,t)}dispose(){this._broadcastChannel!==void 0&&this._broadcastChannel.removeEventListener("message",this.messageHandler),this._webSocket!==void 0&&(this._webSocket.removeEventListener("open",this.openHandler),this._webSocket.removeEventListener("close",this.closeHandler),this._webSocket.removeEventListener("message",this.messageHandler)),this.components.forEach(e=>{e.dispose()}),this.components.clear()}send(e){this._mode!==e.target&&(this._useBC?this._broadcastChannel?.postMessage(e):this._connected&&this._webSocket?.send(JSON.stringify(e)))}messageHandler=e=>{this.listen!==void 0&&(this._useBC?this.listen(e.data):this.listen(JSON.parse(e.data)))};openHandler=()=>{this._connected=!0};closeHandler=()=>{this._connected=!1};get appID(){return this._appID}get connected(){return this._connected}get debugEnabled(){return this._debugEnabled}get mode(){return this._mode}get isApp(){return this._mode==="app"}get editor(){return this._mode==="editor"}set editor(e){e&&(this._mode="editor")}}var A=(s=>(s.CUSTOM="ToolEvents::custom",s.SELECT_DROPDOWN="ToolEvents::selectDropdown",s.DRAG_UPDATE="ToolEvents::dragUpdate",s.ADD_SCENE="ToolEvents::addScene",s.REFRESH_SCENE="ToolEvents::refreshScene",s.REMOVE_SCENE="ToolEvents::removeScene",s.SET_SCENE="ToolEvents::setScene",s.GET_OBJECT="ToolEvents::getObject",s.SET_OBJECT="ToolEvents::setObject",s.UPDATE_OBJECT="ToolEvents::updateObject",s.CREATE_TEXTURE="ToolEvents::createTexture",s.REQUEST_METHOD="ToolEvents::requestMethod",s.ADD_CAMERA="ToolEvents::addCamera",s.REMOVE_CAMERA="ToolEvents::removeCamera",s.ADD_GROUP="ToolEvents::addGroup",s.REMOVE_GROUP="ToolEvents::removeGroup",s.ADD_SPLINE="ToolEvents::addSpline",s.ADD_RENDERER="ToolEvents::addRenderer",s.UPDATE_RENDERER="ToolEvents::updateRenderer",s))(A||{});const R=new r.EventDispatcher;class Lt{app;constructor(e){this.app=e}dispose(){}handleApp(e,t,i){}handleEditor(e,t,i){}}class Ws extends Lt{selectDropdown(e,t){this.app.send({event:"selectComponent",target:"app",data:{dropdown:e,value:t}})}updateDropdown(e,t){this.app.send({event:"draggableListUpdate",target:"app",data:{dropdown:e,value:t}})}handleApp(e,t,i){switch(i.event){case"selectComponent":R.dispatchEvent({type:A.SELECT_DROPDOWN,value:i.data});break;case"draggableListUpdate":R.dispatchEvent({type:A.DRAG_UPDATE,value:i.data});break}}}function Xs(s,e,t){if(s.editor){t.ui.restore(),t.onSelectionChange(a=>{a.length<1||a.forEach(l=>{let h=l.address.sheetId,c="setSheet",p={};switch(l.type){case"Theatre_Sheet_PublicAPI":c="setSheet",p={sheet:l.address.sheetId},e.activeSheet=e.sheets.get(l.address.sheetId);break;case"Theatre_SheetObject_PublicAPI":c="setSheetObject",h+=`_${l.address.objectKey}`,p={id:h,sheet:l.address.sheetId,key:l.address.objectKey},e.activeSheet=e.sheets.get(l.address.sheetId);break}s.send({event:c,target:"app",data:p})})});let i=-1;const n=()=>{if(e.activeSheet!==void 0&&i!==e.activeSheet.sequence.position){i=e.activeSheet.sequence.position;const a=e.activeSheet;s.send({event:"updateTimeline",target:"app",data:{position:i,sheet:a.address.sheetId}})}},o=()=>{n(),requestAnimationFrame(o)};n(),o()}else t.ui.hide()}function Qs(){setTimeout(()=>{const s=document.getElementById("theatrejs-studio-root");if(s===null||s.shadowRoot===null)return;const e=s.shadowRoot.getElementById("pointer-root");if(e===null)return;const t=e.children[0];if(t===null)return;const i=t.children[1];i.style.justifyContent="left";try{const n=i.children[1];for(n.style.transform="translateX(10px)";n.children.length>1;)n.removeChild(n.children[0])}catch{}try{const n=t.children[3];n.style.top="0",n.style.right="300px"}catch{}},1e3)}class qs extends Lt{project;sheets=new Map;sheetObjects=new Map;sheetObjectCBs=new Map;sheetObjectUnsubscribe=new Map;activeSheet;studio=void 0;dispose(){this.project=void 0,this.sheets=new Map,this.sheetObjects=new Map,this.sheetObjectCBs=new Map,this.sheetObjectUnsubscribe=new Map}getSheetInstance(e,t){return t!==void 0?`${e}-${t}`:e}sheet(e,t){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const i=this.getSheetInstance(e,t);let n=this.sheets.get(i);return n!==void 0||(n=this.project?.sheet(e,t),this.sheets.set(i,n)),n}playSheet(e,t,i){return new Promise(n=>{const o=t!==void 0?{...t}:{};this.sheet(e,i)?.sequence.play(o).then(a=>n(a)),this.app.send({event:"playSheet",target:"editor",data:{sheet:e,instance:i,value:t}})})}pauseSheet(e,t){this.sheet(e,t)?.sequence.pause(),this.app.send({event:"pauseSheet",target:"editor",data:{sheet:e,instance:t}})}clearSheetObjects(e){this.sheetObjects.forEach((t,i)=>{i.search(`${e}_`)>-1&&this.unsubscribe(t)})}sheetObject(e,t,i,n,o){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const a=this.sheet(e,o);if(a===void 0)return;const h=`${this.getSheetInstance(e,o)}_${t}`;let c=this.sheetObjects.get(h);c!==void 0?c=a.object(t,{...i,...c.value},{reconfigure:!0}):c=a.object(t,i),this.sheetObjects.set(h,c),this.sheetObjectCBs.set(h,n!==void 0?n:ui);const p=c.onValuesChange(m=>{if(this.app.editor){for(const y in m){const x=m[y];typeof x=="object"&&as(x)&&(m[y]={r:x.r,g:x.g,b:x.b,a:x.a})}this.app.send({event:"updateSheetObject",target:"app",data:{sheet:e,sheetObject:h,values:m}})}const f=this.sheetObjectCBs.get(h);f!==void 0&&f(m)});return this.sheetObjectUnsubscribe.set(h,p),c}unsubscribe(e){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const t=e.address.sheetId,i=e.address.objectKey;this.sheets.get(t)?.detachObject(i);const o=`${t}_${i}`,a=this.sheetObjectUnsubscribe.get(o);a!==void 0&&(this.sheetObjects.delete(o),this.sheetObjectCBs.delete(o),this.sheetObjectUnsubscribe.delete(o),a())}handleApp(e,t,i){const n=t;let o;switch(i.event){case"setSheet":o=n.sheets.get(i.data.sheet),o!==void 0&&(n.activeSheet=o,this.studio?.setSelection([o]));break;case"setSheetObject":o=n.sheetObjects.get(`${i.data.sheet}_${i.data.key}`),o!==void 0&&this.studio?.setSelection([o]);break;case"updateSheetObject":o=n.sheets.get(i.data.sheet),o!==void 0&&o.sequence.pause(),o=n.sheetObjectCBs.get(i.data.sheetObject),o!==void 0&&o(i.data.values);break;case"updateTimeline":o=n.sheets.get(i.data.sheet),n.activeSheet!==void 0&&(n.activeSheet.sequence.position=i.data.position);break}}handleEditor(e,t,i){if(e.editor){const n=t;switch(i.event){case"playSheet":n.sheet(i.data.sheet,i.data.instance)?.sequence.play(i.data.value);break;case"pauseSheet":n.sheet(i.data.sheet,i.data.instance)?.sequence.pause();break}}}handleEditorApp(e,t){if(e.editor){this.studio?.ui.restore(),this.studio?.onSelectionChange(a=>{a.length<1||a.forEach(l=>{let h=l.address.sheetId,c="setSheet",p={};switch(l.type){case"Theatre_Sheet_PublicAPI":c="setSheet",p={sheet:l.address.sheetId},t.activeSheet=t.sheets.get(l.address.sheetId);break;case"Theatre_SheetObject_PublicAPI":c="setSheetObject",h+=`_${l.address.objectKey}`,p={id:h,sheet:l.address.sheetId,key:l.address.objectKey},t.activeSheet=t.sheets.get(l.address.sheetId);break}e.send({event:c,target:"app",data:p})})});let i=-1;const n=()=>{if(t.activeSheet!==void 0&&i!==t.activeSheet.sequence.position){i=t.activeSheet.sequence.position;const a=t.activeSheet;e.send({event:"updateTimeline",target:"app",data:{position:i,sheet:a.address.sheetId}})}},o=()=>{n(),requestAnimationFrame(o)};n(),o()}else this.studio?.ui.hide()}}function Ks(s){if(s.name==="cameras")return"camera";if(s.name==="interactive")return"interactive";if(s.name==="lights")return"light";if(s.name==="ui")return"ui";if(s.name==="utils")return"utils";const e=s.type;return e.search("Helper")>-1?"icon_utils":e.search("Camera")>-1?"camera":e.search("Light")>-1?"light":"obj3D"}function Xe(s){const e={name:s.name,type:s.type,uuid:s.uuid,children:[]};return s.children.forEach(t=>{e.children.push(Xe(t))}),e}function $s(s){const e={};for(const t in s){const i=s[t].value;e[t]={value:i},i===null?e[t].value={src:"",offset:[0,0],repeat:[1,1]}:i!==void 0&&i.isTexture&&(e[t].value={src:i.image.src,offset:[i.offset.x,i.offset.y],repeat:[i.repeat.x,i.repeat.y]})}return e}function Js(s){switch(s){case"blendSrcAlpha":case"blendDstAlpha":case"blendEquationAlpha":case"clippingPlanes":case"shadowSide":case"precision":return!0}return!1}function He(s){const e={};for(const t in s){if(t.substring(0,1)==="_"||t.substring(0,2)==="is"||Js(t))continue;const i=typeof s[t],n=s[t];switch(i){case"boolean":case"number":case"string":e[t]=n;break;case"object":n!==null?(e[t]=n,n.isTexture?e[t]={src:ht.renderToBlob(n),offset:[n.offset.x,n.offset.y],repeat:[n.repeat.x,n.repeat.y]}:t==="uniforms"&&(e[t]=$s(e[t]))):t==="glslVersion"?e[t]="":e[t]={src:"",offset:[0,0],repeat:[1,1]};break}}return s.anisotropy!==void 0&&(e.anisotropy=s.anisotropy),s.clearcoat!==void 0&&(e.clearcoat=s.clearcoat),s.iridescence!==void 0&&(e.iridescence=s.iridescence),s.dispersion!==void 0&&(e.dispersion=s.dispersion),s.sheen!==void 0&&(e.sheen=s.sheen),s.transmission!==void 0&&(e.transmission=s.transmission),s.transmission!==void 0&&(e.transmission=s.transmission),e}function Gt(s){s.updateMatrix();const e={name:s.name,type:s.type,uuid:s.uuid,visible:s.visible,matrix:s.matrix.elements,animations:[],material:void 0,perspectiveCameraInfo:void 0,orthographicCameraInfo:void 0,lightInfo:void 0,children:[]};s.animations.forEach(i=>{e.animations.push({name:i.name,duration:i.duration,blendMode:i.blendMode})});const t=s.type.toLowerCase();if(t.search("mesh")>-1){const i=s;if(Array.isArray(i.material)){const n=[];i.material.forEach(o=>{n.push(He(o))}),e.material=n}else e.material=He(i.material)}else if(t.search("points")>-1){const i=s;if(Array.isArray(i.material)){const n=[];i.material.forEach(o=>{n.push(He(o))}),e.material=n}else e.material=He(i.material)}else if(t.search("line")>-1){const i=s;if(Array.isArray(i.material)){const n=[];i.material.forEach(o=>{n.push(He(o))}),e.material=n}else e.material=He(i.material)}else t.search("camera")>-1?s.type==="PerspectiveCamera"?e.perspectiveCameraInfo={fov:s.fov,zoom:s.zoom,near:s.near,far:s.far,focus:s.focus,aspect:s.aspect,filmGauge:s.filmGauge,filmOffset:s.filmOffset}:s.type==="OrthographicCamera"&&(e.orthographicCameraInfo={zoom:s.zoom,near:s.near,far:s.far,left:s.left,right:s.right,top:s.top,bottom:s.bottom}):t.search("light")>-1&&(e.lightInfo={color:s.color,intensity:s.intensity,decay:s.decay,distance:s.distance,angle:s.angle,penumbra:s.penumbra,groundColor:s.groundColor,width:s.width,height:s.height});return e}function en(s,e){const t=e.split(".");switch(t.length){case 1:return s[t[0]];case 2:return s[t[0]][t[1]];case 3:return s[t[0]][t[1]][t[2]];case 4:return s[t[0]][t[1]][t[2]][t[3]];case 5:return s[t[0]][t[1]][t[2]][t[3]][t[4]];case 6:return s[t[0]][t[1]][t[2]][t[3]][t[4]][t[5]]}}function tn(s,e){for(const t in e)s[t]=e[t]}function q(s,e,t){if(s===void 0)return;const i=e.split("."),n=i.length;if(typeof t!="object")switch(n){case 1:s[i[0]]=t;break;case 2:s[i[0]][i[1]]=t;break;case 3:s[i[0]][i[1]][i[2]]=t;break;case 4:s[i[0]][i[1]][i[2]][i[3]]=t;break;case 5:s[i[0]][i[1]][i[2]][i[3]][i[4]]=t;break}else{let a;switch(n){case 1:a=s[i[0]];break;case 2:a=s[i[0]][i[1]];break;case 3:a=s[i[0]][i[1]][i[2]];break;case 4:a=s[i[0]][i[1]][i[2]][i[3]];break;case 5:a=s[i[0]][i[1]][i[2]][i[3]][i[4]];break}a!=null&&tn(a,t)}}function os(s){return new Promise((e,t)=>{const i=new Image;i.onload=()=>{const n=new r.Texture(i);n.wrapS=r.RepeatWrapping,n.wrapT=r.RepeatWrapping,n.needsUpdate=!0,e(n)},i.onerror=t,i.src=s})}class sn extends Lt{scene=void 0;scenes=new Map;renderer=void 0;renderTargets=new Map;groups=new Map;dispose(){this.scenes.forEach(e=>{be(e)}),this.scenes.clear(),this.scene&&be(this.scene),this.renderTargets.forEach(e=>{e.dispose()}),this.renderTargets.clear(),this.renderer?.dispose()}getObject(e){this.app.debugEnabled&&(this.renderer!==void 0&&(ht.renderer=this.renderer),this.app.send({event:"getObject",target:"app",data:e}))}setObject(e){this.renderer!==void 0&&(ht.renderer=this.renderer);const t=Gt(e);this.app.send({event:"setObject",target:"editor",data:t})}requestMethod(e,t,i,n){this.app.send({event:"requestMethod",target:"app",data:{uuid:e,key:t,value:i,subitem:n}})}updateObject(e,t,i){this.app.send({event:"updateObject",target:"app",data:{uuid:e,key:t,value:i}})}createTexture(e,t,i){this.app.send({event:"createTexture",target:"app",data:{uuid:e,key:t,value:i}})}addGroup(e){this.groups.get(e.title)===void 0&&(this.groups.set(e.title,{title:e.title,onUpdate:e.onUpdate}),this.app.send({event:"addGroup",target:"editor",data:JSON.stringify(e)}))}removeGroup(e){this.groups.get(e)!==void 0&&(this.groups.delete(e),this.app.send({event:"removeGroup",target:"editor",data:e}))}updateGroup(e,t,i){this.app.send({event:"updateGroup",target:"app",data:JSON.stringify({group:e,prop:t,value:i})})}removeAllGroups(){this.groups.forEach(e=>{const t=e.title;this.groups.delete(t),this.app.send({event:"removeGroup",target:"editor",data:t})}),this.groups.clear()}addSpline(e){setTimeout(()=>{this.app.send({event:"addSpline",target:"editor",data:JSON.stringify(e.toJSON())})},1)}addRenderer(e){if(this.renderer=e,!this.app.debugEnabled)return;const t=`#${e.getClearColor(new r.Color).getHexString()}`;this.app.send({event:"addRenderer",target:"editor",data:{autoClear:e.autoClear,autoClearColor:e.autoClearColor,autoClearDepth:e.autoClearDepth,autoClearStencil:e.autoClearStencil,outputColorSpace:e.outputColorSpace,localClippingEnabled:e.localClippingEnabled,clearColor:t,clearAlpha:e.getClearAlpha(),colorManagement:r.ColorManagement.enabled,toneMapping:e.toneMapping,toneMappingExposure:e.toneMappingExposure}})}updateRenderer(e){this.app.send({event:"updateRenderer",target:"app",data:e})}addScene(e){if(e===void 0||(this.scenes.set(e.name,e),!this.app.debugEnabled))return;ai(),Dt(e);const t=Xe(e);this.app.send({event:"addScene",target:"editor",data:t})}refreshScene(e){if(!this.app.debugEnabled)return;const t=this.scenes.get(e);if(t!==void 0){const i=Xe(t);this.app.send({event:"refreshScene",target:"app",data:i})}}removeScene(e){if(e===void 0||(this.scenes.delete(e.name),!this.app.debugEnabled))return;const t=Xe(e);this.app.send({event:"removeScene",target:"editor",data:t})}removeAllScenes(){this.scenes.forEach(e=>this.removeScene(e))}getScene(e){let t=null;return this.scenes.forEach((i,n)=>{e.search(n)>-1&&(t=i)}),t}setScene(e){if(e===void 0||(this.scene=e,!this.app.debugEnabled))return;this.renderer!==void 0&&(ht.renderer=this.renderer),ai(),Dt(e);const t=Xe(e);this.app.send({event:"setScene",target:"editor",data:t})}addCamera(e){if(!this.app.debugEnabled)return;const t=Gt(e);this.app.send({event:"addCamera",target:"editor",data:t})}removeCamera(e){if(!this.app.debugEnabled)return;const t=Gt(e);this.app.send({event:"removeCamera",target:"editor",data:t})}handleApp(e,t,i){const n=t;switch(i.event){case"getObject":R.dispatchEvent({type:A.GET_OBJECT,value:i.data});break;case"updateObject":R.dispatchEvent({type:A.UPDATE_OBJECT,value:i.data});break;case"createTexture":R.dispatchEvent({type:A.CREATE_TEXTURE,value:i.data});break;case"requestMethod":R.dispatchEvent({type:A.REQUEST_METHOD,value:i.data});break;case"refreshScene":e.send({event:"refreshScene",target:"editor",data:Xe(n.scenes.get(i.data.name))});break;case"updateRenderer":n.renderer&&(n.renderer.autoClear=i.data.autoClear,n.renderer.autoClearColor=i.data.autoClearColor,n.renderer.autoClearDepth=i.data.autoClearDepth,n.renderer.autoClearStencil=i.data.autoClearStencil,n.renderer.outputColorSpace=i.data.outputColorSpace,n.renderer.localClippingEnabled=i.data.localClippingEnabled,n.renderer.setClearColor(i.data.clearColor,i.data.clearAlpha),n.renderer.toneMapping=i.data.toneMapping,n.renderer.toneMappingExposure=i.data.toneMappingExposure,r.ColorManagement.enabled=i.data.colorManagement);break}if(i.event==="updateGroup"){const o=JSON.parse(i.data);n.groups.get(o.group)?.onUpdate(o.prop,o.value)}}handleEditor(e,t,i){switch(i.event){case"setObject":R.dispatchEvent({type:A.SET_OBJECT,value:i.data});break;case"addScene":R.dispatchEvent({type:A.ADD_SCENE,value:i.data});break;case"refreshScene":R.dispatchEvent({type:A.REFRESH_SCENE,value:i.data});break;case"removeScene":R.dispatchEvent({type:A.REMOVE_SCENE,value:i.data});break;case"setScene":R.dispatchEvent({type:A.SET_SCENE,value:i.data});break;case"addCamera":R.dispatchEvent({type:A.ADD_CAMERA,value:i.data});break;case"removeCamera":R.dispatchEvent({type:A.REMOVE_CAMERA,value:i.data});break;case"addGroup":R.dispatchEvent({type:A.ADD_GROUP,value:i.data});break;case"removeGroup":R.dispatchEvent({type:A.REMOVE_GROUP,value:i.data});break;case"addSpline":R.dispatchEvent({type:A.ADD_SPLINE,value:i.data});break;case"addRenderer":R.dispatchEvent({type:A.ADD_RENDERER,value:i.data})}}addRT(e,t){const i=new r.WebGLRenderTarget(32,32,t);i.texture.name=e,this.renderTargets.set(e,i)}resize(e,t){const i=this.dpr;this.renderTargets.forEach(n=>{n.setSize(e*i,t*i)}),this.renderer?.setSize(e,t)}set dpr(e){this.renderer?.setPixelRatio(Te(1,2,e))}get dpr(){return this.renderer!==void 0?this.renderer?.getPixelRatio():1}get width(){return this.renderer!==void 0?this.renderer.domElement.width/this.dpr:0}get height(){return this.renderer!==void 0?this.renderer.domElement.height/this.dpr:0}get canvas(){return this.renderer!==void 0?this.renderer?.domElement:null}}var ri={exports:{}},Ke={};/**
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("three"),S=require("react"),is=require("framer-motion"),ui=()=>{},Bs=()=>{};function dt(s){return s.substring(0,1).toUpperCase()+s.substring(1)}function ss(s){const e=JSON.stringify(s);return navigator.clipboard.writeText(e),e}function Te(s,e,t){return Math.min(e,Math.max(s,t))}function si(s,e,t){return(t-s)/(e-s)}function Pt(s,e,t){return s*(1-t)+e*t}function Ys(s,e){const t=s-e;return Math.sqrt(t*t)}function ns(){return Math.round(Math.random()*1e6).toString()}function as(s){return s.r!==void 0&&s.g!==void 0&&s.b!==void 0}function ni(s){const e=Math.round(s.r*255),t=Math.round(s.g*255),i=Math.round(s.b*255),n=h=>{const c=h.toString(16);return c.length===1?"0"+c:c},o=n(e),a=n(t),l=n(i);return"#"+o+a+l}function me(s,e=1){return Number(s.toFixed(e))}exports.totalThreeObjects=0;const ai=()=>{exports.totalThreeObjects=0},Dt=s=>{if(!s)return;let e=s.name.replaceAll(" ","").replaceAll("/",".");if(e.length===0&&(e=`obj_${exports.totalThreeObjects}`,exports.totalThreeObjects++),s.parent!==null&&s.parent.uuid.length>0&&(e=`${s.parent.uuid}.${e}`),s.uuid=e,s.isMesh!==void 0){const t=s;if(Array.isArray(t.material))t.material.forEach((i,n)=>{i.uuid=`${e}.material.${n}`});else{const i=t.material;i.uuid=`${e}.material`}}s.children.forEach(t=>Dt(t))},Gs=s=>{s?.dispose()},rs=s=>{s&&(Array.isArray(s)?s.forEach(e=>e.dispose()):s.dispose())},be=s=>{if(s){for(;s.children.length>0;){const e=s.children[0];e.type==="Audio"?(e.pause(),e.parent&&e.parent.remove(e)):be(e)}if(s.parent&&s.parent.remove(s),s.isMesh){const e=s;e.geometry?.dispose(),rs(e.material)}s.dispose!==void 0&&s.dispose()}};class ht{static renderer;static canvas;static context=null;static scene=null;static camera=null;static material=null;static inited=!1;static width=100;static height=100;static init(){this.inited||(this.canvas=document.createElement("canvas"),this.canvas.width=this.width,this.canvas.height=this.height,this.context=this.canvas.getContext("2d"),this.inited=!0)}static renderToBlob(e){this.init();const t=e.repeat.clone(),i=e.offset.clone();if(e.repeat.set(1,1),e.offset.set(0,0),this.context!==null){this.context.clearRect(0,0,this.width,this.height);const n=e.image;if(n!=null&&n.width>0){this.canvas.title=e.sourceFile;const o=this.canvas.width/n.width,a=this.renderToCanvas(e);this.context.drawImage(a,0,0,n.width*o,n.height*o)}}return e.repeat.copy(t),e.offset.copy(i),this.canvas.toDataURL("image/png")}static renderToCanvas(e){if(this.material===null){this.camera=new r.OrthographicCamera(-.5,.5,.5,-.5,0,100),this.scene=new r.Scene,this.material=new r.MeshBasicMaterial;const t=new r.BufferGeometry;t.setAttribute("position",new r.Float32BufferAttribute([-.5,-.5,0,1.5,-.5,0,-.5,1.5,0],3)),t.setAttribute("normal",new r.Float32BufferAttribute([0,0,1,0,0,1],3)),t.setAttribute("uv",new r.Float32BufferAttribute([0,0,2,0,0,2],2));const i=new r.Mesh(t,this.material);this.scene.add(i)}if(e.isRenderTargetTexture)this.material.map=e,this.renderer.render(this.scene,this.camera);else{const t=this.renderer.outputColorSpace,i=e.colorSpace;this.renderer.outputColorSpace=r.LinearSRGBColorSpace,e.colorSpace=r.LinearSRGBColorSpace,this.material.map=e,this.renderer.render(this.scene,this.camera),this.renderer.outputColorSpace=t,e.colorSpace=i}return this.renderer.domElement}}class Zs{components=new Map;listen;_appID="";_debugEnabled;_broadcastChannel=void 0;_webSocket=void 0;_mode="app";_connected=!1;_useBC=!1;constructor(e,t,i=!0){this._appID=e,this._debugEnabled=t,t&&(this._useBC=i,i?(this._broadcastChannel=new BroadcastChannel(e),this._broadcastChannel.addEventListener("message",this.messageHandler)):(this._webSocket=new WebSocket(e),this._webSocket.addEventListener("open",this.openHandler),this._webSocket.addEventListener("close",this.closeHandler),this._webSocket.addEventListener("message",this.messageHandler)))}addComponent(e,t){this.components.set(e,t)}dispose(){this._broadcastChannel!==void 0&&this._broadcastChannel.removeEventListener("message",this.messageHandler),this._webSocket!==void 0&&(this._webSocket.removeEventListener("open",this.openHandler),this._webSocket.removeEventListener("close",this.closeHandler),this._webSocket.removeEventListener("message",this.messageHandler)),this.components.forEach(e=>{e.dispose()}),this.components.clear()}send(e){this._mode!==e.target&&(this._useBC?this._broadcastChannel?.postMessage(e):this._connected&&this._webSocket?.send(JSON.stringify(e)))}messageHandler=e=>{this.listen!==void 0&&(this._useBC?this.listen(e.data):this.listen(JSON.parse(e.data)))};openHandler=()=>{this._connected=!0};closeHandler=()=>{this._connected=!1};get appID(){return this._appID}get connected(){return this._connected}get debugEnabled(){return this._debugEnabled}get mode(){return this._mode}get isApp(){return this._mode==="app"}get editor(){return this._mode==="editor"}set editor(e){e&&(this._mode="editor")}}var A=(s=>(s.CUSTOM="ToolEvents::custom",s.SELECT_DROPDOWN="ToolEvents::selectDropdown",s.DRAG_UPDATE="ToolEvents::dragUpdate",s.ADD_SCENE="ToolEvents::addScene",s.REFRESH_SCENE="ToolEvents::refreshScene",s.REMOVE_SCENE="ToolEvents::removeScene",s.SET_SCENE="ToolEvents::setScene",s.GET_OBJECT="ToolEvents::getObject",s.SET_OBJECT="ToolEvents::setObject",s.UPDATE_OBJECT="ToolEvents::updateObject",s.CREATE_TEXTURE="ToolEvents::createTexture",s.REQUEST_METHOD="ToolEvents::requestMethod",s.ADD_CAMERA="ToolEvents::addCamera",s.REMOVE_CAMERA="ToolEvents::removeCamera",s.ADD_GROUP="ToolEvents::addGroup",s.REMOVE_GROUP="ToolEvents::removeGroup",s.ADD_SPLINE="ToolEvents::addSpline",s.ADD_RENDERER="ToolEvents::addRenderer",s.UPDATE_RENDERER="ToolEvents::updateRenderer",s))(A||{});const R=new r.EventDispatcher;class Lt{app;constructor(e){this.app=e}dispose(){}handleApp(e,t,i){}handleEditor(e,t,i){}}class Ws extends Lt{selectDropdown(e,t){this.app.send({event:"selectComponent",target:"app",data:{dropdown:e,value:t}})}updateDropdown(e,t){this.app.send({event:"draggableListUpdate",target:"app",data:{dropdown:e,value:t}})}handleApp(e,t,i){switch(i.event){case"selectComponent":R.dispatchEvent({type:A.SELECT_DROPDOWN,value:i.data});break;case"draggableListUpdate":R.dispatchEvent({type:A.DRAG_UPDATE,value:i.data});break}}}function Xs(s,e,t){if(s.editor){t.ui.restore(),t.onSelectionChange(a=>{a.length<1||a.forEach(l=>{let h=l.address.sheetId,c="setSheet",p={};switch(l.type){case"Theatre_Sheet_PublicAPI":c="setSheet",p={sheet:l.address.sheetId},e.activeSheet=e.sheets.get(l.address.sheetId);break;case"Theatre_SheetObject_PublicAPI":c="setSheetObject",h+=`_${l.address.objectKey}`,p={id:h,sheet:l.address.sheetId,key:l.address.objectKey},e.activeSheet=e.sheets.get(l.address.sheetId);break}s.send({event:c,target:"app",data:p})})});let i=-1;const n=()=>{if(e.activeSheet!==void 0&&i!==e.activeSheet.sequence.position){i=e.activeSheet.sequence.position;const a=e.activeSheet;s.send({event:"updateTimeline",target:"app",data:{position:i,sheet:a.address.sheetId}})}},o=()=>{n(),requestAnimationFrame(o)};n(),o()}else t.ui.hide()}function Qs(){setTimeout(()=>{const s=document.getElementById("theatrejs-studio-root");if(s===null||s.shadowRoot===null)return;const e=s.shadowRoot.getElementById("pointer-root");if(e===null)return;const t=e.children[0];if(t===null)return;const i=t.children[1];i.style.justifyContent="left";try{const n=i.children[1];for(n.style.transform="translateX(10px)";n.children.length>1;)n.removeChild(n.children[0])}catch{}try{const n=t.children[3];n.style.top="0",n.style.right="300px"}catch{}},1e3)}class qs extends Lt{project;sheets=new Map;sheetObjects=new Map;sheetObjectCBs=new Map;sheetObjectUnsubscribe=new Map;activeSheet;studio=void 0;dispose(){this.project=void 0,this.sheets=new Map,this.sheetObjects=new Map,this.sheetObjectCBs=new Map,this.sheetObjectUnsubscribe=new Map}getSheetInstance(e,t){return t!==void 0?`${e}-${t}`:e}sheet(e,t){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const i=this.getSheetInstance(e,t);let n=this.sheets.get(i);return n!==void 0||(n=this.project?.sheet(e,t),this.sheets.set(i,n)),n}playSheet(e,t,i){return new Promise(n=>{const o=t!==void 0?{...t}:{};this.sheet(e,i)?.sequence.play(o).then(a=>n(a)),this.app.send({event:"playSheet",target:"editor",data:{sheet:e,instance:i,value:t}})})}pauseSheet(e,t){this.sheet(e,t)?.sequence.pause(),this.app.send({event:"pauseSheet",target:"editor",data:{sheet:e,instance:t}})}clearSheetObjects(e){this.sheetObjects.forEach((t,i)=>{i.search(`${e}_`)>-1&&this.unsubscribe(t)})}sheetObject(e,t,i,n,o){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const a=this.sheet(e,o);if(a===void 0)return;const h=`${this.getSheetInstance(e,o)}_${t}`;let c=this.sheetObjects.get(h);c!==void 0?c=a.object(t,{...i,...c.value},{reconfigure:!0}):c=a.object(t,i),this.sheetObjects.set(h,c),this.sheetObjectCBs.set(h,n!==void 0?n:ui);const p=c.onValuesChange(m=>{if(this.app.editor){for(const y in m){const x=m[y];typeof x=="object"&&as(x)&&(m[y]={r:x.r,g:x.g,b:x.b,a:x.a})}this.app.send({event:"updateSheetObject",target:"app",data:{sheet:e,sheetObject:h,values:m}})}const f=this.sheetObjectCBs.get(h);f!==void 0&&f(m)});return this.sheetObjectUnsubscribe.set(h,p),c}unsubscribe(e){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const t=e.address.sheetId,i=e.address.objectKey;this.sheets.get(t)?.detachObject(i);const o=`${t}_${i}`,a=this.sheetObjectUnsubscribe.get(o);a!==void 0&&(this.sheetObjects.delete(o),this.sheetObjectCBs.delete(o),this.sheetObjectUnsubscribe.delete(o),a())}handleApp(e,t,i){const n=t;let o;switch(i.event){case"setSheet":o=n.sheets.get(i.data.sheet),o!==void 0&&(n.activeSheet=o,this.studio?.setSelection([o]));break;case"setSheetObject":o=n.sheetObjects.get(`${i.data.sheet}_${i.data.key}`),o!==void 0&&this.studio?.setSelection([o]);break;case"updateSheetObject":o=n.sheets.get(i.data.sheet),o!==void 0&&o.sequence.pause(),o=n.sheetObjectCBs.get(i.data.sheetObject),o!==void 0&&o(i.data.values);break;case"updateTimeline":o=n.sheets.get(i.data.sheet),n.activeSheet!==void 0&&(n.activeSheet.sequence.position=i.data.position);break}}handleEditor(e,t,i){if(e.editor){const n=t;switch(i.event){case"playSheet":n.sheet(i.data.sheet,i.data.instance)?.sequence.play(i.data.value);break;case"pauseSheet":n.sheet(i.data.sheet,i.data.instance)?.sequence.pause();break}}}handleEditorApp(e,t){if(e.editor){this.studio?.ui.restore(),this.studio?.onSelectionChange(a=>{a.length<1||a.forEach(l=>{let h=l.address.sheetId,c="setSheet",p={};switch(l.type){case"Theatre_Sheet_PublicAPI":c="setSheet",p={sheet:l.address.sheetId},t.activeSheet=t.sheets.get(l.address.sheetId);break;case"Theatre_SheetObject_PublicAPI":c="setSheetObject",h+=`_${l.address.objectKey}`,p={id:h,sheet:l.address.sheetId,key:l.address.objectKey},t.activeSheet=t.sheets.get(l.address.sheetId);break}e.send({event:c,target:"app",data:p})})});let i=-1;const n=()=>{if(t.activeSheet!==void 0&&i!==t.activeSheet.sequence.position){i=t.activeSheet.sequence.position;const a=t.activeSheet;e.send({event:"updateTimeline",target:"app",data:{position:i,sheet:a.address.sheetId}})}},o=()=>{n(),requestAnimationFrame(o)};n(),o()}else this.studio?.ui.hide()}}function Ks(s){if(s.name==="cameras")return"camera";if(s.name==="interactive")return"interactive";if(s.name==="lights")return"light";if(s.name==="ui")return"ui";if(s.name==="utils")return"utils";const e=s.type;return e.search("Helper")>-1?"icon_utils":e.search("Camera")>-1?"camera":e.search("Light")>-1?"light":"obj3D"}function Xe(s){const e={name:s.name,type:s.type,uuid:s.uuid,children:[]};return s.children.forEach(t=>{e.children.push(Xe(t))}),e}function $s(s){const e={};for(const t in s){const i=s[t].value;e[t]={value:i},i===null?e[t].value={src:"",offset:[0,0],repeat:[1,1]}:i!==void 0&&i.isTexture&&(e[t].value={src:i.image.src,offset:[i.offset.x,i.offset.y],repeat:[i.repeat.x,i.repeat.y]})}return e}function Js(s){switch(s){case"blendSrcAlpha":case"blendDstAlpha":case"blendEquationAlpha":case"clippingPlanes":case"shadowSide":case"precision":return!0}return!1}function He(s){const e={};for(const t in s){if(t.substring(0,1)==="_"||t.substring(0,2)==="is"||Js(t))continue;const i=typeof s[t],n=s[t];switch(i){case"boolean":case"number":case"string":e[t]=n;break;case"object":n!==null?(e[t]=n,n.isTexture?e[t]={src:ht.renderToBlob(n),offset:[n.offset.x,n.offset.y],repeat:[n.repeat.x,n.repeat.y]}:t==="uniforms"&&(e[t]=$s(e[t]))):t==="glslVersion"?e[t]="":e[t]={src:"",offset:[0,0],repeat:[1,1]};break}}return s.anisotropy!==void 0&&(e.anisotropy=s.anisotropy),s.clearcoat!==void 0&&(e.clearcoat=s.clearcoat),s.iridescence!==void 0&&(e.iridescence=s.iridescence),s.dispersion!==void 0&&(e.dispersion=s.dispersion),s.sheen!==void 0&&(e.sheen=s.sheen),s.transmission!==void 0&&(e.transmission=s.transmission),s.transmission!==void 0&&(e.transmission=s.transmission),e}function Gt(s){s.updateMatrix();const e={name:s.name,type:s.type,uuid:s.uuid,visible:s.visible,matrix:s.matrix.elements,animations:[],material:void 0,perspectiveCameraInfo:void 0,orthographicCameraInfo:void 0,lightInfo:void 0,children:[]};s.animations.forEach(i=>{e.animations.push({name:i.name,duration:i.duration,blendMode:i.blendMode})});const t=s.type.toLowerCase();if(t.search("mesh")>-1){const i=s;if(Array.isArray(i.material)){const n=[];i.material.forEach(o=>{n.push(He(o))}),e.material=n}else e.material=He(i.material)}else if(t.search("points")>-1){const i=s;if(Array.isArray(i.material)){const n=[];i.material.forEach(o=>{n.push(He(o))}),e.material=n}else e.material=He(i.material)}else if(t.search("line")>-1){const i=s;if(Array.isArray(i.material)){const n=[];i.material.forEach(o=>{n.push(He(o))}),e.material=n}else e.material=He(i.material)}else t.search("camera")>-1?s.type==="PerspectiveCamera"?e.perspectiveCameraInfo={fov:s.fov,zoom:s.zoom,near:s.near,far:s.far,focus:s.focus,aspect:s.aspect,filmGauge:s.filmGauge,filmOffset:s.filmOffset}:s.type==="OrthographicCamera"&&(e.orthographicCameraInfo={zoom:s.zoom,near:s.near,far:s.far,left:s.left,right:s.right,top:s.top,bottom:s.bottom}):t.search("light")>-1&&(e.lightInfo={color:s.color,intensity:s.intensity,decay:s.decay,distance:s.distance,angle:s.angle,penumbra:s.penumbra,groundColor:s.groundColor,width:s.width,height:s.height});return e}function en(s,e){const t=e.split(".");switch(t.length){case 1:return s[t[0]];case 2:return s[t[0]][t[1]];case 3:return s[t[0]][t[1]][t[2]];case 4:return s[t[0]][t[1]][t[2]][t[3]];case 5:return s[t[0]][t[1]][t[2]][t[3]][t[4]];case 6:return s[t[0]][t[1]][t[2]][t[3]][t[4]][t[5]]}}function tn(s,e){for(const t in e)s[t]=e[t]}function q(s,e,t){if(s===void 0)return;const i=e.split("."),n=i.length;if(typeof t!="object")switch(n){case 1:s[i[0]]=t;break;case 2:s[i[0]][i[1]]=t;break;case 3:s[i[0]][i[1]][i[2]]=t;break;case 4:s[i[0]][i[1]][i[2]][i[3]]=t;break;case 5:s[i[0]][i[1]][i[2]][i[3]][i[4]]=t;break}else{let a;switch(n){case 1:a=s[i[0]];break;case 2:a=s[i[0]][i[1]];break;case 3:a=s[i[0]][i[1]][i[2]];break;case 4:a=s[i[0]][i[1]][i[2]][i[3]];break;case 5:a=s[i[0]][i[1]][i[2]][i[3]][i[4]];break}a!=null&&tn(a,t)}}function os(s){return new Promise((e,t)=>{const i=new Image;i.onload=()=>{const n=new r.Texture(i);n.wrapS=r.RepeatWrapping,n.wrapT=r.RepeatWrapping,n.needsUpdate=!0,e(n)},i.onerror=t,i.src=s})}class sn extends Lt{scene=void 0;scenes=new Map;renderer=void 0;renderTargets=new Map;groups=new Map;dispose(){this.scenes.forEach(e=>{be(e)}),this.scenes.clear(),this.scene&&be(this.scene),this.renderTargets.forEach(e=>{e.dispose()}),this.renderTargets.clear(),this.renderer?.dispose()}getObject(e){this.app.debugEnabled&&(this.renderer!==void 0&&(ht.renderer=this.renderer),this.app.send({event:"getObject",target:"app",data:e}))}setObject(e){this.renderer!==void 0&&(ht.renderer=this.renderer);const t=Gt(e);this.app.send({event:"setObject",target:"editor",data:t})}requestMethod(e,t,i,n){this.app.send({event:"requestMethod",target:"app",data:{uuid:e,key:t,value:i,subitem:n}})}updateObject(e,t,i){this.app.send({event:"updateObject",target:"app",data:{uuid:e,key:t,value:i}})}createTexture(e,t,i){this.app.send({event:"createTexture",target:"app",data:{uuid:e,key:t,value:i}})}addGroup(e){this.groups.get(e.title)===void 0&&(this.groups.set(e.title,{title:e.title,onUpdate:e.onUpdate}),this.app.send({event:"addGroup",target:"editor",data:JSON.stringify(e)}))}removeGroup(e){this.groups.get(e)!==void 0&&(this.groups.delete(e),this.app.send({event:"removeGroup",target:"editor",data:e}))}updateGroup(e,t,i){this.app.send({event:"updateGroup",target:"app",data:JSON.stringify({group:e,prop:t,value:i})})}removeAllGroups(){this.groups.forEach(e=>{const t=e.title;this.groups.delete(t),this.app.send({event:"removeGroup",target:"editor",data:t})}),this.groups.clear()}addSpline(e){setTimeout(()=>{this.app.send({event:"addSpline",target:"editor",data:JSON.stringify(e.toJSON())})},1)}addRenderer(e){if(this.renderer=e,!this.app.debugEnabled)return;const t=`#${e.getClearColor(new r.Color).getHexString()}`;this.app.send({event:"addRenderer",target:"editor",data:{autoClear:e.autoClear,autoClearColor:e.autoClearColor,autoClearDepth:e.autoClearDepth,autoClearStencil:e.autoClearStencil,outputColorSpace:e.outputColorSpace,localClippingEnabled:e.localClippingEnabled,clearColor:t,clearAlpha:e.getClearAlpha(),colorManagement:r.ColorManagement.enabled,toneMapping:e.toneMapping,toneMappingExposure:e.toneMappingExposure}})}updateRenderer(e){this.app.send({event:"updateRenderer",target:"app",data:e})}addScene(e){if(e===void 0||(this.scenes.set(e.name,e),!this.app.debugEnabled))return;ai(),Dt(e);const t=Xe(e);this.app.send({event:"addScene",target:"editor",data:t})}refreshScene(e){if(!this.app.debugEnabled)return;const t=this.scenes.get(e);if(t!==void 0){const i=Xe(t);this.app.send({event:"refreshScene",target:"app",data:i})}}removeScene(e){if(e===void 0||(this.scenes.delete(e.name),!this.app.debugEnabled))return;const t=Xe(e);this.app.send({event:"removeScene",target:"editor",data:t})}removeAllScenes(){this.scenes.forEach(e=>this.removeScene(e))}getScene(e){let t=null;return this.scenes.forEach((i,n)=>{e.search(n)>-1&&(t=i)}),t}setScene(e){if(e===void 0||(this.scene=e,!this.app.debugEnabled))return;this.renderer!==void 0&&(ht.renderer=this.renderer),ai(),Dt(e);const t=Xe(e);this.app.send({event:"setScene",target:"editor",data:t})}addCamera(e){if(!this.app.debugEnabled)return;const t=Gt(e);this.app.send({event:"addCamera",target:"editor",data:t})}removeCamera(e){if(!this.app.debugEnabled)return;const t=Gt(e);this.app.send({event:"removeCamera",target:"editor",data:t})}handleApp(e,t,i){const n=t;switch(i.event){case"getObject":R.dispatchEvent({type:A.GET_OBJECT,value:i.data});break;case"updateObject":R.dispatchEvent({type:A.UPDATE_OBJECT,value:i.data});break;case"createTexture":R.dispatchEvent({type:A.CREATE_TEXTURE,value:i.data});break;case"requestMethod":R.dispatchEvent({type:A.REQUEST_METHOD,value:i.data});break;case"refreshScene":e.send({event:"refreshScene",target:"editor",data:Xe(n.scenes.get(i.data.name))});break;case"updateRenderer":n.renderer&&(n.renderer.autoClear=i.data.autoClear,n.renderer.autoClearColor=i.data.autoClearColor,n.renderer.autoClearDepth=i.data.autoClearDepth,n.renderer.autoClearStencil=i.data.autoClearStencil,n.renderer.outputColorSpace=i.data.outputColorSpace,n.renderer.localClippingEnabled=i.data.localClippingEnabled,n.renderer.setClearColor(i.data.clearColor,i.data.clearAlpha),n.renderer.toneMapping=i.data.toneMapping,n.renderer.toneMappingExposure=i.data.toneMappingExposure,r.ColorManagement.enabled=i.data.colorManagement);break}if(i.event==="updateGroup"){const o=JSON.parse(i.data);n.groups.get(o.group)?.onUpdate(o.prop,o.value)}}handleEditor(e,t,i){switch(i.event){case"setObject":R.dispatchEvent({type:A.SET_OBJECT,value:i.data});break;case"addScene":R.dispatchEvent({type:A.ADD_SCENE,value:i.data});break;case"refreshScene":R.dispatchEvent({type:A.REFRESH_SCENE,value:i.data});break;case"removeScene":R.dispatchEvent({type:A.REMOVE_SCENE,value:i.data});break;case"setScene":R.dispatchEvent({type:A.SET_SCENE,value:i.data});break;case"addCamera":R.dispatchEvent({type:A.ADD_CAMERA,value:i.data});break;case"removeCamera":R.dispatchEvent({type:A.REMOVE_CAMERA,value:i.data});break;case"addGroup":R.dispatchEvent({type:A.ADD_GROUP,value:i.data});break;case"removeGroup":R.dispatchEvent({type:A.REMOVE_GROUP,value:i.data});break;case"addSpline":R.dispatchEvent({type:A.ADD_SPLINE,value:i.data});break;case"addRenderer":R.dispatchEvent({type:A.ADD_RENDERER,value:i.data})}}addRT(e,t){const i=new r.WebGLRenderTarget(32,32,t);i.texture.name=e,this.renderTargets.set(e,i)}resize(e,t){const i=this.dpr;this.renderTargets.forEach(o=>{o.setSize(e*i,t*i)});const n=!(this.renderer?.domElement instanceof OffscreenCanvas);this.renderer?.setSize(e,t,n)}set dpr(e){this.renderer?.setPixelRatio(Te(1,2,e))}get dpr(){return this.renderer!==void 0?this.renderer?.getPixelRatio():1}get width(){return this.renderer!==void 0?this.renderer.domElement.width/this.dpr:0}get height(){return this.renderer!==void 0?this.renderer.domElement.height/this.dpr:0}get canvas(){return this.renderer!==void 0?this.renderer?.domElement:null}}var ri={exports:{}},Ke={};/**
|
2
2
|
* @license React
|
3
3
|
* react-jsx-runtime.production.min.js
|
4
4
|
*
|
package/dist/hermes.es.js
CHANGED
@@ -989,9 +989,11 @@ class uo extends Ui {
|
|
989
989
|
}
|
990
990
|
resize(e, t) {
|
991
991
|
const i = this.dpr;
|
992
|
-
this.renderTargets.forEach((
|
993
|
-
|
994
|
-
})
|
992
|
+
this.renderTargets.forEach((r) => {
|
993
|
+
r.setSize(e * i, t * i);
|
994
|
+
});
|
995
|
+
const n = !(this.renderer?.domElement instanceof OffscreenCanvas);
|
996
|
+
this.renderer?.setSize(e, t, n);
|
995
997
|
}
|
996
998
|
set dpr(e) {
|
997
999
|
this.renderer?.setPixelRatio(Be(1, 2, e));
|
package/package.json
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
"module": "./dist/hermes.esm.js",
|
8
8
|
"types": "./types/index.d.ts",
|
9
9
|
"type": "module",
|
10
|
-
"version": "0.0.
|
10
|
+
"version": "0.0.115",
|
11
11
|
"homepage": "https://github.com/tomorrowevening/hermes#readme",
|
12
12
|
"bugs": {
|
13
13
|
"url": "https://github.com/tomorrowevening/hermes/issues"
|
@@ -1,41 +1,41 @@
|
|
1
|
-
import { Camera, Curve, RenderTargetOptions, Scene, WebGLRenderTarget, WebGLRenderer } from 'three';
|
2
|
-
import Application from '../Application';
|
3
|
-
import BaseRemote from './BaseRemote';
|
4
|
-
import { BroadcastData, GroupData } from '../types';
|
5
|
-
export default class RemoteThree extends BaseRemote {
|
6
|
-
scene?: Scene;
|
7
|
-
scenes: Map<string, Scene>;
|
8
|
-
renderer?: WebGLRenderer;
|
9
|
-
renderTargets: Map<string, WebGLRenderTarget>;
|
10
|
-
private groups;
|
11
|
-
dispose(): void;
|
12
|
-
getObject(uuid: string): void;
|
13
|
-
setObject(value: any): void;
|
14
|
-
requestMethod(uuid: string, key: string, value?: any, subitem?: string): void;
|
15
|
-
updateObject(uuid: string, key: string, value: any): void;
|
16
|
-
createTexture(uuid: string, key: string, value: any): void;
|
17
|
-
addGroup(data: GroupData): void;
|
18
|
-
removeGroup(name: string): void;
|
19
|
-
updateGroup(group: string, prop: string, value: any): void;
|
20
|
-
removeAllGroups(): void;
|
21
|
-
addSpline(spline: Curve<any>): void;
|
22
|
-
addRenderer(value: WebGLRenderer): void;
|
23
|
-
updateRenderer(data: any): void;
|
24
|
-
addScene(value: Scene): void;
|
25
|
-
refreshScene(value: string): void;
|
26
|
-
removeScene(value: Scene): void;
|
27
|
-
removeAllScenes(): void;
|
28
|
-
getScene(uuid: string): Scene | null;
|
29
|
-
setScene(value: Scene): void;
|
30
|
-
addCamera(camera: Camera): void;
|
31
|
-
removeCamera(camera: Camera): void;
|
32
|
-
handleApp(app: Application, remote: BaseRemote, msg: BroadcastData): void;
|
33
|
-
handleEditor(app: Application, remote: BaseRemote, msg: BroadcastData): void;
|
34
|
-
addRT(name: string, params?: RenderTargetOptions): void;
|
35
|
-
resize(width: number, height: number): void;
|
36
|
-
set dpr(value: number);
|
37
|
-
get dpr(): number;
|
38
|
-
get width(): number;
|
39
|
-
get height(): number;
|
40
|
-
get canvas(): HTMLCanvasElement | null;
|
41
|
-
}
|
1
|
+
import { Camera, Curve, RenderTargetOptions, Scene, WebGLRenderTarget, WebGLRenderer } from 'three';
|
2
|
+
import Application from '../Application';
|
3
|
+
import BaseRemote from './BaseRemote';
|
4
|
+
import { BroadcastData, GroupData } from '../types';
|
5
|
+
export default class RemoteThree extends BaseRemote {
|
6
|
+
scene?: Scene;
|
7
|
+
scenes: Map<string, Scene>;
|
8
|
+
renderer?: WebGLRenderer;
|
9
|
+
renderTargets: Map<string, WebGLRenderTarget>;
|
10
|
+
private groups;
|
11
|
+
dispose(): void;
|
12
|
+
getObject(uuid: string): void;
|
13
|
+
setObject(value: any): void;
|
14
|
+
requestMethod(uuid: string, key: string, value?: any, subitem?: string): void;
|
15
|
+
updateObject(uuid: string, key: string, value: any): void;
|
16
|
+
createTexture(uuid: string, key: string, value: any): void;
|
17
|
+
addGroup(data: GroupData): void;
|
18
|
+
removeGroup(name: string): void;
|
19
|
+
updateGroup(group: string, prop: string, value: any): void;
|
20
|
+
removeAllGroups(): void;
|
21
|
+
addSpline(spline: Curve<any>): void;
|
22
|
+
addRenderer(value: WebGLRenderer): void;
|
23
|
+
updateRenderer(data: any): void;
|
24
|
+
addScene(value: Scene): void;
|
25
|
+
refreshScene(value: string): void;
|
26
|
+
removeScene(value: Scene): void;
|
27
|
+
removeAllScenes(): void;
|
28
|
+
getScene(uuid: string): Scene | null;
|
29
|
+
setScene(value: Scene): void;
|
30
|
+
addCamera(camera: Camera): void;
|
31
|
+
removeCamera(camera: Camera): void;
|
32
|
+
handleApp(app: Application, remote: BaseRemote, msg: BroadcastData): void;
|
33
|
+
handleEditor(app: Application, remote: BaseRemote, msg: BroadcastData): void;
|
34
|
+
addRT(name: string, params?: RenderTargetOptions): void;
|
35
|
+
resize(width: number, height: number): void;
|
36
|
+
set dpr(value: number);
|
37
|
+
get dpr(): number;
|
38
|
+
get width(): number;
|
39
|
+
get height(): number;
|
40
|
+
get canvas(): HTMLCanvasElement | null;
|
41
|
+
}
|
package/types/core/types.d.ts
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
import { InspectorFieldType } from '@/editor/sidePanel/inspector/InspectorField';
|
2
|
-
export interface BroadcastData {
|
3
|
-
target: ApplicationMode;
|
4
|
-
event: EditorEvent;
|
5
|
-
data?: any;
|
6
|
-
}
|
7
|
-
export interface GroupItemData {
|
8
|
-
type: InspectorFieldType;
|
9
|
-
prop: string;
|
10
|
-
title?: string;
|
11
|
-
value?: any;
|
12
|
-
min?: number;
|
13
|
-
max?: number;
|
14
|
-
step?: number;
|
15
|
-
disabled?: boolean;
|
16
|
-
options?: any[];
|
17
|
-
}
|
18
|
-
export interface GroupData {
|
19
|
-
title: string;
|
20
|
-
items: GroupItemData[];
|
21
|
-
onUpdate: (prop: string, value: any) => void;
|
22
|
-
}
|
23
|
-
export interface GroupCallback {
|
24
|
-
title: string;
|
25
|
-
onUpdate: (prop: string, value: any) => void;
|
26
|
-
}
|
27
|
-
export type ApplicationMode = 'app' | 'editor';
|
28
|
-
export type VoidCallback = () => void;
|
29
|
-
export type DataUpdateCallback = (data: any) => void;
|
30
|
-
export type EditorEvent = 'custom' | 'setSheet' | 'setSheetObject' | 'updateSheetObject' | 'updateTimeline' | 'playSheet' | 'pauseSheet' | 'getObject' | 'setObject' | 'updateObject' | 'addScene' | 'refreshScene' | 'removeScene' | 'setScene' | 'createTexture' | 'requestMethod' | 'addCamera' | 'removeCamera' | 'addSpline' | 'addRenderer' | 'updateRenderer' | 'addFolder' | 'bindObject' | 'updateBind' | 'addButton' | 'clickButton' | 'selectComponent' | 'draggableListUpdate' | 'addGroup' | 'removeGroup' | 'updateGroup';
|
31
|
-
export type VoidFunc = () => void;
|
32
|
-
export type BroadcastCallback = (data: BroadcastData) => void;
|
33
|
-
export type TheatreUpdateCallback = (data: any) => void;
|
34
|
-
export declare const noop: () => void;
|
35
|
-
export declare const defaultTheatreCallback: TheatreUpdateCallback;
|
1
|
+
import { InspectorFieldType } from '@/editor/sidePanel/inspector/InspectorField';
|
2
|
+
export interface BroadcastData {
|
3
|
+
target: ApplicationMode;
|
4
|
+
event: EditorEvent;
|
5
|
+
data?: any;
|
6
|
+
}
|
7
|
+
export interface GroupItemData {
|
8
|
+
type: InspectorFieldType;
|
9
|
+
prop: string;
|
10
|
+
title?: string;
|
11
|
+
value?: any;
|
12
|
+
min?: number;
|
13
|
+
max?: number;
|
14
|
+
step?: number;
|
15
|
+
disabled?: boolean;
|
16
|
+
options?: any[];
|
17
|
+
}
|
18
|
+
export interface GroupData {
|
19
|
+
title: string;
|
20
|
+
items: GroupItemData[];
|
21
|
+
onUpdate: (prop: string, value: any) => void;
|
22
|
+
}
|
23
|
+
export interface GroupCallback {
|
24
|
+
title: string;
|
25
|
+
onUpdate: (prop: string, value: any) => void;
|
26
|
+
}
|
27
|
+
export type ApplicationMode = 'app' | 'editor';
|
28
|
+
export type VoidCallback = () => void;
|
29
|
+
export type DataUpdateCallback = (data: any) => void;
|
30
|
+
export type EditorEvent = 'custom' | 'setSheet' | 'setSheetObject' | 'updateSheetObject' | 'updateTimeline' | 'playSheet' | 'pauseSheet' | 'getObject' | 'setObject' | 'updateObject' | 'addScene' | 'refreshScene' | 'removeScene' | 'setScene' | 'createTexture' | 'requestMethod' | 'addCamera' | 'removeCamera' | 'addSpline' | 'addRenderer' | 'updateRenderer' | 'addFolder' | 'bindObject' | 'updateBind' | 'addButton' | 'clickButton' | 'selectComponent' | 'draggableListUpdate' | 'addGroup' | 'removeGroup' | 'updateGroup';
|
31
|
+
export type VoidFunc = () => void;
|
32
|
+
export type BroadcastCallback = (data: BroadcastData) => void;
|
33
|
+
export type TheatreUpdateCallback = (data: any) => void;
|
34
|
+
export declare const noop: () => void;
|
35
|
+
export declare const defaultTheatreCallback: TheatreUpdateCallback;
|
package/types/editor/global.d.ts
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
import { EventDispatcher } from 'three';
|
2
|
-
export declare enum ToolEvents {
|
3
|
-
CUSTOM = "ToolEvents::custom",
|
4
|
-
SELECT_DROPDOWN = "ToolEvents::selectDropdown",
|
5
|
-
DRAG_UPDATE = "ToolEvents::dragUpdate",
|
6
|
-
ADD_SCENE = "ToolEvents::addScene",
|
7
|
-
REFRESH_SCENE = "ToolEvents::refreshScene",
|
8
|
-
REMOVE_SCENE = "ToolEvents::removeScene",
|
9
|
-
SET_SCENE = "ToolEvents::setScene",
|
10
|
-
GET_OBJECT = "ToolEvents::getObject",
|
11
|
-
SET_OBJECT = "ToolEvents::setObject",
|
12
|
-
UPDATE_OBJECT = "ToolEvents::updateObject",
|
13
|
-
CREATE_TEXTURE = "ToolEvents::createTexture",
|
14
|
-
REQUEST_METHOD = "ToolEvents::requestMethod",
|
15
|
-
ADD_CAMERA = "ToolEvents::addCamera",
|
16
|
-
REMOVE_CAMERA = "ToolEvents::removeCamera",
|
17
|
-
ADD_GROUP = "ToolEvents::addGroup",
|
18
|
-
REMOVE_GROUP = "ToolEvents::removeGroup",
|
19
|
-
ADD_SPLINE = "ToolEvents::addSpline",
|
20
|
-
ADD_RENDERER = "ToolEvents::addRenderer",
|
21
|
-
UPDATE_RENDERER = "ToolEvents::updateRenderer"
|
22
|
-
}
|
23
|
-
export type ToolEvent = {
|
24
|
-
[key in ToolEvents]: {
|
25
|
-
value?: unknown;
|
26
|
-
};
|
27
|
-
};
|
28
|
-
export declare const debugDispatcher: EventDispatcher<ToolEvent>;
|
1
|
+
import { EventDispatcher } from 'three';
|
2
|
+
export declare enum ToolEvents {
|
3
|
+
CUSTOM = "ToolEvents::custom",
|
4
|
+
SELECT_DROPDOWN = "ToolEvents::selectDropdown",
|
5
|
+
DRAG_UPDATE = "ToolEvents::dragUpdate",
|
6
|
+
ADD_SCENE = "ToolEvents::addScene",
|
7
|
+
REFRESH_SCENE = "ToolEvents::refreshScene",
|
8
|
+
REMOVE_SCENE = "ToolEvents::removeScene",
|
9
|
+
SET_SCENE = "ToolEvents::setScene",
|
10
|
+
GET_OBJECT = "ToolEvents::getObject",
|
11
|
+
SET_OBJECT = "ToolEvents::setObject",
|
12
|
+
UPDATE_OBJECT = "ToolEvents::updateObject",
|
13
|
+
CREATE_TEXTURE = "ToolEvents::createTexture",
|
14
|
+
REQUEST_METHOD = "ToolEvents::requestMethod",
|
15
|
+
ADD_CAMERA = "ToolEvents::addCamera",
|
16
|
+
REMOVE_CAMERA = "ToolEvents::removeCamera",
|
17
|
+
ADD_GROUP = "ToolEvents::addGroup",
|
18
|
+
REMOVE_GROUP = "ToolEvents::removeGroup",
|
19
|
+
ADD_SPLINE = "ToolEvents::addSpline",
|
20
|
+
ADD_RENDERER = "ToolEvents::addRenderer",
|
21
|
+
UPDATE_RENDERER = "ToolEvents::updateRenderer"
|
22
|
+
}
|
23
|
+
export type ToolEvent = {
|
24
|
+
[key in ToolEvents]: {
|
25
|
+
value?: unknown;
|
26
|
+
};
|
27
|
+
};
|
28
|
+
export declare const debugDispatcher: EventDispatcher<ToolEvent>;
|
@@ -1,28 +1,28 @@
|
|
1
|
-
import { Component, ReactNode } from 'react';
|
2
|
-
import RemoteThree from '@/core/remote/RemoteThree';
|
3
|
-
type InspectRendererProps = {
|
4
|
-
three: RemoteThree;
|
5
|
-
};
|
6
|
-
type InspectRendererState = {
|
7
|
-
expanded: boolean;
|
8
|
-
lastUpdated: number;
|
9
|
-
};
|
10
|
-
export default class InspectRenderer extends Component<InspectRendererProps, InspectRendererState> {
|
11
|
-
private autoClear;
|
12
|
-
private autoClearColor;
|
13
|
-
private autoClearDepth;
|
14
|
-
private autoClearStencil;
|
15
|
-
private outputColorSpace;
|
16
|
-
private localClippingEnabled;
|
17
|
-
private clearColor;
|
18
|
-
private clearAlpha;
|
19
|
-
private toneMapping;
|
20
|
-
private toneMappingExposure;
|
21
|
-
constructor(props: InspectRendererProps);
|
22
|
-
componentwillunmount(): void;
|
23
|
-
private onAddRenderer;
|
24
|
-
render(): ReactNode;
|
25
|
-
private saveExpanded;
|
26
|
-
get expandedName(): string;
|
27
|
-
}
|
28
|
-
export {};
|
1
|
+
import { Component, ReactNode } from 'react';
|
2
|
+
import RemoteThree from '@/core/remote/RemoteThree';
|
3
|
+
type InspectRendererProps = {
|
4
|
+
three: RemoteThree;
|
5
|
+
};
|
6
|
+
type InspectRendererState = {
|
7
|
+
expanded: boolean;
|
8
|
+
lastUpdated: number;
|
9
|
+
};
|
10
|
+
export default class InspectRenderer extends Component<InspectRendererProps, InspectRendererState> {
|
11
|
+
private autoClear;
|
12
|
+
private autoClearColor;
|
13
|
+
private autoClearDepth;
|
14
|
+
private autoClearStencil;
|
15
|
+
private outputColorSpace;
|
16
|
+
private localClippingEnabled;
|
17
|
+
private clearColor;
|
18
|
+
private clearAlpha;
|
19
|
+
private toneMapping;
|
20
|
+
private toneMappingExposure;
|
21
|
+
constructor(props: InspectRendererProps);
|
22
|
+
componentwillunmount(): void;
|
23
|
+
private onAddRenderer;
|
24
|
+
render(): ReactNode;
|
25
|
+
private saveExpanded;
|
26
|
+
get expandedName(): string;
|
27
|
+
}
|
28
|
+
export {};
|