@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) • 3.19 kB
JavaScript
import{k as t,b as e,R as o}from"./declarationMapper-13w1YGqM.esm.min.js";import{aH as n,j as r,V as i,i as s,R as a}from"./index-Bw2N6w1y.esm.min.js";import{F as p}from"./flowGraphCachedOperationBlock-rvkBwo1v.esm.min.js";import"./KHR_interactivity-CKt1TdMW.esm.min.js";import"./objectModelMapping-DX92iJ8M.esm.min.js";const c=new RegExp(/\/\{(\w+)\}(?=\/|$)/g);class l{constructor(o,n){this.path=o,this.ownerBlock=n,this.templatedInputs=[];let r=c.exec(o);const i=new Set;for(;r;){const[,s]=r;if(i.has(s))throw new Error("Duplicate template variable detected.");i.add(s),this.templatedInputs.push(n.registerDataInput(s,t,new e(0))),r=c.exec(o)}}getAccessor(t,e){let o=this.path;for(const t of this.templatedInputs){const n=t.getValue(e).value;if("number"!=typeof n||n<0)throw new Error("Invalid value for templated input.");o=o.replace(`{${t.name}}`,n.toString())}return t.convert(o)}}class u extends p{constructor(t){super(o,t),this.config=t,this.object=this.registerDataOutput("object",o),this.propertyName=this.registerDataOutput("propertyName",o),this.setterFunction=this.registerDataOutput("setFunction",o,this._setPropertyValue.bind(this)),this.getterFunction=this.registerDataOutput("getFunction",o,this._getPropertyValue.bind(this)),this.generateAnimationsFunction=this.registerDataOutput("generateAnimationsFunction",o,this._getInterpolationAnimationPropertyInfo.bind(this)),this.templateComponent=new l(t.jsonPointer,this)}_doOperation(t){const e=this.templateComponent.getAccessor(this.config.pathConverter,t),o=e.info.get(e.object),n=e.info.getTarget?.(e.object),r=e.info.getPropertyName?.[0](e.object);if(!n)throw new Error("Object is undefined");return this.object.setValue(n,t),r&&this.propertyName.setValue(r,t),o}_setPropertyValue(t,e,o,n){const r=this.templateComponent.getAccessor(this.config.pathConverter,n),i=r.info.type;i.startsWith("Color")&&(o=h(o,i)),r.info.set?.(o,r.object)}_getPropertyValue(t,e,o){const a=this.templateComponent.getAccessor(this.config.pathConverter,o),p=a.info.type,c=a.info.get(a.object);return p.startsWith("Color")?function(t){if(t instanceof n)return new i(t.r,t.g,t.b);if(t instanceof r)return new s(t.r,t.g,t.b,t.a);throw new Error("Invalid color type")}(c):c}_getInterpolationAnimationPropertyInfo(t,e,o){const n=this.templateComponent.getAccessor(this.config.pathConverter,o);return(t,e,o,r)=>{const i=[],s=n.info.type;return s.startsWith("Color")&&(t=t.map((t=>({frame:t.frame,value:h(t.value,s)})))),n.info.interpolation?.forEach(((e,s)=>{const a=n.info.getPropertyName?.[s](n.object)||"Animation-interpolation-"+s;let p=t;o!==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(n.object,a,60,p);for(const t of c)r&&t.babylonAnimation.setEasingFunction(r),i.push(t.babylonAnimation)})),i}}getClassName(){return"FlowGraphJsonPointerParserBlock"}}function h(t,e){return t.getClassName().startsWith("Color")?t:"Color3"===e?new n(t.x,t.y,t.z):"Color4"===e?new r(t.x,t.y,t.z,t.w):t}a("FlowGraphJsonPointerParserBlock",u);export{u as FlowGraphJsonPointerParserBlock};
//# sourceMappingURL=flowGraphJsonPointerParserBlock-BnFKTvqy.esm.min.js.map