@spiffcommerce/preview 2.1.37 → 2.1.38
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 +1 -1
- package/dist/module.js +1 -1
- package/dist/types.d.ts +5 -4
- package/package.json +1 -1
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 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,"currentConfiguration",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.currentConfiguration}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.currentConfiguration={...this.currentConfiguration,...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?.renderingPipelineConfiguration&&this.renderingPipeline.apply(this.configuration.options.renderingPipelineConfiguration);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,_);
|
|
1
|
+
var e=require("@babylonjs/core/Actions/actionManager"),t=require("@babylonjs/core/Actions/directActions"),i=require("@babylonjs/core/Engines/engine"),n=require("@babylonjs/core/Engines/nullEngine"),a=require("@babylonjs/core/Layers/glowLayer"),r=require("@babylonjs/core/Layers/highlightLayer"),o=require("@babylonjs/core/Loading/sceneLoader"),s=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"),v=require("@babylonjs/core/Materials/Textures/mirrorTexture"),y=require("@babylonjs/core/Maths/math"),P=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"),L=require("@babylonjs/core/PostProcesses/depthOfFieldEffect");require("@babylonjs/core/Rendering/depthRendererSceneComponent");var O=require("@babylonjs/core/Misc/assetsManager");function E(e,t){return Object.keys(t).forEach((function(i){"default"===i||"__esModule"===i||e.hasOwnProperty(i)||Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[i]}})})),e}function R(e,t,i,n){Object.defineProperty(e,t,{get:i,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",(()=>he)),R(q,"createBaseModel",(()=>de));const j=new Map;async function k(e,t,i){return new Promise(((n,a)=>{const r=j.get(e);if(r&&r.scene.uid===t.uid)return n(r);o.SceneLoader.LoadAssetContainerAsync(e,void 0,t,i).then((t=>{j.set(e,t),n(t)})).catch(a)}))}function N(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,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 t=h.Color3.FromHexString(this.customOptions.backgroundColor);return new(0,h.Color4)(t.r,t.g,t.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,t=1)=>{const i=h.Color3.FromHexString(e);return new(0,h.Color4)(i.r,i.g,i.b,t).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 z={};R(z,"RenderingConfiguration",(()=>H)),R(z,"REFLECTION_PROBE_RESOLUTION",(()=>_)),R(z,"renderingPipelineDefaults",(()=>G));class H{static getDynamicTextureResolution(){return this.getIsMobile()||!H.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 _=128,G={antiAliasing:{msaaSamples:1,fxaaEnabled:!1},bloom:{enabled:!1,kernel:64,scale:.5,threshold:.9,weight:.15},chromaticAberration:{enabled:!1,aberrationAmount:30,direction:{x:0,y:0},radialIntensity:0},colorCurves:{enabled:!1},depthOfField:{enabled:!1,blurLevel:"Low",focalLength:50,focusDistance:2e3,fStop:1.4,lensSize:50},grain:{enabled:!1,animated:!1,intensity:30},misc:{contrast:1,exposure:1,toneMappingEnabled:!1,toneMappingType:"Standard"},sharpen:{enabled:!1,colorAmount:1,edgeAmount:.3},vignette:{enabled:!1,blendMode:"Multiply",cameraFov:.5,colorHex:"#000000ff",colorRgba:{r:0,g:0,b:0,a:1},stretch:0,weight:1}};function U(e,t,n){t.forEach((t=>{const a=t.getID(),r=t.getName(),o=H.getDynamicTextureResolution();e.materials.filter((e=>e.name===r)).forEach((s=>{const l=n.get(a);if(l)W(s,l),l.update(false);else{const l=function(e,t,n,a){const r=new(0,c.DynamicTexture)(e,{width:n,height:a},t,H.shouldMipMap(),f.Texture.TRILINEAR_SAMPLINGMODE,i.Engine.TEXTUREFORMAT_RGBA),o=r.getContext();o&&(o.fillStyle="#f5f5f5",o.fillRect(0,0,n,a),r.update());return r}(r,e,o.width,o.height);n.set(a,l),t.setStaticContext(l.getContext()),W(s,l),l.onLoadObservable.addOnce((()=>{l.update(false)}))}}))}))}function W(e,t){if(e instanceof s.PBRMaterial){const i=e,n=i.albedoTexture;n?(t.wrapU=n.wrapU,t.wrapV=n.wrapV):(t.wrapU=1,t.wrapV=1),i.albedoTexture=t}else{const i=e,n=i.diffuseTexture;n&&(t.wrapU=n.wrapU,t.wrapV=n.wrapV),i.diffuseTexture=t}}function K(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class Y{constructor(e){K(this,"name",void 0),K(this,"enabled",void 0),K(this,"loader",void 0),this.name="glbPostProcessor",this.enabled=!0,this.loader=e}onReady(){this.applyReflections(this.loader.babylonScene)}loadNodeAsync(e,t,i){return this.loader.loadNodeAsync(e,t,(function(e){t.extras&&Object.keys(t.extras).forEach((i=>{const n=t.extras[i];e.metadata[i]=n})),i(e)}))}loadMaterialPropertiesAsync(e,t,i){return this.enableMaterialExtrasIfRequired(t,i),this.loader.loadMaterialPropertiesAsync(e,t,i)}dispose(){}enableMaterialExtrasIfRequired(e,t){if(e.extras&&t instanceof s.PBRMaterial){if(e.extras.sheen){const i=t;i.sheen.isEnabled=!0,i.sheen.intensity=e.extras.sheen}if(e.extras.translucency){const i=t;i.subSurface.isTranslucencyEnabled=!0,i.subSurface.translucencyIntensity=e.extras.translucency,e.extras.translucencyR&&e.extras.translucencyG&&e.extras.translucencyB&&(i.subSurface.tintColor=new(0,y.Color3)(e.extras.translucencyR,e.extras.translucencyG,e.extras.translucencyB))}if(e.extras.refractionIOR){t.subSurface.indexOfRefraction=e.extras.refractionIOR}if(e.extras.useDepthPrePass){const e=t;e.needDepthPrePass=!0,e.forceIrradianceInFragment=!0}if(e.extras.useParallax){const i=t;i.useParallax=!0,i.useParallaxOcclusion=!0,i.parallaxScaleBias=e.extras.useParallax}}}applyReflections(e){function t(e){const t=[];return e.transformNodes.forEach((e=>{e.metadata&&e.metadata.reflective&&t.push(...e.getChildMeshes())})),e.meshes.forEach((e=>{e.metadata&&e.metadata.reflective&&!t.includes(e)&&t.push(e)})),t}e.meshes.forEach((i=>{const n=i.metadata;n&&(n.mirrorTexture&&function(i,n=1){const a=i.material;if(!a)return;const r=new(0,v.MirrorTexture)("mirror",H.getMirrorTextureResolution(),e,!0);r.renderList=t(e);const o=i.getVerticesData("normal");if(!o)throw new Error("Mirror attribute specified on: "+i.name+"But no normals exist to generate a mirror from!");i.computeWorldMatrix(!0);const s=i.getWorldMatrix(),l=y.Vector3.TransformNormal(new(0,y.Vector3)(o[0],o[1],o[2]),s).normalize(),c=y.Plane.FromPositionAndNormal(i.position,l.scale(-1));r.mirrorPlane=c,r.level=n,a.reflectionTexture=r}(i,n.mirrorTexture),n.reflectionProbe&&function(i){const n=i.material,a=new(0,P.ReflectionProbe)("probe-"+n.name,_,e);a.attachToMesh(i),a.renderList&&a.renderList.push(...t(e)),n.reflectionTexture=a.cubeTexture}(i))}))}}function Q(e,t,i,n){const a=e.animationGroups,r=e=>e.targetedAnimations.map((e=>e.animation.framePerSecond)).reduce(((e,t)=>e+t),0)/e.targetedAnimations.length||0;void 0===n||void 0===i||n!==i?a.forEach((e=>{e.stop();const a=r(e);e.start(t,1,n*a,i*a)})):a.forEach((e=>{e.stop();const i=r(e),a=n*i;e.start(t,1,a,a)}))}function Z(e){e.animationGroups.forEach((e=>{e.stop()}))}function X(e,t,i){var n,a,r;e.stopAnimation(t),t.animations=[],Math.abs(t.alpha)>2*Math.PI&&(t.alpha=(n=t.alpha,a=0,r=2*Math.PI,n<a?r-(a-n)%(r-a):a+(n-a)%(r-a)));const o=[],s=i.target,l=s?1:0;if(i.target&&Object.keys(i.target).length>0&&o.push(J("cameraTargetLerp","target",(new(0,d.Vector3)).copyFrom(t.target),new(0,d.Vector3)(i.target.x,i.target.y,i.target.z),w.Animation.ANIMATIONTYPE_VECTOR3,0)),o.push(J("cameraAlphaLerp","alpha",t.alpha,$(i.lonDeg),w.Animation.ANIMATIONTYPE_FLOAT,l)),o.push(J("cameraBetaLerp","beta",t.beta,$(i.latDeg),w.Animation.ANIMATIONTYPE_FLOAT,l)),void 0!==i.radius){const e=Math.max(.01,i.radius);o.push(J("cameraRadiusLerp","radius",t.radius,e,w.Animation.ANIMATIONTYPE_FLOAT,l))}t.animations.push(...o);const c=t.useAutoRotationBehavior;t.disableAutoRotationBehavior(),e.beginAnimation(t,0,s?120:60,!1,1,(()=>{t.animations=[],c&&t.enableAutoRotationBehavior()}))}function $(e){return e*Math.PI/180}function J(e,t,i,n,a,r=0,o=w.Animation.ANIMATIONLOOPMODE_CONSTANT){const s=new(0,x.QuadraticEase);s.setEasingMode(x.EasingFunction.EASINGMODE_EASEINOUT);const l=new(0,w.Animation)(e,t,60,a,o),c=[];return r>0&&c.push({frame:0,value:i}),c.push({frame:60*r,value:i}),c.push({frame:60*(r+1),value:n}),l.setKeys(c),l.setEasingFunction(s),l}class ee extends M.ArcRotateCamera{constructor(e,t,i,n,a,r,o,s){var l,c,h;super(e,t,i,n,a,r,s),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,o.camera.autoOrientation&&(this.alpha+=Math.PI),o&&(o.camera.limits.min.beta&&(this.lowerBetaLimit=o.camera.limits.min.beta),o.camera.limits.max.beta&&(this.upperBetaLimit=o.camera.limits.max.beta),o.camera.limits.min.alpha&&(this.lowerAlphaLimit=o.camera.limits.min.alpha),o.camera.limits.max.alpha&&(this.upperAlphaLimit=o.camera.limits.max.alpha),o.camera.limits.min.radius&&(this.lowerRadiusLimit=o.camera.limits.min.radius),o.camera.limits.max.radius&&(this.upperRadiusLimit=o.camera.limits.max.radius),o.camera.autoRotation.enabled&&this.enableAutoRotationBehavior(o.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 t=te(this._scene);return e.zoomOnBoundingInfo(t.min,t.max),this.wheelPrecision=100/this.radius,null===this.lowerRadiusLimit&&(this.lowerRadiusLimit=.1),this.lastFocus.copyFrom(this.target),e}rerunFramingBehavior(e){const t=this.getFramingBehavior();t.framingTime=800;const i=te(this._scene);t.zoomOnBoundingInfo(i.min,i.max,void 0,(()=>{e()})),t.framingTime=0}enableAutoRotationBehavior(e=5e3){this.useAutoRotationBehavior=!0;const t=this.getAutoRotationBehavior();t&&(t.idleRotationWaitTime=e)}disableAutoRotationBehavior(){this.useAutoRotationBehavior=!1}static create(e,t){e.activeCamera&&(e.activeCamera.dispose(),e.activeCamera=null);const i=te(e),n=i.max.subtract(i.min),a=i.min.add(n.scale(.5)),r=new ee("ProductCamera",-Math.PI/2,Math.PI/2,1.5*n.length(),a,e,t);return r.panningInertia=0,r.panningOriginTarget.copyFrom(a),r.onAfterCheckInputsObservable.add((()=>{r.panningSensibility=1e3/n.length()})),e.activeCamera=r,r}}function te(e){const t=e.meshes.filter((e=>e.name.toLowerCase().endsWith("_t")||e.name.toLowerCase().includes("_t_")));return e.getWorldExtends((e=>e.isVisible&&e.isEnabled()&&(0===t.length||t.includes(e))))}function ie(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class ne{constructor(e,t=!0,i=null){ie(this,"renderingPipeline",void 0),ie(this,"currentConfiguration",void 0),this.renderingPipeline=new(0,T.DefaultRenderingPipeline)("default",t,e,i?[i]:void 0,!1),this.renderingPipeline.prepare()}dispose(){this.renderingPipeline.dispose()}addCamera(e){this.renderingPipeline.addCamera(e)}removeCamera(e){this.renderingPipeline.removeCamera(e)}getConfiguration(){return this.currentConfiguration}setConfiguration(e){if(this.renderingPipeline.samples=e.antiAliasing?.msaaSamples??G.antiAliasing.msaaSamples,this.renderingPipeline.fxaaEnabled=e.antiAliasing?.fxaaEnabled??G.antiAliasing.fxaaEnabled,this.renderingPipeline.bloomEnabled=e.bloom?.enabled??G.bloom.enabled,this.renderingPipeline.bloomKernel=e.bloom?.kernel??G.bloom.kernel,this.renderingPipeline.bloomScale=e.bloom?.scale??G.bloom.scale,this.renderingPipeline.bloomThreshold=e.bloom?.threshold??G.bloom.threshold,this.renderingPipeline.bloomWeight=e.bloom?.weight??G.bloom.weight,this.renderingPipeline.chromaticAberrationEnabled=e.chromaticAberration?.enabled??G.chromaticAberration.enabled,this.renderingPipeline.chromaticAberration.aberrationAmount=e.chromaticAberration?.aberrationAmount??G.chromaticAberration.aberrationAmount,this.renderingPipeline.chromaticAberration.radialIntensity=e.chromaticAberration?.radialIntensity??G.chromaticAberration.radialIntensity,this.renderingPipeline.chromaticAberration.direction=e.chromaticAberration?.direction?new(0,d.Vector2)(e.chromaticAberration.direction.x,e.chromaticAberration.direction.y):new(0,d.Vector2)(G.chromaticAberration.direction.x,G.chromaticAberration.direction.y),this.renderingPipeline.imageProcessing.colorCurvesEnabled=e.colorCurves?.enabled??G.colorCurves.enabled,this.renderingPipeline.imageProcessing.colorCurves=e.colorCurves?this.updateColorCurve(e.colorCurves):new(0,C.ColorCurves),this.renderingPipeline.depthOfFieldEnabled=e.depthOfField?.enabled??G.depthOfField.enabled,e.depthOfField)switch(e.depthOfField.blurLevel??G.depthOfField.blurLevel){case"Low":this.renderingPipeline.depthOfFieldBlurLevel=L.DepthOfFieldEffectBlurLevel.Low;break;case"Medium":this.renderingPipeline.depthOfFieldBlurLevel=L.DepthOfFieldEffectBlurLevel.Medium;break;case"High":this.renderingPipeline.depthOfFieldBlurLevel=L.DepthOfFieldEffectBlurLevel.High}if(this.renderingPipeline.depthOfField.focalLength=e.depthOfField?.focalLength??G.depthOfField.focalLength,this.renderingPipeline.depthOfField.fStop=e.depthOfField?.fStop??G.depthOfField.fStop,this.renderingPipeline.depthOfField.focusDistance=e.depthOfField?.focusDistance??G.depthOfField.focusDistance,this.renderingPipeline.depthOfField.lensSize=e.depthOfField?.lensSize??G.depthOfField.lensSize,this.renderingPipeline.grainEnabled=e.grain?.enabled??G.grain.enabled,this.renderingPipeline.grain.animated=e.grain?.animated??G.grain.animated,this.renderingPipeline.grain.intensity=e.grain?.intensity??G.grain.intensity,this.renderingPipeline.imageProcessing.contrast=e.misc?.contrast??G.misc.contrast,this.renderingPipeline.imageProcessing.exposure=e.misc?.exposure??G.misc.exposure,this.renderingPipeline.imageProcessing.toneMappingEnabled=e.misc?.toneMappingEnabled??G.misc.toneMappingEnabled,this.renderingPipeline.imageProcessing.toneMappingEnabled)switch(e.misc.toneMappingType??G.misc.toneMappingType){case"Standard":this.renderingPipeline.imageProcessing.toneMappingType=A.ImageProcessingConfiguration.TONEMAPPING_STANDARD;break;case"ACES":this.renderingPipeline.imageProcessing.toneMappingType=A.ImageProcessingConfiguration.TONEMAPPING_ACES}if(this.renderingPipeline.sharpenEnabled=e.sharpen?.enabled??G.sharpen.enabled,this.renderingPipeline.sharpen.colorAmount=e.sharpen?.colorAmount??G.sharpen.colorAmount,this.renderingPipeline.sharpen.edgeAmount=e.sharpen?.edgeAmount??G.sharpen.edgeAmount,this.renderingPipeline.imageProcessing.vignetteEnabled=e.vignette?.enabled??G.vignette.enabled,e.vignette?.center?(this.renderingPipeline.imageProcessing.vignetteCenterX=e.vignette.center.x,this.renderingPipeline.imageProcessing.vignetteCenterY=e.vignette.center.y):(this.renderingPipeline.imageProcessing.vignetteCenterX=G.vignette.center.x,this.renderingPipeline.imageProcessing.vignetteCenterY=G.vignette.center.y),e.vignette)switch(e.vignette?.blendMode??G.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.vignetteColor=new(0,h.Color4)(G.vignette.colorRgba.r,G.vignette.colorRgba.g,G.vignette.colorRgba.b,G.vignette.colorRgba.a),this.renderingPipeline.imageProcessing.vignetteStretch=e.vignette?.stretch??G.vignette.stretch,this.renderingPipeline.imageProcessing.vignetteWeight=e.vignette?.weight??G.vignette.weight,this.renderingPipeline.prepare(),this.currentConfiguration=e}updateColorCurve(e){const t=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 ae={albedoTexture:"albedoMap",bumpTexture:"normalMap",ambientTexture:"ambientMap",emissiveTexture:"emissionMap",opacityTexture:"alphaMap",metallicTexture:"metallicMap",refractionTexture:"refractionMap"};function re(e,t,i,n){["albedoTexture","bumpTexture","ambientTexture","emissiveTexture","opacityTexture","metallicTexture","refractionTexture"].forEach((a=>{!function(e,t,i,n,a){const r=ae[e];if(!r)throw new Error("Unexpected texture name encountered.");const o=t[r]?.fileLink;o?n.addTextureTask(e,o,!1,!1):a&&i[e]&&(i[e]&&i[e].dispose(),i[e]=null,function(e,t){"opacityTexture"===e&&(t.useAlphaFromAlbedoTexture=!0);"metallicTexture"===e&&(t.useRoughnessFromMetallicTextureAlpha=!1,t.useRoughnessFromMetallicTextureGreen=!1,t.useMetallnessFromMetallicTextureBlue=!1);"refractionTexture"===e&&(t.subSurface.isRefractionEnabled=!1,t.subSurface.refractionIntensity=1)}(e,i))}(a,e,t,i,n)})),function(e,t){if(!e.clearCoat)return;e.clearCoat===B.RemoveWhenSelected?(t.clearCoat.isEnabled=!1,t.clearCoat.indexOfRefraction=1.5):e.clearCoat===B.ApplyWhenSelected&&(t.clearCoat.isEnabled=!0,t.clearCoat.indexOfRefraction=e.clearCoatIOR||t.clearCoat.indexOfRefraction)}(e,t)}function oe(e,t,i,n){"opacityTexture"===e&&(t.useAlphaFromAlbedoTexture=!1),"metallicTexture"===e&&(t.useRoughnessFromMetallicTextureAlpha=!1,t.useRoughnessFromMetallicTextureGreen=!0,t.useMetallnessFromMetallicTextureBlue=!0),"refractionTexture"===e&&(t.subSurface.isRefractionEnabled=!0,t.subSurface.refractionIntensity=i.refractionIntensity||1),t[e]=n}function se(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class le{constructor(){se(this,"materialVariantMap",new Map),se(this,"keysThatRemovedBaseModel",[]),se(this,"loadedContainerForKey",new Map)}async applyMaterial(e,t,i,n,a){return new Promise((r=>{const o=e.materials.filter((e=>e.name===t)),s=this.materialVariantMap.get(t);if(this.materialVariantMap.set(t,{...s,...i}),0===o.length)return void r(void 0);const l=new(0,O.AssetsManager)(e);l.useDefaultLoadingScreen=!1,o.forEach((e=>re(i,e,l,a))),l.onProgress=(e,t,i)=>{n&&n(e/t*100,100,i.name)},l.onFinish=e=>{e.forEach((e=>{const t=e;n&&n(100,100,e.name),o.forEach((n=>oe(e.name,n,i,t.texture)))})),r(void 0)},l.loadAsync()}))}async applyModel(e,t,i,n,a){if(n&&i&&!this.keysThatRemovedBaseModel.includes(t)&&this.keysThatRemovedBaseModel.push(t),!n){const i=this.keysThatRemovedBaseModel.includes(t);return this.loadedContainerForKey.get(t)?.removeAllFromScene(),e&&i&&await de(e.metadata.baseModel,e),Promise.resolve()}const r=await k(n,e,a);if(this.loadedContainerForKey.has(t)&&this.loadedContainerForKey.get(t)?.removeAllFromScene(),i){(await k(e.metadata.baseModel,e)).removeAllFromScene()}r.addAllToScene(),this.loadedContainerForKey.set(t,r);const o=[];this.materialVariantMap.forEach((async(t,i)=>{o.push(this.applyMaterial(e,i,t))})),await Promise.all(o)}}function ce(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}b.GLTF2.GLTFLoader.RegisterExtension("glbPostProcessor",(function(e){return new Y(e)})),o.SceneLoader.OnPluginActivatedObservable.add((e=>{if("gltf"===e.name){e.transparencyAsCoverage=!0}}));class he{constructor(e){ce(this,"engine",void 0),ce(this,"scene",void 0),ce(this,"configuration",void 0),ce(this,"loadProgress",new Map([["initialScene",0]])),ce(this,"materialReadyToLoadCallbacks",new Map),ce(this,"modelReadyToLoadCallbacks",new Map),ce(this,"queuedModelAnimation",void 0),ce(this,"queuedCameraAnimation",void 0),ce(this,"focusLostNotified",!1),ce(this,"loadObservable",new(0,g.Observable)),ce(this,"focusLostObservable",new(0,g.Observable)),ce(this,"dynamicTextures",new Map),ce(this,"highlightLayer",void 0),ce(this,"variantManager",new le),ce(this,"renderingPipeline",void 0);const t=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"}},t&&(t.getContext("webgl2")||t.getContext("webgl"));const a=console.log;console.log=()=>{};const r=t?new(0,i.Engine)(t,!0,{premultipliedAlpha:!1,preserveDrawingBuffer:!!e?.backgroundImage,audioEngine:!1,stencil:this.configuration.highlights.enabled,forceSRGBBufferSupportState:!0}):new(0,n.NullEngine);console.log=a,r.hideLoadingUI(),window.addEventListener("resize",this.fireResizeEvent.bind(this)),this.engine=r,this.scene=new(0,p.Scene)(r),this.renderingPipeline=new ne(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 t=e.height,i=e.width;this.engine.registerView(e),e.setAttribute("height",t.toString()),e.setAttribute("width",i.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(i,n){if(this.scene.clearColor=this.configuration.scene.clearColor,this.scene.metadata={baseModel:i},this.scene.environmentTexture=l.CubeTexture.CreateFromPrefilteredData(this.configuration.scene.environmentFile,this.scene),i){const e=100;await de(i,this.scene,(t=>{this.loadProgress.set("initialScene",t.loaded*e/t.total),this.notifyLoadHandlers()}))}this.configuration.highlights.enabled&&this.scene.meshes.forEach((i=>{"targetcube_t"!==i.name&&"backgroundShell"!==i.name&&(i.isPickable=!0,i.actionManager||(i.actionManager=new(0,e.ActionManager)(this.scene)),i.actionManager.registerAction(new(0,t.ExecuteCodeAction)(e.ActionManager.OnPointerOutTrigger,(()=>{this.setHighlights([])}))),i.actionManager.registerAction(new(0,t.ExecuteCodeAction)(e.ActionManager.OnPointerOverTrigger,(e=>{if(e.meshUnderPointer){const t=e.meshUnderPointer.material;t&&this.setHighlights([t])}}))))}));const r=ee.create(this.scene,this.configuration);this.renderingPipeline.addCamera(r),this.configuration.options?.renderingPipelineConfiguration&&this.renderingPipeline.setConfiguration(this.configuration.options.renderingPipelineConfiguration);const o=n?.getAll()||new Map;U(this.scene,o,this.dynamicTextures);if(this.scene.materials.some((e=>"emissiveTexture"in e&&null!==e.emissiveTexture))){new(0,a.GlowLayer)("GlowLayer",this.scene).intensity=.5}Z(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&&(o.forEach(((e,t)=>{const i=this.dynamicTextures.get(t);i&&e.getStaticContextDirty()&&i.isReady()&&(i.update(!1),e.setStaticContextDirty(!1))})),this.configuration.scene.transparentBackground&&this.engine.views.forEach((e=>{const t=this.engine.getRenderingCanvas();e.target.getContext("2d").clearRect(0,0,t.width,t.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()?Q(this.scene,e.loop,e.to,e.from):this.queuedModelAnimation=e}executeCameraAnimation(e){100===this.getSceneInitializationProgress()&&this.scene.activeCamera?X(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 t=this.scene.activeCamera;t&&(t.target=new(0,d.Vector3)(e.target.x,e.target.y,e.target.z),t.radius=e.radius,t.alpha=e.latDeg,t.beta=e.lonDeg)}}async applyMaterialVariant(e,t,i,n){if(100===this.getSceneInitializationProgress())await this.variantManager.applyMaterial(this.scene,e,i,((e,t,i)=>{this.loadProgress.set(`key_${i}`,e/t*100),this.notifyLoadHandlers()}),n);else if(this.materialReadyToLoadCallbacks.has(e)){this.materialReadyToLoadCallbacks.get(e)?.set(t,i)}else{this.materialReadyToLoadCallbacks.set(e,new Map);this.materialReadyToLoadCallbacks.get(e)?.set(t,i)}}async applyModelVariant(e,t,i){100===this.getSceneInitializationProgress()?(await this.variantManager.applyModel(this.scene,e,i||!1,t.model,(t=>{this.loadProgress.set(e,100*t.loaded/t.total),this.notifyLoadHandlers()})),this.scene.materials.forEach((e=>{if(e&&0===e.getBindedMeshes().length){const t=e instanceof s.PBRMaterial&&!(e.albedoTexture instanceof c.DynamicTexture);e.dispose(!1,t)}})),U(this.scene,t.contextService.getAll(),this.dynamicTextures),Z(this.scene)):this.modelReadyToLoadCallbacks.set(e,(async()=>{await this.applyModelVariant(e,t,i)}))}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 t=this.scene.activeCamera,i=this.configuration;t.rerunFramingBehavior((()=>{this.focusLostNotified=!1,i.camera.limits.min.radius&&(t.lowerRadiusLimit=i.camera.limits.min.radius),i.camera.limits.max.radius&&(t.upperRadiusLimit=i.camera.limits.max.radius),e()}))}))}setAutoRotation(e){const t=this.scene.activeCamera;this.configuration.camera.autoRotation.enabled&&t&&(e?t.enableAutoRotationBehavior(this.configuration.camera.autoRotation.idleTimeMs):t.disableAutoRotationBehavior())}getCurrentConfiguration(){return this.configuration.options}async renderSceneScreenshot(e,t){const i=this.scene.activeCamera;if(!i)throw new Error("Missing product camera, cannot render screenshot!");var n;(n=i).getScene().stopAnimation(n),n.animations=[];const a=i.alpha,r=i.beta,o=i.radius,s=t.latDeg*Math.PI/180,l=t.lonDeg*Math.PI/180;i.alpha=l,i.beta=s,i.radius=t.radius||i.radius;const c=await m.Tools.CreateScreenshotUsingRenderTargetAsync(this.engine,i,e,"image/png",2,!0);return i.alpha=a,i.beta=r,i.radius=o,c}orbitEnabled(){const e=this.configuration;if(!e)return!0;const t=e.camera.limits.min.alpha,i=e.camera.limits.max.alpha,n=e.camera.limits.min.beta,a=e.camera.limits.max.beta;if(void 0===t||void 0===i||void 0===n||void 0===a)return!0;const r=[n,a],o=[t,i].every((e=>e===t)),s=r.every((e=>e===n));return!o&&!s}fireResizeEvent(){this.getNumViewports()>0&&this.engine.resize()}onMaterialSelected(i){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,t.ExecuteCodeAction)(e.ActionManager.OnPickDownTrigger,(e=>{if(e.meshUnderPointer){const t=e.meshUnderPointer.material;t&&i({id:t.id,name:t.name})}}))))}))}listMaterials(){const e=this.scene?.materials;return e?e.map((e=>({id:e.id,name:e.name}))):[]}setHighlights(e,t){0===e.length&&(this.highlightLayer?.dispose(),this.highlightLayer=void 0),this.highlightLayer||(this.highlightLayer=new(0,r.HighlightLayer)("highlights",this.scene,{isStroke:!0,blurVerticalSize:.85,blurHorizontalSize:.85}),this.highlightLayer.innerGlow=!0,this.highlightLayer.outerGlow=!1),this.highlightLayer.removeAllMeshes();const i=t?new(0,h.Color3)(t[0],t[1],t[2]).toLinearSpace():void 0;e.forEach((e=>{const t=this.scene.materials.find((t=>t.name===e.name&&t.id===e.id));t&&t.getBindedMeshes().forEach((e=>this.highlightLayer?.addMesh(e,i||h.Color3.FromHexString("#fcba03"))))}))}setRenderingPipelineConfiguration(e){this.renderingPipeline&&this.renderingPipeline.setConfiguration(e)}reattachControls(e,t=2){this.scene.detachControl(),this.engine.inputElement=e;const i=this.scene.activeCamera;if(i){i.attachControl(!0,!1,t);i.inputs.attached.pointers.multiTouchPanning=!1}this.scene.attachControl(!0,!0,!0)}getLoadListenerEvent(){const e=Array.from(this.loadProgress.values()).filter((e=>e<100)),t=e.reduce(((e,t)=>e+t),0)/e.length||0;return{loadValue:0===e.length?100:t,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,t)=>{e.forEach(((e,i)=>{this.applyMaterialVariant(t,i,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 de(e,t,i){(await k(e,t,i)).addAllToScene()}E(module.exports,S),E(module.exports,q),E(module.exports,z);
|
|
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 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,"currentConfiguration",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.currentConfiguration}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.currentConfiguration={...this.currentConfiguration,...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?.renderingPipelineConfiguration&&this.renderingPipeline.apply(this.configuration.options.renderingPipelineConfiguration);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};
|
|
1
|
+
import{ActionManager as e}from"@babylonjs/core/Actions/actionManager";import{ExecuteCodeAction as t}from"@babylonjs/core/Actions/directActions";import{Engine as i}from"@babylonjs/core/Engines/engine";import{NullEngine as a}from"@babylonjs/core/Engines/nullEngine";import{GlowLayer as n}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 v}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 y}from"@babylonjs/core/Materials/Textures/texture";import{MirrorTexture as P}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,t,i,a){Object.defineProperty(e,t,{get:i,set:a,enumerable:!0,configurable:!0})}var D={};let k;var j;let N;var z;B(D,"ProductCameraRig",(()=>k)),B(D,"MaterialEffectMode",(()=>N)),(j=k||(k={}))[j.Orbit=0]="Orbit",j[j.Pan=1]="Pan",(z=N||(N={})).None="None",z.RemoveWhenSelected="RemoveWhenSelected",z.ApplyWhenSelected="ApplyWhenSelected";var H={};B(H,"SpiffCommerce3DPreviewService",(()=>me)),B(H,"createBaseModel",(()=>pe));const V=new Map;async function _(e,t,i){return new Promise(((a,n)=>{const r=V.get(e);if(r&&r.scene.uid===t.uid)return a(r);s.LoadAssetContainerAsync(e,void 0,t,i).then((t=>{V.set(e,t),a(t)})).catch(n)}))}function U(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,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 t=h.FromHexString(this.customOptions.backgroundColor);return new d(t.r,t.g,t.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,t=1)=>{const i=h.FromHexString(e);return new d(i.r,i.g,i.b,t).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)),B(W,"renderingPipelineDefaults",(()=>Y));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,Y={antiAliasing:{msaaSamples:1,fxaaEnabled:!1},bloom:{enabled:!1,kernel:64,scale:.5,threshold:.9,weight:.15},chromaticAberration:{enabled:!1,aberrationAmount:30,direction:{x:0,y:0},radialIntensity:0},colorCurves:{enabled:!1},depthOfField:{enabled:!1,blurLevel:"Low",focalLength:50,focusDistance:2e3,fStop:1.4,lensSize:50},grain:{enabled:!1,animated:!1,intensity:30},misc:{contrast:1,exposure:1,toneMappingEnabled:!1,toneMappingType:"Standard"},sharpen:{enabled:!1,colorAmount:1,edgeAmount:.3},vignette:{enabled:!1,blendMode:"Multiply",cameraFov:.5,colorHex:"#000000ff",colorRgba:{r:0,g:0,b:0,a:1},stretch:0,weight:1}};function Q(e,t,a){t.forEach((t=>{const n=t.getID(),r=t.getName(),s=q.getDynamicTextureResolution();e.materials.filter((e=>e.name===r)).forEach((o=>{const l=a.get(n);if(l)Z(o,l),l.update(false);else{const l=function(e,t,a,n){const r=new c(e,{width:a,height:n},t,q.shouldMipMap(),y.TRILINEAR_SAMPLINGMODE,i.TEXTUREFORMAT_RGBA),s=r.getContext();s&&(s.fillStyle="#f5f5f5",s.fillRect(0,0,a,n),r.update());return r}(r,e,s.width,s.height);a.set(n,l),t.setStaticContext(l.getContext()),Z(o,l),l.onLoadObservable.addOnce((()=>{l.update(false)}))}}))}))}function Z(e,t){if(e instanceof o){const i=e,a=i.albedoTexture;a?(t.wrapU=a.wrapU,t.wrapV=a.wrapV):(t.wrapU=1,t.wrapV=1),i.albedoTexture=t}else{const i=e,a=i.diffuseTexture;a&&(t.wrapU=a.wrapU,t.wrapV=a.wrapV),i.diffuseTexture=t}}function X(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class ${constructor(e){X(this,"name",void 0),X(this,"enabled",void 0),X(this,"loader",void 0),this.name="glbPostProcessor",this.enabled=!0,this.loader=e}onReady(){this.applyReflections(this.loader.babylonScene)}loadNodeAsync(e,t,i){return this.loader.loadNodeAsync(e,t,(function(e){t.extras&&Object.keys(t.extras).forEach((i=>{const a=t.extras[i];e.metadata[i]=a})),i(e)}))}loadMaterialPropertiesAsync(e,t,i){return this.enableMaterialExtrasIfRequired(t,i),this.loader.loadMaterialPropertiesAsync(e,t,i)}dispose(){}enableMaterialExtrasIfRequired(e,t){if(e.extras&&t instanceof o){if(e.extras.sheen){const i=t;i.sheen.isEnabled=!0,i.sheen.intensity=e.extras.sheen}if(e.extras.translucency){const i=t;i.subSurface.isTranslucencyEnabled=!0,i.subSurface.translucencyIntensity=e.extras.translucency,e.extras.translucencyR&&e.extras.translucencyG&&e.extras.translucencyB&&(i.subSurface.tintColor=new w(e.extras.translucencyR,e.extras.translucencyG,e.extras.translucencyB))}if(e.extras.refractionIOR){t.subSurface.indexOfRefraction=e.extras.refractionIOR}if(e.extras.useDepthPrePass){const e=t;e.needDepthPrePass=!0,e.forceIrradianceInFragment=!0}if(e.extras.useParallax){const i=t;i.useParallax=!0,i.useParallaxOcclusion=!0,i.parallaxScaleBias=e.extras.useParallax}}}applyReflections(e){function t(e){const t=[];return e.transformNodes.forEach((e=>{e.metadata&&e.metadata.reflective&&t.push(...e.getChildMeshes())})),e.meshes.forEach((e=>{e.metadata&&e.metadata.reflective&&!t.includes(e)&&t.push(e)})),t}e.meshes.forEach((i=>{const a=i.metadata;a&&(a.mirrorTexture&&function(i,a=1){const n=i.material;if(!n)return;const r=new P("mirror",q.getMirrorTextureResolution(),e,!0);r.renderList=t(e);const s=i.getVerticesData("normal");if(!s)throw new Error("Mirror attribute specified on: "+i.name+"But no normals exist to generate a mirror from!");i.computeWorldMatrix(!0);const o=i.getWorldMatrix(),l=x.TransformNormal(new x(s[0],s[1],s[2]),o).normalize(),c=M.FromPositionAndNormal(i.position,l.scale(-1));r.mirrorPlane=c,r.level=a,n.reflectionTexture=r}(i,a.mirrorTexture),a.reflectionProbe&&function(i){const a=i.material,n=new C("probe-"+a.name,K,e);n.attachToMesh(i),n.renderList&&n.renderList.push(...t(e)),a.reflectionTexture=n.cubeTexture}(i))}))}}function J(e,t,i,a){const n=e.animationGroups,r=e=>e.targetedAnimations.map((e=>e.animation.framePerSecond)).reduce(((e,t)=>e+t),0)/e.targetedAnimations.length||0;void 0===a||void 0===i||a!==i?n.forEach((e=>{e.stop();const n=r(e);e.start(t,1,a*n,i*n)})):n.forEach((e=>{e.stop();const i=r(e),n=a*i;e.start(t,1,n,n)}))}function ee(e){e.animationGroups.forEach((e=>{e.stop()}))}function te(e,t,i){var a,n,r;e.stopAnimation(t),t.animations=[],Math.abs(t.alpha)>2*Math.PI&&(t.alpha=(a=t.alpha,n=0,r=2*Math.PI,a<n?r-(n-a)%(r-n):n+(a-n)%(r-n)));const s=[],o=i.target,l=o?1:0;if(i.target&&Object.keys(i.target).length>0&&s.push(ae("cameraTargetLerp","target",(new g).copyFrom(t.target),new g(i.target.x,i.target.y,i.target.z),T.ANIMATIONTYPE_VECTOR3,0)),s.push(ae("cameraAlphaLerp","alpha",t.alpha,ie(i.lonDeg),T.ANIMATIONTYPE_FLOAT,l)),s.push(ae("cameraBetaLerp","beta",t.beta,ie(i.latDeg),T.ANIMATIONTYPE_FLOAT,l)),void 0!==i.radius){const e=Math.max(.01,i.radius);s.push(ae("cameraRadiusLerp","radius",t.radius,e,T.ANIMATIONTYPE_FLOAT,l))}t.animations.push(...s);const c=t.useAutoRotationBehavior;t.disableAutoRotationBehavior(),e.beginAnimation(t,0,o?120:60,!1,1,(()=>{t.animations=[],c&&t.enableAutoRotationBehavior()}))}function ie(e){return e*Math.PI/180}function ae(e,t,i,a,n,r=0,s=T.ANIMATIONLOOPMODE_CONSTANT){const o=new A;o.setEasingMode(L.EASINGMODE_EASEINOUT);const l=new T(e,t,60,n,s),c=[];return r>0&&c.push({frame:0,value:i}),c.push({frame:60*r,value:i}),c.push({frame:60*(r+1),value:a}),l.setKeys(c),l.setEasingFunction(o),l}class ne extends O{constructor(e,t,i,a,n,r,s,o){var l,c,h;super(e,t,i,a,n,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 t=re(this._scene);return e.zoomOnBoundingInfo(t.min,t.max),this.wheelPrecision=100/this.radius,null===this.lowerRadiusLimit&&(this.lowerRadiusLimit=.1),this.lastFocus.copyFrom(this.target),e}rerunFramingBehavior(e){const t=this.getFramingBehavior();t.framingTime=800;const i=re(this._scene);t.zoomOnBoundingInfo(i.min,i.max,void 0,(()=>{e()})),t.framingTime=0}enableAutoRotationBehavior(e=5e3){this.useAutoRotationBehavior=!0;const t=this.getAutoRotationBehavior();t&&(t.idleRotationWaitTime=e)}disableAutoRotationBehavior(){this.useAutoRotationBehavior=!1}static create(e,t){e.activeCamera&&(e.activeCamera.dispose(),e.activeCamera=null);const i=re(e),a=i.max.subtract(i.min),n=i.min.add(a.scale(.5)),r=new ne("ProductCamera",-Math.PI/2,Math.PI/2,1.5*a.length(),n,e,t);return r.panningInertia=0,r.panningOriginTarget.copyFrom(n),r.onAfterCheckInputsObservable.add((()=>{r.panningSensibility=1e3/a.length()})),e.activeCamera=r,r}}function re(e){const t=e.meshes.filter((e=>e.name.toLowerCase().endsWith("_t")||e.name.toLowerCase().includes("_t_")));return e.getWorldExtends((e=>e.isVisible&&e.isEnabled()&&(0===t.length||t.includes(e))))}function se(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class oe{constructor(e,t=!0,i=null){se(this,"renderingPipeline",void 0),se(this,"currentConfiguration",void 0),this.renderingPipeline=new S("default",t,e,i?[i]:void 0,!1),this.renderingPipeline.prepare()}dispose(){this.renderingPipeline.dispose()}addCamera(e){this.renderingPipeline.addCamera(e)}removeCamera(e){this.renderingPipeline.removeCamera(e)}getConfiguration(){return this.currentConfiguration}setConfiguration(e){if(this.renderingPipeline.samples=e.antiAliasing?.msaaSamples??Y.antiAliasing.msaaSamples,this.renderingPipeline.fxaaEnabled=e.antiAliasing?.fxaaEnabled??Y.antiAliasing.fxaaEnabled,this.renderingPipeline.bloomEnabled=e.bloom?.enabled??Y.bloom.enabled,this.renderingPipeline.bloomKernel=e.bloom?.kernel??Y.bloom.kernel,this.renderingPipeline.bloomScale=e.bloom?.scale??Y.bloom.scale,this.renderingPipeline.bloomThreshold=e.bloom?.threshold??Y.bloom.threshold,this.renderingPipeline.bloomWeight=e.bloom?.weight??Y.bloom.weight,this.renderingPipeline.chromaticAberrationEnabled=e.chromaticAberration?.enabled??Y.chromaticAberration.enabled,this.renderingPipeline.chromaticAberration.aberrationAmount=e.chromaticAberration?.aberrationAmount??Y.chromaticAberration.aberrationAmount,this.renderingPipeline.chromaticAberration.radialIntensity=e.chromaticAberration?.radialIntensity??Y.chromaticAberration.radialIntensity,this.renderingPipeline.chromaticAberration.direction=e.chromaticAberration?.direction?new u(e.chromaticAberration.direction.x,e.chromaticAberration.direction.y):new u(Y.chromaticAberration.direction.x,Y.chromaticAberration.direction.y),this.renderingPipeline.imageProcessing.colorCurvesEnabled=e.colorCurves?.enabled??Y.colorCurves.enabled,this.renderingPipeline.imageProcessing.colorCurves=e.colorCurves?this.updateColorCurve(e.colorCurves):new E,this.renderingPipeline.depthOfFieldEnabled=e.depthOfField?.enabled??Y.depthOfField.enabled,e.depthOfField)switch(e.depthOfField.blurLevel??Y.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??Y.depthOfField.focalLength,this.renderingPipeline.depthOfField.fStop=e.depthOfField?.fStop??Y.depthOfField.fStop,this.renderingPipeline.depthOfField.focusDistance=e.depthOfField?.focusDistance??Y.depthOfField.focusDistance,this.renderingPipeline.depthOfField.lensSize=e.depthOfField?.lensSize??Y.depthOfField.lensSize,this.renderingPipeline.grainEnabled=e.grain?.enabled??Y.grain.enabled,this.renderingPipeline.grain.animated=e.grain?.animated??Y.grain.animated,this.renderingPipeline.grain.intensity=e.grain?.intensity??Y.grain.intensity,this.renderingPipeline.imageProcessing.contrast=e.misc?.contrast??Y.misc.contrast,this.renderingPipeline.imageProcessing.exposure=e.misc?.exposure??Y.misc.exposure,this.renderingPipeline.imageProcessing.toneMappingEnabled=e.misc?.toneMappingEnabled??Y.misc.toneMappingEnabled,this.renderingPipeline.imageProcessing.toneMappingEnabled)switch(e.misc.toneMappingType??Y.misc.toneMappingType){case"Standard":this.renderingPipeline.imageProcessing.toneMappingType=R.TONEMAPPING_STANDARD;break;case"ACES":this.renderingPipeline.imageProcessing.toneMappingType=R.TONEMAPPING_ACES}if(this.renderingPipeline.sharpenEnabled=e.sharpen?.enabled??Y.sharpen.enabled,this.renderingPipeline.sharpen.colorAmount=e.sharpen?.colorAmount??Y.sharpen.colorAmount,this.renderingPipeline.sharpen.edgeAmount=e.sharpen?.edgeAmount??Y.sharpen.edgeAmount,this.renderingPipeline.imageProcessing.vignetteEnabled=e.vignette?.enabled??Y.vignette.enabled,e.vignette?.center?(this.renderingPipeline.imageProcessing.vignetteCenterX=e.vignette.center.x,this.renderingPipeline.imageProcessing.vignetteCenterY=e.vignette.center.y):(this.renderingPipeline.imageProcessing.vignetteCenterX=Y.vignette.center.x,this.renderingPipeline.imageProcessing.vignetteCenterY=Y.vignette.center.y),e.vignette)switch(e.vignette?.blendMode??Y.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.vignetteColor=new d(Y.vignette.colorRgba.r,Y.vignette.colorRgba.g,Y.vignette.colorRgba.b,Y.vignette.colorRgba.a),this.renderingPipeline.imageProcessing.vignetteStretch=e.vignette?.stretch??Y.vignette.stretch,this.renderingPipeline.imageProcessing.vignetteWeight=e.vignette?.weight??Y.vignette.weight,this.renderingPipeline.prepare(),this.currentConfiguration=e}updateColorCurve(e){const t=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 le={albedoTexture:"albedoMap",bumpTexture:"normalMap",ambientTexture:"ambientMap",emissiveTexture:"emissionMap",opacityTexture:"alphaMap",metallicTexture:"metallicMap",refractionTexture:"refractionMap"};function ce(e,t,i,a){["albedoTexture","bumpTexture","ambientTexture","emissiveTexture","opacityTexture","metallicTexture","refractionTexture"].forEach((n=>{!function(e,t,i,a,n){const r=le[e];if(!r)throw new Error("Unexpected texture name encountered.");const s=t[r]?.fileLink;s?a.addTextureTask(e,s,!1,!1):n&&i[e]&&(i[e]&&i[e].dispose(),i[e]=null,function(e,t){"opacityTexture"===e&&(t.useAlphaFromAlbedoTexture=!0);"metallicTexture"===e&&(t.useRoughnessFromMetallicTextureAlpha=!1,t.useRoughnessFromMetallicTextureGreen=!1,t.useMetallnessFromMetallicTextureBlue=!1);"refractionTexture"===e&&(t.subSurface.isRefractionEnabled=!1,t.subSurface.refractionIntensity=1)}(e,i))}(n,e,t,i,a)})),function(e,t){if(!e.clearCoat)return;e.clearCoat===N.RemoveWhenSelected?(t.clearCoat.isEnabled=!1,t.clearCoat.indexOfRefraction=1.5):e.clearCoat===N.ApplyWhenSelected&&(t.clearCoat.isEnabled=!0,t.clearCoat.indexOfRefraction=e.clearCoatIOR||t.clearCoat.indexOfRefraction)}(e,t)}function he(e,t,i,a){"opacityTexture"===e&&(t.useAlphaFromAlbedoTexture=!1),"metallicTexture"===e&&(t.useRoughnessFromMetallicTextureAlpha=!1,t.useRoughnessFromMetallicTextureGreen=!0,t.useMetallnessFromMetallicTextureBlue=!0),"refractionTexture"===e&&(t.subSurface.isRefractionEnabled=!0,t.subSurface.refractionIntensity=i.refractionIntensity||1),t[e]=a}function de(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class ge{constructor(){de(this,"materialVariantMap",new Map),de(this,"keysThatRemovedBaseModel",[]),de(this,"loadedContainerForKey",new Map)}async applyMaterial(e,t,i,a,n){return new Promise((r=>{const s=e.materials.filter((e=>e.name===t)),o=this.materialVariantMap.get(t);if(this.materialVariantMap.set(t,{...o,...i}),0===s.length)return void r(void 0);const l=new I(e);l.useDefaultLoadingScreen=!1,s.forEach((e=>ce(i,e,l,n))),l.onProgress=(e,t,i)=>{a&&a(e/t*100,100,i.name)},l.onFinish=e=>{e.forEach((e=>{const t=e;a&&a(100,100,e.name),s.forEach((a=>he(e.name,a,i,t.texture)))})),r(void 0)},l.loadAsync()}))}async applyModel(e,t,i,a,n){if(a&&i&&!this.keysThatRemovedBaseModel.includes(t)&&this.keysThatRemovedBaseModel.push(t),!a){const i=this.keysThatRemovedBaseModel.includes(t);return this.loadedContainerForKey.get(t)?.removeAllFromScene(),e&&i&&await pe(e.metadata.baseModel,e),Promise.resolve()}const r=await _(a,e,n);if(this.loadedContainerForKey.has(t)&&this.loadedContainerForKey.get(t)?.removeAllFromScene(),i){(await _(e.metadata.baseModel,e)).removeAllFromScene()}r.addAllToScene(),this.loadedContainerForKey.set(t,r);const s=[];this.materialVariantMap.forEach((async(t,i)=>{s.push(this.applyMaterial(e,i,t))})),await Promise.all(s)}}function ue(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}v.GLTFLoader.RegisterExtension("glbPostProcessor",(function(e){return new $(e)})),s.OnPluginActivatedObservable.add((e=>{if("gltf"===e.name){e.transparencyAsCoverage=!0}}));class me{constructor(e){ue(this,"engine",void 0),ue(this,"scene",void 0),ue(this,"configuration",void 0),ue(this,"loadProgress",new Map([["initialScene",0]])),ue(this,"materialReadyToLoadCallbacks",new Map),ue(this,"modelReadyToLoadCallbacks",new Map),ue(this,"queuedModelAnimation",void 0),ue(this,"queuedCameraAnimation",void 0),ue(this,"focusLostNotified",!1),ue(this,"loadObservable",new p),ue(this,"focusLostObservable",new p),ue(this,"dynamicTextures",new Map),ue(this,"highlightLayer",void 0),ue(this,"variantManager",new ge),ue(this,"renderingPipeline",void 0);const t=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"}},t&&(t.getContext("webgl2")||t.getContext("webgl"));const n=console.log;console.log=()=>{};const r=t?new i(t,!0,{premultipliedAlpha:!1,preserveDrawingBuffer:!!e?.backgroundImage,audioEngine:!1,stencil:this.configuration.highlights.enabled,forceSRGBBufferSupportState:!0}):new a;console.log=n,r.hideLoadingUI(),window.addEventListener("resize",this.fireResizeEvent.bind(this)),this.engine=r,this.scene=new f(r),this.renderingPipeline=new oe(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 t=e.height,i=e.width;this.engine.registerView(e),e.setAttribute("height",t.toString()),e.setAttribute("width",i.toString()),this.orbitEnabled()||this.setCameraState(k.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(i,a){if(this.scene.clearColor=this.configuration.scene.clearColor,this.scene.metadata={baseModel:i},this.scene.environmentTexture=l.CreateFromPrefilteredData(this.configuration.scene.environmentFile,this.scene),i){const e=100;await pe(i,this.scene,(t=>{this.loadProgress.set("initialScene",t.loaded*e/t.total),this.notifyLoadHandlers()}))}this.configuration.highlights.enabled&&this.scene.meshes.forEach((i=>{"targetcube_t"!==i.name&&"backgroundShell"!==i.name&&(i.isPickable=!0,i.actionManager||(i.actionManager=new e(this.scene)),i.actionManager.registerAction(new t(e.OnPointerOutTrigger,(()=>{this.setHighlights([])}))),i.actionManager.registerAction(new t(e.OnPointerOverTrigger,(e=>{if(e.meshUnderPointer){const t=e.meshUnderPointer.material;t&&this.setHighlights([t])}}))))}));const r=ne.create(this.scene,this.configuration);this.renderingPipeline.addCamera(r),this.configuration.options?.renderingPipelineConfiguration&&this.renderingPipeline.setConfiguration(this.configuration.options.renderingPipelineConfiguration);const s=a?.getAll()||new Map;Q(this.scene,s,this.dynamicTextures);if(this.scene.materials.some((e=>"emissiveTexture"in e&&null!==e.emissiveTexture))){new n("GlowLayer",this.scene).intensity=.5}ee(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,t)=>{const i=this.dynamicTextures.get(t);i&&e.getStaticContextDirty()&&i.isReady()&&(i.update(!1),e.setStaticContextDirty(!1))})),this.configuration.scene.transparentBackground&&this.engine.views.forEach((e=>{const t=this.engine.getRenderingCanvas();e.target.getContext("2d").clearRect(0,0,t.width,t.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()?J(this.scene,e.loop,e.to,e.from):this.queuedModelAnimation=e}executeCameraAnimation(e){100===this.getSceneInitializationProgress()&&this.scene.activeCamera?te(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 t=this.scene.activeCamera;t&&(t.target=new g(e.target.x,e.target.y,e.target.z),t.radius=e.radius,t.alpha=e.latDeg,t.beta=e.lonDeg)}}async applyMaterialVariant(e,t,i,a){if(100===this.getSceneInitializationProgress())await this.variantManager.applyMaterial(this.scene,e,i,((e,t,i)=>{this.loadProgress.set(`key_${i}`,e/t*100),this.notifyLoadHandlers()}),a);else if(this.materialReadyToLoadCallbacks.has(e)){this.materialReadyToLoadCallbacks.get(e)?.set(t,i)}else{this.materialReadyToLoadCallbacks.set(e,new Map);this.materialReadyToLoadCallbacks.get(e)?.set(t,i)}}async applyModelVariant(e,t,i){100===this.getSceneInitializationProgress()?(await this.variantManager.applyModel(this.scene,e,i||!1,t.model,(t=>{this.loadProgress.set(e,100*t.loaded/t.total),this.notifyLoadHandlers()})),this.scene.materials.forEach((e=>{if(e&&0===e.getBindedMeshes().length){const t=e instanceof o&&!(e.albedoTexture instanceof c);e.dispose(!1,t)}})),Q(this.scene,t.contextService.getAll(),this.dynamicTextures),ee(this.scene)):this.modelReadyToLoadCallbacks.set(e,(async()=>{await this.applyModelVariant(e,t,i)}))}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===k.Orbit?this.reattachControls(this.engine.views[0].target,2):this.reattachControls(this.engine.views[0].target,0)}animateToLastCameraFocus(){return new Promise((e=>{const t=this.scene.activeCamera,i=this.configuration;t.rerunFramingBehavior((()=>{this.focusLostNotified=!1,i.camera.limits.min.radius&&(t.lowerRadiusLimit=i.camera.limits.min.radius),i.camera.limits.max.radius&&(t.upperRadiusLimit=i.camera.limits.max.radius),e()}))}))}setAutoRotation(e){const t=this.scene.activeCamera;this.configuration.camera.autoRotation.enabled&&t&&(e?t.enableAutoRotationBehavior(this.configuration.camera.autoRotation.idleTimeMs):t.disableAutoRotationBehavior())}getCurrentConfiguration(){return this.configuration.options}async renderSceneScreenshot(e,t){const i=this.scene.activeCamera;if(!i)throw new Error("Missing product camera, cannot render screenshot!");var a;(a=i).getScene().stopAnimation(a),a.animations=[];const n=i.alpha,r=i.beta,s=i.radius,o=t.latDeg*Math.PI/180,l=t.lonDeg*Math.PI/180;i.alpha=l,i.beta=o,i.radius=t.radius||i.radius;const c=await b.CreateScreenshotUsingRenderTargetAsync(this.engine,i,e,"image/png",2,!0);return i.alpha=n,i.beta=r,i.radius=s,c}orbitEnabled(){const e=this.configuration;if(!e)return!0;const t=e.camera.limits.min.alpha,i=e.camera.limits.max.alpha,a=e.camera.limits.min.beta,n=e.camera.limits.max.beta;if(void 0===t||void 0===i||void 0===a||void 0===n)return!0;const r=[a,n],s=[t,i].every((e=>e===t)),o=r.every((e=>e===a));return!s&&!o}fireResizeEvent(){this.getNumViewports()>0&&this.engine.resize()}onMaterialSelected(i){this.scene.meshes.forEach((a=>{"targetcube_t"!==a.name&&"backgroundShell"!==a.name&&(a.actionManager||(a.actionManager=new e(this.scene)),a.actionManager.registerAction(new t(e.OnPickDownTrigger,(e=>{if(e.meshUnderPointer){const t=e.meshUnderPointer.material;t&&i({id:t.id,name:t.name})}}))))}))}listMaterials(){const e=this.scene?.materials;return e?e.map((e=>({id:e.id,name:e.name}))):[]}setHighlights(e,t){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 i=t?new h(t[0],t[1],t[2]).toLinearSpace():void 0;e.forEach((e=>{const t=this.scene.materials.find((t=>t.name===e.name&&t.id===e.id));t&&t.getBindedMeshes().forEach((e=>this.highlightLayer?.addMesh(e,i||h.FromHexString("#fcba03"))))}))}setRenderingPipelineConfiguration(e){this.renderingPipeline&&this.renderingPipeline.setConfiguration(e)}reattachControls(e,t=2){this.scene.detachControl(),this.engine.inputElement=e;const i=this.scene.activeCamera;if(i){i.attachControl(!0,!1,t);i.inputs.attached.pointers.multiTouchPanning=!1}this.scene.attachControl(!0,!0,!0)}getLoadListenerEvent(){const e=Array.from(this.loadProgress.values()).filter((e=>e<100)),t=e.reduce(((e,t)=>e+t),0)/e.length||0;return{loadValue:0===e.length?100:t,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,t)=>{e.forEach(((e,i)=>{this.applyMaterialVariant(t,i,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 pe(e,t,i){(await _(e,t,i)).addAllToScene()}export{k as ProductCameraRig,N as MaterialEffectMode,me as SpiffCommerce3DPreviewService,pe as createBaseModel,q as RenderingConfiguration,K as REFLECTION_PROBE_RESOLUTION,Y as renderingPipelineDefaults};
|
|
2
2
|
//# sourceMappingURL=module.js.map
|
package/dist/types.d.ts
CHANGED
|
@@ -168,10 +168,10 @@ export type ThreeDPreviewService = {
|
|
|
168
168
|
*/
|
|
169
169
|
setHighlights(materials: readonly MaterialHandle[], color?: readonly [number, number, number]): void;
|
|
170
170
|
/**
|
|
171
|
-
* Sets the rendering pipeline configuration for the scene.
|
|
172
|
-
* @param
|
|
171
|
+
* Sets the rendering pipeline configuration for the scene. Overwrites any existing configuration.
|
|
172
|
+
* @param renderingPipelineConfiguration The configuration to apply. Empty values will be set to default.
|
|
173
173
|
*/
|
|
174
|
-
|
|
174
|
+
setRenderingPipelineConfiguration(renderingPipelineConfiguration: RenderingPipelineConfiguration): void;
|
|
175
175
|
};
|
|
176
176
|
/**
|
|
177
177
|
* Represents a service capable of managing and returning contexts that
|
|
@@ -712,6 +712,7 @@ export class RenderingConfiguration {
|
|
|
712
712
|
}
|
|
713
713
|
export const REFLECTION_PROBE_RESOLUTION = 128;
|
|
714
714
|
export type PowerOfTwoNumber = 128 | 256 | 512 | 1024 | 2048 | 4096 | 8192;
|
|
715
|
+
export const renderingPipelineDefaults: RenderingPipelineConfiguration;
|
|
715
716
|
/**
|
|
716
717
|
* An example implementation of the ThreeDPreviewService interface. The inclusion of 3D previews
|
|
717
718
|
* is designed to be optional, anyone can come along and implement their own 3D preview service or
|
|
@@ -747,7 +748,7 @@ export class SpiffCommerce3DPreviewService implements ThreeDPreviewService {
|
|
|
747
748
|
onMaterialSelected(cb: (material: MaterialHandle) => void): void;
|
|
748
749
|
listMaterials(): readonly MaterialHandle[];
|
|
749
750
|
setHighlights(materials: readonly MaterialHandle[], color?: readonly [number, number, number]): void;
|
|
750
|
-
|
|
751
|
+
setRenderingPipelineConfiguration(renderingPipelineConfiguration: RenderingPipelineConfiguration): void;
|
|
751
752
|
}
|
|
752
753
|
/**
|
|
753
754
|
* Adds a tags a base mesh to the scene.
|
package/package.json
CHANGED