@spiffcommerce/preview 2.1.31 → 2.1.32

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/main.js CHANGED
@@ -1,2 +1,2 @@
1
- var e=require("@babylonjs/core/Actions/actionManager"),i=require("@babylonjs/core/Actions/directActions"),t=require("@babylonjs/core/Engines/engine"),n=require("@babylonjs/core/Engines/nullEngine"),r=require("@babylonjs/core/Layers/glowLayer"),a=require("@babylonjs/core/Layers/highlightLayer"),s=require("@babylonjs/core/Loading/sceneLoader"),o=require("@babylonjs/core/Materials/PBR/pbrMaterial"),l=require("@babylonjs/core/Materials/Textures/cubeTexture"),c=require("@babylonjs/core/Materials/Textures/dynamicTexture"),h=require("@babylonjs/core/Maths/math.color"),d=require("@babylonjs/core/Maths/math.vector"),u=require("@babylonjs/core/Meshes/Compression/dracoCompression"),g=require("@babylonjs/core/Misc/observable"),m=require("@babylonjs/core/Misc/tools"),p=require("@babylonjs/core/scene"),b=require("@babylonjs/loaders/glTF");require("@babylonjs/core/Engines/Extensions/engine.views"),require("@babylonjs/core/Meshes/instancedMesh"),require("@babylonjs/core/Materials/Textures/Loaders/ddsTextureLoader"),require("@babylonjs/core/Materials/Textures/Loaders/envTextureLoader"),require("@babylonjs/core/Materials/Textures/Loaders/ktxTextureLoader"),require("@babylonjs/core/Animations/animatable"),require("@babylonjs/core/Misc/screenshotTools"),require("@babylonjs/core/Rendering/boundingBoxRenderer"),require("@babylonjs/loaders/glTF/2.0/Extensions");var f=require("@babylonjs/core/Materials/Textures/texture"),P=require("@babylonjs/core/Materials/Textures/mirrorTexture"),v=require("@babylonjs/core/Maths/math"),y=require("@babylonjs/core/Probes/reflectionProbe"),w=require("@babylonjs/core/Animations/animation"),x=require("@babylonjs/core/Animations/easing"),M=require("@babylonjs/core/Cameras/arcRotateCamera"),C=require("@babylonjs/core/Materials/colorCurves"),A=require("@babylonjs/core/Materials/imageProcessingConfiguration"),T=require("@babylonjs/core/PostProcesses/RenderPipeline"),O=require("@babylonjs/core/PostProcesses/depthOfFieldEffect");require("@babylonjs/core/Rendering/depthRendererSceneComponent");var L=require("@babylonjs/core/Misc/assetsManager");function E(e,i){return Object.keys(i).forEach((function(t){"default"===t||"__esModule"===t||e.hasOwnProperty(t)||Object.defineProperty(e,t,{enumerable:!0,get:function(){return i[t]}})})),e}function R(e,i,t,n){Object.defineProperty(e,i,{get:t,set:n,enumerable:!0,configurable:!0})}var S={};let F;var I;let B;var D;R(S,"ProductCameraRig",(()=>F)),R(S,"MaterialEffectMode",(()=>B)),(I=F||(F={}))[I.Orbit=0]="Orbit",I[I.Pan=1]="Pan",(D=B||(B={})).None="None",D.RemoveWhenSelected="RemoveWhenSelected",D.ApplyWhenSelected="ApplyWhenSelected";var q={};R(q,"SpiffCommerce3DPreviewService",(()=>ce)),R(q,"createBaseModel",(()=>he));const j=new Map;async function k(e,i,t){return new Promise(((n,r)=>{const a=j.get(e);if(a&&a.scene.uid===i.uid)return n(a);s.SceneLoader.LoadAssetContainerAsync(e,void 0,i,t).then((i=>{j.set(e,i),n(i)})).catch(r)}))}function N(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class V{constructor(e){N(this,"customOptions",void 0),N(this,"getSceneClearColor",(()=>{const e=this.customOptions?.transparentBackground||this.customOptions?.backgroundImage?0:1;if(this.customOptions&&this.customOptions?.transparentBackground||this.customOptions?.backgroundImage)return new(0,h.Color4)(0,0,0,e).toLinearSpace();if(this.customOptions&&this.customOptions.backgroundColor){const i=h.Color3.FromHexString(this.customOptions.backgroundColor);return new(0,h.Color4)(i.r,i.g,i.b,e).toLinearSpace()}return new(0,h.Color4)(.98,.98,.98,e).toLinearSpace()})),N(this,"highlightColorFromConfig",(()=>this.customOptions&&this.customOptions.highlightColor?this.hexToColor4(this.customOptions.highlightColor):new(0,h.Color4)(.98,.98,.98,1).toLinearSpace())),N(this,"hexToColor4",((e,i=1)=>{const t=h.Color3.FromHexString(e);return new(0,h.Color4)(t.r,t.g,t.b,i).toLinearSpace()})),this.customOptions=e}get options(){return this.customOptions}get scene(){return{clearColor:this.getSceneClearColor(),transparentBackground:this.customOptions?.transparentBackground||this.customOptions?.backgroundImage,environmentFile:this.customOptions?.environmentFile??"assets/model-viewer/default.env"}}get camera(){return{autoOrientation:this.customOptions?.disableAutomaticOrientation??!0,autoRotation:{enabled:this.customOptions?.autoRotation??!1,idleTimeMs:this.customOptions?.idleTimeBeforeRotation??5e3},limits:{min:{alpha:this.customOptions?.lowerAlphaLimitDeg?this.customOptions?.lowerAlphaLimitDeg*Math.PI/180:void 0,beta:this.customOptions?.lowerBetaLimitDeg?this.customOptions?.lowerBetaLimitDeg*Math.PI/180:void 0,radius:this.customOptions?.minZoomOverride},max:{alpha:this.customOptions?.upperAlphaLimitDeg?this.customOptions?.upperAlphaLimitDeg*Math.PI/180:void 0,beta:this.customOptions?.upperBetaLimitDeg?this.customOptions?.upperBetaLimitDeg*Math.PI/180:void 0,radius:this.customOptions?.maxZoomOverride}}}}get highlights(){return{enabled:this.customOptions?.highlightOnMaterialHover??!1,color:this.highlightColorFromConfig()}}get lighting(){return{exposure:this.customOptions?.lighting?.exposure??.9,contrast:this.customOptions?.lighting?.contrast??1.6}}}var _={};R(_,"RenderingConfiguration",(()=>z)),R(_,"REFLECTION_PROBE_RESOLUTION",(()=>H));class z{static getDynamicTextureResolution(){return this.getIsMobile()||!z.offscreenRenderingSupported()?{width:1024,height:1024}:{width:2048,height:2048}}static shouldMipMap(){return!0}static offscreenRenderingSupported(){return!navigator.userAgent.includes("SamsungBrowser")&&(!!window.Worker&&!!window.OffscreenCanvas)}static getMirrorTextureResolution(){return this.getIsMobile()?512:1024}static getIsMobile(){return window.innerWidth<=480}}const H=128;function G(e,i,n){i.forEach((i=>{const r=i.getID(),a=i.getName(),s=z.getDynamicTextureResolution();e.materials.filter((e=>e.name===a)).forEach((o=>{const l=n.get(r);if(l)U(o,l),l.update(false);else{const l=function(e,i,n,r){const a=new(0,c.DynamicTexture)(e,{width:n,height:r},i,z.shouldMipMap(),f.Texture.TRILINEAR_SAMPLINGMODE,t.Engine.TEXTUREFORMAT_RGBA),s=a.getContext();s&&(s.fillStyle="#f5f5f5",s.fillRect(0,0,n,r),a.update());return a}(a,e,s.width,s.height);n.set(r,l),i.setStaticContext(l.getContext()),U(o,l),l.onLoadObservable.addOnce((()=>{l.update(false)}))}}))}))}function U(e,i){if(e instanceof o.PBRMaterial){const t=e,n=t.albedoTexture;n?(i.wrapU=n.wrapU,i.wrapV=n.wrapV):(i.wrapU=1,i.wrapV=1),t.albedoTexture=i}else{const t=e,n=t.diffuseTexture;n&&(i.wrapU=n.wrapU,i.wrapV=n.wrapV),t.diffuseTexture=i}}function W(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class K{constructor(e){W(this,"name",void 0),W(this,"enabled",void 0),W(this,"loader",void 0),this.name="glbPostProcessor",this.enabled=!0,this.loader=e}onReady(){this.applyReflections(this.loader.babylonScene)}loadNodeAsync(e,i,t){return this.loader.loadNodeAsync(e,i,(function(e){i.extras&&Object.keys(i.extras).forEach((t=>{const n=i.extras[t];e.metadata[t]=n})),t(e)}))}loadMaterialPropertiesAsync(e,i,t){return this.enableMaterialExtrasIfRequired(i,t),this.loader.loadMaterialPropertiesAsync(e,i,t)}dispose(){}enableMaterialExtrasIfRequired(e,i){if(e.extras&&i instanceof o.PBRMaterial){if(e.extras.sheen){const t=i;t.sheen.isEnabled=!0,t.sheen.intensity=e.extras.sheen}if(e.extras.translucency){const t=i;t.subSurface.isTranslucencyEnabled=!0,t.subSurface.translucencyIntensity=e.extras.translucency,e.extras.translucencyR&&e.extras.translucencyG&&e.extras.translucencyB&&(t.subSurface.tintColor=new(0,v.Color3)(e.extras.translucencyR,e.extras.translucencyG,e.extras.translucencyB))}if(e.extras.refractionIOR){i.subSurface.indexOfRefraction=e.extras.refractionIOR}if(e.extras.useDepthPrePass){const e=i;e.needDepthPrePass=!0,e.forceIrradianceInFragment=!0}if(e.extras.useParallax){const t=i;t.useParallax=!0,t.useParallaxOcclusion=!0,t.parallaxScaleBias=e.extras.useParallax}}}applyReflections(e){function i(e){const i=[];return e.transformNodes.forEach((e=>{e.metadata&&e.metadata.reflective&&i.push(...e.getChildMeshes())})),e.meshes.forEach((e=>{e.metadata&&e.metadata.reflective&&!i.includes(e)&&i.push(e)})),i}e.meshes.forEach((t=>{const n=t.metadata;n&&(n.mirrorTexture&&function(t,n=1){const r=t.material;if(!r)return;const a=new(0,P.MirrorTexture)("mirror",z.getMirrorTextureResolution(),e,!0);a.renderList=i(e);const s=t.getVerticesData("normal");if(!s)throw new Error("Mirror attribute specified on: "+t.name+"But no normals exist to generate a mirror from!");t.computeWorldMatrix(!0);const o=t.getWorldMatrix(),l=v.Vector3.TransformNormal(new(0,v.Vector3)(s[0],s[1],s[2]),o).normalize(),c=v.Plane.FromPositionAndNormal(t.position,l.scale(-1));a.mirrorPlane=c,a.level=n,r.reflectionTexture=a}(t,n.mirrorTexture),n.reflectionProbe&&function(t){const n=t.material,r=new(0,y.ReflectionProbe)("probe-"+n.name,H,e);r.attachToMesh(t),r.renderList&&r.renderList.push(...i(e)),n.reflectionTexture=r.cubeTexture}(t))}))}}function Y(e,i,t,n){const r=e.animationGroups,a=e=>e.targetedAnimations.map((e=>e.animation.framePerSecond)).reduce(((e,i)=>e+i),0)/e.targetedAnimations.length||0;void 0===n||void 0===t||n!==t?r.forEach((e=>{e.stop();const r=a(e);e.start(i,1,n*r,t*r)})):r.forEach((e=>{e.stop();const t=a(e),r=n*t;e.start(i,1,r,r)}))}function Q(e){e.animationGroups.forEach((e=>{e.stop()}))}function Z(e,i,t){var n,r,a;e.stopAnimation(i),i.animations=[],Math.abs(i.alpha)>2*Math.PI&&(i.alpha=(n=i.alpha,r=0,a=2*Math.PI,n<r?a-(r-n)%(a-r):r+(n-r)%(a-r)));const s=[],o=t.target,l=o?1:0;if(t.target&&Object.keys(t.target).length>0&&s.push($("cameraTargetLerp","target",(new(0,d.Vector3)).copyFrom(i.target),new(0,d.Vector3)(t.target.x,t.target.y,t.target.z),w.Animation.ANIMATIONTYPE_VECTOR3,0)),s.push($("cameraAlphaLerp","alpha",i.alpha,X(t.lonDeg),w.Animation.ANIMATIONTYPE_FLOAT,l)),s.push($("cameraBetaLerp","beta",i.beta,X(t.latDeg),w.Animation.ANIMATIONTYPE_FLOAT,l)),void 0!==t.radius){const e=Math.max(.01,t.radius);s.push($("cameraRadiusLerp","radius",i.radius,e,w.Animation.ANIMATIONTYPE_FLOAT,l))}i.animations.push(...s);const c=i.useAutoRotationBehavior;i.disableAutoRotationBehavior(),e.beginAnimation(i,0,o?120:60,!1,1,(()=>{i.animations=[],c&&i.enableAutoRotationBehavior()}))}function X(e){return e*Math.PI/180}function $(e,i,t,n,r,a=0,s=w.Animation.ANIMATIONLOOPMODE_CONSTANT){const o=new(0,x.QuadraticEase);o.setEasingMode(x.EasingFunction.EASINGMODE_EASEINOUT);const l=new(0,w.Animation)(e,i,60,r,s),c=[];return a>0&&c.push({frame:0,value:t}),c.push({frame:60*a,value:t}),c.push({frame:60*(a+1),value:n}),l.setKeys(c),l.setEasingFunction(o),l}class J extends M.ArcRotateCamera{constructor(e,i,t,n,r,a,s,o){var l,c,h;super(e,i,t,n,r,a,o),l=this,c="lastFocus",h=new(0,d.Vector3)(0,0,0),c in l?Object.defineProperty(l,c,{value:h,enumerable:!0,configurable:!0,writable:!0}):l[c]=h,this.minZ=.01,this.maxZ=1e3*this.radius,this.lowerRadiusLimit=.01*this.radius,this.enableFramingBehavior(),this.upperRadiusLimit=1.5*this.radius,this.wheelPrecision=100/this.radius,this.pinchPrecision=300/this.radius,this.wheelDeltaPercentage=.01,this.pinchDeltaPercentage=.005,this.useNaturalPinchZoom=!0,s.camera.autoOrientation&&(this.alpha+=Math.PI),s&&(s.camera.limits.min.beta&&(this.lowerBetaLimit=s.camera.limits.min.beta),s.camera.limits.max.beta&&(this.upperBetaLimit=s.camera.limits.max.beta),s.camera.limits.min.alpha&&(this.lowerAlphaLimit=s.camera.limits.min.alpha),s.camera.limits.max.alpha&&(this.upperAlphaLimit=s.camera.limits.max.alpha),s.camera.limits.min.radius&&(this.lowerRadiusLimit=s.camera.limits.min.radius),s.camera.limits.max.radius&&(this.upperRadiusLimit=s.camera.limits.max.radius),s.camera.autoRotation.enabled&&this.enableAutoRotationBehavior(s.camera.autoRotation.idleTimeMs))}getFramingBehavior(){return this.getBehaviorByName("Framing")}getAutoRotationBehavior(){const e=this.getBehaviorByName("AutoRotation");return e||void 0}enableFramingBehavior(){this.useFramingBehavior=!0;const e=this.getFramingBehavior();e.attach(this),e.framingTime=0,e.elevationReturnTime=-1,e.zoomStopsAnimation=!1,this.lowerRadiusLimit=null;const i=ee(this._scene);return e.zoomOnBoundingInfo(i.min,i.max),this.wheelPrecision=100/this.radius,null===this.lowerRadiusLimit&&(this.lowerRadiusLimit=.1),this.lastFocus.copyFrom(this.target),e}rerunFramingBehavior(e){const i=this.getFramingBehavior();i.framingTime=800;const t=ee(this._scene);i.zoomOnBoundingInfo(t.min,t.max,void 0,(()=>{e()})),i.framingTime=0}enableAutoRotationBehavior(e=5e3){this.useAutoRotationBehavior=!0;const i=this.getAutoRotationBehavior();i&&(i.idleRotationWaitTime=e)}disableAutoRotationBehavior(){this.useAutoRotationBehavior=!1}static create(e,i){e.activeCamera&&(e.activeCamera.dispose(),e.activeCamera=null);const t=ee(e),n=t.max.subtract(t.min),r=t.min.add(n.scale(.5)),a=new J("ProductCamera",-Math.PI/2,Math.PI/2,1.5*n.length(),r,e,i);return a.panningInertia=0,a.panningOriginTarget.copyFrom(r),a.onAfterCheckInputsObservable.add((()=>{a.panningSensibility=1e3/n.length()})),e.activeCamera=a,a}}function ee(e){const i=e.meshes.filter((e=>e.name.toLowerCase().endsWith("_t")||e.name.toLowerCase().includes("_t_")));return e.getWorldExtends((e=>e.isVisible&&e.isEnabled()&&(0===i.length||i.includes(e))))}function ie(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class te{constructor(e,i=!0,t=null){ie(this,"renderingPipeline",void 0),ie(this,"currentConfig",void 0),this.renderingPipeline=new(0,T.DefaultRenderingPipeline)("default",i,e,t?[t]:void 0,!1),this.renderingPipeline.prepare()}dispose(){this.renderingPipeline.dispose()}addCamera(e){this.renderingPipeline.addCamera(e)}removeCamera(e){this.renderingPipeline.removeCamera(e)}getConfig(){return this.currentConfig}apply(e){if(this.renderingPipeline.samples=e.antiAliasing?.msaaSamples||this.renderingPipeline.samples,this.renderingPipeline.fxaaEnabled=e.antiAliasing?.fxaaEnabled||this.renderingPipeline.fxaaEnabled,this.renderingPipeline.bloomEnabled=e.bloom?.enabled||this.renderingPipeline.bloomEnabled,this.renderingPipeline.bloomKernel=e.bloom?.kernel||this.renderingPipeline.bloomKernel,this.renderingPipeline.bloomScale=e.bloom?.scale||this.renderingPipeline.bloomScale,this.renderingPipeline.bloomThreshold=e.bloom?.threshold||this.renderingPipeline.bloomThreshold,this.renderingPipeline.bloomWeight=e.bloom?.weight||this.renderingPipeline.bloomWeight,this.renderingPipeline.chromaticAberrationEnabled=e.chromaticAberration?.enabled||this.renderingPipeline.chromaticAberrationEnabled,this.renderingPipeline.chromaticAberration.aberrationAmount=e.chromaticAberration?.aberrationAmount||this.renderingPipeline.chromaticAberration.aberrationAmount,this.renderingPipeline.chromaticAberration.radialIntensity=e.chromaticAberration?.radialIntensity||this.renderingPipeline.chromaticAberration.radialIntensity,this.renderingPipeline.chromaticAberration.direction=e.chromaticAberration?.direction?new(0,d.Vector2)(e.chromaticAberration.direction.x,e.chromaticAberration.direction.y):this.renderingPipeline.chromaticAberration.direction,this.renderingPipeline.imageProcessing.colorCurvesEnabled=e.colorCurves?.enabled||this.renderingPipeline.imageProcessing.colorCurvesEnabled,this.renderingPipeline.imageProcessing.colorCurves=e.colorCurves?this.updateColorCurve(e.colorCurves,this.renderingPipeline.imageProcessing.colorCurves):this.renderingPipeline.imageProcessing.colorCurves,this.renderingPipeline.depthOfFieldEnabled=e.depthOfField?.enabled||this.renderingPipeline.depthOfFieldEnabled,e.depthOfField.blurLevel)switch(e.depthOfField.blurLevel){case"Low":this.renderingPipeline.depthOfFieldBlurLevel=O.DepthOfFieldEffectBlurLevel.Low;break;case"Medium":this.renderingPipeline.depthOfFieldBlurLevel=O.DepthOfFieldEffectBlurLevel.Medium;break;case"High":this.renderingPipeline.depthOfFieldBlurLevel=O.DepthOfFieldEffectBlurLevel.High}if(this.renderingPipeline.depthOfField.focalLength=e.depthOfField?.focalLength||this.renderingPipeline.depthOfField.focalLength,this.renderingPipeline.depthOfField.fStop=e.depthOfField?.fStop||this.renderingPipeline.depthOfField.fStop,this.renderingPipeline.depthOfField.focusDistance=e.depthOfField?.focusDistance||this.renderingPipeline.depthOfField.focusDistance,this.renderingPipeline.depthOfField.lensSize=e.depthOfField?.lensSize||this.renderingPipeline.depthOfField.lensSize,this.renderingPipeline.grainEnabled=e.grain?.enabled||this.renderingPipeline.grainEnabled,this.renderingPipeline.grain.animated=e.grain?.animated||this.renderingPipeline.grain.animated,this.renderingPipeline.grain.intensity=e.grain?.intensity||this.renderingPipeline.grain.intensity,this.renderingPipeline.imageProcessing.contrast=e.misc?.contrast||this.renderingPipeline.imageProcessing.contrast,this.renderingPipeline.imageProcessing.exposure=e.misc?.exposure||this.renderingPipeline.imageProcessing.exposure,this.renderingPipeline.imageProcessing.toneMappingEnabled=e.misc?.toneMappingEnabled||this.renderingPipeline.imageProcessing.toneMappingEnabled,e.misc.toneMappingType)switch(e.misc.toneMappingType){case"Standard":this.renderingPipeline.imageProcessing.toneMappingType=A.ImageProcessingConfiguration.TONEMAPPING_STANDARD;break;case"ACES":this.renderingPipeline.imageProcessing.toneMappingType=A.ImageProcessingConfiguration.TONEMAPPING_ACES}switch(this.renderingPipeline.sharpenEnabled=e.sharpen?.enabled||this.renderingPipeline.sharpenEnabled,this.renderingPipeline.sharpen.colorAmount=e.sharpen?.colorAmount||this.renderingPipeline.sharpen.colorAmount,this.renderingPipeline.sharpen.edgeAmount=e.sharpen?.edgeAmount||this.renderingPipeline.sharpen.edgeAmount,this.renderingPipeline.imageProcessing.vignetteEnabled=e.vignette?.enabled||this.renderingPipeline.imageProcessing.vignetteEnabled,this.renderingPipeline.imageProcessing.vignetteCenterX=e.vignette?.centerX||this.renderingPipeline.imageProcessing.vignetteCenterX,this.renderingPipeline.imageProcessing.vignetteCenterY=e.vignette?.centerY||this.renderingPipeline.imageProcessing.vignetteCenterY,e.vignette?.blendMode){case"Multiply":this.renderingPipeline.imageProcessing.vignetteBlendMode=A.ImageProcessingConfiguration.VIGNETTEMODE_MULTIPLY;break;case"Opaque":this.renderingPipeline.imageProcessing.vignetteBlendMode=A.ImageProcessingConfiguration.VIGNETTEMODE_OPAQUE}e.vignette.colorRgba?this.renderingPipeline.imageProcessing.vignetteColor=new(0,h.Color4)(e.vignette.colorRgba.r,e.vignette.colorRgba.g,e.vignette.colorRgba.b,e.vignette.colorRgba.a):e.vignette.colorHex&&(this.renderingPipeline.imageProcessing.vignetteColor=h.Color4.FromHexString(e.vignette.colorHex)),this.renderingPipeline.imageProcessing.vignetteStretch=e.vignette?.stretch||this.renderingPipeline.imageProcessing.vignetteStretch,this.renderingPipeline.imageProcessing.vignetteWeight=e.vignette?.weight||this.renderingPipeline.imageProcessing.vignetteWeight,this.renderingPipeline.prepare(),this.currentConfig={...this.currentConfig,...e}}updateColorCurve(e,i){const t=i??new(0,C.ColorCurves);return t.globalDensity=e.globalDensity??t.globalDensity,t.globalExposure=e.globalExposure??t.globalExposure,t.globalHue=e.globalHue??t.globalHue,t.globalSaturation=e.globalSaturation??t.globalSaturation,t.highlightsDensity=e.highlightsDensity??t.highlightsDensity,t.highlightsExposure=e.highlightsExposure??t.highlightsExposure,t.highlightsHue=e.highlightsHue??t.highlightsHue,t.highlightsSaturation=e.highlightsSaturation??t.highlightsSaturation,t.midtonesDensity=e.midtonesDensity??t.midtonesDensity,t.midtonesExposure=e.midtonesExposure??t.midtonesExposure,t.midtonesHue=e.midtonesHue??t.midtonesHue,t.midtonesSaturation=e.midtonesSaturation??t.midtonesSaturation,t.shadowsDensity=e.shadowsDensity??t.shadowsDensity,t.shadowsExposure=e.shadowsExposure??t.shadowsExposure,t.shadowsHue=e.shadowsHue??t.shadowsHue,t.shadowsSaturation=e.shadowsSaturation??t.shadowsSaturation,t}}const ne={albedoTexture:"albedoMap",bumpTexture:"normalMap",ambientTexture:"ambientMap",emissiveTexture:"emissionMap",opacityTexture:"alphaMap",metallicTexture:"metallicMap",refractionTexture:"refractionMap"};function re(e,i,t,n){["albedoTexture","bumpTexture","ambientTexture","emissiveTexture","opacityTexture","metallicTexture","refractionTexture"].forEach((r=>{!function(e,i,t,n,r){const a=ne[e];if(!a)throw new Error("Unexpected texture name encountered.");const s=i[a]?.fileLink;s?n.addTextureTask(e,s,!1,!1):r&&t[e]&&(t[e]&&t[e].dispose(),t[e]=null,function(e,i){"opacityTexture"===e&&(i.useAlphaFromAlbedoTexture=!0);"metallicTexture"===e&&(i.useRoughnessFromMetallicTextureAlpha=!1,i.useRoughnessFromMetallicTextureGreen=!1,i.useMetallnessFromMetallicTextureBlue=!1);"refractionTexture"===e&&(i.subSurface.isRefractionEnabled=!1,i.subSurface.refractionIntensity=1)}(e,t))}(r,e,i,t,n)})),function(e,i){if(!e.clearCoat)return;e.clearCoat===B.RemoveWhenSelected?(i.clearCoat.isEnabled=!1,i.clearCoat.indexOfRefraction=1.5):e.clearCoat===B.ApplyWhenSelected&&(i.clearCoat.isEnabled=!0,i.clearCoat.indexOfRefraction=e.clearCoatIOR||i.clearCoat.indexOfRefraction)}(e,i)}function ae(e,i,t,n){"opacityTexture"===e&&(i.useAlphaFromAlbedoTexture=!1),"metallicTexture"===e&&(i.useRoughnessFromMetallicTextureAlpha=!1,i.useRoughnessFromMetallicTextureGreen=!0,i.useMetallnessFromMetallicTextureBlue=!0),"refractionTexture"===e&&(i.subSurface.isRefractionEnabled=!0,i.subSurface.refractionIntensity=t.refractionIntensity||1),i[e]=n}function se(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class oe{constructor(){se(this,"materialVariantMap",new Map),se(this,"keysThatRemovedBaseModel",[]),se(this,"loadedContainerForKey",new Map)}async applyMaterial(e,i,t,n,r){return new Promise((a=>{const s=e.materials.filter((e=>e.name===i)),o=this.materialVariantMap.get(i);if(this.materialVariantMap.set(i,{...o,...t}),0===s.length)return void a(void 0);const l=new(0,L.AssetsManager)(e);l.useDefaultLoadingScreen=!1,s.forEach((e=>re(t,e,l,r))),l.onProgress=(e,i,t)=>{n&&n(e/i*100,100,t.name)},l.onFinish=e=>{e.forEach((e=>{const i=e;n&&n(100,100,e.name),s.forEach((n=>ae(e.name,n,t,i.texture)))})),a(void 0)},l.loadAsync()}))}async applyModel(e,i,t,n,r){if(n&&t&&!this.keysThatRemovedBaseModel.includes(i)&&this.keysThatRemovedBaseModel.push(i),!n){const t=this.keysThatRemovedBaseModel.includes(i);return this.loadedContainerForKey.get(i)?.removeAllFromScene(),e&&t&&await he(e.metadata.baseModel,e),Promise.resolve()}const a=await k(n,e,r);if(this.loadedContainerForKey.has(i)&&this.loadedContainerForKey.get(i)?.removeAllFromScene(),t){(await k(e.metadata.baseModel,e)).removeAllFromScene()}a.addAllToScene(),this.loadedContainerForKey.set(i,a);const s=[];this.materialVariantMap.forEach((async(i,t)=>{s.push(this.applyMaterial(e,t,i))})),await Promise.all(s)}}function le(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}b.GLTF2.GLTFLoader.RegisterExtension("glbPostProcessor",(function(e){return new K(e)})),s.SceneLoader.OnPluginActivatedObservable.add((e=>{if("gltf"===e.name){e.transparencyAsCoverage=!0}}));class ce{constructor(e){le(this,"engine",void 0),le(this,"scene",void 0),le(this,"configuration",void 0),le(this,"loadProgress",new Map([["initialScene",0]])),le(this,"materialReadyToLoadCallbacks",new Map),le(this,"modelReadyToLoadCallbacks",new Map),le(this,"queuedModelAnimation",void 0),le(this,"queuedCameraAnimation",void 0),le(this,"focusLostNotified",!1),le(this,"loadObservable",new(0,g.Observable)),le(this,"focusLostObservable",new(0,g.Observable)),le(this,"dynamicTextures",new Map),le(this,"highlightLayer",void 0),le(this,"variantManager",new oe),le(this,"renderingPipeline",void 0);const i=e?.noRender?void 0:document.createElement("canvas");this.configuration=new V(e);u.DracoCompression.Configuration={decoder:{wasmUrl:"https://www.gstatic.com/draco/versioned/decoders/1.5.6/draco_wasm_wrapper_gltf.js",wasmBinaryUrl:"https://www.gstatic.com/draco/versioned/decoders/1.5.6/draco_decoder_gltf.wasm",fallbackUrl:"https://www.gstatic.com/draco/versioned/decoders/1.5.6/draco_decoder_gltf.js"}},i&&(i.getContext("webgl2")||i.getContext("webgl"));const r=console.log;console.log=()=>{};const a=i?new(0,t.Engine)(i,!0,{premultipliedAlpha:!1,preserveDrawingBuffer:!!e?.backgroundImage,audioEngine:!1,stencil:this.configuration.highlights.enabled,forceSRGBBufferSupportState:!0}):new(0,n.NullEngine);console.log=r,a.hideLoadingUI(),window.addEventListener("resize",this.fireResizeEvent.bind(this)),this.engine=a,this.scene=new(0,p.Scene)(a),this.renderingPipeline=new te(this.scene,!0),this.scene.imageProcessingConfiguration.exposure=this.configuration.lighting.exposure,this.scene.imageProcessingConfiguration.contrast=this.configuration.lighting.contrast}registerFocusLostListener(e){this.focusLostObservable.add(e)}unregisterFocusLostListener(e){this.focusLostObservable.removeCallback(e)}registerLoadProgressListener(e){this.loadObservable.add(e),e(this.getLoadListenerEvent())}unregisterLoadProgressListener(e){this.loadObservable.removeCallback(e)}registerView(e){const i=e.height,t=e.width;this.engine.registerView(e),e.setAttribute("height",i.toString()),e.setAttribute("width",t.toString()),this.orbitEnabled()||this.setCameraState(F.Pan),this.reattachControls(e)}getNumViewports(){return this.engine.views?.length||0}unregisterView(e){this.engine.unRegisterView(e)}shutdown(){this.renderingPipeline.dispose(),this.engine&&this.engine.dispose(),window.removeEventListener("resize",this.fireResizeEvent)}getSceneInitializationProgress(){return this.loadProgress.get("initialScene")}async initialize(t,n){if(this.scene.clearColor=this.configuration.scene.clearColor,this.scene.metadata={baseModel:t},this.scene.environmentTexture=l.CubeTexture.CreateFromPrefilteredData(this.configuration.scene.environmentFile,this.scene),t){const e=100;await he(t,this.scene,(i=>{this.loadProgress.set("initialScene",i.loaded*e/i.total),this.notifyLoadHandlers()}))}this.configuration.highlights.enabled&&this.scene.meshes.forEach((t=>{"targetcube_t"!==t.name&&"backgroundShell"!==t.name&&(t.isPickable=!0,t.actionManager||(t.actionManager=new(0,e.ActionManager)(this.scene)),t.actionManager.registerAction(new(0,i.ExecuteCodeAction)(e.ActionManager.OnPointerOutTrigger,(()=>{this.setHighlights([])}))),t.actionManager.registerAction(new(0,i.ExecuteCodeAction)(e.ActionManager.OnPointerOverTrigger,(e=>{if(e.meshUnderPointer){const i=e.meshUnderPointer.material;i&&this.setHighlights([i])}}))))}));const a=J.create(this.scene,this.configuration);this.renderingPipeline.addCamera(a),this.configuration.options.renderingPipelineConfig&&this.renderingPipeline.apply(this.configuration.options.renderingPipelineConfig);const s=n?.getAll()||new Map;G(this.scene,s,this.dynamicTextures);if(this.scene.materials.some((e=>"emissiveTexture"in e&&null!==e.emissiveTexture))){new(0,r.GlowLayer)("GlowLayer",this.scene).intensity=.5}Q(this.scene),this.engine.views?.length>=1&&this.reattachControls(this.engine.views[this.engine.views.length-1].target),await this.processQueuedLoadEvents(),this.engine.runRenderLoop((()=>{this.engine.views&&(s.forEach(((e,i)=>{const t=this.dynamicTextures.get(i);t&&e.getStaticContextDirty()&&t.isReady()&&(t.update(!1),e.setStaticContextDirty(!1))})),this.configuration.scene.transparentBackground&&this.engine.views.forEach((e=>{const i=this.engine.getRenderingCanvas();e.target.getContext("2d").clearRect(0,0,i.width,i.height)})),this.scene.render(),a.target.equalsWithEpsilon(a.lastFocus,.1)||this.focusLostNotified||(this.focusLostObservable.notifyObservers(void 0),this.focusLostNotified=!0))}))}executeModelAnimation(e){100===this.getSceneInitializationProgress()?Y(this.scene,e.loop,e.to,e.from):this.queuedModelAnimation=e}executeCameraAnimation(e){100===this.getSceneInitializationProgress()&&this.scene.activeCamera?Z(this.scene,this.scene.activeCamera,e):this.queuedCameraAnimation=e}getCameraPose(){if(this.scene){const e=this.scene.activeCamera;if(e)return{lonDeg:Math.round(180*e.alpha/Math.PI),latDeg:Math.round(180*e.beta/Math.PI),radius:Math.round(1e4*(e.radius+Number.EPSILON))/1e4,target:{x:e.target.x,y:e.target.y,z:e.target.z}}}}setCameraPose(e){if(this.scene){const i=this.scene.activeCamera;i&&(i.target=new(0,d.Vector3)(e.target.x,e.target.y,e.target.z),i.radius=e.radius,i.alpha=e.latDeg,i.beta=e.lonDeg)}}async applyMaterialVariant(e,i,t,n){if(100===this.getSceneInitializationProgress())await this.variantManager.applyMaterial(this.scene,e,t,((e,i,t)=>{this.loadProgress.set(`key_${t}`,e/i*100),this.notifyLoadHandlers()}),n);else if(this.materialReadyToLoadCallbacks.has(e)){this.materialReadyToLoadCallbacks.get(e)?.set(i,t)}else{this.materialReadyToLoadCallbacks.set(e,new Map);this.materialReadyToLoadCallbacks.get(e)?.set(i,t)}}async applyModelVariant(e,i,t){100===this.getSceneInitializationProgress()?(await this.variantManager.applyModel(this.scene,e,t||!1,i.model,(i=>{this.loadProgress.set(e,100*i.loaded/i.total),this.notifyLoadHandlers()})),this.scene.materials.forEach((e=>{if(e&&0===e.getBindedMeshes().length){const i=e instanceof o.PBRMaterial&&!(e.albedoTexture instanceof c.DynamicTexture);e.dispose(!1,i)}})),G(this.scene,i.contextService.getAll(),this.dynamicTextures),Q(this.scene)):this.modelReadyToLoadCallbacks.set(e,(async()=>{await this.applyModelVariant(e,i,t)}))}getQueuedMaterialVariants(){return this.materialReadyToLoadCallbacks.size}getQueuedModelVariants(){return this.modelReadyToLoadCallbacks.size}setCameraState(e){if(!this.engine?.views||!this.engine?.views[0])throw new Error("No views attached, camera state requires a view to attach controls onto.");e===F.Orbit?this.reattachControls(this.engine.views[0].target,2):this.reattachControls(this.engine.views[0].target,0)}animateToLastCameraFocus(){return new Promise((e=>{const i=this.scene.activeCamera,t=this.configuration;i.rerunFramingBehavior((()=>{this.focusLostNotified=!1,t.camera.limits.min.radius&&(i.lowerRadiusLimit=t.camera.limits.min.radius),t.camera.limits.max.radius&&(i.upperRadiusLimit=t.camera.limits.max.radius),e()}))}))}setAutoRotation(e){const i=this.scene.activeCamera;this.configuration.camera.autoRotation.enabled&&i&&(e?i.enableAutoRotationBehavior(this.configuration.camera.autoRotation.idleTimeMs):i.disableAutoRotationBehavior())}getCurrentConfiguration(){return this.configuration.options}async renderSceneScreenshot(e,i){const t=this.scene.activeCamera;if(!t)throw new Error("Missing product camera, cannot render screenshot!");var n;(n=t).getScene().stopAnimation(n),n.animations=[];const r=t.alpha,a=t.beta,s=t.radius,o=i.latDeg*Math.PI/180,l=i.lonDeg*Math.PI/180;t.alpha=l,t.beta=o,t.radius=i.radius||t.radius;const c=await m.Tools.CreateScreenshotUsingRenderTargetAsync(this.engine,t,e,"image/png",2,!0);return t.alpha=r,t.beta=a,t.radius=s,c}orbitEnabled(){const e=this.configuration;if(!e)return!0;const i=e.camera.limits.min.alpha,t=e.camera.limits.max.alpha,n=e.camera.limits.min.beta,r=e.camera.limits.max.beta;if(void 0===i||void 0===t||void 0===n||void 0===r)return!0;const a=[n,r],s=[i,t].every((e=>e===i)),o=a.every((e=>e===n));return!s&&!o}fireResizeEvent(){this.getNumViewports()>0&&this.engine.resize()}onMaterialSelected(t){this.scene.meshes.forEach((n=>{"targetcube_t"!==n.name&&"backgroundShell"!==n.name&&(n.actionManager||(n.actionManager=new(0,e.ActionManager)(this.scene)),n.actionManager.registerAction(new(0,i.ExecuteCodeAction)(e.ActionManager.OnPickDownTrigger,(e=>{if(e.meshUnderPointer){const i=e.meshUnderPointer.material;i&&t({id:i.id,name:i.name})}}))))}))}listMaterials(){const e=this.scene?.materials;return e?e.map((e=>({id:e.id,name:e.name}))):[]}setHighlights(e,i){0===e.length&&(this.highlightLayer?.dispose(),this.highlightLayer=void 0),this.highlightLayer||(this.highlightLayer=new(0,a.HighlightLayer)("highlights",this.scene,{isStroke:!0,blurVerticalSize:.85,blurHorizontalSize:.85}),this.highlightLayer.innerGlow=!0,this.highlightLayer.outerGlow=!1),this.highlightLayer.removeAllMeshes();const t=i?new(0,h.Color3)(i[0],i[1],i[2]).toLinearSpace():void 0;e.forEach((e=>{const i=this.scene.materials.find((i=>i.name===e.name&&i.id===e.id));i&&i.getBindedMeshes().forEach((e=>this.highlightLayer?.addMesh(e,t||h.Color3.FromHexString("#fcba03"))))}))}setRenderingPipelineConfig(e){this.renderingPipeline&&this.renderingPipeline.apply(e)}reattachControls(e,i=2){this.scene.detachControl(),this.engine.inputElement=e;const t=this.scene.activeCamera;if(t){t.attachControl(!0,!1,i);t.inputs.attached.pointers.multiTouchPanning=!1}this.scene.attachControl(!0,!0,!0)}getLoadListenerEvent(){const e=Array.from(this.loadProgress.values()).filter((e=>e<100)),i=e.reduce(((e,i)=>e+i),0)/e.length||0;return{loadValue:0===e.length?100:i,sceneInitialized:100===this.getSceneInitializationProgress()}}notifyLoadHandlers(){this.loadObservable.notifyObservers(this.getLoadListenerEvent())}async processQueuedLoadEvents(){await Promise.all(Array.from(this.modelReadyToLoadCallbacks.values()).map((e=>e(this.scene)))),this.modelReadyToLoadCallbacks.clear(),this.materialReadyToLoadCallbacks.forEach(((e,i)=>{e.forEach(((e,t)=>{this.applyMaterialVariant(i,t,e)}))})),this.materialReadyToLoadCallbacks.clear(),this.queuedModelAnimation&&(this.executeModelAnimation(this.queuedModelAnimation),this.queuedModelAnimation=void 0),this.queuedCameraAnimation&&(this.executeCameraAnimation(this.queuedCameraAnimation),this.queuedCameraAnimation=void 0)}}async function he(e,i,t){(await k(e,i,t)).addAllToScene()}E(module.exports,S),E(module.exports,q),E(module.exports,_);
1
+ var e=require("@babylonjs/core/Actions/actionManager"),i=require("@babylonjs/core/Actions/directActions"),t=require("@babylonjs/core/Engines/engine"),n=require("@babylonjs/core/Engines/nullEngine"),r=require("@babylonjs/core/Layers/glowLayer"),a=require("@babylonjs/core/Layers/highlightLayer"),s=require("@babylonjs/core/Loading/sceneLoader"),o=require("@babylonjs/core/Materials/PBR/pbrMaterial"),l=require("@babylonjs/core/Materials/Textures/cubeTexture"),c=require("@babylonjs/core/Materials/Textures/dynamicTexture"),h=require("@babylonjs/core/Maths/math.color"),d=require("@babylonjs/core/Maths/math.vector"),u=require("@babylonjs/core/Meshes/Compression/dracoCompression"),g=require("@babylonjs/core/Misc/observable"),m=require("@babylonjs/core/Misc/tools"),p=require("@babylonjs/core/scene"),b=require("@babylonjs/loaders/glTF");require("@babylonjs/core/Engines/Extensions/engine.views"),require("@babylonjs/core/Meshes/instancedMesh"),require("@babylonjs/core/Materials/Textures/Loaders/ddsTextureLoader"),require("@babylonjs/core/Materials/Textures/Loaders/envTextureLoader"),require("@babylonjs/core/Materials/Textures/Loaders/ktxTextureLoader"),require("@babylonjs/core/Animations/animatable"),require("@babylonjs/core/Misc/screenshotTools"),require("@babylonjs/core/Rendering/boundingBoxRenderer"),require("@babylonjs/loaders/glTF/2.0/Extensions");var f=require("@babylonjs/core/Materials/Textures/texture"),P=require("@babylonjs/core/Materials/Textures/mirrorTexture"),v=require("@babylonjs/core/Maths/math"),y=require("@babylonjs/core/Probes/reflectionProbe"),w=require("@babylonjs/core/Animations/animation"),x=require("@babylonjs/core/Animations/easing"),M=require("@babylonjs/core/Cameras/arcRotateCamera"),C=require("@babylonjs/core/Materials/colorCurves"),A=require("@babylonjs/core/Materials/imageProcessingConfiguration"),T=require("@babylonjs/core/PostProcesses/RenderPipeline"),O=require("@babylonjs/core/PostProcesses/depthOfFieldEffect");require("@babylonjs/core/Rendering/depthRendererSceneComponent");var L=require("@babylonjs/core/Misc/assetsManager");function E(e,i){return Object.keys(i).forEach((function(t){"default"===t||"__esModule"===t||e.hasOwnProperty(t)||Object.defineProperty(e,t,{enumerable:!0,get:function(){return i[t]}})})),e}function R(e,i,t,n){Object.defineProperty(e,i,{get:t,set:n,enumerable:!0,configurable:!0})}var S={};let F;var I;let B;var D;R(S,"ProductCameraRig",(()=>F)),R(S,"MaterialEffectMode",(()=>B)),(I=F||(F={}))[I.Orbit=0]="Orbit",I[I.Pan=1]="Pan",(D=B||(B={})).None="None",D.RemoveWhenSelected="RemoveWhenSelected",D.ApplyWhenSelected="ApplyWhenSelected";var q={};R(q,"SpiffCommerce3DPreviewService",(()=>ce)),R(q,"createBaseModel",(()=>he));const j=new Map;async function k(e,i,t){return new Promise(((n,r)=>{const a=j.get(e);if(a&&a.scene.uid===i.uid)return n(a);s.SceneLoader.LoadAssetContainerAsync(e,void 0,i,t).then((i=>{j.set(e,i),n(i)})).catch(r)}))}function N(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class V{constructor(e){N(this,"customOptions",void 0),N(this,"getSceneClearColor",(()=>{const e=this.customOptions?.transparentBackground||this.customOptions?.backgroundImage?0:1;if(this.customOptions&&this.customOptions?.transparentBackground||this.customOptions?.backgroundImage)return new(0,h.Color4)(0,0,0,e).toLinearSpace();if(this.customOptions&&this.customOptions.backgroundColor){const i=h.Color3.FromHexString(this.customOptions.backgroundColor);return new(0,h.Color4)(i.r,i.g,i.b,e).toLinearSpace()}return new(0,h.Color4)(.98,.98,.98,e).toLinearSpace()})),N(this,"highlightColorFromConfig",(()=>this.customOptions&&this.customOptions.highlightColor?this.hexToColor4(this.customOptions.highlightColor):new(0,h.Color4)(.98,.98,.98,1).toLinearSpace())),N(this,"hexToColor4",((e,i=1)=>{const t=h.Color3.FromHexString(e);return new(0,h.Color4)(t.r,t.g,t.b,i).toLinearSpace()})),this.customOptions=e}get options(){return this.customOptions}get scene(){return{clearColor:this.getSceneClearColor(),transparentBackground:this.customOptions?.transparentBackground||this.customOptions?.backgroundImage,environmentFile:this.customOptions?.environmentFile??"assets/model-viewer/default.env"}}get camera(){return{autoOrientation:this.customOptions?.disableAutomaticOrientation??!0,autoRotation:{enabled:this.customOptions?.autoRotation??!1,idleTimeMs:this.customOptions?.idleTimeBeforeRotation??5e3},limits:{min:{alpha:this.customOptions?.lowerAlphaLimitDeg?this.customOptions?.lowerAlphaLimitDeg*Math.PI/180:void 0,beta:this.customOptions?.lowerBetaLimitDeg?this.customOptions?.lowerBetaLimitDeg*Math.PI/180:void 0,radius:this.customOptions?.minZoomOverride},max:{alpha:this.customOptions?.upperAlphaLimitDeg?this.customOptions?.upperAlphaLimitDeg*Math.PI/180:void 0,beta:this.customOptions?.upperBetaLimitDeg?this.customOptions?.upperBetaLimitDeg*Math.PI/180:void 0,radius:this.customOptions?.maxZoomOverride}}}}get highlights(){return{enabled:this.customOptions?.highlightOnMaterialHover??!1,color:this.highlightColorFromConfig()}}get lighting(){return{exposure:this.customOptions?.lighting?.exposure??.9,contrast:this.customOptions?.lighting?.contrast??1.6}}}var _={};R(_,"RenderingConfiguration",(()=>z)),R(_,"REFLECTION_PROBE_RESOLUTION",(()=>H));class z{static getDynamicTextureResolution(){return this.getIsMobile()||!z.offscreenRenderingSupported()?{width:1024,height:1024}:{width:2048,height:2048}}static shouldMipMap(){return!0}static offscreenRenderingSupported(){return!navigator.userAgent.includes("SamsungBrowser")&&(!!window.Worker&&!!window.OffscreenCanvas)}static getMirrorTextureResolution(){return this.getIsMobile()?512:1024}static getIsMobile(){return window.innerWidth<=480}}const H=128;function G(e,i,n){i.forEach((i=>{const r=i.getID(),a=i.getName(),s=z.getDynamicTextureResolution();e.materials.filter((e=>e.name===a)).forEach((o=>{const l=n.get(r);if(l)U(o,l),l.update(false);else{const l=function(e,i,n,r){const a=new(0,c.DynamicTexture)(e,{width:n,height:r},i,z.shouldMipMap(),f.Texture.TRILINEAR_SAMPLINGMODE,t.Engine.TEXTUREFORMAT_RGBA),s=a.getContext();s&&(s.fillStyle="#f5f5f5",s.fillRect(0,0,n,r),a.update());return a}(a,e,s.width,s.height);n.set(r,l),i.setStaticContext(l.getContext()),U(o,l),l.onLoadObservable.addOnce((()=>{l.update(false)}))}}))}))}function U(e,i){if(e instanceof o.PBRMaterial){const t=e,n=t.albedoTexture;n?(i.wrapU=n.wrapU,i.wrapV=n.wrapV):(i.wrapU=1,i.wrapV=1),t.albedoTexture=i}else{const t=e,n=t.diffuseTexture;n&&(i.wrapU=n.wrapU,i.wrapV=n.wrapV),t.diffuseTexture=i}}function W(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class K{constructor(e){W(this,"name",void 0),W(this,"enabled",void 0),W(this,"loader",void 0),this.name="glbPostProcessor",this.enabled=!0,this.loader=e}onReady(){this.applyReflections(this.loader.babylonScene)}loadNodeAsync(e,i,t){return this.loader.loadNodeAsync(e,i,(function(e){i.extras&&Object.keys(i.extras).forEach((t=>{const n=i.extras[t];e.metadata[t]=n})),t(e)}))}loadMaterialPropertiesAsync(e,i,t){return this.enableMaterialExtrasIfRequired(i,t),this.loader.loadMaterialPropertiesAsync(e,i,t)}dispose(){}enableMaterialExtrasIfRequired(e,i){if(e.extras&&i instanceof o.PBRMaterial){if(e.extras.sheen){const t=i;t.sheen.isEnabled=!0,t.sheen.intensity=e.extras.sheen}if(e.extras.translucency){const t=i;t.subSurface.isTranslucencyEnabled=!0,t.subSurface.translucencyIntensity=e.extras.translucency,e.extras.translucencyR&&e.extras.translucencyG&&e.extras.translucencyB&&(t.subSurface.tintColor=new(0,v.Color3)(e.extras.translucencyR,e.extras.translucencyG,e.extras.translucencyB))}if(e.extras.refractionIOR){i.subSurface.indexOfRefraction=e.extras.refractionIOR}if(e.extras.useDepthPrePass){const e=i;e.needDepthPrePass=!0,e.forceIrradianceInFragment=!0}if(e.extras.useParallax){const t=i;t.useParallax=!0,t.useParallaxOcclusion=!0,t.parallaxScaleBias=e.extras.useParallax}}}applyReflections(e){function i(e){const i=[];return e.transformNodes.forEach((e=>{e.metadata&&e.metadata.reflective&&i.push(...e.getChildMeshes())})),e.meshes.forEach((e=>{e.metadata&&e.metadata.reflective&&!i.includes(e)&&i.push(e)})),i}e.meshes.forEach((t=>{const n=t.metadata;n&&(n.mirrorTexture&&function(t,n=1){const r=t.material;if(!r)return;const a=new(0,P.MirrorTexture)("mirror",z.getMirrorTextureResolution(),e,!0);a.renderList=i(e);const s=t.getVerticesData("normal");if(!s)throw new Error("Mirror attribute specified on: "+t.name+"But no normals exist to generate a mirror from!");t.computeWorldMatrix(!0);const o=t.getWorldMatrix(),l=v.Vector3.TransformNormal(new(0,v.Vector3)(s[0],s[1],s[2]),o).normalize(),c=v.Plane.FromPositionAndNormal(t.position,l.scale(-1));a.mirrorPlane=c,a.level=n,r.reflectionTexture=a}(t,n.mirrorTexture),n.reflectionProbe&&function(t){const n=t.material,r=new(0,y.ReflectionProbe)("probe-"+n.name,H,e);r.attachToMesh(t),r.renderList&&r.renderList.push(...i(e)),n.reflectionTexture=r.cubeTexture}(t))}))}}function Q(e,i,t,n){const r=e.animationGroups,a=e=>e.targetedAnimations.map((e=>e.animation.framePerSecond)).reduce(((e,i)=>e+i),0)/e.targetedAnimations.length||0;void 0===n||void 0===t||n!==t?r.forEach((e=>{e.stop();const r=a(e);e.start(i,1,n*r,t*r)})):r.forEach((e=>{e.stop();const t=a(e),r=n*t;e.start(i,1,r,r)}))}function Y(e){e.animationGroups.forEach((e=>{e.stop()}))}function Z(e,i,t){var n,r,a;e.stopAnimation(i),i.animations=[],Math.abs(i.alpha)>2*Math.PI&&(i.alpha=(n=i.alpha,r=0,a=2*Math.PI,n<r?a-(r-n)%(a-r):r+(n-r)%(a-r)));const s=[],o=t.target,l=o?1:0;if(t.target&&Object.keys(t.target).length>0&&s.push($("cameraTargetLerp","target",(new(0,d.Vector3)).copyFrom(i.target),new(0,d.Vector3)(t.target.x,t.target.y,t.target.z),w.Animation.ANIMATIONTYPE_VECTOR3,0)),s.push($("cameraAlphaLerp","alpha",i.alpha,X(t.lonDeg),w.Animation.ANIMATIONTYPE_FLOAT,l)),s.push($("cameraBetaLerp","beta",i.beta,X(t.latDeg),w.Animation.ANIMATIONTYPE_FLOAT,l)),void 0!==t.radius){const e=Math.max(.01,t.radius);s.push($("cameraRadiusLerp","radius",i.radius,e,w.Animation.ANIMATIONTYPE_FLOAT,l))}i.animations.push(...s);const c=i.useAutoRotationBehavior;i.disableAutoRotationBehavior(),e.beginAnimation(i,0,o?120:60,!1,1,(()=>{i.animations=[],c&&i.enableAutoRotationBehavior()}))}function X(e){return e*Math.PI/180}function $(e,i,t,n,r,a=0,s=w.Animation.ANIMATIONLOOPMODE_CONSTANT){const o=new(0,x.QuadraticEase);o.setEasingMode(x.EasingFunction.EASINGMODE_EASEINOUT);const l=new(0,w.Animation)(e,i,60,r,s),c=[];return a>0&&c.push({frame:0,value:t}),c.push({frame:60*a,value:t}),c.push({frame:60*(a+1),value:n}),l.setKeys(c),l.setEasingFunction(o),l}class J extends M.ArcRotateCamera{constructor(e,i,t,n,r,a,s,o){var l,c,h;super(e,i,t,n,r,a,o),l=this,c="lastFocus",h=new(0,d.Vector3)(0,0,0),c in l?Object.defineProperty(l,c,{value:h,enumerable:!0,configurable:!0,writable:!0}):l[c]=h,this.minZ=.01,this.maxZ=1e3*this.radius,this.lowerRadiusLimit=.01*this.radius,this.enableFramingBehavior(),this.upperRadiusLimit=1.5*this.radius,this.wheelPrecision=100/this.radius,this.pinchPrecision=300/this.radius,this.wheelDeltaPercentage=.01,this.pinchDeltaPercentage=.005,this.useNaturalPinchZoom=!0,s.camera.autoOrientation&&(this.alpha+=Math.PI),s&&(s.camera.limits.min.beta&&(this.lowerBetaLimit=s.camera.limits.min.beta),s.camera.limits.max.beta&&(this.upperBetaLimit=s.camera.limits.max.beta),s.camera.limits.min.alpha&&(this.lowerAlphaLimit=s.camera.limits.min.alpha),s.camera.limits.max.alpha&&(this.upperAlphaLimit=s.camera.limits.max.alpha),s.camera.limits.min.radius&&(this.lowerRadiusLimit=s.camera.limits.min.radius),s.camera.limits.max.radius&&(this.upperRadiusLimit=s.camera.limits.max.radius),s.camera.autoRotation.enabled&&this.enableAutoRotationBehavior(s.camera.autoRotation.idleTimeMs))}getFramingBehavior(){return this.getBehaviorByName("Framing")}getAutoRotationBehavior(){const e=this.getBehaviorByName("AutoRotation");return e||void 0}enableFramingBehavior(){this.useFramingBehavior=!0;const e=this.getFramingBehavior();e.attach(this),e.framingTime=0,e.elevationReturnTime=-1,e.zoomStopsAnimation=!1,this.lowerRadiusLimit=null;const i=ee(this._scene);return e.zoomOnBoundingInfo(i.min,i.max),this.wheelPrecision=100/this.radius,null===this.lowerRadiusLimit&&(this.lowerRadiusLimit=.1),this.lastFocus.copyFrom(this.target),e}rerunFramingBehavior(e){const i=this.getFramingBehavior();i.framingTime=800;const t=ee(this._scene);i.zoomOnBoundingInfo(t.min,t.max,void 0,(()=>{e()})),i.framingTime=0}enableAutoRotationBehavior(e=5e3){this.useAutoRotationBehavior=!0;const i=this.getAutoRotationBehavior();i&&(i.idleRotationWaitTime=e)}disableAutoRotationBehavior(){this.useAutoRotationBehavior=!1}static create(e,i){e.activeCamera&&(e.activeCamera.dispose(),e.activeCamera=null);const t=ee(e),n=t.max.subtract(t.min),r=t.min.add(n.scale(.5)),a=new J("ProductCamera",-Math.PI/2,Math.PI/2,1.5*n.length(),r,e,i);return a.panningInertia=0,a.panningOriginTarget.copyFrom(r),a.onAfterCheckInputsObservable.add((()=>{a.panningSensibility=1e3/n.length()})),e.activeCamera=a,a}}function ee(e){const i=e.meshes.filter((e=>e.name.toLowerCase().endsWith("_t")||e.name.toLowerCase().includes("_t_")));return e.getWorldExtends((e=>e.isVisible&&e.isEnabled()&&(0===i.length||i.includes(e))))}function ie(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class te{constructor(e,i=!0,t=null){ie(this,"renderingPipeline",void 0),ie(this,"currentConfig",void 0),this.renderingPipeline=new(0,T.DefaultRenderingPipeline)("default",i,e,t?[t]:void 0,!1),this.renderingPipeline.prepare()}dispose(){this.renderingPipeline.dispose()}addCamera(e){this.renderingPipeline.addCamera(e)}removeCamera(e){this.renderingPipeline.removeCamera(e)}getConfig(){return this.currentConfig}apply(e){if(this.renderingPipeline.samples=e.antiAliasing?.msaaSamples||this.renderingPipeline.samples,this.renderingPipeline.fxaaEnabled=e.antiAliasing?.fxaaEnabled||this.renderingPipeline.fxaaEnabled,this.renderingPipeline.bloomEnabled=e.bloom?.enabled||this.renderingPipeline.bloomEnabled,this.renderingPipeline.bloomKernel=e.bloom?.kernel||this.renderingPipeline.bloomKernel,this.renderingPipeline.bloomScale=e.bloom?.scale||this.renderingPipeline.bloomScale,this.renderingPipeline.bloomThreshold=e.bloom?.threshold||this.renderingPipeline.bloomThreshold,this.renderingPipeline.bloomWeight=e.bloom?.weight||this.renderingPipeline.bloomWeight,this.renderingPipeline.chromaticAberrationEnabled=e.chromaticAberration?.enabled||this.renderingPipeline.chromaticAberrationEnabled,this.renderingPipeline.chromaticAberration.aberrationAmount=e.chromaticAberration?.aberrationAmount||this.renderingPipeline.chromaticAberration.aberrationAmount,this.renderingPipeline.chromaticAberration.radialIntensity=e.chromaticAberration?.radialIntensity||this.renderingPipeline.chromaticAberration.radialIntensity,this.renderingPipeline.chromaticAberration.direction=e.chromaticAberration?.direction?new(0,d.Vector2)(e.chromaticAberration.direction.x,e.chromaticAberration.direction.y):this.renderingPipeline.chromaticAberration.direction,this.renderingPipeline.imageProcessing.colorCurvesEnabled=e.colorCurves?.enabled||this.renderingPipeline.imageProcessing.colorCurvesEnabled,this.renderingPipeline.imageProcessing.colorCurves=e.colorCurves?this.updateColorCurve(e.colorCurves,this.renderingPipeline.imageProcessing.colorCurves):this.renderingPipeline.imageProcessing.colorCurves,this.renderingPipeline.depthOfFieldEnabled=e.depthOfField?.enabled||this.renderingPipeline.depthOfFieldEnabled,e.depthOfField.blurLevel)switch(e.depthOfField.blurLevel){case"Low":this.renderingPipeline.depthOfFieldBlurLevel=O.DepthOfFieldEffectBlurLevel.Low;break;case"Medium":this.renderingPipeline.depthOfFieldBlurLevel=O.DepthOfFieldEffectBlurLevel.Medium;break;case"High":this.renderingPipeline.depthOfFieldBlurLevel=O.DepthOfFieldEffectBlurLevel.High}if(this.renderingPipeline.depthOfField.focalLength=e.depthOfField?.focalLength||this.renderingPipeline.depthOfField.focalLength,this.renderingPipeline.depthOfField.fStop=e.depthOfField?.fStop||this.renderingPipeline.depthOfField.fStop,this.renderingPipeline.depthOfField.focusDistance=e.depthOfField?.focusDistance||this.renderingPipeline.depthOfField.focusDistance,this.renderingPipeline.depthOfField.lensSize=e.depthOfField?.lensSize||this.renderingPipeline.depthOfField.lensSize,this.renderingPipeline.grainEnabled=e.grain?.enabled||this.renderingPipeline.grainEnabled,this.renderingPipeline.grain.animated=e.grain?.animated||this.renderingPipeline.grain.animated,this.renderingPipeline.grain.intensity=e.grain?.intensity||this.renderingPipeline.grain.intensity,this.renderingPipeline.imageProcessing.contrast=e.misc?.contrast||this.renderingPipeline.imageProcessing.contrast,this.renderingPipeline.imageProcessing.exposure=e.misc?.exposure||this.renderingPipeline.imageProcessing.exposure,this.renderingPipeline.imageProcessing.toneMappingEnabled=e.misc?.toneMappingEnabled||this.renderingPipeline.imageProcessing.toneMappingEnabled,e.misc.toneMappingType)switch(e.misc.toneMappingType){case"Standard":this.renderingPipeline.imageProcessing.toneMappingType=A.ImageProcessingConfiguration.TONEMAPPING_STANDARD;break;case"ACES":this.renderingPipeline.imageProcessing.toneMappingType=A.ImageProcessingConfiguration.TONEMAPPING_ACES}switch(this.renderingPipeline.sharpenEnabled=e.sharpen?.enabled||this.renderingPipeline.sharpenEnabled,this.renderingPipeline.sharpen.colorAmount=e.sharpen?.colorAmount||this.renderingPipeline.sharpen.colorAmount,this.renderingPipeline.sharpen.edgeAmount=e.sharpen?.edgeAmount||this.renderingPipeline.sharpen.edgeAmount,this.renderingPipeline.imageProcessing.vignetteEnabled=e.vignette?.enabled||this.renderingPipeline.imageProcessing.vignetteEnabled,e.vignette?.center&&(this.renderingPipeline.imageProcessing.vignetteCenterX=e.vignette.center.x,this.renderingPipeline.imageProcessing.vignetteCenterY=e.vignette.center.y),e.vignette?.blendMode){case"Multiply":this.renderingPipeline.imageProcessing.vignetteBlendMode=A.ImageProcessingConfiguration.VIGNETTEMODE_MULTIPLY;break;case"Opaque":this.renderingPipeline.imageProcessing.vignetteBlendMode=A.ImageProcessingConfiguration.VIGNETTEMODE_OPAQUE}e.vignette.colorRgba?this.renderingPipeline.imageProcessing.vignetteColor=new(0,h.Color4)(e.vignette.colorRgba.r,e.vignette.colorRgba.g,e.vignette.colorRgba.b,e.vignette.colorRgba.a):e.vignette.colorHex&&(this.renderingPipeline.imageProcessing.vignetteColor=h.Color4.FromHexString(e.vignette.colorHex)),this.renderingPipeline.imageProcessing.vignetteStretch=e.vignette?.stretch||this.renderingPipeline.imageProcessing.vignetteStretch,this.renderingPipeline.imageProcessing.vignetteWeight=e.vignette?.weight||this.renderingPipeline.imageProcessing.vignetteWeight,this.renderingPipeline.prepare(),this.currentConfig={...this.currentConfig,...e}}updateColorCurve(e,i){const t=i??new(0,C.ColorCurves);return t.globalDensity=e.globalDensity??t.globalDensity,t.globalExposure=e.globalExposure??t.globalExposure,t.globalHue=e.globalHue??t.globalHue,t.globalSaturation=e.globalSaturation??t.globalSaturation,t.highlightsDensity=e.highlightsDensity??t.highlightsDensity,t.highlightsExposure=e.highlightsExposure??t.highlightsExposure,t.highlightsHue=e.highlightsHue??t.highlightsHue,t.highlightsSaturation=e.highlightsSaturation??t.highlightsSaturation,t.midtonesDensity=e.midtonesDensity??t.midtonesDensity,t.midtonesExposure=e.midtonesExposure??t.midtonesExposure,t.midtonesHue=e.midtonesHue??t.midtonesHue,t.midtonesSaturation=e.midtonesSaturation??t.midtonesSaturation,t.shadowsDensity=e.shadowsDensity??t.shadowsDensity,t.shadowsExposure=e.shadowsExposure??t.shadowsExposure,t.shadowsHue=e.shadowsHue??t.shadowsHue,t.shadowsSaturation=e.shadowsSaturation??t.shadowsSaturation,t}}const ne={albedoTexture:"albedoMap",bumpTexture:"normalMap",ambientTexture:"ambientMap",emissiveTexture:"emissionMap",opacityTexture:"alphaMap",metallicTexture:"metallicMap",refractionTexture:"refractionMap"};function re(e,i,t,n){["albedoTexture","bumpTexture","ambientTexture","emissiveTexture","opacityTexture","metallicTexture","refractionTexture"].forEach((r=>{!function(e,i,t,n,r){const a=ne[e];if(!a)throw new Error("Unexpected texture name encountered.");const s=i[a]?.fileLink;s?n.addTextureTask(e,s,!1,!1):r&&t[e]&&(t[e]&&t[e].dispose(),t[e]=null,function(e,i){"opacityTexture"===e&&(i.useAlphaFromAlbedoTexture=!0);"metallicTexture"===e&&(i.useRoughnessFromMetallicTextureAlpha=!1,i.useRoughnessFromMetallicTextureGreen=!1,i.useMetallnessFromMetallicTextureBlue=!1);"refractionTexture"===e&&(i.subSurface.isRefractionEnabled=!1,i.subSurface.refractionIntensity=1)}(e,t))}(r,e,i,t,n)})),function(e,i){if(!e.clearCoat)return;e.clearCoat===B.RemoveWhenSelected?(i.clearCoat.isEnabled=!1,i.clearCoat.indexOfRefraction=1.5):e.clearCoat===B.ApplyWhenSelected&&(i.clearCoat.isEnabled=!0,i.clearCoat.indexOfRefraction=e.clearCoatIOR||i.clearCoat.indexOfRefraction)}(e,i)}function ae(e,i,t,n){"opacityTexture"===e&&(i.useAlphaFromAlbedoTexture=!1),"metallicTexture"===e&&(i.useRoughnessFromMetallicTextureAlpha=!1,i.useRoughnessFromMetallicTextureGreen=!0,i.useMetallnessFromMetallicTextureBlue=!0),"refractionTexture"===e&&(i.subSurface.isRefractionEnabled=!0,i.subSurface.refractionIntensity=t.refractionIntensity||1),i[e]=n}function se(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class oe{constructor(){se(this,"materialVariantMap",new Map),se(this,"keysThatRemovedBaseModel",[]),se(this,"loadedContainerForKey",new Map)}async applyMaterial(e,i,t,n,r){return new Promise((a=>{const s=e.materials.filter((e=>e.name===i)),o=this.materialVariantMap.get(i);if(this.materialVariantMap.set(i,{...o,...t}),0===s.length)return void a(void 0);const l=new(0,L.AssetsManager)(e);l.useDefaultLoadingScreen=!1,s.forEach((e=>re(t,e,l,r))),l.onProgress=(e,i,t)=>{n&&n(e/i*100,100,t.name)},l.onFinish=e=>{e.forEach((e=>{const i=e;n&&n(100,100,e.name),s.forEach((n=>ae(e.name,n,t,i.texture)))})),a(void 0)},l.loadAsync()}))}async applyModel(e,i,t,n,r){if(n&&t&&!this.keysThatRemovedBaseModel.includes(i)&&this.keysThatRemovedBaseModel.push(i),!n){const t=this.keysThatRemovedBaseModel.includes(i);return this.loadedContainerForKey.get(i)?.removeAllFromScene(),e&&t&&await he(e.metadata.baseModel,e),Promise.resolve()}const a=await k(n,e,r);if(this.loadedContainerForKey.has(i)&&this.loadedContainerForKey.get(i)?.removeAllFromScene(),t){(await k(e.metadata.baseModel,e)).removeAllFromScene()}a.addAllToScene(),this.loadedContainerForKey.set(i,a);const s=[];this.materialVariantMap.forEach((async(i,t)=>{s.push(this.applyMaterial(e,t,i))})),await Promise.all(s)}}function le(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}b.GLTF2.GLTFLoader.RegisterExtension("glbPostProcessor",(function(e){return new K(e)})),s.SceneLoader.OnPluginActivatedObservable.add((e=>{if("gltf"===e.name){e.transparencyAsCoverage=!0}}));class ce{constructor(e){le(this,"engine",void 0),le(this,"scene",void 0),le(this,"configuration",void 0),le(this,"loadProgress",new Map([["initialScene",0]])),le(this,"materialReadyToLoadCallbacks",new Map),le(this,"modelReadyToLoadCallbacks",new Map),le(this,"queuedModelAnimation",void 0),le(this,"queuedCameraAnimation",void 0),le(this,"focusLostNotified",!1),le(this,"loadObservable",new(0,g.Observable)),le(this,"focusLostObservable",new(0,g.Observable)),le(this,"dynamicTextures",new Map),le(this,"highlightLayer",void 0),le(this,"variantManager",new oe),le(this,"renderingPipeline",void 0);const i=e?.noRender?void 0:document.createElement("canvas");this.configuration=new V(e);u.DracoCompression.Configuration={decoder:{wasmUrl:"https://www.gstatic.com/draco/versioned/decoders/1.5.6/draco_wasm_wrapper_gltf.js",wasmBinaryUrl:"https://www.gstatic.com/draco/versioned/decoders/1.5.6/draco_decoder_gltf.wasm",fallbackUrl:"https://www.gstatic.com/draco/versioned/decoders/1.5.6/draco_decoder_gltf.js"}},i&&(i.getContext("webgl2")||i.getContext("webgl"));const r=console.log;console.log=()=>{};const a=i?new(0,t.Engine)(i,!0,{premultipliedAlpha:!1,preserveDrawingBuffer:!!e?.backgroundImage,audioEngine:!1,stencil:this.configuration.highlights.enabled,forceSRGBBufferSupportState:!0}):new(0,n.NullEngine);console.log=r,a.hideLoadingUI(),window.addEventListener("resize",this.fireResizeEvent.bind(this)),this.engine=a,this.scene=new(0,p.Scene)(a),this.renderingPipeline=new te(this.scene,!0),this.scene.imageProcessingConfiguration.exposure=this.configuration.lighting.exposure,this.scene.imageProcessingConfiguration.contrast=this.configuration.lighting.contrast}registerFocusLostListener(e){this.focusLostObservable.add(e)}unregisterFocusLostListener(e){this.focusLostObservable.removeCallback(e)}registerLoadProgressListener(e){this.loadObservable.add(e),e(this.getLoadListenerEvent())}unregisterLoadProgressListener(e){this.loadObservable.removeCallback(e)}registerView(e){const i=e.height,t=e.width;this.engine.registerView(e),e.setAttribute("height",i.toString()),e.setAttribute("width",t.toString()),this.orbitEnabled()||this.setCameraState(F.Pan),this.reattachControls(e)}getNumViewports(){return this.engine.views?.length||0}unregisterView(e){this.engine.unRegisterView(e)}shutdown(){this.renderingPipeline.dispose(),this.engine&&this.engine.dispose(),window.removeEventListener("resize",this.fireResizeEvent)}getSceneInitializationProgress(){return this.loadProgress.get("initialScene")}async initialize(t,n){if(this.scene.clearColor=this.configuration.scene.clearColor,this.scene.metadata={baseModel:t},this.scene.environmentTexture=l.CubeTexture.CreateFromPrefilteredData(this.configuration.scene.environmentFile,this.scene),t){const e=100;await he(t,this.scene,(i=>{this.loadProgress.set("initialScene",i.loaded*e/i.total),this.notifyLoadHandlers()}))}this.configuration.highlights.enabled&&this.scene.meshes.forEach((t=>{"targetcube_t"!==t.name&&"backgroundShell"!==t.name&&(t.isPickable=!0,t.actionManager||(t.actionManager=new(0,e.ActionManager)(this.scene)),t.actionManager.registerAction(new(0,i.ExecuteCodeAction)(e.ActionManager.OnPointerOutTrigger,(()=>{this.setHighlights([])}))),t.actionManager.registerAction(new(0,i.ExecuteCodeAction)(e.ActionManager.OnPointerOverTrigger,(e=>{if(e.meshUnderPointer){const i=e.meshUnderPointer.material;i&&this.setHighlights([i])}}))))}));const a=J.create(this.scene,this.configuration);this.renderingPipeline.addCamera(a),this.configuration.options.renderingPipelineConfig&&this.renderingPipeline.apply(this.configuration.options.renderingPipelineConfig);const s=n?.getAll()||new Map;G(this.scene,s,this.dynamicTextures);if(this.scene.materials.some((e=>"emissiveTexture"in e&&null!==e.emissiveTexture))){new(0,r.GlowLayer)("GlowLayer",this.scene).intensity=.5}Y(this.scene),this.engine.views?.length>=1&&this.reattachControls(this.engine.views[this.engine.views.length-1].target),await this.processQueuedLoadEvents(),this.engine.runRenderLoop((()=>{this.engine.views&&(s.forEach(((e,i)=>{const t=this.dynamicTextures.get(i);t&&e.getStaticContextDirty()&&t.isReady()&&(t.update(!1),e.setStaticContextDirty(!1))})),this.configuration.scene.transparentBackground&&this.engine.views.forEach((e=>{const i=this.engine.getRenderingCanvas();e.target.getContext("2d").clearRect(0,0,i.width,i.height)})),this.scene.render(),a.target.equalsWithEpsilon(a.lastFocus,.1)||this.focusLostNotified||(this.focusLostObservable.notifyObservers(void 0),this.focusLostNotified=!0))}))}executeModelAnimation(e){100===this.getSceneInitializationProgress()?Q(this.scene,e.loop,e.to,e.from):this.queuedModelAnimation=e}executeCameraAnimation(e){100===this.getSceneInitializationProgress()&&this.scene.activeCamera?Z(this.scene,this.scene.activeCamera,e):this.queuedCameraAnimation=e}getCameraPose(){if(this.scene){const e=this.scene.activeCamera;if(e)return{lonDeg:Math.round(180*e.alpha/Math.PI),latDeg:Math.round(180*e.beta/Math.PI),radius:Math.round(1e4*(e.radius+Number.EPSILON))/1e4,target:{x:e.target.x,y:e.target.y,z:e.target.z}}}}setCameraPose(e){if(this.scene){const i=this.scene.activeCamera;i&&(i.target=new(0,d.Vector3)(e.target.x,e.target.y,e.target.z),i.radius=e.radius,i.alpha=e.latDeg,i.beta=e.lonDeg)}}async applyMaterialVariant(e,i,t,n){if(100===this.getSceneInitializationProgress())await this.variantManager.applyMaterial(this.scene,e,t,((e,i,t)=>{this.loadProgress.set(`key_${t}`,e/i*100),this.notifyLoadHandlers()}),n);else if(this.materialReadyToLoadCallbacks.has(e)){this.materialReadyToLoadCallbacks.get(e)?.set(i,t)}else{this.materialReadyToLoadCallbacks.set(e,new Map);this.materialReadyToLoadCallbacks.get(e)?.set(i,t)}}async applyModelVariant(e,i,t){100===this.getSceneInitializationProgress()?(await this.variantManager.applyModel(this.scene,e,t||!1,i.model,(i=>{this.loadProgress.set(e,100*i.loaded/i.total),this.notifyLoadHandlers()})),this.scene.materials.forEach((e=>{if(e&&0===e.getBindedMeshes().length){const i=e instanceof o.PBRMaterial&&!(e.albedoTexture instanceof c.DynamicTexture);e.dispose(!1,i)}})),G(this.scene,i.contextService.getAll(),this.dynamicTextures),Y(this.scene)):this.modelReadyToLoadCallbacks.set(e,(async()=>{await this.applyModelVariant(e,i,t)}))}getQueuedMaterialVariants(){return this.materialReadyToLoadCallbacks.size}getQueuedModelVariants(){return this.modelReadyToLoadCallbacks.size}setCameraState(e){if(!this.engine?.views||!this.engine?.views[0])throw new Error("No views attached, camera state requires a view to attach controls onto.");e===F.Orbit?this.reattachControls(this.engine.views[0].target,2):this.reattachControls(this.engine.views[0].target,0)}animateToLastCameraFocus(){return new Promise((e=>{const i=this.scene.activeCamera,t=this.configuration;i.rerunFramingBehavior((()=>{this.focusLostNotified=!1,t.camera.limits.min.radius&&(i.lowerRadiusLimit=t.camera.limits.min.radius),t.camera.limits.max.radius&&(i.upperRadiusLimit=t.camera.limits.max.radius),e()}))}))}setAutoRotation(e){const i=this.scene.activeCamera;this.configuration.camera.autoRotation.enabled&&i&&(e?i.enableAutoRotationBehavior(this.configuration.camera.autoRotation.idleTimeMs):i.disableAutoRotationBehavior())}getCurrentConfiguration(){return this.configuration.options}async renderSceneScreenshot(e,i){const t=this.scene.activeCamera;if(!t)throw new Error("Missing product camera, cannot render screenshot!");var n;(n=t).getScene().stopAnimation(n),n.animations=[];const r=t.alpha,a=t.beta,s=t.radius,o=i.latDeg*Math.PI/180,l=i.lonDeg*Math.PI/180;t.alpha=l,t.beta=o,t.radius=i.radius||t.radius;const c=await m.Tools.CreateScreenshotUsingRenderTargetAsync(this.engine,t,e,"image/png",2,!0);return t.alpha=r,t.beta=a,t.radius=s,c}orbitEnabled(){const e=this.configuration;if(!e)return!0;const i=e.camera.limits.min.alpha,t=e.camera.limits.max.alpha,n=e.camera.limits.min.beta,r=e.camera.limits.max.beta;if(void 0===i||void 0===t||void 0===n||void 0===r)return!0;const a=[n,r],s=[i,t].every((e=>e===i)),o=a.every((e=>e===n));return!s&&!o}fireResizeEvent(){this.getNumViewports()>0&&this.engine.resize()}onMaterialSelected(t){this.scene.meshes.forEach((n=>{"targetcube_t"!==n.name&&"backgroundShell"!==n.name&&(n.actionManager||(n.actionManager=new(0,e.ActionManager)(this.scene)),n.actionManager.registerAction(new(0,i.ExecuteCodeAction)(e.ActionManager.OnPickDownTrigger,(e=>{if(e.meshUnderPointer){const i=e.meshUnderPointer.material;i&&t({id:i.id,name:i.name})}}))))}))}listMaterials(){const e=this.scene?.materials;return e?e.map((e=>({id:e.id,name:e.name}))):[]}setHighlights(e,i){0===e.length&&(this.highlightLayer?.dispose(),this.highlightLayer=void 0),this.highlightLayer||(this.highlightLayer=new(0,a.HighlightLayer)("highlights",this.scene,{isStroke:!0,blurVerticalSize:.85,blurHorizontalSize:.85}),this.highlightLayer.innerGlow=!0,this.highlightLayer.outerGlow=!1),this.highlightLayer.removeAllMeshes();const t=i?new(0,h.Color3)(i[0],i[1],i[2]).toLinearSpace():void 0;e.forEach((e=>{const i=this.scene.materials.find((i=>i.name===e.name&&i.id===e.id));i&&i.getBindedMeshes().forEach((e=>this.highlightLayer?.addMesh(e,t||h.Color3.FromHexString("#fcba03"))))}))}setRenderingPipelineConfig(e){this.renderingPipeline&&this.renderingPipeline.apply(e)}reattachControls(e,i=2){this.scene.detachControl(),this.engine.inputElement=e;const t=this.scene.activeCamera;if(t){t.attachControl(!0,!1,i);t.inputs.attached.pointers.multiTouchPanning=!1}this.scene.attachControl(!0,!0,!0)}getLoadListenerEvent(){const e=Array.from(this.loadProgress.values()).filter((e=>e<100)),i=e.reduce(((e,i)=>e+i),0)/e.length||0;return{loadValue:0===e.length?100:i,sceneInitialized:100===this.getSceneInitializationProgress()}}notifyLoadHandlers(){this.loadObservable.notifyObservers(this.getLoadListenerEvent())}async processQueuedLoadEvents(){await Promise.all(Array.from(this.modelReadyToLoadCallbacks.values()).map((e=>e(this.scene)))),this.modelReadyToLoadCallbacks.clear(),this.materialReadyToLoadCallbacks.forEach(((e,i)=>{e.forEach(((e,t)=>{this.applyMaterialVariant(i,t,e)}))})),this.materialReadyToLoadCallbacks.clear(),this.queuedModelAnimation&&(this.executeModelAnimation(this.queuedModelAnimation),this.queuedModelAnimation=void 0),this.queuedCameraAnimation&&(this.executeCameraAnimation(this.queuedCameraAnimation),this.queuedCameraAnimation=void 0)}}async function he(e,i,t){(await k(e,i,t)).addAllToScene()}E(module.exports,S),E(module.exports,q),E(module.exports,_);
2
2
  //# sourceMappingURL=main.js.map
package/dist/module.js CHANGED
@@ -1,2 +1,2 @@
1
- import{ActionManager as e}from"@babylonjs/core/Actions/actionManager";import{ExecuteCodeAction as i}from"@babylonjs/core/Actions/directActions";import{Engine as t}from"@babylonjs/core/Engines/engine";import{NullEngine as n}from"@babylonjs/core/Engines/nullEngine";import{GlowLayer as a}from"@babylonjs/core/Layers/glowLayer";import{HighlightLayer as r}from"@babylonjs/core/Layers/highlightLayer";import{SceneLoader as s}from"@babylonjs/core/Loading/sceneLoader";import{PBRMaterial as o}from"@babylonjs/core/Materials/PBR/pbrMaterial";import{CubeTexture as l}from"@babylonjs/core/Materials/Textures/cubeTexture";import{DynamicTexture as c}from"@babylonjs/core/Materials/Textures/dynamicTexture";import{Color3 as h,Color4 as d}from"@babylonjs/core/Maths/math.color";import{Vector3 as g,Vector2 as u}from"@babylonjs/core/Maths/math.vector";import{DracoCompression as m}from"@babylonjs/core/Meshes/Compression/dracoCompression";import{Observable as p}from"@babylonjs/core/Misc/observable";import{Tools as b}from"@babylonjs/core/Misc/tools";import{Scene as f}from"@babylonjs/core/scene";import{GLTF2 as P}from"@babylonjs/loaders/glTF";import"@babylonjs/core/Engines/Extensions/engine.views";import"@babylonjs/core/Meshes/instancedMesh";import"@babylonjs/core/Materials/Textures/Loaders/ddsTextureLoader";import"@babylonjs/core/Materials/Textures/Loaders/envTextureLoader";import"@babylonjs/core/Materials/Textures/Loaders/ktxTextureLoader";import"@babylonjs/core/Animations/animatable";import"@babylonjs/core/Misc/screenshotTools";import"@babylonjs/core/Rendering/boundingBoxRenderer";import"@babylonjs/loaders/glTF/2.0/Extensions";import{Texture as v}from"@babylonjs/core/Materials/Textures/texture";import{MirrorTexture as y}from"@babylonjs/core/Materials/Textures/mirrorTexture";import{Color3 as w,Vector3 as x,Plane as M}from"@babylonjs/core/Maths/math";import{ReflectionProbe as C}from"@babylonjs/core/Probes/reflectionProbe";import{Animation as T}from"@babylonjs/core/Animations/animation";import{QuadraticEase as A,EasingFunction as L}from"@babylonjs/core/Animations/easing";import{ArcRotateCamera as O}from"@babylonjs/core/Cameras/arcRotateCamera";import{ColorCurves as E}from"@babylonjs/core/Materials/colorCurves";import{ImageProcessingConfiguration as R}from"@babylonjs/core/Materials/imageProcessingConfiguration";import{DefaultRenderingPipeline as S}from"@babylonjs/core/PostProcesses/RenderPipeline";import{DepthOfFieldEffectBlurLevel as F}from"@babylonjs/core/PostProcesses/depthOfFieldEffect";import"@babylonjs/core/Rendering/depthRendererSceneComponent";import{AssetsManager as I}from"@babylonjs/core/Misc/assetsManager";function B(e,i,t,n){Object.defineProperty(e,i,{get:t,set:n,enumerable:!0,configurable:!0})}var D={};let j;var k;let N;var V;B(D,"ProductCameraRig",(()=>j)),B(D,"MaterialEffectMode",(()=>N)),(k=j||(j={}))[k.Orbit=0]="Orbit",k[k.Pan=1]="Pan",(V=N||(N={})).None="None",V.RemoveWhenSelected="RemoveWhenSelected",V.ApplyWhenSelected="ApplyWhenSelected";var _={};B(_,"SpiffCommerce3DPreviewService",(()=>ue)),B(_,"createBaseModel",(()=>me));const z=new Map;async function H(e,i,t){return new Promise(((n,a)=>{const r=z.get(e);if(r&&r.scene.uid===i.uid)return n(r);s.LoadAssetContainerAsync(e,void 0,i,t).then((i=>{z.set(e,i),n(i)})).catch(a)}))}function U(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class G{constructor(e){U(this,"customOptions",void 0),U(this,"getSceneClearColor",(()=>{const e=this.customOptions?.transparentBackground||this.customOptions?.backgroundImage?0:1;if(this.customOptions&&this.customOptions?.transparentBackground||this.customOptions?.backgroundImage)return new d(0,0,0,e).toLinearSpace();if(this.customOptions&&this.customOptions.backgroundColor){const i=h.FromHexString(this.customOptions.backgroundColor);return new d(i.r,i.g,i.b,e).toLinearSpace()}return new d(.98,.98,.98,e).toLinearSpace()})),U(this,"highlightColorFromConfig",(()=>this.customOptions&&this.customOptions.highlightColor?this.hexToColor4(this.customOptions.highlightColor):new d(.98,.98,.98,1).toLinearSpace())),U(this,"hexToColor4",((e,i=1)=>{const t=h.FromHexString(e);return new d(t.r,t.g,t.b,i).toLinearSpace()})),this.customOptions=e}get options(){return this.customOptions}get scene(){return{clearColor:this.getSceneClearColor(),transparentBackground:this.customOptions?.transparentBackground||this.customOptions?.backgroundImage,environmentFile:this.customOptions?.environmentFile??"assets/model-viewer/default.env"}}get camera(){return{autoOrientation:this.customOptions?.disableAutomaticOrientation??!0,autoRotation:{enabled:this.customOptions?.autoRotation??!1,idleTimeMs:this.customOptions?.idleTimeBeforeRotation??5e3},limits:{min:{alpha:this.customOptions?.lowerAlphaLimitDeg?this.customOptions?.lowerAlphaLimitDeg*Math.PI/180:void 0,beta:this.customOptions?.lowerBetaLimitDeg?this.customOptions?.lowerBetaLimitDeg*Math.PI/180:void 0,radius:this.customOptions?.minZoomOverride},max:{alpha:this.customOptions?.upperAlphaLimitDeg?this.customOptions?.upperAlphaLimitDeg*Math.PI/180:void 0,beta:this.customOptions?.upperBetaLimitDeg?this.customOptions?.upperBetaLimitDeg*Math.PI/180:void 0,radius:this.customOptions?.maxZoomOverride}}}}get highlights(){return{enabled:this.customOptions?.highlightOnMaterialHover??!1,color:this.highlightColorFromConfig()}}get lighting(){return{exposure:this.customOptions?.lighting?.exposure??.9,contrast:this.customOptions?.lighting?.contrast??1.6}}}var W={};B(W,"RenderingConfiguration",(()=>q)),B(W,"REFLECTION_PROBE_RESOLUTION",(()=>K));class q{static getDynamicTextureResolution(){return this.getIsMobile()||!q.offscreenRenderingSupported()?{width:1024,height:1024}:{width:2048,height:2048}}static shouldMipMap(){return!0}static offscreenRenderingSupported(){return!navigator.userAgent.includes("SamsungBrowser")&&(!!window.Worker&&!!window.OffscreenCanvas)}static getMirrorTextureResolution(){return this.getIsMobile()?512:1024}static getIsMobile(){return window.innerWidth<=480}}const K=128;function Y(e,i,n){i.forEach((i=>{const a=i.getID(),r=i.getName(),s=q.getDynamicTextureResolution();e.materials.filter((e=>e.name===r)).forEach((o=>{const l=n.get(a);if(l)Q(o,l),l.update(false);else{const l=function(e,i,n,a){const r=new c(e,{width:n,height:a},i,q.shouldMipMap(),v.TRILINEAR_SAMPLINGMODE,t.TEXTUREFORMAT_RGBA),s=r.getContext();s&&(s.fillStyle="#f5f5f5",s.fillRect(0,0,n,a),r.update());return r}(r,e,s.width,s.height);n.set(a,l),i.setStaticContext(l.getContext()),Q(o,l),l.onLoadObservable.addOnce((()=>{l.update(false)}))}}))}))}function Q(e,i){if(e instanceof o){const t=e,n=t.albedoTexture;n?(i.wrapU=n.wrapU,i.wrapV=n.wrapV):(i.wrapU=1,i.wrapV=1),t.albedoTexture=i}else{const t=e,n=t.diffuseTexture;n&&(i.wrapU=n.wrapU,i.wrapV=n.wrapV),t.diffuseTexture=i}}function Z(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class X{constructor(e){Z(this,"name",void 0),Z(this,"enabled",void 0),Z(this,"loader",void 0),this.name="glbPostProcessor",this.enabled=!0,this.loader=e}onReady(){this.applyReflections(this.loader.babylonScene)}loadNodeAsync(e,i,t){return this.loader.loadNodeAsync(e,i,(function(e){i.extras&&Object.keys(i.extras).forEach((t=>{const n=i.extras[t];e.metadata[t]=n})),t(e)}))}loadMaterialPropertiesAsync(e,i,t){return this.enableMaterialExtrasIfRequired(i,t),this.loader.loadMaterialPropertiesAsync(e,i,t)}dispose(){}enableMaterialExtrasIfRequired(e,i){if(e.extras&&i instanceof o){if(e.extras.sheen){const t=i;t.sheen.isEnabled=!0,t.sheen.intensity=e.extras.sheen}if(e.extras.translucency){const t=i;t.subSurface.isTranslucencyEnabled=!0,t.subSurface.translucencyIntensity=e.extras.translucency,e.extras.translucencyR&&e.extras.translucencyG&&e.extras.translucencyB&&(t.subSurface.tintColor=new w(e.extras.translucencyR,e.extras.translucencyG,e.extras.translucencyB))}if(e.extras.refractionIOR){i.subSurface.indexOfRefraction=e.extras.refractionIOR}if(e.extras.useDepthPrePass){const e=i;e.needDepthPrePass=!0,e.forceIrradianceInFragment=!0}if(e.extras.useParallax){const t=i;t.useParallax=!0,t.useParallaxOcclusion=!0,t.parallaxScaleBias=e.extras.useParallax}}}applyReflections(e){function i(e){const i=[];return e.transformNodes.forEach((e=>{e.metadata&&e.metadata.reflective&&i.push(...e.getChildMeshes())})),e.meshes.forEach((e=>{e.metadata&&e.metadata.reflective&&!i.includes(e)&&i.push(e)})),i}e.meshes.forEach((t=>{const n=t.metadata;n&&(n.mirrorTexture&&function(t,n=1){const a=t.material;if(!a)return;const r=new y("mirror",q.getMirrorTextureResolution(),e,!0);r.renderList=i(e);const s=t.getVerticesData("normal");if(!s)throw new Error("Mirror attribute specified on: "+t.name+"But no normals exist to generate a mirror from!");t.computeWorldMatrix(!0);const o=t.getWorldMatrix(),l=x.TransformNormal(new x(s[0],s[1],s[2]),o).normalize(),c=M.FromPositionAndNormal(t.position,l.scale(-1));r.mirrorPlane=c,r.level=n,a.reflectionTexture=r}(t,n.mirrorTexture),n.reflectionProbe&&function(t){const n=t.material,a=new C("probe-"+n.name,K,e);a.attachToMesh(t),a.renderList&&a.renderList.push(...i(e)),n.reflectionTexture=a.cubeTexture}(t))}))}}function $(e,i,t,n){const a=e.animationGroups,r=e=>e.targetedAnimations.map((e=>e.animation.framePerSecond)).reduce(((e,i)=>e+i),0)/e.targetedAnimations.length||0;void 0===n||void 0===t||n!==t?a.forEach((e=>{e.stop();const a=r(e);e.start(i,1,n*a,t*a)})):a.forEach((e=>{e.stop();const t=r(e),a=n*t;e.start(i,1,a,a)}))}function J(e){e.animationGroups.forEach((e=>{e.stop()}))}function ee(e,i,t){var n,a,r;e.stopAnimation(i),i.animations=[],Math.abs(i.alpha)>2*Math.PI&&(i.alpha=(n=i.alpha,a=0,r=2*Math.PI,n<a?r-(a-n)%(r-a):a+(n-a)%(r-a)));const s=[],o=t.target,l=o?1:0;if(t.target&&Object.keys(t.target).length>0&&s.push(te("cameraTargetLerp","target",(new g).copyFrom(i.target),new g(t.target.x,t.target.y,t.target.z),T.ANIMATIONTYPE_VECTOR3,0)),s.push(te("cameraAlphaLerp","alpha",i.alpha,ie(t.lonDeg),T.ANIMATIONTYPE_FLOAT,l)),s.push(te("cameraBetaLerp","beta",i.beta,ie(t.latDeg),T.ANIMATIONTYPE_FLOAT,l)),void 0!==t.radius){const e=Math.max(.01,t.radius);s.push(te("cameraRadiusLerp","radius",i.radius,e,T.ANIMATIONTYPE_FLOAT,l))}i.animations.push(...s);const c=i.useAutoRotationBehavior;i.disableAutoRotationBehavior(),e.beginAnimation(i,0,o?120:60,!1,1,(()=>{i.animations=[],c&&i.enableAutoRotationBehavior()}))}function ie(e){return e*Math.PI/180}function te(e,i,t,n,a,r=0,s=T.ANIMATIONLOOPMODE_CONSTANT){const o=new A;o.setEasingMode(L.EASINGMODE_EASEINOUT);const l=new T(e,i,60,a,s),c=[];return r>0&&c.push({frame:0,value:t}),c.push({frame:60*r,value:t}),c.push({frame:60*(r+1),value:n}),l.setKeys(c),l.setEasingFunction(o),l}class ne extends O{constructor(e,i,t,n,a,r,s,o){var l,c,h;super(e,i,t,n,a,r,o),l=this,c="lastFocus",h=new g(0,0,0),c in l?Object.defineProperty(l,c,{value:h,enumerable:!0,configurable:!0,writable:!0}):l[c]=h,this.minZ=.01,this.maxZ=1e3*this.radius,this.lowerRadiusLimit=.01*this.radius,this.enableFramingBehavior(),this.upperRadiusLimit=1.5*this.radius,this.wheelPrecision=100/this.radius,this.pinchPrecision=300/this.radius,this.wheelDeltaPercentage=.01,this.pinchDeltaPercentage=.005,this.useNaturalPinchZoom=!0,s.camera.autoOrientation&&(this.alpha+=Math.PI),s&&(s.camera.limits.min.beta&&(this.lowerBetaLimit=s.camera.limits.min.beta),s.camera.limits.max.beta&&(this.upperBetaLimit=s.camera.limits.max.beta),s.camera.limits.min.alpha&&(this.lowerAlphaLimit=s.camera.limits.min.alpha),s.camera.limits.max.alpha&&(this.upperAlphaLimit=s.camera.limits.max.alpha),s.camera.limits.min.radius&&(this.lowerRadiusLimit=s.camera.limits.min.radius),s.camera.limits.max.radius&&(this.upperRadiusLimit=s.camera.limits.max.radius),s.camera.autoRotation.enabled&&this.enableAutoRotationBehavior(s.camera.autoRotation.idleTimeMs))}getFramingBehavior(){return this.getBehaviorByName("Framing")}getAutoRotationBehavior(){const e=this.getBehaviorByName("AutoRotation");return e||void 0}enableFramingBehavior(){this.useFramingBehavior=!0;const e=this.getFramingBehavior();e.attach(this),e.framingTime=0,e.elevationReturnTime=-1,e.zoomStopsAnimation=!1,this.lowerRadiusLimit=null;const i=ae(this._scene);return e.zoomOnBoundingInfo(i.min,i.max),this.wheelPrecision=100/this.radius,null===this.lowerRadiusLimit&&(this.lowerRadiusLimit=.1),this.lastFocus.copyFrom(this.target),e}rerunFramingBehavior(e){const i=this.getFramingBehavior();i.framingTime=800;const t=ae(this._scene);i.zoomOnBoundingInfo(t.min,t.max,void 0,(()=>{e()})),i.framingTime=0}enableAutoRotationBehavior(e=5e3){this.useAutoRotationBehavior=!0;const i=this.getAutoRotationBehavior();i&&(i.idleRotationWaitTime=e)}disableAutoRotationBehavior(){this.useAutoRotationBehavior=!1}static create(e,i){e.activeCamera&&(e.activeCamera.dispose(),e.activeCamera=null);const t=ae(e),n=t.max.subtract(t.min),a=t.min.add(n.scale(.5)),r=new ne("ProductCamera",-Math.PI/2,Math.PI/2,1.5*n.length(),a,e,i);return r.panningInertia=0,r.panningOriginTarget.copyFrom(a),r.onAfterCheckInputsObservable.add((()=>{r.panningSensibility=1e3/n.length()})),e.activeCamera=r,r}}function ae(e){const i=e.meshes.filter((e=>e.name.toLowerCase().endsWith("_t")||e.name.toLowerCase().includes("_t_")));return e.getWorldExtends((e=>e.isVisible&&e.isEnabled()&&(0===i.length||i.includes(e))))}function re(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class se{constructor(e,i=!0,t=null){re(this,"renderingPipeline",void 0),re(this,"currentConfig",void 0),this.renderingPipeline=new S("default",i,e,t?[t]:void 0,!1),this.renderingPipeline.prepare()}dispose(){this.renderingPipeline.dispose()}addCamera(e){this.renderingPipeline.addCamera(e)}removeCamera(e){this.renderingPipeline.removeCamera(e)}getConfig(){return this.currentConfig}apply(e){if(this.renderingPipeline.samples=e.antiAliasing?.msaaSamples||this.renderingPipeline.samples,this.renderingPipeline.fxaaEnabled=e.antiAliasing?.fxaaEnabled||this.renderingPipeline.fxaaEnabled,this.renderingPipeline.bloomEnabled=e.bloom?.enabled||this.renderingPipeline.bloomEnabled,this.renderingPipeline.bloomKernel=e.bloom?.kernel||this.renderingPipeline.bloomKernel,this.renderingPipeline.bloomScale=e.bloom?.scale||this.renderingPipeline.bloomScale,this.renderingPipeline.bloomThreshold=e.bloom?.threshold||this.renderingPipeline.bloomThreshold,this.renderingPipeline.bloomWeight=e.bloom?.weight||this.renderingPipeline.bloomWeight,this.renderingPipeline.chromaticAberrationEnabled=e.chromaticAberration?.enabled||this.renderingPipeline.chromaticAberrationEnabled,this.renderingPipeline.chromaticAberration.aberrationAmount=e.chromaticAberration?.aberrationAmount||this.renderingPipeline.chromaticAberration.aberrationAmount,this.renderingPipeline.chromaticAberration.radialIntensity=e.chromaticAberration?.radialIntensity||this.renderingPipeline.chromaticAberration.radialIntensity,this.renderingPipeline.chromaticAberration.direction=e.chromaticAberration?.direction?new u(e.chromaticAberration.direction.x,e.chromaticAberration.direction.y):this.renderingPipeline.chromaticAberration.direction,this.renderingPipeline.imageProcessing.colorCurvesEnabled=e.colorCurves?.enabled||this.renderingPipeline.imageProcessing.colorCurvesEnabled,this.renderingPipeline.imageProcessing.colorCurves=e.colorCurves?this.updateColorCurve(e.colorCurves,this.renderingPipeline.imageProcessing.colorCurves):this.renderingPipeline.imageProcessing.colorCurves,this.renderingPipeline.depthOfFieldEnabled=e.depthOfField?.enabled||this.renderingPipeline.depthOfFieldEnabled,e.depthOfField.blurLevel)switch(e.depthOfField.blurLevel){case"Low":this.renderingPipeline.depthOfFieldBlurLevel=F.Low;break;case"Medium":this.renderingPipeline.depthOfFieldBlurLevel=F.Medium;break;case"High":this.renderingPipeline.depthOfFieldBlurLevel=F.High}if(this.renderingPipeline.depthOfField.focalLength=e.depthOfField?.focalLength||this.renderingPipeline.depthOfField.focalLength,this.renderingPipeline.depthOfField.fStop=e.depthOfField?.fStop||this.renderingPipeline.depthOfField.fStop,this.renderingPipeline.depthOfField.focusDistance=e.depthOfField?.focusDistance||this.renderingPipeline.depthOfField.focusDistance,this.renderingPipeline.depthOfField.lensSize=e.depthOfField?.lensSize||this.renderingPipeline.depthOfField.lensSize,this.renderingPipeline.grainEnabled=e.grain?.enabled||this.renderingPipeline.grainEnabled,this.renderingPipeline.grain.animated=e.grain?.animated||this.renderingPipeline.grain.animated,this.renderingPipeline.grain.intensity=e.grain?.intensity||this.renderingPipeline.grain.intensity,this.renderingPipeline.imageProcessing.contrast=e.misc?.contrast||this.renderingPipeline.imageProcessing.contrast,this.renderingPipeline.imageProcessing.exposure=e.misc?.exposure||this.renderingPipeline.imageProcessing.exposure,this.renderingPipeline.imageProcessing.toneMappingEnabled=e.misc?.toneMappingEnabled||this.renderingPipeline.imageProcessing.toneMappingEnabled,e.misc.toneMappingType)switch(e.misc.toneMappingType){case"Standard":this.renderingPipeline.imageProcessing.toneMappingType=R.TONEMAPPING_STANDARD;break;case"ACES":this.renderingPipeline.imageProcessing.toneMappingType=R.TONEMAPPING_ACES}switch(this.renderingPipeline.sharpenEnabled=e.sharpen?.enabled||this.renderingPipeline.sharpenEnabled,this.renderingPipeline.sharpen.colorAmount=e.sharpen?.colorAmount||this.renderingPipeline.sharpen.colorAmount,this.renderingPipeline.sharpen.edgeAmount=e.sharpen?.edgeAmount||this.renderingPipeline.sharpen.edgeAmount,this.renderingPipeline.imageProcessing.vignetteEnabled=e.vignette?.enabled||this.renderingPipeline.imageProcessing.vignetteEnabled,this.renderingPipeline.imageProcessing.vignetteCenterX=e.vignette?.centerX||this.renderingPipeline.imageProcessing.vignetteCenterX,this.renderingPipeline.imageProcessing.vignetteCenterY=e.vignette?.centerY||this.renderingPipeline.imageProcessing.vignetteCenterY,e.vignette?.blendMode){case"Multiply":this.renderingPipeline.imageProcessing.vignetteBlendMode=R.VIGNETTEMODE_MULTIPLY;break;case"Opaque":this.renderingPipeline.imageProcessing.vignetteBlendMode=R.VIGNETTEMODE_OPAQUE}e.vignette.colorRgba?this.renderingPipeline.imageProcessing.vignetteColor=new d(e.vignette.colorRgba.r,e.vignette.colorRgba.g,e.vignette.colorRgba.b,e.vignette.colorRgba.a):e.vignette.colorHex&&(this.renderingPipeline.imageProcessing.vignetteColor=d.FromHexString(e.vignette.colorHex)),this.renderingPipeline.imageProcessing.vignetteStretch=e.vignette?.stretch||this.renderingPipeline.imageProcessing.vignetteStretch,this.renderingPipeline.imageProcessing.vignetteWeight=e.vignette?.weight||this.renderingPipeline.imageProcessing.vignetteWeight,this.renderingPipeline.prepare(),this.currentConfig={...this.currentConfig,...e}}updateColorCurve(e,i){const t=i??new E;return t.globalDensity=e.globalDensity??t.globalDensity,t.globalExposure=e.globalExposure??t.globalExposure,t.globalHue=e.globalHue??t.globalHue,t.globalSaturation=e.globalSaturation??t.globalSaturation,t.highlightsDensity=e.highlightsDensity??t.highlightsDensity,t.highlightsExposure=e.highlightsExposure??t.highlightsExposure,t.highlightsHue=e.highlightsHue??t.highlightsHue,t.highlightsSaturation=e.highlightsSaturation??t.highlightsSaturation,t.midtonesDensity=e.midtonesDensity??t.midtonesDensity,t.midtonesExposure=e.midtonesExposure??t.midtonesExposure,t.midtonesHue=e.midtonesHue??t.midtonesHue,t.midtonesSaturation=e.midtonesSaturation??t.midtonesSaturation,t.shadowsDensity=e.shadowsDensity??t.shadowsDensity,t.shadowsExposure=e.shadowsExposure??t.shadowsExposure,t.shadowsHue=e.shadowsHue??t.shadowsHue,t.shadowsSaturation=e.shadowsSaturation??t.shadowsSaturation,t}}const oe={albedoTexture:"albedoMap",bumpTexture:"normalMap",ambientTexture:"ambientMap",emissiveTexture:"emissionMap",opacityTexture:"alphaMap",metallicTexture:"metallicMap",refractionTexture:"refractionMap"};function le(e,i,t,n){["albedoTexture","bumpTexture","ambientTexture","emissiveTexture","opacityTexture","metallicTexture","refractionTexture"].forEach((a=>{!function(e,i,t,n,a){const r=oe[e];if(!r)throw new Error("Unexpected texture name encountered.");const s=i[r]?.fileLink;s?n.addTextureTask(e,s,!1,!1):a&&t[e]&&(t[e]&&t[e].dispose(),t[e]=null,function(e,i){"opacityTexture"===e&&(i.useAlphaFromAlbedoTexture=!0);"metallicTexture"===e&&(i.useRoughnessFromMetallicTextureAlpha=!1,i.useRoughnessFromMetallicTextureGreen=!1,i.useMetallnessFromMetallicTextureBlue=!1);"refractionTexture"===e&&(i.subSurface.isRefractionEnabled=!1,i.subSurface.refractionIntensity=1)}(e,t))}(a,e,i,t,n)})),function(e,i){if(!e.clearCoat)return;e.clearCoat===N.RemoveWhenSelected?(i.clearCoat.isEnabled=!1,i.clearCoat.indexOfRefraction=1.5):e.clearCoat===N.ApplyWhenSelected&&(i.clearCoat.isEnabled=!0,i.clearCoat.indexOfRefraction=e.clearCoatIOR||i.clearCoat.indexOfRefraction)}(e,i)}function ce(e,i,t,n){"opacityTexture"===e&&(i.useAlphaFromAlbedoTexture=!1),"metallicTexture"===e&&(i.useRoughnessFromMetallicTextureAlpha=!1,i.useRoughnessFromMetallicTextureGreen=!0,i.useMetallnessFromMetallicTextureBlue=!0),"refractionTexture"===e&&(i.subSurface.isRefractionEnabled=!0,i.subSurface.refractionIntensity=t.refractionIntensity||1),i[e]=n}function he(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class de{constructor(){he(this,"materialVariantMap",new Map),he(this,"keysThatRemovedBaseModel",[]),he(this,"loadedContainerForKey",new Map)}async applyMaterial(e,i,t,n,a){return new Promise((r=>{const s=e.materials.filter((e=>e.name===i)),o=this.materialVariantMap.get(i);if(this.materialVariantMap.set(i,{...o,...t}),0===s.length)return void r(void 0);const l=new I(e);l.useDefaultLoadingScreen=!1,s.forEach((e=>le(t,e,l,a))),l.onProgress=(e,i,t)=>{n&&n(e/i*100,100,t.name)},l.onFinish=e=>{e.forEach((e=>{const i=e;n&&n(100,100,e.name),s.forEach((n=>ce(e.name,n,t,i.texture)))})),r(void 0)},l.loadAsync()}))}async applyModel(e,i,t,n,a){if(n&&t&&!this.keysThatRemovedBaseModel.includes(i)&&this.keysThatRemovedBaseModel.push(i),!n){const t=this.keysThatRemovedBaseModel.includes(i);return this.loadedContainerForKey.get(i)?.removeAllFromScene(),e&&t&&await me(e.metadata.baseModel,e),Promise.resolve()}const r=await H(n,e,a);if(this.loadedContainerForKey.has(i)&&this.loadedContainerForKey.get(i)?.removeAllFromScene(),t){(await H(e.metadata.baseModel,e)).removeAllFromScene()}r.addAllToScene(),this.loadedContainerForKey.set(i,r);const s=[];this.materialVariantMap.forEach((async(i,t)=>{s.push(this.applyMaterial(e,t,i))})),await Promise.all(s)}}function ge(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}P.GLTFLoader.RegisterExtension("glbPostProcessor",(function(e){return new X(e)})),s.OnPluginActivatedObservable.add((e=>{if("gltf"===e.name){e.transparencyAsCoverage=!0}}));class ue{constructor(e){ge(this,"engine",void 0),ge(this,"scene",void 0),ge(this,"configuration",void 0),ge(this,"loadProgress",new Map([["initialScene",0]])),ge(this,"materialReadyToLoadCallbacks",new Map),ge(this,"modelReadyToLoadCallbacks",new Map),ge(this,"queuedModelAnimation",void 0),ge(this,"queuedCameraAnimation",void 0),ge(this,"focusLostNotified",!1),ge(this,"loadObservable",new p),ge(this,"focusLostObservable",new p),ge(this,"dynamicTextures",new Map),ge(this,"highlightLayer",void 0),ge(this,"variantManager",new de),ge(this,"renderingPipeline",void 0);const i=e?.noRender?void 0:document.createElement("canvas");this.configuration=new G(e);m.Configuration={decoder:{wasmUrl:"https://www.gstatic.com/draco/versioned/decoders/1.5.6/draco_wasm_wrapper_gltf.js",wasmBinaryUrl:"https://www.gstatic.com/draco/versioned/decoders/1.5.6/draco_decoder_gltf.wasm",fallbackUrl:"https://www.gstatic.com/draco/versioned/decoders/1.5.6/draco_decoder_gltf.js"}},i&&(i.getContext("webgl2")||i.getContext("webgl"));const a=console.log;console.log=()=>{};const r=i?new t(i,!0,{premultipliedAlpha:!1,preserveDrawingBuffer:!!e?.backgroundImage,audioEngine:!1,stencil:this.configuration.highlights.enabled,forceSRGBBufferSupportState:!0}):new n;console.log=a,r.hideLoadingUI(),window.addEventListener("resize",this.fireResizeEvent.bind(this)),this.engine=r,this.scene=new f(r),this.renderingPipeline=new se(this.scene,!0),this.scene.imageProcessingConfiguration.exposure=this.configuration.lighting.exposure,this.scene.imageProcessingConfiguration.contrast=this.configuration.lighting.contrast}registerFocusLostListener(e){this.focusLostObservable.add(e)}unregisterFocusLostListener(e){this.focusLostObservable.removeCallback(e)}registerLoadProgressListener(e){this.loadObservable.add(e),e(this.getLoadListenerEvent())}unregisterLoadProgressListener(e){this.loadObservable.removeCallback(e)}registerView(e){const i=e.height,t=e.width;this.engine.registerView(e),e.setAttribute("height",i.toString()),e.setAttribute("width",t.toString()),this.orbitEnabled()||this.setCameraState(j.Pan),this.reattachControls(e)}getNumViewports(){return this.engine.views?.length||0}unregisterView(e){this.engine.unRegisterView(e)}shutdown(){this.renderingPipeline.dispose(),this.engine&&this.engine.dispose(),window.removeEventListener("resize",this.fireResizeEvent)}getSceneInitializationProgress(){return this.loadProgress.get("initialScene")}async initialize(t,n){if(this.scene.clearColor=this.configuration.scene.clearColor,this.scene.metadata={baseModel:t},this.scene.environmentTexture=l.CreateFromPrefilteredData(this.configuration.scene.environmentFile,this.scene),t){const e=100;await me(t,this.scene,(i=>{this.loadProgress.set("initialScene",i.loaded*e/i.total),this.notifyLoadHandlers()}))}this.configuration.highlights.enabled&&this.scene.meshes.forEach((t=>{"targetcube_t"!==t.name&&"backgroundShell"!==t.name&&(t.isPickable=!0,t.actionManager||(t.actionManager=new e(this.scene)),t.actionManager.registerAction(new i(e.OnPointerOutTrigger,(()=>{this.setHighlights([])}))),t.actionManager.registerAction(new i(e.OnPointerOverTrigger,(e=>{if(e.meshUnderPointer){const i=e.meshUnderPointer.material;i&&this.setHighlights([i])}}))))}));const r=ne.create(this.scene,this.configuration);this.renderingPipeline.addCamera(r),this.configuration.options.renderingPipelineConfig&&this.renderingPipeline.apply(this.configuration.options.renderingPipelineConfig);const s=n?.getAll()||new Map;Y(this.scene,s,this.dynamicTextures);if(this.scene.materials.some((e=>"emissiveTexture"in e&&null!==e.emissiveTexture))){new a("GlowLayer",this.scene).intensity=.5}J(this.scene),this.engine.views?.length>=1&&this.reattachControls(this.engine.views[this.engine.views.length-1].target),await this.processQueuedLoadEvents(),this.engine.runRenderLoop((()=>{this.engine.views&&(s.forEach(((e,i)=>{const t=this.dynamicTextures.get(i);t&&e.getStaticContextDirty()&&t.isReady()&&(t.update(!1),e.setStaticContextDirty(!1))})),this.configuration.scene.transparentBackground&&this.engine.views.forEach((e=>{const i=this.engine.getRenderingCanvas();e.target.getContext("2d").clearRect(0,0,i.width,i.height)})),this.scene.render(),r.target.equalsWithEpsilon(r.lastFocus,.1)||this.focusLostNotified||(this.focusLostObservable.notifyObservers(void 0),this.focusLostNotified=!0))}))}executeModelAnimation(e){100===this.getSceneInitializationProgress()?$(this.scene,e.loop,e.to,e.from):this.queuedModelAnimation=e}executeCameraAnimation(e){100===this.getSceneInitializationProgress()&&this.scene.activeCamera?ee(this.scene,this.scene.activeCamera,e):this.queuedCameraAnimation=e}getCameraPose(){if(this.scene){const e=this.scene.activeCamera;if(e)return{lonDeg:Math.round(180*e.alpha/Math.PI),latDeg:Math.round(180*e.beta/Math.PI),radius:Math.round(1e4*(e.radius+Number.EPSILON))/1e4,target:{x:e.target.x,y:e.target.y,z:e.target.z}}}}setCameraPose(e){if(this.scene){const i=this.scene.activeCamera;i&&(i.target=new g(e.target.x,e.target.y,e.target.z),i.radius=e.radius,i.alpha=e.latDeg,i.beta=e.lonDeg)}}async applyMaterialVariant(e,i,t,n){if(100===this.getSceneInitializationProgress())await this.variantManager.applyMaterial(this.scene,e,t,((e,i,t)=>{this.loadProgress.set(`key_${t}`,e/i*100),this.notifyLoadHandlers()}),n);else if(this.materialReadyToLoadCallbacks.has(e)){this.materialReadyToLoadCallbacks.get(e)?.set(i,t)}else{this.materialReadyToLoadCallbacks.set(e,new Map);this.materialReadyToLoadCallbacks.get(e)?.set(i,t)}}async applyModelVariant(e,i,t){100===this.getSceneInitializationProgress()?(await this.variantManager.applyModel(this.scene,e,t||!1,i.model,(i=>{this.loadProgress.set(e,100*i.loaded/i.total),this.notifyLoadHandlers()})),this.scene.materials.forEach((e=>{if(e&&0===e.getBindedMeshes().length){const i=e instanceof o&&!(e.albedoTexture instanceof c);e.dispose(!1,i)}})),Y(this.scene,i.contextService.getAll(),this.dynamicTextures),J(this.scene)):this.modelReadyToLoadCallbacks.set(e,(async()=>{await this.applyModelVariant(e,i,t)}))}getQueuedMaterialVariants(){return this.materialReadyToLoadCallbacks.size}getQueuedModelVariants(){return this.modelReadyToLoadCallbacks.size}setCameraState(e){if(!this.engine?.views||!this.engine?.views[0])throw new Error("No views attached, camera state requires a view to attach controls onto.");e===j.Orbit?this.reattachControls(this.engine.views[0].target,2):this.reattachControls(this.engine.views[0].target,0)}animateToLastCameraFocus(){return new Promise((e=>{const i=this.scene.activeCamera,t=this.configuration;i.rerunFramingBehavior((()=>{this.focusLostNotified=!1,t.camera.limits.min.radius&&(i.lowerRadiusLimit=t.camera.limits.min.radius),t.camera.limits.max.radius&&(i.upperRadiusLimit=t.camera.limits.max.radius),e()}))}))}setAutoRotation(e){const i=this.scene.activeCamera;this.configuration.camera.autoRotation.enabled&&i&&(e?i.enableAutoRotationBehavior(this.configuration.camera.autoRotation.idleTimeMs):i.disableAutoRotationBehavior())}getCurrentConfiguration(){return this.configuration.options}async renderSceneScreenshot(e,i){const t=this.scene.activeCamera;if(!t)throw new Error("Missing product camera, cannot render screenshot!");var n;(n=t).getScene().stopAnimation(n),n.animations=[];const a=t.alpha,r=t.beta,s=t.radius,o=i.latDeg*Math.PI/180,l=i.lonDeg*Math.PI/180;t.alpha=l,t.beta=o,t.radius=i.radius||t.radius;const c=await b.CreateScreenshotUsingRenderTargetAsync(this.engine,t,e,"image/png",2,!0);return t.alpha=a,t.beta=r,t.radius=s,c}orbitEnabled(){const e=this.configuration;if(!e)return!0;const i=e.camera.limits.min.alpha,t=e.camera.limits.max.alpha,n=e.camera.limits.min.beta,a=e.camera.limits.max.beta;if(void 0===i||void 0===t||void 0===n||void 0===a)return!0;const r=[n,a],s=[i,t].every((e=>e===i)),o=r.every((e=>e===n));return!s&&!o}fireResizeEvent(){this.getNumViewports()>0&&this.engine.resize()}onMaterialSelected(t){this.scene.meshes.forEach((n=>{"targetcube_t"!==n.name&&"backgroundShell"!==n.name&&(n.actionManager||(n.actionManager=new e(this.scene)),n.actionManager.registerAction(new i(e.OnPickDownTrigger,(e=>{if(e.meshUnderPointer){const i=e.meshUnderPointer.material;i&&t({id:i.id,name:i.name})}}))))}))}listMaterials(){const e=this.scene?.materials;return e?e.map((e=>({id:e.id,name:e.name}))):[]}setHighlights(e,i){0===e.length&&(this.highlightLayer?.dispose(),this.highlightLayer=void 0),this.highlightLayer||(this.highlightLayer=new r("highlights",this.scene,{isStroke:!0,blurVerticalSize:.85,blurHorizontalSize:.85}),this.highlightLayer.innerGlow=!0,this.highlightLayer.outerGlow=!1),this.highlightLayer.removeAllMeshes();const t=i?new h(i[0],i[1],i[2]).toLinearSpace():void 0;e.forEach((e=>{const i=this.scene.materials.find((i=>i.name===e.name&&i.id===e.id));i&&i.getBindedMeshes().forEach((e=>this.highlightLayer?.addMesh(e,t||h.FromHexString("#fcba03"))))}))}setRenderingPipelineConfig(e){this.renderingPipeline&&this.renderingPipeline.apply(e)}reattachControls(e,i=2){this.scene.detachControl(),this.engine.inputElement=e;const t=this.scene.activeCamera;if(t){t.attachControl(!0,!1,i);t.inputs.attached.pointers.multiTouchPanning=!1}this.scene.attachControl(!0,!0,!0)}getLoadListenerEvent(){const e=Array.from(this.loadProgress.values()).filter((e=>e<100)),i=e.reduce(((e,i)=>e+i),0)/e.length||0;return{loadValue:0===e.length?100:i,sceneInitialized:100===this.getSceneInitializationProgress()}}notifyLoadHandlers(){this.loadObservable.notifyObservers(this.getLoadListenerEvent())}async processQueuedLoadEvents(){await Promise.all(Array.from(this.modelReadyToLoadCallbacks.values()).map((e=>e(this.scene)))),this.modelReadyToLoadCallbacks.clear(),this.materialReadyToLoadCallbacks.forEach(((e,i)=>{e.forEach(((e,t)=>{this.applyMaterialVariant(i,t,e)}))})),this.materialReadyToLoadCallbacks.clear(),this.queuedModelAnimation&&(this.executeModelAnimation(this.queuedModelAnimation),this.queuedModelAnimation=void 0),this.queuedCameraAnimation&&(this.executeCameraAnimation(this.queuedCameraAnimation),this.queuedCameraAnimation=void 0)}}async function me(e,i,t){(await H(e,i,t)).addAllToScene()}export{j as ProductCameraRig,N as MaterialEffectMode,ue as SpiffCommerce3DPreviewService,me as createBaseModel,q as RenderingConfiguration,K as REFLECTION_PROBE_RESOLUTION};
1
+ import{ActionManager as e}from"@babylonjs/core/Actions/actionManager";import{ExecuteCodeAction as i}from"@babylonjs/core/Actions/directActions";import{Engine as t}from"@babylonjs/core/Engines/engine";import{NullEngine as n}from"@babylonjs/core/Engines/nullEngine";import{GlowLayer as a}from"@babylonjs/core/Layers/glowLayer";import{HighlightLayer as r}from"@babylonjs/core/Layers/highlightLayer";import{SceneLoader as s}from"@babylonjs/core/Loading/sceneLoader";import{PBRMaterial as o}from"@babylonjs/core/Materials/PBR/pbrMaterial";import{CubeTexture as l}from"@babylonjs/core/Materials/Textures/cubeTexture";import{DynamicTexture as c}from"@babylonjs/core/Materials/Textures/dynamicTexture";import{Color3 as h,Color4 as d}from"@babylonjs/core/Maths/math.color";import{Vector3 as g,Vector2 as u}from"@babylonjs/core/Maths/math.vector";import{DracoCompression as m}from"@babylonjs/core/Meshes/Compression/dracoCompression";import{Observable as p}from"@babylonjs/core/Misc/observable";import{Tools as b}from"@babylonjs/core/Misc/tools";import{Scene as f}from"@babylonjs/core/scene";import{GLTF2 as P}from"@babylonjs/loaders/glTF";import"@babylonjs/core/Engines/Extensions/engine.views";import"@babylonjs/core/Meshes/instancedMesh";import"@babylonjs/core/Materials/Textures/Loaders/ddsTextureLoader";import"@babylonjs/core/Materials/Textures/Loaders/envTextureLoader";import"@babylonjs/core/Materials/Textures/Loaders/ktxTextureLoader";import"@babylonjs/core/Animations/animatable";import"@babylonjs/core/Misc/screenshotTools";import"@babylonjs/core/Rendering/boundingBoxRenderer";import"@babylonjs/loaders/glTF/2.0/Extensions";import{Texture as v}from"@babylonjs/core/Materials/Textures/texture";import{MirrorTexture as y}from"@babylonjs/core/Materials/Textures/mirrorTexture";import{Color3 as w,Vector3 as x,Plane as M}from"@babylonjs/core/Maths/math";import{ReflectionProbe as C}from"@babylonjs/core/Probes/reflectionProbe";import{Animation as T}from"@babylonjs/core/Animations/animation";import{QuadraticEase as A,EasingFunction as L}from"@babylonjs/core/Animations/easing";import{ArcRotateCamera as O}from"@babylonjs/core/Cameras/arcRotateCamera";import{ColorCurves as E}from"@babylonjs/core/Materials/colorCurves";import{ImageProcessingConfiguration as R}from"@babylonjs/core/Materials/imageProcessingConfiguration";import{DefaultRenderingPipeline as S}from"@babylonjs/core/PostProcesses/RenderPipeline";import{DepthOfFieldEffectBlurLevel as F}from"@babylonjs/core/PostProcesses/depthOfFieldEffect";import"@babylonjs/core/Rendering/depthRendererSceneComponent";import{AssetsManager as I}from"@babylonjs/core/Misc/assetsManager";function B(e,i,t,n){Object.defineProperty(e,i,{get:t,set:n,enumerable:!0,configurable:!0})}var D={};let j;var k;let N;var V;B(D,"ProductCameraRig",(()=>j)),B(D,"MaterialEffectMode",(()=>N)),(k=j||(j={}))[k.Orbit=0]="Orbit",k[k.Pan=1]="Pan",(V=N||(N={})).None="None",V.RemoveWhenSelected="RemoveWhenSelected",V.ApplyWhenSelected="ApplyWhenSelected";var _={};B(_,"SpiffCommerce3DPreviewService",(()=>ue)),B(_,"createBaseModel",(()=>me));const z=new Map;async function H(e,i,t){return new Promise(((n,a)=>{const r=z.get(e);if(r&&r.scene.uid===i.uid)return n(r);s.LoadAssetContainerAsync(e,void 0,i,t).then((i=>{z.set(e,i),n(i)})).catch(a)}))}function U(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class G{constructor(e){U(this,"customOptions",void 0),U(this,"getSceneClearColor",(()=>{const e=this.customOptions?.transparentBackground||this.customOptions?.backgroundImage?0:1;if(this.customOptions&&this.customOptions?.transparentBackground||this.customOptions?.backgroundImage)return new d(0,0,0,e).toLinearSpace();if(this.customOptions&&this.customOptions.backgroundColor){const i=h.FromHexString(this.customOptions.backgroundColor);return new d(i.r,i.g,i.b,e).toLinearSpace()}return new d(.98,.98,.98,e).toLinearSpace()})),U(this,"highlightColorFromConfig",(()=>this.customOptions&&this.customOptions.highlightColor?this.hexToColor4(this.customOptions.highlightColor):new d(.98,.98,.98,1).toLinearSpace())),U(this,"hexToColor4",((e,i=1)=>{const t=h.FromHexString(e);return new d(t.r,t.g,t.b,i).toLinearSpace()})),this.customOptions=e}get options(){return this.customOptions}get scene(){return{clearColor:this.getSceneClearColor(),transparentBackground:this.customOptions?.transparentBackground||this.customOptions?.backgroundImage,environmentFile:this.customOptions?.environmentFile??"assets/model-viewer/default.env"}}get camera(){return{autoOrientation:this.customOptions?.disableAutomaticOrientation??!0,autoRotation:{enabled:this.customOptions?.autoRotation??!1,idleTimeMs:this.customOptions?.idleTimeBeforeRotation??5e3},limits:{min:{alpha:this.customOptions?.lowerAlphaLimitDeg?this.customOptions?.lowerAlphaLimitDeg*Math.PI/180:void 0,beta:this.customOptions?.lowerBetaLimitDeg?this.customOptions?.lowerBetaLimitDeg*Math.PI/180:void 0,radius:this.customOptions?.minZoomOverride},max:{alpha:this.customOptions?.upperAlphaLimitDeg?this.customOptions?.upperAlphaLimitDeg*Math.PI/180:void 0,beta:this.customOptions?.upperBetaLimitDeg?this.customOptions?.upperBetaLimitDeg*Math.PI/180:void 0,radius:this.customOptions?.maxZoomOverride}}}}get highlights(){return{enabled:this.customOptions?.highlightOnMaterialHover??!1,color:this.highlightColorFromConfig()}}get lighting(){return{exposure:this.customOptions?.lighting?.exposure??.9,contrast:this.customOptions?.lighting?.contrast??1.6}}}var W={};B(W,"RenderingConfiguration",(()=>q)),B(W,"REFLECTION_PROBE_RESOLUTION",(()=>K));class q{static getDynamicTextureResolution(){return this.getIsMobile()||!q.offscreenRenderingSupported()?{width:1024,height:1024}:{width:2048,height:2048}}static shouldMipMap(){return!0}static offscreenRenderingSupported(){return!navigator.userAgent.includes("SamsungBrowser")&&(!!window.Worker&&!!window.OffscreenCanvas)}static getMirrorTextureResolution(){return this.getIsMobile()?512:1024}static getIsMobile(){return window.innerWidth<=480}}const K=128;function Q(e,i,n){i.forEach((i=>{const a=i.getID(),r=i.getName(),s=q.getDynamicTextureResolution();e.materials.filter((e=>e.name===r)).forEach((o=>{const l=n.get(a);if(l)Y(o,l),l.update(false);else{const l=function(e,i,n,a){const r=new c(e,{width:n,height:a},i,q.shouldMipMap(),v.TRILINEAR_SAMPLINGMODE,t.TEXTUREFORMAT_RGBA),s=r.getContext();s&&(s.fillStyle="#f5f5f5",s.fillRect(0,0,n,a),r.update());return r}(r,e,s.width,s.height);n.set(a,l),i.setStaticContext(l.getContext()),Y(o,l),l.onLoadObservable.addOnce((()=>{l.update(false)}))}}))}))}function Y(e,i){if(e instanceof o){const t=e,n=t.albedoTexture;n?(i.wrapU=n.wrapU,i.wrapV=n.wrapV):(i.wrapU=1,i.wrapV=1),t.albedoTexture=i}else{const t=e,n=t.diffuseTexture;n&&(i.wrapU=n.wrapU,i.wrapV=n.wrapV),t.diffuseTexture=i}}function Z(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class X{constructor(e){Z(this,"name",void 0),Z(this,"enabled",void 0),Z(this,"loader",void 0),this.name="glbPostProcessor",this.enabled=!0,this.loader=e}onReady(){this.applyReflections(this.loader.babylonScene)}loadNodeAsync(e,i,t){return this.loader.loadNodeAsync(e,i,(function(e){i.extras&&Object.keys(i.extras).forEach((t=>{const n=i.extras[t];e.metadata[t]=n})),t(e)}))}loadMaterialPropertiesAsync(e,i,t){return this.enableMaterialExtrasIfRequired(i,t),this.loader.loadMaterialPropertiesAsync(e,i,t)}dispose(){}enableMaterialExtrasIfRequired(e,i){if(e.extras&&i instanceof o){if(e.extras.sheen){const t=i;t.sheen.isEnabled=!0,t.sheen.intensity=e.extras.sheen}if(e.extras.translucency){const t=i;t.subSurface.isTranslucencyEnabled=!0,t.subSurface.translucencyIntensity=e.extras.translucency,e.extras.translucencyR&&e.extras.translucencyG&&e.extras.translucencyB&&(t.subSurface.tintColor=new w(e.extras.translucencyR,e.extras.translucencyG,e.extras.translucencyB))}if(e.extras.refractionIOR){i.subSurface.indexOfRefraction=e.extras.refractionIOR}if(e.extras.useDepthPrePass){const e=i;e.needDepthPrePass=!0,e.forceIrradianceInFragment=!0}if(e.extras.useParallax){const t=i;t.useParallax=!0,t.useParallaxOcclusion=!0,t.parallaxScaleBias=e.extras.useParallax}}}applyReflections(e){function i(e){const i=[];return e.transformNodes.forEach((e=>{e.metadata&&e.metadata.reflective&&i.push(...e.getChildMeshes())})),e.meshes.forEach((e=>{e.metadata&&e.metadata.reflective&&!i.includes(e)&&i.push(e)})),i}e.meshes.forEach((t=>{const n=t.metadata;n&&(n.mirrorTexture&&function(t,n=1){const a=t.material;if(!a)return;const r=new y("mirror",q.getMirrorTextureResolution(),e,!0);r.renderList=i(e);const s=t.getVerticesData("normal");if(!s)throw new Error("Mirror attribute specified on: "+t.name+"But no normals exist to generate a mirror from!");t.computeWorldMatrix(!0);const o=t.getWorldMatrix(),l=x.TransformNormal(new x(s[0],s[1],s[2]),o).normalize(),c=M.FromPositionAndNormal(t.position,l.scale(-1));r.mirrorPlane=c,r.level=n,a.reflectionTexture=r}(t,n.mirrorTexture),n.reflectionProbe&&function(t){const n=t.material,a=new C("probe-"+n.name,K,e);a.attachToMesh(t),a.renderList&&a.renderList.push(...i(e)),n.reflectionTexture=a.cubeTexture}(t))}))}}function $(e,i,t,n){const a=e.animationGroups,r=e=>e.targetedAnimations.map((e=>e.animation.framePerSecond)).reduce(((e,i)=>e+i),0)/e.targetedAnimations.length||0;void 0===n||void 0===t||n!==t?a.forEach((e=>{e.stop();const a=r(e);e.start(i,1,n*a,t*a)})):a.forEach((e=>{e.stop();const t=r(e),a=n*t;e.start(i,1,a,a)}))}function J(e){e.animationGroups.forEach((e=>{e.stop()}))}function ee(e,i,t){var n,a,r;e.stopAnimation(i),i.animations=[],Math.abs(i.alpha)>2*Math.PI&&(i.alpha=(n=i.alpha,a=0,r=2*Math.PI,n<a?r-(a-n)%(r-a):a+(n-a)%(r-a)));const s=[],o=t.target,l=o?1:0;if(t.target&&Object.keys(t.target).length>0&&s.push(te("cameraTargetLerp","target",(new g).copyFrom(i.target),new g(t.target.x,t.target.y,t.target.z),T.ANIMATIONTYPE_VECTOR3,0)),s.push(te("cameraAlphaLerp","alpha",i.alpha,ie(t.lonDeg),T.ANIMATIONTYPE_FLOAT,l)),s.push(te("cameraBetaLerp","beta",i.beta,ie(t.latDeg),T.ANIMATIONTYPE_FLOAT,l)),void 0!==t.radius){const e=Math.max(.01,t.radius);s.push(te("cameraRadiusLerp","radius",i.radius,e,T.ANIMATIONTYPE_FLOAT,l))}i.animations.push(...s);const c=i.useAutoRotationBehavior;i.disableAutoRotationBehavior(),e.beginAnimation(i,0,o?120:60,!1,1,(()=>{i.animations=[],c&&i.enableAutoRotationBehavior()}))}function ie(e){return e*Math.PI/180}function te(e,i,t,n,a,r=0,s=T.ANIMATIONLOOPMODE_CONSTANT){const o=new A;o.setEasingMode(L.EASINGMODE_EASEINOUT);const l=new T(e,i,60,a,s),c=[];return r>0&&c.push({frame:0,value:t}),c.push({frame:60*r,value:t}),c.push({frame:60*(r+1),value:n}),l.setKeys(c),l.setEasingFunction(o),l}class ne extends O{constructor(e,i,t,n,a,r,s,o){var l,c,h;super(e,i,t,n,a,r,o),l=this,c="lastFocus",h=new g(0,0,0),c in l?Object.defineProperty(l,c,{value:h,enumerable:!0,configurable:!0,writable:!0}):l[c]=h,this.minZ=.01,this.maxZ=1e3*this.radius,this.lowerRadiusLimit=.01*this.radius,this.enableFramingBehavior(),this.upperRadiusLimit=1.5*this.radius,this.wheelPrecision=100/this.radius,this.pinchPrecision=300/this.radius,this.wheelDeltaPercentage=.01,this.pinchDeltaPercentage=.005,this.useNaturalPinchZoom=!0,s.camera.autoOrientation&&(this.alpha+=Math.PI),s&&(s.camera.limits.min.beta&&(this.lowerBetaLimit=s.camera.limits.min.beta),s.camera.limits.max.beta&&(this.upperBetaLimit=s.camera.limits.max.beta),s.camera.limits.min.alpha&&(this.lowerAlphaLimit=s.camera.limits.min.alpha),s.camera.limits.max.alpha&&(this.upperAlphaLimit=s.camera.limits.max.alpha),s.camera.limits.min.radius&&(this.lowerRadiusLimit=s.camera.limits.min.radius),s.camera.limits.max.radius&&(this.upperRadiusLimit=s.camera.limits.max.radius),s.camera.autoRotation.enabled&&this.enableAutoRotationBehavior(s.camera.autoRotation.idleTimeMs))}getFramingBehavior(){return this.getBehaviorByName("Framing")}getAutoRotationBehavior(){const e=this.getBehaviorByName("AutoRotation");return e||void 0}enableFramingBehavior(){this.useFramingBehavior=!0;const e=this.getFramingBehavior();e.attach(this),e.framingTime=0,e.elevationReturnTime=-1,e.zoomStopsAnimation=!1,this.lowerRadiusLimit=null;const i=ae(this._scene);return e.zoomOnBoundingInfo(i.min,i.max),this.wheelPrecision=100/this.radius,null===this.lowerRadiusLimit&&(this.lowerRadiusLimit=.1),this.lastFocus.copyFrom(this.target),e}rerunFramingBehavior(e){const i=this.getFramingBehavior();i.framingTime=800;const t=ae(this._scene);i.zoomOnBoundingInfo(t.min,t.max,void 0,(()=>{e()})),i.framingTime=0}enableAutoRotationBehavior(e=5e3){this.useAutoRotationBehavior=!0;const i=this.getAutoRotationBehavior();i&&(i.idleRotationWaitTime=e)}disableAutoRotationBehavior(){this.useAutoRotationBehavior=!1}static create(e,i){e.activeCamera&&(e.activeCamera.dispose(),e.activeCamera=null);const t=ae(e),n=t.max.subtract(t.min),a=t.min.add(n.scale(.5)),r=new ne("ProductCamera",-Math.PI/2,Math.PI/2,1.5*n.length(),a,e,i);return r.panningInertia=0,r.panningOriginTarget.copyFrom(a),r.onAfterCheckInputsObservable.add((()=>{r.panningSensibility=1e3/n.length()})),e.activeCamera=r,r}}function ae(e){const i=e.meshes.filter((e=>e.name.toLowerCase().endsWith("_t")||e.name.toLowerCase().includes("_t_")));return e.getWorldExtends((e=>e.isVisible&&e.isEnabled()&&(0===i.length||i.includes(e))))}function re(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class se{constructor(e,i=!0,t=null){re(this,"renderingPipeline",void 0),re(this,"currentConfig",void 0),this.renderingPipeline=new S("default",i,e,t?[t]:void 0,!1),this.renderingPipeline.prepare()}dispose(){this.renderingPipeline.dispose()}addCamera(e){this.renderingPipeline.addCamera(e)}removeCamera(e){this.renderingPipeline.removeCamera(e)}getConfig(){return this.currentConfig}apply(e){if(this.renderingPipeline.samples=e.antiAliasing?.msaaSamples||this.renderingPipeline.samples,this.renderingPipeline.fxaaEnabled=e.antiAliasing?.fxaaEnabled||this.renderingPipeline.fxaaEnabled,this.renderingPipeline.bloomEnabled=e.bloom?.enabled||this.renderingPipeline.bloomEnabled,this.renderingPipeline.bloomKernel=e.bloom?.kernel||this.renderingPipeline.bloomKernel,this.renderingPipeline.bloomScale=e.bloom?.scale||this.renderingPipeline.bloomScale,this.renderingPipeline.bloomThreshold=e.bloom?.threshold||this.renderingPipeline.bloomThreshold,this.renderingPipeline.bloomWeight=e.bloom?.weight||this.renderingPipeline.bloomWeight,this.renderingPipeline.chromaticAberrationEnabled=e.chromaticAberration?.enabled||this.renderingPipeline.chromaticAberrationEnabled,this.renderingPipeline.chromaticAberration.aberrationAmount=e.chromaticAberration?.aberrationAmount||this.renderingPipeline.chromaticAberration.aberrationAmount,this.renderingPipeline.chromaticAberration.radialIntensity=e.chromaticAberration?.radialIntensity||this.renderingPipeline.chromaticAberration.radialIntensity,this.renderingPipeline.chromaticAberration.direction=e.chromaticAberration?.direction?new u(e.chromaticAberration.direction.x,e.chromaticAberration.direction.y):this.renderingPipeline.chromaticAberration.direction,this.renderingPipeline.imageProcessing.colorCurvesEnabled=e.colorCurves?.enabled||this.renderingPipeline.imageProcessing.colorCurvesEnabled,this.renderingPipeline.imageProcessing.colorCurves=e.colorCurves?this.updateColorCurve(e.colorCurves,this.renderingPipeline.imageProcessing.colorCurves):this.renderingPipeline.imageProcessing.colorCurves,this.renderingPipeline.depthOfFieldEnabled=e.depthOfField?.enabled||this.renderingPipeline.depthOfFieldEnabled,e.depthOfField.blurLevel)switch(e.depthOfField.blurLevel){case"Low":this.renderingPipeline.depthOfFieldBlurLevel=F.Low;break;case"Medium":this.renderingPipeline.depthOfFieldBlurLevel=F.Medium;break;case"High":this.renderingPipeline.depthOfFieldBlurLevel=F.High}if(this.renderingPipeline.depthOfField.focalLength=e.depthOfField?.focalLength||this.renderingPipeline.depthOfField.focalLength,this.renderingPipeline.depthOfField.fStop=e.depthOfField?.fStop||this.renderingPipeline.depthOfField.fStop,this.renderingPipeline.depthOfField.focusDistance=e.depthOfField?.focusDistance||this.renderingPipeline.depthOfField.focusDistance,this.renderingPipeline.depthOfField.lensSize=e.depthOfField?.lensSize||this.renderingPipeline.depthOfField.lensSize,this.renderingPipeline.grainEnabled=e.grain?.enabled||this.renderingPipeline.grainEnabled,this.renderingPipeline.grain.animated=e.grain?.animated||this.renderingPipeline.grain.animated,this.renderingPipeline.grain.intensity=e.grain?.intensity||this.renderingPipeline.grain.intensity,this.renderingPipeline.imageProcessing.contrast=e.misc?.contrast||this.renderingPipeline.imageProcessing.contrast,this.renderingPipeline.imageProcessing.exposure=e.misc?.exposure||this.renderingPipeline.imageProcessing.exposure,this.renderingPipeline.imageProcessing.toneMappingEnabled=e.misc?.toneMappingEnabled||this.renderingPipeline.imageProcessing.toneMappingEnabled,e.misc.toneMappingType)switch(e.misc.toneMappingType){case"Standard":this.renderingPipeline.imageProcessing.toneMappingType=R.TONEMAPPING_STANDARD;break;case"ACES":this.renderingPipeline.imageProcessing.toneMappingType=R.TONEMAPPING_ACES}switch(this.renderingPipeline.sharpenEnabled=e.sharpen?.enabled||this.renderingPipeline.sharpenEnabled,this.renderingPipeline.sharpen.colorAmount=e.sharpen?.colorAmount||this.renderingPipeline.sharpen.colorAmount,this.renderingPipeline.sharpen.edgeAmount=e.sharpen?.edgeAmount||this.renderingPipeline.sharpen.edgeAmount,this.renderingPipeline.imageProcessing.vignetteEnabled=e.vignette?.enabled||this.renderingPipeline.imageProcessing.vignetteEnabled,e.vignette?.center&&(this.renderingPipeline.imageProcessing.vignetteCenterX=e.vignette.center.x,this.renderingPipeline.imageProcessing.vignetteCenterY=e.vignette.center.y),e.vignette?.blendMode){case"Multiply":this.renderingPipeline.imageProcessing.vignetteBlendMode=R.VIGNETTEMODE_MULTIPLY;break;case"Opaque":this.renderingPipeline.imageProcessing.vignetteBlendMode=R.VIGNETTEMODE_OPAQUE}e.vignette.colorRgba?this.renderingPipeline.imageProcessing.vignetteColor=new d(e.vignette.colorRgba.r,e.vignette.colorRgba.g,e.vignette.colorRgba.b,e.vignette.colorRgba.a):e.vignette.colorHex&&(this.renderingPipeline.imageProcessing.vignetteColor=d.FromHexString(e.vignette.colorHex)),this.renderingPipeline.imageProcessing.vignetteStretch=e.vignette?.stretch||this.renderingPipeline.imageProcessing.vignetteStretch,this.renderingPipeline.imageProcessing.vignetteWeight=e.vignette?.weight||this.renderingPipeline.imageProcessing.vignetteWeight,this.renderingPipeline.prepare(),this.currentConfig={...this.currentConfig,...e}}updateColorCurve(e,i){const t=i??new E;return t.globalDensity=e.globalDensity??t.globalDensity,t.globalExposure=e.globalExposure??t.globalExposure,t.globalHue=e.globalHue??t.globalHue,t.globalSaturation=e.globalSaturation??t.globalSaturation,t.highlightsDensity=e.highlightsDensity??t.highlightsDensity,t.highlightsExposure=e.highlightsExposure??t.highlightsExposure,t.highlightsHue=e.highlightsHue??t.highlightsHue,t.highlightsSaturation=e.highlightsSaturation??t.highlightsSaturation,t.midtonesDensity=e.midtonesDensity??t.midtonesDensity,t.midtonesExposure=e.midtonesExposure??t.midtonesExposure,t.midtonesHue=e.midtonesHue??t.midtonesHue,t.midtonesSaturation=e.midtonesSaturation??t.midtonesSaturation,t.shadowsDensity=e.shadowsDensity??t.shadowsDensity,t.shadowsExposure=e.shadowsExposure??t.shadowsExposure,t.shadowsHue=e.shadowsHue??t.shadowsHue,t.shadowsSaturation=e.shadowsSaturation??t.shadowsSaturation,t}}const oe={albedoTexture:"albedoMap",bumpTexture:"normalMap",ambientTexture:"ambientMap",emissiveTexture:"emissionMap",opacityTexture:"alphaMap",metallicTexture:"metallicMap",refractionTexture:"refractionMap"};function le(e,i,t,n){["albedoTexture","bumpTexture","ambientTexture","emissiveTexture","opacityTexture","metallicTexture","refractionTexture"].forEach((a=>{!function(e,i,t,n,a){const r=oe[e];if(!r)throw new Error("Unexpected texture name encountered.");const s=i[r]?.fileLink;s?n.addTextureTask(e,s,!1,!1):a&&t[e]&&(t[e]&&t[e].dispose(),t[e]=null,function(e,i){"opacityTexture"===e&&(i.useAlphaFromAlbedoTexture=!0);"metallicTexture"===e&&(i.useRoughnessFromMetallicTextureAlpha=!1,i.useRoughnessFromMetallicTextureGreen=!1,i.useMetallnessFromMetallicTextureBlue=!1);"refractionTexture"===e&&(i.subSurface.isRefractionEnabled=!1,i.subSurface.refractionIntensity=1)}(e,t))}(a,e,i,t,n)})),function(e,i){if(!e.clearCoat)return;e.clearCoat===N.RemoveWhenSelected?(i.clearCoat.isEnabled=!1,i.clearCoat.indexOfRefraction=1.5):e.clearCoat===N.ApplyWhenSelected&&(i.clearCoat.isEnabled=!0,i.clearCoat.indexOfRefraction=e.clearCoatIOR||i.clearCoat.indexOfRefraction)}(e,i)}function ce(e,i,t,n){"opacityTexture"===e&&(i.useAlphaFromAlbedoTexture=!1),"metallicTexture"===e&&(i.useRoughnessFromMetallicTextureAlpha=!1,i.useRoughnessFromMetallicTextureGreen=!0,i.useMetallnessFromMetallicTextureBlue=!0),"refractionTexture"===e&&(i.subSurface.isRefractionEnabled=!0,i.subSurface.refractionIntensity=t.refractionIntensity||1),i[e]=n}function he(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class de{constructor(){he(this,"materialVariantMap",new Map),he(this,"keysThatRemovedBaseModel",[]),he(this,"loadedContainerForKey",new Map)}async applyMaterial(e,i,t,n,a){return new Promise((r=>{const s=e.materials.filter((e=>e.name===i)),o=this.materialVariantMap.get(i);if(this.materialVariantMap.set(i,{...o,...t}),0===s.length)return void r(void 0);const l=new I(e);l.useDefaultLoadingScreen=!1,s.forEach((e=>le(t,e,l,a))),l.onProgress=(e,i,t)=>{n&&n(e/i*100,100,t.name)},l.onFinish=e=>{e.forEach((e=>{const i=e;n&&n(100,100,e.name),s.forEach((n=>ce(e.name,n,t,i.texture)))})),r(void 0)},l.loadAsync()}))}async applyModel(e,i,t,n,a){if(n&&t&&!this.keysThatRemovedBaseModel.includes(i)&&this.keysThatRemovedBaseModel.push(i),!n){const t=this.keysThatRemovedBaseModel.includes(i);return this.loadedContainerForKey.get(i)?.removeAllFromScene(),e&&t&&await me(e.metadata.baseModel,e),Promise.resolve()}const r=await H(n,e,a);if(this.loadedContainerForKey.has(i)&&this.loadedContainerForKey.get(i)?.removeAllFromScene(),t){(await H(e.metadata.baseModel,e)).removeAllFromScene()}r.addAllToScene(),this.loadedContainerForKey.set(i,r);const s=[];this.materialVariantMap.forEach((async(i,t)=>{s.push(this.applyMaterial(e,t,i))})),await Promise.all(s)}}function ge(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}P.GLTFLoader.RegisterExtension("glbPostProcessor",(function(e){return new X(e)})),s.OnPluginActivatedObservable.add((e=>{if("gltf"===e.name){e.transparencyAsCoverage=!0}}));class ue{constructor(e){ge(this,"engine",void 0),ge(this,"scene",void 0),ge(this,"configuration",void 0),ge(this,"loadProgress",new Map([["initialScene",0]])),ge(this,"materialReadyToLoadCallbacks",new Map),ge(this,"modelReadyToLoadCallbacks",new Map),ge(this,"queuedModelAnimation",void 0),ge(this,"queuedCameraAnimation",void 0),ge(this,"focusLostNotified",!1),ge(this,"loadObservable",new p),ge(this,"focusLostObservable",new p),ge(this,"dynamicTextures",new Map),ge(this,"highlightLayer",void 0),ge(this,"variantManager",new de),ge(this,"renderingPipeline",void 0);const i=e?.noRender?void 0:document.createElement("canvas");this.configuration=new G(e);m.Configuration={decoder:{wasmUrl:"https://www.gstatic.com/draco/versioned/decoders/1.5.6/draco_wasm_wrapper_gltf.js",wasmBinaryUrl:"https://www.gstatic.com/draco/versioned/decoders/1.5.6/draco_decoder_gltf.wasm",fallbackUrl:"https://www.gstatic.com/draco/versioned/decoders/1.5.6/draco_decoder_gltf.js"}},i&&(i.getContext("webgl2")||i.getContext("webgl"));const a=console.log;console.log=()=>{};const r=i?new t(i,!0,{premultipliedAlpha:!1,preserveDrawingBuffer:!!e?.backgroundImage,audioEngine:!1,stencil:this.configuration.highlights.enabled,forceSRGBBufferSupportState:!0}):new n;console.log=a,r.hideLoadingUI(),window.addEventListener("resize",this.fireResizeEvent.bind(this)),this.engine=r,this.scene=new f(r),this.renderingPipeline=new se(this.scene,!0),this.scene.imageProcessingConfiguration.exposure=this.configuration.lighting.exposure,this.scene.imageProcessingConfiguration.contrast=this.configuration.lighting.contrast}registerFocusLostListener(e){this.focusLostObservable.add(e)}unregisterFocusLostListener(e){this.focusLostObservable.removeCallback(e)}registerLoadProgressListener(e){this.loadObservable.add(e),e(this.getLoadListenerEvent())}unregisterLoadProgressListener(e){this.loadObservable.removeCallback(e)}registerView(e){const i=e.height,t=e.width;this.engine.registerView(e),e.setAttribute("height",i.toString()),e.setAttribute("width",t.toString()),this.orbitEnabled()||this.setCameraState(j.Pan),this.reattachControls(e)}getNumViewports(){return this.engine.views?.length||0}unregisterView(e){this.engine.unRegisterView(e)}shutdown(){this.renderingPipeline.dispose(),this.engine&&this.engine.dispose(),window.removeEventListener("resize",this.fireResizeEvent)}getSceneInitializationProgress(){return this.loadProgress.get("initialScene")}async initialize(t,n){if(this.scene.clearColor=this.configuration.scene.clearColor,this.scene.metadata={baseModel:t},this.scene.environmentTexture=l.CreateFromPrefilteredData(this.configuration.scene.environmentFile,this.scene),t){const e=100;await me(t,this.scene,(i=>{this.loadProgress.set("initialScene",i.loaded*e/i.total),this.notifyLoadHandlers()}))}this.configuration.highlights.enabled&&this.scene.meshes.forEach((t=>{"targetcube_t"!==t.name&&"backgroundShell"!==t.name&&(t.isPickable=!0,t.actionManager||(t.actionManager=new e(this.scene)),t.actionManager.registerAction(new i(e.OnPointerOutTrigger,(()=>{this.setHighlights([])}))),t.actionManager.registerAction(new i(e.OnPointerOverTrigger,(e=>{if(e.meshUnderPointer){const i=e.meshUnderPointer.material;i&&this.setHighlights([i])}}))))}));const r=ne.create(this.scene,this.configuration);this.renderingPipeline.addCamera(r),this.configuration.options.renderingPipelineConfig&&this.renderingPipeline.apply(this.configuration.options.renderingPipelineConfig);const s=n?.getAll()||new Map;Q(this.scene,s,this.dynamicTextures);if(this.scene.materials.some((e=>"emissiveTexture"in e&&null!==e.emissiveTexture))){new a("GlowLayer",this.scene).intensity=.5}J(this.scene),this.engine.views?.length>=1&&this.reattachControls(this.engine.views[this.engine.views.length-1].target),await this.processQueuedLoadEvents(),this.engine.runRenderLoop((()=>{this.engine.views&&(s.forEach(((e,i)=>{const t=this.dynamicTextures.get(i);t&&e.getStaticContextDirty()&&t.isReady()&&(t.update(!1),e.setStaticContextDirty(!1))})),this.configuration.scene.transparentBackground&&this.engine.views.forEach((e=>{const i=this.engine.getRenderingCanvas();e.target.getContext("2d").clearRect(0,0,i.width,i.height)})),this.scene.render(),r.target.equalsWithEpsilon(r.lastFocus,.1)||this.focusLostNotified||(this.focusLostObservable.notifyObservers(void 0),this.focusLostNotified=!0))}))}executeModelAnimation(e){100===this.getSceneInitializationProgress()?$(this.scene,e.loop,e.to,e.from):this.queuedModelAnimation=e}executeCameraAnimation(e){100===this.getSceneInitializationProgress()&&this.scene.activeCamera?ee(this.scene,this.scene.activeCamera,e):this.queuedCameraAnimation=e}getCameraPose(){if(this.scene){const e=this.scene.activeCamera;if(e)return{lonDeg:Math.round(180*e.alpha/Math.PI),latDeg:Math.round(180*e.beta/Math.PI),radius:Math.round(1e4*(e.radius+Number.EPSILON))/1e4,target:{x:e.target.x,y:e.target.y,z:e.target.z}}}}setCameraPose(e){if(this.scene){const i=this.scene.activeCamera;i&&(i.target=new g(e.target.x,e.target.y,e.target.z),i.radius=e.radius,i.alpha=e.latDeg,i.beta=e.lonDeg)}}async applyMaterialVariant(e,i,t,n){if(100===this.getSceneInitializationProgress())await this.variantManager.applyMaterial(this.scene,e,t,((e,i,t)=>{this.loadProgress.set(`key_${t}`,e/i*100),this.notifyLoadHandlers()}),n);else if(this.materialReadyToLoadCallbacks.has(e)){this.materialReadyToLoadCallbacks.get(e)?.set(i,t)}else{this.materialReadyToLoadCallbacks.set(e,new Map);this.materialReadyToLoadCallbacks.get(e)?.set(i,t)}}async applyModelVariant(e,i,t){100===this.getSceneInitializationProgress()?(await this.variantManager.applyModel(this.scene,e,t||!1,i.model,(i=>{this.loadProgress.set(e,100*i.loaded/i.total),this.notifyLoadHandlers()})),this.scene.materials.forEach((e=>{if(e&&0===e.getBindedMeshes().length){const i=e instanceof o&&!(e.albedoTexture instanceof c);e.dispose(!1,i)}})),Q(this.scene,i.contextService.getAll(),this.dynamicTextures),J(this.scene)):this.modelReadyToLoadCallbacks.set(e,(async()=>{await this.applyModelVariant(e,i,t)}))}getQueuedMaterialVariants(){return this.materialReadyToLoadCallbacks.size}getQueuedModelVariants(){return this.modelReadyToLoadCallbacks.size}setCameraState(e){if(!this.engine?.views||!this.engine?.views[0])throw new Error("No views attached, camera state requires a view to attach controls onto.");e===j.Orbit?this.reattachControls(this.engine.views[0].target,2):this.reattachControls(this.engine.views[0].target,0)}animateToLastCameraFocus(){return new Promise((e=>{const i=this.scene.activeCamera,t=this.configuration;i.rerunFramingBehavior((()=>{this.focusLostNotified=!1,t.camera.limits.min.radius&&(i.lowerRadiusLimit=t.camera.limits.min.radius),t.camera.limits.max.radius&&(i.upperRadiusLimit=t.camera.limits.max.radius),e()}))}))}setAutoRotation(e){const i=this.scene.activeCamera;this.configuration.camera.autoRotation.enabled&&i&&(e?i.enableAutoRotationBehavior(this.configuration.camera.autoRotation.idleTimeMs):i.disableAutoRotationBehavior())}getCurrentConfiguration(){return this.configuration.options}async renderSceneScreenshot(e,i){const t=this.scene.activeCamera;if(!t)throw new Error("Missing product camera, cannot render screenshot!");var n;(n=t).getScene().stopAnimation(n),n.animations=[];const a=t.alpha,r=t.beta,s=t.radius,o=i.latDeg*Math.PI/180,l=i.lonDeg*Math.PI/180;t.alpha=l,t.beta=o,t.radius=i.radius||t.radius;const c=await b.CreateScreenshotUsingRenderTargetAsync(this.engine,t,e,"image/png",2,!0);return t.alpha=a,t.beta=r,t.radius=s,c}orbitEnabled(){const e=this.configuration;if(!e)return!0;const i=e.camera.limits.min.alpha,t=e.camera.limits.max.alpha,n=e.camera.limits.min.beta,a=e.camera.limits.max.beta;if(void 0===i||void 0===t||void 0===n||void 0===a)return!0;const r=[n,a],s=[i,t].every((e=>e===i)),o=r.every((e=>e===n));return!s&&!o}fireResizeEvent(){this.getNumViewports()>0&&this.engine.resize()}onMaterialSelected(t){this.scene.meshes.forEach((n=>{"targetcube_t"!==n.name&&"backgroundShell"!==n.name&&(n.actionManager||(n.actionManager=new e(this.scene)),n.actionManager.registerAction(new i(e.OnPickDownTrigger,(e=>{if(e.meshUnderPointer){const i=e.meshUnderPointer.material;i&&t({id:i.id,name:i.name})}}))))}))}listMaterials(){const e=this.scene?.materials;return e?e.map((e=>({id:e.id,name:e.name}))):[]}setHighlights(e,i){0===e.length&&(this.highlightLayer?.dispose(),this.highlightLayer=void 0),this.highlightLayer||(this.highlightLayer=new r("highlights",this.scene,{isStroke:!0,blurVerticalSize:.85,blurHorizontalSize:.85}),this.highlightLayer.innerGlow=!0,this.highlightLayer.outerGlow=!1),this.highlightLayer.removeAllMeshes();const t=i?new h(i[0],i[1],i[2]).toLinearSpace():void 0;e.forEach((e=>{const i=this.scene.materials.find((i=>i.name===e.name&&i.id===e.id));i&&i.getBindedMeshes().forEach((e=>this.highlightLayer?.addMesh(e,t||h.FromHexString("#fcba03"))))}))}setRenderingPipelineConfig(e){this.renderingPipeline&&this.renderingPipeline.apply(e)}reattachControls(e,i=2){this.scene.detachControl(),this.engine.inputElement=e;const t=this.scene.activeCamera;if(t){t.attachControl(!0,!1,i);t.inputs.attached.pointers.multiTouchPanning=!1}this.scene.attachControl(!0,!0,!0)}getLoadListenerEvent(){const e=Array.from(this.loadProgress.values()).filter((e=>e<100)),i=e.reduce(((e,i)=>e+i),0)/e.length||0;return{loadValue:0===e.length?100:i,sceneInitialized:100===this.getSceneInitializationProgress()}}notifyLoadHandlers(){this.loadObservable.notifyObservers(this.getLoadListenerEvent())}async processQueuedLoadEvents(){await Promise.all(Array.from(this.modelReadyToLoadCallbacks.values()).map((e=>e(this.scene)))),this.modelReadyToLoadCallbacks.clear(),this.materialReadyToLoadCallbacks.forEach(((e,i)=>{e.forEach(((e,t)=>{this.applyMaterialVariant(i,t,e)}))})),this.materialReadyToLoadCallbacks.clear(),this.queuedModelAnimation&&(this.executeModelAnimation(this.queuedModelAnimation),this.queuedModelAnimation=void 0),this.queuedCameraAnimation&&(this.executeCameraAnimation(this.queuedCameraAnimation),this.queuedCameraAnimation=void 0)}}async function me(e,i,t){(await H(e,i,t)).addAllToScene()}export{j as ProductCameraRig,N as MaterialEffectMode,ue as SpiffCommerce3DPreviewService,me as createBaseModel,q as RenderingConfiguration,K as REFLECTION_PROBE_RESOLUTION};
2
2
  //# sourceMappingURL=module.js.map
package/dist/types.d.ts CHANGED
@@ -648,13 +648,12 @@ export interface VignettePipelineConfig {
648
648
  */
649
649
  cameraFov?: number;
650
650
  /**
651
- * X offset of the vignette center, in screen space.
651
+ * The offset of the vignette center, in screen space.
652
652
  */
653
- centerX?: number;
654
- /**
655
- * Y offset of the vignette center, in screen space.
656
- */
657
- centerY?: number;
653
+ center?: {
654
+ x: number;
655
+ y: number;
656
+ };
658
657
  /**
659
658
  * The color of the vignette, provided as an RGBA value.
660
659
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spiffcommerce/preview",
3
- "version": "2.1.31",
3
+ "version": "2.1.32",
4
4
  "description": "An internal implementation of the ThreeDPreviewService interface used by Spiff Commerce",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/main.js",