@soonspacejs/plugin-flow 2.13.6 → 2.13.7

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.
Files changed (60) hide show
  1. package/README.md +4 -4
  2. package/dist/index.esm.js +1881 -1
  3. package/dist/index.esm.js.map +1 -0
  4. package/package.json +3 -3
  5. package/test/test.ts +118 -118
  6. package/dist/flows/ComponentFlowParser.d.ts +0 -8
  7. package/dist/flows/FlowParser.d.ts +0 -46
  8. package/dist/flows/edges/index.d.ts +0 -9
  9. package/dist/flows/index.d.ts +0 -4
  10. package/dist/flows/nodes/ColorNode.d.ts +0 -8
  11. package/dist/flows/nodes/ConditionNode.d.ts +0 -9
  12. package/dist/flows/nodes/DataExtractionNode.d.ts +0 -8
  13. package/dist/flows/nodes/DataFilterNode.d.ts +0 -8
  14. package/dist/flows/nodes/DelayNode.d.ts +0 -8
  15. package/dist/flows/nodes/EmissiveNode.d.ts +0 -10
  16. package/dist/flows/nodes/FlyToNode.d.ts +0 -8
  17. package/dist/flows/nodes/HideNode.d.ts +0 -10
  18. package/dist/flows/nodes/HighlightNode.d.ts +0 -10
  19. package/dist/flows/nodes/MeshNode.d.ts +0 -8
  20. package/dist/flows/nodes/MeshesNode.d.ts +0 -8
  21. package/dist/flows/nodes/ModelNode.d.ts +0 -8
  22. package/dist/flows/nodes/ModelsNode.d.ts +0 -8
  23. package/dist/flows/nodes/Node.d.ts +0 -48
  24. package/dist/flows/nodes/NumberNode.d.ts +0 -8
  25. package/dist/flows/nodes/OpacityNode.d.ts +0 -10
  26. package/dist/flows/nodes/POINode.d.ts +0 -8
  27. package/dist/flows/nodes/POISNode.d.ts +0 -8
  28. package/dist/flows/nodes/PathNode.d.ts +0 -8
  29. package/dist/flows/nodes/PathsNode.d.ts +0 -8
  30. package/dist/flows/nodes/RotateNode.d.ts +0 -8
  31. package/dist/flows/nodes/ScaleNode.d.ts +0 -8
  32. package/dist/flows/nodes/ShowNode.d.ts +0 -10
  33. package/dist/flows/nodes/SpaceNode.d.ts +0 -8
  34. package/dist/flows/nodes/SpacesNode.d.ts +0 -8
  35. package/dist/flows/nodes/StartNode.d.ts +0 -7
  36. package/dist/flows/nodes/TranslateNode.d.ts +0 -8
  37. package/dist/flows/nodes/UnEmissiveNode.d.ts +0 -10
  38. package/dist/flows/nodes/UnHighlightNode.d.ts +0 -10
  39. package/dist/flows/nodes/UnOpacityNode.d.ts +0 -10
  40. package/dist/flows/nodes/clip-animation/ClipAnimationNode.d.ts +0 -8
  41. package/dist/flows/nodes/clip-animation/UnClipAnimationNode.d.ts +0 -8
  42. package/dist/flows/nodes/clip-animation/index.d.ts +0 -2
  43. package/dist/flows/nodes/component-tween-animation/ComponentTweenAnimationNode.d.ts +0 -8
  44. package/dist/flows/nodes/component-tween-animation/UnComponentTweenAnimationNode.d.ts +0 -8
  45. package/dist/flows/nodes/component-tween-animation/index.d.ts +0 -2
  46. package/dist/flows/nodes/component-tween-animation/utils.d.ts +0 -5
  47. package/dist/flows/nodes/index.d.ts +0 -33
  48. package/dist/flows/nodes/tween-animation/TweenAnimationNode.d.ts +0 -8
  49. package/dist/flows/nodes/tween-animation/UnTweenAnimationNode.d.ts +0 -8
  50. package/dist/flows/nodes/tween-animation/index.d.ts +0 -2
  51. package/dist/flows/nodes/tween-animation/utils.d.ts +0 -5
  52. package/dist/flows/types.d.ts +0 -106
  53. package/dist/flows/utils.d.ts +0 -12
  54. package/dist/index.d.ts +0 -3
  55. package/dist/triggers/ComponentTrigger.d.ts +0 -18
  56. package/dist/triggers/Trigger.d.ts +0 -27
  57. package/dist/triggers/index.d.ts +0 -3
  58. package/dist/triggers/types.d.ts +0 -54
  59. package/dist/triggers/utils.d.ts +0 -2
  60. package/dist/types.d.ts +0 -16
package/dist/index.esm.js CHANGED
@@ -1 +1,1881 @@
1
- import{Vector3 as t,Euler as s,EventDispatcher as e,FileLoader as i,ImageLoader as n,TextureLoader as o}from"three";import a from"soonspacejs";import{AnimationPlayer as r}from"umanager-animation-parser";import{FlowParser as c,InteractionAction as l,InteractionType as h,InteractionObsType as d}from"@soonspacejs/plugin-flow";import{RGBELoader as u}from"three/examples/jsm/loaders/RGBELoader.js";import"three/examples/jsm/exporters/GLTFExporter.js";class p{constructor(t){this.id=t.id,this.source=t.source,this.target=t.target,this.sourceHandle=t.sourceHandle}}var f,C;!function(t){t.LOCAL="LOCAL",t.READ_CTX="READ_CTX",t.WRITE_CTX="WRITE_CTX"}(f||(f={})),function(t){t.START="START",t.COLOR="COLOR",t.NUMBER="NUMBER",t.HIGHLIGHT="HIGHLIGHT",t.UN_HIGHLIGHT="UN_HIGHLIGHT",t.OPACITY="OPACITY",t.UN_OPACITY="UN_OPACITY",t.EMISSIVE="EMISSIVE",t.UN_EMISSIVE="UN_EMISSIVE",t.MESH="MESH",t.MESHES="MESHES",t.MODEL="MODEL",t.MODELS="MODELS",t.SHOW="SHOW",t.HIDE="HIDE",t.CLIP_ANIMATION="CLIP_ANIMATION",t.UN_CLIP_ANIMATION="UN_CLIP_ANIMATION",t.TWEEN_ANIMATION="TWEEN_ANIMATION",t.UN_TWEEN_ANIMATION="UN_TWEEN_ANIMATION",t.COMPONENT_TWEEN_ANIMATION="COMPONENT_TWEEN_ANIMATION",t.UN_COMPONENT_TWEEN_ANIMATION="UN_COMPONENT_TWEEN_ANIMATION",t.SPACE="SPACE",t.SPACES="SPACES",t.PATH="PATH",t.PATHS="PATHS",t.POI="POI",t.POIS="POIS",t.FLY_TO="FLY_TO",t.TRANSLATE="TRANSLATE",t.ROTATE="ROTATE",t.SCALE="SCALE",t.DATA_FILTER="DATA_FILTER",t.DATA_EXTRACTION="DATA_EXTRACTION",t.CONDITION_NODE="CONDITION_NODE",t.DELAY="DELAY"}(C||(C={}));let T=0;class E{constructor(t,s){this.prevNodes=[],this.postNodes=[],this.execOrder=0,this.cleanSets=new Set,this.onBefore=null,this.onAfter=null,this.parser=t,this.ssp=t.ssp,this.id=s.id,this.type=s.type,this.props=s.props,this.rejected=!1,this.init()}init(){this.ctx={},this.promise=new Promise(((t,s)=>{this.resolve=t,this.reject=()=>{this.rejected=!0,s()}}))}readContext(t){return this.ctx[t]}writeContext(t,s){this.ctx[t]=s}findProp(t,s){if(!(s instanceof Array))return this.props.find((e=>e.name===t&&e.type===s));for(const e of s){const s=this.findProp(t,e);if(s)return s}}async waitForPrevNodes(){return await Promise.all(this.prevNodes.map((t=>t.promise)))}mergeContext(){this.prevNodes.forEach((t=>{Object.assign(this.ctx,t.ctx)}))}async exec(t){}async run(t){var s,e,i,n;try{if(await this.waitForPrevNodes(),this.rejected)throw new Error;this.mergeContext(),await(null===(e=null!==(s=this.onBefore)&&void 0!==s?s:this.parser.onNodeBefore)||void 0===e?void 0:e(this));try{this.execOrder=++T,await this.exec(t)}catch(t){throw this.reject(t),t}await(null===(n=null!==(i=this.onAfter)&&void 0!==i?i:this.parser.onNodeAfter)||void 0===n?void 0:n(this)),this.resolve()}catch(t){this.reject()}}cleanup(){this.cleanSets.forEach((t=>t())),this.cleanSets.clear()}getValue(t,s){if(t.type===f.READ_CTX)return this.readContext(Tt(t.value));if(t.type===f.LOCAL){const{viewport:{scene:e}}=this.ssp;return"objects"===t.name||"models"===t.name||"meshs"===t.name?Tt(t.value).map((t=>At(this.ssp,t,null!=s?s:e))):"object"===t.name||"model"===t.name||"mesh"===t.name?At(this.ssp,Tt(t.value),null!=s?s:e):Tt(t.value)}}}class A extends E{constructor(t,s){super(t,s)}}class g extends E{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("color",f.LOCAL),s=this.findProp("out",f.WRITE_CTX);t&&s&&this.writeContext(Tt(s.value),Tt(t.value))}}class O extends E{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("number",f.LOCAL),s=this.findProp("out",f.WRITE_CTX);t&&s&&this.writeContext(Tt(s.value),Tt(t.value))}}const{objectHandle:v}=a.utils;class L extends E{constructor(t,s){super(t,s)}filterHighlightObject(t){const s=[];return v(t,(t=>{this.ssp.viewport.scener.selectedObjects.highlight.has(t)||s.push(t)})),s}async exec(t){var s;const e=this.findProp("objects",[f.READ_CTX,f.LOCAL]),i=this.findProp("color",[f.READ_CTX,f.LOCAL]),n=this.findProp("opacity",[f.READ_CTX,f.LOCAL]),o=await(null===(s=t.getTarget)||void 0===s?void 0:s.call(t,this));if(e&&i&&n){const t=this.getValue(e,o),s=this.getValue(i),a=this.getValue(n);if(t){const e=this.filterHighlightObject(t);this.ssp.highlightShow(e,{color:s,opacity:a}),this.cleanSets.add((()=>{this.ssp.unHighlightShow(e)}))}}}}const{objectHandle:w}=a.utils;class I extends E{constructor(t,s){super(t,s)}filterUnHighlightObject(t){const s=[];return w(t,(t=>{this.ssp.viewport.scener.selectedObjects.highlight.has(t)&&s.push(t)})),s}async exec(t){var s;const e=this.findProp("objects",[f.READ_CTX,f.LOCAL]),i=await(null===(s=t.getTarget)||void 0===s?void 0:s.call(t,this));if(e){const t=this.getValue(e,i);if(t){const s=this.filterUnHighlightObject(t);this.ssp.unHighlightShow(s),this.cleanSets.add((()=>{this.ssp.highlightShow(s)}))}}}}const{objectHandle:y}=a.utils;class N extends E{constructor(t,s){super(t,s)}filterOpacityObject(t){const s=[];return y(t,(t=>{this.ssp.viewport.scener.selectedObjects.opacity.has(t)||s.push(t)})),s}async exec(t){var s;const e=this.findProp("objects",[f.READ_CTX,f.LOCAL]),i=this.findProp("color",[f.READ_CTX,f.LOCAL]),n=this.findProp("opacity",[f.READ_CTX,f.LOCAL]),o=await(null===(s=t.getTarget)||void 0===s?void 0:s.call(t,this));if(e&&i&&n){const t=this.getValue(e,o),s=this.getValue(i),a=this.getValue(n);if(t){const e=this.filterOpacityObject(t);this.ssp.opacityShow(e,{color:s,opacity:a}),this.cleanSets.add((()=>{this.ssp.unOpacityShow(e)}))}}}}const{objectHandle:P}=a.utils;class x extends E{constructor(t,s){super(t,s)}filterUnOpacityObject(t){const s=[];return P(t,(t=>{this.ssp.viewport.scener.selectedObjects.opacity.has(t)&&s.push(t)})),s}async exec(t){var s;const e=this.findProp("objects",[f.READ_CTX,f.LOCAL]),i=await(null===(s=t.getTarget)||void 0===s?void 0:s.call(t,this));if(e){const t=this.getValue(e,i);if(t){const s=this.filterUnOpacityObject(t);this.ssp.unOpacityShow(s),this.cleanSets.add((()=>{this.ssp.opacityShow(s)}))}}}}const{objectHandle:m}=a.utils;class _ extends E{constructor(t,s){super(t,s)}filterEmissiveObject(t){const s=[];return m(t,(t=>{this.ssp.viewport.scener.selectedObjects.emissive.has(t)||s.push(t)})),s}async exec(t){var s;const e=this.findProp("objects",[f.READ_CTX,f.LOCAL]),i=this.findProp("color",[f.READ_CTX,f.LOCAL]),n=this.findProp("baseColor",[f.READ_CTX,f.LOCAL]),o=this.findProp("minOpacity",[f.READ_CTX,f.LOCAL]),a=this.findProp("maxOpacity",[f.READ_CTX,f.LOCAL]),r=this.findProp("duration",[f.READ_CTX,f.LOCAL]),c=await(null===(s=t.getTarget)||void 0===s?void 0:s.call(t,this));if(e&&i&&n&&o&&a&&r){const t=this.getValue(e,c),s=this.getValue(i),l=this.getValue(n),h=this.getValue(o),d=this.getValue(a),u=this.getValue(r);if(t){const e=this.filterEmissiveObject(t);this.ssp.emissiveShow(e,{color:s,baseColor:l,minOpacity:h,maxOpacity:d,duration:u}),this.cleanSets.add((()=>{this.ssp.unEmissiveShow(e)}))}}}}const{objectHandle:b}=a.utils;class S extends E{constructor(t,s){super(t,s)}filterUnEmissiveObject(t){const s=[];return b(t,(t=>{this.ssp.viewport.scener.selectedObjects.emissive.has(t)&&s.push(t)})),s}async exec(t){var s;const e=this.findProp("objects",[f.READ_CTX,f.LOCAL]),i=await(null===(s=t.getTarget)||void 0===s?void 0:s.call(t,this));if(e){const t=this.getValue(e,i);if(t){const s=this.filterUnEmissiveObject(t);this.ssp.unEmissiveShow(s),this.cleanSets.add((()=>{this.ssp.emissiveShow(s)}))}}}}const M=Symbol("meshCache");class R extends E{constructor(t,s){super(t,s)}async exec(t){var s;const{viewport:{scene:e}}=this.ssp,i=await(null===(s=t.getTarget)||void 0===s?void 0:s.call(t,this))||e;t[M]||(t[M]={});const n=this.findProp("mesh",f.LOCAL),o=this.findProp("out",f.WRITE_CTX);if(n&&o){let s=null;const e=Tt(n.value),a=Tt(o.value),r=t[M][e];if(r)return void(s=r);const c=gt(i,e);c&&(s=c,t[M][e]=c),this.writeContext(a,s)}}}const D=Symbol("meshesCache");class H extends E{constructor(t,s){super(t,s)}async exec(t){var s;const{viewport:{scene:e}}=this.ssp,i=await(null===(s=t.getTarget)||void 0===s?void 0:s.call(t,this))||e;t[D]||(t[D]={});const n=this.findProp("meshes",f.LOCAL),o=this.findProp("out",f.WRITE_CTX);if(n&&o){const s=[],e=Tt(n.value),a=Tt(o.value);e.forEach((e=>{const n=t[D][e];if(n)return void s.push(n);const o=gt(i,e);o&&(s.push(o),t[D][e]=o)})),this.writeContext(a,s)}}}class j extends E{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("model",f.LOCAL),s=this.findProp("out",f.WRITE_CTX);if(t&&s){const e=Tt(t.value),i=Tt(s.value);this.writeContext(i,At(this.ssp,e))}}}class X extends E{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("models",f.LOCAL),s=this.findProp("out",f.WRITE_CTX);if(t&&s){const i=Tt(t.value),n=Tt(s.value);this.writeContext(n,(e=this.ssp,i.map((t=>e.getObjectById(t))).filter(Boolean)))}var e}}class B extends E{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("delay",f.LOCAL);if(t){const s=Tt(t.value);await a.utils.sleep(s)}}}class k extends E{constructor(t,s){super(t,s)}execFn(t){return new Function("sourceData",t)(this.ctx)}async exec(){const t=this.findProp("conditaion_node",f.LOCAL);if(t){const s=Tt(t.value),e=this.parser.edges.filter((t=>t.source===this.id));s.forEach((t=>{try{if(!0!==this.execFn(t.value))throw new Error}catch(s){const i=e.find((s=>s.sourceHandle==String(t.id)));if(!i)return;const n=this.postNodes.find((t=>t.id===i.target));null==n||n.reject()}}))}}}const{objectHandle:V}=a.utils;class G extends E{constructor(t,s){super(t,s)}filterShowObject(t){const s=[];return V(t,(t=>{!1===t.visible&&s.push(t)})),s}async exec(t){var s;const e=this.findProp("objects",[f.READ_CTX,f.LOCAL]),i=await(null===(s=t.getTarget)||void 0===s?void 0:s.call(t,this));if(e){const t=this.getValue(e,i);if(t){const s=this.filterShowObject(t),e=t=>{V(s,(s=>{s.visible=t})),this.ssp.render()};e(!0),this.cleanSets.add((()=>e(!1)))}}}}const{objectHandle:U}=a.utils;class W extends E{constructor(t,s){super(t,s)}filterHideObject(t){const s=[];return U(t,(t=>{!0===t.visible&&s.push(t)})),s}async exec(t){var s;const e=this.findProp("objects",[f.READ_CTX,f.LOCAL]),i=await(null===(s=t.getTarget)||void 0===s?void 0:s.call(t,this));if(e){const t=this.getValue(e,i);if(t){const s=this.filterHideObject(t),e=t=>{U(s,(s=>{s.visible=t})),this.ssp.render()};e(!1),this.cleanSets.add((()=>e(!0)))}}}}const{objectHandle:F}=a.utils;class z extends E{constructor(t,s){super(t,s)}async exec(s){var e;const i=this.findProp("objects",[f.READ_CTX,f.LOCAL]),n=this.findProp("axis",[f.READ_CTX,f.LOCAL]),o=this.findProp("translate",[f.READ_CTX,f.LOCAL]),a=await(null===(e=s.getTarget)||void 0===e?void 0:e.call(s,this));if(i&&n&&o){const s=this.getValue(i,a),e=this.getValue(n),r=this.getValue(o);if(s){const i=[],n=800;F(s,(t=>{i.push(t.position.clone())}));const o=(t,s)=>{switch(e){case"x":t.setX(s.x);break;case"y":t.setY(s.y);break;case"z":t.setZ(s.z)}},a=async()=>{const i=F(s,(async s=>{const i=s.position.clone();switch(e){case"x":await this.ssp.animation(i,(new t).set(i.x+r,i.y,i.z),{duration:n},(t=>o(s.position,t)));break;case"y":await this.ssp.animation(i,(new t).set(i.x,i.y+r,i.z),{duration:n},(t=>o(s.position,t)));break;case"z":await this.ssp.animation(i,(new t).set(i.x,i.y,i.z+r),{duration:n},(t=>o(s.position,t)))}}));i instanceof Array?await Promise.all(i):await i,this.ssp.render()};await a(),this.cleanSets.add((()=>{let t=0;F(s,(s=>{s.position.copy(i[t++])}))}))}}}}const{objectHandle:Y}=a.utils;class K extends E{constructor(t,s){super(t,s)}async exec(s){var e;const i=this.findProp("objects",[f.READ_CTX,f.LOCAL]),n=this.findProp("axis",[f.READ_CTX,f.LOCAL]),o=this.findProp("scale",[f.READ_CTX,f.LOCAL]),a=await(null===(e=s.getTarget)||void 0===e?void 0:e.call(s,this));if(i&&n&&o){const s=this.getValue(i,a),e=this.getValue(n),r=this.getValue(o);if(s){const i=[],n=800;Y(s,(t=>{i.push(t.scale.clone())}));const o=(t,s)=>{switch(e){case"x":t.setX(s.x);break;case"y":t.setY(s.y);break;case"z":t.setZ(s.z)}},a=async()=>{const i=Y(s,(async s=>{const i=s.scale.clone();switch(e){case"x":await this.ssp.animation(i,(new t).set(i.x*r,i.y,i.z),{duration:n},(t=>o(s.scale,t)));break;case"y":await this.ssp.animation(i,(new t).set(i.x,i.y*r,i.z),{duration:n},(t=>o(s.scale,t)));break;case"z":await this.ssp.animation(i,(new t).set(i.x,i.y,i.z*r),{duration:n},(t=>o(s.scale,t)))}}));i instanceof Array?await Promise.all(i):await i,this.ssp.render()};await a(),this.cleanSets.add((()=>{let t=0;Y(s,(s=>{s.scale.copy(i[t++])}))}))}}}}const{objectHandle:q}=a.utils;class J extends E{constructor(t,s){super(t,s)}async exec(t){var e;const i=this.findProp("objects",[f.READ_CTX,f.LOCAL]),n=this.findProp("axis",[f.READ_CTX,f.LOCAL]),o=this.findProp("rotation",[f.READ_CTX,f.LOCAL]),a=await(null===(e=t.getTarget)||void 0===e?void 0:e.call(t,this));if(i&&n&&o){const t=this.getValue(i,a),e=this.getValue(n),r=this.getValue(o);if(t){const i=[],n=800;q(t,(t=>{i.push(t.rotation.clone())}));const o=(t,s)=>{switch(e){case"x":t.x=s.x;break;case"y":t.y=s.y;break;case"z":t.z=s.z}},a=async()=>{const i=r/180*Math.PI,a=q(t,(async t=>{const a=t.rotation.clone();switch(e){case"x":await this.ssp.animation(a,(new s).set(a.x+i,a.y,a.z),{duration:n},(s=>o(t.rotation,s)));break;case"y":await this.ssp.animation(a,(new s).set(a.x,a.y+i,a.z),{duration:n},(s=>o(t.rotation,s)));break;case"z":await this.ssp.animation(a,(new s).set(a.x,a.y,a.z+i),{duration:n},(s=>o(t.rotation,s)))}}));a instanceof Array?await Promise.all(a):await a,this.ssp.render()};await a(),this.cleanSets.add((()=>{let s=0;q(t,(t=>{t.rotation.copy(i[s++])}))}))}}}}class Z extends E{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("viewpoint",[f.READ_CTX,f.LOCAL]);if(t){const s=Tt(this.getValue(t));s&&this.ssp.setCameraViewpoint(s,!0)}}}class Q extends E{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("space",f.LOCAL),s=this.findProp("out",f.WRITE_CTX);if(t&&s){const e=Tt(t.value),i=Tt(s.value);this.writeContext(i,At(this.ssp,e))}}}class $ extends E{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("spaces",f.LOCAL),s=this.findProp("out",f.WRITE_CTX);if(t&&s){const e=Tt(t.value),i=Tt(s.value),n=e.map((t=>At(this.ssp,t)));this.writeContext(i,n)}}}class tt extends E{constructor(t,s){super(t,s)}async exec(t){const s=this.findProp("poi",f.LOCAL),e=this.findProp("out",f.WRITE_CTX);if(s&&e){const t=Tt(s.value),i=Tt(e.value);this.writeContext(i,At(this.ssp,t))}}}class st extends E{constructor(t,s){super(t,s)}async exec(t){const s=this.findProp("pois",f.LOCAL),e=this.findProp("out",f.WRITE_CTX);if(s&&e){const t=Tt(s.value),i=Tt(e.value),n=t.map((t=>At(this.ssp,t)));this.writeContext(i,n)}}}class et extends E{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("value",f.LOCAL),s=this.findProp("out",f.WRITE_CTX);if(t&&s){const e=Tt(t.value),i=Tt(s.value);this.writeContext(i,e)}}}class it extends E{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("model",f.LOCAL);if(t){const s=Tt(t.value),e=new Function("sourceData",s);for(const t in this.ctx){const s=e(this.ctx[t]);null!=s&&!1!==s||delete this.ctx[t]}}}}class nt extends E{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("path",f.LOCAL),s=this.findProp("out",f.WRITE_CTX);if(t&&s){const e=Tt(t.value),i=Tt(s.value);this.writeContext(i,At(this.ssp,e))}}}class ot extends E{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("paths",f.LOCAL),s=this.findProp("out",f.WRITE_CTX);if(t&&s){const e=Tt(t.value),i=Tt(s.value),n=e.map((t=>At(this.ssp,t)));this.writeContext(i,n)}}}class at extends E{constructor(t,s){super(t,s)}async exec(t){var s;let e=await(null===(s=t.getTarget)||void 0===s?void 0:s.call(t,this));if(!e){const t=this.findProp("model",[f.READ_CTX,f.LOCAL]);t&&(e=this.getValue(t))}const i=this.findProp("animation",[f.READ_CTX,f.LOCAL]);if(e&&i){let t;if(i.type===f.READ_CTX){const s=this.parser.getVariableNameById(Tt(i.value));t=this.readContext(s)}else t=Tt(i.value);const s=e.animations[t];s&&(this.ssp.playModelAnimation(e,s),this.cleanSets.add((()=>{this.ssp.stopModelAnimation(e,s)})))}}}class rt extends E{constructor(t,s){super(t,s)}async exec(t){var s;let e=await(null===(s=t.getTarget)||void 0===s?void 0:s.call(t,this));if(!e){const t=this.findProp("model",[f.READ_CTX,f.LOCAL]);t&&(e=this.getValue(t))}const i=this.findProp("animation",[f.READ_CTX,f.LOCAL]);if(e&&i){let t;if(i.type===f.READ_CTX){const s=this.parser.getVariableNameById(Tt(i.value));t=this.readContext(s)}else t=Tt(i.value);const s=e.animations[t];s&&this.ssp.stopModelAnimation(e,s)}}}const ct=new Map;function lt(t){var s,e;null===(s=ct.get(t))||void 0===s||s.forEach((t=>t.stop())),null===(e=ct.get(t))||void 0===e||e.clear()}class ht extends E{constructor(t,s){super(t,s)}async exec(t){var s;const e=this.findProp("model",[f.READ_CTX,f.LOCAL]),i=this.findProp("animation",f.LOCAL),n=this.findProp("wait",f.LOCAL);if(e&&i&&n){const o=this.getValue(e),a=Tt(i.value),c=Tt(n.value);if(o){const e=await(null===(s=t.getAnimations)||void 0===s?void 0:s.call(t,this,o,a));if(e){const t=e.find((t=>t.id===a));t&&await Et((async()=>{const s=o.matrix.clone();await async function(t,s,e){var i;const{id:n,keyframes:o}=e,a=new r(t,s);ct.has(n)||ct.set(n,new Set),null===(i=ct.get(n))||void 0===i||i.add(a),await a.play(o)}(this.ssp,o,t),this.cleanSets.add((()=>{lt(t.id),o&&s.decompose(o.position,o.quaternion,o.scale)}))}),c)}}}}}class dt extends E{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("animation",f.LOCAL);if(t){lt(Tt(t.value))}}}const ut=new Map;function pt(t){var s,e;null===(s=ut.get(t))||void 0===s||s.forEach((t=>t.stop())),null===(e=ut.get(t))||void 0===e||e.clear()}class ft extends E{constructor(t,s){super(t,s)}async exec(t){var s;const e=this.findProp("mesh",[f.READ_CTX,f.LOCAL]),i=this.findProp("animation",f.LOCAL),n=this.findProp("wait",f.LOCAL);if(e&&i&&n){const o=this.getValue(e),a=Tt(i.value),c=Tt(n.value);if(o){const i=await(null===(s=t.getComponentAnimations)||void 0===s?void 0:s.call(t,this,o,a));if(i){const t=i.find((t=>t.id===a));if(t){let s=null;"Mesh"===e.valueType?s=o:"Model"===e.valueType&&(s=gt(o,t.refId)),s&&await Et((async()=>{if(s){const e=s.matrix.clone();await async function(t,s,e){var i;const{id:n,keyframes:o}=e,a=new r(t,s);ut.has(n)||ut.set(n,new Set),null===(i=ut.get(n))||void 0===i||i.add(a),await a.play(o)}(this.ssp,s,t),this.cleanSets.add((()=>{pt(t.id),s&&e.decompose(s.position,s.quaternion,s.scale)}))}}),c)}}}}}}class Ct extends E{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("animation",f.LOCAL);if(t){pt(Tt(t.value))}}}function Tt(t){return JSON.parse(t)}async function Et(t,s){s?await t():t()}function At(t,s,e){const i=t.getObjectById(s);if(i)return i;{const{viewport:{scene:i}}=t;return gt(null!=e?e:i,s)}}function gt(t,s){if(t.userData.key===s||t.uuid===s)return t;for(let e=0,i=t.children.length;e<i;e++){const i=gt(t.children[e],s);if(null!==i)return i}return null}const{utils:{sleep:Ot}}=a;class vt extends e{constructor(t,s){super(),this.onNodeBefore=null,this.onNodeAfter=null,this.ssp=t,this.flow=s,this.nodes=[],this.nodesMap=new Map,this.edges=[],this.edgesMap=new Map}addNode(t){this.nodes.push(t),this.nodesMap.set(t.id,t)}addEdge(t){this.edges.push(t),this.edgesMap.set(t.id,t)}getNodeById(t){return this.nodesMap.get(t)}getEdgeById(t){return this.edgesMap.get(t)}clear(){this.nodes.length=0,this.nodesMap.clear(),this.edges.length=0,this.edgesMap.clear()}parse(){this.clear();const{nodes:t,edges:s}=this.flow;t.forEach((t=>{const s=function(t,s){switch(s.type){case C.START:return new A(t,s);case C.COLOR:return new g(t,s);case C.NUMBER:return new O(t,s);case C.HIGHLIGHT:return new L(t,s);case C.UN_HIGHLIGHT:return new I(t,s);case C.OPACITY:return new N(t,s);case C.UN_OPACITY:return new x(t,s);case C.EMISSIVE:return new _(t,s);case C.UN_EMISSIVE:return new S(t,s);case C.MESH:return new R(t,s);case C.MESHES:return new H(t,s);case C.MODEL:return new j(t,s);case C.MODELS:return new X(t,s);case C.SPACE:return new Q(t,s);case C.SPACES:return new $(t,s);case C.POIS:return new st(t,s);case C.POI:return new tt(t,s);case C.PATH:return new nt(t,s);case C.PATHS:return new ot(t,s);case C.DELAY:return new B(t,s);case C.CONDITION_NODE:return new k(t,s);case C.SHOW:return new G(t,s);case C.HIDE:return new W(t,s);case C.CLIP_ANIMATION:return new at(t,s);case C.UN_CLIP_ANIMATION:return new rt(t,s);case C.TWEEN_ANIMATION:return new ht(t,s);case C.UN_TWEEN_ANIMATION:return new dt(t,s);case C.COMPONENT_TWEEN_ANIMATION:return new ft(t,s);case C.UN_COMPONENT_TWEEN_ANIMATION:return new Ct(t,s);case C.TRANSLATE:return new z(t,s);case C.ROTATE:return new J(t,s);case C.SCALE:return new K(t,s);case C.FLY_TO:return new Z(t,s);case C.DATA_EXTRACTION:return new et(t,s);case C.DATA_FILTER:return new it(t,s);default:return new E(t,s)}}(this,t);this.addNode(s)})),s.forEach((t=>{const s=new p(t);this.addEdge(s);const e=this.getNodeById(t.source),i=this.getNodeById(t.target);e&&i&&(e.postNodes.push(i),i.prevNodes.push(e))}))}async run(t={}){const s=this.nodes.filter((t=>t.prevNodes.length||t.postNodes.length)).map((s=>s.run(t)));await Promise.allSettled(s)}async debug(t={},s=1500){const e=this.onNodeAfter;this.onNodeAfter=async t=>{await Ot(s),null==e||e(t)},await this.run(t)}stop(){this.nodes.forEach((t=>t.reject(new Error("Flow stopped"))))}cleanup(){this.nodes.sort(((t,s)=>s.execOrder-t.execOrder)).forEach((t=>t.cleanup()))}getVariableNameById(t){const s=this.nodes.find((s=>s.id===t));if(s){const t=s.props.find((t=>"out"===t.name));return t?Tt(t.value):null}return null}dispose(){this.stop(),this.cleanup()}}class Lt extends vt{constructor(t,s){super(t,s),this.flow=s}}function wt(t,s,e,i){if("a"===e&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof s?t!==s||!i:!s.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===e?i:"a"===e?i.call(t):i?i.value:s.get(t)}var It,yt;"function"==typeof SuppressedError&&SuppressedError,function(t){t.Group="Group",t.Light="Light",t.Model="Model",t.Poi="Poi",t.PoiNode="PoiNode",t.Canvas3D="Canvas3D",t.Topology="Topology",t.Helper="Helper",t.Decal="Decal",t.PluginObject="PluginObject"}(It||(It={})),function(t){t.sbm="SBM",t.sbmx="SBMX",t.glb="GLB",t.gltf="GLTF",t.fbx="FBX",t.obj="OBJ",t.stl="STL"}(yt||(yt={})),new t,new t,new t;const Nt={},Pt=new i;Pt.setRequestHeader(Nt);(new n).load=(t,s,e,i)=>{const n=new Image;return Pt.setResponseType("blob"),Pt.load(t,(function(t){n.src=URL.createObjectURL(t),n.onload=()=>{URL.revokeObjectURL(n.src),null==s||s(n)}}),e,i),n};(new o).setRequestHeader(Nt);async function xt(t){return async function(t,s){return await s()}(0,t)}(new u).setRequestHeader(Nt),new t,new t,new t;const mt=(t,s)=>t.userData.key===s||!!t.parent&&mt(t.parent,s);var _t,bt,St;const{groupBy:Mt}=a.utils;class Rt{constructor(t,s,e,i){_t.add(this),this.disposables=[],this.status="ready",this.ssp=t,this.interaction=s,this.flows=e,this.flowsMap=Mt(e,"id"),this.options=i||{},wt(this,_t,"m",bt).call(this)}modelHandler(t){var s;const{target:e,currentTarget:i}=t,n=this.interaction.editionId;n?e.sid!==n&&e.userData.familyId!==n||!mt(i,this.interaction.modelId)||(this.target=e,this.execBehavior()):null===(s=this.interaction.obsTargets)||void 0===s||s.forEach((t=>{t!==e.userData.id&&t!==e.userData.sid||(this.target=e,this.execBehavior())}))}runFlowByIds(t){const s=this.target?async()=>this.target:wt(this,_t,"m",St).bind(this);t.forEach((t=>{const e=this.flowsMap.get(t);if(e){const t=new c(this.ssp,e[0]);t.parse(),xt((()=>t.run({getTarget:s,getAnimations:this.options.getAnimations,getComponentAnimations:this.options.getComponentAnimations})))}}))}async execBehavior(){var t,s,e,i,n;if(null===(t=this.interaction.active)||void 0===t||t)try{this.status="running";const{behaviors:t}=this.interaction;null==t||t.forEach((t=>{if(t.action===l.FLOW)t.actionRefs&&this.runFlowByIds(t.actionRefs)})),(null===(s=this.options)||void 0===s?void 0:s.onTrigger)&&(null===(e=this.options)||void 0===e||e.onTrigger(this.interaction))}catch(t){this.status="error",(null===(i=this.options)||void 0===i?void 0:i.onError)&&(null===(n=this.options)||void 0===n||n.onError(t))}}initMouseClick(){const t=this.modelHandler.bind(this);this.ssp.signals.modelClick.add(t),this.disposables.push((()=>this.ssp.signals.modelClick.remove(t)))}initMouseDbClick(){const t=this.modelHandler.bind(this);this.ssp.signals.modelDblClick.add(t),this.disposables.push((()=>this.ssp.signals.modelDblClick.remove(t)))}initMouseRightClick(){const t=this.modelHandler.bind(this);this.ssp.signals.modelRightClick.add(t),this.disposables.push((()=>this.ssp.signals.modelRightClick.remove(t)))}initLoaded(){(()=>{this.execBehavior()})()}modelPropChangeHandler(t){var s,e;(null===(s=null==t?void 0:t.target)||void 0===s?void 0:s.refId)&&"code"!==this.ssp.utils.propertiesCtx.source&&(null===(e=t.target)||void 0===e||e.refId,this.interaction.editionId&&(this.target=this.ssp.getObjectByUserDataProperty("familyId",this.interaction.editionId)[0]),this.execBehavior())}initModelPropChange(){const t=this.modelPropChangeHandler.bind(this);this.ssp.signals.propertiesChanged.add(t),this.disposables.push((()=>this.ssp.signals.propertiesChanged.remove(t)))}initThingPropChange(){}initThingEvent(){}dispose(){this.disposables.forEach((t=>t()))}}var Dt,Ht,jt,Xt,Bt,kt,Vt,Gt;_t=new WeakSet,bt=function(){switch(this.interaction.type){case h.MOUSE_CLICK:this.initMouseClick();break;case h.MOUSE_DB_CLICK:this.initMouseDbClick();break;case h.MOUSE_RIGHT_CLICK:this.initMouseRightClick();break;case h.LOADED:this.initLoaded();break;case h.THING_PROP_CHANGE:this.initThingPropChange();break;case h.THING_EVENT:this.initThingEvent();break;case h.MODEL_PROP_CHANGE:this.initModelPropChange()}},St=async function(t){const{obsType:s,obsTargets:e,editionId:i}=this.interaction;if(s===d.GLOBAL)return null;if(s===d.INSTANCE){let t;i?(t=this.ssp.getModelById(i),t||console.warn("Target not found:",i)):t=null==e?void 0:e.map((t=>{const s=this.ssp.getModelById(t);return s||console.warn("Target not found:",e[0]),s}))[0]}return null},function(t){t.GLOBAL="GLOBAL",t.SELF="SELF",t.OTHER="OTHER"}(Dt||(Dt={})),function(t){t.FLOW="FLOW",t.ANIMATION="ANIMATION",t.DELAY="DELAY"}(Ht||(Ht={})),function(t){t.GLOBAL="GLOBAL",t.INSTANCE="INSTANCE",t.FAMILY="FAMILY"}(jt||(jt={})),function(t){t.MOUSE_CLICK="MOUSE_CLICK",t.MOUSE_DB_CLICK="MOUSE_DB_CLICK",t.MOUSE_RIGHT_CLICK="MOUSE_RIGHT_CLICK",t.THING_PROP_CHANGE="THING_PROP_CHANGE",t.THING_EVENT="THING_EVENT",t.LOADED="LOADED",t.MODEL_PROP_CHANGE="MODEL_PROP_CHANGE"}(Xt||(Xt={}));const{groupBy:Ut}=a.utils;class Wt extends Rt{constructor(t,s,e,i){super(t,s,e,i),Bt.add(this),this.flows=e,this.flowsMap=Ut(e,"id"),wt(this,Bt,"m",kt).call(this)}modelHandler(t){var s;const{currentTarget:e}=t;null===(s=this.interaction.obsTargets)||void 0===s||s.forEach((t=>{t===e.userData.key&&this.execBehavior()}))}runFlowByIds(t){const s=wt(this,Bt,"m",Vt).bind(this);t.forEach((t=>{const e=this.flowsMap.get(t);if(e){const t=new Lt(this.ssp,e[0]);t.parse(),xt((()=>t.run({getTarget:s})))}}))}async execBehavior(){var t,s,e,i;try{const{behaviors:e}=this.interaction;null==e||e.forEach((t=>{if(t.action===Ht.FLOW)t.actionRefs&&this.runFlowByIds(t.actionRefs)})),(null===(t=this.options)||void 0===t?void 0:t.onTrigger)&&(null===(s=this.options)||void 0===s||s.onTrigger(this.interaction))}catch(t){(null===(e=this.options)||void 0===e?void 0:e.onError)&&(null===(i=this.options)||void 0===i||i.onError(t))}}initLoaded(){const t=()=>{this.execBehavior()};wt(this,Bt,"m",Vt).call(this).then((s=>{s&&(s.addEventListener("load",t),this.disposables.push((()=>s.removeEventListener("load",t))))}))}initThingPropChange(){const t=wt(this,Bt,"m",Gt).bind(this);this.ssp.signals.thingModelPropsChange.add(t),this.disposables.push((()=>this.ssp.signals.thingModelPropsChange.remove(t)))}initThingEvent(){}onThingPropChange(t){this.ssp.signals.thingModelPropsChange.dispatch({propKey:t})}}Bt=new WeakSet,kt=function(){switch(this.interaction.type){case Xt.MOUSE_CLICK:this.initMouseClick();break;case Xt.MOUSE_DB_CLICK:this.initMouseDbClick();break;case Xt.MOUSE_RIGHT_CLICK:this.initMouseRightClick();break;case Xt.LOADED:this.initLoaded();break;case Xt.THING_PROP_CHANGE:this.initThingPropChange();break;case Xt.THING_EVENT:this.initThingEvent();break;case Xt.MODEL_PROP_CHANGE:this.initModelPropChange()}},Vt=async function(t){console.log("currentNode",t);const{obsType:s,obsTargets:e}=this.interaction;if(s===jt.GLOBAL)return null;if(s===jt.INSTANCE){const t=null==e?void 0:e.map((t=>{const s=this.ssp.getModelById(t);return s||console.warn("Target not found:",t),s}));return t?t[0]:null}return null},Gt=function(t){var s;const{propKey:e}=t;null===(s=this.interaction.obsProps)||void 0===s||s.forEach((t=>{t===e&&this.execBehavior()}))};export{Lt as ComponentFlowParser,Wt as ComponentTrigger,vt as FlowParser,Ht as InteractionAction,Dt as InteractionActionType,jt as InteractionObsType,Xt as InteractionType,E as Node,f as NodePropTypeEnum,C as NodeTypeEnum,Rt as Trigger};
1
+ import { Vector3, Euler, EventDispatcher, FileLoader, ImageLoader, TextureLoader } from 'three';
2
+ import SoonSpace from 'soonspacejs';
3
+ import { AnimationPlayer } from 'umanager-animation-parser';
4
+ import { FlowParser as FlowParser$1, InteractionAction as InteractionAction$1, InteractionType as InteractionType$1, InteractionObsType as InteractionObsType$1 } from '@soonspacejs/plugin-flow';
5
+ import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader.js';
6
+ import 'three/examples/jsm/exporters/GLTFExporter.js';
7
+
8
+ class Edge {
9
+ constructor(edge) {
10
+ this.id = edge.id;
11
+ this.source = edge.source;
12
+ this.target = edge.target;
13
+ this.sourceHandle = edge.sourceHandle;
14
+ }
15
+ }
16
+
17
+ var NodePropTypeEnum;
18
+ (function (NodePropTypeEnum) {
19
+ NodePropTypeEnum["LOCAL"] = "LOCAL";
20
+ NodePropTypeEnum["READ_CTX"] = "READ_CTX";
21
+ NodePropTypeEnum["WRITE_CTX"] = "WRITE_CTX";
22
+ })(NodePropTypeEnum || (NodePropTypeEnum = {}));
23
+ var NodeTypeEnum;
24
+ (function (NodeTypeEnum) {
25
+ NodeTypeEnum["START"] = "START";
26
+ NodeTypeEnum["COLOR"] = "COLOR";
27
+ NodeTypeEnum["NUMBER"] = "NUMBER";
28
+ NodeTypeEnum["HIGHLIGHT"] = "HIGHLIGHT";
29
+ NodeTypeEnum["UN_HIGHLIGHT"] = "UN_HIGHLIGHT";
30
+ NodeTypeEnum["OPACITY"] = "OPACITY";
31
+ NodeTypeEnum["UN_OPACITY"] = "UN_OPACITY";
32
+ NodeTypeEnum["EMISSIVE"] = "EMISSIVE";
33
+ NodeTypeEnum["UN_EMISSIVE"] = "UN_EMISSIVE";
34
+ NodeTypeEnum["MESH"] = "MESH";
35
+ NodeTypeEnum["MESHES"] = "MESHES";
36
+ NodeTypeEnum["MODEL"] = "MODEL";
37
+ NodeTypeEnum["MODELS"] = "MODELS";
38
+ NodeTypeEnum["SHOW"] = "SHOW";
39
+ NodeTypeEnum["HIDE"] = "HIDE";
40
+ NodeTypeEnum["CLIP_ANIMATION"] = "CLIP_ANIMATION";
41
+ NodeTypeEnum["UN_CLIP_ANIMATION"] = "UN_CLIP_ANIMATION";
42
+ NodeTypeEnum["TWEEN_ANIMATION"] = "TWEEN_ANIMATION";
43
+ NodeTypeEnum["UN_TWEEN_ANIMATION"] = "UN_TWEEN_ANIMATION";
44
+ NodeTypeEnum["COMPONENT_TWEEN_ANIMATION"] = "COMPONENT_TWEEN_ANIMATION";
45
+ NodeTypeEnum["UN_COMPONENT_TWEEN_ANIMATION"] = "UN_COMPONENT_TWEEN_ANIMATION";
46
+ NodeTypeEnum["SPACE"] = "SPACE";
47
+ NodeTypeEnum["SPACES"] = "SPACES";
48
+ NodeTypeEnum["PATH"] = "PATH";
49
+ NodeTypeEnum["PATHS"] = "PATHS";
50
+ NodeTypeEnum["POI"] = "POI";
51
+ NodeTypeEnum["POIS"] = "POIS";
52
+ NodeTypeEnum["FLY_TO"] = "FLY_TO";
53
+ NodeTypeEnum["TRANSLATE"] = "TRANSLATE";
54
+ NodeTypeEnum["ROTATE"] = "ROTATE";
55
+ NodeTypeEnum["SCALE"] = "SCALE";
56
+ NodeTypeEnum["DATA_FILTER"] = "DATA_FILTER";
57
+ NodeTypeEnum["DATA_EXTRACTION"] = "DATA_EXTRACTION";
58
+ NodeTypeEnum["CONDITION_NODE"] = "CONDITION_NODE";
59
+ NodeTypeEnum["DELAY"] = "DELAY";
60
+ })(NodeTypeEnum || (NodeTypeEnum = {}));
61
+
62
+ let count = 0;
63
+ class Node {
64
+ constructor(parser, node) {
65
+ // 前置节点
66
+ this.prevNodes = [];
67
+ // 后置节点
68
+ this.postNodes = [];
69
+ // 执行顺序
70
+ this.execOrder = 0;
71
+ // 清空队列回调
72
+ this.cleanSets = new Set();
73
+ // 前置钩子
74
+ this.onBefore = null;
75
+ // 后置钩子
76
+ this.onAfter = null;
77
+ this.parser = parser;
78
+ this.ssp = parser.ssp;
79
+ this.id = node.id;
80
+ this.type = node.type;
81
+ this.props = node.props;
82
+ this.rejected = false;
83
+ this.init();
84
+ }
85
+ init() {
86
+ this.ctx = {};
87
+ this.promise = new Promise((resolve, reject) => {
88
+ this.resolve = resolve;
89
+ this.reject = () => {
90
+ this.rejected = true;
91
+ reject();
92
+ };
93
+ });
94
+ }
95
+ readContext(key) {
96
+ return this.ctx[key];
97
+ }
98
+ writeContext(key, value) {
99
+ this.ctx[key] = value;
100
+ }
101
+ findProp(name, type) {
102
+ // 如果是数组则从第一个成员开始查找,如果有prop则返回该值
103
+ if (type instanceof Array) {
104
+ for (const item of type) {
105
+ const prop = this.findProp(name, item);
106
+ if (prop)
107
+ return prop;
108
+ }
109
+ }
110
+ else {
111
+ return this.props.find(prop => prop.name === name && prop.type === type);
112
+ }
113
+ }
114
+ /**
115
+ * 等待前置节点执行完毕
116
+ */
117
+ async waitForPrevNodes() {
118
+ return await Promise.all(this.prevNodes.map(prevNode => prevNode.promise));
119
+ }
120
+ /**
121
+ * 合并上下文
122
+ */
123
+ mergeContext() {
124
+ this.prevNodes.forEach(prevNode => {
125
+ Object.assign(this.ctx, prevNode.ctx);
126
+ });
127
+ }
128
+ /**
129
+ * 执行节点逻辑
130
+ * @param global
131
+ */
132
+ async exec(_global) {
133
+ // 子类实现
134
+ }
135
+ /**
136
+ * 运行节点
137
+ * @param global
138
+ */
139
+ async run(global) {
140
+ var _a, _b, _c, _d;
141
+ try {
142
+ await this.waitForPrevNodes();
143
+ if (this.rejected)
144
+ throw new Error();
145
+ this.mergeContext();
146
+ await ((_b = ((_a = this.onBefore) !== null && _a !== void 0 ? _a : this.parser.onNodeBefore)) === null || _b === void 0 ? void 0 : _b(this));
147
+ try {
148
+ this.execOrder = ++count;
149
+ await this.exec(global);
150
+ }
151
+ catch (e) {
152
+ this.reject(e);
153
+ throw e;
154
+ }
155
+ await ((_d = ((_c = this.onAfter) !== null && _c !== void 0 ? _c : this.parser.onNodeAfter)) === null || _d === void 0 ? void 0 : _d(this));
156
+ this.resolve();
157
+ }
158
+ catch (e) {
159
+ this.reject();
160
+ }
161
+ }
162
+ // 清空节点逻辑
163
+ cleanup() {
164
+ this.cleanSets.forEach(clean => clean());
165
+ this.cleanSets.clear();
166
+ }
167
+ getValue(prop, object) {
168
+ if (prop.type === NodePropTypeEnum.READ_CTX) {
169
+ return this.readContext(parseValue(prop.value));
170
+ }
171
+ else if (prop.type === NodePropTypeEnum.LOCAL) {
172
+ const { viewport: { scene, }, } = this.ssp;
173
+ if (prop.name === 'objects' || prop.name === 'models' || prop.name === 'meshs') {
174
+ return parseValue(prop.value).map((item) => getObjectById(this.ssp, item, object !== null && object !== void 0 ? object : scene));
175
+ }
176
+ else if (prop.name === 'object' || prop.name === 'model' || prop.name === 'mesh') {
177
+ return getObjectById(this.ssp, parseValue(prop.value), object !== null && object !== void 0 ? object : scene);
178
+ }
179
+ else {
180
+ return parseValue(prop.value);
181
+ }
182
+ // return prop.name === 'objects' ? getObjectById( parseValue( prop.value ) ) : parseValue( prop.value )
183
+ }
184
+ }
185
+ }
186
+
187
+ class StartNode extends Node {
188
+ constructor(parser, node) {
189
+ super(parser, node);
190
+ }
191
+ }
192
+
193
+ class ColorNode extends Node {
194
+ constructor(parser, node) {
195
+ super(parser, node);
196
+ }
197
+ async exec() {
198
+ const colorProp = this.findProp('color', NodePropTypeEnum.LOCAL);
199
+ const out = this.findProp('out', NodePropTypeEnum.WRITE_CTX);
200
+ if (colorProp && out) {
201
+ this.writeContext(parseValue(out.value), parseValue(colorProp.value));
202
+ }
203
+ }
204
+ }
205
+
206
+ class NumberNode extends Node {
207
+ constructor(parser, node) {
208
+ super(parser, node);
209
+ }
210
+ async exec() {
211
+ const numberProp = this.findProp('number', NodePropTypeEnum.LOCAL);
212
+ const outProp = this.findProp('out', NodePropTypeEnum.WRITE_CTX);
213
+ if (numberProp && outProp) {
214
+ this.writeContext(parseValue(outProp.value), parseValue(numberProp.value));
215
+ }
216
+ }
217
+ }
218
+
219
+ const { objectHandle: objectHandle$a, } = SoonSpace.utils;
220
+ class HighlightNode extends Node {
221
+ constructor(parser, node) {
222
+ super(parser, node);
223
+ }
224
+ filterHighlightObject(objectsValue) {
225
+ const objects = [];
226
+ objectHandle$a(objectsValue, obj => {
227
+ if (!this.ssp.viewport.scener.selectedObjects.highlight.has(obj)) {
228
+ objects.push(obj);
229
+ }
230
+ });
231
+ return objects;
232
+ }
233
+ async exec(global) {
234
+ var _a;
235
+ const objectsProp = this.findProp('objects', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
236
+ const colorProp = this.findProp('color', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
237
+ const opacityProp = this.findProp('opacity', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
238
+ const model = await ((_a = global.getTarget) === null || _a === void 0 ? void 0 : _a.call(global, this));
239
+ if (objectsProp && colorProp && opacityProp) {
240
+ const objectsValue = this.getValue(objectsProp, model);
241
+ const colorValue = this.getValue(colorProp);
242
+ const opacityValue = this.getValue(opacityProp);
243
+ if (objectsValue) {
244
+ const filteredObjects = this.filterHighlightObject(objectsValue);
245
+ this.ssp.highlightShow(filteredObjects, { color: colorValue, opacity: opacityValue, });
246
+ this.cleanSets.add(() => {
247
+ this.ssp.unHighlightShow(filteredObjects);
248
+ });
249
+ }
250
+ }
251
+ }
252
+ }
253
+
254
+ const { objectHandle: objectHandle$9, } = SoonSpace.utils;
255
+ class UnHighlightNode extends Node {
256
+ constructor(parser, node) {
257
+ super(parser, node);
258
+ }
259
+ filterUnHighlightObject(objectsValue) {
260
+ const objects = [];
261
+ objectHandle$9(objectsValue, obj => {
262
+ if (this.ssp.viewport.scener.selectedObjects.highlight.has(obj)) {
263
+ objects.push(obj);
264
+ }
265
+ });
266
+ return objects;
267
+ }
268
+ async exec(global) {
269
+ var _a;
270
+ const objects = this.findProp('objects', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
271
+ const model = await ((_a = global.getTarget) === null || _a === void 0 ? void 0 : _a.call(global, this));
272
+ if (objects) {
273
+ const objectsValue = this.getValue(objects, model);
274
+ if (objectsValue) {
275
+ const filteredObjects = this.filterUnHighlightObject(objectsValue);
276
+ this.ssp.unHighlightShow(filteredObjects);
277
+ this.cleanSets.add(() => {
278
+ this.ssp.highlightShow(filteredObjects); // @todo 参数
279
+ });
280
+ }
281
+ }
282
+ }
283
+ }
284
+
285
+ const { objectHandle: objectHandle$8, } = SoonSpace.utils;
286
+ class OpacityNode extends Node {
287
+ constructor(parser, node) {
288
+ super(parser, node);
289
+ }
290
+ filterOpacityObject(objectsValue) {
291
+ const objects = [];
292
+ objectHandle$8(objectsValue, obj => {
293
+ if (!this.ssp.viewport.scener.selectedObjects.opacity.has(obj)) {
294
+ objects.push(obj);
295
+ }
296
+ });
297
+ return objects;
298
+ }
299
+ async exec(global) {
300
+ var _a;
301
+ const objectsProp = this.findProp('objects', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
302
+ const colorProp = this.findProp('color', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
303
+ const opacityProp = this.findProp('opacity', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
304
+ const model = await ((_a = global.getTarget) === null || _a === void 0 ? void 0 : _a.call(global, this));
305
+ if (objectsProp && colorProp && opacityProp) {
306
+ const objectsValue = this.getValue(objectsProp, model);
307
+ const colorValue = this.getValue(colorProp);
308
+ const opacityValue = this.getValue(opacityProp);
309
+ if (objectsValue) {
310
+ const filteredObjects = this.filterOpacityObject(objectsValue);
311
+ this.ssp.opacityShow(filteredObjects, { color: colorValue, opacity: opacityValue, });
312
+ this.cleanSets.add(() => {
313
+ this.ssp.unOpacityShow(filteredObjects);
314
+ });
315
+ }
316
+ }
317
+ }
318
+ }
319
+
320
+ const { objectHandle: objectHandle$7, } = SoonSpace.utils;
321
+ class UnOpacityNode extends Node {
322
+ constructor(parser, node) {
323
+ super(parser, node);
324
+ }
325
+ filterUnOpacityObject(objectsValue) {
326
+ const objects = [];
327
+ objectHandle$7(objectsValue, obj => {
328
+ if (this.ssp.viewport.scener.selectedObjects.opacity.has(obj)) {
329
+ objects.push(obj);
330
+ }
331
+ });
332
+ return objects;
333
+ }
334
+ async exec(global) {
335
+ var _a;
336
+ const objects = this.findProp('objects', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
337
+ const model = await ((_a = global.getTarget) === null || _a === void 0 ? void 0 : _a.call(global, this));
338
+ if (objects) {
339
+ const objectsValue = this.getValue(objects, model);
340
+ if (objectsValue) {
341
+ const filteredObjects = this.filterUnOpacityObject(objectsValue);
342
+ this.ssp.unOpacityShow(filteredObjects);
343
+ this.cleanSets.add(() => {
344
+ this.ssp.opacityShow(filteredObjects); // @todo 参数
345
+ });
346
+ }
347
+ }
348
+ }
349
+ }
350
+
351
+ const { objectHandle: objectHandle$6, } = SoonSpace.utils;
352
+ class EmissiveNode extends Node {
353
+ constructor(parser, node) {
354
+ super(parser, node);
355
+ }
356
+ filterEmissiveObject(objectsValue) {
357
+ const objects = [];
358
+ objectHandle$6(objectsValue, obj => {
359
+ if (!this.ssp.viewport.scener.selectedObjects.emissive.has(obj)) {
360
+ objects.push(obj);
361
+ }
362
+ });
363
+ return objects;
364
+ }
365
+ async exec(global) {
366
+ var _a;
367
+ const objectsProp = this.findProp('objects', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
368
+ const colorProp = this.findProp('color', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
369
+ const baseColorProp = this.findProp('baseColor', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
370
+ const minOpacityProp = this.findProp('minOpacity', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
371
+ const maxOpacityProp = this.findProp('maxOpacity', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
372
+ const durationProp = this.findProp('duration', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
373
+ const model = await ((_a = global.getTarget) === null || _a === void 0 ? void 0 : _a.call(global, this));
374
+ if (objectsProp && colorProp && baseColorProp && minOpacityProp && maxOpacityProp && durationProp) {
375
+ const objectsValue = this.getValue(objectsProp, model);
376
+ const colorValue = this.getValue(colorProp);
377
+ const baseColorValue = this.getValue(baseColorProp);
378
+ const minOpacityValue = this.getValue(minOpacityProp);
379
+ const maxOpacityValue = this.getValue(maxOpacityProp);
380
+ const durationValue = this.getValue(durationProp);
381
+ if (objectsValue) {
382
+ const filteredObjects = this.filterEmissiveObject(objectsValue);
383
+ this.ssp.emissiveShow(filteredObjects, {
384
+ color: colorValue,
385
+ baseColor: baseColorValue,
386
+ minOpacity: minOpacityValue,
387
+ maxOpacity: maxOpacityValue,
388
+ duration: durationValue,
389
+ });
390
+ this.cleanSets.add(() => {
391
+ this.ssp.unEmissiveShow(filteredObjects);
392
+ });
393
+ }
394
+ }
395
+ }
396
+ }
397
+
398
+ const { objectHandle: objectHandle$5, } = SoonSpace.utils;
399
+ class UnEmissiveNode extends Node {
400
+ constructor(parser, node) {
401
+ super(parser, node);
402
+ }
403
+ filterUnEmissiveObject(objectsValue) {
404
+ const objects = [];
405
+ objectHandle$5(objectsValue, obj => {
406
+ if (this.ssp.viewport.scener.selectedObjects.emissive.has(obj)) {
407
+ objects.push(obj);
408
+ }
409
+ });
410
+ return objects;
411
+ }
412
+ async exec(global) {
413
+ var _a;
414
+ const objects = this.findProp('objects', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
415
+ const model = await ((_a = global.getTarget) === null || _a === void 0 ? void 0 : _a.call(global, this));
416
+ if (objects) {
417
+ const objectsValue = this.getValue(objects, model);
418
+ if (objectsValue) {
419
+ const filteredObjects = this.filterUnEmissiveObject(objectsValue);
420
+ this.ssp.unEmissiveShow(filteredObjects);
421
+ this.cleanSets.add(() => {
422
+ this.ssp.emissiveShow(filteredObjects); // @todo 参数
423
+ });
424
+ }
425
+ }
426
+ }
427
+ }
428
+
429
+ const meshCacheSymbol = Symbol('meshCache');
430
+ class MeshNode extends Node {
431
+ constructor(parser, node) {
432
+ super(parser, node);
433
+ }
434
+ async exec(global) {
435
+ var _a;
436
+ const { viewport: { scene, }, } = this.ssp;
437
+ const model = await ((_a = global.getTarget) === null || _a === void 0 ? void 0 : _a.call(global, this)) || scene;
438
+ // 检查缓存
439
+ if (!global[meshCacheSymbol]) {
440
+ global[meshCacheSymbol] = {};
441
+ }
442
+ const meshProp = this.findProp('mesh', NodePropTypeEnum.LOCAL);
443
+ const outProp = this.findProp('out', NodePropTypeEnum.WRITE_CTX);
444
+ if (meshProp && outProp) {
445
+ let meshObject = null;
446
+ const meshValue = parseValue(meshProp.value);
447
+ const outValue = parseValue(outProp.value);
448
+ const cachedMesh = global[meshCacheSymbol][meshValue];
449
+ if (cachedMesh) {
450
+ meshObject = cachedMesh;
451
+ return;
452
+ }
453
+ const mesh = getMeshByUserDataUuid(model, meshValue);
454
+ if (mesh) {
455
+ meshObject = mesh;
456
+ global[meshCacheSymbol][meshValue] = mesh;
457
+ }
458
+ this.writeContext(outValue, meshObject);
459
+ }
460
+ }
461
+ }
462
+
463
+ const meshesCacheSymbol = Symbol('meshesCache');
464
+ class MeshesNode extends Node {
465
+ constructor(parser, node) {
466
+ super(parser, node);
467
+ }
468
+ async exec(global) {
469
+ var _a;
470
+ const { viewport: { scene, }, } = this.ssp;
471
+ const model = await ((_a = global.getTarget) === null || _a === void 0 ? void 0 : _a.call(global, this)) || scene;
472
+ // 检查缓存
473
+ if (!global[meshesCacheSymbol]) {
474
+ global[meshesCacheSymbol] = {};
475
+ }
476
+ const meshesProp = this.findProp('meshes', NodePropTypeEnum.LOCAL);
477
+ const outProp = this.findProp('out', NodePropTypeEnum.WRITE_CTX);
478
+ if (meshesProp && outProp) {
479
+ const meshesObject = [];
480
+ const meshesValue = parseValue(meshesProp.value);
481
+ const outValue = parseValue(outProp.value);
482
+ meshesValue.forEach((uuid) => {
483
+ const cachedMesh = global[meshesCacheSymbol][uuid];
484
+ if (cachedMesh) {
485
+ meshesObject.push(cachedMesh);
486
+ return;
487
+ }
488
+ const mesh = getMeshByUserDataUuid(model, uuid);
489
+ if (mesh) {
490
+ meshesObject.push(mesh);
491
+ global[meshesCacheSymbol][uuid] = mesh;
492
+ }
493
+ });
494
+ this.writeContext(outValue, meshesObject);
495
+ }
496
+ }
497
+ }
498
+
499
+ class ModelNode extends Node {
500
+ constructor(parser, node) {
501
+ super(parser, node);
502
+ }
503
+ async exec() {
504
+ const modelProp = this.findProp('model', NodePropTypeEnum.LOCAL);
505
+ const outProp = this.findProp('out', NodePropTypeEnum.WRITE_CTX);
506
+ if (modelProp && outProp) {
507
+ const modelValue = parseValue(modelProp.value);
508
+ const outValue = parseValue(outProp.value);
509
+ this.writeContext(outValue, getObjectById(this.ssp, modelValue));
510
+ }
511
+ }
512
+ }
513
+
514
+ class ModelsNode extends Node {
515
+ constructor(parser, node) {
516
+ super(parser, node);
517
+ }
518
+ async exec() {
519
+ const modelsProp = this.findProp('models', NodePropTypeEnum.LOCAL);
520
+ const outProp = this.findProp('out', NodePropTypeEnum.WRITE_CTX);
521
+ if (modelsProp && outProp) {
522
+ const modelValue = parseValue(modelsProp.value);
523
+ const outValue = parseValue(outProp.value);
524
+ this.writeContext(outValue, getObjectByIds(this.ssp, modelValue));
525
+ }
526
+ }
527
+ }
528
+
529
+ class DelayNode extends Node {
530
+ constructor(parser, node) {
531
+ super(parser, node);
532
+ }
533
+ async exec() {
534
+ const delayProp = this.findProp('delay', NodePropTypeEnum.LOCAL);
535
+ if (delayProp) {
536
+ const delayValue = parseValue(delayProp.value);
537
+ await SoonSpace.utils.sleep(delayValue);
538
+ }
539
+ }
540
+ }
541
+
542
+ class ConditionNode extends Node {
543
+ constructor(parser, node) {
544
+ super(parser, node);
545
+ }
546
+ execFn(fnStr) {
547
+ const fn = new Function('sourceData', fnStr);
548
+ return fn(this.ctx);
549
+ }
550
+ async exec() {
551
+ const conditionProp = this.findProp('conditaion_node', NodePropTypeEnum.LOCAL);
552
+ if (conditionProp) {
553
+ const conditionValue = parseValue(conditionProp.value);
554
+ const edges = this.parser.edges.filter(edge => edge.source === this.id);
555
+ conditionValue.forEach(item => {
556
+ try {
557
+ const res = this.execFn(item.value);
558
+ if (res !== true)
559
+ throw new Error();
560
+ }
561
+ catch (e) {
562
+ const edge = edges.find(edge => edge.sourceHandle == String(item.id));
563
+ if (!edge)
564
+ return;
565
+ const targetNode = this.postNodes.find(node => node.id === edge.target);
566
+ targetNode === null || targetNode === void 0 ? void 0 : targetNode.reject();
567
+ }
568
+ });
569
+ }
570
+ }
571
+ }
572
+
573
+ const { objectHandle: objectHandle$4, } = SoonSpace.utils;
574
+ class ShowNode extends Node {
575
+ constructor(parser, node) {
576
+ super(parser, node);
577
+ }
578
+ filterShowObject(objectsValue) {
579
+ const objects = [];
580
+ objectHandle$4(objectsValue, obj => {
581
+ if (obj.visible === false) {
582
+ objects.push(obj);
583
+ }
584
+ });
585
+ return objects;
586
+ }
587
+ async exec(global) {
588
+ var _a;
589
+ const objectsProp = this.findProp('objects', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
590
+ const model = await ((_a = global.getTarget) === null || _a === void 0 ? void 0 : _a.call(global, this));
591
+ if (objectsProp) {
592
+ const objectsValue = this.getValue(objectsProp, model);
593
+ if (objectsValue) {
594
+ const filteredObjects = this.filterShowObject(objectsValue);
595
+ const handler = (visible) => {
596
+ objectHandle$4(filteredObjects, obj => {
597
+ obj.visible = visible;
598
+ });
599
+ this.ssp.render();
600
+ };
601
+ handler(true);
602
+ this.cleanSets.add(() => handler(false));
603
+ }
604
+ }
605
+ }
606
+ }
607
+
608
+ const { objectHandle: objectHandle$3, } = SoonSpace.utils;
609
+ class HideNode extends Node {
610
+ constructor(parser, node) {
611
+ super(parser, node);
612
+ }
613
+ filterHideObject(objectsValue) {
614
+ const objects = [];
615
+ objectHandle$3(objectsValue, obj => {
616
+ if (obj.visible === true) {
617
+ objects.push(obj);
618
+ }
619
+ });
620
+ return objects;
621
+ }
622
+ async exec(global) {
623
+ var _a;
624
+ const objectsProp = this.findProp('objects', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
625
+ const model = await ((_a = global.getTarget) === null || _a === void 0 ? void 0 : _a.call(global, this));
626
+ if (objectsProp) {
627
+ const objectsValue = this.getValue(objectsProp, model);
628
+ if (objectsValue) {
629
+ const filteredObjects = this.filterHideObject(objectsValue);
630
+ const handler = (visible) => {
631
+ objectHandle$3(filteredObjects, obj => {
632
+ obj.visible = visible;
633
+ });
634
+ this.ssp.render();
635
+ };
636
+ handler(false);
637
+ this.cleanSets.add(() => handler(true));
638
+ }
639
+ }
640
+ }
641
+ }
642
+
643
+ const { objectHandle: objectHandle$2, } = SoonSpace.utils;
644
+ class TranslateNode extends Node {
645
+ constructor(parser, node) {
646
+ super(parser, node);
647
+ }
648
+ async exec(global) {
649
+ var _a;
650
+ const objectsProp = this.findProp('objects', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
651
+ const axisProp = this.findProp('axis', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
652
+ const translateProp = this.findProp('translate', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
653
+ const model = await ((_a = global.getTarget) === null || _a === void 0 ? void 0 : _a.call(global, this));
654
+ if (objectsProp && axisProp && translateProp) {
655
+ const objectsValue = this.getValue(objectsProp, model);
656
+ const axisValue = this.getValue(axisProp);
657
+ const translateValue = this.getValue(translateProp);
658
+ if (objectsValue) {
659
+ const positions = [];
660
+ const duration = 800;
661
+ objectHandle$2(objectsValue, obj => {
662
+ positions.push(obj.position.clone());
663
+ });
664
+ const onUpdate = (position, current) => {
665
+ switch (axisValue) {
666
+ case 'x':
667
+ position.setX(current.x);
668
+ break;
669
+ case 'y':
670
+ position.setY(current.y);
671
+ break;
672
+ case 'z':
673
+ position.setZ(current.z);
674
+ break;
675
+ }
676
+ };
677
+ const handler = async () => {
678
+ const res = objectHandle$2(objectsValue, async (obj) => {
679
+ const position = obj.position.clone();
680
+ switch (axisValue) {
681
+ case 'x':
682
+ await this.ssp.animation(position, new Vector3().set(position.x + translateValue, position.y, position.z), { duration, }, (e) => onUpdate(obj.position, e));
683
+ break;
684
+ case 'y':
685
+ await this.ssp.animation(position, new Vector3().set(position.x, position.y + translateValue, position.z), { duration, }, (e) => onUpdate(obj.position, e));
686
+ break;
687
+ case 'z':
688
+ await this.ssp.animation(position, new Vector3().set(position.x, position.y, position.z + translateValue), { duration, }, (e) => onUpdate(obj.position, e));
689
+ break;
690
+ }
691
+ });
692
+ if (res instanceof Array) {
693
+ await Promise.all(res);
694
+ }
695
+ else {
696
+ await res;
697
+ }
698
+ this.ssp.render();
699
+ };
700
+ await handler();
701
+ this.cleanSets.add(() => {
702
+ let i = 0;
703
+ objectHandle$2(objectsValue, obj => {
704
+ obj.position.copy(positions[i++]);
705
+ });
706
+ });
707
+ }
708
+ }
709
+ }
710
+ }
711
+
712
+ const { objectHandle: objectHandle$1, } = SoonSpace.utils;
713
+ class ScaleNode extends Node {
714
+ constructor(parser, node) {
715
+ super(parser, node);
716
+ }
717
+ async exec(global) {
718
+ var _a;
719
+ const objectsProp = this.findProp('objects', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
720
+ const axisProp = this.findProp('axis', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
721
+ const scaleProp = this.findProp('scale', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
722
+ const model = await ((_a = global.getTarget) === null || _a === void 0 ? void 0 : _a.call(global, this));
723
+ if (objectsProp && axisProp && scaleProp) {
724
+ const objectsValue = this.getValue(objectsProp, model);
725
+ const axisValue = this.getValue(axisProp);
726
+ const scaleValue = this.getValue(scaleProp);
727
+ if (objectsValue) {
728
+ const scales = [];
729
+ const duration = 800;
730
+ objectHandle$1(objectsValue, obj => {
731
+ scales.push(obj.scale.clone());
732
+ });
733
+ const onUpdate = (scale, current) => {
734
+ switch (axisValue) {
735
+ case 'x':
736
+ scale.setX(current.x);
737
+ break;
738
+ case 'y':
739
+ scale.setY(current.y);
740
+ break;
741
+ case 'z':
742
+ scale.setZ(current.z);
743
+ break;
744
+ }
745
+ };
746
+ const handler = async () => {
747
+ const res = objectHandle$1(objectsValue, async (obj) => {
748
+ const scal = obj.scale.clone();
749
+ switch (axisValue) {
750
+ case 'x':
751
+ await this.ssp.animation(scal, new Vector3().set(scal.x * scaleValue, scal.y, scal.z), { duration, }, (e) => onUpdate(obj.scale, e));
752
+ break;
753
+ case 'y':
754
+ await this.ssp.animation(scal, new Vector3().set(scal.x, scal.y * scaleValue, scal.z), { duration, }, (e) => onUpdate(obj.scale, e));
755
+ break;
756
+ case 'z':
757
+ await this.ssp.animation(scal, new Vector3().set(scal.x, scal.y, scal.z * scaleValue), { duration, }, (e) => onUpdate(obj.scale, e));
758
+ break;
759
+ }
760
+ });
761
+ if (res instanceof Array) {
762
+ await Promise.all(res);
763
+ }
764
+ else {
765
+ await res;
766
+ }
767
+ this.ssp.render();
768
+ };
769
+ await handler();
770
+ this.cleanSets.add(() => {
771
+ let i = 0;
772
+ objectHandle$1(objectsValue, obj => {
773
+ obj.scale.copy(scales[i++]);
774
+ });
775
+ });
776
+ }
777
+ }
778
+ }
779
+ }
780
+
781
+ const { objectHandle, } = SoonSpace.utils;
782
+ class RotateNode extends Node {
783
+ constructor(parser, node) {
784
+ super(parser, node);
785
+ }
786
+ async exec(global) {
787
+ var _a;
788
+ const objectsProp = this.findProp('objects', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
789
+ const axisProp = this.findProp('axis', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
790
+ const rotationProp = this.findProp('rotation', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
791
+ const model = await ((_a = global.getTarget) === null || _a === void 0 ? void 0 : _a.call(global, this));
792
+ if (objectsProp && axisProp && rotationProp) {
793
+ const objectsValue = this.getValue(objectsProp, model);
794
+ const axisValue = this.getValue(axisProp);
795
+ const rotationValue = this.getValue(rotationProp);
796
+ if (objectsValue) {
797
+ const rotations = [];
798
+ const duration = 800;
799
+ objectHandle(objectsValue, obj => {
800
+ rotations.push(obj.rotation.clone());
801
+ });
802
+ const onUpdate = (rotation, current) => {
803
+ switch (axisValue) {
804
+ case 'x':
805
+ rotation.x = current.x;
806
+ break;
807
+ case 'y':
808
+ rotation.y = current.y;
809
+ break;
810
+ case 'z':
811
+ rotation.z = current.z;
812
+ break;
813
+ }
814
+ };
815
+ const handler = async () => {
816
+ const rad = rotationValue / 180 * Math.PI;
817
+ const res = objectHandle(objectsValue, async (obj) => {
818
+ const rotation = obj.rotation.clone();
819
+ switch (axisValue) {
820
+ case 'x':
821
+ await this.ssp.animation(rotation, new Euler().set(rotation.x + rad, rotation.y, rotation.z), { duration, }, (e) => onUpdate(obj.rotation, e));
822
+ break;
823
+ case 'y':
824
+ await this.ssp.animation(rotation, new Euler().set(rotation.x, rotation.y + rad, rotation.z), { duration, }, (e) => onUpdate(obj.rotation, e));
825
+ break;
826
+ case 'z':
827
+ await this.ssp.animation(rotation, new Euler().set(rotation.x, rotation.y, rotation.z + rad), { duration, }, (e) => onUpdate(obj.rotation, e));
828
+ break;
829
+ }
830
+ });
831
+ if (res instanceof Array) {
832
+ await Promise.all(res);
833
+ }
834
+ else {
835
+ await res;
836
+ }
837
+ this.ssp.render();
838
+ };
839
+ await handler();
840
+ this.cleanSets.add(() => {
841
+ let i = 0;
842
+ objectHandle(objectsValue, obj => {
843
+ obj.rotation.copy(rotations[i++]);
844
+ });
845
+ });
846
+ }
847
+ }
848
+ }
849
+ }
850
+
851
+ class FlyToNode extends Node {
852
+ constructor(parser, node) {
853
+ super(parser, node);
854
+ }
855
+ async exec() {
856
+ const viewpointProp = this.findProp('viewpoint', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
857
+ if (viewpointProp) {
858
+ const viewpointValue = parseValue(this.getValue(viewpointProp));
859
+ if (viewpointValue) {
860
+ // const oldViewpoint = this.ssp.getCameraViewpoint()
861
+ this.ssp.setCameraViewpoint(viewpointValue, true);
862
+ // this.cleanSets.add( () => this.ssp.setCameraViewpoint( oldViewpoint ) )
863
+ }
864
+ }
865
+ }
866
+ }
867
+
868
+ class SpaceNode extends Node {
869
+ constructor(parser, node) {
870
+ super(parser, node);
871
+ }
872
+ async exec() {
873
+ const spaceProp = this.findProp('space', NodePropTypeEnum.LOCAL);
874
+ const outProp = this.findProp('out', NodePropTypeEnum.WRITE_CTX);
875
+ if (spaceProp && outProp) {
876
+ const spaceValue = parseValue(spaceProp.value);
877
+ const outValue = parseValue(outProp.value);
878
+ this.writeContext(outValue, getObjectById(this.ssp, spaceValue));
879
+ }
880
+ }
881
+ }
882
+
883
+ class SpacesNode extends Node {
884
+ constructor(parser, node) {
885
+ super(parser, node);
886
+ }
887
+ async exec() {
888
+ const spaceProp = this.findProp('spaces', NodePropTypeEnum.LOCAL);
889
+ const outProp = this.findProp('out', NodePropTypeEnum.WRITE_CTX);
890
+ if (spaceProp && outProp) {
891
+ const spacesValue = parseValue(spaceProp.value);
892
+ const outValue = parseValue(outProp.value);
893
+ const spaces = spacesValue.map(item => getObjectById(this.ssp, item));
894
+ this.writeContext(outValue, spaces);
895
+ }
896
+ }
897
+ }
898
+
899
+ class POINode extends Node {
900
+ constructor(parser, node) {
901
+ super(parser, node);
902
+ }
903
+ async exec(global) {
904
+ const POIProp = this.findProp('poi', NodePropTypeEnum.LOCAL);
905
+ const outProp = this.findProp('out', NodePropTypeEnum.WRITE_CTX);
906
+ if (POIProp && outProp) {
907
+ const POIValue = parseValue(POIProp.value);
908
+ const outValue = parseValue(outProp.value);
909
+ this.writeContext(outValue, getObjectById(this.ssp, POIValue));
910
+ }
911
+ }
912
+ }
913
+
914
+ class POIsNode extends Node {
915
+ constructor(parser, node) {
916
+ super(parser, node);
917
+ }
918
+ async exec(global) {
919
+ const POIsProp = this.findProp('pois', NodePropTypeEnum.LOCAL);
920
+ const outProp = this.findProp('out', NodePropTypeEnum.WRITE_CTX);
921
+ if (POIsProp && outProp) {
922
+ const POIsValue = parseValue(POIsProp.value);
923
+ const outValue = parseValue(outProp.value);
924
+ const POIs = POIsValue.map(item => getObjectById(this.ssp, item));
925
+ this.writeContext(outValue, POIs);
926
+ }
927
+ }
928
+ }
929
+
930
+ class DataExtractionNode extends Node {
931
+ constructor(parser, node) {
932
+ super(parser, node);
933
+ }
934
+ async exec() {
935
+ const modelProp = this.findProp('value', NodePropTypeEnum.LOCAL);
936
+ const outProp = this.findProp('out', NodePropTypeEnum.WRITE_CTX);
937
+ if (modelProp && outProp) {
938
+ const modelValue = parseValue(modelProp.value);
939
+ const outValue = parseValue(outProp.value);
940
+ this.writeContext(outValue, modelValue);
941
+ }
942
+ }
943
+ }
944
+
945
+ class DataFilterNode extends Node {
946
+ constructor(parser, node) {
947
+ super(parser, node);
948
+ }
949
+ async exec() {
950
+ const filterProp = this.findProp('model', NodePropTypeEnum.LOCAL);
951
+ if (filterProp) {
952
+ const conditionValue = parseValue(filterProp.value);
953
+ const fn = new Function('sourceData', conditionValue);
954
+ for (const key in this.ctx) {
955
+ const res = fn(this.ctx[key]);
956
+ if (res === undefined || res === null || res === false) {
957
+ delete this.ctx[key];
958
+ }
959
+ }
960
+ }
961
+ }
962
+ }
963
+
964
+ class PathNode extends Node {
965
+ constructor(parser, node) {
966
+ super(parser, node);
967
+ }
968
+ async exec() {
969
+ const pathProp = this.findProp('path', NodePropTypeEnum.LOCAL);
970
+ const outProp = this.findProp('out', NodePropTypeEnum.WRITE_CTX);
971
+ if (pathProp && outProp) {
972
+ const pathValue = parseValue(pathProp.value);
973
+ const outValue = parseValue(outProp.value);
974
+ this.writeContext(outValue, getObjectById(this.ssp, pathValue));
975
+ }
976
+ }
977
+ }
978
+
979
+ class PathsNode extends Node {
980
+ constructor(parser, node) {
981
+ super(parser, node);
982
+ }
983
+ async exec() {
984
+ const pathsProp = this.findProp('paths', NodePropTypeEnum.LOCAL);
985
+ const outProp = this.findProp('out', NodePropTypeEnum.WRITE_CTX);
986
+ if (pathsProp && outProp) {
987
+ const pathsValue = parseValue(pathsProp.value);
988
+ const outValue = parseValue(outProp.value);
989
+ const paths = pathsValue.map(item => getObjectById(this.ssp, item));
990
+ this.writeContext(outValue, paths);
991
+ }
992
+ }
993
+ }
994
+
995
+ class ClipAnimationNode extends Node {
996
+ constructor(parser, node) {
997
+ super(parser, node);
998
+ }
999
+ async exec(global) {
1000
+ var _a;
1001
+ let target = await ((_a = global.getTarget) === null || _a === void 0 ? void 0 : _a.call(global, this));
1002
+ if (!target) {
1003
+ const objectProp = this.findProp('model', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
1004
+ if (objectProp) {
1005
+ target = this.getValue(objectProp);
1006
+ }
1007
+ }
1008
+ const animationProp = this.findProp('animation', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
1009
+ if (target && animationProp) {
1010
+ let animationValue;
1011
+ if (animationProp.type === NodePropTypeEnum.READ_CTX) {
1012
+ const variableName = this.parser.getVariableNameById(parseValue(animationProp.value));
1013
+ animationValue = this.readContext(variableName);
1014
+ }
1015
+ else {
1016
+ animationValue = parseValue(animationProp.value);
1017
+ }
1018
+ const foundClip = target.animations[animationValue];
1019
+ if (foundClip) {
1020
+ this.ssp.playModelAnimation(target, foundClip);
1021
+ this.cleanSets.add(() => {
1022
+ this.ssp.stopModelAnimation(target, foundClip);
1023
+ });
1024
+ }
1025
+ }
1026
+ }
1027
+ }
1028
+
1029
+ class UnClipAnimationNode extends Node {
1030
+ constructor(parser, node) {
1031
+ super(parser, node);
1032
+ }
1033
+ async exec(global) {
1034
+ var _a;
1035
+ let target = await ((_a = global.getTarget) === null || _a === void 0 ? void 0 : _a.call(global, this));
1036
+ if (!target) {
1037
+ const objectProp = this.findProp('model', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
1038
+ if (objectProp) {
1039
+ target = this.getValue(objectProp);
1040
+ }
1041
+ }
1042
+ const animationProp = this.findProp('animation', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
1043
+ if (target && animationProp) {
1044
+ let animationValue;
1045
+ if (animationProp.type === NodePropTypeEnum.READ_CTX) {
1046
+ const variableName = this.parser.getVariableNameById(parseValue(animationProp.value));
1047
+ animationValue = this.readContext(variableName);
1048
+ }
1049
+ else {
1050
+ animationValue = parseValue(animationProp.value);
1051
+ }
1052
+ const foundClip = target.animations[animationValue];
1053
+ if (foundClip)
1054
+ this.ssp.stopModelAnimation(target, foundClip);
1055
+ }
1056
+ }
1057
+ }
1058
+
1059
+ const tweenCache$1 = new Map();
1060
+ async function playTweenAnimation(ssp, object, animation) {
1061
+ var _a;
1062
+ const { id, keyframes, } = animation;
1063
+ const player = new AnimationPlayer(ssp, object);
1064
+ if (!tweenCache$1.has(id)) {
1065
+ tweenCache$1.set(id, new Set());
1066
+ }
1067
+ (_a = tweenCache$1.get(id)) === null || _a === void 0 ? void 0 : _a.add(player);
1068
+ await player.play(keyframes);
1069
+ }
1070
+ function stopTweenAnimation(animationId) {
1071
+ var _a, _b;
1072
+ (_a = tweenCache$1.get(animationId)) === null || _a === void 0 ? void 0 : _a.forEach(player => player.stop());
1073
+ (_b = tweenCache$1.get(animationId)) === null || _b === void 0 ? void 0 : _b.clear();
1074
+ }
1075
+
1076
+ class TweenAnimationNode extends Node {
1077
+ constructor(parser, node) {
1078
+ super(parser, node);
1079
+ }
1080
+ async exec(global) {
1081
+ var _a;
1082
+ const objectProp = this.findProp('model', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
1083
+ const animationProp = this.findProp('animation', NodePropTypeEnum.LOCAL);
1084
+ const waitProp = this.findProp('wait', NodePropTypeEnum.LOCAL);
1085
+ if (objectProp && animationProp && waitProp) {
1086
+ const objectValue = this.getValue(objectProp);
1087
+ const animationValue = parseValue(animationProp.value);
1088
+ const waitValue = parseValue(waitProp.value);
1089
+ if (objectValue) {
1090
+ const animations = await ((_a = global.getAnimations) === null || _a === void 0 ? void 0 : _a.call(global, this, objectValue, animationValue));
1091
+ if (animations) {
1092
+ const foundComponentAnimation = animations.find(c => c.id === animationValue);
1093
+ if (foundComponentAnimation) {
1094
+ await waitFor(async () => {
1095
+ const beforeMatrix = objectValue.matrix.clone();
1096
+ await playTweenAnimation(this.ssp, objectValue, foundComponentAnimation);
1097
+ this.cleanSets.add(() => {
1098
+ stopTweenAnimation(foundComponentAnimation.id);
1099
+ if (objectValue)
1100
+ beforeMatrix.decompose(objectValue.position, objectValue.quaternion, objectValue.scale);
1101
+ });
1102
+ }, waitValue);
1103
+ }
1104
+ }
1105
+ }
1106
+ }
1107
+ }
1108
+ }
1109
+
1110
+ class UnTweenAnimationNode extends Node {
1111
+ constructor(parser, node) {
1112
+ super(parser, node);
1113
+ }
1114
+ async exec() {
1115
+ const animationProp = this.findProp('animation', NodePropTypeEnum.LOCAL);
1116
+ if (animationProp) {
1117
+ const animationValue = parseValue(animationProp.value);
1118
+ stopTweenAnimation(animationValue);
1119
+ }
1120
+ }
1121
+ }
1122
+
1123
+ const tweenCache = new Map();
1124
+ async function playComponentTweenAnimation(ssp, object, componentAnimation) {
1125
+ var _a;
1126
+ const { id, keyframes, } = componentAnimation;
1127
+ const player = new AnimationPlayer(ssp, object);
1128
+ if (!tweenCache.has(id)) {
1129
+ tweenCache.set(id, new Set());
1130
+ }
1131
+ (_a = tweenCache.get(id)) === null || _a === void 0 ? void 0 : _a.add(player);
1132
+ await player.play(keyframes);
1133
+ }
1134
+ function stopComponentTweenAnimation(animationId) {
1135
+ var _a, _b;
1136
+ (_a = tweenCache.get(animationId)) === null || _a === void 0 ? void 0 : _a.forEach(player => player.stop());
1137
+ (_b = tweenCache.get(animationId)) === null || _b === void 0 ? void 0 : _b.clear();
1138
+ }
1139
+
1140
+ class ComponentTweenAnimationNode extends Node {
1141
+ constructor(parser, node) {
1142
+ super(parser, node);
1143
+ }
1144
+ async exec(global) {
1145
+ var _a;
1146
+ const objectProp = this.findProp('mesh', [NodePropTypeEnum.READ_CTX, NodePropTypeEnum.LOCAL]);
1147
+ const animationProp = this.findProp('animation', NodePropTypeEnum.LOCAL);
1148
+ const waitProp = this.findProp('wait', NodePropTypeEnum.LOCAL);
1149
+ if (objectProp && animationProp && waitProp) {
1150
+ const objectValue = this.getValue(objectProp);
1151
+ const animationValue = parseValue(animationProp.value);
1152
+ const waitValue = parseValue(waitProp.value);
1153
+ if (objectValue) {
1154
+ const componentAnimations = await ((_a = global.getComponentAnimations) === null || _a === void 0 ? void 0 : _a.call(global, this, objectValue, animationValue));
1155
+ if (componentAnimations) {
1156
+ const foundComponentAnimation = componentAnimations.find(c => c.id === animationValue);
1157
+ if (foundComponentAnimation) {
1158
+ let animationTarget = null;
1159
+ // valueType 可能是 mesh | model
1160
+ // mesh 直接从上下文中获取,model 从上下文中获取后,再获取 mesh 对象
1161
+ if (objectProp.valueType === 'Mesh') {
1162
+ animationTarget = objectValue;
1163
+ }
1164
+ else if (objectProp.valueType === 'Model') {
1165
+ animationTarget = getMeshByUserDataUuid(objectValue, foundComponentAnimation.refId);
1166
+ }
1167
+ if (animationTarget) {
1168
+ await waitFor(async () => {
1169
+ if (animationTarget) {
1170
+ const beforeMatrix = animationTarget.matrix.clone();
1171
+ await playComponentTweenAnimation(this.ssp, animationTarget, foundComponentAnimation);
1172
+ this.cleanSets.add(() => {
1173
+ stopComponentTweenAnimation(foundComponentAnimation.id);
1174
+ if (animationTarget)
1175
+ beforeMatrix.decompose(animationTarget.position, animationTarget.quaternion, animationTarget.scale);
1176
+ });
1177
+ }
1178
+ }, waitValue);
1179
+ }
1180
+ }
1181
+ }
1182
+ }
1183
+ }
1184
+ }
1185
+ }
1186
+
1187
+ class UnComponentTweenAnimationNode extends Node {
1188
+ constructor(parser, node) {
1189
+ super(parser, node);
1190
+ }
1191
+ async exec() {
1192
+ const animationProp = this.findProp('animation', NodePropTypeEnum.LOCAL);
1193
+ if (animationProp) {
1194
+ // id
1195
+ const animationValue = parseValue(animationProp.value);
1196
+ stopComponentTweenAnimation(animationValue);
1197
+ }
1198
+ }
1199
+ }
1200
+
1201
+ function parseNodeByType(parser, node) {
1202
+ switch (node.type) {
1203
+ case NodeTypeEnum.START:
1204
+ return new StartNode(parser, node);
1205
+ case NodeTypeEnum.COLOR:
1206
+ return new ColorNode(parser, node);
1207
+ case NodeTypeEnum.NUMBER:
1208
+ return new NumberNode(parser, node);
1209
+ case NodeTypeEnum.HIGHLIGHT:
1210
+ return new HighlightNode(parser, node);
1211
+ case NodeTypeEnum.UN_HIGHLIGHT:
1212
+ return new UnHighlightNode(parser, node);
1213
+ case NodeTypeEnum.OPACITY:
1214
+ return new OpacityNode(parser, node);
1215
+ case NodeTypeEnum.UN_OPACITY:
1216
+ return new UnOpacityNode(parser, node);
1217
+ case NodeTypeEnum.EMISSIVE:
1218
+ return new EmissiveNode(parser, node);
1219
+ case NodeTypeEnum.UN_EMISSIVE:
1220
+ return new UnEmissiveNode(parser, node);
1221
+ // 获取对象
1222
+ case NodeTypeEnum.MESH:
1223
+ return new MeshNode(parser, node);
1224
+ case NodeTypeEnum.MESHES:
1225
+ return new MeshesNode(parser, node);
1226
+ case NodeTypeEnum.MODEL:
1227
+ return new ModelNode(parser, node);
1228
+ case NodeTypeEnum.MODELS:
1229
+ return new ModelsNode(parser, node);
1230
+ case NodeTypeEnum.SPACE:
1231
+ return new SpaceNode(parser, node);
1232
+ case NodeTypeEnum.SPACES:
1233
+ return new SpacesNode(parser, node);
1234
+ case NodeTypeEnum.POIS:
1235
+ return new POIsNode(parser, node);
1236
+ case NodeTypeEnum.POI:
1237
+ return new POINode(parser, node);
1238
+ case NodeTypeEnum.PATH:
1239
+ return new PathNode(parser, node);
1240
+ case NodeTypeEnum.PATHS:
1241
+ return new PathsNode(parser, node);
1242
+ // 逻辑节点
1243
+ case NodeTypeEnum.DELAY:
1244
+ return new DelayNode(parser, node);
1245
+ case NodeTypeEnum.CONDITION_NODE:
1246
+ return new ConditionNode(parser, node);
1247
+ // 显示隐藏
1248
+ case NodeTypeEnum.SHOW:
1249
+ return new ShowNode(parser, node);
1250
+ case NodeTypeEnum.HIDE:
1251
+ return new HideNode(parser, node);
1252
+ // 动画相关
1253
+ case NodeTypeEnum.CLIP_ANIMATION:
1254
+ return new ClipAnimationNode(parser, node);
1255
+ case NodeTypeEnum.UN_CLIP_ANIMATION:
1256
+ return new UnClipAnimationNode(parser, node);
1257
+ case NodeTypeEnum.TWEEN_ANIMATION:
1258
+ return new TweenAnimationNode(parser, node);
1259
+ case NodeTypeEnum.UN_TWEEN_ANIMATION:
1260
+ return new UnTweenAnimationNode(parser, node);
1261
+ case NodeTypeEnum.COMPONENT_TWEEN_ANIMATION:
1262
+ return new ComponentTweenAnimationNode(parser, node);
1263
+ case NodeTypeEnum.UN_COMPONENT_TWEEN_ANIMATION:
1264
+ return new UnComponentTweenAnimationNode(parser, node);
1265
+ // 移动
1266
+ case NodeTypeEnum.TRANSLATE:
1267
+ return new TranslateNode(parser, node);
1268
+ case NodeTypeEnum.ROTATE:
1269
+ return new RotateNode(parser, node);
1270
+ case NodeTypeEnum.SCALE:
1271
+ return new ScaleNode(parser, node);
1272
+ case NodeTypeEnum.FLY_TO:
1273
+ return new FlyToNode(parser, node);
1274
+ // 数据处理节点
1275
+ case NodeTypeEnum.DATA_EXTRACTION:
1276
+ return new DataExtractionNode(parser, node);
1277
+ case NodeTypeEnum.DATA_FILTER:
1278
+ return new DataFilterNode(parser, node);
1279
+ default:
1280
+ return new Node(parser, node);
1281
+ }
1282
+ }
1283
+ function parseValue(value) {
1284
+ return JSON.parse(value);
1285
+ }
1286
+ async function waitFor(fn, wait) {
1287
+ if (wait) {
1288
+ await fn();
1289
+ }
1290
+ else {
1291
+ fn();
1292
+ }
1293
+ }
1294
+ function getObjectByIds(ssp, ids) {
1295
+ return ids.map(id => ssp.getObjectById(id)).filter(Boolean);
1296
+ }
1297
+ function getObjectById(ssp, id, object) {
1298
+ const obj = ssp.getObjectById(id);
1299
+ if (obj) {
1300
+ return obj;
1301
+ }
1302
+ else {
1303
+ const { viewport: { scene, }, } = ssp;
1304
+ return getMeshByUserDataUuid(object !== null && object !== void 0 ? object : scene, id);
1305
+ }
1306
+ }
1307
+ function getMeshByUserDataUuid(object, uuid) {
1308
+ // 组件编辑内写入 key
1309
+ if (object.userData.key === uuid || object.uuid === uuid)
1310
+ return object;
1311
+ for (let i = 0, l = object.children.length; i < l; i++) {
1312
+ const child = object.children[i];
1313
+ const _object = getMeshByUserDataUuid(child, uuid);
1314
+ if (_object !== null) {
1315
+ return _object;
1316
+ }
1317
+ }
1318
+ return null;
1319
+ }
1320
+
1321
+ const { utils: { sleep, }, } = SoonSpace;
1322
+ class FlowParser extends EventDispatcher {
1323
+ constructor(ssp, flow) {
1324
+ super();
1325
+ this.onNodeBefore = null;
1326
+ this.onNodeAfter = null;
1327
+ this.ssp = ssp;
1328
+ this.flow = flow;
1329
+ this.nodes = [];
1330
+ this.nodesMap = new Map();
1331
+ this.edges = [];
1332
+ this.edgesMap = new Map();
1333
+ }
1334
+ addNode(node) {
1335
+ this.nodes.push(node);
1336
+ this.nodesMap.set(node.id, node);
1337
+ }
1338
+ addEdge(edge) {
1339
+ this.edges.push(edge);
1340
+ this.edgesMap.set(edge.id, edge);
1341
+ }
1342
+ getNodeById(id) {
1343
+ return this.nodesMap.get(id);
1344
+ }
1345
+ getEdgeById(id) {
1346
+ return this.edgesMap.get(id);
1347
+ }
1348
+ clear() {
1349
+ this.nodes.length = 0;
1350
+ this.nodesMap.clear();
1351
+ this.edges.length = 0;
1352
+ this.edgesMap.clear();
1353
+ }
1354
+ /**
1355
+ * 解析流程
1356
+ */
1357
+ parse() {
1358
+ this.clear();
1359
+ const { nodes, edges, } = this.flow;
1360
+ nodes.forEach(node => {
1361
+ // 创建 Node 实例
1362
+ const nodeInstance = parseNodeByType(this, node);
1363
+ this.addNode(nodeInstance);
1364
+ });
1365
+ edges.forEach(edge => {
1366
+ // 创建 Edge 实例
1367
+ const edgeInstance = new Edge(edge);
1368
+ this.addEdge(edgeInstance);
1369
+ // 记录 Node 前后节点
1370
+ const sourceNode = this.getNodeById(edge.source);
1371
+ const targetNode = this.getNodeById(edge.target);
1372
+ if (sourceNode && targetNode) {
1373
+ sourceNode.postNodes.push(targetNode);
1374
+ targetNode.prevNodes.push(sourceNode);
1375
+ }
1376
+ });
1377
+ }
1378
+ /**
1379
+ * 执行流程
1380
+ * @param startNode
1381
+ * @param ctx
1382
+ */
1383
+ async run(global = {}) {
1384
+ const nodes = this.nodes.filter((node) => node.prevNodes.length || node.postNodes.length);
1385
+ const tasks = nodes.map((node) => node.run(global));
1386
+ await Promise.allSettled(tasks);
1387
+ }
1388
+ /**
1389
+ * 调试流程
1390
+ */
1391
+ async debug(global = {}, time = 1500) {
1392
+ const onNodeAfter = this.onNodeAfter;
1393
+ this.onNodeAfter = async (node) => {
1394
+ await sleep(time);
1395
+ onNodeAfter === null || onNodeAfter === void 0 ? void 0 : onNodeAfter(node);
1396
+ };
1397
+ await this.run(global);
1398
+ }
1399
+ /**
1400
+ * 停止流程
1401
+ */
1402
+ stop() {
1403
+ this.nodes.forEach(node => node.reject(new Error('Flow stopped')));
1404
+ }
1405
+ /**
1406
+ * 清理流程
1407
+ */
1408
+ cleanup() {
1409
+ this.nodes
1410
+ .sort((a, b) => b.execOrder - a.execOrder)
1411
+ .forEach((node) => node.cleanup());
1412
+ }
1413
+ getVariableNameById(id) {
1414
+ const node = this.nodes.find(node => node.id === id);
1415
+ if (node) {
1416
+ const prop = node.props.find(prop => prop.name === 'out');
1417
+ return prop ? parseValue(prop.value) : null;
1418
+ }
1419
+ return null;
1420
+ }
1421
+ dispose() {
1422
+ this.stop();
1423
+ this.cleanup();
1424
+ }
1425
+ }
1426
+
1427
+ class ComponentFlowParser extends FlowParser {
1428
+ constructor(ssp, flow) {
1429
+ super(ssp, flow);
1430
+ this.flow = flow;
1431
+ }
1432
+ }
1433
+
1434
+ /******************************************************************************
1435
+ Copyright (c) Microsoft Corporation.
1436
+
1437
+ Permission to use, copy, modify, and/or distribute this software for any
1438
+ purpose with or without fee is hereby granted.
1439
+
1440
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1441
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1442
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1443
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1444
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1445
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1446
+ PERFORMANCE OF THIS SOFTWARE.
1447
+ ***************************************************************************** */
1448
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
1449
+
1450
+
1451
+ function __classPrivateFieldGet(receiver, state, kind, f) {
1452
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1453
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1454
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1455
+ }
1456
+
1457
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1458
+ var e = new Error(message);
1459
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1460
+ };
1461
+
1462
+ var ObjecType;
1463
+ (function (ObjecType) {
1464
+ ObjecType["Group"] = "Group";
1465
+ ObjecType["Light"] = "Light";
1466
+ ObjecType["Model"] = "Model";
1467
+ ObjecType["Poi"] = "Poi";
1468
+ ObjecType["PoiNode"] = "PoiNode";
1469
+ ObjecType["Canvas3D"] = "Canvas3D";
1470
+ ObjecType["Topology"] = "Topology";
1471
+ ObjecType["Helper"] = "Helper";
1472
+ ObjecType["Decal"] = "Decal";
1473
+ ObjecType["PluginObject"] = "PluginObject";
1474
+ })(ObjecType || (ObjecType = {}));
1475
+ var ModelFormat;
1476
+ (function (ModelFormat) {
1477
+ ModelFormat["sbm"] = "SBM";
1478
+ ModelFormat["sbmx"] = "SBMX";
1479
+ ModelFormat["glb"] = "GLB";
1480
+ ModelFormat["gltf"] = "GLTF";
1481
+ ModelFormat["fbx"] = "FBX";
1482
+ ModelFormat["obj"] = "OBJ";
1483
+ ModelFormat["stl"] = "STL";
1484
+ })(ModelFormat || (ModelFormat = {}));
1485
+
1486
+ new Vector3();
1487
+ new Vector3();
1488
+ new Vector3();
1489
+
1490
+ const FileRequestHeaders = {};
1491
+
1492
+ const fileLoader = new FileLoader();
1493
+ fileLoader.setRequestHeader(FileRequestHeaders);
1494
+ const imageLoader = new ImageLoader();
1495
+ imageLoader.load = (url, onLoad, onProgress, onError) => {
1496
+ const image = new Image();
1497
+ fileLoader.setResponseType('blob');
1498
+ fileLoader.load(url, function (blob) {
1499
+ image.src = URL.createObjectURL(blob);
1500
+ image.onload = () => {
1501
+ URL.revokeObjectURL(image.src);
1502
+ onLoad === null || onLoad === void 0 ? void 0 : onLoad(image);
1503
+ };
1504
+ }, onProgress, onError);
1505
+ return image;
1506
+ };
1507
+ const textureLoader = new TextureLoader();
1508
+ textureLoader.setRequestHeader(FileRequestHeaders);
1509
+ const rgbeLoader = new RGBELoader();
1510
+ rgbeLoader.setRequestHeader(FileRequestHeaders);
1511
+
1512
+ new Vector3();
1513
+ new Vector3();
1514
+ new Vector3();
1515
+
1516
+ async function asyncRunWithCtx(source, fn) {
1517
+ const result = await fn();
1518
+ return result;
1519
+ }
1520
+ async function asyncRunWithCode(fn) {
1521
+ return asyncRunWithCtx('code', fn);
1522
+ }
1523
+
1524
+ const findObjectFromTarget = (target, key) => {
1525
+ if (target.userData.key === key) {
1526
+ return true;
1527
+ }
1528
+ else {
1529
+ if (target.parent)
1530
+ return findObjectFromTarget(target.parent, key);
1531
+ return false;
1532
+ }
1533
+ };
1534
+
1535
+ var _Trigger_instances, _Trigger_init, _Trigger_getObsTarget;
1536
+ const { groupBy: groupBy$1, } = SoonSpace.utils;
1537
+ class Trigger {
1538
+ constructor(ssp, interaction, flows, options) {
1539
+ _Trigger_instances.add(this);
1540
+ this.disposables = [];
1541
+ this.status = 'ready';
1542
+ this.ssp = ssp;
1543
+ // this.target = target
1544
+ this.interaction = interaction;
1545
+ this.flows = flows;
1546
+ this.flowsMap = groupBy$1(flows, 'id');
1547
+ this.options = options || {};
1548
+ __classPrivateFieldGet(this, _Trigger_instances, "m", _Trigger_init).call(this);
1549
+ }
1550
+ // 模型事件触发
1551
+ modelHandler(params) {
1552
+ var _a;
1553
+ const { target, currentTarget, } = params;
1554
+ const editionId = this.interaction.editionId;
1555
+ if (editionId) {
1556
+ // 组件交互
1557
+ if ((target.sid === editionId || target.userData.familyId === editionId) &&
1558
+ findObjectFromTarget(currentTarget, this.interaction.modelId)) {
1559
+ this.target = target;
1560
+ this.execBehavior();
1561
+ }
1562
+ }
1563
+ else {
1564
+ (_a = this.interaction.obsTargets) === null || _a === void 0 ? void 0 : _a.forEach(targetKey => {
1565
+ if (targetKey === target.userData.id || targetKey === target.userData.sid) {
1566
+ this.target = target;
1567
+ this.execBehavior();
1568
+ }
1569
+ });
1570
+ }
1571
+ }
1572
+ runFlowByIds(flowIds) {
1573
+ const getTarget = this.target ? async () => this.target : __classPrivateFieldGet(this, _Trigger_instances, "m", _Trigger_getObsTarget).bind(this);
1574
+ flowIds.forEach(flowId => {
1575
+ const foundFlow = this.flowsMap.get(flowId);
1576
+ if (foundFlow) {
1577
+ const flow = new FlowParser$1(this.ssp, foundFlow[0]);
1578
+ flow.parse();
1579
+ // todo 确定ctx 包转具体位置
1580
+ asyncRunWithCode(() => flow.run({
1581
+ getTarget: getTarget,
1582
+ getAnimations: this.options.getAnimations,
1583
+ getComponentAnimations: this.options.getComponentAnimations,
1584
+ }));
1585
+ }
1586
+ });
1587
+ }
1588
+ async execBehavior() {
1589
+ var _a, _b, _c, _d, _e;
1590
+ const active = (_a = this.interaction.active) !== null && _a !== void 0 ? _a : true;
1591
+ if (!active)
1592
+ return;
1593
+ try {
1594
+ this.status = 'running';
1595
+ const { behaviors, } = this.interaction;
1596
+ behaviors === null || behaviors === void 0 ? void 0 : behaviors.forEach(behavior => {
1597
+ switch (behavior.action) {
1598
+ case InteractionAction$1.FLOW:
1599
+ if (behavior.actionRefs)
1600
+ this.runFlowByIds(behavior.actionRefs);
1601
+ break;
1602
+ }
1603
+ });
1604
+ ((_b = this.options) === null || _b === void 0 ? void 0 : _b.onTrigger) && ((_c = this.options) === null || _c === void 0 ? void 0 : _c.onTrigger(this.interaction));
1605
+ }
1606
+ catch (e) {
1607
+ this.status = 'error';
1608
+ ((_d = this.options) === null || _d === void 0 ? void 0 : _d.onError) && ((_e = this.options) === null || _e === void 0 ? void 0 : _e.onError(e));
1609
+ }
1610
+ }
1611
+ initMouseClick() {
1612
+ const modelHandler = this.modelHandler.bind(this);
1613
+ this.ssp.signals.modelClick.add(modelHandler);
1614
+ this.disposables.push(() => this.ssp.signals.modelClick.remove(modelHandler));
1615
+ }
1616
+ initMouseDbClick() {
1617
+ const modelHandler = this.modelHandler.bind(this);
1618
+ this.ssp.signals.modelDblClick.add(modelHandler);
1619
+ this.disposables.push(() => this.ssp.signals.modelDblClick.remove(modelHandler));
1620
+ }
1621
+ initMouseRightClick() {
1622
+ const modelHandler = this.modelHandler.bind(this);
1623
+ this.ssp.signals.modelRightClick.add(modelHandler);
1624
+ this.disposables.push(() => this.ssp.signals.modelRightClick.remove(modelHandler));
1625
+ }
1626
+ initLoaded() {
1627
+ const loadHandler = () => {
1628
+ this.execBehavior();
1629
+ };
1630
+ // todo 场景加载结束是否有信号或事件
1631
+ loadHandler();
1632
+ // this.ssp.viewport.scene.addEventListener( 'load', loadHandler )
1633
+ //
1634
+ // this.disposables.push( () => this.target.removeEventListener( 'load', loadHandler ) )
1635
+ }
1636
+ modelPropChangeHandler(properties) {
1637
+ var _a, _b;
1638
+ if (!((_a = properties === null || properties === void 0 ? void 0 : properties.target) === null || _a === void 0 ? void 0 : _a.refId)) {
1639
+ return;
1640
+ }
1641
+ // todo diff next and before
1642
+ // 流程节点修改的自定义属性不触发 交互流程
1643
+ if (this.ssp.utils.propertiesCtx.source === 'code') {
1644
+ return;
1645
+ }
1646
+ (_b = properties.target) === null || _b === void 0 ? void 0 : _b.refId;
1647
+ if (this.interaction.editionId) {
1648
+ this.target = this.ssp.getObjectByUserDataProperty('familyId', this.interaction.editionId)[0];
1649
+ }
1650
+ this.execBehavior();
1651
+ }
1652
+ initModelPropChange() {
1653
+ const modelPropChangeHandler = this.modelPropChangeHandler.bind(this);
1654
+ this.ssp.signals.propertiesChanged.add(modelPropChangeHandler);
1655
+ this.disposables.push(() => this.ssp.signals.propertiesChanged.remove(modelPropChangeHandler));
1656
+ }
1657
+ initThingPropChange() {
1658
+ // @todo
1659
+ }
1660
+ initThingEvent() {
1661
+ // @todo
1662
+ }
1663
+ dispose() {
1664
+ this.disposables.forEach(dispose => dispose());
1665
+ }
1666
+ }
1667
+ _Trigger_instances = new WeakSet(), _Trigger_init = function _Trigger_init() {
1668
+ switch (this.interaction.type) {
1669
+ case InteractionType$1.MOUSE_CLICK:
1670
+ this.initMouseClick();
1671
+ break;
1672
+ case InteractionType$1.MOUSE_DB_CLICK:
1673
+ this.initMouseDbClick();
1674
+ break;
1675
+ case InteractionType$1.MOUSE_RIGHT_CLICK:
1676
+ this.initMouseRightClick();
1677
+ break;
1678
+ case InteractionType$1.LOADED:
1679
+ this.initLoaded();
1680
+ break;
1681
+ case InteractionType$1.THING_PROP_CHANGE:
1682
+ this.initThingPropChange();
1683
+ break;
1684
+ case InteractionType$1.THING_EVENT:
1685
+ this.initThingEvent();
1686
+ break;
1687
+ case InteractionType$1.MODEL_PROP_CHANGE:
1688
+ this.initModelPropChange();
1689
+ break;
1690
+ }
1691
+ }, _Trigger_getObsTarget =
1692
+ // 获取交互触发
1693
+ async function _Trigger_getObsTarget(currentNode) {
1694
+ const { obsType, obsTargets, editionId, } = this.interaction;
1695
+ if (obsType === InteractionObsType$1.GLOBAL) {
1696
+ // return this.target
1697
+ return null;
1698
+ }
1699
+ if (obsType === InteractionObsType$1.INSTANCE) {
1700
+ let target;
1701
+ if (editionId) {
1702
+ target = this.ssp.getModelById(editionId);
1703
+ if (!target) {
1704
+ console.warn('Target not found:', editionId);
1705
+ }
1706
+ }
1707
+ else {
1708
+ target = obsTargets === null || obsTargets === void 0 ? void 0 : obsTargets.map(targetId => {
1709
+ const target = this.ssp.getModelById(targetId);
1710
+ if (!target) {
1711
+ console.warn('Target not found:', obsTargets[0]);
1712
+ }
1713
+ return target;
1714
+ })[0];
1715
+ }
1716
+ }
1717
+ return null;
1718
+ };
1719
+
1720
+ var InteractionActionType;
1721
+ (function (InteractionActionType) {
1722
+ InteractionActionType["GLOBAL"] = "GLOBAL";
1723
+ InteractionActionType["SELF"] = "SELF";
1724
+ InteractionActionType["OTHER"] = "OTHER";
1725
+ })(InteractionActionType || (InteractionActionType = {}));
1726
+ var InteractionAction;
1727
+ (function (InteractionAction) {
1728
+ InteractionAction["FLOW"] = "FLOW";
1729
+ InteractionAction["ANIMATION"] = "ANIMATION";
1730
+ InteractionAction["DELAY"] = "DELAY";
1731
+ })(InteractionAction || (InteractionAction = {}));
1732
+ var InteractionObsType;
1733
+ (function (InteractionObsType) {
1734
+ InteractionObsType["GLOBAL"] = "GLOBAL";
1735
+ InteractionObsType["INSTANCE"] = "INSTANCE";
1736
+ InteractionObsType["FAMILY"] = "FAMILY";
1737
+ })(InteractionObsType || (InteractionObsType = {}));
1738
+ var InteractionType;
1739
+ (function (InteractionType) {
1740
+ InteractionType["MOUSE_CLICK"] = "MOUSE_CLICK";
1741
+ InteractionType["MOUSE_DB_CLICK"] = "MOUSE_DB_CLICK";
1742
+ InteractionType["MOUSE_RIGHT_CLICK"] = "MOUSE_RIGHT_CLICK";
1743
+ InteractionType["THING_PROP_CHANGE"] = "THING_PROP_CHANGE";
1744
+ InteractionType["THING_EVENT"] = "THING_EVENT";
1745
+ InteractionType["LOADED"] = "LOADED";
1746
+ InteractionType["MODEL_PROP_CHANGE"] = "MODEL_PROP_CHANGE";
1747
+ })(InteractionType || (InteractionType = {}));
1748
+
1749
+ var _ComponentTrigger_instances, _ComponentTrigger_init, _ComponentTrigger_getObsTarget, _ComponentTrigger_thingModelHandler;
1750
+ const { groupBy, } = SoonSpace.utils;
1751
+ class ComponentTrigger extends Trigger {
1752
+ constructor(ssp, interaction, flows, options) {
1753
+ super(ssp, interaction, flows, options);
1754
+ _ComponentTrigger_instances.add(this);
1755
+ this.flows = flows;
1756
+ this.flowsMap = groupBy(flows, 'id');
1757
+ __classPrivateFieldGet(this, _ComponentTrigger_instances, "m", _ComponentTrigger_init).call(this);
1758
+ }
1759
+ // 模型事件触发
1760
+ modelHandler(params) {
1761
+ var _a;
1762
+ const { currentTarget, } = params;
1763
+ (_a = this.interaction.obsTargets) === null || _a === void 0 ? void 0 : _a.forEach(targetKey => {
1764
+ // todo confirm component id
1765
+ if (targetKey === currentTarget.userData.key) {
1766
+ this.execBehavior();
1767
+ }
1768
+ });
1769
+ }
1770
+ runFlowByIds(flowIds) {
1771
+ const getTarget = __classPrivateFieldGet(this, _ComponentTrigger_instances, "m", _ComponentTrigger_getObsTarget).bind(this);
1772
+ flowIds.forEach(flowId => {
1773
+ const foundFlow = this.flowsMap.get(flowId);
1774
+ if (foundFlow) {
1775
+ const flow = new ComponentFlowParser(this.ssp, foundFlow[0]);
1776
+ flow.parse();
1777
+ asyncRunWithCode(() => flow.run({
1778
+ getTarget,
1779
+ }));
1780
+ }
1781
+ });
1782
+ }
1783
+ async execBehavior() {
1784
+ var _a, _b, _c, _d;
1785
+ try {
1786
+ const { behaviors, } = this.interaction;
1787
+ behaviors === null || behaviors === void 0 ? void 0 : behaviors.forEach(behavior => {
1788
+ switch (behavior.action) {
1789
+ case InteractionAction.FLOW:
1790
+ if (behavior.actionRefs)
1791
+ this.runFlowByIds(behavior.actionRefs);
1792
+ break;
1793
+ }
1794
+ });
1795
+ ((_a = this.options) === null || _a === void 0 ? void 0 : _a.onTrigger) && ((_b = this.options) === null || _b === void 0 ? void 0 : _b.onTrigger(this.interaction));
1796
+ }
1797
+ catch (e) {
1798
+ ((_c = this.options) === null || _c === void 0 ? void 0 : _c.onError) && ((_d = this.options) === null || _d === void 0 ? void 0 : _d.onError(e));
1799
+ }
1800
+ }
1801
+ initLoaded() {
1802
+ const loadHandler = () => {
1803
+ this.execBehavior();
1804
+ };
1805
+ __classPrivateFieldGet(this, _ComponentTrigger_instances, "m", _ComponentTrigger_getObsTarget).call(this).then(target => {
1806
+ if (target) {
1807
+ target.addEventListener('load', loadHandler);
1808
+ this.disposables.push(() => target.removeEventListener('load', loadHandler));
1809
+ }
1810
+ });
1811
+ }
1812
+ initThingPropChange() {
1813
+ const thingModelHandler = __classPrivateFieldGet(this, _ComponentTrigger_instances, "m", _ComponentTrigger_thingModelHandler).bind(this);
1814
+ this.ssp.signals.thingModelPropsChange.add(thingModelHandler);
1815
+ this.disposables.push(() => this.ssp.signals.thingModelPropsChange.remove(thingModelHandler));
1816
+ }
1817
+ initThingEvent() {
1818
+ // @todo
1819
+ }
1820
+ onThingPropChange(newProps) {
1821
+ this.ssp.signals.thingModelPropsChange.dispatch({
1822
+ propKey: newProps,
1823
+ });
1824
+ }
1825
+ }
1826
+ _ComponentTrigger_instances = new WeakSet(), _ComponentTrigger_init = function _ComponentTrigger_init() {
1827
+ switch (this.interaction.type) {
1828
+ case InteractionType.MOUSE_CLICK:
1829
+ this.initMouseClick();
1830
+ break;
1831
+ case InteractionType.MOUSE_DB_CLICK:
1832
+ this.initMouseDbClick();
1833
+ break;
1834
+ case InteractionType.MOUSE_RIGHT_CLICK:
1835
+ this.initMouseRightClick();
1836
+ break;
1837
+ case InteractionType.LOADED:
1838
+ this.initLoaded();
1839
+ break;
1840
+ case InteractionType.THING_PROP_CHANGE:
1841
+ this.initThingPropChange();
1842
+ break;
1843
+ case InteractionType.THING_EVENT:
1844
+ this.initThingEvent();
1845
+ break;
1846
+ case InteractionType.MODEL_PROP_CHANGE:
1847
+ this.initModelPropChange();
1848
+ break;
1849
+ }
1850
+ }, _ComponentTrigger_getObsTarget =
1851
+ // 获取交互触发的Mesh
1852
+ async function _ComponentTrigger_getObsTarget(currentNode) {
1853
+ console.log('currentNode', currentNode);
1854
+ const { obsType, obsTargets, } = this.interaction;
1855
+ if (obsType === InteractionObsType.GLOBAL) {
1856
+ // return this.target
1857
+ return null;
1858
+ }
1859
+ if (obsType === InteractionObsType.INSTANCE) {
1860
+ const targets = obsTargets === null || obsTargets === void 0 ? void 0 : obsTargets.map(targetId => {
1861
+ const target = this.ssp.getModelById(targetId);
1862
+ if (!target) {
1863
+ console.warn('Target not found:', targetId);
1864
+ }
1865
+ return target;
1866
+ });
1867
+ return targets ? targets[0] : null;
1868
+ }
1869
+ return null;
1870
+ }, _ComponentTrigger_thingModelHandler = function _ComponentTrigger_thingModelHandler(params) {
1871
+ var _a;
1872
+ const { propKey, } = params;
1873
+ (_a = this.interaction.obsProps) === null || _a === void 0 ? void 0 : _a.forEach(targetProp => {
1874
+ if (targetProp === propKey) {
1875
+ this.execBehavior();
1876
+ }
1877
+ });
1878
+ };
1879
+
1880
+ export { ComponentFlowParser, ComponentTrigger, FlowParser, InteractionAction, InteractionActionType, InteractionObsType, InteractionType, Node, NodePropTypeEnum, NodeTypeEnum, Trigger };
1881
+ //# sourceMappingURL=index.esm.js.map