@tomorrowevening/hermes 0.0.20 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/hermes.js
CHANGED
@@ -165,7 +165,7 @@ const bn = () => {
|
|
165
165
|
H(this, "sheetObjectUnsubscribe", /* @__PURE__ */ new Map());
|
166
166
|
}
|
167
167
|
init(a, e) {
|
168
|
-
this.project = Zn(a, e);
|
168
|
+
return this.project = Zn(a, e), this.project.ready;
|
169
169
|
}
|
170
170
|
dispose() {
|
171
171
|
this.project = void 0, this.sheets = /* @__PURE__ */ new Map(), this.sheetObjects = /* @__PURE__ */ new Map(), this.sheetObjectCBs = /* @__PURE__ */ new Map(), this.sheetObjectUnsubscribe = /* @__PURE__ */ new Map();
|
package/dist/hermes.umd.cjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
(function(w,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("three"),require("@theatre/core"),require("@theatre/studio"),require("tweakpane"),require("@tweakpane/plugin-essentials"),require("react"),require("framer-motion")):typeof define=="function"&&define.amd?define(["exports","three","@theatre/core","@theatre/studio","tweakpane","@tweakpane/plugin-essentials","react","framer-motion"],u):(w=typeof globalThis<"u"?globalThis:w||self,u(w.Hermes={},w.Three,w["Theatre Core"],w["Theatre Studio"],w.tweakpane,w["tweakpane-plugin-essentials"],w.React,w["framer-motion"]))})(this,function(w,u,Se,Xe,xn,On,R,Bt){"use strict";var Ma=Object.defineProperty;var Ra=(w,u,Se)=>u in w?Ma(w,u,{enumerable:!0,configurable:!0,writable:!0,value:Se}):w[u]=Se;var Z=(w,u,Se)=>(Ra(w,typeof u!="symbol"?u+"":u,Se),Se);function Tn(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const e=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,e.get?e:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const Mn=Tn(On);function Rn(t,n,a){return Math.min(n,Math.max(t,a))}function Pn(t,n){const a=t-n;return Math.sqrt(a*a)}function Gt(){return Math.round(Math.random()*1e6).toString()}function Ht(t){return t.r!==void 0&&t.g!==void 0&&t.b!==void 0}function zt(t){const n=Math.round(t.r*255),a=Math.round(t.g*255),e=Math.round(t.b*255),r=f=>{const m=f.toString(16);return m.length===1?"0"+m:m},s=r(n),d=r(a),l=r(e);return"#"+s+d+l}function ct(t,n=1){return Number(t.toFixed(n))}w.totalThreeObjects=0;const Yt=()=>{w.totalThreeObjects=0},Tt=t=>{if(!t)return;let n=t.name.replace(" ","");n.length===0&&(n=`obj_${w.totalThreeObjects}`,w.totalThreeObjects++),t.parent!==null&&(n=`${t.parent.uuid}.${n}`),t.uuid=n,t.children.forEach(a=>{Tt(a)})},jn=t=>{t==null||t.dispose()},Wt=t=>{t&&(Array.isArray(t)?t.forEach(n=>n.dispose()):t.dispose())},Mt=t=>{var n;if(t){for(;t.children.length>0;){const a=t.children[0];a instanceof u.PositionalAudio?(a.pause(),a.parent&&a.parent.remove(a)):Mt(a)}if(t.parent&&t.parent.remove(t),t.isMesh){const a=t;(n=a.geometry)==null||n.dispose(),Wt(a.material)}t.dispose!==void 0&&t.dispose()}};class _n{constructor(n,a,e="editor"){Z(this,"channel");Z(this,"components",new Map);Z(this,"_mode","app");this.editor=a&&document.location.hash.search(e)>-1,a&&(this.channel=new BroadcastChannel(n))}addComponent(n,a){this.components.set(n,a)}dispose(){this.components.forEach(n=>{n.dispose()}),this.components.clear()}send(n){this.channel!==void 0&&this._mode!==n.target&&this.channel.postMessage(n)}listen(n){this.channel!==void 0&&(this.channel.onmessage=a=>{n(a.data)})}get mode(){return this._mode}get isApp(){return this._mode==="app"}get editor(){return this._mode==="editor"}set editor(n){n&&(this._mode="editor",document.title+=" - Editor")}}const D=new u.EventDispatcher,A={CUSTOM:"ToolEvents::custom",SELECT_DROPDOWN:"ToolEvents::selectDropdown",DRAG_UPDATE:"ToolEvents::dragUpdate",SET_SCENE:"ToolEvents::setScene",GET_OBJECT:"ToolEvents::getObject",SET_OBJECT:"ToolEvents::setObject",UPDATE_OBJECT:"ToolEvents::updateObject",CREATE_TEXTURE:"ToolEvents::createTexture",REQUEST_METHOD:"ToolEvents::requestMethod",ADD_CAMERA:"ToolEvents::addCamera",REMOVE_CAMERA:"ToolEvents::removeCamera"};class Ze{constructor(n){Z(this,"app");this.app=n}dispose(){}}class Kt extends Ze{selectDropdown(n,a){this.app.send({event:"selectComponent",target:"app",data:{dropdown:n,value:a}})}updateDropdown(n,a){this.app.send({event:"draggableListUpdate",target:"app",data:{dropdown:n,value:a}})}}function kn(t,n){switch(n.event){case"selectComponent":D.dispatchEvent({type:A.SELECT_DROPDOWN,value:n.data});break;case"draggableListUpdate":D.dispatchEvent({type:A.DRAG_UPDATE,value:n.data});break}}const Xt=()=>{},Ge=class Ge extends Ze{constructor(){super(...arguments);Z(this,"project");Z(this,"sheets",new Map);Z(this,"sheetObjects",new Map);Z(this,"sheetObjectCBs",new Map);Z(this,"sheetObjectUnsubscribe",new Map)}init(a,e){this.project=Se.getProject(a,e)}dispose(){this.project=void 0,this.sheets=new Map,this.sheetObjects=new Map,this.sheetObjectCBs=new Map,this.sheetObjectUnsubscribe=new Map}sheet(a){var r;if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}let e=this.sheets.get(a);return e!==void 0||(e=(r=this.project)==null?void 0:r.sheet(a),this.sheets.set(a,e)),e}clearSheetObjects(a){this.sheetObjects.forEach((e,r)=>{r.search(`${a}_`)>-1&&this.unsubscribe(e)})}sheetObject(a,e,r,s){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const d=this.sheet(a);if(d===void 0)return;const l=`${a}_${e}`;let f=this.sheetObjects.get(l);f!==void 0?f=d.object(e,{...r,...f.value},{reconfigure:!0}):f=d.object(e,r),this.sheetObjects.set(l,f),this.sheetObjectCBs.set(l,s!==void 0?s:Xt);const m=f.onValuesChange(b=>{if(this.app.editor){for(const x in b){const O=b[x];typeof O=="object"&&Ht(O)&&(b[x]={r:O.r,g:O.g,b:O.b,a:O.a})}this.app.send({event:"updateSheetObject",target:"app",data:{sheetObject:l,values:b}})}const C=this.sheetObjectCBs.get(l);C!==void 0&&C(b)});return this.sheetObjectUnsubscribe.set(l,m),f}unsubscribe(a){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const e=a.address.sheetId,r=a.address.objectKey,s=this.sheets.get(e);s==null||s.detachObject(r);const d=`${e}_${r}`,l=this.sheetObjectUnsubscribe.get(d);l!==void 0&&(this.sheetObjects.delete(d),this.sheetObjectCBs.delete(d),this.sheetObjectUnsubscribe.delete(d),l())}static getRafDriver(){return Ge.rafDriver||(Ge.rafDriver=Se.createRafDriver()),Ge.rafDriver}};Z(Ge,"rafDriver",null);let Re=Ge,xe;function Dn(t,n){t.components.forEach(a=>{if(a instanceof Re){let e;const r=a;switch(n.event){case"setSheet":e=r.sheets.get(n.data.sheet),e!==void 0&&(xe=e,Xe.setSelection([e]));break;case"setSheetObject":e=r.sheetObjects.get(`${n.data.sheet}_${n.data.key}`),e!==void 0&&Xe.setSelection([e]);break;case"updateSheetObject":e=r.sheetObjectCBs.get(n.data.sheetObject),e!==void 0&&e(n.data.values);break;case"updateTimeline":e=r.sheets.get(n.data.sheet),xe!==void 0&&(xe.sequence.position=n.data.position);break}}})}function An(t){if(t.editor){let n;t.components.forEach(s=>{s instanceof Re&&(n=s)}),Xe.ui.restore(),Xe.onSelectionChange(s=>{s.length<1||s.forEach(d=>{let l=d.address.sheetId,f="setSheet",m={};switch(d.type){case"Theatre_Sheet_PublicAPI":f="setSheet",m={sheet:d.address.sheetId},xe=n.sheets.get(d.address.sheetId);break;case"Theatre_SheetObject_PublicAPI":f="setSheetObject",l+=`_${d.address.objectKey}`,m={id:l,sheet:d.address.sheetId,key:d.address.objectKey};break}t.send({event:f,target:"app",data:m})})});let a=0;const e=()=>{if(Re.getRafDriver().tick(performance.now()),xe!==void 0&&a!==xe.sequence.position){a=xe.sequence.position;const s=xe;t.send({event:"updateTimeline",target:"app",data:{position:a,sheet:s.address.sheetId}})}},r=()=>{e(),requestAnimationFrame(r)};e(),r()}else Xe.ui.hide()}function In(t){if(t.name==="cameras")return"camera";if(t.name==="interactive")return"interactive";if(t.name==="lights")return"light";if(t.name==="ui")return"ui";if(t.name==="utils")return"utils";const n=t.type;return n.search("Helper")>-1?"icon_utils":n.search("Camera")>-1?"camera":n.search("Light")>-1?"light":"obj3D"}function Zt(t){const n={name:t.name,type:t.type,uuid:t.uuid,children:[]};return t.children.forEach(a=>{n.children.push(Zt(a))}),n}function Nn(t){const n={};for(const a in t){const e=t[a].value;n[a]={value:e},e===null?n[a].value={src:""}:e.isTexture&&(n[a].value={src:e.image.src})}return n}function Ln(t){switch(t){case"blendSrcAlpha":case"blendDstAlpha":case"blendEquationAlpha":case"clippingPlanes":case"shadowSide":case"precision":return!0}return!1}function Jt(t){const n={};for(const a in t){if(a.substring(0,1)==="_"||a.substring(0,2)==="is"||Ln(a))continue;const e=typeof t[a],r=t[a];switch(e){case"boolean":case"number":case"string":n[a]=r;break;case"object":if(r!==null)if(n[a]=r,r.isTexture)if(r instanceof u.Texture){const s=r.source.toJSON();n[a]={src:s.url}}else r instanceof u.CubeTexture&&(console.log("env map"),console.log(r.source.data),console.log(r.source.toJSON()),n[a]={src:""});else a==="uniforms"&&(n[a]=Nn(n[a]));else n[a]={src:""};break}}return n}function Rt(t){t.updateMatrix();const n={name:t.name,type:t.type,uuid:t.uuid,visible:t.visible,matrix:t.matrix.elements,animations:[],material:void 0,perspectiveCameraInfo:void 0,orthographicCameraInfo:void 0,lightInfo:void 0};t.animations.forEach(e=>{n.animations.push({name:e.name,duration:e.duration,blendMode:e.blendMode})});const a=t.type.toLowerCase();if(a.search("mesh")>-1){const e=t;if(Array.isArray(e.material)){const r=[];e.material.forEach(s=>{r.push(Jt(s))}),n.material=r}else n.material=Jt(e.material)}else a.search("camera")>-1?t.type==="PerspectiveCamera"?n.perspectiveCameraInfo={fov:t.fov,zoom:t.zoom,near:t.near,far:t.far,focus:t.focus,aspect:t.aspect,filmGauge:t.filmGauge,filmOffset:t.filmOffset}:t.type==="OrthographicCamera"&&(n.orthographicCameraInfo={zoom:t.zoom,near:t.near,far:t.far,left:t.left,right:t.right,top:t.top,bottom:t.bottom}):a.search("light")>-1&&(n.lightInfo={color:t.color,intensity:t.intensity,decay:t.decay,distance:t.distance,angle:t.angle,penumbra:t.penumbra,groundColor:t.groundColor});return n}function te(t,n,a){const e=n.split(".");switch(e.length){case 1:t[e[0]]=a;break;case 2:t[e[0]][e[1]]=a;break;case 3:t[e[0]][e[1]][e[2]]=a;break;case 4:t[e[0]][e[1]][e[2]][e[3]]=a;break;case 5:t[e[0]][e[1]][e[2]][e[3]][e[4]]=a;break}}function Pt(t){return new Promise((n,a)=>{const e=new Image;e.onload=()=>{const r=new u.Texture(e);r.wrapS=u.RepeatWrapping,r.wrapT=u.RepeatWrapping,r.needsUpdate=!0,n(r)},e.onerror=a,e.src=t})}class Qt extends Ze{constructor(){super(...arguments);Z(this,"scene")}getObject(a){this.app.send({event:"getObject",target:"app",data:a})}setObject(a){const e=Rt(a);this.app.send({event:"setObject",target:"editor",data:e})}requestMethod(a,e,r){this.app.send({event:"requestMethod",target:"app",data:{uuid:a,key:e,value:r}})}updateObject(a,e,r){this.app.send({event:"updateObject",target:"app",data:{uuid:a,key:e,value:r}})}createTexture(a,e,r){this.app.send({event:"createTexture",target:"app",data:{uuid:a,key:e,value:r}})}setScene(a){if(a===void 0)return;this.scene=a,Yt(),Tt(this.scene);const e=Zt(this.scene);this.app.send({event:"setScene",target:"editor",data:e})}addCamera(a){const e=Rt(a);this.app.send({event:"addCamera",target:"editor",data:e})}removeCamera(a){const e=Rt(a);this.app.send({event:"removeCamera",target:"editor",data:e})}}function Un(t,n){switch(n.event){case"getObject":D.dispatchEvent({type:A.GET_OBJECT,value:n.data});break;case"updateObject":D.dispatchEvent({type:A.UPDATE_OBJECT,value:n.data});break;case"createTexture":D.dispatchEvent({type:A.CREATE_TEXTURE,value:n.data});break;case"requestMethod":D.dispatchEvent({type:A.REQUEST_METHOD,value:n.data});break}}function Fn(t,n){switch(n.event){case"setObject":D.dispatchEvent({type:A.SET_OBJECT,value:n.data});break;case"setScene":D.dispatchEvent({type:A.SET_SCENE,value:n.data});break;case"addCamera":D.dispatchEvent({type:A.ADD_CAMERA,value:n.data});break;case"removeCamera":D.dispatchEvent({type:A.REMOVE_CAMERA,value:n.data});break}}class jt extends Ze{constructor(a){super(a);Z(this,"bindCBs");Z(this,"buttonCBs");Z(this,"pane");Z(this,"appCallbacks",0);Z(this,"editorCallbacks",0);Z(this,"inspectorFolder");this.bindCBs=new Map,this.buttonCBs=new Map,a.editor&&this.createGUI()}createGUI(){this.pane=new xn.Pane({title:"GUI"}),this.pane.registerPlugin(Mn)}dispose(){var a;this.bindCBs.clear(),this.buttonCBs.clear(),this.appCallbacks=0,this.editorCallbacks=0,this.app.editor&&((a=this.pane)==null||a.dispose(),this.pane=void 0)}addFolder(a,e=void 0,r=void 0){if(this.app.editor)return this.pane===void 0&&this.createGUI(),(r!==void 0?r:this.pane).addFolder({title:a,...e});this.app.send({event:"addFolder",target:"app",data:{name:a,params:e,parent:r}})}get bindID(){return`debug_${Math.max(this.appCallbacks,this.editorCallbacks)}`}bind(a,e,r,s=void 0){const d=this.bindID,l=r.onChange!==void 0?r.onChange:Xt;this.bindCBs.set(d,l),this.app.editor?(this.pane===void 0&&this.createGUI(),(s!==void 0?s:this.pane).addBinding(a,e,r).on("change",m=>{this.app.send({event:"updateBind",target:"app",data:{id:d,value:m.value}})}),this.editorCallbacks++):(this.app.send({event:"bindObject",target:"app",data:{id:d,name:e,params:r,parent:s}}),this.appCallbacks++)}triggerBind(a,e){const r=this.bindCBs.get(a);r!==void 0?r(e):console.warn(`No callback for: ${a}`,e)}button(a,e,r=void 0){const s=this.bindID;this.buttonCBs.set(s,e),this.app.editor?(this.pane===void 0&&this.createGUI(),(r!==void 0?r:this.pane).addButton({title:a}).on("click",()=>{this.app.send({event:"clickButton",target:"app",data:{id:s}})}),this.editorCallbacks++):(this.app.send({event:"addButton",target:"app",data:{id:s,name:a,callback:e,parent:r}}),this.appCallbacks++)}triggerButton(a){const e=this.buttonCBs.get(a);e!==void 0&&e()}createInspector(){this.inspectorFolder=this.addFolder("Inspector",this.pane)}clearInspector(){const a=this.inspectorFolder.children.length-1;for(let e=a;e>-1;--e)this.inspectorFolder.remove(this.inspectorFolder.children[e])}}function Vn(t,n){t.components.forEach(a=>{if(a instanceof jt){const e=a;switch(n.event){case"addFolder":e.addFolder(n.data.name,n.data.params,n.data.parent);break;case"bindObject":e.bind(n.data.name,n.data.params,n.data.parent);break;case"updateBind":e.triggerBind(n.data.id,n.data.value);break;case"addButton":e.button(n.data.name,n.data.callback,n.data.parent);break;case"clickButton":e.triggerButton(n.data.id);break}return}})}var _t={exports:{}},Je={};/**
|
1
|
+
(function(w,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("three"),require("@theatre/core"),require("@theatre/studio"),require("tweakpane"),require("@tweakpane/plugin-essentials"),require("react"),require("framer-motion")):typeof define=="function"&&define.amd?define(["exports","three","@theatre/core","@theatre/studio","tweakpane","@tweakpane/plugin-essentials","react","framer-motion"],u):(w=typeof globalThis<"u"?globalThis:w||self,u(w.Hermes={},w.Three,w["Theatre Core"],w["Theatre Studio"],w.tweakpane,w["tweakpane-plugin-essentials"],w.React,w["framer-motion"]))})(this,function(w,u,Se,Xe,xn,On,R,Bt){"use strict";var Ma=Object.defineProperty;var Ra=(w,u,Se)=>u in w?Ma(w,u,{enumerable:!0,configurable:!0,writable:!0,value:Se}):w[u]=Se;var Z=(w,u,Se)=>(Ra(w,typeof u!="symbol"?u+"":u,Se),Se);function Tn(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const e=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,e.get?e:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const Mn=Tn(On);function Rn(t,n,a){return Math.min(n,Math.max(t,a))}function Pn(t,n){const a=t-n;return Math.sqrt(a*a)}function Gt(){return Math.round(Math.random()*1e6).toString()}function Ht(t){return t.r!==void 0&&t.g!==void 0&&t.b!==void 0}function zt(t){const n=Math.round(t.r*255),a=Math.round(t.g*255),e=Math.round(t.b*255),r=f=>{const m=f.toString(16);return m.length===1?"0"+m:m},s=r(n),d=r(a),l=r(e);return"#"+s+d+l}function ct(t,n=1){return Number(t.toFixed(n))}w.totalThreeObjects=0;const Yt=()=>{w.totalThreeObjects=0},Tt=t=>{if(!t)return;let n=t.name.replace(" ","");n.length===0&&(n=`obj_${w.totalThreeObjects}`,w.totalThreeObjects++),t.parent!==null&&(n=`${t.parent.uuid}.${n}`),t.uuid=n,t.children.forEach(a=>{Tt(a)})},jn=t=>{t==null||t.dispose()},Wt=t=>{t&&(Array.isArray(t)?t.forEach(n=>n.dispose()):t.dispose())},Mt=t=>{var n;if(t){for(;t.children.length>0;){const a=t.children[0];a instanceof u.PositionalAudio?(a.pause(),a.parent&&a.parent.remove(a)):Mt(a)}if(t.parent&&t.parent.remove(t),t.isMesh){const a=t;(n=a.geometry)==null||n.dispose(),Wt(a.material)}t.dispose!==void 0&&t.dispose()}};class _n{constructor(n,a,e="editor"){Z(this,"channel");Z(this,"components",new Map);Z(this,"_mode","app");this.editor=a&&document.location.hash.search(e)>-1,a&&(this.channel=new BroadcastChannel(n))}addComponent(n,a){this.components.set(n,a)}dispose(){this.components.forEach(n=>{n.dispose()}),this.components.clear()}send(n){this.channel!==void 0&&this._mode!==n.target&&this.channel.postMessage(n)}listen(n){this.channel!==void 0&&(this.channel.onmessage=a=>{n(a.data)})}get mode(){return this._mode}get isApp(){return this._mode==="app"}get editor(){return this._mode==="editor"}set editor(n){n&&(this._mode="editor",document.title+=" - Editor")}}const D=new u.EventDispatcher,A={CUSTOM:"ToolEvents::custom",SELECT_DROPDOWN:"ToolEvents::selectDropdown",DRAG_UPDATE:"ToolEvents::dragUpdate",SET_SCENE:"ToolEvents::setScene",GET_OBJECT:"ToolEvents::getObject",SET_OBJECT:"ToolEvents::setObject",UPDATE_OBJECT:"ToolEvents::updateObject",CREATE_TEXTURE:"ToolEvents::createTexture",REQUEST_METHOD:"ToolEvents::requestMethod",ADD_CAMERA:"ToolEvents::addCamera",REMOVE_CAMERA:"ToolEvents::removeCamera"};class Ze{constructor(n){Z(this,"app");this.app=n}dispose(){}}class Kt extends Ze{selectDropdown(n,a){this.app.send({event:"selectComponent",target:"app",data:{dropdown:n,value:a}})}updateDropdown(n,a){this.app.send({event:"draggableListUpdate",target:"app",data:{dropdown:n,value:a}})}}function kn(t,n){switch(n.event){case"selectComponent":D.dispatchEvent({type:A.SELECT_DROPDOWN,value:n.data});break;case"draggableListUpdate":D.dispatchEvent({type:A.DRAG_UPDATE,value:n.data});break}}const Xt=()=>{},Ge=class Ge extends Ze{constructor(){super(...arguments);Z(this,"project");Z(this,"sheets",new Map);Z(this,"sheetObjects",new Map);Z(this,"sheetObjectCBs",new Map);Z(this,"sheetObjectUnsubscribe",new Map)}init(a,e){return this.project=Se.getProject(a,e),this.project.ready}dispose(){this.project=void 0,this.sheets=new Map,this.sheetObjects=new Map,this.sheetObjectCBs=new Map,this.sheetObjectUnsubscribe=new Map}sheet(a){var r;if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}let e=this.sheets.get(a);return e!==void 0||(e=(r=this.project)==null?void 0:r.sheet(a),this.sheets.set(a,e)),e}clearSheetObjects(a){this.sheetObjects.forEach((e,r)=>{r.search(`${a}_`)>-1&&this.unsubscribe(e)})}sheetObject(a,e,r,s){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const d=this.sheet(a);if(d===void 0)return;const l=`${a}_${e}`;let f=this.sheetObjects.get(l);f!==void 0?f=d.object(e,{...r,...f.value},{reconfigure:!0}):f=d.object(e,r),this.sheetObjects.set(l,f),this.sheetObjectCBs.set(l,s!==void 0?s:Xt);const m=f.onValuesChange(b=>{if(this.app.editor){for(const x in b){const O=b[x];typeof O=="object"&&Ht(O)&&(b[x]={r:O.r,g:O.g,b:O.b,a:O.a})}this.app.send({event:"updateSheetObject",target:"app",data:{sheetObject:l,values:b}})}const C=this.sheetObjectCBs.get(l);C!==void 0&&C(b)});return this.sheetObjectUnsubscribe.set(l,m),f}unsubscribe(a){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const e=a.address.sheetId,r=a.address.objectKey,s=this.sheets.get(e);s==null||s.detachObject(r);const d=`${e}_${r}`,l=this.sheetObjectUnsubscribe.get(d);l!==void 0&&(this.sheetObjects.delete(d),this.sheetObjectCBs.delete(d),this.sheetObjectUnsubscribe.delete(d),l())}static getRafDriver(){return Ge.rafDriver||(Ge.rafDriver=Se.createRafDriver()),Ge.rafDriver}};Z(Ge,"rafDriver",null);let Re=Ge,xe;function Dn(t,n){t.components.forEach(a=>{if(a instanceof Re){let e;const r=a;switch(n.event){case"setSheet":e=r.sheets.get(n.data.sheet),e!==void 0&&(xe=e,Xe.setSelection([e]));break;case"setSheetObject":e=r.sheetObjects.get(`${n.data.sheet}_${n.data.key}`),e!==void 0&&Xe.setSelection([e]);break;case"updateSheetObject":e=r.sheetObjectCBs.get(n.data.sheetObject),e!==void 0&&e(n.data.values);break;case"updateTimeline":e=r.sheets.get(n.data.sheet),xe!==void 0&&(xe.sequence.position=n.data.position);break}}})}function An(t){if(t.editor){let n;t.components.forEach(s=>{s instanceof Re&&(n=s)}),Xe.ui.restore(),Xe.onSelectionChange(s=>{s.length<1||s.forEach(d=>{let l=d.address.sheetId,f="setSheet",m={};switch(d.type){case"Theatre_Sheet_PublicAPI":f="setSheet",m={sheet:d.address.sheetId},xe=n.sheets.get(d.address.sheetId);break;case"Theatre_SheetObject_PublicAPI":f="setSheetObject",l+=`_${d.address.objectKey}`,m={id:l,sheet:d.address.sheetId,key:d.address.objectKey};break}t.send({event:f,target:"app",data:m})})});let a=0;const e=()=>{if(Re.getRafDriver().tick(performance.now()),xe!==void 0&&a!==xe.sequence.position){a=xe.sequence.position;const s=xe;t.send({event:"updateTimeline",target:"app",data:{position:a,sheet:s.address.sheetId}})}},r=()=>{e(),requestAnimationFrame(r)};e(),r()}else Xe.ui.hide()}function In(t){if(t.name==="cameras")return"camera";if(t.name==="interactive")return"interactive";if(t.name==="lights")return"light";if(t.name==="ui")return"ui";if(t.name==="utils")return"utils";const n=t.type;return n.search("Helper")>-1?"icon_utils":n.search("Camera")>-1?"camera":n.search("Light")>-1?"light":"obj3D"}function Zt(t){const n={name:t.name,type:t.type,uuid:t.uuid,children:[]};return t.children.forEach(a=>{n.children.push(Zt(a))}),n}function Nn(t){const n={};for(const a in t){const e=t[a].value;n[a]={value:e},e===null?n[a].value={src:""}:e.isTexture&&(n[a].value={src:e.image.src})}return n}function Ln(t){switch(t){case"blendSrcAlpha":case"blendDstAlpha":case"blendEquationAlpha":case"clippingPlanes":case"shadowSide":case"precision":return!0}return!1}function Jt(t){const n={};for(const a in t){if(a.substring(0,1)==="_"||a.substring(0,2)==="is"||Ln(a))continue;const e=typeof t[a],r=t[a];switch(e){case"boolean":case"number":case"string":n[a]=r;break;case"object":if(r!==null)if(n[a]=r,r.isTexture)if(r instanceof u.Texture){const s=r.source.toJSON();n[a]={src:s.url}}else r instanceof u.CubeTexture&&(console.log("env map"),console.log(r.source.data),console.log(r.source.toJSON()),n[a]={src:""});else a==="uniforms"&&(n[a]=Nn(n[a]));else n[a]={src:""};break}}return n}function Rt(t){t.updateMatrix();const n={name:t.name,type:t.type,uuid:t.uuid,visible:t.visible,matrix:t.matrix.elements,animations:[],material:void 0,perspectiveCameraInfo:void 0,orthographicCameraInfo:void 0,lightInfo:void 0};t.animations.forEach(e=>{n.animations.push({name:e.name,duration:e.duration,blendMode:e.blendMode})});const a=t.type.toLowerCase();if(a.search("mesh")>-1){const e=t;if(Array.isArray(e.material)){const r=[];e.material.forEach(s=>{r.push(Jt(s))}),n.material=r}else n.material=Jt(e.material)}else a.search("camera")>-1?t.type==="PerspectiveCamera"?n.perspectiveCameraInfo={fov:t.fov,zoom:t.zoom,near:t.near,far:t.far,focus:t.focus,aspect:t.aspect,filmGauge:t.filmGauge,filmOffset:t.filmOffset}:t.type==="OrthographicCamera"&&(n.orthographicCameraInfo={zoom:t.zoom,near:t.near,far:t.far,left:t.left,right:t.right,top:t.top,bottom:t.bottom}):a.search("light")>-1&&(n.lightInfo={color:t.color,intensity:t.intensity,decay:t.decay,distance:t.distance,angle:t.angle,penumbra:t.penumbra,groundColor:t.groundColor});return n}function te(t,n,a){const e=n.split(".");switch(e.length){case 1:t[e[0]]=a;break;case 2:t[e[0]][e[1]]=a;break;case 3:t[e[0]][e[1]][e[2]]=a;break;case 4:t[e[0]][e[1]][e[2]][e[3]]=a;break;case 5:t[e[0]][e[1]][e[2]][e[3]][e[4]]=a;break}}function Pt(t){return new Promise((n,a)=>{const e=new Image;e.onload=()=>{const r=new u.Texture(e);r.wrapS=u.RepeatWrapping,r.wrapT=u.RepeatWrapping,r.needsUpdate=!0,n(r)},e.onerror=a,e.src=t})}class Qt extends Ze{constructor(){super(...arguments);Z(this,"scene")}getObject(a){this.app.send({event:"getObject",target:"app",data:a})}setObject(a){const e=Rt(a);this.app.send({event:"setObject",target:"editor",data:e})}requestMethod(a,e,r){this.app.send({event:"requestMethod",target:"app",data:{uuid:a,key:e,value:r}})}updateObject(a,e,r){this.app.send({event:"updateObject",target:"app",data:{uuid:a,key:e,value:r}})}createTexture(a,e,r){this.app.send({event:"createTexture",target:"app",data:{uuid:a,key:e,value:r}})}setScene(a){if(a===void 0)return;this.scene=a,Yt(),Tt(this.scene);const e=Zt(this.scene);this.app.send({event:"setScene",target:"editor",data:e})}addCamera(a){const e=Rt(a);this.app.send({event:"addCamera",target:"editor",data:e})}removeCamera(a){const e=Rt(a);this.app.send({event:"removeCamera",target:"editor",data:e})}}function Un(t,n){switch(n.event){case"getObject":D.dispatchEvent({type:A.GET_OBJECT,value:n.data});break;case"updateObject":D.dispatchEvent({type:A.UPDATE_OBJECT,value:n.data});break;case"createTexture":D.dispatchEvent({type:A.CREATE_TEXTURE,value:n.data});break;case"requestMethod":D.dispatchEvent({type:A.REQUEST_METHOD,value:n.data});break}}function Fn(t,n){switch(n.event){case"setObject":D.dispatchEvent({type:A.SET_OBJECT,value:n.data});break;case"setScene":D.dispatchEvent({type:A.SET_SCENE,value:n.data});break;case"addCamera":D.dispatchEvent({type:A.ADD_CAMERA,value:n.data});break;case"removeCamera":D.dispatchEvent({type:A.REMOVE_CAMERA,value:n.data});break}}class jt extends Ze{constructor(a){super(a);Z(this,"bindCBs");Z(this,"buttonCBs");Z(this,"pane");Z(this,"appCallbacks",0);Z(this,"editorCallbacks",0);Z(this,"inspectorFolder");this.bindCBs=new Map,this.buttonCBs=new Map,a.editor&&this.createGUI()}createGUI(){this.pane=new xn.Pane({title:"GUI"}),this.pane.registerPlugin(Mn)}dispose(){var a;this.bindCBs.clear(),this.buttonCBs.clear(),this.appCallbacks=0,this.editorCallbacks=0,this.app.editor&&((a=this.pane)==null||a.dispose(),this.pane=void 0)}addFolder(a,e=void 0,r=void 0){if(this.app.editor)return this.pane===void 0&&this.createGUI(),(r!==void 0?r:this.pane).addFolder({title:a,...e});this.app.send({event:"addFolder",target:"app",data:{name:a,params:e,parent:r}})}get bindID(){return`debug_${Math.max(this.appCallbacks,this.editorCallbacks)}`}bind(a,e,r,s=void 0){const d=this.bindID,l=r.onChange!==void 0?r.onChange:Xt;this.bindCBs.set(d,l),this.app.editor?(this.pane===void 0&&this.createGUI(),(s!==void 0?s:this.pane).addBinding(a,e,r).on("change",m=>{this.app.send({event:"updateBind",target:"app",data:{id:d,value:m.value}})}),this.editorCallbacks++):(this.app.send({event:"bindObject",target:"app",data:{id:d,name:e,params:r,parent:s}}),this.appCallbacks++)}triggerBind(a,e){const r=this.bindCBs.get(a);r!==void 0?r(e):console.warn(`No callback for: ${a}`,e)}button(a,e,r=void 0){const s=this.bindID;this.buttonCBs.set(s,e),this.app.editor?(this.pane===void 0&&this.createGUI(),(r!==void 0?r:this.pane).addButton({title:a}).on("click",()=>{this.app.send({event:"clickButton",target:"app",data:{id:s}})}),this.editorCallbacks++):(this.app.send({event:"addButton",target:"app",data:{id:s,name:a,callback:e,parent:r}}),this.appCallbacks++)}triggerButton(a){const e=this.buttonCBs.get(a);e!==void 0&&e()}createInspector(){this.inspectorFolder=this.addFolder("Inspector",this.pane)}clearInspector(){const a=this.inspectorFolder.children.length-1;for(let e=a;e>-1;--e)this.inspectorFolder.remove(this.inspectorFolder.children[e])}}function Vn(t,n){t.components.forEach(a=>{if(a instanceof jt){const e=a;switch(n.event){case"addFolder":e.addFolder(n.data.name,n.data.params,n.data.parent);break;case"bindObject":e.bind(n.data.name,n.data.params,n.data.parent);break;case"updateBind":e.triggerBind(n.data.id,n.data.value);break;case"addButton":e.button(n.data.name,n.data.callback,n.data.parent);break;case"clickButton":e.triggerButton(n.data.id);break}return}})}var _t={exports:{}},Je={};/**
|
2
2
|
* @license React
|
3
3
|
* react-jsx-runtime.production.min.js
|
4
4
|
*
|
package/package.json
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
"module": "./dist/hermes.js",
|
8
8
|
"types": "./types/index.d.ts",
|
9
9
|
"type": "module",
|
10
|
-
"version": "0.0.
|
10
|
+
"version": "0.0.21",
|
11
11
|
"homepage": "https://github.com/tomorrowevening/hermes#readme",
|
12
12
|
"bugs": {
|
13
13
|
"url": "https://github.com/tomorrowevening/hermes/issues"
|
@@ -18,8 +18,9 @@ export default class RemoteTheatre extends BaseRemote {
|
|
18
18
|
|
19
19
|
private static rafDriver: IRafDriver | null = null;
|
20
20
|
|
21
|
-
init(projectName: string, projectConfig?: IProjectConfig | undefined) {
|
21
|
+
init(projectName: string, projectConfig?: IProjectConfig | undefined): Promise<void> {
|
22
22
|
this.project = getProject(projectName, projectConfig);
|
23
|
+
return this.project.ready;
|
23
24
|
}
|
24
25
|
|
25
26
|
override dispose(): void {
|
@@ -10,7 +10,7 @@ export default class RemoteTheatre extends BaseRemote {
|
|
10
10
|
sheetObjectCBs: Map<string, DataUpdateCallback>;
|
11
11
|
sheetObjectUnsubscribe: Map<string, VoidCallback>;
|
12
12
|
private static rafDriver;
|
13
|
-
init(projectName: string, projectConfig?: IProjectConfig | undefined): void
|
13
|
+
init(projectName: string, projectConfig?: IProjectConfig | undefined): Promise<void>;
|
14
14
|
dispose(): void;
|
15
15
|
sheet(name: string): ISheet | undefined;
|
16
16
|
clearSheetObjects(sheetName: string): void;
|