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) 3.31 kB
import{j as t,F as e,R as o}from"./declarationMapper-D_filC93.esm.min.js";import{i as n,b1 as r,V as i,bc as s,u as a}from"./index-BPURObVq.esm.min.js";import{F as p}from"./flowGraphCachedOperationBlock-CIvATd1Y.esm.min.js";import"./KHR_interactivity-D4lwBSW9.esm.min.js";import"./objectModelMapping-ClgDmo5Q.esm.min.js";import"./spotLight.pure-5s2DDDIt.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=m(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:m(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 m(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}let h=!1;function f(){h||(h=!0,a("FlowGraphJsonPointerParserBlock",u))}f();export{u as FlowGraphJsonPointerParserBlock,f as RegisterFlowGraphJsonPointerParserBlock}; //# sourceMappingURL=flowGraphJsonPointerParserBlock-LYw7vRyo.esm.min.js.map