@soonspacejs/plugin-flow 2.13.1 → 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.
- package/dist/flows/FlowParser.d.ts +18 -2
- package/dist/flows/nodes/ColorNode.d.ts +2 -2
- package/dist/flows/nodes/DelayNode.d.ts +2 -2
- package/dist/flows/nodes/EmissiveNode.d.ts +4 -2
- package/dist/flows/nodes/HideNode.d.ts +4 -2
- package/dist/flows/nodes/HighlightNode.d.ts +4 -2
- package/dist/flows/nodes/MeshNode.d.ts +2 -2
- package/dist/flows/nodes/MeshesNode.d.ts +2 -2
- package/dist/flows/nodes/ModelNode.d.ts +2 -2
- package/dist/flows/nodes/ModelsNode.d.ts +2 -2
- package/dist/flows/nodes/Node.d.ts +9 -2
- package/dist/flows/nodes/NumberNode.d.ts +2 -2
- package/dist/flows/nodes/OpacityNode.d.ts +4 -2
- package/dist/flows/nodes/ShowNode.d.ts +4 -2
- package/dist/flows/nodes/StartNode.d.ts +2 -2
- package/dist/flows/nodes/UnEmissiveNode.d.ts +4 -2
- package/dist/flows/nodes/UnHighlightNode.d.ts +4 -2
- package/dist/flows/nodes/UnOpacityNode.d.ts +4 -2
- package/dist/flows/nodes/clip-animation/ClipAnimationNode.d.ts +2 -2
- package/dist/flows/nodes/clip-animation/UnClipAnimationNode.d.ts +2 -2
- package/dist/flows/nodes/component-tween-animation/ComponentTweenAnimationNode.d.ts +2 -2
- package/dist/flows/nodes/component-tween-animation/UnComponentTweenAnimationNode.d.ts +2 -2
- package/dist/flows/nodes/tween-animation/TweenAnimationNode.d.ts +2 -2
- package/dist/flows/nodes/tween-animation/UnTweenAnimationNode.d.ts +2 -2
- package/dist/flows/types.d.ts +1 -0
- package/dist/flows/utils.d.ts +2 -1
- package/dist/index.esm.js +1 -1
- package/package.json +3 -3
|
@@ -1,14 +1,17 @@
|
|
|
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[];
|
|
9
10
|
nodesMap: Map<Node['id'], Node>;
|
|
10
11
|
edges: Edge[];
|
|
11
12
|
edgesMap: Map<Edge['id'], Edge>;
|
|
13
|
+
onNodeBefore: Node['onBefore'];
|
|
14
|
+
onNodeAfter: Node['onAfter'];
|
|
12
15
|
constructor(ssp: SoonSpace, flow: FlowType);
|
|
13
16
|
addNode(node: Node): void;
|
|
14
17
|
addEdge(edge: Edge): void;
|
|
@@ -25,5 +28,18 @@ declare class FlowParser {
|
|
|
25
28
|
* @param ctx
|
|
26
29
|
*/
|
|
27
30
|
run(global?: NodeGlobalType): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* 调试流程
|
|
33
|
+
*/
|
|
34
|
+
debug(global?: NodeGlobalType, time?: number): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* 停止流程
|
|
37
|
+
*/
|
|
38
|
+
stop(): void;
|
|
39
|
+
/**
|
|
40
|
+
* 清理流程
|
|
41
|
+
*/
|
|
42
|
+
cleanup(): void;
|
|
43
|
+
dispose(): void;
|
|
28
44
|
}
|
|
29
45
|
export { FlowParser, };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FlowParser } from '../FlowParser';
|
|
2
2
|
import { NodeType } from '../types';
|
|
3
3
|
import { Node } from './Node';
|
|
4
4
|
declare class ColorNode extends Node {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
6
6
|
exec(): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
export { ColorNode, };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FlowParser } from '../FlowParser';
|
|
2
2
|
import { NodeType } from '../types';
|
|
3
3
|
import { Node } from './Node';
|
|
4
4
|
declare class DelayNode extends Node {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
6
6
|
exec(): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
export { DelayNode, };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Object3D } from 'three';
|
|
2
|
+
import { FlowParser } from '../FlowParser';
|
|
2
3
|
import { NodeType } from '../types';
|
|
3
4
|
import { Node } from './Node';
|
|
4
5
|
declare class EmissiveNode extends Node {
|
|
5
|
-
constructor(
|
|
6
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
7
|
+
filterEmissiveObject(objectsValue: Object3D[] | Object3D): Object3D<import("three").Object3DEventMap>[];
|
|
6
8
|
exec(): Promise<void>;
|
|
7
9
|
}
|
|
8
10
|
export { EmissiveNode, };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FlowParser } from '../FlowParser';
|
|
2
2
|
import { NodeType } from '../types';
|
|
3
3
|
import { Node } from './Node';
|
|
4
|
+
import { Object3D } from 'three';
|
|
4
5
|
declare class HideNode extends Node {
|
|
5
|
-
constructor(
|
|
6
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
7
|
+
filterHideObject(objectsValue: Object3D[] | Object3D): Object3D<import("three").Object3DEventMap>[];
|
|
6
8
|
exec(): Promise<void>;
|
|
7
9
|
}
|
|
8
10
|
export { HideNode, };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Object3D } from 'three';
|
|
2
|
+
import { FlowParser } from '../FlowParser';
|
|
2
3
|
import { NodeType } from '../types';
|
|
3
4
|
import { Node } from './Node';
|
|
4
5
|
declare class HighlightNode extends Node {
|
|
5
|
-
constructor(
|
|
6
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
7
|
+
filterHighlightObject(objectsValue: Object3D[] | Object3D): Object3D<import("three").Object3DEventMap>[];
|
|
6
8
|
exec(): Promise<void>;
|
|
7
9
|
}
|
|
8
10
|
export { HighlightNode, };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FlowParser } from '../FlowParser';
|
|
2
2
|
import { NodeGlobalType, NodeType } from '../types';
|
|
3
3
|
import { Node } from './Node';
|
|
4
4
|
declare class MeshNode extends Node {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
6
6
|
exec(global: NodeGlobalType): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
export { MeshNode, };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FlowParser } from '../FlowParser';
|
|
2
2
|
import { NodeGlobalType, NodeType } from '../types';
|
|
3
3
|
import { Node } from './Node';
|
|
4
4
|
declare class MeshesNode extends Node {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
6
6
|
exec(global: NodeGlobalType): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
export { MeshesNode, };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FlowParser } from '../FlowParser';
|
|
2
2
|
import { NodeType } from '../types';
|
|
3
3
|
import { Node } from './Node';
|
|
4
4
|
declare class ModelNode extends Node {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
6
6
|
exec(): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
export { ModelNode, };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FlowParser } from '../FlowParser';
|
|
2
2
|
import { NodeType } from '../types';
|
|
3
3
|
import { Node } from './Node';
|
|
4
4
|
declare class ModelsNode extends Node {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
6
6
|
exec(): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
export { ModelsNode, };
|
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
import SoonSpace from 'soonspacejs';
|
|
2
|
+
import { FlowParser } from '../FlowParser';
|
|
2
3
|
import { NodeType, NodeCtxType, NodePropType, NodeGlobalType, NodeTypeEnum } from '../types';
|
|
3
4
|
declare class Node {
|
|
5
|
+
parser: FlowParser;
|
|
4
6
|
ssp: SoonSpace;
|
|
5
7
|
id: string;
|
|
6
8
|
type: NodeTypeEnum;
|
|
7
9
|
props: NodeType['props'];
|
|
8
10
|
prevNodes: Node[];
|
|
9
11
|
postNodes: Node[];
|
|
12
|
+
execOrder: number;
|
|
10
13
|
ctx: NodeCtxType;
|
|
11
14
|
promise: Promise<void>;
|
|
12
15
|
resolve: () => void;
|
|
13
16
|
reject: (reason?: any) => void;
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
cleanSets: Set<() => void>;
|
|
18
|
+
onBefore: ((node: Node) => (Promise<void> | void)) | null;
|
|
19
|
+
onAfter: ((node: Node) => (Promise<void> | void)) | null;
|
|
20
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
21
|
+
init(): void;
|
|
16
22
|
readContext<T = any>(key: string): T | undefined;
|
|
17
23
|
writeContext(key: string, value: any): void;
|
|
18
24
|
findProp(name: string, type: NodePropType['type']): NodePropType | undefined;
|
|
@@ -34,5 +40,6 @@ declare class Node {
|
|
|
34
40
|
* @param global
|
|
35
41
|
*/
|
|
36
42
|
run(global: NodeGlobalType): Promise<void>;
|
|
43
|
+
cleanup(): void;
|
|
37
44
|
}
|
|
38
45
|
export { Node, };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FlowParser } from '../FlowParser';
|
|
2
2
|
import { NodeType } from '../types';
|
|
3
3
|
import { Node } from './Node';
|
|
4
4
|
declare class NumberNode extends Node {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
6
6
|
exec(): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
export { NumberNode, };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Object3D } from 'three';
|
|
2
|
+
import { FlowParser } from '../FlowParser';
|
|
2
3
|
import { NodeType } from '../types';
|
|
3
4
|
import { Node } from './Node';
|
|
4
5
|
declare class OpacityNode extends Node {
|
|
5
|
-
constructor(
|
|
6
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
7
|
+
filterOpacityObject(objectsValue: Object3D[] | Object3D): Object3D<import("three").Object3DEventMap>[];
|
|
6
8
|
exec(): Promise<void>;
|
|
7
9
|
}
|
|
8
10
|
export { OpacityNode, };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FlowParser } from '../FlowParser';
|
|
2
2
|
import { NodeType } from '../types';
|
|
3
3
|
import { Node } from './Node';
|
|
4
|
+
import { Object3D } from 'three';
|
|
4
5
|
declare class ShowNode extends Node {
|
|
5
|
-
constructor(
|
|
6
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
7
|
+
filterShowObject(objectsValue: Object3D[] | Object3D): Object3D<import("three").Object3DEventMap>[];
|
|
6
8
|
exec(): Promise<void>;
|
|
7
9
|
}
|
|
8
10
|
export { ShowNode, };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FlowParser } from '../FlowParser';
|
|
2
2
|
import { NodeType } from '../types';
|
|
3
3
|
import { Node } from './Node';
|
|
4
4
|
declare class StartNode extends Node {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
6
6
|
}
|
|
7
7
|
export { StartNode, };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Object3D } from 'three';
|
|
2
|
+
import { FlowParser } from '../FlowParser';
|
|
2
3
|
import { NodeType } from '../types';
|
|
3
4
|
import { Node } from './Node';
|
|
4
5
|
declare class UnEmissiveNode extends Node {
|
|
5
|
-
constructor(
|
|
6
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
7
|
+
filterUnEmissiveObject(objectsValue: Object3D[] | Object3D): Object3D<import("three").Object3DEventMap>[];
|
|
6
8
|
exec(): Promise<void>;
|
|
7
9
|
}
|
|
8
10
|
export { UnEmissiveNode, };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Object3D } from 'three';
|
|
2
|
+
import { FlowParser } from '../FlowParser';
|
|
2
3
|
import { NodeType } from '../types';
|
|
3
4
|
import { Node } from './Node';
|
|
4
5
|
declare class UnHighlightNode extends Node {
|
|
5
|
-
constructor(
|
|
6
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
7
|
+
filterUnHighlightObject(objectsValue: Object3D[] | Object3D): Object3D<import("three").Object3DEventMap>[];
|
|
6
8
|
exec(): Promise<void>;
|
|
7
9
|
}
|
|
8
10
|
export { UnHighlightNode, };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Object3D } from 'three';
|
|
2
|
+
import { FlowParser } from '../FlowParser';
|
|
2
3
|
import { NodeType } from '../types';
|
|
3
4
|
import { Node } from './Node';
|
|
4
5
|
declare class UnOpacityNode extends Node {
|
|
5
|
-
constructor(
|
|
6
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
7
|
+
filterUnOpacityObject(objectsValue: Object3D[] | Object3D): Object3D<import("three").Object3DEventMap>[];
|
|
6
8
|
exec(): Promise<void>;
|
|
7
9
|
}
|
|
8
10
|
export { UnOpacityNode, };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FlowParser } from '../../FlowParser';
|
|
2
2
|
import { NodeGlobalType, NodeType } from '../../types';
|
|
3
3
|
import { Node } from '../Node';
|
|
4
4
|
declare class ClipAnimationNode extends Node {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
6
6
|
exec(global: NodeGlobalType): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
export { ClipAnimationNode, };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FlowParser } from '../../FlowParser';
|
|
2
2
|
import { NodeGlobalType, NodeType } from '../../types';
|
|
3
3
|
import { Node } from '../Node';
|
|
4
4
|
declare class UnClipAnimationNode extends Node {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
6
6
|
exec(global: NodeGlobalType): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
export { UnClipAnimationNode, };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FlowParser } from '../../FlowParser';
|
|
2
2
|
import { NodeType, NodeGlobalType } from '../../types';
|
|
3
3
|
import { Node } from '../Node';
|
|
4
4
|
declare class ComponentTweenAnimationNode extends Node {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
6
6
|
exec(global: NodeGlobalType): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
export { ComponentTweenAnimationNode, };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FlowParser } from '../../FlowParser';
|
|
2
2
|
import { NodeType } from '../../types';
|
|
3
3
|
import { Node } from '../Node';
|
|
4
4
|
declare class UnComponentTweenAnimationNode extends Node {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
6
6
|
exec(): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
export { UnComponentTweenAnimationNode, };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FlowParser } from '../../FlowParser';
|
|
2
2
|
import { NodeType, NodeGlobalType } from '../../types';
|
|
3
3
|
import { Node } from '../Node';
|
|
4
4
|
declare class TweenAnimationNode extends Node {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
6
6
|
exec(global: NodeGlobalType): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
export { TweenAnimationNode, };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { FlowParser } from '../../FlowParser';
|
|
2
2
|
import { NodeType } from '../../types';
|
|
3
3
|
import { Node } from '../Node';
|
|
4
4
|
declare class UnTweenAnimationNode extends Node {
|
|
5
|
-
constructor(
|
|
5
|
+
constructor(parser: FlowParser, node: NodeType);
|
|
6
6
|
exec(): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
export { UnTweenAnimationNode, };
|
package/dist/flows/types.d.ts
CHANGED
package/dist/flows/utils.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Object3D } from 'three';
|
|
2
2
|
import SoonSpace, { Model } from 'soonspacejs';
|
|
3
|
+
import { FlowParser } from './FlowParser';
|
|
3
4
|
import { Node } from './nodes';
|
|
4
5
|
import { NodeType } from './types';
|
|
5
|
-
export declare function parseNodeByType(
|
|
6
|
+
export declare function parseNodeByType(parser: FlowParser, node: NodeType): Node;
|
|
6
7
|
export declare function parseValue<T = any>(value: string): T;
|
|
7
8
|
export declare function waitFor(fn: () => Promise<void>, wait: boolean): Promise<void>;
|
|
8
9
|
export declare function getModelByUuid(ssp: SoonSpace, uuid: string): Model | null;
|
package/dist/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import s from"soonspacejs";import{AnimationPlayer as t}from"umanager-animation-parser";class e{constructor(s){this.id=s.id,this.source=s.source,this.target=s.target}}class i{constructor(s,t){this.prevNodes=[],this.postNodes=[],this.ssp=s,this.id=t.id,this.type=t.type,this.props=t.props,this.reset()}reset(){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){await this.waitForPrevNodes(),this.mergeContext(),await this.exec(s).then(this.resolve)}}class n extends i{constructor(s,t){super(s,t)}}var o,a;!function(s){s.LOCAL="LOCAL",s.READ_CTX="READ_CTX",s.WRITE_CTX="WRITE_CTX"}(o||(o={})),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"}(a||(a={}));class r extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("color",o.LOCAL),t=this.findProp("out",o.WRITE_CTX);s&&t&&this.writeContext(H(t.value),H(s.value))}}class c extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("number",o.LOCAL),t=this.findProp("out",o.WRITE_CTX);s&&t&&this.writeContext(H(t.value),H(s.value))}}class h extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX),t=this.findProp("color",o.READ_CTX),e=this.findProp("opacity",o.READ_CTX);if(s&&t&&e){const i=this.readContext(H(s.value)),n=this.readContext(H(t.value)),o=this.readContext(H(e.value));i&&this.ssp.highlightShow(i,{color:n,opacity:o})}}}class l extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX);if(s){const t=this.readContext(H(s.value));t&&this.ssp.unHighlightShow(t)}}}class d extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX),t=this.findProp("color",o.READ_CTX),e=this.findProp("opacity",o.READ_CTX);if(s&&t&&e){const i=this.readContext(H(s.value)),n=this.readContext(H(t.value)),o=this.readContext(H(e.value));i&&this.ssp.opacityShow(i,{color:n,opacity:o})}}}class u extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX);if(s){const t=this.readContext(H(s.value));t&&this.ssp.unOpacityShow(t)}}}class p extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX),t=this.findProp("color",o.READ_CTX),e=this.findProp("baseColor",o.READ_CTX),i=this.findProp("minOpacity",o.READ_CTX),n=this.findProp("maxOpacity",o.READ_CTX),a=this.findProp("duration",o.READ_CTX);if(s&&t&&e&&i&&n&&a){const o=this.readContext(H(s.value)),r=this.readContext(H(t.value)),c=this.readContext(H(e.value)),h=this.readContext(H(i.value)),l=this.readContext(H(n.value)),d=this.readContext(H(a.value));o&&this.ssp.emissiveShow(o,{color:r,baseColor:c,minOpacity:h,maxOpacity:l,duration:d})}}}class E extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX);if(s){const t=this.readContext(H(s.value));t&&this.ssp.unEmissiveShow(t)}}}const C=Symbol("meshCache");class T extends i{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[C]||(s[C]={});const n=this.findProp("mesh",o.LOCAL),a=this.findProp("out",o.WRITE_CTX);if(n&&a){let t=null;const e=H(n.value),o=H(a.value),r=s[C][e];if(r)return void(t=r);const c=b(i,e);c&&(t=c,s[C][e]=c),this.writeContext(o,t)}}}const f=Symbol("meshesCache");class I extends i{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[f]||(s[f]={});const n=this.findProp("meshes",o.LOCAL),a=this.findProp("out",o.WRITE_CTX);if(n&&a){const t=[],e=H(n.value),o=H(a.value);e.forEach((e=>{const n=s[f][e];if(n)return void t.push(n);const o=b(i,e);o&&(t.push(o),s[f][e]=o)})),this.writeContext(o,t)}}}class N extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("model",o.LOCAL),t=this.findProp("out",o.WRITE_CTX);if(s&&t){const o=H(s.value),a=H(t.value);this.writeContext(a,(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 A extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("models",o.LOCAL),t=this.findProp("out",o.WRITE_CTX);if(s&&t){const e=H(s.value),i=H(t.value);this.writeContext(i,function(s,t){const e=new Set(t);return s.getAllModel().filter((s=>e.has(s.userData.id)||e.has(s.userData.uuid)))}(this.ssp,e))}}}class v extends i{constructor(s,t){super(s,t)}async exec(){const t=this.findProp("delay",o.LOCAL);if(t){const e=H(t.value);await s.utils.sleep(e)}}}const{objectHandle:O}=s.utils;class _ extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX);if(s){const t=this.readContext(H(s.value));t&&(O(t,(s=>{s.visible=!0})),this.ssp.render())}}}const{objectHandle:L}=s.utils;class x extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("objects",o.READ_CTX);if(s){const t=this.readContext(H(s.value));t&&(L(t,(s=>{s.visible=!1})),this.ssp.render())}}}class M extends i{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",o.READ_CTX);s&&(e=this.readContext(H(s.value)))}const i=this.findProp("animation",o.LOCAL);if(e&&i){const s=H(i.value),t=e.animations[s];t&&this.ssp.playModelAnimation(e,t)}}}class w extends i{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",o.READ_CTX);s&&(e=this.readContext(H(s.value)))}const i=this.findProp("animation",o.LOCAL);if(e&&i){const s=H(i.value),t=e.animations[s];t&&this.ssp.stopModelAnimation(e,t)}}}const g=new Map;class P extends i{constructor(s,t){super(s,t)}async exec(s){var e;const i=this.findProp("object",o.READ_CTX),n=this.findProp("animation",o.LOCAL),a=this.findProp("wait",o.LOCAL);if(i&&n&&a){const o=this.readContext(H(i.value)),r=H(n.value),c=H(a.value);if(o){const i=await(null===(e=s.getAnimations)||void 0===e?void 0:e.call(s,this,o,r));if(i){const s=i.find((s=>s.id===r));s&&await R((async()=>{await async function(s,e,i){var n;const{id:o,keyframes:a}=i,r=new t(s,e);g.has(o)||g.set(o,new Set),null===(n=g.get(o))||void 0===n||n.add(r),await r.play(a)}(this.ssp,o,s)}),c)}}}}}class y extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("animation",o.LOCAL);if(s){const n=H(s.value);t=n,null===(e=g.get(t))||void 0===e||e.forEach((s=>s.stop())),null===(i=g.get(t))||void 0===i||i.clear()}var t,e,i}}const m=new Map;class D extends i{constructor(s,t){super(s,t)}async exec(s){var e;const i=this.findProp("object",o.READ_CTX),n=this.findProp("animation",o.LOCAL),a=this.findProp("wait",o.LOCAL);if(i&&n&&a){const o=this.readContext(H(i.value)),r=H(n.value),c=H(a.value);if(o){const n=await(null===(e=s.getComponentAnimations)||void 0===e?void 0:e.call(s,this,o,r));if(n){const s=n.find((s=>s.id===r));if(s){let e=null;"Mesh"===i.valueType?e=o:"Model"===i.valueType&&(e=b(o,s.refId)),e&&await R((async()=>{e&&await async function(s,e,i){var n;const{id:o,keyframes:a}=i,r=new t(s,e);m.has(o)||m.set(o,new Set),null===(n=m.get(o))||void 0===n||n.add(r),await r.play(a)}(this.ssp,e,s)}),c)}}}}}}class S extends i{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("animation",o.LOCAL);if(s){const n=H(s.value);t=n,null===(e=m.get(t))||void 0===e||e.forEach((s=>s.stop())),null===(i=m.get(t))||void 0===i||i.clear()}var t,e,i}}function H(s){return JSON.parse(s)}async function R(s,t){t?await s():s()}function b(s,t){if(s.userData.key===t)return s;for(let e=0,i=s.children.length;e<i;e++){const i=b(s.children[e],t);if(null!==i)return i}return null}class X{constructor(s,t){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 a.START:return new n(s,t);case a.COLOR:return new r(s,t);case a.NUMBER:return new c(s,t);case a.HIGHLIGHT:return new h(s,t);case a.UN_HIGHLIGHT:return new l(s,t);case a.OPACITY:return new d(s,t);case a.UN_OPACITY:return new u(s,t);case a.EMISSIVE:return new p(s,t);case a.UN_EMISSIVE:return new E(s,t);case a.MESH:return new T(s,t);case a.MESHES:return new I(s,t);case a.MODEL:return new N(s,t);case a.MODELS:return new A(s,t);case a.DELAY:return new v(s,t);case a.SHOW:return new _(s,t);case a.HIDE:return new x(s,t);case a.CLIP_ANIMATION:return new M(s,t);case a.UN_CLIP_ANIMATION:return new w(s,t);case a.TWEEN_ANIMATION:return new P(s,t);case a.UN_TWEEN_ANIMATION:return new y(s,t);case a.COMPONENT_TWEEN_ANIMATION:return new D(s,t);case a.UN_COMPONENT_TWEEN_ANIMATION:return new S(s,t);default:return new i(s,t)}}(this.ssp,s);this.addNode(t)})),t.forEach((s=>{const t=new e(s);this.addEdge(t);const i=this.getNodeById(s.source),n=this.getNodeById(s.target);i&&n&&(i.postNodes.push(n),n.prevNodes.push(i))}))}async run(s={}){const t=this.nodes.map((t=>t.run(s)));await Promise.all(t)}}class U extends X{constructor(s,t){super(s,t),this.flow=t}}class G{constructor(s){this.disposables=[],this.ssp=s}dispose(){this.disposables.forEach((s=>s()))}}var W,k,B,j;!function(s){s.GLOBAL="GLOBAL",s.SELF="SELF",s.OTHER="OTHER"}(W||(W={})),function(s){s.FLOW="FLOW",s.ANIMATION="ANIMATION",s.DELAY="DELAY"}(k||(k={})),function(s){s.GLOBAL="GLOBAL",s.INSTANCE="INSTANCE",s.FAMILY="FAMILY"}(B||(B={})),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"}(j||(j={}));const{groupBy:Y}=s.utils;class F extends G{constructor(s,t,e,i){super(s),this.target=t,this.interaction=e,this.flows=i,this.flowsMap=Y(i,"id"),this.init()}init(){switch(this.interaction.type){case j.MOUSE_CLICK:this.initMouseClick();break;case j.MOUSE_DB_CLICK:this.initMouseDbClick();break;case j.MOUSE_RIGHT_CLICK:this.initMouseRightClick();break;case j.LOADED:this.initLoaded();break;case j.THING_PROP_CHANGE:this.initThingPropChange();break;case j.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 U(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===k.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{U as ComponentFlowParser,F as ComponentTrigger,X as FlowParser,k as InteractionAction,W as InteractionActionType,B as InteractionObsType,j as InteractionType,o as NodePropTypeEnum,a as NodeTypeEnum,G 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.
|
|
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": "
|
|
16
|
+
"gitHead": "83e90d5d0264f95d32df7d367617b7300c5fe582",
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"soonspacejs": "2.13.
|
|
18
|
+
"soonspacejs": "2.13.4",
|
|
19
19
|
"umanager-animation-parser": "^0.0.6"
|
|
20
20
|
}
|
|
21
21
|
}
|