UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

3 lines (2 loc) 4.43 kB
import{F as t}from"./objectModelMapping-DA3c5cv8.esm.min.js";import{R as e}from"./declarationMapper-sl3auZpG.esm.min.js";import{i as n,b1 as o,V as r,bc as i,u as s}from"./index-OM-TXt9s.esm.min.js";import{F as a}from"./flowGraphCachedOperationBlock-YPEvoRCv.esm.min.js";import"./spotLight.pure-guqQj5Iw.esm.min.js";import"./KHR_interactivity-BMn2G2LI.esm.min.js";class p{constructor(n,o){this.path=n,this.ownerBlock=o,this.templatedInputs=[],this.templateInfos=[];const r=new Set,i=(i,s)=>{let a=i.exec(n);for(;a;){const[,p]=a;if(r.has(p))throw new Error("Duplicate template variable detected.");r.add(p);const c=o.registerDataInput(p,e,new t(0));this.templatedInputs.push(c),this.templateInfos.push({name:p,style:s,connection:c}),a=i.exec(n)}};i(new RegExp(/\/\{(\w+)\}(?=\/|$)/g),"curly"),i(new RegExp(/\/\[(\w+)\](?=\/|$)/g),"square")}getAccessor(t,e){let n=this.path;for(const t of this.templateInfos){const o=t.connection.getValue(e),r="curly"===t.style?`{${t.name}}`:`[${t.name}]`,i=c(this.path,t.name,o,e);n=n.replace(r,i)}return t.convert(n)}}function c(e,n,o,r){if(o instanceof t)return u(o.value,n),o.value.toString();if("number"==typeof o)return u(o,n),o.toString();if("string"==typeof o){if(""===o)throw new Error(`Templated reference input "${n}" is null.`);return l(e,n,o)}if(o&&"object"==typeof o){const t=r.getObjectReference(o,function(t,e){const n=function(t,e){const n=[`{${e}}`,`[${e}]`];return t.split("/").findIndex(t=>n.indexOf(t)>=0)}(t,e);return n>0?t.split("/")[n-1]:void 0}(e,n));if(t)return l(e,n,t)}throw new Error(`Invalid value for templated input "${n}": got ${typeof o}.`)}function u(t,e){if("number"!=typeof t||t<0||!Number.isFinite(t))throw new Error(`Invalid value for templated input "${e}": ${t}.`)}function l(t,e,n){const o=t.split("/"),r=[`{${e}}`,`[${e}]`],i=o.findIndex(t=>r.indexOf(t)>=0),s=n.split("/");if(i>=0&&i<s.length&&""!==s[i])return s[i];for(let t=s.length-1;t>=0;t--)if(""!==s[t])return s[t];return n}class f extends a{constructor(t){super(e,t),this.config=t,this.object=this.registerDataOutput("object",e),this.propertyName=this.registerDataOutput("propertyName",e),this.setterFunction=this.registerDataOutput("setFunction",e,this._setPropertyValue.bind(this)),this.getterFunction=this.registerDataOutput("getFunction",e,this._getPropertyValue.bind(this)),this.generateAnimationsFunction=this.registerDataOutput("generateAnimationsFunction",e,this._getInterpolationAnimationPropertyInfo.bind(this)),this.templateComponent=new p(t.jsonPointer,this)}_doOperation(t){const e=this.templateComponent.getAccessor(this.config.pathConverter,t),n=e.info.get(e.object,void 0,t),o=e.info.getTarget?.(e.object),r=e.info.getPropertyName?.[0](e.object);if(!o)throw new Error("Object is undefined");return this.object.setValue(o,t),r&&this.propertyName.setValue(r,t),n}_setPropertyValue(t,e,n,o){const r=this.templateComponent.getAccessor(this.config.pathConverter,o),i=r.info.type;i.startsWith("Color")&&(n=m(n,i)),"number"==typeof n?.value&&"FlowGraphInteger"===n?.getClassName?.()&&(n=n.value),r.info.set?.(n,r.object)}_getPropertyValue(t,e,s){const a=this.templateComponent.getAccessor(this.config.pathConverter,s),p=a.info.type,c=a.info.get(a.object,void 0,s);return p.startsWith("Color")?function(t){if(t instanceof n)return new r(t.r,t.g,t.b);if(t instanceof o)return new i(t.r,t.g,t.b,t.a);throw new Error("Invalid color type")}(c):c}_getInterpolationAnimationPropertyInfo(t,e,n){const o=this.templateComponent.getAccessor(this.config.pathConverter,n);return(t,e,n,r)=>{const i=[],s=o.info.type;return s.startsWith("Color")&&(t=t.map(t=>({frame:t.frame,value:m(t.value,s)}))),o.info.interpolation?.forEach((e,s)=>{const a=o.info.getPropertyName?.[s](o.object)||"Animation-interpolation-"+s;let p=t;n!==e.type&&(p=t.map(t=>({frame:t.frame,value:e.getValue(void 0,t.value.asArray?t.value.asArray():[t.value],0,1)})));const c=e.buildAnimations(o.object,a,60,p);for(const t of c)r&&t.babylonAnimation.setEasingFunction(r),i.push(t.babylonAnimation)}),i}}getClassName(){return"FlowGraphJsonPointerParserBlock"}}function m(t,e){return t.getClassName().startsWith("Color")?t:"Color3"===e?new n(t.x,t.y,t.z):"Color4"===e?new o(t.x,t.y,t.z,t.w):t}let h=!1;function g(){h||(h=!0,s("FlowGraphJsonPointerParserBlock",f))}g();export{f as FlowGraphJsonPointerParserBlock,g as RegisterFlowGraphJsonPointerParserBlock}; //# sourceMappingURL=flowGraphJsonPointerParserBlock-CpPYFKl0.esm.min.js.map