3 lines
4.3 KiB
JavaScript
3 lines
4.3 KiB
JavaScript
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(t,e){super(t,e);this._materialType=n.Model3DRuntimeObject.MaterialType.Basic;this._currentAnimationIndex=0;this._animationSpeedScale=1;this._animationPaused=!1;this._modelResourceName=e.content.modelResourceName,this._animations=e.content.animations,this._originPoint=o(e.content.originLocation),this._centerPoint=o(e.content.centerLocation),this._renderer=new n.Model3DRuntimeObjectRenderer(this,t),this._materialType=this._convertMaterialType(e.content.materialType),this._updateModel(e),this._animations.length>0&&this._renderer.playAnimation(this._animations[0].source,this._animations[0].loop),this.onCreated()}updateFromObjectData(t,e){return super.updateFromObjectData(t,e),(t.content.width!==e.content.width||t.content.height!==e.content.height||t.content.depth!==e.content.depth||t.content.rotationX!==e.content.rotationX||t.content.rotationY!==e.content.rotationY||t.content.rotationZ!==e.content.rotationZ||t.content.keepAspectRatio!==e.content.keepAspectRatio)&&this._updateModel(e),t.content.materialType!==e.content.materialType&&(this._materialType=this._convertMaterialType(e.content.materialType),this._updateModel(e)),t.content.originLocation!==e.content.originLocation&&(this._originPoint=o(e.content.originLocation)),t.content.centerLocation!==e.content.centerLocation&&(this._centerPoint=o(e.content.centerLocation)),!0}_updateModel(t){const e=t.content.rotationX||0,a=t.content.rotationY||0,m=t.content.rotationZ||0,i=t.content.keepAspectRatio;this._renderer._updateModel(e,a,m,this._getOriginalWidth(),this._getOriginalHeight(),this._getOriginalDepth(),i)}getRenderer(){return this._renderer}_convertMaterialType(t){return t==="KeepOriginal"?n.Model3DRuntimeObject.MaterialType.KeepOriginal:t==="StandardWithoutMetalness"?n.Model3DRuntimeObject.MaterialType.StandardWithoutMetalness:n.Model3DRuntimeObject.MaterialType.Basic}update(t){const e=this.getElapsedTime()/1e3;this._renderer.updateAnimation(e*this._animationSpeedScale)}getAnimationIndex(){return this._currentAnimationIndex}setAnimationIndex(t){if(t=t|0,t<this._animations.length&&this._currentAnimationIndex!==t&&t>=0){const e=this._animations[t];this._currentAnimationIndex=t,this._renderer.playAnimation(e.source,e.loop),this._animationPaused&&this._renderer.pauseAnimation()}}getAnimationName(){return this._currentAnimationIndex>=this._animations.length?"":this._animations[this._currentAnimationIndex].name}setAnimationName(t){if(!t)return;const e=this._animations.findIndex(a=>a.name===t);e>=0&&this.setAnimationIndex(e)}isCurrentAnimationName(t){return this.getAnimationName()===t}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(t){this._animationSpeedScale=t}getAnimationElapsedTime(){return this._renderer.getAnimationElapsedTime()}setAnimationElapsedTime(t){this._renderer.setAnimationElapsedTime(t)}getAnimationDuration(){return this._renderer.getAnimationDuration(this._animations[this._currentAnimationIndex].source)}getCenterX(){const t=this._renderer.getCenterPoint();return this.getWidth()*t[0]}getCenterY(){const t=this._renderer.getCenterPoint();return this.getHeight()*t[1]}getCenterZ(){const t=this._renderer.getCenterPoint();return this.getDepth()*t[2]}getDrawableX(){const t=this._renderer.getOriginPoint();return this.getX()-this.getWidth()*t[0]}getDrawableY(){const t=this._renderer.getOriginPoint();return this.getY()-this.getHeight()*t[1]}getDrawableZ(){const t=this._renderer.getOriginPoint();return this.getZ()-this.getDepth()*t[2]}}n.Model3DRuntimeObject=s,function(t){let r;(function(i){i[i.Basic=0]="Basic",i[i.StandardWithoutMetalness=1]="StandardWithoutMetalness",i[i.KeepOriginal=2]="KeepOriginal"})(r=t.MaterialType||(t.MaterialType={}))}(s=n.Model3DRuntimeObject||(n.Model3DRuntimeObject={})),n.registerObject("Scene3D::Model3DObject",n.Model3DRuntimeObject)})(gdjs||(gdjs={}));
|
|
//# sourceMappingURL=Model3DRuntimeObject.js.map
|