var gdjs;(function(n){const o=r=>{switch(r){case"ModelOrigin":return null;case"ObjectCenter":return[.5,.5,.5];case"BottomCenterZ":return[.5,.5,0];case"BottomCenterY":return[.5,1,.5];case"TopLeft":return[0,0,0];default:return null}};class s extends n.RuntimeObject3D{constructor(e,t){super(e,t);this._materialType=n.Model3DRuntimeObject.MaterialType.Basic;this._currentAnimationIndex=0;this._animationSpeedScale=1;this._animationPaused=!1;this._modelResourceName=t.content.modelResourceName,this._animations=t.content.animations,this._originPoint=o(t.content.originLocation),this._centerPoint=o(t.content.centerLocation),this._renderer=new n.Model3DRuntimeObjectRenderer(this,e),this._materialType=this._convertMaterialType(t.content.materialType),this.onModelChanged(t),this.onCreated()}onModelChanged(e){this._updateModel(e),this._animations.length>0&&this._renderer.playAnimation(this._animations[0].source,this._animations[0].loop)}updateFromObjectData(e,t){return super.updateFromObjectData(e,t),e.content.materialType!==t.content.materialType&&(this._materialType=this._convertMaterialType(t.content.materialType)),e.content.modelResourceName!==t.content.modelResourceName?this._reloadModel(t):(e.content.width!==t.content.width||e.content.height!==t.content.height||e.content.depth!==t.content.depth||e.content.rotationX!==t.content.rotationX||e.content.rotationY!==t.content.rotationY||e.content.rotationZ!==t.content.rotationZ||e.content.keepAspectRatio!==t.content.keepAspectRatio||e.content.materialType!==t.content.materialType)&&this._updateModel(t),e.content.originLocation!==t.content.originLocation&&(this._originPoint=o(t.content.originLocation)),e.content.centerLocation!==t.content.centerLocation&&(this._centerPoint=o(t.content.centerLocation)),!0}getNetworkSyncData(){return{...super.getNetworkSyncData(),mt:this._materialType,op:this._originPoint,cp:this._centerPoint,anis:this._animations,ai:this._currentAnimationIndex,ass:this._animationSpeedScale,ap:this._animationPaused}}updateFromNetworkSyncData(e){super.updateFromNetworkSyncData(e),e.mt!==void 0&&(this._materialType=e.mt),e.op!==void 0&&(this._originPoint=e.op),e.cp!==void 0&&(this._centerPoint=e.cp),e.anis!==void 0&&(this._animations=e.anis),e.ai!==void 0&&this.setAnimationIndex(e.ai),e.ass!==void 0&&this.setAnimationSpeedScale(e.ass),e.ap!==void 0&&e.ap!==this.isAnimationPaused()&&(e.ap?this.pauseAnimation():this.resumeAnimation())}_reloadModel(e){this._modelResourceName=e.content.modelResourceName,this._renderer._reloadModel(this,this._runtimeScene),this.onModelChanged(e)}_updateModel(e){const t=e.content.rotationX||0,a=e.content.rotationY||0,d=e.content.rotationZ||0,i=e.content.keepAspectRatio;this._renderer._updateModel(t,a,d,this._getOriginalWidth(),this._getOriginalHeight(),this._getOriginalDepth(),i)}getRenderer(){return this._renderer}_convertMaterialType(e){return e==="KeepOriginal"?n.Model3DRuntimeObject.MaterialType.KeepOriginal:e==="StandardWithoutMetalness"?n.Model3DRuntimeObject.MaterialType.StandardWithoutMetalness:n.Model3DRuntimeObject.MaterialType.Basic}update(e){const t=this.getElapsedTime()/1e3;this._renderer.updateAnimation(t*this._animationSpeedScale)}getAnimationIndex(){return this._currentAnimationIndex}setAnimationIndex(e){if(e=e|0,e=0){const t=this._animations[e];this._currentAnimationIndex=e,this._renderer.playAnimation(t.source,t.loop),this._animationPaused&&this._renderer.pauseAnimation()}}getAnimationName(){return this._currentAnimationIndex>=this._animations.length?"":this._animations[this._currentAnimationIndex].name}setAnimationName(e){if(!e)return;const t=this._animations.findIndex(a=>a.name===e);t>=0&&this.setAnimationIndex(t)}isCurrentAnimationName(e){return this.getAnimationName()===e}hasAnimationEnded(){return this._renderer.hasAnimationEnded()}isAnimationPaused(){return this._animationPaused}pauseAnimation(){this._animationPaused=!0,this._renderer.pauseAnimation()}resumeAnimation(){this._animationPaused=!1,this._renderer.resumeAnimation()}getAnimationSpeedScale(){return this._animationSpeedScale}setAnimationSpeedScale(e){this._animationSpeedScale=e}getAnimationElapsedTime(){return this._renderer.getAnimationElapsedTime()}setAnimationElapsedTime(e){this._renderer.setAnimationElapsedTime(e),this._animationPaused||this._renderer.resumeAnimation()}getAnimationDuration(){return this._renderer.getAnimationDuration(this._animations[this._currentAnimationIndex].source)}getCenterX(){const e=this._renderer.getCenterPoint();return this.getWidth()*e[0]}getCenterY(){const e=this._renderer.getCenterPoint();return this.getHeight()*e[1]}getCenterZ(){const e=this._renderer.getCenterPoint();return this.getDepth()*e[2]}getDrawableX(){const e=this._renderer.getOriginPoint();return this.getX()-this.getWidth()*e[0]}getDrawableY(){const e=this._renderer.getOriginPoint();return this.getY()-this.getHeight()*e[1]}getDrawableZ(){const e=this._renderer.getOriginPoint();return this.getZ()-this.getDepth()*e[2]}}n.Model3DRuntimeObject=s,function(e){let r;(function(i){i[i.Basic=0]="Basic",i[i.StandardWithoutMetalness=1]="StandardWithoutMetalness",i[i.KeepOriginal=2]="KeepOriginal"})(r=e.MaterialType||(e.MaterialType={}))}(s=n.Model3DRuntimeObject||(n.Model3DRuntimeObject={})),n.registerObject("Scene3D::Model3DObject",n.Model3DRuntimeObject)})(gdjs||(gdjs={})); //# sourceMappingURL=Model3DRuntimeObject.js.map