@soonspacejs/plugin-flow 2.13.2 → 2.13.4

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.
@@ -1,8 +1,9 @@
1
+ import { EventDispatcher } from 'three';
1
2
  import SoonSpace from 'soonspacejs';
2
3
  import { Edge } from './edges';
3
4
  import { Node } from './nodes';
4
- import { FlowType, NodeGlobalType } from './types';
5
- declare class FlowParser {
5
+ import { FlowParserEventMap, FlowType, NodeGlobalType } from './types';
6
+ declare class FlowParser extends EventDispatcher<FlowParserEventMap> {
6
7
  ssp: SoonSpace;
7
8
  flow: FlowType;
8
9
  nodes: Node[];
@@ -27,6 +28,10 @@ declare class FlowParser {
27
28
  * @param ctx
28
29
  */
29
30
  run(global?: NodeGlobalType): Promise<void>;
31
+ /**
32
+ * 调试流程
33
+ */
34
+ debug(global?: NodeGlobalType, time?: number): Promise<void>;
30
35
  /**
31
36
  * 停止流程
32
37
  */
@@ -35,5 +40,6 @@ declare class FlowParser {
35
40
  * 清理流程
36
41
  */
37
42
  cleanup(): void;
43
+ dispose(): void;
38
44
  }
39
45
  export { FlowParser, };
@@ -89,3 +89,4 @@ export type NodeGlobalType = {
89
89
  getComponentAnimations?: (currentNode: Node, object: Object3D, animationId: string) => Promise<IComponentAnimation[] | null>;
90
90
  [s: symbol]: any;
91
91
  };
92
+ export type FlowParserEventMap = {};
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
1
- import t from"soonspacejs";import{AnimationPlayer as s}from"umanager-animation-parser";class e{constructor(t){this.id=t.id,this.source=t.source,this.target=t.target}}let i=0;class n{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.init()}init(){this.ctx={},this.promise=new Promise(((t,s)=>{this.resolve=t,this.reject=s}))}readContext(t){return this.ctx[t]}writeContext(t,s){this.ctx[t]=s}findProp(t,s){return this.props.find((e=>e.name===t&&e.type===s))}async waitForPrevNodes(){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,n,o;await(null===(e=null!==(s=this.onBefore)&&void 0!==s?s:this.parser.onNodeBefore)||void 0===e?void 0:e(this)),await this.waitForPrevNodes(),this.mergeContext();try{this.execOrder=++i,await this.exec(t).then(this.resolve)}catch(t){throw this.reject(t),t}await(null===(o=null!==(n=this.onAfter)&&void 0!==n?n:this.parser.onNodeAfter)||void 0===o?void 0:o(this))}cleanup(){this.cleanSets.forEach((t=>t())),this.cleanSets.clear()}}class o extends n{constructor(t,s){super(t,s)}}var a,c;!function(t){t.LOCAL="LOCAL",t.READ_CTX="READ_CTX",t.WRITE_CTX="WRITE_CTX"}(a||(a={})),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.DELAY="DELAY",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"}(c||(c={}));class r extends n{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("color",a.LOCAL),s=this.findProp("out",a.WRITE_CTX);t&&s&&this.writeContext(k(s.value),k(t.value))}}class h extends n{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("number",a.LOCAL),s=this.findProp("out",a.WRITE_CTX);t&&s&&this.writeContext(k(s.value),k(t.value))}}const{objectHandle:l}=t.utils;class d extends n{constructor(t,s){super(t,s)}filterHighlightObject(t){const s=[];return l(t,(t=>{this.ssp.viewport.scener.selectedObjects.highlight.has(t)||s.push(t)})),s}async exec(){const t=this.findProp("objects",a.READ_CTX),s=this.findProp("color",a.READ_CTX),e=this.findProp("opacity",a.READ_CTX);if(t&&s&&e){const i=this.readContext(k(t.value)),n=this.readContext(k(s.value)),o=this.readContext(k(e.value));if(i){const t=this.filterHighlightObject(i);this.ssp.highlightShow(t,{color:n,opacity:o}),this.cleanSets.add((()=>{this.ssp.unHighlightShow(t)}))}}}}const{objectHandle:u}=t.utils;class p extends n{constructor(t,s){super(t,s)}filterUnHighlightObject(t){const s=[];return u(t,(t=>{this.ssp.viewport.scener.selectedObjects.highlight.has(t)&&s.push(t)})),s}async exec(){const t=this.findProp("objects",a.READ_CTX);if(t){const s=this.readContext(k(t.value));if(s){const t=this.filterUnHighlightObject(s);this.ssp.unHighlightShow(t),this.cleanSets.add((()=>{this.ssp.highlightShow(t)}))}}}}const{objectHandle:f}=t.utils;class E extends n{constructor(t,s){super(t,s)}filterOpacityObject(t){const s=[];return f(t,(t=>{this.ssp.viewport.scener.selectedObjects.opacity.has(t)||s.push(t)})),s}async exec(){const t=this.findProp("objects",a.READ_CTX),s=this.findProp("color",a.READ_CTX),e=this.findProp("opacity",a.READ_CTX);if(t&&s&&e){const i=this.readContext(k(t.value)),n=this.readContext(k(s.value)),o=this.readContext(k(e.value));if(i){const t=this.filterOpacityObject(i);this.ssp.opacityShow(t,{color:n,opacity:o}),this.cleanSets.add((()=>{this.ssp.unOpacityShow(t)}))}}}}const{objectHandle:C}=t.utils;class O extends n{constructor(t,s){super(t,s)}filterUnOpacityObject(t){const s=[];return C(t,(t=>{this.ssp.viewport.scener.selectedObjects.opacity.has(t)&&s.push(t)})),s}async exec(){const t=this.findProp("objects",a.READ_CTX);if(t){const s=this.readContext(k(t.value));if(s){const t=this.filterUnOpacityObject(s);this.ssp.unOpacityShow(t),this.cleanSets.add((()=>{this.ssp.opacityShow(t)}))}}}}const{objectHandle:v}=t.utils;class T extends n{constructor(t,s){super(t,s)}filterEmissiveObject(t){const s=[];return v(t,(t=>{this.ssp.viewport.scener.selectedObjects.emissive.has(t)||s.push(t)})),s}async exec(){const t=this.findProp("objects",a.READ_CTX),s=this.findProp("color",a.READ_CTX),e=this.findProp("baseColor",a.READ_CTX),i=this.findProp("minOpacity",a.READ_CTX),n=this.findProp("maxOpacity",a.READ_CTX),o=this.findProp("duration",a.READ_CTX);if(t&&s&&e&&i&&n&&o){const a=this.readContext(k(t.value)),c=this.readContext(k(s.value)),r=this.readContext(k(e.value)),h=this.readContext(k(i.value)),l=this.readContext(k(n.value)),d=this.readContext(k(o.value));if(a){const t=this.filterEmissiveObject(a);this.ssp.emissiveShow(t,{color:c,baseColor:r,minOpacity:h,maxOpacity:l,duration:d}),this.cleanSets.add((()=>{this.ssp.unEmissiveShow(t)}))}}}}const{objectHandle:A}=t.utils;class N extends n{constructor(t,s){super(t,s)}filterUnEmissiveObject(t){const s=[];return A(t,(t=>{this.ssp.viewport.scener.selectedObjects.emissive.has(t)&&s.push(t)})),s}async exec(){const t=this.findProp("objects",a.READ_CTX);if(t){const s=this.readContext(k(t.value));if(s){const t=this.filterUnEmissiveObject(s);this.ssp.unEmissiveShow(t),this.cleanSets.add((()=>{this.ssp.emissiveShow(t)}))}}}}const I=Symbol("meshCache");class w extends n{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[I]||(t[I]={});const n=this.findProp("mesh",a.LOCAL),o=this.findProp("out",a.WRITE_CTX);if(n&&o){let s=null;const e=k(n.value),a=k(o.value),c=t[I][e];if(c)return void(s=c);const r=F(i,e);r&&(s=r,t[I][e]=r),this.writeContext(a,s)}}}const _=Symbol("meshesCache");class x extends n{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[_]||(t[_]={});const n=this.findProp("meshes",a.LOCAL),o=this.findProp("out",a.WRITE_CTX);if(n&&o){const s=[],e=k(n.value),a=k(o.value);e.forEach((e=>{const n=t[_][e];if(n)return void s.push(n);const o=F(i,e);o&&(s.push(o),t[_][e]=o)})),this.writeContext(a,s)}}}class g extends n{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("model",a.LOCAL),s=this.findProp("out",a.WRITE_CTX);if(t&&s){const o=k(t.value),a=k(s.value);this.writeContext(a,(e=this.ssp,i=o,null!==(n=e.getAllModel().find((t=>t.userData.id===i||t.userData.uuid===i)))&&void 0!==n?n:null))}var e,i,n}}class L extends n{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("models",a.LOCAL),s=this.findProp("out",a.WRITE_CTX);if(t&&s){const e=k(t.value),i=k(s.value);this.writeContext(i,function(t,s){const e=new Set(s);return t.getAllModel().filter((t=>e.has(t.userData.id)||e.has(t.userData.uuid)))}(this.ssp,e))}}}class M extends n{constructor(t,s){super(t,s)}async exec(){const s=this.findProp("delay",a.LOCAL);if(s){const e=k(s.value);await t.utils.sleep(e)}}}const{objectHandle:S}=t.utils;class m extends n{constructor(t,s){super(t,s)}filterShowObject(t){const s=[];return S(t,(t=>{!1===t.visible&&s.push(t)})),s}async exec(){const t=this.findProp("objects",a.READ_CTX);if(t){const s=this.readContext(k(t.value));if(s){const t=this.filterShowObject(s),e=s=>{S(t,(t=>{t.visible=s})),this.ssp.render()};e(!0),this.cleanSets.add((()=>e(!1)))}}}}const{objectHandle:y}=t.utils;class P extends n{constructor(t,s){super(t,s)}filterHideObject(t){const s=[];return y(t,(t=>{!0===t.visible&&s.push(t)})),s}async exec(){const t=this.findProp("objects",a.READ_CTX);if(t){const s=this.readContext(k(t.value));if(s){const t=this.filterHideObject(s),e=s=>{y(t,(t=>{t.visible=s})),this.ssp.render()};e(!1),this.cleanSets.add((()=>e(!0)))}}}}class b extends n{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("object",a.READ_CTX);t&&(e=this.readContext(k(t.value)))}const i=this.findProp("animation",a.LOCAL);if(e&&i){const t=k(i.value),s=e.animations[t];s&&(this.ssp.playModelAnimation(e,s),this.cleanSets.add((()=>{this.ssp.stopModelAnimation(e,s)})))}}}class H extends n{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("object",a.READ_CTX);t&&(e=this.readContext(k(t.value)))}const i=this.findProp("animation",a.LOCAL);if(e&&i){const t=k(i.value),s=e.animations[t];s&&this.ssp.stopModelAnimation(e,s)}}}const D=new Map;function R(t){var s,e;null===(s=D.get(t))||void 0===s||s.forEach((t=>t.stop())),null===(e=D.get(t))||void 0===e||e.clear()}class j extends n{constructor(t,s){super(t,s)}async exec(t){var e;const i=this.findProp("object",a.READ_CTX),n=this.findProp("animation",a.LOCAL),o=this.findProp("wait",a.LOCAL);if(i&&n&&o){const a=this.readContext(k(i.value)),c=k(n.value),r=k(o.value);if(a){const i=await(null===(e=t.getAnimations)||void 0===e?void 0:e.call(t,this,a,c));if(i){const t=i.find((t=>t.id===c));t&&await Y((async()=>{const e=a.matrix.clone();await async function(t,e,i){var n;const{id:o,keyframes:a}=i,c=new s(t,e);D.has(o)||D.set(o,new Set),null===(n=D.get(o))||void 0===n||n.add(c),await c.play(a)}(this.ssp,a,t),this.cleanSets.add((()=>{R(t.id),a&&e.decompose(a.position,a.quaternion,a.scale)}))}),r)}}}}}class U extends n{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("animation",a.LOCAL);if(t){R(k(t.value))}}}const X=new Map;function G(t){var s,e;null===(s=X.get(t))||void 0===s||s.forEach((t=>t.stop())),null===(e=X.get(t))||void 0===e||e.clear()}class W extends n{constructor(t,s){super(t,s)}async exec(t){var e;const i=this.findProp("object",a.READ_CTX),n=this.findProp("animation",a.LOCAL),o=this.findProp("wait",a.LOCAL);if(i&&n&&o){const a=this.readContext(k(i.value)),c=k(n.value),r=k(o.value);if(a){const n=await(null===(e=t.getComponentAnimations)||void 0===e?void 0:e.call(t,this,a,c));if(n){const t=n.find((t=>t.id===c));if(t){let e=null;"Mesh"===i.valueType?e=a:"Model"===i.valueType&&(e=F(a,t.refId)),e&&await Y((async()=>{if(e){const i=e.matrix.clone();await async function(t,e,i){var n;const{id:o,keyframes:a}=i,c=new s(t,e);X.has(o)||X.set(o,new Set),null===(n=X.get(o))||void 0===n||n.add(c),await c.play(a)}(this.ssp,e,t),this.cleanSets.add((()=>{G(t.id),e&&i.decompose(e.position,e.quaternion,e.scale)}))}}),r)}}}}}}class B extends n{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("animation",a.LOCAL);if(t){G(k(t.value))}}}function k(t){return JSON.parse(t)}async function Y(t,s){s?await t():t()}function F(t,s){if(t.userData.key===s)return t;for(let e=0,i=t.children.length;e<i;e++){const i=F(t.children[e],s);if(null!==i)return i}return null}class K{constructor(t,s){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 o(t,s);case c.COLOR:return new r(t,s);case c.NUMBER:return new h(t,s);case c.HIGHLIGHT:return new d(t,s);case c.UN_HIGHLIGHT:return new p(t,s);case c.OPACITY:return new E(t,s);case c.UN_OPACITY:return new O(t,s);case c.EMISSIVE:return new T(t,s);case c.UN_EMISSIVE:return new N(t,s);case c.MESH:return new w(t,s);case c.MESHES:return new x(t,s);case c.MODEL:return new g(t,s);case c.MODELS:return new L(t,s);case c.DELAY:return new M(t,s);case c.SHOW:return new m(t,s);case c.HIDE:return new P(t,s);case c.CLIP_ANIMATION:return new b(t,s);case c.UN_CLIP_ANIMATION:return new H(t,s);case c.TWEEN_ANIMATION:return new j(t,s);case c.UN_TWEEN_ANIMATION:return new U(t,s);case c.COMPONENT_TWEEN_ANIMATION:return new W(t,s);case c.UN_COMPONENT_TWEEN_ANIMATION:return new B(t,s);default:return new n(t,s)}}(this,t);this.addNode(s)})),s.forEach((t=>{const s=new e(t);this.addEdge(s);const i=this.getNodeById(t.source),n=this.getNodeById(t.target);i&&n&&(i.postNodes.push(n),n.prevNodes.push(i))}))}async run(t={}){const s=this.nodes.map((s=>s.run(t)));await Promise.all(s)}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()))}}class V extends K{constructor(t,s){super(t,s),this.flow=s}}class q{constructor(t){this.disposables=[],this.ssp=t}dispose(){this.disposables.forEach((t=>t()))}}var J,z,Q,Z;!function(t){t.GLOBAL="GLOBAL",t.SELF="SELF",t.OTHER="OTHER"}(J||(J={})),function(t){t.FLOW="FLOW",t.ANIMATION="ANIMATION",t.DELAY="DELAY"}(z||(z={})),function(t){t.GLOBAL="GLOBAL",t.INSTANCE="INSTANCE",t.FAMILY="FAMILY"}(Q||(Q={})),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"}(Z||(Z={}));const{groupBy:$}=t.utils;class tt extends q{constructor(t,s,e,i){super(t),this.target=s,this.interaction=e,this.flows=i,this.flowsMap=$(i,"id"),this.init()}init(){switch(this.interaction.type){case Z.MOUSE_CLICK:this.initMouseClick();break;case Z.MOUSE_DB_CLICK:this.initMouseDbClick();break;case Z.MOUSE_RIGHT_CLICK:this.initMouseRightClick();break;case Z.LOADED:this.initLoaded();break;case Z.THING_PROP_CHANGE:this.initThingPropChange();break;case Z.THING_EVENT:this.initThingEvent()}}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){t.forEach((t=>{const s=this.flowsMap.get(t);if(s){const t=new V(this.ssp,s[0]);t.parse(),t.run({getTarget:async()=>this.target})}}))}async execBehavior(){const{behaviors:t}=this.interaction;null==t||t.forEach((t=>{if(t.action===z.FLOW)t.actionRefs&&this.runFlowByIds(t.actionRefs)}))}initMouseClick(){this.ssp.signals.modelClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelClick.remove(this.modelHandler)))}initMouseDbClick(){this.ssp.signals.modelDblClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelDblClick.remove(this.modelHandler)))}initMouseRightClick(){this.ssp.signals.modelRightClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelRightClick.remove(this.modelHandler)))}initLoaded(){const t=()=>{this.execBehavior()};this.target.addEventListener("load",t),this.disposables.push((()=>this.target.removeEventListener("load",t)))}initThingPropChange(){}initThingEvent(){}}export{V as ComponentFlowParser,tt as ComponentTrigger,K as FlowParser,z as InteractionAction,J as InteractionActionType,Q as InteractionObsType,Z as InteractionType,a as NodePropTypeEnum,c as NodeTypeEnum,q as Trigger};
1
+ import{EventDispatcher as s}from"three";import t from"soonspacejs";import{AnimationPlayer as e}from"umanager-animation-parser";class i{constructor(s){this.id=s.id,this.source=s.source,this.target=s.target}}let n=0;class o{constructor(s,t){this.prevNodes=[],this.postNodes=[],this.execOrder=0,this.cleanSets=new Set,this.onBefore=null,this.onAfter=null,this.parser=s,this.ssp=s.ssp,this.id=t.id,this.type=t.type,this.props=t.props,this.init()}init(){this.ctx={},this.promise=new Promise(((s,t)=>{this.resolve=s,this.reject=t}))}readContext(s){return this.ctx[s]}writeContext(s,t){this.ctx[s]=t}findProp(s,t){return this.props.find((e=>e.name===s&&e.type===t))}async waitForPrevNodes(){await Promise.all(this.prevNodes.map((s=>s.promise)))}mergeContext(){this.prevNodes.forEach((s=>{Object.assign(this.ctx,s.ctx)}))}async exec(s){}async run(s){var t,e,i,o;await this.waitForPrevNodes(),this.mergeContext(),await(null===(e=null!==(t=this.onBefore)&&void 0!==t?t:this.parser.onNodeBefore)||void 0===e?void 0:e(this));try{this.execOrder=++n,await this.exec(s)}catch(s){throw this.reject(s),s}await(null===(o=null!==(i=this.onAfter)&&void 0!==i?i:this.parser.onNodeAfter)||void 0===o?void 0:o(this)),this.resolve()}cleanup(){this.cleanSets.forEach((s=>s())),this.cleanSets.clear()}}class c extends o{constructor(s,t){super(s,t)}}var a,r;!function(s){s.LOCAL="LOCAL",s.READ_CTX="READ_CTX",s.WRITE_CTX="WRITE_CTX"}(a||(a={})),function(s){s.START="START",s.COLOR="COLOR",s.NUMBER="NUMBER",s.HIGHLIGHT="HIGHLIGHT",s.UN_HIGHLIGHT="UN_HIGHLIGHT",s.OPACITY="OPACITY",s.UN_OPACITY="UN_OPACITY",s.EMISSIVE="EMISSIVE",s.UN_EMISSIVE="UN_EMISSIVE",s.MESH="MESH",s.MESHES="MESHES",s.MODEL="MODEL",s.MODELS="MODELS",s.DELAY="DELAY",s.SHOW="SHOW",s.HIDE="HIDE",s.CLIP_ANIMATION="CLIP_ANIMATION",s.UN_CLIP_ANIMATION="UN_CLIP_ANIMATION",s.TWEEN_ANIMATION="TWEEN_ANIMATION",s.UN_TWEEN_ANIMATION="UN_TWEEN_ANIMATION",s.COMPONENT_TWEEN_ANIMATION="COMPONENT_TWEEN_ANIMATION",s.UN_COMPONENT_TWEEN_ANIMATION="UN_COMPONENT_TWEEN_ANIMATION"}(r||(r={}));class h extends o{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("color",a.LOCAL),t=this.findProp("out",a.WRITE_CTX);s&&t&&this.writeContext(Y(t.value),Y(s.value))}}class l extends o{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("number",a.LOCAL),t=this.findProp("out",a.WRITE_CTX);s&&t&&this.writeContext(Y(t.value),Y(s.value))}}const{objectHandle:d}=t.utils;class u extends o{constructor(s,t){super(s,t)}filterHighlightObject(s){const t=[];return d(s,(s=>{this.ssp.viewport.scener.selectedObjects.highlight.has(s)||t.push(s)})),t}async exec(){const s=this.findProp("objects",a.LOCAL),t=this.findProp("color",a.LOCAL),e=this.findProp("opacity",a.LOCAL);if(s&&t&&e){const i=K(this.ssp,Y(s.value)),n=Y(t.value),o=Y(e.value);if(i){const s=this.filterHighlightObject(i);this.ssp.highlightShow(s,{color:n,opacity:o}),this.cleanSets.add((()=>{this.ssp.unHighlightShow(s)}))}}}}const{objectHandle:p}=t.utils;class f extends o{constructor(s,t){super(s,t)}filterUnHighlightObject(s){const t=[];return p(s,(s=>{this.ssp.viewport.scener.selectedObjects.highlight.has(s)&&t.push(s)})),t}async exec(){const s=this.findProp("objects",a.LOCAL);if(s){const t=K(this.ssp,Y(s.value));if(t){const s=this.filterUnHighlightObject(t);this.ssp.unHighlightShow(s),this.cleanSets.add((()=>{this.ssp.highlightShow(s)}))}}}}const{objectHandle:E}=t.utils;class O extends o{constructor(s,t){super(s,t)}filterOpacityObject(s){const t=[];return E(s,(s=>{this.ssp.viewport.scener.selectedObjects.opacity.has(s)||t.push(s)})),t}async exec(){const s=this.findProp("objects",a.LOCAL),t=this.findProp("color",a.LOCAL),e=this.findProp("opacity",a.LOCAL);if(s&&t&&e){const i=K(this.ssp,Y(s.value)),n=Y(t.value),o=Y(e.value);if(i){const s=this.filterOpacityObject(i);this.ssp.opacityShow(s,{color:n,opacity:o}),this.cleanSets.add((()=>{this.ssp.unOpacityShow(s)}))}}}}const{objectHandle:C}=t.utils;class v extends o{constructor(s,t){super(s,t)}filterUnOpacityObject(s){const t=[];return C(s,(s=>{this.ssp.viewport.scener.selectedObjects.opacity.has(s)&&t.push(s)})),t}async exec(){const s=this.findProp("objects",a.LOCAL);if(s){const t=K(this.ssp,Y(s.value));if(t){const s=this.filterUnOpacityObject(t);this.ssp.unOpacityShow(s),this.cleanSets.add((()=>{this.ssp.opacityShow(s)}))}}}}const{objectHandle:N}=t.utils;class A extends o{constructor(s,t){super(s,t)}filterEmissiveObject(s){const t=[];return N(s,(s=>{this.ssp.viewport.scener.selectedObjects.emissive.has(s)||t.push(s)})),t}async exec(){const s=this.findProp("objects",a.READ_CTX),t=this.findProp("color",a.READ_CTX),e=this.findProp("baseColor",a.READ_CTX),i=this.findProp("minOpacity",a.READ_CTX),n=this.findProp("maxOpacity",a.READ_CTX),o=this.findProp("duration",a.READ_CTX);if(s&&t&&e&&i&&n&&o){const c=this.readContext(Y(s.value)),a=this.readContext(Y(t.value)),r=this.readContext(Y(e.value)),h=this.readContext(Y(i.value)),l=this.readContext(Y(n.value)),d=this.readContext(Y(o.value));if(c){const s=this.filterEmissiveObject(c);this.ssp.emissiveShow(s,{color:a,baseColor:r,minOpacity:h,maxOpacity:l,duration:d}),this.cleanSets.add((()=>{this.ssp.unEmissiveShow(s)}))}}}}const{objectHandle:I}=t.utils;class T extends o{constructor(s,t){super(s,t)}filterUnEmissiveObject(s){const t=[];return I(s,(s=>{this.ssp.viewport.scener.selectedObjects.emissive.has(s)&&t.push(s)})),t}async exec(){const s=this.findProp("objects",a.READ_CTX);if(s){const t=this.readContext(Y(s.value));if(t){const s=this.filterUnEmissiveObject(t);this.ssp.unEmissiveShow(s),this.cleanSets.add((()=>{this.ssp.emissiveShow(s)}))}}}}const L=Symbol("meshCache");class w extends o{constructor(s,t){super(s,t)}async exec(s){var t;const{viewport:{scene:e}}=this.ssp,i=await(null===(t=s.getTarget)||void 0===t?void 0:t.call(s,this))||e;s[L]||(s[L]={});const n=this.findProp("mesh",a.LOCAL),o=this.findProp("out",a.WRITE_CTX);if(n&&o){let t=null;const e=Y(n.value),c=Y(o.value),a=s[L][e];if(a)return void(t=a);const r=V(i,e);r&&(t=r,s[L][e]=r),this.writeContext(c,t)}}}const g=Symbol("meshesCache");class _ extends o{constructor(s,t){super(s,t)}async exec(s){var t;const{viewport:{scene:e}}=this.ssp,i=await(null===(t=s.getTarget)||void 0===t?void 0:t.call(s,this))||e;s[g]||(s[g]={});const n=this.findProp("meshes",a.LOCAL),o=this.findProp("out",a.WRITE_CTX);if(n&&o){const t=[],e=Y(n.value),c=Y(o.value);e.forEach((e=>{const n=s[g][e];if(n)return void t.push(n);const o=V(i,e);o&&(t.push(o),s[g][e]=o)})),this.writeContext(c,t)}}}class x extends o{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("model",a.LOCAL),t=this.findProp("out",a.WRITE_CTX);if(s&&t){const o=Y(s.value),c=Y(t.value);this.writeContext(c,(e=this.ssp,i=o,null!==(n=e.getAllModel().find((s=>s.userData.id===i||s.userData.uuid===i)))&&void 0!==n?n:null))}var e,i,n}}class M extends o{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("models",a.LOCAL),t=this.findProp("out",a.WRITE_CTX);if(s&&t){const e=Y(s.value),i=Y(t.value);this.writeContext(i,K(this.ssp,e))}}}class m extends o{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("delay",a.LOCAL);if(s){const e=Y(s.value);await t.utils.sleep(e)}}}const{objectHandle:S}=t.utils;class y extends o{constructor(s,t){super(s,t)}filterShowObject(s){const t=[];return S(s,(s=>{!1===s.visible&&t.push(s)})),t}async exec(){const s=this.findProp("objects",a.READ_CTX);if(s){const t=this.readContext(Y(s.value));if(t){const s=this.filterShowObject(t),e=t=>{S(s,(s=>{s.visible=t})),this.ssp.render()};e(!0),this.cleanSets.add((()=>e(!1)))}}}}const{objectHandle:P}=t.utils;class b extends o{constructor(s,t){super(s,t)}filterHideObject(s){const t=[];return P(s,(s=>{!0===s.visible&&t.push(s)})),t}async exec(){const s=this.findProp("objects",a.READ_CTX);if(s){const t=this.readContext(Y(s.value));if(t){const s=this.filterHideObject(t),e=t=>{P(s,(s=>{s.visible=t})),this.ssp.render()};e(!1),this.cleanSets.add((()=>e(!0)))}}}}class H extends o{constructor(s,t){super(s,t)}async exec(s){var t;let e=await(null===(t=s.getTarget)||void 0===t?void 0:t.call(s,this));if(!e){const s=this.findProp("object",a.READ_CTX);s&&(e=this.readContext(Y(s.value)))}const i=this.findProp("animation",a.LOCAL);if(e&&i){const s=Y(i.value),t=e.animations[s];t&&(this.ssp.playModelAnimation(e,t),this.cleanSets.add((()=>{this.ssp.stopModelAnimation(e,t)})))}}}class D extends o{constructor(s,t){super(s,t)}async exec(s){var t;let e=await(null===(t=s.getTarget)||void 0===t?void 0:t.call(s,this));if(!e){const s=this.findProp("object",a.READ_CTX);s&&(e=this.readContext(Y(s.value)))}const i=this.findProp("animation",a.LOCAL);if(e&&i){const s=Y(i.value),t=e.animations[s];t&&this.ssp.stopModelAnimation(e,t)}}}const j=new Map;function R(s){var t,e;null===(t=j.get(s))||void 0===t||t.forEach((s=>s.stop())),null===(e=j.get(s))||void 0===e||e.clear()}class U extends o{constructor(s,t){super(s,t)}async exec(s){var t;const i=this.findProp("object",a.READ_CTX),n=this.findProp("animation",a.LOCAL),o=this.findProp("wait",a.LOCAL);if(i&&n&&o){const c=this.readContext(Y(i.value)),a=Y(n.value),r=Y(o.value);if(c){const i=await(null===(t=s.getAnimations)||void 0===t?void 0:t.call(s,this,c,a));if(i){const s=i.find((s=>s.id===a));s&&await F((async()=>{const t=c.matrix.clone();await async function(s,t,i){var n;const{id:o,keyframes:c}=i,a=new e(s,t);j.has(o)||j.set(o,new Set),null===(n=j.get(o))||void 0===n||n.add(a),await a.play(c)}(this.ssp,c,s),this.cleanSets.add((()=>{R(s.id),c&&t.decompose(c.position,c.quaternion,c.scale)}))}),r)}}}}}class G extends o{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("animation",a.LOCAL);if(s){R(Y(s.value))}}}const W=new Map;function B(s){var t,e;null===(t=W.get(s))||void 0===t||t.forEach((s=>s.stop())),null===(e=W.get(s))||void 0===e||e.clear()}class X extends o{constructor(s,t){super(s,t)}async exec(s){var t;const i=this.findProp("object",a.READ_CTX),n=this.findProp("animation",a.LOCAL),o=this.findProp("wait",a.LOCAL);if(i&&n&&o){const c=this.readContext(Y(i.value)),a=Y(n.value),r=Y(o.value);if(c){const n=await(null===(t=s.getComponentAnimations)||void 0===t?void 0:t.call(s,this,c,a));if(n){const s=n.find((s=>s.id===a));if(s){let t=null;"Mesh"===i.valueType?t=c:"Model"===i.valueType&&(t=V(c,s.refId)),t&&await F((async()=>{if(t){const i=t.matrix.clone();await async function(s,t,i){var n;const{id:o,keyframes:c}=i,a=new e(s,t);W.has(o)||W.set(o,new Set),null===(n=W.get(o))||void 0===n||n.add(a),await a.play(c)}(this.ssp,t,s),this.cleanSets.add((()=>{B(s.id),t&&i.decompose(t.position,t.quaternion,t.scale)}))}}),r)}}}}}}class k extends o{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("animation",a.LOCAL);if(s){B(Y(s.value))}}}function Y(s){return JSON.parse(s)}async function F(s,t){t?await s():s()}function K(s,t){const e=new Set(t);return s.getAllModel().filter((s=>e.has(s.userData.id)||e.has(s.userData.uuid)))}function V(s,t){if(s.userData.key===t)return s;for(let e=0,i=s.children.length;e<i;e++){const i=V(s.children[e],t);if(null!==i)return i}return null}const{utils:{sleep:q}}=t;class J extends s{constructor(s,t){super(),this.onNodeBefore=null,this.onNodeAfter=null,this.ssp=s,this.flow=t,this.nodes=[],this.nodesMap=new Map,this.edges=[],this.edgesMap=new Map}addNode(s){this.nodes.push(s),this.nodesMap.set(s.id,s)}addEdge(s){this.edges.push(s),this.edgesMap.set(s.id,s)}getNodeById(s){return this.nodesMap.get(s)}getEdgeById(s){return this.edgesMap.get(s)}clear(){this.nodes.length=0,this.nodesMap.clear(),this.edges.length=0,this.edgesMap.clear()}parse(){this.clear();const{nodes:s,edges:t}=this.flow;s.forEach((s=>{const t=function(s,t){switch(t.type){case r.START:return new c(s,t);case r.COLOR:return new h(s,t);case r.NUMBER:return new l(s,t);case r.HIGHLIGHT:return new u(s,t);case r.UN_HIGHLIGHT:return new f(s,t);case r.OPACITY:return new O(s,t);case r.UN_OPACITY:return new v(s,t);case r.EMISSIVE:return new A(s,t);case r.UN_EMISSIVE:return new T(s,t);case r.MESH:return new w(s,t);case r.MESHES:return new _(s,t);case r.MODEL:return new x(s,t);case r.MODELS:return new M(s,t);case r.DELAY:return new m(s,t);case r.SHOW:return new y(s,t);case r.HIDE:return new b(s,t);case r.CLIP_ANIMATION:return new H(s,t);case r.UN_CLIP_ANIMATION:return new D(s,t);case r.TWEEN_ANIMATION:return new U(s,t);case r.UN_TWEEN_ANIMATION:return new G(s,t);case r.COMPONENT_TWEEN_ANIMATION:return new X(s,t);case r.UN_COMPONENT_TWEEN_ANIMATION:return new k(s,t);default:return new o(s,t)}}(this,s);this.addNode(t)})),t.forEach((s=>{const t=new i(s);this.addEdge(t);const e=this.getNodeById(s.source),n=this.getNodeById(s.target);e&&n&&(e.postNodes.push(n),n.prevNodes.push(e))}))}async run(s={}){const t=this.nodes.filter((s=>s.prevNodes.length||s.postNodes.length)).map((t=>t.run(s)));await Promise.all(t)}async debug(s={},t=1500){this.onNodeAfter=async()=>await q(t),await this.run(s)}stop(){this.nodes.forEach((s=>s.reject(new Error("Flow stopped"))))}cleanup(){this.nodes.sort(((s,t)=>t.execOrder-s.execOrder)).forEach((s=>s.cleanup()))}dispose(){this.stop(),this.cleanup()}}class z extends J{constructor(s,t){super(s,t),this.flow=t}}class Q{constructor(s){this.disposables=[],this.ssp=s}dispose(){this.disposables.forEach((s=>s()))}}var Z,$,ss,ts;!function(s){s.GLOBAL="GLOBAL",s.SELF="SELF",s.OTHER="OTHER"}(Z||(Z={})),function(s){s.FLOW="FLOW",s.ANIMATION="ANIMATION",s.DELAY="DELAY"}($||($={})),function(s){s.GLOBAL="GLOBAL",s.INSTANCE="INSTANCE",s.FAMILY="FAMILY"}(ss||(ss={})),function(s){s.MOUSE_CLICK="MOUSE_CLICK",s.MOUSE_DB_CLICK="MOUSE_DB_CLICK",s.MOUSE_RIGHT_CLICK="MOUSE_RIGHT_CLICK",s.THING_PROP_CHANGE="THING_PROP_CHANGE",s.THING_EVENT="THING_EVENT",s.LOADED="LOADED"}(ts||(ts={}));const{groupBy:es}=t.utils;class is extends Q{constructor(s,t,e,i){super(s),this.target=t,this.interaction=e,this.flows=i,this.flowsMap=es(i,"id"),this.init()}init(){switch(this.interaction.type){case ts.MOUSE_CLICK:this.initMouseClick();break;case ts.MOUSE_DB_CLICK:this.initMouseDbClick();break;case ts.MOUSE_RIGHT_CLICK:this.initMouseRightClick();break;case ts.LOADED:this.initLoaded();break;case ts.THING_PROP_CHANGE:this.initThingPropChange();break;case ts.THING_EVENT:this.initThingEvent()}}modelHandler(s){var t;const{currentTarget:e}=s;null===(t=this.interaction.obsTargets)||void 0===t||t.forEach((s=>{s===e.userData.key&&this.execBehavior()}))}runFlowByIds(s){s.forEach((s=>{const t=this.flowsMap.get(s);if(t){const s=new z(this.ssp,t[0]);s.parse(),s.run({getTarget:async()=>this.target})}}))}async execBehavior(){const{behaviors:s}=this.interaction;null==s||s.forEach((s=>{if(s.action===$.FLOW)s.actionRefs&&this.runFlowByIds(s.actionRefs)}))}initMouseClick(){this.ssp.signals.modelClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelClick.remove(this.modelHandler)))}initMouseDbClick(){this.ssp.signals.modelDblClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelDblClick.remove(this.modelHandler)))}initMouseRightClick(){this.ssp.signals.modelRightClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelRightClick.remove(this.modelHandler)))}initLoaded(){const s=()=>{this.execBehavior()};this.target.addEventListener("load",s),this.disposables.push((()=>this.target.removeEventListener("load",s)))}initThingPropChange(){}initThingEvent(){}}export{z as ComponentFlowParser,is as ComponentTrigger,J as FlowParser,$ as InteractionAction,Z as InteractionActionType,ss as InteractionObsType,ts as InteractionType,a as NodePropTypeEnum,r as NodeTypeEnum,Q as Trigger};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@soonspacejs/plugin-flow",
3
3
  "pluginName": "FlowPlugin",
4
- "version": "2.13.2",
4
+ "version": "2.13.4",
5
5
  "description": "FlowPlugin plugin for SoonSpace.js",
6
6
  "main": "dist/index.esm.js",
7
7
  "module": "dist/index.esm.js",
@@ -13,9 +13,9 @@
13
13
  ],
14
14
  "author": "xunwei",
15
15
  "license": "UNLICENSED",
16
- "gitHead": "31d61cfb34a7879b1cff3a955663415672ef2ef7",
16
+ "gitHead": "83e90d5d0264f95d32df7d367617b7300c5fe582",
17
17
  "peerDependencies": {
18
- "soonspacejs": "2.13.2",
18
+ "soonspacejs": "2.13.4",
19
19
  "umanager-animation-parser": "^0.0.6"
20
20
  }
21
21
  }