@spiffcommerce/preview 3.0.0 → 3.1.0
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 +11 -3
- package/package.json +2 -2
package/dist/main.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("@babylonjs/core/Engines/engine"),t=require("@babylonjs/core/Engines/nullEngine"),i=require("@babylonjs/core/Layers/highlightLayer"),a=require("@babylonjs/core/Loading/sceneLoader"),r=require("@babylonjs/core/Materials/Textures/cubeTexture"),n=require("@babylonjs/core/Maths/math.color"),s=require("@babylonjs/core/Maths/math.vector"),o=require("@babylonjs/core/Meshes/Compression/dracoCompression"),l=require("@babylonjs/core/Misc/observable"),c=require("@babylonjs/core/Misc/tools"),h=require("@babylonjs/core/scene"),d=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 u=require("@babylonjs/core/Materials/PBR/pbrMaterial"),g=require("@babylonjs/core/Materials/Textures/mirrorTexture"),m=require("@babylonjs/core/Maths/math"),p=require("@babylonjs/core/Probes/reflectionProbe"),b=require("@babylonjs/core/Actions/actionManager"),f=require("@babylonjs/core/Actions/directActions"),v=require("@babylonjs/core/Layers/glowLayer"),y=require("@babylonjs/core/Meshes/transformNode"),P=require("@babylonjs/core/Materials/Textures/dynamicTexture"),M=require("@babylonjs/core/Materials/Textures/texture"),w=require("@babylonjs/core/Animations/animation"),C=require("@babylonjs/core/Animations/easing"),x=require("@babylonjs/core/Misc/assetsManager"),O=require("@babylonjs/core/Cameras/arcRotateCamera"),A=require("@babylonjs/core/Materials/colorCurves"),T=require("@babylonjs/core/Materials/imageProcessingConfiguration"),L=require("@babylonjs/core/PostProcesses/RenderPipeline"),R=require("@babylonjs/core/PostProcesses/depthOfFieldEffect");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 S(e,t,i,a){Object.defineProperty(e,t,{get:i,set:a,enumerable:!0,configurable:!0})}require("@babylonjs/core/Rendering/depthRendererSceneComponent");var I={};let F;var D;let k;var B;S(I,"ProductCameraRig",(()=>F)),S(I,"MaterialEffectMode",(()=>k)),(D=F||(F={}))[D.Orbit=0]="Orbit",D[D.Pan=1]="Pan",(B=k||(k={})).None="None",B.RemoveWhenSelected="RemoveWhenSelected",B.ApplyWhenSelected="ApplyWhenSelected";var V={};function z(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}S(V,"SpiffCommerce3DPreviewService",(()=>be));class q{constructor(e){z(this,"customOptions",void 0),z(this,"getSceneClearColor",(()=>{const e=this.customOptions?.transparentBackground||this.customOptions?.backgroundImage?0:1;if(this.customOptions&&this.customOptions?.transparentBackground||this.customOptions?.backgroundImage)return new(0,n.Color4)(0,0,0,e).toLinearSpace();if(this.customOptions&&this.customOptions.backgroundColor){const t=n.Color3.FromHexString(this.customOptions.backgroundColor);return new(0,n.Color4)(t.r,t.g,t.b,e).toLinearSpace()}return new(0,n.Color4)(.98,.98,.98,e).toLinearSpace()})),z(this,"highlightColorFromConfig",(()=>this.customOptions&&this.customOptions.highlightColor?this.hexToColor4(this.customOptions.highlightColor):new(0,n.Color4)(.98,.98,.98,1).toLinearSpace())),z(this,"hexToColor4",((e,t=1)=>{const i=n.Color3.FromHexString(e);return new(0,n.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 j={};S(j,"RenderingConfiguration",(()=>N)),S(j,"REFLECTION_PROBE_RESOLUTION",(()=>H)),S(j,"renderingPipelineDefaults",(()=>_));class N{static getDynamicTextureResolution(){return this.getIsMobile()||!N.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,_={antiAliasing:{samples:4,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,center:{x:0,y:0},colorHex:"#000000ff",colorRgba:{r:0,g:0,b:0,a:1},stretch:0,weight:1}};function G(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class U{constructor(e){G(this,"name",void 0),G(this,"enabled",void 0),G(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)}))}async loadMaterialPropertiesAsync(e,t,i){await this.loader.loadMaterialPropertiesAsync(e,t,i),this.enableMaterialExtrasIfRequired(t,i)}dispose(){}enableMaterialExtrasIfRequired(e,t){if(e.extras&&t instanceof u.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,m.Color3)(e.extras.translucencyR,e.extras.translucencyG,e.extras.translucencyB))}if(e.extras.refractionIOR){const i=t;i.subSurface.isRefractionEnabled=!0,i.subSurface.volumeIndexOfRefraction=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 r=i.material;if(!r)return;const n=new(0,g.MirrorTexture)("mirror",N.getMirrorTextureResolution(),e,!0);n.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=m.Vector3.TransformNormal(new(0,m.Vector3)(s[0],s[1],s[2]),o).normalize(),c=m.Plane.FromPositionAndNormal(i.position,l.scale(-1));n.mirrorPlane=c,n.level=a,r.reflectionTexture=n}(i,a.mirrorTexture),a.reflectionProbe&&function(i){const a=i.material,r=new(0,p.ReflectionProbe)("probe-"+a.name,H,e);r.attachToMesh(i),r.renderList&&r.renderList.push(...t(e)),a.reflectionTexture=r.cubeTexture}(i))}))}}const W=new Map;async function K(e,t,i){return new Promise(((r,n)=>{const s=W.get(e);if(s&&s.scene.uid===t.uid)return r(s);a.SceneLoader.LoadAssetContainerAsync(e,void 0,t,i).then((t=>{W.set(e,t),r(t)})).catch(n)}))}function Q(t,i,a,r,n=""){a.forEach((a=>{const s=a.getID(),o=a.getName(),l=N.getDynamicTextureResolution();t.filter((e=>e.name===n+o)).forEach((t=>{const n=r.get(s);if(n)Y(t,n),n.update(false);else{const n=function(t,i,a,r){const n=new(0,P.DynamicTexture)(t,{width:a,height:r},i,N.shouldMipMap(),M.Texture.TRILINEAR_SAMPLINGMODE,e.Engine.TEXTUREFORMAT_RGBA),s=n.getContext();s&&(s.fillStyle="#f5f5f5",s.fillRect(0,0,a,r),n.update());return n}(o,i,l.width,l.height);r.set(s,n),a.setStaticContext(n.getContext()),Y(t,n),n.onLoadObservable.addOnce((()=>{n.update(false)}))}}))}))}function Y(e,t){if(e instanceof u.PBRMaterial){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 Z(){const e=()=>Math.floor(65536*(1+Math.random())).toString(16).substring(1);return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()}function $(e,t,i,a){const 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?e.forEach((e=>{e.stop();const n=r(e);e.start(t,1,a*n,i*n)})):e.forEach((e=>{e.stop();const i=r(e),n=a*i;e.start(t,1,n,n)}))}function X(e){e.forEach((e=>{e.stop()}))}function J(e,t,i){var a,r,n;e.stopAnimation(t),t.animations=[],Math.abs(t.alpha)>2*Math.PI&&(t.alpha=(a=t.alpha,r=0,n=2*Math.PI,a<r?n-(r-a)%(n-r):r+(a-r)%(n-r)));const o=[],l=i.target,c=l?1:0;if(i.target&&Object.keys(i.target).length>0&&o.push(te("cameraTargetLerp","target",(new(0,s.Vector3)).copyFrom(t.target),new(0,s.Vector3)(i.target.x,i.target.y,i.target.z),w.Animation.ANIMATIONTYPE_VECTOR3,0)),o.push(te("cameraAlphaLerp","alpha",t.alpha,ee(i.lonDeg),w.Animation.ANIMATIONTYPE_FLOAT,c)),o.push(te("cameraBetaLerp","beta",t.beta,ee(i.latDeg),w.Animation.ANIMATIONTYPE_FLOAT,c)),void 0!==i.radius){const e=Math.max(.01,i.radius);o.push(te("cameraRadiusLerp","radius",t.radius,e,w.Animation.ANIMATIONTYPE_FLOAT,c))}t.animations.push(...o);const h=t.useAutoRotationBehavior;t.disableAutoRotationBehavior(),e.beginAnimation(t,0,l?120:60,!1,1,(()=>{t.animations=[],h&&t.enableAutoRotationBehavior()}))}function ee(e){return e*Math.PI/180}function te(e,t,i,a,r,n=0,s=w.Animation.ANIMATIONLOOPMODE_CONSTANT){const o=new(0,C.QuadraticEase);o.setEasingMode(C.EasingFunction.EASINGMODE_EASEINOUT);const l=new(0,w.Animation)(e,t,60,r,s),c=[];return n>0&&c.push({frame:0,value:i}),c.push({frame:60*n,value:i}),c.push({frame:60*(n+1),value:a}),l.setKeys(c),l.setEasingFunction(o),l}const ie={albedoTexture:"albedoMap",bumpTexture:"normalMap",ambientTexture:"ambientMap",emissiveTexture:"emissionMap",opacityTexture:"alphaMap",metallicTexture:"metallicMap",refractionTexture:"refractionMap"};function ae(e,t,i,a){["albedoTexture","bumpTexture","ambientTexture","emissiveTexture","opacityTexture","metallicTexture","refractionTexture"].forEach((r=>{!function(e,t,i,a,r){const n=ie[e];if(!n)throw new Error("Unexpected texture name encountered.");const s=t[n]?.fileLink;s?a.addTextureTask(e,s,!1,!1):r&&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))}(r,e,t,i,a)})),function(e,t){if(!e.clearCoat)return;e.clearCoat===k.RemoveWhenSelected?(t.clearCoat.isEnabled=!1,t.clearCoat.indexOfRefraction=1.5):e.clearCoat===k.ApplyWhenSelected&&(t.clearCoat.isEnabled=!0,t.clearCoat.indexOfRefraction=e.clearCoatIOR||t.clearCoat.indexOfRefraction)}(e,t)}function re(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 ne(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class se{constructor(e,t,i){ne(this,"materialVariantMap",new Map),ne(this,"keysThatRemovedBaseModel",[]),ne(this,"loadedContainerForKey",new Map),ne(this,"loadedMaterialsForKey",new Map),ne(this,"scene",void 0),ne(this,"renameClonedAsset",void 0),ne(this,"setBaseModelEnabled",void 0),this.scene=e,this.renameClonedAsset=t,this.setBaseModelEnabled=i}async applyMaterial(e,t,i,a){return new Promise((r=>{e=this.renameClonedAsset(e);const n=this.scene.materials.filter((t=>t.name===e)),s=this.materialVariantMap.get(e);if(this.materialVariantMap.set(e,{...s,...t}),0===n.length)return void r(void 0);const o=new(0,x.AssetsManager)(this.scene);o.useDefaultLoadingScreen=!1,n.forEach((e=>ae(t,e,o,a))),o.onProgress=(e,t,a)=>{i&&i(e/t*100,100,a.name)},o.onFinish=e=>{e.forEach((e=>{const a=e;i&&i(100,100,e.name),n.forEach((i=>re(e.name,i,t,a.texture)))})),r(void 0)},o.loadAsync()}))}async applyModel(e,t,i,a){if(i&&t&&!this.keysThatRemovedBaseModel.includes(e)&&this.keysThatRemovedBaseModel.push(e),!i)return this.keysThatRemovedBaseModel.includes(e)&&this.setBaseModelEnabled(!0),this.loadedContainerForKey.get(e)?.dispose(),this.loadedMaterialsForKey.delete(e),Promise.resolve(void 0);this.loadedContainerForKey.has(e)&&(this.loadedContainerForKey.get(e)?.dispose(),this.loadedMaterialsForKey.delete(e)),t&&this.setBaseModelEnabled(!1);const r=(await K(i,this.scene,a)).instantiateModelsToScene(this.renameClonedAsset,!0);this.loadedContainerForKey.set(e,r),this.loadedMaterialsForKey.set(e,oe(r));const n=[];return this.materialVariantMap.forEach((async(e,t)=>{n.push(this.applyMaterial(t,e))})),await Promise.all(n),r}getAllMaterials(){const e=[];return this.loadedMaterialsForKey.forEach((t=>{t.forEach((t=>{e.includes(t)||e.push(t)}))})),e}}function oe(e){const t=[];return e.rootNodes.forEach((e=>{e.getChildMeshes().forEach((e=>{e.material&&t.push(e.material),e.subMeshes&&e.subMeshes.forEach((e=>{const i=e.getMaterial(!1);i&&t.push(i)}))}))})),t}function le(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class ce{constructor(e){le(this,"id",void 0),le(this,"previewService",void 0),le(this,"scene",void 0),le(this,"variantManager",void 0),le(this,"materialSelectedObservable",new(0,l.Observable)),le(this,"materialDeselectedObservable",new(0,l.Observable)),le(this,"materialVariantObservable",new(0,l.Observable)),le(this,"modelVariantObservable",new(0,l.Observable)),le(this,"queuedModelAnimation",void 0),le(this,"materialReadyToLoadCallbacks",new Map),le(this,"modelReadyToLoadCallbacks",new Map),le(this,"dynamicTextures",new Map),le(this,"assetContainer",void 0),le(this,"canvasPanels",void 0),le(this,"contextService",void 0),le(this,"importPromise",void 0),le(this,"initialized",!1),le(this,"materials",[]),le(this,"modelInstance",void 0),le(this,"transformRoot",void 0);const{modelDetails:t,previewService:i,progressHandler:a,scene:r}=e;this.contextService=t.contextService,this.id=Z(),this.previewService=i,this.scene=r,this.variantManager=new se(r,this.renameClonedAsset.bind(this),this.setEnabled.bind(this)),this.previewService.registerInitializedListener((async()=>await this.processQueuedEvents()));this.importPromise=(async()=>{this.assetContainer=await K(t.model,r,a),this.initialized=!0,this.transformRoot=new(0,y.TransformNode)("root",this.scene),this.instantiate()})()}async applyMaterialVariant(e,t,i,a){if(100===this.previewService.getSceneInitializationProgress()&&this.initialized)await this.variantManager.applyMaterial(e,i,((e,t,i)=>{this.materialVariantObservable.notifyObservers({remainingCount:e,totalCount:t,taskName:i})}),a);else if(this.materialReadyToLoadCallbacks.has(e)){this.materialReadyToLoadCallbacks.get(e)?.set(t,this.applyMaterialVariant.bind(this,e,t,i,a))}else{this.materialReadyToLoadCallbacks.set(e,new Map);this.materialReadyToLoadCallbacks.get(e)?.set(t,this.applyMaterialVariant.bind(this,e,t,i,a))}}async applyModelVariant(e,t,i){if(100!==this.previewService.getSceneInitializationProgress()||!this.initialized)return void this.modelReadyToLoadCallbacks.set(e,this.applyModelVariant.bind(this,e,t,i));const a=await this.variantManager.applyModel(e,i,t?.model,(t=>{this.modelVariantObservable.notifyObservers({...t,key:e})}));this.modelInstance&&X(this.modelInstance.animationGroups),this.contextService||(this.contextService=t?.contextService),a&&this.configureModelInstance(a)}executeAnimation(e){100===this.previewService.getSceneInitializationProgress()?this.modelInstance&&$(this.modelInstance.animationGroups,e.loop,e.to,e.from):this.queuedModelAnimation=e}getId(){return this.id}listMaterials(){const e=this.scene?.materials.filter((e=>e.name.startsWith(this.id)));return e?e.map((e=>({id:e.id,name:e.name}))):[]}registerMaterialSelectedCallback(e){this.materialSelectedObservable.add(e)}unregisterMaterialSelectedCallback(e){this.materialSelectedObservable.removeCallback(e)}registerMaterialDeselectedCallback(e){this.materialDeselectedObservable.add(e)}unregisterMaterialDeselectedCallback(e){this.materialDeselectedObservable.removeCallback(e)}get position(){return this.transformRoot.position}set position(e){this.transformRoot.position=new(0,s.Vector3)(e.x,e.y,e.z)}get rotation(){return this.transformRoot.rotation}set rotation(e){this.transformRoot.rotation=new(0,s.Vector3)(e.x,e.y,e.z)}get scale(){return this.transformRoot.scaling}set scale(e){this.transformRoot.scaling=new(0,s.Vector3)(e.x,e.y,e.z)}attachPickingHandler(e){e.rootNodes.forEach((e=>{e.getChildMeshes(!1).forEach((e=>{"targetcube_t"!==e.name&&"backgroundShell"!==e.name&&(e.isPickable=!0,e.actionManager||(e.actionManager=new(0,b.ActionManager)(this.scene)),e.actionManager||(e.actionManager=new(0,b.ActionManager)(this.scene)),e.actionManager.registerAction(new(0,f.ExecuteCodeAction)(b.ActionManager.OnPointerOutTrigger,(()=>{e.material&&this.materialDeselectedObservable.notifyObservers({id:e.material.id,name:e.material.name})}))),e.actionManager.registerAction(new(0,f.ExecuteCodeAction)(b.ActionManager.OnPickDownTrigger,(t=>{t.meshUnderPointer&&e.material&&this.materialSelectedObservable.notifyObservers({id:e.material.id,name:e.material.name})}))))}))}))}getImportPromise(){return this.importPromise}getQueuedMaterialVariantCount(){return this.materialReadyToLoadCallbacks.size}getQueuedModelVariantCount(){return this.modelReadyToLoadCallbacks.size}configureModelInstance(e){const t=this.transformRoot.position,i=this.transformRoot.rotation,a=this.transformRoot.scaling;this.transformRoot.position=s.Vector3.Zero(),this.transformRoot.rotation=s.Vector3.Zero(),this.transformRoot.scaling=s.Vector3.One(),e.rootNodes.forEach((e=>{e.parent=this.transformRoot})),this.transformRoot.position=t,this.transformRoot.rotation=i,this.transformRoot.scaling=a,this.canvasPanels=this.contextService?.getAll()||new Map,Q(this.materials.concat(this.variantManager.getAllMaterials()),this.scene,this.canvasPanels,this.dynamicTextures,`${this.id}_`),this.attachPickingHandler(e)}dispose(){this.modelInstance.dispose(),this.modelInstance=void 0}instantiate(){this.modelInstance=this.assetContainer.instantiateModelsToScene(this.renameClonedAsset.bind(this),!0),this.materials=oe(this.modelInstance),this.configureModelInstance(this.modelInstance);if(this.materials.some((e=>"emissiveTexture"in e&&null!==e.emissiveTexture))){new(0,v.GlowLayer)("GlowLayer",this.scene).intensity=.5}this.processQueuedEvents()}renameClonedAsset(e){return`${this.id}_${e}`}setEnabled(e){e&&!this.modelInstance?this.instantiate():!e&&this.modelInstance&&this.dispose()}updateDynamicTextures(){this.canvasPanels?.forEach(((e,t)=>{const i=this.dynamicTextures.get(t);i&&e.getStaticContextDirty()&&i.isReady()&&(i.update(!1),e.setStaticContextDirty(!1))}))}registerMaterialVariantListener(e){this.materialVariantObservable.add(e)}unregisterMaterialVariantListener(e){this.materialVariantObservable.removeCallback(e)}registerModelVariantListener(e){this.modelVariantObservable.add(e)}unregisterModelVariantListener(e){this.modelVariantObservable.removeCallback(e)}async processQueuedEvents(){100===this.previewService.getSceneInitializationProgress()&&(await Promise.all(Array.from(this.materialReadyToLoadCallbacks.values()).map((e=>Array.from(e.values()).map((e=>e()))))),this.materialReadyToLoadCallbacks.clear(),await Promise.all(Array.from(this.modelReadyToLoadCallbacks.values()).map((e=>e()))),this.modelReadyToLoadCallbacks.clear(),this.queuedModelAnimation&&(this.executeAnimation(this.queuedModelAnimation),this.queuedModelAnimation=void 0))}}function he(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class de extends O.ArcRotateCamera{constructor(e,t,i,a,r,n,o,l){super(e,t,i,a,r,n,l),he(this,"lastFocus",new(0,s.Vector3)(0,0,0)),he(this,"panDenominator",1),this.minZ=.01,this.setRadius(this.radius),this.enableFramingBehavior(),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=ue(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,t){const i=this.getFramingBehavior();i.framingTime=t||800;const a=ue(this._scene),r=a.max.subtract(a.min),n=a.min.add(r.scale(.5));this.setRadius(1.5*r.length()),this.wheelPrecision=100/this.radius,this.panningInertia=0,this.panningOriginTarget.copyFrom(n),this.panDenominator=r.length(),i.zoomOnBoundingInfo(a.min,a.max,void 0,(()=>{e&&e()})),i.framingTime=0}enableAutoRotationBehavior(e=5e3){this.useAutoRotationBehavior=!0;const t=this.getAutoRotationBehavior();t&&(t.idleRotationWaitTime=e)}disableAutoRotationBehavior(){this.useAutoRotationBehavior=!1}setRadius(e){this.radius=e,this.maxZ=1e3*this.radius,this.lowerRadiusLimit=.01*this.radius,this.upperRadiusLimit=1.5*this.radius,this.wheelPrecision=100/this.radius,this.pinchPrecision=300/this.radius}static create(e,t,i){const a=ue(e),r=a.max.subtract(a.min),n=a.min.add(r.scale(.5)),s=new de("ProductCamera",-Math.PI/2,Math.PI/2,1.5*r.length(),n,e,t);return s.panningInertia=0,s.panningOriginTarget.copyFrom(n),s.panDenominator=r.length(),s.onAfterCheckInputsObservable.add((()=>{s.panningSensibility=1e3/s.panDenominator})),i&&(e.activeCamera=s),s}}function ue(e){if(0===e.meshes.length)return{min:new(0,s.Vector3)(-1,-1,-1),max:new(0,s.Vector3)(1,1,1)};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 ge(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class me{constructor(e,t=!0,i=null){ge(this,"renderingPipeline",void 0),ge(this,"currentConfiguration",void 0),this.renderingPipeline=new(0,L.DefaultRenderingPipeline)("default",t,e,i?[i]:void 0,!1),this.renderingPipeline.isSupported&&this.renderingPipeline.prepare()}dispose(){this.renderingPipeline.dispose()}addCamera(e){this.renderingPipeline.isSupported&&this.renderingPipeline.addCamera(e)}removeCamera(e){this.renderingPipeline.isSupported&&this.renderingPipeline.removeCamera(e)}getConfiguration(){return this.currentConfiguration}setConfiguration(e){if(this.renderingPipeline.isSupported){if(this.renderingPipeline.samples=e.antiAliasing?.samples??_.antiAliasing.samples,this.renderingPipeline.fxaaEnabled=e.antiAliasing?.fxaaEnabled??_.antiAliasing.fxaaEnabled,this.renderingPipeline.bloomEnabled=e.bloom?.enabled??_.bloom.enabled,this.renderingPipeline.bloomKernel=e.bloom?.kernel??_.bloom.kernel,this.renderingPipeline.bloomScale=e.bloom?.scale??_.bloom.scale,this.renderingPipeline.bloomThreshold=e.bloom?.threshold??_.bloom.threshold,this.renderingPipeline.bloomWeight=e.bloom?.weight??_.bloom.weight,this.renderingPipeline.chromaticAberrationEnabled=e.chromaticAberration?.enabled??_.chromaticAberration.enabled,this.renderingPipeline.chromaticAberration.aberrationAmount=e.chromaticAberration?.aberrationAmount??_.chromaticAberration.aberrationAmount,this.renderingPipeline.chromaticAberration.radialIntensity=e.chromaticAberration?.radialIntensity??_.chromaticAberration.radialIntensity,this.renderingPipeline.chromaticAberration.direction=e.chromaticAberration?.direction?new(0,s.Vector2)(e.chromaticAberration.direction.x,e.chromaticAberration.direction.y):new(0,s.Vector2)(_.chromaticAberration.direction.x,_.chromaticAberration.direction.y),this.renderingPipeline.imageProcessing.colorCurvesEnabled=e.colorCurves?.enabled??_.colorCurves.enabled,this.renderingPipeline.imageProcessing.colorCurves=e.colorCurves?this.updateColorCurve(e.colorCurves):new(0,A.ColorCurves),this.renderingPipeline.depthOfFieldEnabled=e.depthOfField?.enabled??_.depthOfField.enabled,e.depthOfField)switch(e.depthOfField.blurLevel??_.depthOfField.blurLevel){case"Low":this.renderingPipeline.depthOfFieldBlurLevel=R.DepthOfFieldEffectBlurLevel.Low;break;case"Medium":this.renderingPipeline.depthOfFieldBlurLevel=R.DepthOfFieldEffectBlurLevel.Medium;break;case"High":this.renderingPipeline.depthOfFieldBlurLevel=R.DepthOfFieldEffectBlurLevel.High}if(this.renderingPipeline.depthOfField.focalLength=e.depthOfField?.focalLength??_.depthOfField.focalLength,this.renderingPipeline.depthOfField.fStop=e.depthOfField?.fStop??_.depthOfField.fStop,this.renderingPipeline.depthOfField.focusDistance=e.depthOfField?.focusDistance??_.depthOfField.focusDistance,this.renderingPipeline.depthOfField.lensSize=e.depthOfField?.lensSize??_.depthOfField.lensSize,this.renderingPipeline.grainEnabled=e.grain?.enabled??_.grain.enabled,this.renderingPipeline.grain.animated=e.grain?.animated??_.grain.animated,this.renderingPipeline.grain.intensity=e.grain?.intensity??_.grain.intensity,this.renderingPipeline.imageProcessing.contrast=e.misc?.contrast??_.misc.contrast,this.renderingPipeline.imageProcessing.exposure=e.misc?.exposure??_.misc.exposure,this.renderingPipeline.imageProcessing.toneMappingEnabled=e.misc?.toneMappingEnabled??_.misc.toneMappingEnabled,this.renderingPipeline.imageProcessing.toneMappingEnabled)switch(e.misc.toneMappingType??_.misc.toneMappingType){case"Standard":this.renderingPipeline.imageProcessing.toneMappingType=T.ImageProcessingConfiguration.TONEMAPPING_STANDARD;break;case"ACES":this.renderingPipeline.imageProcessing.toneMappingType=T.ImageProcessingConfiguration.TONEMAPPING_ACES}if(this.renderingPipeline.sharpenEnabled=e.sharpen?.enabled??_.sharpen.enabled,this.renderingPipeline.sharpen.colorAmount=e.sharpen?.colorAmount??_.sharpen.colorAmount,this.renderingPipeline.sharpen.edgeAmount=e.sharpen?.edgeAmount??_.sharpen.edgeAmount,this.renderingPipeline.imageProcessing.vignetteEnabled=e.vignette?.enabled??_.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=_.vignette.center.x,this.renderingPipeline.imageProcessing.vignetteCenterY=_.vignette.center.y),e.vignette)switch(e.vignette?.blendMode??_.vignette.blendMode){case"Multiply":this.renderingPipeline.imageProcessing.vignetteBlendMode=T.ImageProcessingConfiguration.VIGNETTEMODE_MULTIPLY;break;case"Opaque":this.renderingPipeline.imageProcessing.vignetteBlendMode=T.ImageProcessingConfiguration.VIGNETTEMODE_OPAQUE}e.vignette?.colorRgba?this.renderingPipeline.imageProcessing.vignetteColor=new(0,n.Color4)(e.vignette.colorRgba.r,e.vignette.colorRgba.g,e.vignette.colorRgba.b,e.vignette.colorRgba.a):e.vignette?.colorHex?this.renderingPipeline.imageProcessing.vignetteColor=n.Color4.FromHexString(e.vignette.colorHex):this.renderingPipeline.imageProcessing.vignetteColor=new(0,n.Color4)(_.vignette.colorRgba.r,_.vignette.colorRgba.g,_.vignette.colorRgba.b,_.vignette.colorRgba.a),this.renderingPipeline.imageProcessing.vignetteStretch=e.vignette?.stretch??_.vignette.stretch,this.renderingPipeline.imageProcessing.vignetteWeight=e.vignette?.weight??_.vignette.weight,this.renderingPipeline.prepare(),this.currentConfiguration=e}}updateColorCurve(e){const t=new(0,A.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}}function pe(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}d.GLTF2.GLTFLoader.RegisterExtension("glbPostProcessor",(function(e){return new U(e)})),a.SceneLoader.OnPluginActivatedObservable.add((e=>{if("gltf"===e.name){e.transparencyAsCoverage=!0}}));class be{constructor(i){pe(this,"camera",void 0),pe(this,"configuration",void 0),pe(this,"engine",void 0),pe(this,"scene",void 0),pe(this,"loadProgress",new Map([["initialScene",0]])),pe(this,"queuedCameraAnimation",void 0),pe(this,"focusLostNotified",!1),pe(this,"loadObservable",new(0,l.Observable)),pe(this,"focusLostObservable",new(0,l.Observable)),pe(this,"initializedCallbacks",[]),pe(this,"isInitialized",!1),pe(this,"highlightLayer",void 0),pe(this,"renderingPipeline",void 0),pe(this,"modelContainers",new Map),pe(this,"plugins",[]);const a=i?.noRender?void 0:document.createElement("canvas");this.configuration=new q(i);o.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"}},a&&(a.getContext("webgl2")||a.getContext("webgl"));const r=console.log;console.log=()=>{};const n=a?new(0,e.Engine)(a,!0,{adaptToDeviceRatio:!0,limitDeviceRatio:2,premultipliedAlpha:!1,preserveDrawingBuffer:!!i?.backgroundImage,audioEngine:!1,stencil:this.configuration.highlights.enabled,forceSRGBBufferSupportState:!0}):new(0,t.NullEngine);console.log=r,n.hideLoadingUI(),window.addEventListener("resize",this.fireResizeEvent.bind(this)),this.engine=n,this.scene=new(0,h.Scene)(n),this.camera=de.create(this.scene,this.configuration),this.renderingPipeline=new me(this.scene,!0),this.renderingPipeline.addCamera(this.camera),this.scene.imageProcessingConfiguration.exposure=this.configuration.lighting.exposure,this.scene.imageProcessingConfiguration.contrast=this.configuration.lighting.contrast}getEngineContext(){return{engine:this.engine,scene:this.scene,camera:this.camera}}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)}registerInitializedListener(e){this.isInitialized||!this.isInitialized&&this.initializedCallbacks.push(e)}unregisterInitializedListener(e){if(this.isInitialized)return;const t=this.initializedCallbacks.indexOf(e);t>-1&&this.initializedCallbacks.splice(t,1)}getIsInitialized(){return this.isInitialized}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.plugins.forEach((e=>e.dispose(!0))),this.renderingPipeline.dispose(),this.engine&&this.engine.dispose(),window.removeEventListener("resize",this.fireResizeEvent)}getSceneInitializationProgress(){return this.loadProgress.get("initialScene")}async initialize(e){let t;if(this.scene.clearColor=this.configuration.scene.clearColor,this.scene.environmentTexture=r.CubeTexture.CreateFromPrefilteredData(this.configuration.scene.environmentFile,this.scene),e){const i=100;t=await this.loadModel(e,(e=>{this.loadProgress.set("initialScene",e.loaded*i/e.total),this.notifyLoadHandlers()}))}return this.loadProgress.set("initialScene",100),this.notifyLoadHandlers(),this.scene.activeCamera=this.camera,this.camera.rerunFramingBehavior(void 0,1),this.configuration.options?.renderingPipelineConfiguration&&this.renderingPipeline.setConfiguration(this.configuration.options.renderingPipelineConfiguration),X(this.scene.animationGroups),this.engine.views?.length>=1&&this.reattachControls(this.engine.views[this.engine.views.length-1].target),await this.processQueuedLoadEvents(),await Promise.all(this.initializedCallbacks.map((e=>e()))),this.initializedCallbacks=[],this.isInitialized=!0,this.engine.runRenderLoop((()=>{this.engine.views&&(this.modelContainers.forEach((e=>{e.updateDynamicTextures()})),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(),this.camera.target.equalsWithEpsilon(this.camera.lastFocus,.1)||this.focusLostNotified||(this.focusLostObservable.notifyObservers(void 0),this.focusLostNotified=!0))})),t}executeCameraAnimation(e){100===this.getSceneInitializationProgress()&&this.camera&&this.scene.activeCamera===this.camera?J(this.scene,this.scene.activeCamera,e):this.queuedCameraAnimation=e}getCameraPose(){if(this.scene&&this.camera)return{lonDeg:Math.round(180*this.camera.alpha/Math.PI),latDeg:Math.round(180*this.camera.beta/Math.PI),radius:Math.round(1e4*(this.camera.radius+Number.EPSILON))/1e4,target:{x:this.camera.target.x,y:this.camera.target.y,z:this.camera.target.z}}}setCameraPose(e){this.scene&&this.camera&&(this.camera.target=new(0,s.Vector3)(e.target.x,e.target.y,e.target.z),this.camera.radius=e.radius,this.camera.alpha=e.latDeg,this.camera.beta=e.lonDeg)}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.configuration;this.camera.rerunFramingBehavior((()=>{this.focusLostNotified=!1,t.camera.limits.min.radius&&(this.camera.lowerRadiusLimit=t.camera.limits.min.radius),t.camera.limits.max.radius&&(this.camera.upperRadiusLimit=t.camera.limits.max.radius),e()}))}))}setAutoRotation(e){this.configuration.camera.autoRotation.enabled&&this.camera&&(e?this.camera.enableAutoRotationBehavior(this.configuration.camera.autoRotation.idleTimeMs):this.camera.disableAutoRotationBehavior())}getCurrentConfiguration(){return this.configuration.options}async renderSceneScreenshot(e,t){if(!this.camera)throw new Error("Missing product camera, cannot render screenshot!");var i;(i=this.camera).getScene().stopAnimation(i),i.animations=[];const a=this.camera.alpha,r=this.camera.beta,n=this.camera.radius,s=t.latDeg*Math.PI/180,o=t.lonDeg*Math.PI/180;this.camera.alpha=o,this.camera.beta=s,this.camera.radius=t.radius||this.camera.radius;const l=await c.Tools.CreateScreenshotUsingRenderTargetAsync(this.engine,this.camera,e,"image/png",2,!0);return this.camera.alpha=a,this.camera.beta=r,this.camera.radius=n,l}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,r=e.camera.limits.max.beta;if(void 0===t||void 0===i||void 0===a||void 0===r)return!0;const n=[a,r],s=[t,i].every((e=>e===t)),o=n.every((e=>e===a));return!s&&!o}fireResizeEvent(){this.getNumViewports()>0&&this.engine.resize()}setHighlights(e,t){0===e.length&&(this.highlightLayer?.dispose(),this.highlightLayer=void 0),this.highlightLayer||(this.highlightLayer=new(0,i.HighlightLayer)("highlights",this.scene,{isStroke:!0,blurVerticalSize:.85,blurHorizontalSize:.85}),this.highlightLayer.innerGlow=!0,this.highlightLayer.outerGlow=!1),this.highlightLayer.removeAllMeshes();const a=t?new(0,n.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,a||n.Color3.FromHexString("#fcba03"))))}))}setRenderingPipelineConfiguration(e){this.renderingPipeline&&this.renderingPipeline.setConfiguration(e)}async loadModel(e,t){const i=new ce({modelDetails:e,scene:this.scene,previewService:this,progressHandler:t});return i.registerMaterialVariantListener((e=>this.handleMaterialProgressCallback(e.remainingCount,e.totalCount,e.taskName))),i.registerModelVariantListener((e=>this.handleModelProgressCallback(e,e.key))),this.configuration.highlights.enabled&&(i.registerMaterialSelectedCallback((e=>{this.setHighlights([e])})),i.registerMaterialDeselectedCallback((()=>{this.setHighlights([])}))),this.modelContainers.set(i.getId(),i),await i.getImportPromise(),i}getAllModels(){return Array.from(this.modelContainers.values())}getModelById(e){return this.modelContainers.get(e)}registerPlugin(e){this.plugins.push(e),e.initialize(this,{camera:this.camera,engine:this.engine,scene:this.scene})}unregisterPlugin(e){const t=this.plugins.indexOf(e);if(t>-1){this.plugins.splice(t,1).forEach((e=>e.dispose(!1)))}}handleMaterialProgressCallback(e,t,i){this.loadProgress.set(`key_${i}`,e/t*100),this.notifyLoadHandlers()}handleModelProgressCallback(e,t){this.loadProgress.set(t,100*e.loaded/e.total),this.notifyLoadHandlers()}reattachControls(e,t=2){if(this.scene.detachControl(),this.engine.inputElement=e,this.camera){this.camera.attachControl(!0,!1,t);this.camera.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(){this.queuedCameraAnimation&&(this.executeCameraAnimation(this.queuedCameraAnimation),this.queuedCameraAnimation=void 0)}}E(module.exports,I),E(module.exports,V),E(module.exports,j);
|
|
1
|
+
var e=require("@babylonjs/core/Engines/engine"),i=require("@babylonjs/core/Engines/nullEngine"),t=require("@babylonjs/core/Layers/highlightLayer"),a=require("@babylonjs/core/Loading/sceneLoader"),r=require("@babylonjs/core/Materials/Textures/cubeTexture"),n=require("@babylonjs/core/Maths/math.color"),s=require("@babylonjs/core/Maths/math.vector"),o=require("@babylonjs/core/Meshes/Compression/dracoCompression"),l=require("@babylonjs/core/Misc/observable"),c=require("@babylonjs/core/Misc/tools"),h=require("@babylonjs/core/scene"),d=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 u=require("@babylonjs/core/Materials/PBR/pbrMaterial"),g=require("@babylonjs/core/Materials/Textures/mirrorTexture"),m=require("@babylonjs/core/Maths/math"),p=require("@babylonjs/core/Probes/reflectionProbe"),b=require("@babylonjs/core/Actions/actionManager"),f=require("@babylonjs/core/Actions/directActions"),v=require("@babylonjs/core/Layers/glowLayer"),y=require("@babylonjs/core/Meshes/transformNode"),P=require("@babylonjs/core/Materials/Textures/dynamicTexture"),M=require("@babylonjs/core/Materials/Textures/texture"),w=require("@babylonjs/core/Animations/animation"),C=require("@babylonjs/core/Animations/easing"),x=require("@babylonjs/core/Misc/assetsManager"),O=require("@babylonjs/core/Cameras/arcRotateCamera"),A=require("@babylonjs/core/Materials/colorCurves"),T=require("@babylonjs/core/Materials/imageProcessingConfiguration"),L=require("@babylonjs/core/PostProcesses/RenderPipeline"),R=require("@babylonjs/core/PostProcesses/depthOfFieldEffect");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 S(e,i,t,a){Object.defineProperty(e,i,{get:t,set:a,enumerable:!0,configurable:!0})}require("@babylonjs/core/Rendering/depthRendererSceneComponent");var I={};let F;var D;let k;var B;S(I,"ProductCameraRig",(()=>F)),S(I,"MaterialEffectMode",(()=>k)),(D=F||(F={}))[D.Orbit=0]="Orbit",D[D.Pan=1]="Pan",(B=k||(k={})).None="None",B.RemoveWhenSelected="RemoveWhenSelected",B.ApplyWhenSelected="ApplyWhenSelected";var z={};function V(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}S(z,"SpiffCommerce3DPreviewService",(()=>be));class q{constructor(e){V(this,"customOptions",void 0),V(this,"getSceneClearColor",(()=>{const e=this.customOptions?.transparentBackground||this.customOptions?.backgroundImage?0:1;if(this.customOptions&&this.customOptions?.transparentBackground||this.customOptions?.backgroundImage)return new(0,n.Color4)(0,0,0,e).toLinearSpace();if(this.customOptions&&this.customOptions.backgroundColor){const i=n.Color3.FromHexString(this.customOptions.backgroundColor);return new(0,n.Color4)(i.r,i.g,i.b,e).toLinearSpace()}return new(0,n.Color4)(.98,.98,.98,e).toLinearSpace()})),V(this,"highlightColorFromConfig",(()=>this.customOptions&&this.customOptions.highlightColor?this.hexToColor4(this.customOptions.highlightColor):new(0,n.Color4)(.98,.98,.98,1).toLinearSpace())),V(this,"hexToColor4",((e,i=1)=>{const t=n.Color3.FromHexString(e);return new(0,n.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 j={};S(j,"RenderingConfiguration",(()=>N)),S(j,"REFLECTION_PROBE_RESOLUTION",(()=>H)),S(j,"renderingPipelineDefaults",(()=>_));class N{static getDynamicTextureResolution(){return this.getIsMobile()||!N.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,_={antiAliasing:{samples:4,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,center:{x:0,y:0},colorHex:"#000000ff",colorRgba:{r:0,g:0,b:0,a:1},stretch:0,weight:1}};function G(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class U{constructor(e){G(this,"name",void 0),G(this,"enabled",void 0),G(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 a=i.extras[t];e.metadata[t]=a})),t(e)}))}async loadMaterialPropertiesAsync(e,i,t){await this.loader.loadMaterialPropertiesAsync(e,i,t),this.enableMaterialExtrasIfRequired(i,t)}dispose(){}enableMaterialExtrasIfRequired(e,i){if(e.extras&&i instanceof u.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,m.Color3)(e.extras.translucencyR,e.extras.translucencyG,e.extras.translucencyB))}if(e.extras.refractionIOR){const t=i;t.subSurface.isRefractionEnabled=!0,t.subSurface.volumeIndexOfRefraction=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 a=t.metadata;a&&(a.mirrorTexture&&function(t,a=1){const r=t.material;if(!r)return;const n=new(0,g.MirrorTexture)("mirror",N.getMirrorTextureResolution(),e,!0);n.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=m.Vector3.TransformNormal(new(0,m.Vector3)(s[0],s[1],s[2]),o).normalize(),c=m.Plane.FromPositionAndNormal(t.position,l.scale(-1));n.mirrorPlane=c,n.level=a,r.reflectionTexture=n}(t,a.mirrorTexture),a.reflectionProbe&&function(t){const a=t.material,r=new(0,p.ReflectionProbe)("probe-"+a.name,H,e);r.attachToMesh(t),r.renderList&&r.renderList.push(...i(e)),a.reflectionTexture=r.cubeTexture}(t))}))}}const W=new Map;async function K(e,i,t){return new Promise(((r,n)=>{const s=W.get(e);if(s&&s.scene.uid===i.uid)return r(s);a.SceneLoader.LoadAssetContainerAsync(e,void 0,i,t).then((i=>{W.set(e,i),r(i)})).catch(n)}))}function Q(i,t,a,r,n=""){a.forEach((a=>{const s=a.getID(),o=a.getName(),l=N.getDynamicTextureResolution();i.filter((e=>e.name===n+o)).forEach((i=>{const n=r.get(s);if(n)Y(i,n),n.update(false);else{const n=function(i,t,a,r){const n=new(0,P.DynamicTexture)(i,{width:a,height:r},t,N.shouldMipMap(),M.Texture.TRILINEAR_SAMPLINGMODE,e.Engine.TEXTUREFORMAT_RGBA),s=n.getContext();s&&(s.fillStyle="#f5f5f5",s.fillRect(0,0,a,r),n.update());return n}(o,t,l.width,l.height);r.set(s,n),a.setStaticContext(n.getContext()),Y(i,n),n.onLoadObservable.addOnce((()=>{n.update(false)}))}}))}))}function Y(e,i){if(e instanceof u.PBRMaterial){const t=e,a=t.albedoTexture;a?(i.wrapU=a.wrapU,i.wrapV=a.wrapV):(i.wrapU=1,i.wrapV=1),t.albedoTexture=i}else{const t=e,a=t.diffuseTexture;a&&(i.wrapU=a.wrapU,i.wrapV=a.wrapV),t.diffuseTexture=i}}function Z(){const e=()=>Math.floor(65536*(1+Math.random())).toString(16).substring(1);return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()}function $(e,i,t,a){const r=e=>e.targetedAnimations.map((e=>e.animation.framePerSecond)).reduce(((e,i)=>e+i),0)/e.targetedAnimations.length||0;void 0===a||void 0===t||a!==t?e.forEach((e=>{e.stop();const n=r(e);e.start(i,1,a*n,t*n)})):e.forEach((e=>{e.stop();const t=r(e),n=a*t;e.start(i,1,n,n)}))}function X(e){e.forEach((e=>{e.stop()}))}function J(e,i,t){var a,r,n;e.stopAnimation(i),i.animations=[],Math.abs(i.alpha)>2*Math.PI&&(i.alpha=(a=i.alpha,r=0,n=2*Math.PI,a<r?n-(r-a)%(n-r):r+(a-r)%(n-r)));const o=[],l=t.target,c=l?1:0;if(t.target&&Object.keys(t.target).length>0&&o.push(ie("cameraTargetLerp","target",(new(0,s.Vector3)).copyFrom(i.target),new(0,s.Vector3)(t.target.x,t.target.y,t.target.z),w.Animation.ANIMATIONTYPE_VECTOR3,0)),o.push(ie("cameraAlphaLerp","alpha",i.alpha,ee(t.lonDeg),w.Animation.ANIMATIONTYPE_FLOAT,c)),o.push(ie("cameraBetaLerp","beta",i.beta,ee(t.latDeg),w.Animation.ANIMATIONTYPE_FLOAT,c)),void 0!==t.radius){const e=Math.max(.01,t.radius);o.push(ie("cameraRadiusLerp","radius",i.radius,e,w.Animation.ANIMATIONTYPE_FLOAT,c))}i.animations.push(...o);const h=i.useAutoRotationBehavior;i.disableAutoRotationBehavior(),e.beginAnimation(i,0,l?120:60,!1,1,(()=>{i.animations=[],h&&i.enableAutoRotationBehavior()}))}function ee(e){return e*Math.PI/180}function ie(e,i,t,a,r,n=0,s=w.Animation.ANIMATIONLOOPMODE_CONSTANT){const o=new(0,C.QuadraticEase);o.setEasingMode(C.EasingFunction.EASINGMODE_EASEINOUT);const l=new(0,w.Animation)(e,i,60,r,s),c=[];return n>0&&c.push({frame:0,value:t}),c.push({frame:60*n,value:t}),c.push({frame:60*(n+1),value:a}),l.setKeys(c),l.setEasingFunction(o),l}const te={albedoTexture:"albedoMap",bumpTexture:"normalMap",ambientTexture:"ambientMap",emissiveTexture:"emissionMap",opacityTexture:"alphaMap",metallicTexture:"metallicMap",refractionTexture:"refractionMap"};function ae(e,i,t,a){["albedoTexture","bumpTexture","ambientTexture","emissiveTexture","opacityTexture","metallicTexture","refractionTexture"].forEach((r=>{!function(e,i,t,a,r){const n=te[e];if(!n)throw new Error("Unexpected texture name encountered.");const s=i[n]?.fileLink;s?a.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,a)})),function(e,i){if(!e.clearCoat)return;e.clearCoat===k.RemoveWhenSelected?(i.clearCoat.isEnabled=!1,i.clearCoat.indexOfRefraction=1.5):e.clearCoat===k.ApplyWhenSelected&&(i.clearCoat.isEnabled=!0,i.clearCoat.indexOfRefraction=e.clearCoatIOR||i.clearCoat.indexOfRefraction)}(e,i)}function re(e,i,t,a){"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]=a}function ne(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,t){ne(this,"materialVariantMap",new Map),ne(this,"keysThatRemovedBaseModel",[]),ne(this,"loadedContainerForKey",new Map),ne(this,"loadedMaterialsForKey",new Map),ne(this,"scene",void 0),ne(this,"renameClonedAsset",void 0),ne(this,"setBaseModelEnabled",void 0),this.scene=e,this.renameClonedAsset=i,this.setBaseModelEnabled=t}async applyMaterial(e,i,t,a){return new Promise((r=>{e=this.renameClonedAsset(e);const n=this.scene.materials.filter((i=>i.name===e)),s=this.materialVariantMap.get(e);if(this.materialVariantMap.set(e,{...s,...i}),0===n.length)return void r(void 0);const o=new(0,x.AssetsManager)(this.scene);o.useDefaultLoadingScreen=!1,n.forEach((e=>ae(i,e,o,a))),o.onProgress=(e,i,a)=>{t&&t(e/i*100,100,a.name)},o.onFinish=e=>{e.forEach((e=>{const a=e;t&&t(100,100,e.name),n.forEach((t=>re(e.name,t,i,a.texture)))})),r(void 0)},o.loadAsync()}))}async applyModel(e,i,t,a){if(t&&i&&!this.keysThatRemovedBaseModel.includes(e)&&this.keysThatRemovedBaseModel.push(e),!t)return this.keysThatRemovedBaseModel.includes(e)&&this.setBaseModelEnabled(!0),this.loadedContainerForKey.get(e)?.dispose(),this.loadedMaterialsForKey.delete(e),Promise.resolve(void 0);this.loadedContainerForKey.has(e)&&(this.loadedContainerForKey.get(e)?.dispose(),this.loadedMaterialsForKey.delete(e)),i&&this.setBaseModelEnabled(!1);const r=(await K(t,this.scene,a)).instantiateModelsToScene(this.renameClonedAsset,!0);this.loadedContainerForKey.set(e,r),this.loadedMaterialsForKey.set(e,oe(r));const n=[];return this.materialVariantMap.forEach((async(e,i)=>{n.push(this.applyMaterial(i,e))})),await Promise.all(n),r}getAllMaterials(){const e=[];return this.loadedMaterialsForKey.forEach((i=>{i.forEach((i=>{e.includes(i)||e.push(i)}))})),e}}function oe(e){const i=[];return e.rootNodes.forEach((e=>{e.getChildMeshes().forEach((e=>{e.material&&i.push(e.material),e.subMeshes&&e.subMeshes.forEach((e=>{const t=e.getMaterial(!1);t&&i.push(t)}))}))})),i}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}class ce{constructor(e){le(this,"id",void 0),le(this,"previewService",void 0),le(this,"scene",void 0),le(this,"variantManager",void 0),le(this,"materialSelectedObservable",new(0,l.Observable)),le(this,"materialDeselectedObservable",new(0,l.Observable)),le(this,"materialVariantObservable",new(0,l.Observable)),le(this,"modelVariantObservable",new(0,l.Observable)),le(this,"queuedModelAnimation",void 0),le(this,"materialReadyToLoadCallbacks",new Map),le(this,"modelReadyToLoadCallbacks",new Map),le(this,"dynamicTextures",new Map),le(this,"assetContainer",void 0),le(this,"canvasPanels",void 0),le(this,"contextService",void 0),le(this,"importPromise",void 0),le(this,"initialized",!1),le(this,"materials",[]),le(this,"modelInstance",void 0),le(this,"transformRoot",void 0);const{modelDetails:i,previewService:t,progressHandler:a,scene:r}=e;this.contextService=i.contextService,this.id=Z(),this.previewService=t,this.scene=r,this.variantManager=new se(r,this.renameClonedAsset.bind(this),this.setEnabled.bind(this)),this.previewService.registerInitializedListener((async()=>await this.processQueuedEvents()));this.importPromise=(async()=>(this.assetContainer=await K(i.model,r,a),this.initialized=!0,this.transformRoot=new(0,y.TransformNode)("root",this.scene),this.instantiate(),this))()}async applyMaterialVariant(e,i,t,a){if(100===this.previewService.getSceneInitializationProgress()&&this.initialized)await this.variantManager.applyMaterial(e,t,((e,i,t)=>{this.materialVariantObservable.notifyObservers({remainingCount:e,totalCount:i,taskName:t})}),a);else if(this.materialReadyToLoadCallbacks.has(e)){this.materialReadyToLoadCallbacks.get(e)?.set(i,this.applyMaterialVariant.bind(this,e,i,t,a))}else{this.materialReadyToLoadCallbacks.set(e,new Map);this.materialReadyToLoadCallbacks.get(e)?.set(i,this.applyMaterialVariant.bind(this,e,i,t,a))}}async applyModelVariant(e,i,t){if(100!==this.previewService.getSceneInitializationProgress()||!this.initialized)return void this.modelReadyToLoadCallbacks.set(e,this.applyModelVariant.bind(this,e,i,t));const a=await this.variantManager.applyModel(e,t,i?.model,(i=>{this.modelVariantObservable.notifyObservers({...i,key:e})}));this.modelInstance&&X(this.modelInstance.animationGroups),this.contextService||(this.contextService=i?.contextService),a&&this.configureModelInstance(a)}executeAnimation(e){100===this.previewService.getSceneInitializationProgress()?this.modelInstance&&$(this.modelInstance.animationGroups,e.loop,e.to,e.from):this.queuedModelAnimation=e}getId(){return this.id}listMaterials(){const e=this.scene?.materials.filter((e=>e.name.startsWith(this.id)));return e?e.map((e=>({id:e.id,name:e.name}))):[]}registerMaterialSelectedCallback(e){this.materialSelectedObservable.add(e)}unregisterMaterialSelectedCallback(e){this.materialSelectedObservable.removeCallback(e)}registerMaterialDeselectedCallback(e){this.materialDeselectedObservable.add(e)}unregisterMaterialDeselectedCallback(e){this.materialDeselectedObservable.removeCallback(e)}get position(){return this.transformRoot.position}set position(e){this.transformRoot.position=new(0,s.Vector3)(e.x,e.y,e.z)}get rotation(){return this.transformRoot.rotation}set rotation(e){this.transformRoot.rotation=new(0,s.Vector3)(e.x,e.y,e.z)}get scale(){return this.transformRoot.scaling}set scale(e){this.transformRoot.scaling=new(0,s.Vector3)(e.x,e.y,e.z)}attachPickingHandler(e){e.rootNodes.forEach((e=>{e.getChildMeshes(!1).forEach((e=>{"targetcube_t"!==e.name&&"backgroundShell"!==e.name&&(e.isPickable=!0,e.actionManager||(e.actionManager=new(0,b.ActionManager)(this.scene)),e.actionManager||(e.actionManager=new(0,b.ActionManager)(this.scene)),e.actionManager.registerAction(new(0,f.ExecuteCodeAction)(b.ActionManager.OnPointerOutTrigger,(()=>{e.material&&this.materialDeselectedObservable.notifyObservers({id:e.material.id,name:e.material.name})}))),e.actionManager.registerAction(new(0,f.ExecuteCodeAction)(b.ActionManager.OnPickDownTrigger,(i=>{i.meshUnderPointer&&e.material&&this.materialSelectedObservable.notifyObservers({id:e.material.id,name:e.material.name})}))))}))}))}getInitializationPromise(){return this.importPromise}getIsInitialized(){return this.initialized}getQueuedMaterialVariantCount(){return this.materialReadyToLoadCallbacks.size}getQueuedModelVariantCount(){return this.modelReadyToLoadCallbacks.size}configureModelInstance(e){const i=this.transformRoot.position,t=this.transformRoot.rotation,a=this.transformRoot.scaling;this.transformRoot.position=s.Vector3.Zero(),this.transformRoot.rotation=s.Vector3.Zero(),this.transformRoot.scaling=s.Vector3.One(),e.rootNodes.forEach((e=>{e.parent=this.transformRoot})),this.transformRoot.position=i,this.transformRoot.rotation=t,this.transformRoot.scaling=a,this.canvasPanels=this.contextService?.getAll()||new Map,Q(this.materials.concat(this.variantManager.getAllMaterials()),this.scene,this.canvasPanels,this.dynamicTextures,`${this.id}_`),this.attachPickingHandler(e)}dispose(){this.modelInstance.dispose(),this.modelInstance=void 0}instantiate(){this.modelInstance=this.assetContainer.instantiateModelsToScene(this.renameClonedAsset.bind(this),!0),this.materials=oe(this.modelInstance),this.configureModelInstance(this.modelInstance);if(this.materials.some((e=>"emissiveTexture"in e&&null!==e.emissiveTexture))){new(0,v.GlowLayer)("GlowLayer",this.scene).intensity=.5}this.processQueuedEvents()}renameClonedAsset(e){return`${this.id}_${e}`}setEnabled(e){e&&!this.modelInstance?this.instantiate():!e&&this.modelInstance&&this.dispose()}updateDynamicTextures(){this.canvasPanels?.forEach(((e,i)=>{const t=this.dynamicTextures.get(i);t&&e.getStaticContextDirty()&&t.isReady()&&(t.update(!1),e.setStaticContextDirty(!1))}))}registerMaterialVariantListener(e){this.materialVariantObservable.add(e)}unregisterMaterialVariantListener(e){this.materialVariantObservable.removeCallback(e)}registerModelVariantListener(e){this.modelVariantObservable.add(e)}unregisterModelVariantListener(e){this.modelVariantObservable.removeCallback(e)}async processQueuedEvents(){100===this.previewService.getSceneInitializationProgress()&&(await Promise.all(Array.from(this.materialReadyToLoadCallbacks.values()).map((e=>Array.from(e.values()).map((e=>e()))))),this.materialReadyToLoadCallbacks.clear(),await Promise.all(Array.from(this.modelReadyToLoadCallbacks.values()).map((e=>e()))),this.modelReadyToLoadCallbacks.clear(),this.queuedModelAnimation&&(this.executeAnimation(this.queuedModelAnimation),this.queuedModelAnimation=void 0))}}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 extends O.ArcRotateCamera{constructor(e,i,t,a,r,n,o,l){super(e,i,t,a,r,n,l),he(this,"lastFocus",new(0,s.Vector3)(0,0,0)),he(this,"panDenominator",1),this.minZ=.01,this.setRadius(this.radius),this.enableFramingBehavior(),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 i=ue(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,i){const t=this.getFramingBehavior();t.framingTime=i||800;const a=ue(this._scene),r=a.max.subtract(a.min),n=a.min.add(r.scale(.5));this.setRadius(1.5*r.length()),this.wheelPrecision=100/this.radius,this.panningInertia=0,this.panningOriginTarget.copyFrom(n),this.panDenominator=r.length(),t.zoomOnBoundingInfo(a.min,a.max,void 0,(()=>{e&&e()})),t.framingTime=0}enableAutoRotationBehavior(e=5e3){this.useAutoRotationBehavior=!0;const i=this.getAutoRotationBehavior();i&&(i.idleRotationWaitTime=e)}disableAutoRotationBehavior(){this.useAutoRotationBehavior=!1}setRadius(e){this.radius=e,this.maxZ=1e3*this.radius,this.lowerRadiusLimit=.01*this.radius,this.upperRadiusLimit=1.5*this.radius,this.wheelPrecision=100/this.radius,this.pinchPrecision=300/this.radius}static create(e,i,t){const a=ue(e),r=a.max.subtract(a.min),n=a.min.add(r.scale(.5)),s=new de("ProductCamera",-Math.PI/2,Math.PI/2,1.5*r.length(),n,e,i);return s.panningInertia=0,s.panningOriginTarget.copyFrom(n),s.panDenominator=r.length(),s.onAfterCheckInputsObservable.add((()=>{s.panningSensibility=1e3/s.panDenominator})),t&&(e.activeCamera=s),s}}function ue(e){if(0===e.meshes.length)return{min:new(0,s.Vector3)(-1,-1,-1),max:new(0,s.Vector3)(1,1,1)};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 ge(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}class me{constructor(e,i=!0,t=null){ge(this,"renderingPipeline",void 0),ge(this,"currentConfiguration",void 0),this.renderingPipeline=new(0,L.DefaultRenderingPipeline)("default",i,e,t?[t]:void 0,!1),this.renderingPipeline.isSupported&&this.renderingPipeline.prepare()}dispose(){this.renderingPipeline.dispose()}addCamera(e){this.renderingPipeline.isSupported&&this.renderingPipeline.addCamera(e)}removeCamera(e){this.renderingPipeline.isSupported&&this.renderingPipeline.removeCamera(e)}getConfiguration(){return this.currentConfiguration}setConfiguration(e){if(this.renderingPipeline.isSupported){if(this.renderingPipeline.samples=e.antiAliasing?.samples??_.antiAliasing.samples,this.renderingPipeline.fxaaEnabled=e.antiAliasing?.fxaaEnabled??_.antiAliasing.fxaaEnabled,this.renderingPipeline.bloomEnabled=e.bloom?.enabled??_.bloom.enabled,this.renderingPipeline.bloomKernel=e.bloom?.kernel??_.bloom.kernel,this.renderingPipeline.bloomScale=e.bloom?.scale??_.bloom.scale,this.renderingPipeline.bloomThreshold=e.bloom?.threshold??_.bloom.threshold,this.renderingPipeline.bloomWeight=e.bloom?.weight??_.bloom.weight,this.renderingPipeline.chromaticAberrationEnabled=e.chromaticAberration?.enabled??_.chromaticAberration.enabled,this.renderingPipeline.chromaticAberration.aberrationAmount=e.chromaticAberration?.aberrationAmount??_.chromaticAberration.aberrationAmount,this.renderingPipeline.chromaticAberration.radialIntensity=e.chromaticAberration?.radialIntensity??_.chromaticAberration.radialIntensity,this.renderingPipeline.chromaticAberration.direction=e.chromaticAberration?.direction?new(0,s.Vector2)(e.chromaticAberration.direction.x,e.chromaticAberration.direction.y):new(0,s.Vector2)(_.chromaticAberration.direction.x,_.chromaticAberration.direction.y),this.renderingPipeline.imageProcessing.colorCurvesEnabled=e.colorCurves?.enabled??_.colorCurves.enabled,this.renderingPipeline.imageProcessing.colorCurves=e.colorCurves?this.updateColorCurve(e.colorCurves):new(0,A.ColorCurves),this.renderingPipeline.depthOfFieldEnabled=e.depthOfField?.enabled??_.depthOfField.enabled,e.depthOfField)switch(e.depthOfField.blurLevel??_.depthOfField.blurLevel){case"Low":this.renderingPipeline.depthOfFieldBlurLevel=R.DepthOfFieldEffectBlurLevel.Low;break;case"Medium":this.renderingPipeline.depthOfFieldBlurLevel=R.DepthOfFieldEffectBlurLevel.Medium;break;case"High":this.renderingPipeline.depthOfFieldBlurLevel=R.DepthOfFieldEffectBlurLevel.High}if(this.renderingPipeline.depthOfField.focalLength=e.depthOfField?.focalLength??_.depthOfField.focalLength,this.renderingPipeline.depthOfField.fStop=e.depthOfField?.fStop??_.depthOfField.fStop,this.renderingPipeline.depthOfField.focusDistance=e.depthOfField?.focusDistance??_.depthOfField.focusDistance,this.renderingPipeline.depthOfField.lensSize=e.depthOfField?.lensSize??_.depthOfField.lensSize,this.renderingPipeline.grainEnabled=e.grain?.enabled??_.grain.enabled,this.renderingPipeline.grain.animated=e.grain?.animated??_.grain.animated,this.renderingPipeline.grain.intensity=e.grain?.intensity??_.grain.intensity,this.renderingPipeline.imageProcessing.contrast=e.misc?.contrast??_.misc.contrast,this.renderingPipeline.imageProcessing.exposure=e.misc?.exposure??_.misc.exposure,this.renderingPipeline.imageProcessing.toneMappingEnabled=e.misc?.toneMappingEnabled??_.misc.toneMappingEnabled,this.renderingPipeline.imageProcessing.toneMappingEnabled)switch(e.misc.toneMappingType??_.misc.toneMappingType){case"Standard":this.renderingPipeline.imageProcessing.toneMappingType=T.ImageProcessingConfiguration.TONEMAPPING_STANDARD;break;case"ACES":this.renderingPipeline.imageProcessing.toneMappingType=T.ImageProcessingConfiguration.TONEMAPPING_ACES}if(this.renderingPipeline.sharpenEnabled=e.sharpen?.enabled??_.sharpen.enabled,this.renderingPipeline.sharpen.colorAmount=e.sharpen?.colorAmount??_.sharpen.colorAmount,this.renderingPipeline.sharpen.edgeAmount=e.sharpen?.edgeAmount??_.sharpen.edgeAmount,this.renderingPipeline.imageProcessing.vignetteEnabled=e.vignette?.enabled??_.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=_.vignette.center.x,this.renderingPipeline.imageProcessing.vignetteCenterY=_.vignette.center.y),e.vignette)switch(e.vignette?.blendMode??_.vignette.blendMode){case"Multiply":this.renderingPipeline.imageProcessing.vignetteBlendMode=T.ImageProcessingConfiguration.VIGNETTEMODE_MULTIPLY;break;case"Opaque":this.renderingPipeline.imageProcessing.vignetteBlendMode=T.ImageProcessingConfiguration.VIGNETTEMODE_OPAQUE}e.vignette?.colorRgba?this.renderingPipeline.imageProcessing.vignetteColor=new(0,n.Color4)(e.vignette.colorRgba.r,e.vignette.colorRgba.g,e.vignette.colorRgba.b,e.vignette.colorRgba.a):e.vignette?.colorHex?this.renderingPipeline.imageProcessing.vignetteColor=n.Color4.FromHexString(e.vignette.colorHex):this.renderingPipeline.imageProcessing.vignetteColor=new(0,n.Color4)(_.vignette.colorRgba.r,_.vignette.colorRgba.g,_.vignette.colorRgba.b,_.vignette.colorRgba.a),this.renderingPipeline.imageProcessing.vignetteStretch=e.vignette?.stretch??_.vignette.stretch,this.renderingPipeline.imageProcessing.vignetteWeight=e.vignette?.weight??_.vignette.weight,this.renderingPipeline.prepare(),this.currentConfiguration=e}}updateColorCurve(e){const i=new(0,A.ColorCurves);return i.globalDensity=e.globalDensity??i.globalDensity,i.globalExposure=e.globalExposure??i.globalExposure,i.globalHue=e.globalHue??i.globalHue,i.globalSaturation=e.globalSaturation??i.globalSaturation,i.highlightsDensity=e.highlightsDensity??i.highlightsDensity,i.highlightsExposure=e.highlightsExposure??i.highlightsExposure,i.highlightsHue=e.highlightsHue??i.highlightsHue,i.highlightsSaturation=e.highlightsSaturation??i.highlightsSaturation,i.midtonesDensity=e.midtonesDensity??i.midtonesDensity,i.midtonesExposure=e.midtonesExposure??i.midtonesExposure,i.midtonesHue=e.midtonesHue??i.midtonesHue,i.midtonesSaturation=e.midtonesSaturation??i.midtonesSaturation,i.shadowsDensity=e.shadowsDensity??i.shadowsDensity,i.shadowsExposure=e.shadowsExposure??i.shadowsExposure,i.shadowsHue=e.shadowsHue??i.shadowsHue,i.shadowsSaturation=e.shadowsSaturation??i.shadowsSaturation,i}}function pe(e,i,t){return i in e?Object.defineProperty(e,i,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[i]=t,e}d.GLTF2.GLTFLoader.RegisterExtension("glbPostProcessor",(function(e){return new U(e)})),a.SceneLoader.OnPluginActivatedObservable.add((e=>{if("gltf"===e.name){e.transparencyAsCoverage=!0}}));class be{constructor(t){pe(this,"camera",void 0),pe(this,"configuration",void 0),pe(this,"engine",void 0),pe(this,"scene",void 0),pe(this,"loadProgress",new Map([["initialScene",0]])),pe(this,"queuedCameraAnimation",void 0),pe(this,"focusLostNotified",!1),pe(this,"loadObservable",new(0,l.Observable)),pe(this,"focusLostObservable",new(0,l.Observable)),pe(this,"initializedCallbacks",[]),pe(this,"isInitialized",!1),pe(this,"highlightLayer",void 0),pe(this,"renderingPipeline",void 0),pe(this,"modelContainers",new Map),pe(this,"plugins",[]);const a=t?.noRender?void 0:document.createElement("canvas");this.configuration=new q(t);o.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"}},a&&(a.getContext("webgl2")||a.getContext("webgl"));const r=console.log;console.log=()=>{};const n=a?new(0,e.Engine)(a,!0,{adaptToDeviceRatio:!0,limitDeviceRatio:2,premultipliedAlpha:!1,preserveDrawingBuffer:!!t?.backgroundImage,audioEngine:!1,stencil:this.configuration.highlights.enabled,forceSRGBBufferSupportState:!0}):new(0,i.NullEngine);console.log=r,n.hideLoadingUI(),window.addEventListener("resize",this.fireResizeEvent.bind(this)),this.engine=n,this.scene=new(0,h.Scene)(n),this.camera=de.create(this.scene,this.configuration),this.renderingPipeline=new me(this.scene,!0),this.renderingPipeline.addCamera(this.camera),this.scene.imageProcessingConfiguration.exposure=this.configuration.lighting.exposure,this.scene.imageProcessingConfiguration.contrast=this.configuration.lighting.contrast}getEngineContext(){return{engine:this.engine,scene:this.scene,camera:this.camera}}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)}registerInitializedListener(e){this.isInitialized||!this.isInitialized&&this.initializedCallbacks.push(e)}unregisterInitializedListener(e){if(this.isInitialized)return;const i=this.initializedCallbacks.indexOf(e);i>-1&&this.initializedCallbacks.splice(i,1)}getIsInitialized(){return this.isInitialized}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.plugins.forEach((e=>e.dispose(!0))),this.renderingPipeline.dispose(),this.engine&&this.engine.dispose(),window.removeEventListener("resize",this.fireResizeEvent)}getSceneInitializationProgress(){return this.loadProgress.get("initialScene")}async initialize(e){let i;if(this.scene.clearColor=this.configuration.scene.clearColor,this.scene.environmentTexture=r.CubeTexture.CreateFromPrefilteredData(this.configuration.scene.environmentFile,this.scene),e){const t=100;i=await this.loadModel(e,(e=>{this.loadProgress.set("initialScene",e.loaded*t/e.total),this.notifyLoadHandlers()})).getInitializationPromise()}return this.loadProgress.set("initialScene",100),this.notifyLoadHandlers(),this.scene.activeCamera=this.camera,this.camera.rerunFramingBehavior(void 0,1),this.configuration.options?.renderingPipelineConfiguration&&this.renderingPipeline.setConfiguration(this.configuration.options.renderingPipelineConfiguration),X(this.scene.animationGroups),this.engine.views?.length>=1&&this.reattachControls(this.engine.views[this.engine.views.length-1].target),await this.processQueuedLoadEvents(),await Promise.all(this.initializedCallbacks.map((e=>e()))),this.initializedCallbacks=[],this.isInitialized=!0,this.engine.runRenderLoop((()=>{this.engine.views&&(this.modelContainers.forEach((e=>{e.updateDynamicTextures()})),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(),this.camera.target.equalsWithEpsilon(this.camera.lastFocus,.1)||this.focusLostNotified||(this.focusLostObservable.notifyObservers(void 0),this.focusLostNotified=!0))})),i}executeCameraAnimation(e){100===this.getSceneInitializationProgress()&&this.camera&&this.scene.activeCamera===this.camera?J(this.scene,this.scene.activeCamera,e):this.queuedCameraAnimation=e}getCameraPose(){if(this.scene&&this.camera)return{lonDeg:Math.round(180*this.camera.alpha/Math.PI),latDeg:Math.round(180*this.camera.beta/Math.PI),radius:Math.round(1e4*(this.camera.radius+Number.EPSILON))/1e4,target:{x:this.camera.target.x,y:this.camera.target.y,z:this.camera.target.z}}}setCameraPose(e){this.scene&&this.camera&&(this.camera.target=new(0,s.Vector3)(e.target.x,e.target.y,e.target.z),this.camera.radius=e.radius,this.camera.alpha=e.latDeg,this.camera.beta=e.lonDeg)}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.configuration;this.camera.rerunFramingBehavior((()=>{this.focusLostNotified=!1,i.camera.limits.min.radius&&(this.camera.lowerRadiusLimit=i.camera.limits.min.radius),i.camera.limits.max.radius&&(this.camera.upperRadiusLimit=i.camera.limits.max.radius),e()}))}))}setAutoRotation(e){this.configuration.camera.autoRotation.enabled&&this.camera&&(e?this.camera.enableAutoRotationBehavior(this.configuration.camera.autoRotation.idleTimeMs):this.camera.disableAutoRotationBehavior())}getCurrentConfiguration(){return this.configuration.options}async renderSceneScreenshot(e,i){if(!this.camera)throw new Error("Missing product camera, cannot render screenshot!");var t;(t=this.camera).getScene().stopAnimation(t),t.animations=[];const a=this.camera.alpha,r=this.camera.beta,n=this.camera.radius,s=i.latDeg*Math.PI/180,o=i.lonDeg*Math.PI/180;this.camera.alpha=o,this.camera.beta=s,this.camera.radius=i.radius||this.camera.radius;const l=await c.Tools.CreateScreenshotUsingRenderTargetAsync(this.engine,this.camera,e,"image/png",2,!0);return this.camera.alpha=a,this.camera.beta=r,this.camera.radius=n,l}orbitEnabled(){const e=this.configuration;if(!e)return!0;const i=e.camera.limits.min.alpha,t=e.camera.limits.max.alpha,a=e.camera.limits.min.beta,r=e.camera.limits.max.beta;if(void 0===i||void 0===t||void 0===a||void 0===r)return!0;const n=[a,r],s=[i,t].every((e=>e===i)),o=n.every((e=>e===a));return!s&&!o}fireResizeEvent(){this.getNumViewports()>0&&this.engine.resize()}setHighlights(e,i){0===e.length&&(this.highlightLayer?.dispose(),this.highlightLayer=void 0),this.highlightLayer||(this.highlightLayer=new(0,t.HighlightLayer)("highlights",this.scene,{isStroke:!0,blurVerticalSize:.85,blurHorizontalSize:.85}),this.highlightLayer.innerGlow=!0,this.highlightLayer.outerGlow=!1),this.highlightLayer.removeAllMeshes();const a=i?new(0,n.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,a||n.Color3.FromHexString("#fcba03"))))}))}setRenderingPipelineConfiguration(e){this.renderingPipeline&&this.renderingPipeline.setConfiguration(e)}loadModel(e,i){const t=new ce({modelDetails:e,scene:this.scene,previewService:this,progressHandler:i});return t.registerMaterialVariantListener((e=>this.handleMaterialProgressCallback(e.remainingCount,e.totalCount,e.taskName))),t.registerModelVariantListener((e=>this.handleModelProgressCallback(e,e.key))),this.configuration.highlights.enabled&&(t.registerMaterialSelectedCallback((e=>{this.setHighlights([e])})),t.registerMaterialDeselectedCallback((()=>{this.setHighlights([])}))),this.modelContainers.set(t.getId(),t),t}getAllModels(){return Array.from(this.modelContainers.values())}getModelById(e){return this.modelContainers.get(e)}registerPlugin(e){this.plugins.push(e),e.initialize(this,{camera:this.camera,engine:this.engine,scene:this.scene})}unregisterPlugin(e){const i=this.plugins.indexOf(e);if(i>-1){this.plugins.splice(i,1).forEach((e=>e.dispose(!1)))}}handleMaterialProgressCallback(e,i,t){this.loadProgress.set(`key_${t}`,e/i*100),this.notifyLoadHandlers()}handleModelProgressCallback(e,i){this.loadProgress.set(i,100*e.loaded/e.total),this.notifyLoadHandlers()}reattachControls(e,i=2){if(this.scene.detachControl(),this.engine.inputElement=e,this.camera){this.camera.attachControl(!0,!1,i);this.camera.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(){this.queuedCameraAnimation&&(this.executeCameraAnimation(this.queuedCameraAnimation),this.queuedCameraAnimation=void 0)}}E(module.exports,I),E(module.exports,z),E(module.exports,j);
|
|
2
2
|
//# sourceMappingURL=main.js.map
|
package/dist/module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Engine as e}from"@babylonjs/core/Engines/engine";import{NullEngine as t}from"@babylonjs/core/Engines/nullEngine";import{HighlightLayer as i}from"@babylonjs/core/Layers/highlightLayer";import{SceneLoader as a}from"@babylonjs/core/Loading/sceneLoader";import{CubeTexture as n}from"@babylonjs/core/Materials/Textures/cubeTexture";import{Color3 as r,Color4 as s}from"@babylonjs/core/Maths/math.color";import{Vector3 as o,Vector2 as l}from"@babylonjs/core/Maths/math.vector";import{DracoCompression as c}from"@babylonjs/core/Meshes/Compression/dracoCompression";import{Observable as h}from"@babylonjs/core/Misc/observable";import{Tools as d}from"@babylonjs/core/Misc/tools";import{Scene as m}from"@babylonjs/core/scene";import{GLTF2 as g}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{PBRMaterial as u}from"@babylonjs/core/Materials/PBR/pbrMaterial";import{MirrorTexture as p}from"@babylonjs/core/Materials/Textures/mirrorTexture";import{Color3 as b,Vector3 as f,Plane as v}from"@babylonjs/core/Maths/math";import{ReflectionProbe as y}from"@babylonjs/core/Probes/reflectionProbe";import{ActionManager as P}from"@babylonjs/core/Actions/actionManager";import{ExecuteCodeAction as w}from"@babylonjs/core/Actions/directActions";import{GlowLayer as M}from"@babylonjs/core/Layers/glowLayer";import{TransformNode as C}from"@babylonjs/core/Meshes/transformNode";import{DynamicTexture as x}from"@babylonjs/core/Materials/Textures/dynamicTexture";import{Texture as O}from"@babylonjs/core/Materials/Textures/texture";import{Animation as A}from"@babylonjs/core/Animations/animation";import{QuadraticEase as R,EasingFunction as T}from"@babylonjs/core/Animations/easing";import{AssetsManager as L}from"@babylonjs/core/Misc/assetsManager";import{ArcRotateCamera as E}from"@babylonjs/core/Cameras/arcRotateCamera";import{ColorCurves as S}from"@babylonjs/core/Materials/colorCurves";import{ImageProcessingConfiguration as I}from"@babylonjs/core/Materials/imageProcessingConfiguration";import{DefaultRenderingPipeline as F}from"@babylonjs/core/PostProcesses/RenderPipeline";import{DepthOfFieldEffectBlurLevel as D}from"@babylonjs/core/PostProcesses/depthOfFieldEffect";import"@babylonjs/core/Rendering/depthRendererSceneComponent";function k(e,t,i,a){Object.defineProperty(e,t,{get:i,set:a,enumerable:!0,configurable:!0})}var B={};let z;var N;let j;var V;k(B,"ProductCameraRig",(()=>z)),k(B,"MaterialEffectMode",(()=>j)),(N=z||(z={}))[N.Orbit=0]="Orbit",N[N.Pan=1]="Pan",(V=j||(j={})).None="None",V.RemoveWhenSelected="RemoveWhenSelected",V.ApplyWhenSelected="ApplyWhenSelected";function H(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}k({},"SpiffCommerce3DPreviewService",(()=>ye));class _{constructor(e){H(this,"customOptions",void 0),H(this,"getSceneClearColor",(()=>{const e=this.customOptions?.transparentBackground||this.customOptions?.backgroundImage?0:1;if(this.customOptions&&this.customOptions?.transparentBackground||this.customOptions?.backgroundImage)return new s(0,0,0,e).toLinearSpace();if(this.customOptions&&this.customOptions.backgroundColor){const t=r.FromHexString(this.customOptions.backgroundColor);return new s(t.r,t.g,t.b,e).toLinearSpace()}return new s(.98,.98,.98,e).toLinearSpace()})),H(this,"highlightColorFromConfig",(()=>this.customOptions&&this.customOptions.highlightColor?this.hexToColor4(this.customOptions.highlightColor):new s(.98,.98,.98,1).toLinearSpace())),H(this,"hexToColor4",((e,t=1)=>{const i=r.FromHexString(e);return new s(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 G={};k(G,"RenderingConfiguration",(()=>U)),k(G,"REFLECTION_PROBE_RESOLUTION",(()=>W)),k(G,"renderingPipelineDefaults",(()=>q));class U{static getDynamicTextureResolution(){return this.getIsMobile()||!U.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 W=128,q={antiAliasing:{samples:4,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,center:{x:0,y:0},colorHex:"#000000ff",colorRgba:{r:0,g:0,b:0,a:1},stretch:0,weight:1}};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 Q{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 a=t.extras[i];e.metadata[i]=a})),i(e)}))}async loadMaterialPropertiesAsync(e,t,i){await this.loader.loadMaterialPropertiesAsync(e,t,i),this.enableMaterialExtrasIfRequired(t,i)}dispose(){}enableMaterialExtrasIfRequired(e,t){if(e.extras&&t instanceof u){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 b(e.extras.translucencyR,e.extras.translucencyG,e.extras.translucencyB))}if(e.extras.refractionIOR){const i=t;i.subSurface.isRefractionEnabled=!0,i.subSurface.volumeIndexOfRefraction=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",U.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=f.TransformNormal(new f(s[0],s[1],s[2]),o).normalize(),c=v.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 y("probe-"+a.name,W,e);n.attachToMesh(i),n.renderList&&n.renderList.push(...t(e)),a.reflectionTexture=n.cubeTexture}(i))}))}}const Y=new Map;async function Z(e,t,i){return new Promise(((n,r)=>{const s=Y.get(e);if(s&&s.scene.uid===t.uid)return n(s);a.LoadAssetContainerAsync(e,void 0,t,i).then((t=>{Y.set(e,t),n(t)})).catch(r)}))}function $(t,i,a,n,r=""){a.forEach((a=>{const s=a.getID(),o=a.getName(),l=U.getDynamicTextureResolution();t.filter((e=>e.name===r+o)).forEach((t=>{const r=n.get(s);if(r)X(t,r),r.update(false);else{const r=function(t,i,a,n){const r=new x(t,{width:a,height:n},i,U.shouldMipMap(),O.TRILINEAR_SAMPLINGMODE,e.TEXTUREFORMAT_RGBA),s=r.getContext();s&&(s.fillStyle="#f5f5f5",s.fillRect(0,0,a,n),r.update());return r}(o,i,l.width,l.height);n.set(s,r),a.setStaticContext(r.getContext()),X(t,r),r.onLoadObservable.addOnce((()=>{r.update(false)}))}}))}))}function X(e,t){if(e instanceof u){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 J(){const e=()=>Math.floor(65536*(1+Math.random())).toString(16).substring(1);return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()}function ee(e,t,i,a){const n=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?e.forEach((e=>{e.stop();const r=n(e);e.start(t,1,a*r,i*r)})):e.forEach((e=>{e.stop();const i=n(e),r=a*i;e.start(t,1,r,r)}))}function te(e){e.forEach((e=>{e.stop()}))}function ie(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=[],l=i.target,c=l?1:0;if(i.target&&Object.keys(i.target).length>0&&s.push(ne("cameraTargetLerp","target",(new o).copyFrom(t.target),new o(i.target.x,i.target.y,i.target.z),A.ANIMATIONTYPE_VECTOR3,0)),s.push(ne("cameraAlphaLerp","alpha",t.alpha,ae(i.lonDeg),A.ANIMATIONTYPE_FLOAT,c)),s.push(ne("cameraBetaLerp","beta",t.beta,ae(i.latDeg),A.ANIMATIONTYPE_FLOAT,c)),void 0!==i.radius){const e=Math.max(.01,i.radius);s.push(ne("cameraRadiusLerp","radius",t.radius,e,A.ANIMATIONTYPE_FLOAT,c))}t.animations.push(...s);const h=t.useAutoRotationBehavior;t.disableAutoRotationBehavior(),e.beginAnimation(t,0,l?120:60,!1,1,(()=>{t.animations=[],h&&t.enableAutoRotationBehavior()}))}function ae(e){return e*Math.PI/180}function ne(e,t,i,a,n,r=0,s=A.ANIMATIONLOOPMODE_CONSTANT){const o=new R;o.setEasingMode(T.EASINGMODE_EASEINOUT);const l=new A(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}const re={albedoTexture:"albedoMap",bumpTexture:"normalMap",ambientTexture:"ambientMap",emissiveTexture:"emissionMap",opacityTexture:"alphaMap",metallicTexture:"metallicMap",refractionTexture:"refractionMap"};function se(e,t,i,a){["albedoTexture","bumpTexture","ambientTexture","emissiveTexture","opacityTexture","metallicTexture","refractionTexture"].forEach((n=>{!function(e,t,i,a,n){const r=re[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===j.RemoveWhenSelected?(t.clearCoat.isEnabled=!1,t.clearCoat.indexOfRefraction=1.5):e.clearCoat===j.ApplyWhenSelected&&(t.clearCoat.isEnabled=!0,t.clearCoat.indexOfRefraction=e.clearCoatIOR||t.clearCoat.indexOfRefraction)}(e,t)}function oe(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 le(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class ce{constructor(e,t,i){le(this,"materialVariantMap",new Map),le(this,"keysThatRemovedBaseModel",[]),le(this,"loadedContainerForKey",new Map),le(this,"loadedMaterialsForKey",new Map),le(this,"scene",void 0),le(this,"renameClonedAsset",void 0),le(this,"setBaseModelEnabled",void 0),this.scene=e,this.renameClonedAsset=t,this.setBaseModelEnabled=i}async applyMaterial(e,t,i,a){return new Promise((n=>{e=this.renameClonedAsset(e);const r=this.scene.materials.filter((t=>t.name===e)),s=this.materialVariantMap.get(e);if(this.materialVariantMap.set(e,{...s,...t}),0===r.length)return void n(void 0);const o=new L(this.scene);o.useDefaultLoadingScreen=!1,r.forEach((e=>se(t,e,o,a))),o.onProgress=(e,t,a)=>{i&&i(e/t*100,100,a.name)},o.onFinish=e=>{e.forEach((e=>{const a=e;i&&i(100,100,e.name),r.forEach((i=>oe(e.name,i,t,a.texture)))})),n(void 0)},o.loadAsync()}))}async applyModel(e,t,i,a){if(i&&t&&!this.keysThatRemovedBaseModel.includes(e)&&this.keysThatRemovedBaseModel.push(e),!i)return this.keysThatRemovedBaseModel.includes(e)&&this.setBaseModelEnabled(!0),this.loadedContainerForKey.get(e)?.dispose(),this.loadedMaterialsForKey.delete(e),Promise.resolve(void 0);this.loadedContainerForKey.has(e)&&(this.loadedContainerForKey.get(e)?.dispose(),this.loadedMaterialsForKey.delete(e)),t&&this.setBaseModelEnabled(!1);const n=(await Z(i,this.scene,a)).instantiateModelsToScene(this.renameClonedAsset,!0);this.loadedContainerForKey.set(e,n),this.loadedMaterialsForKey.set(e,he(n));const r=[];return this.materialVariantMap.forEach((async(e,t)=>{r.push(this.applyMaterial(t,e))})),await Promise.all(r),n}getAllMaterials(){const e=[];return this.loadedMaterialsForKey.forEach((t=>{t.forEach((t=>{e.includes(t)||e.push(t)}))})),e}}function he(e){const t=[];return e.rootNodes.forEach((e=>{e.getChildMeshes().forEach((e=>{e.material&&t.push(e.material),e.subMeshes&&e.subMeshes.forEach((e=>{const i=e.getMaterial(!1);i&&t.push(i)}))}))})),t}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 me{constructor(e){de(this,"id",void 0),de(this,"previewService",void 0),de(this,"scene",void 0),de(this,"variantManager",void 0),de(this,"materialSelectedObservable",new h),de(this,"materialDeselectedObservable",new h),de(this,"materialVariantObservable",new h),de(this,"modelVariantObservable",new h),de(this,"queuedModelAnimation",void 0),de(this,"materialReadyToLoadCallbacks",new Map),de(this,"modelReadyToLoadCallbacks",new Map),de(this,"dynamicTextures",new Map),de(this,"assetContainer",void 0),de(this,"canvasPanels",void 0),de(this,"contextService",void 0),de(this,"importPromise",void 0),de(this,"initialized",!1),de(this,"materials",[]),de(this,"modelInstance",void 0),de(this,"transformRoot",void 0);const{modelDetails:t,previewService:i,progressHandler:a,scene:n}=e;this.contextService=t.contextService,this.id=J(),this.previewService=i,this.scene=n,this.variantManager=new ce(n,this.renameClonedAsset.bind(this),this.setEnabled.bind(this)),this.previewService.registerInitializedListener((async()=>await this.processQueuedEvents()));this.importPromise=(async()=>{this.assetContainer=await Z(t.model,n,a),this.initialized=!0,this.transformRoot=new C("root",this.scene),this.instantiate()})()}async applyMaterialVariant(e,t,i,a){if(100===this.previewService.getSceneInitializationProgress()&&this.initialized)await this.variantManager.applyMaterial(e,i,((e,t,i)=>{this.materialVariantObservable.notifyObservers({remainingCount:e,totalCount:t,taskName:i})}),a);else if(this.materialReadyToLoadCallbacks.has(e)){this.materialReadyToLoadCallbacks.get(e)?.set(t,this.applyMaterialVariant.bind(this,e,t,i,a))}else{this.materialReadyToLoadCallbacks.set(e,new Map);this.materialReadyToLoadCallbacks.get(e)?.set(t,this.applyMaterialVariant.bind(this,e,t,i,a))}}async applyModelVariant(e,t,i){if(100!==this.previewService.getSceneInitializationProgress()||!this.initialized)return void this.modelReadyToLoadCallbacks.set(e,this.applyModelVariant.bind(this,e,t,i));const a=await this.variantManager.applyModel(e,i,t?.model,(t=>{this.modelVariantObservable.notifyObservers({...t,key:e})}));this.modelInstance&&te(this.modelInstance.animationGroups),this.contextService||(this.contextService=t?.contextService),a&&this.configureModelInstance(a)}executeAnimation(e){100===this.previewService.getSceneInitializationProgress()?this.modelInstance&&ee(this.modelInstance.animationGroups,e.loop,e.to,e.from):this.queuedModelAnimation=e}getId(){return this.id}listMaterials(){const e=this.scene?.materials.filter((e=>e.name.startsWith(this.id)));return e?e.map((e=>({id:e.id,name:e.name}))):[]}registerMaterialSelectedCallback(e){this.materialSelectedObservable.add(e)}unregisterMaterialSelectedCallback(e){this.materialSelectedObservable.removeCallback(e)}registerMaterialDeselectedCallback(e){this.materialDeselectedObservable.add(e)}unregisterMaterialDeselectedCallback(e){this.materialDeselectedObservable.removeCallback(e)}get position(){return this.transformRoot.position}set position(e){this.transformRoot.position=new o(e.x,e.y,e.z)}get rotation(){return this.transformRoot.rotation}set rotation(e){this.transformRoot.rotation=new o(e.x,e.y,e.z)}get scale(){return this.transformRoot.scaling}set scale(e){this.transformRoot.scaling=new o(e.x,e.y,e.z)}attachPickingHandler(e){e.rootNodes.forEach((e=>{e.getChildMeshes(!1).forEach((e=>{"targetcube_t"!==e.name&&"backgroundShell"!==e.name&&(e.isPickable=!0,e.actionManager||(e.actionManager=new P(this.scene)),e.actionManager||(e.actionManager=new P(this.scene)),e.actionManager.registerAction(new w(P.OnPointerOutTrigger,(()=>{e.material&&this.materialDeselectedObservable.notifyObservers({id:e.material.id,name:e.material.name})}))),e.actionManager.registerAction(new w(P.OnPickDownTrigger,(t=>{t.meshUnderPointer&&e.material&&this.materialSelectedObservable.notifyObservers({id:e.material.id,name:e.material.name})}))))}))}))}getImportPromise(){return this.importPromise}getQueuedMaterialVariantCount(){return this.materialReadyToLoadCallbacks.size}getQueuedModelVariantCount(){return this.modelReadyToLoadCallbacks.size}configureModelInstance(e){const t=this.transformRoot.position,i=this.transformRoot.rotation,a=this.transformRoot.scaling;this.transformRoot.position=o.Zero(),this.transformRoot.rotation=o.Zero(),this.transformRoot.scaling=o.One(),e.rootNodes.forEach((e=>{e.parent=this.transformRoot})),this.transformRoot.position=t,this.transformRoot.rotation=i,this.transformRoot.scaling=a,this.canvasPanels=this.contextService?.getAll()||new Map,$(this.materials.concat(this.variantManager.getAllMaterials()),this.scene,this.canvasPanels,this.dynamicTextures,`${this.id}_`),this.attachPickingHandler(e)}dispose(){this.modelInstance.dispose(),this.modelInstance=void 0}instantiate(){this.modelInstance=this.assetContainer.instantiateModelsToScene(this.renameClonedAsset.bind(this),!0),this.materials=he(this.modelInstance),this.configureModelInstance(this.modelInstance);if(this.materials.some((e=>"emissiveTexture"in e&&null!==e.emissiveTexture))){new M("GlowLayer",this.scene).intensity=.5}this.processQueuedEvents()}renameClonedAsset(e){return`${this.id}_${e}`}setEnabled(e){e&&!this.modelInstance?this.instantiate():!e&&this.modelInstance&&this.dispose()}updateDynamicTextures(){this.canvasPanels?.forEach(((e,t)=>{const i=this.dynamicTextures.get(t);i&&e.getStaticContextDirty()&&i.isReady()&&(i.update(!1),e.setStaticContextDirty(!1))}))}registerMaterialVariantListener(e){this.materialVariantObservable.add(e)}unregisterMaterialVariantListener(e){this.materialVariantObservable.removeCallback(e)}registerModelVariantListener(e){this.modelVariantObservable.add(e)}unregisterModelVariantListener(e){this.modelVariantObservable.removeCallback(e)}async processQueuedEvents(){100===this.previewService.getSceneInitializationProgress()&&(await Promise.all(Array.from(this.materialReadyToLoadCallbacks.values()).map((e=>Array.from(e.values()).map((e=>e()))))),this.materialReadyToLoadCallbacks.clear(),await Promise.all(Array.from(this.modelReadyToLoadCallbacks.values()).map((e=>e()))),this.modelReadyToLoadCallbacks.clear(),this.queuedModelAnimation&&(this.executeAnimation(this.queuedModelAnimation),this.queuedModelAnimation=void 0))}}function ge(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class ue extends E{constructor(e,t,i,a,n,r,s,l){super(e,t,i,a,n,r,l),ge(this,"lastFocus",new o(0,0,0)),ge(this,"panDenominator",1),this.minZ=.01,this.setRadius(this.radius),this.enableFramingBehavior(),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=pe(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,t){const i=this.getFramingBehavior();i.framingTime=t||800;const a=pe(this._scene),n=a.max.subtract(a.min),r=a.min.add(n.scale(.5));this.setRadius(1.5*n.length()),this.wheelPrecision=100/this.radius,this.panningInertia=0,this.panningOriginTarget.copyFrom(r),this.panDenominator=n.length(),i.zoomOnBoundingInfo(a.min,a.max,void 0,(()=>{e&&e()})),i.framingTime=0}enableAutoRotationBehavior(e=5e3){this.useAutoRotationBehavior=!0;const t=this.getAutoRotationBehavior();t&&(t.idleRotationWaitTime=e)}disableAutoRotationBehavior(){this.useAutoRotationBehavior=!1}setRadius(e){this.radius=e,this.maxZ=1e3*this.radius,this.lowerRadiusLimit=.01*this.radius,this.upperRadiusLimit=1.5*this.radius,this.wheelPrecision=100/this.radius,this.pinchPrecision=300/this.radius}static create(e,t,i){const a=pe(e),n=a.max.subtract(a.min),r=a.min.add(n.scale(.5)),s=new ue("ProductCamera",-Math.PI/2,Math.PI/2,1.5*n.length(),r,e,t);return s.panningInertia=0,s.panningOriginTarget.copyFrom(r),s.panDenominator=n.length(),s.onAfterCheckInputsObservable.add((()=>{s.panningSensibility=1e3/s.panDenominator})),i&&(e.activeCamera=s),s}}function pe(e){if(0===e.meshes.length)return{min:new o(-1,-1,-1),max:new o(1,1,1)};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 be(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class fe{constructor(e,t=!0,i=null){be(this,"renderingPipeline",void 0),be(this,"currentConfiguration",void 0),this.renderingPipeline=new F("default",t,e,i?[i]:void 0,!1),this.renderingPipeline.isSupported&&this.renderingPipeline.prepare()}dispose(){this.renderingPipeline.dispose()}addCamera(e){this.renderingPipeline.isSupported&&this.renderingPipeline.addCamera(e)}removeCamera(e){this.renderingPipeline.isSupported&&this.renderingPipeline.removeCamera(e)}getConfiguration(){return this.currentConfiguration}setConfiguration(e){if(this.renderingPipeline.isSupported){if(this.renderingPipeline.samples=e.antiAliasing?.samples??q.antiAliasing.samples,this.renderingPipeline.fxaaEnabled=e.antiAliasing?.fxaaEnabled??q.antiAliasing.fxaaEnabled,this.renderingPipeline.bloomEnabled=e.bloom?.enabled??q.bloom.enabled,this.renderingPipeline.bloomKernel=e.bloom?.kernel??q.bloom.kernel,this.renderingPipeline.bloomScale=e.bloom?.scale??q.bloom.scale,this.renderingPipeline.bloomThreshold=e.bloom?.threshold??q.bloom.threshold,this.renderingPipeline.bloomWeight=e.bloom?.weight??q.bloom.weight,this.renderingPipeline.chromaticAberrationEnabled=e.chromaticAberration?.enabled??q.chromaticAberration.enabled,this.renderingPipeline.chromaticAberration.aberrationAmount=e.chromaticAberration?.aberrationAmount??q.chromaticAberration.aberrationAmount,this.renderingPipeline.chromaticAberration.radialIntensity=e.chromaticAberration?.radialIntensity??q.chromaticAberration.radialIntensity,this.renderingPipeline.chromaticAberration.direction=e.chromaticAberration?.direction?new l(e.chromaticAberration.direction.x,e.chromaticAberration.direction.y):new l(q.chromaticAberration.direction.x,q.chromaticAberration.direction.y),this.renderingPipeline.imageProcessing.colorCurvesEnabled=e.colorCurves?.enabled??q.colorCurves.enabled,this.renderingPipeline.imageProcessing.colorCurves=e.colorCurves?this.updateColorCurve(e.colorCurves):new S,this.renderingPipeline.depthOfFieldEnabled=e.depthOfField?.enabled??q.depthOfField.enabled,e.depthOfField)switch(e.depthOfField.blurLevel??q.depthOfField.blurLevel){case"Low":this.renderingPipeline.depthOfFieldBlurLevel=D.Low;break;case"Medium":this.renderingPipeline.depthOfFieldBlurLevel=D.Medium;break;case"High":this.renderingPipeline.depthOfFieldBlurLevel=D.High}if(this.renderingPipeline.depthOfField.focalLength=e.depthOfField?.focalLength??q.depthOfField.focalLength,this.renderingPipeline.depthOfField.fStop=e.depthOfField?.fStop??q.depthOfField.fStop,this.renderingPipeline.depthOfField.focusDistance=e.depthOfField?.focusDistance??q.depthOfField.focusDistance,this.renderingPipeline.depthOfField.lensSize=e.depthOfField?.lensSize??q.depthOfField.lensSize,this.renderingPipeline.grainEnabled=e.grain?.enabled??q.grain.enabled,this.renderingPipeline.grain.animated=e.grain?.animated??q.grain.animated,this.renderingPipeline.grain.intensity=e.grain?.intensity??q.grain.intensity,this.renderingPipeline.imageProcessing.contrast=e.misc?.contrast??q.misc.contrast,this.renderingPipeline.imageProcessing.exposure=e.misc?.exposure??q.misc.exposure,this.renderingPipeline.imageProcessing.toneMappingEnabled=e.misc?.toneMappingEnabled??q.misc.toneMappingEnabled,this.renderingPipeline.imageProcessing.toneMappingEnabled)switch(e.misc.toneMappingType??q.misc.toneMappingType){case"Standard":this.renderingPipeline.imageProcessing.toneMappingType=I.TONEMAPPING_STANDARD;break;case"ACES":this.renderingPipeline.imageProcessing.toneMappingType=I.TONEMAPPING_ACES}if(this.renderingPipeline.sharpenEnabled=e.sharpen?.enabled??q.sharpen.enabled,this.renderingPipeline.sharpen.colorAmount=e.sharpen?.colorAmount??q.sharpen.colorAmount,this.renderingPipeline.sharpen.edgeAmount=e.sharpen?.edgeAmount??q.sharpen.edgeAmount,this.renderingPipeline.imageProcessing.vignetteEnabled=e.vignette?.enabled??q.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=q.vignette.center.x,this.renderingPipeline.imageProcessing.vignetteCenterY=q.vignette.center.y),e.vignette)switch(e.vignette?.blendMode??q.vignette.blendMode){case"Multiply":this.renderingPipeline.imageProcessing.vignetteBlendMode=I.VIGNETTEMODE_MULTIPLY;break;case"Opaque":this.renderingPipeline.imageProcessing.vignetteBlendMode=I.VIGNETTEMODE_OPAQUE}e.vignette?.colorRgba?this.renderingPipeline.imageProcessing.vignetteColor=new s(e.vignette.colorRgba.r,e.vignette.colorRgba.g,e.vignette.colorRgba.b,e.vignette.colorRgba.a):e.vignette?.colorHex?this.renderingPipeline.imageProcessing.vignetteColor=s.FromHexString(e.vignette.colorHex):this.renderingPipeline.imageProcessing.vignetteColor=new s(q.vignette.colorRgba.r,q.vignette.colorRgba.g,q.vignette.colorRgba.b,q.vignette.colorRgba.a),this.renderingPipeline.imageProcessing.vignetteStretch=e.vignette?.stretch??q.vignette.stretch,this.renderingPipeline.imageProcessing.vignetteWeight=e.vignette?.weight??q.vignette.weight,this.renderingPipeline.prepare(),this.currentConfiguration=e}}updateColorCurve(e){const t=new S;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}}function ve(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}g.GLTFLoader.RegisterExtension("glbPostProcessor",(function(e){return new Q(e)})),a.OnPluginActivatedObservable.add((e=>{if("gltf"===e.name){e.transparencyAsCoverage=!0}}));class ye{constructor(i){ve(this,"camera",void 0),ve(this,"configuration",void 0),ve(this,"engine",void 0),ve(this,"scene",void 0),ve(this,"loadProgress",new Map([["initialScene",0]])),ve(this,"queuedCameraAnimation",void 0),ve(this,"focusLostNotified",!1),ve(this,"loadObservable",new h),ve(this,"focusLostObservable",new h),ve(this,"initializedCallbacks",[]),ve(this,"isInitialized",!1),ve(this,"highlightLayer",void 0),ve(this,"renderingPipeline",void 0),ve(this,"modelContainers",new Map),ve(this,"plugins",[]);const a=i?.noRender?void 0:document.createElement("canvas");this.configuration=new _(i);c.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"}},a&&(a.getContext("webgl2")||a.getContext("webgl"));const n=console.log;console.log=()=>{};const r=a?new e(a,!0,{adaptToDeviceRatio:!0,limitDeviceRatio:2,premultipliedAlpha:!1,preserveDrawingBuffer:!!i?.backgroundImage,audioEngine:!1,stencil:this.configuration.highlights.enabled,forceSRGBBufferSupportState:!0}):new t;console.log=n,r.hideLoadingUI(),window.addEventListener("resize",this.fireResizeEvent.bind(this)),this.engine=r,this.scene=new m(r),this.camera=ue.create(this.scene,this.configuration),this.renderingPipeline=new fe(this.scene,!0),this.renderingPipeline.addCamera(this.camera),this.scene.imageProcessingConfiguration.exposure=this.configuration.lighting.exposure,this.scene.imageProcessingConfiguration.contrast=this.configuration.lighting.contrast}getEngineContext(){return{engine:this.engine,scene:this.scene,camera:this.camera}}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)}registerInitializedListener(e){this.isInitialized||!this.isInitialized&&this.initializedCallbacks.push(e)}unregisterInitializedListener(e){if(this.isInitialized)return;const t=this.initializedCallbacks.indexOf(e);t>-1&&this.initializedCallbacks.splice(t,1)}getIsInitialized(){return this.isInitialized}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(z.Pan),this.reattachControls(e)}getNumViewports(){return this.engine.views?.length||0}unregisterView(e){this.engine.unRegisterView(e)}shutdown(){this.plugins.forEach((e=>e.dispose(!0))),this.renderingPipeline.dispose(),this.engine&&this.engine.dispose(),window.removeEventListener("resize",this.fireResizeEvent)}getSceneInitializationProgress(){return this.loadProgress.get("initialScene")}async initialize(e){let t;if(this.scene.clearColor=this.configuration.scene.clearColor,this.scene.environmentTexture=n.CreateFromPrefilteredData(this.configuration.scene.environmentFile,this.scene),e){const i=100;t=await this.loadModel(e,(e=>{this.loadProgress.set("initialScene",e.loaded*i/e.total),this.notifyLoadHandlers()}))}return this.loadProgress.set("initialScene",100),this.notifyLoadHandlers(),this.scene.activeCamera=this.camera,this.camera.rerunFramingBehavior(void 0,1),this.configuration.options?.renderingPipelineConfiguration&&this.renderingPipeline.setConfiguration(this.configuration.options.renderingPipelineConfiguration),te(this.scene.animationGroups),this.engine.views?.length>=1&&this.reattachControls(this.engine.views[this.engine.views.length-1].target),await this.processQueuedLoadEvents(),await Promise.all(this.initializedCallbacks.map((e=>e()))),this.initializedCallbacks=[],this.isInitialized=!0,this.engine.runRenderLoop((()=>{this.engine.views&&(this.modelContainers.forEach((e=>{e.updateDynamicTextures()})),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(),this.camera.target.equalsWithEpsilon(this.camera.lastFocus,.1)||this.focusLostNotified||(this.focusLostObservable.notifyObservers(void 0),this.focusLostNotified=!0))})),t}executeCameraAnimation(e){100===this.getSceneInitializationProgress()&&this.camera&&this.scene.activeCamera===this.camera?ie(this.scene,this.scene.activeCamera,e):this.queuedCameraAnimation=e}getCameraPose(){if(this.scene&&this.camera)return{lonDeg:Math.round(180*this.camera.alpha/Math.PI),latDeg:Math.round(180*this.camera.beta/Math.PI),radius:Math.round(1e4*(this.camera.radius+Number.EPSILON))/1e4,target:{x:this.camera.target.x,y:this.camera.target.y,z:this.camera.target.z}}}setCameraPose(e){this.scene&&this.camera&&(this.camera.target=new o(e.target.x,e.target.y,e.target.z),this.camera.radius=e.radius,this.camera.alpha=e.latDeg,this.camera.beta=e.lonDeg)}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===z.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.configuration;this.camera.rerunFramingBehavior((()=>{this.focusLostNotified=!1,t.camera.limits.min.radius&&(this.camera.lowerRadiusLimit=t.camera.limits.min.radius),t.camera.limits.max.radius&&(this.camera.upperRadiusLimit=t.camera.limits.max.radius),e()}))}))}setAutoRotation(e){this.configuration.camera.autoRotation.enabled&&this.camera&&(e?this.camera.enableAutoRotationBehavior(this.configuration.camera.autoRotation.idleTimeMs):this.camera.disableAutoRotationBehavior())}getCurrentConfiguration(){return this.configuration.options}async renderSceneScreenshot(e,t){if(!this.camera)throw new Error("Missing product camera, cannot render screenshot!");var i;(i=this.camera).getScene().stopAnimation(i),i.animations=[];const a=this.camera.alpha,n=this.camera.beta,r=this.camera.radius,s=t.latDeg*Math.PI/180,o=t.lonDeg*Math.PI/180;this.camera.alpha=o,this.camera.beta=s,this.camera.radius=t.radius||this.camera.radius;const l=await d.CreateScreenshotUsingRenderTargetAsync(this.engine,this.camera,e,"image/png",2,!0);return this.camera.alpha=a,this.camera.beta=n,this.camera.radius=r,l}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()}setHighlights(e,t){0===e.length&&(this.highlightLayer?.dispose(),this.highlightLayer=void 0),this.highlightLayer||(this.highlightLayer=new i("highlights",this.scene,{isStroke:!0,blurVerticalSize:.85,blurHorizontalSize:.85}),this.highlightLayer.innerGlow=!0,this.highlightLayer.outerGlow=!1),this.highlightLayer.removeAllMeshes();const a=t?new r(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,a||r.FromHexString("#fcba03"))))}))}setRenderingPipelineConfiguration(e){this.renderingPipeline&&this.renderingPipeline.setConfiguration(e)}async loadModel(e,t){const i=new me({modelDetails:e,scene:this.scene,previewService:this,progressHandler:t});return i.registerMaterialVariantListener((e=>this.handleMaterialProgressCallback(e.remainingCount,e.totalCount,e.taskName))),i.registerModelVariantListener((e=>this.handleModelProgressCallback(e,e.key))),this.configuration.highlights.enabled&&(i.registerMaterialSelectedCallback((e=>{this.setHighlights([e])})),i.registerMaterialDeselectedCallback((()=>{this.setHighlights([])}))),this.modelContainers.set(i.getId(),i),await i.getImportPromise(),i}getAllModels(){return Array.from(this.modelContainers.values())}getModelById(e){return this.modelContainers.get(e)}registerPlugin(e){this.plugins.push(e),e.initialize(this,{camera:this.camera,engine:this.engine,scene:this.scene})}unregisterPlugin(e){const t=this.plugins.indexOf(e);if(t>-1){this.plugins.splice(t,1).forEach((e=>e.dispose(!1)))}}handleMaterialProgressCallback(e,t,i){this.loadProgress.set(`key_${i}`,e/t*100),this.notifyLoadHandlers()}handleModelProgressCallback(e,t){this.loadProgress.set(t,100*e.loaded/e.total),this.notifyLoadHandlers()}reattachControls(e,t=2){if(this.scene.detachControl(),this.engine.inputElement=e,this.camera){this.camera.attachControl(!0,!1,t);this.camera.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(){this.queuedCameraAnimation&&(this.executeCameraAnimation(this.queuedCameraAnimation),this.queuedCameraAnimation=void 0)}}export{z as ProductCameraRig,j as MaterialEffectMode,ye as SpiffCommerce3DPreviewService,U as RenderingConfiguration,W as REFLECTION_PROBE_RESOLUTION,q as renderingPipelineDefaults};
|
|
1
|
+
import{Engine as e}from"@babylonjs/core/Engines/engine";import{NullEngine as t}from"@babylonjs/core/Engines/nullEngine";import{HighlightLayer as i}from"@babylonjs/core/Layers/highlightLayer";import{SceneLoader as a}from"@babylonjs/core/Loading/sceneLoader";import{CubeTexture as n}from"@babylonjs/core/Materials/Textures/cubeTexture";import{Color3 as r,Color4 as s}from"@babylonjs/core/Maths/math.color";import{Vector3 as o,Vector2 as l}from"@babylonjs/core/Maths/math.vector";import{DracoCompression as c}from"@babylonjs/core/Meshes/Compression/dracoCompression";import{Observable as h}from"@babylonjs/core/Misc/observable";import{Tools as d}from"@babylonjs/core/Misc/tools";import{Scene as m}from"@babylonjs/core/scene";import{GLTF2 as g}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{PBRMaterial as u}from"@babylonjs/core/Materials/PBR/pbrMaterial";import{MirrorTexture as p}from"@babylonjs/core/Materials/Textures/mirrorTexture";import{Color3 as b,Vector3 as f,Plane as v}from"@babylonjs/core/Maths/math";import{ReflectionProbe as y}from"@babylonjs/core/Probes/reflectionProbe";import{ActionManager as P}from"@babylonjs/core/Actions/actionManager";import{ExecuteCodeAction as w}from"@babylonjs/core/Actions/directActions";import{GlowLayer as M}from"@babylonjs/core/Layers/glowLayer";import{TransformNode as C}from"@babylonjs/core/Meshes/transformNode";import{DynamicTexture as x}from"@babylonjs/core/Materials/Textures/dynamicTexture";import{Texture as O}from"@babylonjs/core/Materials/Textures/texture";import{Animation as A}from"@babylonjs/core/Animations/animation";import{QuadraticEase as R,EasingFunction as T}from"@babylonjs/core/Animations/easing";import{AssetsManager as L}from"@babylonjs/core/Misc/assetsManager";import{ArcRotateCamera as E}from"@babylonjs/core/Cameras/arcRotateCamera";import{ColorCurves as S}from"@babylonjs/core/Materials/colorCurves";import{ImageProcessingConfiguration as I}from"@babylonjs/core/Materials/imageProcessingConfiguration";import{DefaultRenderingPipeline as F}from"@babylonjs/core/PostProcesses/RenderPipeline";import{DepthOfFieldEffectBlurLevel as D}from"@babylonjs/core/PostProcesses/depthOfFieldEffect";import"@babylonjs/core/Rendering/depthRendererSceneComponent";function k(e,t,i,a){Object.defineProperty(e,t,{get:i,set:a,enumerable:!0,configurable:!0})}var B={};let z;var N;let j;var V;k(B,"ProductCameraRig",(()=>z)),k(B,"MaterialEffectMode",(()=>j)),(N=z||(z={}))[N.Orbit=0]="Orbit",N[N.Pan=1]="Pan",(V=j||(j={})).None="None",V.RemoveWhenSelected="RemoveWhenSelected",V.ApplyWhenSelected="ApplyWhenSelected";function H(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}k({},"SpiffCommerce3DPreviewService",(()=>ye));class _{constructor(e){H(this,"customOptions",void 0),H(this,"getSceneClearColor",(()=>{const e=this.customOptions?.transparentBackground||this.customOptions?.backgroundImage?0:1;if(this.customOptions&&this.customOptions?.transparentBackground||this.customOptions?.backgroundImage)return new s(0,0,0,e).toLinearSpace();if(this.customOptions&&this.customOptions.backgroundColor){const t=r.FromHexString(this.customOptions.backgroundColor);return new s(t.r,t.g,t.b,e).toLinearSpace()}return new s(.98,.98,.98,e).toLinearSpace()})),H(this,"highlightColorFromConfig",(()=>this.customOptions&&this.customOptions.highlightColor?this.hexToColor4(this.customOptions.highlightColor):new s(.98,.98,.98,1).toLinearSpace())),H(this,"hexToColor4",((e,t=1)=>{const i=r.FromHexString(e);return new s(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 G={};k(G,"RenderingConfiguration",(()=>U)),k(G,"REFLECTION_PROBE_RESOLUTION",(()=>W)),k(G,"renderingPipelineDefaults",(()=>q));class U{static getDynamicTextureResolution(){return this.getIsMobile()||!U.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 W=128,q={antiAliasing:{samples:4,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,center:{x:0,y:0},colorHex:"#000000ff",colorRgba:{r:0,g:0,b:0,a:1},stretch:0,weight:1}};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 Q{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 a=t.extras[i];e.metadata[i]=a})),i(e)}))}async loadMaterialPropertiesAsync(e,t,i){await this.loader.loadMaterialPropertiesAsync(e,t,i),this.enableMaterialExtrasIfRequired(t,i)}dispose(){}enableMaterialExtrasIfRequired(e,t){if(e.extras&&t instanceof u){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 b(e.extras.translucencyR,e.extras.translucencyG,e.extras.translucencyB))}if(e.extras.refractionIOR){const i=t;i.subSurface.isRefractionEnabled=!0,i.subSurface.volumeIndexOfRefraction=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",U.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=f.TransformNormal(new f(s[0],s[1],s[2]),o).normalize(),c=v.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 y("probe-"+a.name,W,e);n.attachToMesh(i),n.renderList&&n.renderList.push(...t(e)),a.reflectionTexture=n.cubeTexture}(i))}))}}const Y=new Map;async function Z(e,t,i){return new Promise(((n,r)=>{const s=Y.get(e);if(s&&s.scene.uid===t.uid)return n(s);a.LoadAssetContainerAsync(e,void 0,t,i).then((t=>{Y.set(e,t),n(t)})).catch(r)}))}function $(t,i,a,n,r=""){a.forEach((a=>{const s=a.getID(),o=a.getName(),l=U.getDynamicTextureResolution();t.filter((e=>e.name===r+o)).forEach((t=>{const r=n.get(s);if(r)X(t,r),r.update(false);else{const r=function(t,i,a,n){const r=new x(t,{width:a,height:n},i,U.shouldMipMap(),O.TRILINEAR_SAMPLINGMODE,e.TEXTUREFORMAT_RGBA),s=r.getContext();s&&(s.fillStyle="#f5f5f5",s.fillRect(0,0,a,n),r.update());return r}(o,i,l.width,l.height);n.set(s,r),a.setStaticContext(r.getContext()),X(t,r),r.onLoadObservable.addOnce((()=>{r.update(false)}))}}))}))}function X(e,t){if(e instanceof u){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 J(){const e=()=>Math.floor(65536*(1+Math.random())).toString(16).substring(1);return e()+e()+"-"+e()+"-"+e()+"-"+e()+"-"+e()+e()+e()}function ee(e,t,i,a){const n=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?e.forEach((e=>{e.stop();const r=n(e);e.start(t,1,a*r,i*r)})):e.forEach((e=>{e.stop();const i=n(e),r=a*i;e.start(t,1,r,r)}))}function te(e){e.forEach((e=>{e.stop()}))}function ie(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=[],l=i.target,c=l?1:0;if(i.target&&Object.keys(i.target).length>0&&s.push(ne("cameraTargetLerp","target",(new o).copyFrom(t.target),new o(i.target.x,i.target.y,i.target.z),A.ANIMATIONTYPE_VECTOR3,0)),s.push(ne("cameraAlphaLerp","alpha",t.alpha,ae(i.lonDeg),A.ANIMATIONTYPE_FLOAT,c)),s.push(ne("cameraBetaLerp","beta",t.beta,ae(i.latDeg),A.ANIMATIONTYPE_FLOAT,c)),void 0!==i.radius){const e=Math.max(.01,i.radius);s.push(ne("cameraRadiusLerp","radius",t.radius,e,A.ANIMATIONTYPE_FLOAT,c))}t.animations.push(...s);const h=t.useAutoRotationBehavior;t.disableAutoRotationBehavior(),e.beginAnimation(t,0,l?120:60,!1,1,(()=>{t.animations=[],h&&t.enableAutoRotationBehavior()}))}function ae(e){return e*Math.PI/180}function ne(e,t,i,a,n,r=0,s=A.ANIMATIONLOOPMODE_CONSTANT){const o=new R;o.setEasingMode(T.EASINGMODE_EASEINOUT);const l=new A(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}const re={albedoTexture:"albedoMap",bumpTexture:"normalMap",ambientTexture:"ambientMap",emissiveTexture:"emissionMap",opacityTexture:"alphaMap",metallicTexture:"metallicMap",refractionTexture:"refractionMap"};function se(e,t,i,a){["albedoTexture","bumpTexture","ambientTexture","emissiveTexture","opacityTexture","metallicTexture","refractionTexture"].forEach((n=>{!function(e,t,i,a,n){const r=re[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===j.RemoveWhenSelected?(t.clearCoat.isEnabled=!1,t.clearCoat.indexOfRefraction=1.5):e.clearCoat===j.ApplyWhenSelected&&(t.clearCoat.isEnabled=!0,t.clearCoat.indexOfRefraction=e.clearCoatIOR||t.clearCoat.indexOfRefraction)}(e,t)}function oe(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 le(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class ce{constructor(e,t,i){le(this,"materialVariantMap",new Map),le(this,"keysThatRemovedBaseModel",[]),le(this,"loadedContainerForKey",new Map),le(this,"loadedMaterialsForKey",new Map),le(this,"scene",void 0),le(this,"renameClonedAsset",void 0),le(this,"setBaseModelEnabled",void 0),this.scene=e,this.renameClonedAsset=t,this.setBaseModelEnabled=i}async applyMaterial(e,t,i,a){return new Promise((n=>{e=this.renameClonedAsset(e);const r=this.scene.materials.filter((t=>t.name===e)),s=this.materialVariantMap.get(e);if(this.materialVariantMap.set(e,{...s,...t}),0===r.length)return void n(void 0);const o=new L(this.scene);o.useDefaultLoadingScreen=!1,r.forEach((e=>se(t,e,o,a))),o.onProgress=(e,t,a)=>{i&&i(e/t*100,100,a.name)},o.onFinish=e=>{e.forEach((e=>{const a=e;i&&i(100,100,e.name),r.forEach((i=>oe(e.name,i,t,a.texture)))})),n(void 0)},o.loadAsync()}))}async applyModel(e,t,i,a){if(i&&t&&!this.keysThatRemovedBaseModel.includes(e)&&this.keysThatRemovedBaseModel.push(e),!i)return this.keysThatRemovedBaseModel.includes(e)&&this.setBaseModelEnabled(!0),this.loadedContainerForKey.get(e)?.dispose(),this.loadedMaterialsForKey.delete(e),Promise.resolve(void 0);this.loadedContainerForKey.has(e)&&(this.loadedContainerForKey.get(e)?.dispose(),this.loadedMaterialsForKey.delete(e)),t&&this.setBaseModelEnabled(!1);const n=(await Z(i,this.scene,a)).instantiateModelsToScene(this.renameClonedAsset,!0);this.loadedContainerForKey.set(e,n),this.loadedMaterialsForKey.set(e,he(n));const r=[];return this.materialVariantMap.forEach((async(e,t)=>{r.push(this.applyMaterial(t,e))})),await Promise.all(r),n}getAllMaterials(){const e=[];return this.loadedMaterialsForKey.forEach((t=>{t.forEach((t=>{e.includes(t)||e.push(t)}))})),e}}function he(e){const t=[];return e.rootNodes.forEach((e=>{e.getChildMeshes().forEach((e=>{e.material&&t.push(e.material),e.subMeshes&&e.subMeshes.forEach((e=>{const i=e.getMaterial(!1);i&&t.push(i)}))}))})),t}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 me{constructor(e){de(this,"id",void 0),de(this,"previewService",void 0),de(this,"scene",void 0),de(this,"variantManager",void 0),de(this,"materialSelectedObservable",new h),de(this,"materialDeselectedObservable",new h),de(this,"materialVariantObservable",new h),de(this,"modelVariantObservable",new h),de(this,"queuedModelAnimation",void 0),de(this,"materialReadyToLoadCallbacks",new Map),de(this,"modelReadyToLoadCallbacks",new Map),de(this,"dynamicTextures",new Map),de(this,"assetContainer",void 0),de(this,"canvasPanels",void 0),de(this,"contextService",void 0),de(this,"importPromise",void 0),de(this,"initialized",!1),de(this,"materials",[]),de(this,"modelInstance",void 0),de(this,"transformRoot",void 0);const{modelDetails:t,previewService:i,progressHandler:a,scene:n}=e;this.contextService=t.contextService,this.id=J(),this.previewService=i,this.scene=n,this.variantManager=new ce(n,this.renameClonedAsset.bind(this),this.setEnabled.bind(this)),this.previewService.registerInitializedListener((async()=>await this.processQueuedEvents()));this.importPromise=(async()=>(this.assetContainer=await Z(t.model,n,a),this.initialized=!0,this.transformRoot=new C("root",this.scene),this.instantiate(),this))()}async applyMaterialVariant(e,t,i,a){if(100===this.previewService.getSceneInitializationProgress()&&this.initialized)await this.variantManager.applyMaterial(e,i,((e,t,i)=>{this.materialVariantObservable.notifyObservers({remainingCount:e,totalCount:t,taskName:i})}),a);else if(this.materialReadyToLoadCallbacks.has(e)){this.materialReadyToLoadCallbacks.get(e)?.set(t,this.applyMaterialVariant.bind(this,e,t,i,a))}else{this.materialReadyToLoadCallbacks.set(e,new Map);this.materialReadyToLoadCallbacks.get(e)?.set(t,this.applyMaterialVariant.bind(this,e,t,i,a))}}async applyModelVariant(e,t,i){if(100!==this.previewService.getSceneInitializationProgress()||!this.initialized)return void this.modelReadyToLoadCallbacks.set(e,this.applyModelVariant.bind(this,e,t,i));const a=await this.variantManager.applyModel(e,i,t?.model,(t=>{this.modelVariantObservable.notifyObservers({...t,key:e})}));this.modelInstance&&te(this.modelInstance.animationGroups),this.contextService||(this.contextService=t?.contextService),a&&this.configureModelInstance(a)}executeAnimation(e){100===this.previewService.getSceneInitializationProgress()?this.modelInstance&&ee(this.modelInstance.animationGroups,e.loop,e.to,e.from):this.queuedModelAnimation=e}getId(){return this.id}listMaterials(){const e=this.scene?.materials.filter((e=>e.name.startsWith(this.id)));return e?e.map((e=>({id:e.id,name:e.name}))):[]}registerMaterialSelectedCallback(e){this.materialSelectedObservable.add(e)}unregisterMaterialSelectedCallback(e){this.materialSelectedObservable.removeCallback(e)}registerMaterialDeselectedCallback(e){this.materialDeselectedObservable.add(e)}unregisterMaterialDeselectedCallback(e){this.materialDeselectedObservable.removeCallback(e)}get position(){return this.transformRoot.position}set position(e){this.transformRoot.position=new o(e.x,e.y,e.z)}get rotation(){return this.transformRoot.rotation}set rotation(e){this.transformRoot.rotation=new o(e.x,e.y,e.z)}get scale(){return this.transformRoot.scaling}set scale(e){this.transformRoot.scaling=new o(e.x,e.y,e.z)}attachPickingHandler(e){e.rootNodes.forEach((e=>{e.getChildMeshes(!1).forEach((e=>{"targetcube_t"!==e.name&&"backgroundShell"!==e.name&&(e.isPickable=!0,e.actionManager||(e.actionManager=new P(this.scene)),e.actionManager||(e.actionManager=new P(this.scene)),e.actionManager.registerAction(new w(P.OnPointerOutTrigger,(()=>{e.material&&this.materialDeselectedObservable.notifyObservers({id:e.material.id,name:e.material.name})}))),e.actionManager.registerAction(new w(P.OnPickDownTrigger,(t=>{t.meshUnderPointer&&e.material&&this.materialSelectedObservable.notifyObservers({id:e.material.id,name:e.material.name})}))))}))}))}getInitializationPromise(){return this.importPromise}getIsInitialized(){return this.initialized}getQueuedMaterialVariantCount(){return this.materialReadyToLoadCallbacks.size}getQueuedModelVariantCount(){return this.modelReadyToLoadCallbacks.size}configureModelInstance(e){const t=this.transformRoot.position,i=this.transformRoot.rotation,a=this.transformRoot.scaling;this.transformRoot.position=o.Zero(),this.transformRoot.rotation=o.Zero(),this.transformRoot.scaling=o.One(),e.rootNodes.forEach((e=>{e.parent=this.transformRoot})),this.transformRoot.position=t,this.transformRoot.rotation=i,this.transformRoot.scaling=a,this.canvasPanels=this.contextService?.getAll()||new Map,$(this.materials.concat(this.variantManager.getAllMaterials()),this.scene,this.canvasPanels,this.dynamicTextures,`${this.id}_`),this.attachPickingHandler(e)}dispose(){this.modelInstance.dispose(),this.modelInstance=void 0}instantiate(){this.modelInstance=this.assetContainer.instantiateModelsToScene(this.renameClonedAsset.bind(this),!0),this.materials=he(this.modelInstance),this.configureModelInstance(this.modelInstance);if(this.materials.some((e=>"emissiveTexture"in e&&null!==e.emissiveTexture))){new M("GlowLayer",this.scene).intensity=.5}this.processQueuedEvents()}renameClonedAsset(e){return`${this.id}_${e}`}setEnabled(e){e&&!this.modelInstance?this.instantiate():!e&&this.modelInstance&&this.dispose()}updateDynamicTextures(){this.canvasPanels?.forEach(((e,t)=>{const i=this.dynamicTextures.get(t);i&&e.getStaticContextDirty()&&i.isReady()&&(i.update(!1),e.setStaticContextDirty(!1))}))}registerMaterialVariantListener(e){this.materialVariantObservable.add(e)}unregisterMaterialVariantListener(e){this.materialVariantObservable.removeCallback(e)}registerModelVariantListener(e){this.modelVariantObservable.add(e)}unregisterModelVariantListener(e){this.modelVariantObservable.removeCallback(e)}async processQueuedEvents(){100===this.previewService.getSceneInitializationProgress()&&(await Promise.all(Array.from(this.materialReadyToLoadCallbacks.values()).map((e=>Array.from(e.values()).map((e=>e()))))),this.materialReadyToLoadCallbacks.clear(),await Promise.all(Array.from(this.modelReadyToLoadCallbacks.values()).map((e=>e()))),this.modelReadyToLoadCallbacks.clear(),this.queuedModelAnimation&&(this.executeAnimation(this.queuedModelAnimation),this.queuedModelAnimation=void 0))}}function ge(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class ue extends E{constructor(e,t,i,a,n,r,s,l){super(e,t,i,a,n,r,l),ge(this,"lastFocus",new o(0,0,0)),ge(this,"panDenominator",1),this.minZ=.01,this.setRadius(this.radius),this.enableFramingBehavior(),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=pe(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,t){const i=this.getFramingBehavior();i.framingTime=t||800;const a=pe(this._scene),n=a.max.subtract(a.min),r=a.min.add(n.scale(.5));this.setRadius(1.5*n.length()),this.wheelPrecision=100/this.radius,this.panningInertia=0,this.panningOriginTarget.copyFrom(r),this.panDenominator=n.length(),i.zoomOnBoundingInfo(a.min,a.max,void 0,(()=>{e&&e()})),i.framingTime=0}enableAutoRotationBehavior(e=5e3){this.useAutoRotationBehavior=!0;const t=this.getAutoRotationBehavior();t&&(t.idleRotationWaitTime=e)}disableAutoRotationBehavior(){this.useAutoRotationBehavior=!1}setRadius(e){this.radius=e,this.maxZ=1e3*this.radius,this.lowerRadiusLimit=.01*this.radius,this.upperRadiusLimit=1.5*this.radius,this.wheelPrecision=100/this.radius,this.pinchPrecision=300/this.radius}static create(e,t,i){const a=pe(e),n=a.max.subtract(a.min),r=a.min.add(n.scale(.5)),s=new ue("ProductCamera",-Math.PI/2,Math.PI/2,1.5*n.length(),r,e,t);return s.panningInertia=0,s.panningOriginTarget.copyFrom(r),s.panDenominator=n.length(),s.onAfterCheckInputsObservable.add((()=>{s.panningSensibility=1e3/s.panDenominator})),i&&(e.activeCamera=s),s}}function pe(e){if(0===e.meshes.length)return{min:new o(-1,-1,-1),max:new o(1,1,1)};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 be(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}class fe{constructor(e,t=!0,i=null){be(this,"renderingPipeline",void 0),be(this,"currentConfiguration",void 0),this.renderingPipeline=new F("default",t,e,i?[i]:void 0,!1),this.renderingPipeline.isSupported&&this.renderingPipeline.prepare()}dispose(){this.renderingPipeline.dispose()}addCamera(e){this.renderingPipeline.isSupported&&this.renderingPipeline.addCamera(e)}removeCamera(e){this.renderingPipeline.isSupported&&this.renderingPipeline.removeCamera(e)}getConfiguration(){return this.currentConfiguration}setConfiguration(e){if(this.renderingPipeline.isSupported){if(this.renderingPipeline.samples=e.antiAliasing?.samples??q.antiAliasing.samples,this.renderingPipeline.fxaaEnabled=e.antiAliasing?.fxaaEnabled??q.antiAliasing.fxaaEnabled,this.renderingPipeline.bloomEnabled=e.bloom?.enabled??q.bloom.enabled,this.renderingPipeline.bloomKernel=e.bloom?.kernel??q.bloom.kernel,this.renderingPipeline.bloomScale=e.bloom?.scale??q.bloom.scale,this.renderingPipeline.bloomThreshold=e.bloom?.threshold??q.bloom.threshold,this.renderingPipeline.bloomWeight=e.bloom?.weight??q.bloom.weight,this.renderingPipeline.chromaticAberrationEnabled=e.chromaticAberration?.enabled??q.chromaticAberration.enabled,this.renderingPipeline.chromaticAberration.aberrationAmount=e.chromaticAberration?.aberrationAmount??q.chromaticAberration.aberrationAmount,this.renderingPipeline.chromaticAberration.radialIntensity=e.chromaticAberration?.radialIntensity??q.chromaticAberration.radialIntensity,this.renderingPipeline.chromaticAberration.direction=e.chromaticAberration?.direction?new l(e.chromaticAberration.direction.x,e.chromaticAberration.direction.y):new l(q.chromaticAberration.direction.x,q.chromaticAberration.direction.y),this.renderingPipeline.imageProcessing.colorCurvesEnabled=e.colorCurves?.enabled??q.colorCurves.enabled,this.renderingPipeline.imageProcessing.colorCurves=e.colorCurves?this.updateColorCurve(e.colorCurves):new S,this.renderingPipeline.depthOfFieldEnabled=e.depthOfField?.enabled??q.depthOfField.enabled,e.depthOfField)switch(e.depthOfField.blurLevel??q.depthOfField.blurLevel){case"Low":this.renderingPipeline.depthOfFieldBlurLevel=D.Low;break;case"Medium":this.renderingPipeline.depthOfFieldBlurLevel=D.Medium;break;case"High":this.renderingPipeline.depthOfFieldBlurLevel=D.High}if(this.renderingPipeline.depthOfField.focalLength=e.depthOfField?.focalLength??q.depthOfField.focalLength,this.renderingPipeline.depthOfField.fStop=e.depthOfField?.fStop??q.depthOfField.fStop,this.renderingPipeline.depthOfField.focusDistance=e.depthOfField?.focusDistance??q.depthOfField.focusDistance,this.renderingPipeline.depthOfField.lensSize=e.depthOfField?.lensSize??q.depthOfField.lensSize,this.renderingPipeline.grainEnabled=e.grain?.enabled??q.grain.enabled,this.renderingPipeline.grain.animated=e.grain?.animated??q.grain.animated,this.renderingPipeline.grain.intensity=e.grain?.intensity??q.grain.intensity,this.renderingPipeline.imageProcessing.contrast=e.misc?.contrast??q.misc.contrast,this.renderingPipeline.imageProcessing.exposure=e.misc?.exposure??q.misc.exposure,this.renderingPipeline.imageProcessing.toneMappingEnabled=e.misc?.toneMappingEnabled??q.misc.toneMappingEnabled,this.renderingPipeline.imageProcessing.toneMappingEnabled)switch(e.misc.toneMappingType??q.misc.toneMappingType){case"Standard":this.renderingPipeline.imageProcessing.toneMappingType=I.TONEMAPPING_STANDARD;break;case"ACES":this.renderingPipeline.imageProcessing.toneMappingType=I.TONEMAPPING_ACES}if(this.renderingPipeline.sharpenEnabled=e.sharpen?.enabled??q.sharpen.enabled,this.renderingPipeline.sharpen.colorAmount=e.sharpen?.colorAmount??q.sharpen.colorAmount,this.renderingPipeline.sharpen.edgeAmount=e.sharpen?.edgeAmount??q.sharpen.edgeAmount,this.renderingPipeline.imageProcessing.vignetteEnabled=e.vignette?.enabled??q.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=q.vignette.center.x,this.renderingPipeline.imageProcessing.vignetteCenterY=q.vignette.center.y),e.vignette)switch(e.vignette?.blendMode??q.vignette.blendMode){case"Multiply":this.renderingPipeline.imageProcessing.vignetteBlendMode=I.VIGNETTEMODE_MULTIPLY;break;case"Opaque":this.renderingPipeline.imageProcessing.vignetteBlendMode=I.VIGNETTEMODE_OPAQUE}e.vignette?.colorRgba?this.renderingPipeline.imageProcessing.vignetteColor=new s(e.vignette.colorRgba.r,e.vignette.colorRgba.g,e.vignette.colorRgba.b,e.vignette.colorRgba.a):e.vignette?.colorHex?this.renderingPipeline.imageProcessing.vignetteColor=s.FromHexString(e.vignette.colorHex):this.renderingPipeline.imageProcessing.vignetteColor=new s(q.vignette.colorRgba.r,q.vignette.colorRgba.g,q.vignette.colorRgba.b,q.vignette.colorRgba.a),this.renderingPipeline.imageProcessing.vignetteStretch=e.vignette?.stretch??q.vignette.stretch,this.renderingPipeline.imageProcessing.vignetteWeight=e.vignette?.weight??q.vignette.weight,this.renderingPipeline.prepare(),this.currentConfiguration=e}}updateColorCurve(e){const t=new S;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}}function ve(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}g.GLTFLoader.RegisterExtension("glbPostProcessor",(function(e){return new Q(e)})),a.OnPluginActivatedObservable.add((e=>{if("gltf"===e.name){e.transparencyAsCoverage=!0}}));class ye{constructor(i){ve(this,"camera",void 0),ve(this,"configuration",void 0),ve(this,"engine",void 0),ve(this,"scene",void 0),ve(this,"loadProgress",new Map([["initialScene",0]])),ve(this,"queuedCameraAnimation",void 0),ve(this,"focusLostNotified",!1),ve(this,"loadObservable",new h),ve(this,"focusLostObservable",new h),ve(this,"initializedCallbacks",[]),ve(this,"isInitialized",!1),ve(this,"highlightLayer",void 0),ve(this,"renderingPipeline",void 0),ve(this,"modelContainers",new Map),ve(this,"plugins",[]);const a=i?.noRender?void 0:document.createElement("canvas");this.configuration=new _(i);c.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"}},a&&(a.getContext("webgl2")||a.getContext("webgl"));const n=console.log;console.log=()=>{};const r=a?new e(a,!0,{adaptToDeviceRatio:!0,limitDeviceRatio:2,premultipliedAlpha:!1,preserveDrawingBuffer:!!i?.backgroundImage,audioEngine:!1,stencil:this.configuration.highlights.enabled,forceSRGBBufferSupportState:!0}):new t;console.log=n,r.hideLoadingUI(),window.addEventListener("resize",this.fireResizeEvent.bind(this)),this.engine=r,this.scene=new m(r),this.camera=ue.create(this.scene,this.configuration),this.renderingPipeline=new fe(this.scene,!0),this.renderingPipeline.addCamera(this.camera),this.scene.imageProcessingConfiguration.exposure=this.configuration.lighting.exposure,this.scene.imageProcessingConfiguration.contrast=this.configuration.lighting.contrast}getEngineContext(){return{engine:this.engine,scene:this.scene,camera:this.camera}}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)}registerInitializedListener(e){this.isInitialized||!this.isInitialized&&this.initializedCallbacks.push(e)}unregisterInitializedListener(e){if(this.isInitialized)return;const t=this.initializedCallbacks.indexOf(e);t>-1&&this.initializedCallbacks.splice(t,1)}getIsInitialized(){return this.isInitialized}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(z.Pan),this.reattachControls(e)}getNumViewports(){return this.engine.views?.length||0}unregisterView(e){this.engine.unRegisterView(e)}shutdown(){this.plugins.forEach((e=>e.dispose(!0))),this.renderingPipeline.dispose(),this.engine&&this.engine.dispose(),window.removeEventListener("resize",this.fireResizeEvent)}getSceneInitializationProgress(){return this.loadProgress.get("initialScene")}async initialize(e){let t;if(this.scene.clearColor=this.configuration.scene.clearColor,this.scene.environmentTexture=n.CreateFromPrefilteredData(this.configuration.scene.environmentFile,this.scene),e){const i=100;t=await this.loadModel(e,(e=>{this.loadProgress.set("initialScene",e.loaded*i/e.total),this.notifyLoadHandlers()})).getInitializationPromise()}return this.loadProgress.set("initialScene",100),this.notifyLoadHandlers(),this.scene.activeCamera=this.camera,this.camera.rerunFramingBehavior(void 0,1),this.configuration.options?.renderingPipelineConfiguration&&this.renderingPipeline.setConfiguration(this.configuration.options.renderingPipelineConfiguration),te(this.scene.animationGroups),this.engine.views?.length>=1&&this.reattachControls(this.engine.views[this.engine.views.length-1].target),await this.processQueuedLoadEvents(),await Promise.all(this.initializedCallbacks.map((e=>e()))),this.initializedCallbacks=[],this.isInitialized=!0,this.engine.runRenderLoop((()=>{this.engine.views&&(this.modelContainers.forEach((e=>{e.updateDynamicTextures()})),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(),this.camera.target.equalsWithEpsilon(this.camera.lastFocus,.1)||this.focusLostNotified||(this.focusLostObservable.notifyObservers(void 0),this.focusLostNotified=!0))})),t}executeCameraAnimation(e){100===this.getSceneInitializationProgress()&&this.camera&&this.scene.activeCamera===this.camera?ie(this.scene,this.scene.activeCamera,e):this.queuedCameraAnimation=e}getCameraPose(){if(this.scene&&this.camera)return{lonDeg:Math.round(180*this.camera.alpha/Math.PI),latDeg:Math.round(180*this.camera.beta/Math.PI),radius:Math.round(1e4*(this.camera.radius+Number.EPSILON))/1e4,target:{x:this.camera.target.x,y:this.camera.target.y,z:this.camera.target.z}}}setCameraPose(e){this.scene&&this.camera&&(this.camera.target=new o(e.target.x,e.target.y,e.target.z),this.camera.radius=e.radius,this.camera.alpha=e.latDeg,this.camera.beta=e.lonDeg)}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===z.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.configuration;this.camera.rerunFramingBehavior((()=>{this.focusLostNotified=!1,t.camera.limits.min.radius&&(this.camera.lowerRadiusLimit=t.camera.limits.min.radius),t.camera.limits.max.radius&&(this.camera.upperRadiusLimit=t.camera.limits.max.radius),e()}))}))}setAutoRotation(e){this.configuration.camera.autoRotation.enabled&&this.camera&&(e?this.camera.enableAutoRotationBehavior(this.configuration.camera.autoRotation.idleTimeMs):this.camera.disableAutoRotationBehavior())}getCurrentConfiguration(){return this.configuration.options}async renderSceneScreenshot(e,t){if(!this.camera)throw new Error("Missing product camera, cannot render screenshot!");var i;(i=this.camera).getScene().stopAnimation(i),i.animations=[];const a=this.camera.alpha,n=this.camera.beta,r=this.camera.radius,s=t.latDeg*Math.PI/180,o=t.lonDeg*Math.PI/180;this.camera.alpha=o,this.camera.beta=s,this.camera.radius=t.radius||this.camera.radius;const l=await d.CreateScreenshotUsingRenderTargetAsync(this.engine,this.camera,e,"image/png",2,!0);return this.camera.alpha=a,this.camera.beta=n,this.camera.radius=r,l}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()}setHighlights(e,t){0===e.length&&(this.highlightLayer?.dispose(),this.highlightLayer=void 0),this.highlightLayer||(this.highlightLayer=new i("highlights",this.scene,{isStroke:!0,blurVerticalSize:.85,blurHorizontalSize:.85}),this.highlightLayer.innerGlow=!0,this.highlightLayer.outerGlow=!1),this.highlightLayer.removeAllMeshes();const a=t?new r(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,a||r.FromHexString("#fcba03"))))}))}setRenderingPipelineConfiguration(e){this.renderingPipeline&&this.renderingPipeline.setConfiguration(e)}loadModel(e,t){const i=new me({modelDetails:e,scene:this.scene,previewService:this,progressHandler:t});return i.registerMaterialVariantListener((e=>this.handleMaterialProgressCallback(e.remainingCount,e.totalCount,e.taskName))),i.registerModelVariantListener((e=>this.handleModelProgressCallback(e,e.key))),this.configuration.highlights.enabled&&(i.registerMaterialSelectedCallback((e=>{this.setHighlights([e])})),i.registerMaterialDeselectedCallback((()=>{this.setHighlights([])}))),this.modelContainers.set(i.getId(),i),i}getAllModels(){return Array.from(this.modelContainers.values())}getModelById(e){return this.modelContainers.get(e)}registerPlugin(e){this.plugins.push(e),e.initialize(this,{camera:this.camera,engine:this.engine,scene:this.scene})}unregisterPlugin(e){const t=this.plugins.indexOf(e);if(t>-1){this.plugins.splice(t,1).forEach((e=>e.dispose(!1)))}}handleMaterialProgressCallback(e,t,i){this.loadProgress.set(`key_${i}`,e/t*100),this.notifyLoadHandlers()}handleModelProgressCallback(e,t){this.loadProgress.set(t,100*e.loaded/e.total),this.notifyLoadHandlers()}reattachControls(e,t=2){if(this.scene.detachControl(),this.engine.inputElement=e,this.camera){this.camera.attachControl(!0,!1,t);this.camera.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(){this.queuedCameraAnimation&&(this.executeCameraAnimation(this.queuedCameraAnimation),this.queuedCameraAnimation=void 0)}}export{z as ProductCameraRig,j as MaterialEffectMode,ye as SpiffCommerce3DPreviewService,U as RenderingConfiguration,W as REFLECTION_PROBE_RESOLUTION,q as renderingPipelineDefaults};
|
|
2
2
|
//# sourceMappingURL=module.js.map
|
package/dist/types.d.ts
CHANGED
|
@@ -175,9 +175,9 @@ export type ThreeDPreviewService = {
|
|
|
175
175
|
/**
|
|
176
176
|
* Loads a model into the scene.
|
|
177
177
|
* @param modelDetails The details of the model to load.
|
|
178
|
-
* @returns A
|
|
178
|
+
* @returns A reference to the model container. Call `getInitializationPromise()` to wait for the model to be loaded.
|
|
179
179
|
*/
|
|
180
|
-
loadModel(modelDetails: ModelDetails):
|
|
180
|
+
loadModel(modelDetails: ModelDetails): ModelContainer;
|
|
181
181
|
/**
|
|
182
182
|
* Returns all loaded models.
|
|
183
183
|
* @returns A map of id to model container.
|
|
@@ -743,6 +743,14 @@ export type ModelContainer = {
|
|
|
743
743
|
* Returns the unique ID of the model container.
|
|
744
744
|
*/
|
|
745
745
|
getId(): string;
|
|
746
|
+
/**
|
|
747
|
+
* Returns a promise which resolves when the model has been initialized.
|
|
748
|
+
*/
|
|
749
|
+
getInitializationPromise(): Promise<ModelContainer>;
|
|
750
|
+
/**
|
|
751
|
+
* Returns true if the model has been initialized.
|
|
752
|
+
*/
|
|
753
|
+
getIsInitialized(): boolean;
|
|
746
754
|
/**
|
|
747
755
|
* List named materials that are available on the model.
|
|
748
756
|
* Designed for use when utilizing the 3D preview in an editor format.
|
|
@@ -988,7 +996,7 @@ export class SpiffCommerce3DPreviewService implements ThreeDPreviewService {
|
|
|
988
996
|
fireResizeEvent(): void;
|
|
989
997
|
setHighlights(materials: readonly MaterialHandle[], color?: readonly [number, number, number]): void;
|
|
990
998
|
setRenderingPipelineConfiguration(renderingPipelineConfiguration: RenderingPipelineConfiguration): void;
|
|
991
|
-
loadModel(modelDetails: ModelDetails, progressHandler?: (event: ISceneLoaderProgressEvent) => void):
|
|
999
|
+
loadModel(modelDetails: ModelDetails, progressHandler?: (event: ISceneLoaderProgressEvent) => void): ModelContainer;
|
|
992
1000
|
getAllModels(): ReadonlyArray<ModelContainer>;
|
|
993
1001
|
getModelById(id: string): ModelContainer | undefined;
|
|
994
1002
|
registerPlugin(plugin: PreviewServicePlugin): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spiffcommerce/preview",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "An internal implementation of the ThreeDPreviewService interface used by Spiff Commerce",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
},
|
|
66
66
|
"size-limit": [
|
|
67
67
|
{
|
|
68
|
-
"limit": "
|
|
68
|
+
"limit": "485 KB",
|
|
69
69
|
"path": "dist/module.js"
|
|
70
70
|
}
|
|
71
71
|
],
|