@soonflow/plugin-soonmanager2-node
Advanced tools
Comparing version 0.2.8 to 0.2.9
@@ -1,630 +0,1 @@ | ||
import { error } from '@soonflow/core'; | ||
import axios from 'axios'; | ||
const methods$d = { | ||
async parse({ node }) { | ||
const { refId } = node; | ||
for (let i = 0; i < node.outputs.length; i++) { | ||
await this.parseFlowNode(node, { | ||
...node.outputs[i], | ||
data: { | ||
type: 'model', | ||
refId, | ||
}, | ||
}); | ||
} | ||
}, | ||
}; | ||
const methods$c = { | ||
async parse({ node }) { | ||
const { refId } = node; | ||
for (let i = 0; i < node.outputs.length; i++) { | ||
await this.parseFlowNode(node, { | ||
...node.outputs[i], | ||
data: { | ||
type: 'material', | ||
refId, | ||
}, | ||
}); | ||
} | ||
}, | ||
}; | ||
const methods$b = { | ||
// async ready(node) { | ||
// const config = JSON.parse(node.config) | ||
// node.outputs.forEach((_, index, arr) => { | ||
// arr[index].data = config | ||
// }) | ||
// }, | ||
async parse({ node }) { | ||
// const config = JSON.parse(node.config) | ||
// const flow = flows.find((flow) => flow.id === config.flowId) | ||
// if (!flow) { | ||
// this.parseFlowNode(node, node.outputs[0]) | ||
// return | ||
// } | ||
// this.parseFlow(flow) | ||
node.outputs.forEach((output) => { | ||
this.parseFlowNode(node, output); | ||
}); | ||
}, | ||
}; | ||
const methods$a = { | ||
async parse({ node }) { | ||
const ssp = this.getOutInstance('ssp'); | ||
if (!ssp) | ||
return Promise.reject('In SoonFlow: path-element-node not have ssp!'); | ||
const cpsManager = this.getOutInstance('cpsManager'); | ||
if (cpsManager) { | ||
/** | ||
* 插件使用 | ||
*/ | ||
const topologyData = await cpsManager.getTopologies(); | ||
const topologyInfo = topologyData.find((t) => t.id === node.refId); | ||
if (topologyInfo) | ||
ssp.createTopology(topologyInfo); | ||
} | ||
else { | ||
/** | ||
* 平台使用 | ||
*/ | ||
const { config } = node; | ||
const { pathData } = JSON.parse(config); | ||
ssp.createTopology({ | ||
type: 'network', | ||
...pathData, | ||
imgUrl: pathData.imgUri?.path ?? undefined, | ||
animation: { | ||
duration: pathData.animation?.duration ?? 0, | ||
}, | ||
}); | ||
} | ||
for (let i = 0; i < node.outputs.length; i++) { | ||
await this.parseFlowNode(node, { | ||
...node.outputs[i], | ||
data: {}, | ||
}); | ||
} | ||
}, | ||
}; | ||
var ObjectAnimationType; | ||
(function (ObjectAnimationType) { | ||
ObjectAnimationType["CLIP"] = "cilp"; | ||
ObjectAnimationType["INNER"] = "inner"; | ||
})(ObjectAnimationType || (ObjectAnimationType = {})); | ||
var ObjectAnimationPlayState; | ||
(function (ObjectAnimationPlayState) { | ||
ObjectAnimationPlayState["PLAY"] = "play"; | ||
ObjectAnimationPlayState["STOP"] = "stop"; | ||
})(ObjectAnimationPlayState || (ObjectAnimationPlayState = {})); | ||
const cilpAnimationMap = new Map(); | ||
const playCilpAnimation = async (ssp, modelId, initDataConfig) => { | ||
const { cilpAnimationKeyframes } = initDataConfig; | ||
const prevAnimationMapData = cilpAnimationMap.get(modelId); | ||
const object = ssp.getObjectById(modelId); | ||
if (!object) { | ||
return error(`播放模型动画 -> 方法 playCilpAnimation 执行时 modelId 为 ${modelId} 场景对象未找到`); | ||
} | ||
if (prevAnimationMapData) { | ||
prevAnimationMapData.tween.stop(); | ||
const { positionX, positionY, positionZ, rotationX, rotationY, rotationZ, scaleX, scaleY, scaleZ, } = prevAnimationMapData.source; | ||
object.position.set(positionX, positionY, positionZ); | ||
object.rotation.set(rotationX, rotationY, rotationZ); | ||
object.scale.set(scaleX, scaleY, scaleZ); | ||
ssp.render(); | ||
cilpAnimationMap.delete(modelId); | ||
} | ||
for (let i = 0; i < cilpAnimationKeyframes.length; i++) { | ||
const currentFrame = { | ||
positionX: object.position.x, | ||
positionY: object.position.y, | ||
positionZ: object.position.z, | ||
rotationX: object.rotation.x, | ||
rotationY: object.rotation.y, | ||
rotationZ: object.rotation.z, | ||
scaleX: object.scale.x, | ||
scaleY: object.scale.y, | ||
scaleZ: object.scale.z, | ||
}; | ||
const keyframe = cilpAnimationKeyframes[i]; | ||
const { delay, duration, easing, repeat, yoyo } = keyframe; | ||
const nextFrame = { | ||
positionX: keyframe.position.x || 0, | ||
positionY: keyframe.position.y || 0, | ||
positionZ: keyframe.position.z || 0, | ||
rotationX: keyframe.rotation.x || 0, | ||
rotationY: keyframe.rotation.y || 0, | ||
rotationZ: keyframe.rotation.z || 0, | ||
scaleX: keyframe.scale.x || 1, | ||
scaleY: keyframe.scale.y || 1, | ||
scaleZ: keyframe.scale.z || 1, | ||
}; | ||
await ssp.animation(currentFrame, nextFrame, { | ||
delay, | ||
duration, | ||
mode: easing, | ||
repeat: repeat === -1 ? Infinity : repeat, | ||
yoyo, | ||
}, ({ positionX, positionY, positionZ, rotationX, rotationY, rotationZ, scaleX, scaleY, scaleZ, }) => { | ||
object.position.set(positionX, positionY, positionZ); | ||
object.rotation.set(rotationX, rotationY, rotationZ); | ||
object.scale.set(scaleX, scaleY, scaleZ); | ||
}, (tween) => { | ||
cilpAnimationMap.set(modelId, { | ||
source: JSON.parse(JSON.stringify(currentFrame)), | ||
tween, | ||
}); | ||
}); | ||
cilpAnimationMap.delete(modelId); | ||
} | ||
}; | ||
const stopCilpAnimation = async (modelId) => { | ||
cilpAnimationMap.get(modelId)?.tween.stop(); | ||
cilpAnimationMap.delete(modelId); | ||
}; | ||
const methods$9 = { | ||
async parse({ node, inputData }) { | ||
const ssp = this.getOutInstance('ssp'); | ||
if (!ssp) | ||
return Promise.reject('In SoonFlow: object-animation-node not have ssp!'); | ||
const configData = JSON.parse(node.config); | ||
const { refId } = inputData; | ||
if (!refId) | ||
return Promise.reject(`In SoonFlow: object-animation-node 未绑定模型数据!`); | ||
const { animationType, innerAnimationIndex, animationPlayState, delay, duration, } = configData; | ||
await ssp.utils.sleep(delay); | ||
const runInnerAnimation = async () => { | ||
const model = ssp.getObjectById(refId); | ||
if (!model) { | ||
return Promise.reject(`In SoonFlow: object-animation-node 场景中未找到 modelId 为 "${refId}" 的模型对象`); | ||
} | ||
switch (animationPlayState) { | ||
case ObjectAnimationPlayState.PLAY: | ||
ssp.playModelAnimation(model, innerAnimationIndex); | ||
break; | ||
case ObjectAnimationPlayState.STOP: | ||
ssp.stopModelAnimation(model, innerAnimationIndex); | ||
break; | ||
} | ||
await ssp.utils.sleep(duration); | ||
}; | ||
const runCilpAnimation = async () => { | ||
switch (animationPlayState) { | ||
case ObjectAnimationPlayState.PLAY: | ||
playCilpAnimation(ssp, refId, configData); | ||
break; | ||
case ObjectAnimationPlayState.STOP: | ||
stopCilpAnimation(refId); | ||
break; | ||
} | ||
await ssp.utils.sleep(duration); | ||
}; | ||
switch (animationType) { | ||
case ObjectAnimationType.INNER: | ||
await runInnerAnimation(); | ||
break; | ||
case ObjectAnimationType.CLIP: | ||
await runCilpAnimation(); | ||
break; | ||
} | ||
for (let i = 0; i < node.outputs.length; i++) { | ||
await this.parseFlowNode(node, { | ||
...node.outputs[i], | ||
data: inputData, | ||
}); | ||
} | ||
}, | ||
}; | ||
const methods$8 = { | ||
async parse({ node, inputData }) { | ||
const ssp = this.getOutInstance('ssp'); | ||
if (!ssp) | ||
return Promise.reject('In SoonFlow: object-poi-node not have ssp!'); | ||
const configData = JSON.parse(node.config); | ||
const { delay, duration, poiId, poiShow } = configData; | ||
await ssp.utils.sleep(delay); | ||
if (poiId) { | ||
const poi = ssp.getObjectById(poiId); | ||
if (!poi) { | ||
return Promise.reject(`In SoonFlow: object-animation-node 场景中未找到 Poi 为 "${poiId}" 的模型对象`); | ||
} | ||
if (poiShow) | ||
poi.show(); | ||
else | ||
poi.hide(); | ||
} | ||
await ssp.utils.sleep(duration); | ||
for (let i = 0; i < node.outputs.length; i++) { | ||
await this.parseFlowNode(node, { | ||
...node.outputs[i], | ||
data: inputData, | ||
}); | ||
} | ||
}, | ||
}; | ||
var ObjectViewpointType; | ||
(function (ObjectViewpointType) { | ||
ObjectViewpointType["CUSTOM"] = "custom"; | ||
ObjectViewpointType["FIXED"] = "fixed"; | ||
})(ObjectViewpointType || (ObjectViewpointType = {})); | ||
const methods$7 = { | ||
async parse({ node, inputData }) { | ||
const ssp = this.getOutInstance('ssp'); | ||
if (!ssp) | ||
return Promise.reject('In SoonFlow: object-viewpoint-node not have ssp!'); | ||
const configData = JSON.parse(node.config); | ||
const { refId } = inputData; | ||
if (!refId) | ||
return Promise.reject('In SoonFlow: object-viewpoint-node 未绑定模型数据!'); | ||
const { viewpointType, customViewpointData, fixedViewpointValue, delay, duration, } = configData; | ||
await ssp.utils.sleep(delay); | ||
const flyToCustomViewpoint = async () => { | ||
if (!customViewpointData) { | ||
return Promise.reject('In SoonFlow: object-viewpoint-node 解析时缺少视角数据!'); | ||
} | ||
await ssp.flyTo(customViewpointData.position, customViewpointData.rotation, { | ||
duration: duration, | ||
}); | ||
}; | ||
const flyToFixedViewpoint = async () => { | ||
const model = ssp.getObjectById(refId); | ||
if (!model) { | ||
return Promise.reject(`In SoonFlow: object-viewpoint-node 场景中未找到 modelId 为 "${refId}" 的模型对象!`); | ||
} | ||
await ssp.flyToObj(model, fixedViewpointValue, { | ||
duration: duration, | ||
}); | ||
}; | ||
switch (viewpointType) { | ||
case ObjectViewpointType.CUSTOM: | ||
await flyToCustomViewpoint(); | ||
break; | ||
case ObjectViewpointType.FIXED: | ||
await flyToFixedViewpoint(); | ||
break; | ||
} | ||
for (let i = 0; i < node.outputs.length; i++) { | ||
await this.parseFlowNode(node, { | ||
...node.outputs[i], | ||
data: inputData, | ||
}); | ||
} | ||
}, | ||
}; | ||
const methods$6 = { | ||
async parse({ node, inputData }) { | ||
const ssp = this.getOutInstance('ssp'); | ||
if (!ssp) | ||
return Promise.reject('In SoonFlow: object-animation-node not have ssp!'); | ||
const { viewpointData } = JSON.parse(node.config); | ||
const viewpoint = JSON.parse(viewpointData); | ||
await ssp.flyTo(viewpoint.position, viewpoint.rotation); | ||
for (let i = 0; i < node.outputs.length; i++) { | ||
await this.parseFlowNode(node, { | ||
...node.outputs[i], | ||
data: inputData, | ||
}); | ||
} | ||
}, | ||
}; | ||
function getBehaviorVars(behaviorVars) { | ||
const varsInfo = {}; | ||
behaviorVars.forEach((item) => { | ||
let value = item.defaultValue; | ||
switch (item.varType) { | ||
case 'boolean': | ||
value = | ||
typeof item.defaultValue === 'boolean' | ||
? item.defaultValue | ||
: item.defaultValue === 'true'; | ||
break; | ||
case 'number': | ||
value = Number(item.defaultValue); | ||
break; | ||
} | ||
varsInfo[item.parameterName] = value; | ||
}); | ||
return varsInfo; | ||
} | ||
const methods$5 = { | ||
async parse({ node, inputData }) { | ||
const ssp = this.getOutInstance('ssp'); | ||
if (!ssp) | ||
return Promise.reject('In SoonFlow: action-node not have ssp!'); | ||
const { type, refId, fromInteraction, eventKey, nodeId } = inputData; | ||
const { behaviorType, actionCode, customCode, behaviorVars, delay, duration, } = JSON.parse(node.config); | ||
await ssp.utils.sleep(delay); | ||
const objects = []; | ||
switch (type) { | ||
case 'model': | ||
case 'path': | ||
{ | ||
const object = ssp.getObjectById(refId); | ||
object && objects.push(object); | ||
} | ||
break; | ||
case 'material': | ||
objects.push(...ssp.getObjectByUserDataProperty('familyId', refId)); | ||
break; | ||
} | ||
// 来至交互事件 | ||
if (fromInteraction) { | ||
if (behaviorType === 'SYS' || behaviorType === 'CUS') { | ||
const varsInfo = getBehaviorVars(behaviorVars); | ||
objects.forEach((object) => { | ||
this.addSignal(`${nodeId}_${object.sid}_${eventKey}`, async () => { | ||
const fn = new Function('{ssp, vars, _this}', `(async () => { ${actionCode} })()`); | ||
await fn({ ssp, vars: varsInfo, _this: object }); | ||
}); | ||
}); | ||
} | ||
else if (behaviorType === 'CUSTOM') { | ||
objects.forEach((object) => { | ||
this.addSignal(`${nodeId}_${object.sid}_${eventKey}`, async () => { | ||
const fn = new Function('{ ssp, object, inputData }', `(async () => { ${customCode} })()`); | ||
await fn({ ssp, object, inputData }); | ||
}); | ||
}); | ||
} | ||
} | ||
else { | ||
if (behaviorType === 'SYS' || behaviorType === 'CUS') { | ||
const varsInfo = getBehaviorVars(behaviorVars); | ||
for (let index = 0; index < objects.length; index++) { | ||
const object = objects[index]; | ||
const fn = new Function('{ssp, vars, _this}', `(async () => { ${actionCode} })()`); | ||
await fn({ ssp, vars: varsInfo, _this: object }); | ||
} | ||
} | ||
else if (behaviorType === 'CUSTOM') { | ||
for (let index = 0; index < objects.length; index++) { | ||
const object = objects[index]; | ||
const fn = new Function('{ ssp, object, inputData }', `(async () => { ${customCode} })()`); | ||
await fn({ ssp, object, inputData }); | ||
} | ||
} | ||
} | ||
await ssp.utils.sleep(duration); | ||
for (let i = 0; i < node.outputs.length; i++) { | ||
await this.parseFlowNode(node, node.outputs[i]); | ||
} | ||
}, | ||
}; | ||
const methods$4 = { | ||
async parse({ node, inputData }) { | ||
const ssp = this.getOutInstance('ssp'); | ||
if (!ssp) | ||
return Promise.reject('In SoonFlow: interaction-node not have ssp!'); | ||
const { type, refId } = inputData; | ||
const { eventKey } = JSON.parse(node.config); | ||
const setSceneObjectEvent = (object, eventKey) => { | ||
if (!object) | ||
return; | ||
let oldEvent = null; | ||
switch (eventKey) { | ||
case 'click': | ||
oldEvent = object.onClick; | ||
object.onClick = () => { | ||
oldEvent?.(); | ||
this.dispatchSignal(`${node.id}_${object.sid}_${eventKey}`); | ||
}; | ||
break; | ||
case 'dblClick': | ||
oldEvent = object.onDblClick; | ||
object.onDblClick = () => { | ||
oldEvent?.(); | ||
this.dispatchSignal(`${node.id}_${object.sid}_${eventKey}`); | ||
}; | ||
break; | ||
case 'rightClick': | ||
oldEvent = object.onRightClick; | ||
object.onRightClick = () => { | ||
oldEvent?.(); | ||
this.dispatchSignal(`${node.id}_${object.sid}_${eventKey}`); | ||
}; | ||
break; | ||
} | ||
}; | ||
const objects = []; | ||
switch (type) { | ||
case 'model': | ||
{ | ||
const object = ssp.getObjectById(refId); | ||
object && objects.push(object); | ||
} | ||
break; | ||
case 'material': | ||
objects.push(...ssp.getObjectByUserDataProperty('familyId', refId)); | ||
break; | ||
} | ||
objects.forEach((model) => setSceneObjectEvent(model, eventKey)); | ||
for (let i = 0; i < node.outputs.length; i++) { | ||
await this.parseFlowNode(node, { | ||
...node.outputs[i], | ||
data: { | ||
...inputData, | ||
fromInteraction: true, | ||
eventKey, | ||
nodeId: node.id, | ||
}, | ||
}); | ||
} | ||
}, | ||
}; | ||
const methods$3 = { | ||
async parse({ node }) { | ||
const config = JSON.parse(node.config); | ||
const outputData = JSON.parse(config.codeString); | ||
for (let i = 0; i < node.outputs.length; i++) { | ||
await this.parseFlowNode(node, { | ||
...node.outputs[i], | ||
data: outputData, | ||
}); | ||
} | ||
}, | ||
}; | ||
const formKeyValuesObj = (arr) => { | ||
return arr.reduce((prev, next) => { | ||
if (next.key) { | ||
prev[next.key] = next.value; | ||
} | ||
return prev; | ||
}, {}); | ||
}; | ||
const methods$2 = { | ||
async parse({ node }) { | ||
const config = JSON.parse(node.config); | ||
const { address, bodies, bodyType, headers, params, type } = config.requestInfo; | ||
let _params = undefined; | ||
if (params.length > 0) { | ||
_params = formKeyValuesObj(params); | ||
} | ||
let data = undefined; | ||
if (bodies.length > 0) { | ||
if (bodyType === 'multipart/form-data') { | ||
const formData = new FormData(); | ||
bodies.map((field) => { | ||
formData.set(field.key, field.value); | ||
}); | ||
data = formData; | ||
} | ||
else if (bodyType === 'application/x-www-form-urlencoded') { | ||
data = new URLSearchParams(bodies.map((field) => [field.key, field.value])); | ||
} | ||
else { | ||
data = formKeyValuesObj(bodies); | ||
} | ||
} | ||
let _headers = undefined; | ||
if (headers.length > 0) { | ||
_headers = formKeyValuesObj(headers); | ||
} | ||
try { | ||
const res = await axios({ | ||
method: type, | ||
url: address, | ||
params: _params, | ||
data, | ||
headers: _headers, | ||
}); | ||
for (let i = 0; i < node.outputs.length; i++) { | ||
await this.parseFlowNode(node, { | ||
...node.outputs[i], | ||
data: res, | ||
}); | ||
} | ||
} | ||
catch (err) { | ||
error(`flow node "${node.name}" parse error`, err); | ||
return Promise.reject(err); | ||
} | ||
}, | ||
}; | ||
const methods$1 = { | ||
async parse({ node, inputData }) { | ||
if (!inputData) | ||
return Promise.reject('In SoonFlow: condition-node not have inputData!'); | ||
for (let i = 0; i < node.outputs.length; i++) { | ||
const { config } = node.outputs[i]; | ||
const { codeString } = JSON.parse(config); | ||
const fn = new Function('sourceData', codeString); | ||
const res = fn(inputData); | ||
if (res) { | ||
await this.parseFlowNode(node, { | ||
...node.outputs[i], | ||
data: res, | ||
}); | ||
} | ||
} | ||
}, | ||
}; | ||
const methods = { | ||
async parse({ node, inputData }) { | ||
if (!inputData) | ||
return Promise.reject('In SoonFlow: condition-node not have inputData!'); | ||
const { filterCode } = JSON.parse(node.config); | ||
const fn = new Function('sourceData', filterCode); | ||
const res = fn(inputData); | ||
for (let i = 0; i < node.outputs.length; i++) { | ||
await this.parseFlowNode(node, { | ||
...node.outputs[i], | ||
data: res, | ||
}); | ||
} | ||
}, | ||
}; | ||
var FlowNodeTypesEnum; | ||
(function (FlowNodeTypesEnum) { | ||
// | ||
FlowNodeTypesEnum["START"] = "start"; | ||
// | ||
FlowNodeTypesEnum["MODEL"] = "model"; | ||
FlowNodeTypesEnum["MATERIAL"] = "material"; | ||
FlowNodeTypesEnum["PATH"] = "path"; | ||
FlowNodeTypesEnum["FLOW"] = "flow"; | ||
// | ||
FlowNodeTypesEnum["OBJECT_ANIMATION"] = "objectAnimation"; | ||
FlowNodeTypesEnum["OBJECT_POI"] = "objectPoi"; | ||
FlowNodeTypesEnum["OBJECT_VIEWPOINT"] = "objectViewpoint"; | ||
FlowNodeTypesEnum["SCENE_VIEWPOINT"] = "sceneViewpoint"; | ||
FlowNodeTypesEnum["ACTION"] = "action"; | ||
FlowNodeTypesEnum["INTERACTION"] = "interaction"; | ||
// | ||
FlowNodeTypesEnum["STATIC_DATA"] = "staticData"; | ||
FlowNodeTypesEnum["INTERFACE_DATA"] = "interfaceData"; | ||
// | ||
FlowNodeTypesEnum["CONDITION"] = "condition"; | ||
FlowNodeTypesEnum["FILTER"] = "filter"; | ||
/** | ||
* Deprecated type | ||
*/ | ||
// Deprecated, use "sceneViewpoint" | ||
FlowNodeTypesEnum["VIEWPOINT"] = "viewpoint"; | ||
})(FlowNodeTypesEnum || (FlowNodeTypesEnum = {})); | ||
// | ||
// 节点解析方法 | ||
const FlowNodesParseMethods = { | ||
// | ||
model: methods$d, | ||
material: methods$c, | ||
path: methods$a, | ||
flow: methods$b, | ||
// | ||
objectAnimation: methods$9, | ||
objectPoi: methods$8, | ||
objectViewpoint: methods$7, | ||
sceneViewpoint: methods$6, | ||
action: methods$5, | ||
interaction: methods$4, | ||
// | ||
staticData: methods$3, | ||
interfaceData: methods$2, | ||
// | ||
condition: methods$1, | ||
filter: methods, | ||
/** | ||
* Deprecated type | ||
*/ | ||
// Deprecated, use "sceneViewpoint" | ||
viewpoint: methods$6, | ||
}; | ||
export { FlowNodeTypesEnum, FlowNodesParseMethods, methods$9 as ObjectAnimationNodeParseMethods, ObjectAnimationPlayState, ObjectAnimationType, methods$8 as ObjectPoiNodeParseMethods, methods$7 as ObjectViewpointNodeParseMethods, ObjectViewpointType }; | ||
import{error as t}from"@soonflow/core";import e from"axios";const o={async parse({node:t}){const{refId:e}=t;for(let o=0;o<t.outputs.length;o++)await this.parseFlowNode(t,{...t.outputs[o],data:{type:"model",refId:e}})}},a={async parse({node:t}){const{refId:e}=t;for(let o=0;o<t.outputs.length;o++)await this.parseFlowNode(t,{...t.outputs[o],data:{type:"material",refId:e}})}},n={async parse({node:t}){t.outputs.forEach((e=>{this.parseFlowNode(t,e)}))}},s={async parse({node:t}){const e=this.getOutInstance("ssp");if(!e)return Promise.reject("In SoonFlow: path-element-node not have ssp!");const o=this.getOutInstance("cpsManager");if(o){const a=(await o.getTopologies()).find((e=>e.id===t.refId));a&&e.createTopology(a)}else{const{config:o}=t,{pathData:a}=JSON.parse(o);e.createTopology({type:"network",...a,imgUrl:a.imgUri?.path??void 0,animation:{duration:a.animation?.duration??0}})}for(let e=0;e<t.outputs.length;e++)await this.parseFlowNode(t,{...t.outputs[e],data:{}})}};var i,r;!function(t){t.CLIP="cilp",t.INNER="inner"}(i||(i={})),function(t){t.PLAY="play",t.STOP="stop"}(r||(r={}));const c=new Map,p={async parse({node:e,inputData:o}){const a=this.getOutInstance("ssp");if(!a)return Promise.reject("In SoonFlow: object-animation-node not have ssp!");const n=JSON.parse(e.config),{refId:s}=o;if(!s)return Promise.reject("In SoonFlow: object-animation-node 未绑定模型数据!");const{animationType:p,innerAnimationIndex:l,animationPlayState:d,delay:u,duration:w}=n;await a.utils.sleep(u);const f=async()=>{switch(d){case r.PLAY:(async(e,o,a)=>{const{cilpAnimationKeyframes:n}=a,s=c.get(o),i=e.getObjectById(o);if(!i)return t(`播放模型动画 -> 方法 playCilpAnimation 执行时 modelId 为 ${o} 场景对象未找到`);if(s){s.tween.stop();const{positionX:t,positionY:a,positionZ:n,rotationX:r,rotationY:p,rotationZ:l,scaleX:d,scaleY:u,scaleZ:w}=s.source;i.position.set(t,a,n),i.rotation.set(r,p,l),i.scale.set(d,u,w),e.render(),c.delete(o)}for(let t=0;t<n.length;t++){const a={positionX:i.position.x,positionY:i.position.y,positionZ:i.position.z,rotationX:i.rotation.x,rotationY:i.rotation.y,rotationZ:i.rotation.z,scaleX:i.scale.x,scaleY:i.scale.y,scaleZ:i.scale.z},s=n[t],{delay:r,duration:p,easing:l,repeat:d,yoyo:u}=s,w={positionX:s.position.x||0,positionY:s.position.y||0,positionZ:s.position.z||0,rotationX:s.rotation.x||0,rotationY:s.rotation.y||0,rotationZ:s.rotation.z||0,scaleX:s.scale.x||1,scaleY:s.scale.y||1,scaleZ:s.scale.z||1};await e.animation(a,w,{delay:r,duration:p,mode:l,repeat:-1===d?1/0:d,yoyo:u},(({positionX:t,positionY:e,positionZ:o,rotationX:a,rotationY:n,rotationZ:s,scaleX:r,scaleY:c,scaleZ:p})=>{i.position.set(t,e,o),i.rotation.set(a,n,s),i.scale.set(r,c,p)}),(t=>{c.set(o,{source:JSON.parse(JSON.stringify(a)),tween:t})})),c.delete(o)}})(a,s,n);break;case r.STOP:(async t=>{c.get(t)?.tween.stop(),c.delete(t)})(s)}await a.utils.sleep(w)};switch(p){case i.INNER:await(async()=>{const t=a.getObjectById(s);if(!t)return Promise.reject(`In SoonFlow: object-animation-node 场景中未找到 modelId 为 "${s}" 的模型对象`);switch(d){case r.PLAY:a.playModelAnimation(t,l);break;case r.STOP:a.stopModelAnimation(t,l)}await a.utils.sleep(w)})();break;case i.CLIP:await f()}for(let t=0;t<e.outputs.length;t++)await this.parseFlowNode(e,{...e.outputs[t],data:o})}},l={async parse({node:t,inputData:e}){const o=this.getOutInstance("ssp");if(!o)return Promise.reject("In SoonFlow: object-poi-node not have ssp!");const a=JSON.parse(t.config),{delay:n,duration:s,poiId:i,poiShow:r}=a;if(await o.utils.sleep(n),i){const t=o.getObjectById(i);if(!t)return Promise.reject(`In SoonFlow: object-animation-node 场景中未找到 Poi 为 "${i}" 的模型对象`);r?t.show():t.hide()}await o.utils.sleep(s);for(let o=0;o<t.outputs.length;o++)await this.parseFlowNode(t,{...t.outputs[o],data:e})}};var d;!function(t){t.CUSTOM="custom",t.FIXED="fixed"}(d||(d={}));const u={async parse({node:t,inputData:e}){const o=this.getOutInstance("ssp");if(!o)return Promise.reject("In SoonFlow: object-viewpoint-node not have ssp!");const a=JSON.parse(t.config),{refId:n}=e;if(!n)return Promise.reject("In SoonFlow: object-viewpoint-node 未绑定模型数据!");const{viewpointType:s,customViewpointData:i,fixedViewpointValue:r,delay:c,duration:p}=a;await o.utils.sleep(c);switch(s){case d.CUSTOM:await(async()=>{if(!i)return Promise.reject("In SoonFlow: object-viewpoint-node 解析时缺少视角数据!");await o.flyTo(i.position,i.rotation,{duration:p})})();break;case d.FIXED:await(async()=>{const t=o.getObjectById(n);if(!t)return Promise.reject(`In SoonFlow: object-viewpoint-node 场景中未找到 modelId 为 "${n}" 的模型对象!`);await o.flyToObj(t,r,{duration:p})})()}for(let o=0;o<t.outputs.length;o++)await this.parseFlowNode(t,{...t.outputs[o],data:e})}},w={async parse({node:t,inputData:e}){const o=this.getOutInstance("ssp");if(!o)return Promise.reject("In SoonFlow: object-animation-node not have ssp!");const{viewpointData:a}=JSON.parse(t.config),n=JSON.parse(a);await o.flyTo(n.position,n.rotation);for(let o=0;o<t.outputs.length;o++)await this.parseFlowNode(t,{...t.outputs[o],data:e})}};function f(t){const e={};return t.forEach((t=>{let o=t.defaultValue;switch(t.varType){case"boolean":o="boolean"==typeof t.defaultValue?t.defaultValue:"true"===t.defaultValue;break;case"number":o=Number(t.defaultValue)}e[t.parameterName]=o})),e}const h={async parse({node:t,inputData:e}){const o=this.getOutInstance("ssp");if(!o)return Promise.reject("In SoonFlow: action-node not have ssp!");const{type:a,refId:n,fromInteraction:s,eventKey:i,nodeId:r}=e,{behaviorType:c,actionCode:p,customCode:l,behaviorVars:d,delay:u,duration:w}=JSON.parse(t.config);await o.utils.sleep(u);const h=[];switch(a){case"model":case"path":{const t=o.getObjectById(n);t&&h.push(t)}break;case"material":h.push(...o.getObjectByUserDataProperty("familyId",n))}if(s)if("SYS"===c||"CUS"===c){const t=f(d);h.forEach((e=>{this.addSignal(`${r}_${e.sid}_${i}`,(async()=>{const a=new Function("{ssp, vars, _this}",`(async () => { ${p} })()`);await a({ssp:o,vars:t,_this:e})}))}))}else"CUSTOM"===c&&h.forEach((t=>{this.addSignal(`${r}_${t.sid}_${i}`,(async()=>{const a=new Function("{ ssp, object, inputData }",`(async () => { ${l} })()`);await a({ssp:o,object:t,inputData:e})}))}));else if("SYS"===c||"CUS"===c){const t=f(d);for(let e=0;e<h.length;e++){const a=h[e],n=new Function("{ssp, vars, _this}",`(async () => { ${p} })()`);await n({ssp:o,vars:t,_this:a})}}else if("CUSTOM"===c)for(let t=0;t<h.length;t++){const a=h[t],n=new Function("{ ssp, object, inputData }",`(async () => { ${l} })()`);await n({ssp:o,object:a,inputData:e})}await o.utils.sleep(w);for(let e=0;e<t.outputs.length;e++)await this.parseFlowNode(t,t.outputs[e])}},y={async parse({node:t,inputData:e}){const o=this.getOutInstance("ssp");if(!o)return Promise.reject("In SoonFlow: interaction-node not have ssp!");const{type:a,refId:n}=e,{eventKey:s}=JSON.parse(t.config),i=(e,o)=>{if(!e)return;let a=null;switch(o){case"click":a=e.onClick,e.onClick=()=>{a?.(),this.dispatchSignal(`${t.id}_${e.sid}_${o}`)};break;case"dblClick":a=e.onDblClick,e.onDblClick=()=>{a?.(),this.dispatchSignal(`${t.id}_${e.sid}_${o}`)};break;case"rightClick":a=e.onRightClick,e.onRightClick=()=>{a?.(),this.dispatchSignal(`${t.id}_${e.sid}_${o}`)}}},r=[];switch(a){case"model":{const t=o.getObjectById(n);t&&r.push(t)}break;case"material":r.push(...o.getObjectByUserDataProperty("familyId",n))}r.forEach((t=>i(t,s)));for(let o=0;o<t.outputs.length;o++)await this.parseFlowNode(t,{...t.outputs[o],data:{...e,fromInteraction:!0,eventKey:s,nodeId:t.id}})}},m={async parse({node:t}){const e=JSON.parse(t.config),o=JSON.parse(e.codeString);for(let e=0;e<t.outputs.length;e++)await this.parseFlowNode(t,{...t.outputs[e],data:o})}},I=t=>t.reduce(((t,e)=>(e.key&&(t[e.key]=e.value),t)),{}),g={async parse({node:o}){const a=JSON.parse(o.config),{address:n,bodies:s,bodyType:i,headers:r,params:c,type:p}=a.requestInfo;let l,d,u;if(c.length>0&&(l=I(c)),s.length>0)if("multipart/form-data"===i){const t=new FormData;s.map((e=>{t.set(e.key,e.value)})),d=t}else d="application/x-www-form-urlencoded"===i?new URLSearchParams(s.map((t=>[t.key,t.value]))):I(s);r.length>0&&(u=I(r));try{const t=await e({method:p,url:n,params:l,data:d,headers:u});for(let e=0;e<o.outputs.length;e++)await this.parseFlowNode(o,{...o.outputs[e],data:t})}catch(e){return t(`flow node "${o.name}" parse error`,e),Promise.reject(e)}}},O={async parse({node:t,inputData:e}){if(!e)return Promise.reject("In SoonFlow: condition-node not have inputData!");for(let o=0;o<t.outputs.length;o++){const{config:a}=t.outputs[o],{codeString:n}=JSON.parse(a),s=new Function("sourceData",n)(e);s&&await this.parseFlowNode(t,{...t.outputs[o],data:s})}}},S={async parse({node:t,inputData:e}){if(!e)return Promise.reject("In SoonFlow: condition-node not have inputData!");const{filterCode:o}=JSON.parse(t.config),a=new Function("sourceData",o)(e);for(let e=0;e<t.outputs.length;e++)await this.parseFlowNode(t,{...t.outputs[e],data:a})}};var b;!function(t){t.START="start",t.MODEL="model",t.MATERIAL="material",t.PATH="path",t.FLOW="flow",t.OBJECT_ANIMATION="objectAnimation",t.OBJECT_POI="objectPoi",t.OBJECT_VIEWPOINT="objectViewpoint",t.SCENE_VIEWPOINT="sceneViewpoint",t.ACTION="action",t.INTERACTION="interaction",t.STATIC_DATA="staticData",t.INTERFACE_DATA="interfaceData",t.CONDITION="condition",t.FILTER="filter",t.VIEWPOINT="viewpoint"}(b||(b={}));const N={model:o,material:a,path:s,flow:n,objectAnimation:p,objectPoi:l,objectViewpoint:u,sceneViewpoint:w,action:h,interaction:y,staticData:m,interfaceData:g,condition:O,filter:S,viewpoint:w};export{b as FlowNodeTypesEnum,N as FlowNodesParseMethods,p as ObjectAnimationNodeParseMethods,r as ObjectAnimationPlayState,i as ObjectAnimationType,l as ObjectPoiNodeParseMethods,u as ObjectViewpointNodeParseMethods,d as ObjectViewpointType}; |
{ | ||
"name": "@soonflow/plugin-soonmanager2-node", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"description": "Soonmanager2 node parsing methods sync plugin for Soonflow", | ||
@@ -23,3 +23,3 @@ "main": "dist/index.esm.js", | ||
}, | ||
"gitHead": "b5f1024a262891e3977e83affed5b22a756d7699" | ||
"gitHead": "b07a4f680e3b08db730236fe3b4dcbf832c05f0d" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
15355
171