|
var gdjs;(function(o){const a=1/(1<<16),g=i=>{i.metalness&&(i.metalness=0)},T=i=>{const t=i;if(!!t.material)if(Array.isArray(t.material))for(let e=0;e<t.material.length;e++)g(t.material[e]);else g(t.material)},f=i=>i.traverse(T),M=i=>{const t=new THREE.MeshBasicMaterial;return i.color&&(t.color=i.color),i.map&&(t.map=i.map),t},b=i=>{const t=i;if(!!t.material)if(Array.isArray(t.material))for(let e=0;e<t.material.length;e++)t.material[e]=M(t.material[e]);else t.material=M(t.material)},D=i=>i.traverse(b);class j extends o.RuntimeObject3DRenderer{constructor(t,e){const s=e.getGame().getModel3DManager().getModel(t._modelResourceName),r=new THREE.Group,h=new THREE.Group;h.rotation.order="ZYX",h.add(r);super(t,e,h);this._model3DRuntimeObject=t,this._threeObject=r,this._originalModel=s,this._modelOriginPoint=[0,0,0],this.updateSize(),this.updatePosition(),this.updateRotation(),this._animationMixer=new THREE.AnimationMixer(r),this._action=null}updateAnimation(t){this._animationMixer.update(t)}updatePosition(){const t=this.getOriginPoint(),e=this.getCenterPoint();this.get3DRendererObject().position.set(this._object.getX()-this._object.getWidth()*(t[0]-e[0]),this._object.getY()-this._object.getHeight()*(t[1]-e[1]),this._object.getZ()-this._object.getDepth()*(t[2]-e[2]))}getOriginPoint(){return this._model3DRuntimeObject._originPoint||this._modelOriginPoint}getCenterPoint(){return this._model3DRuntimeObject._centerPoint||this._modelOriginPoint}_updateDefaultTransformation(t,e,s,r,h,R,p,l){t.rotation.set(o.toRad(e),o.toRad(s),o.toRad(r)),t.updateMatrixWorld(!0);const n=new THREE.Box3().setFromObject(t);!this._model3DRuntimeObject._originPoint&&n.expandByPoint(new THREE.Vector3(0,0,0));const m=n.max.x-n.min.x,c=n.max.y-n.min.y,d=n.max.z-n.min.z;this._modelOriginPoint[0]=m<a?0:-n.min.x/m,this._modelOriginPoint[1]=c<a?0:-n.min.y/c,this._modelOriginPoint[2]=d<a?0:-n.min.z/d,this._modelOriginPoint[1]=1-this._modelOriginPoint[1];const u=this._model3DRuntimeObject._centerPoint;u&&t.position.set(-(n.min.x+m*u[0]),-(n.min.y+c*(1-u[1])),-(n.min.z+d*u[2])),t.scale.set(1,1,1),t.rotation.set(o.toRad(e),o.toRad(s),o.toRad(r));const x=m<a?1:1/m,H=c<a?1:1/c,P=d<a?1:1/d,O=new THREE.Matrix4;if(O.makeScale(x,-H,P),t.updateMatrix(),t.applyMatrix4(O),l){const A=m<a?Number.POSITIVE_INFINITY:h/m,I=c<a?Number.POSITIVE_INFINITY:R/c,v=d<a?Number.POSITIVE_INFINITY:p/d;let _=Math.min(A,I,v);Number.isFinite(_)||(_=1),this._object._setOriginalWidth(_*m),this._object._setOriginalHeight(_*c),this._object._setOriginalDepth(_*d)}}_reloadModel(t,e){this._originalModel=e.getGame().getModel3DManager().getModel(t._modelResourceName)}_updateModel(t,e,s,r,h,R,p){const l=new THREE.Group;l.rotation.order="ZYX";const n=THREE_ADDONS.SkeletonUtils.clone(this._originalModel.scene);l.add(n),this._replaceMaterials(l),this._updateDefaultTransformation(l,t,e,s,r,h,R,p),this.get3DRendererObject().remove(this._threeObject),this.get3DRendererObject().add(l),this._threeObject=l,this._animationMixer=new THREE.AnimationMixer(n);const E=this._model3DRuntimeObject.isAnimationPaused();this._model3DRuntimeObject.setAnimationIndex(this._model3DRuntimeObject.getAnimationIndex()),E&&this.pauseAnimation()}_replaceMaterials(t){this._model3DRuntimeObject._materialType===o.Model3DRuntimeObject.MaterialType.StandardWithoutMetalness?f(t):this._model3DRuntimeObject._materialType===o.Model3DRuntimeObject.MaterialType.Basic&&D(t)}getAnimationCount(){return this._originalModel.animations.length}getAnimationName(t){return this._originalModel.animations[t].name}hasAnimationEnded(){return this._action?!this._action.isRunning():!0}animationPaused(){if(!!this._action)return this._action.paused}pauseAnimation(){!this._action||(this._action.paused=!0)}resumeAnimation(){!this._action||(this._action.paused=!1)}playAnimation(t,e){this._animationMixer.stopAllAction();const s=THREE.AnimationClip.findByName(this._originalModel.animations,t);if(!s){console.error(`The GLB file: ${this._model3DRuntimeObject._modelResourceName} doesn't have any animation named: ${t}`);return}this._action=this._animationMixer.clipAction(s),this._action.setLoop(e?THREE.LoopRepeat:THREE.LoopOnce,Number.POSITIVE_INFINITY),this._action.clampWhenFinished=!0,this._action.play(),this._animationMixer.update(0)}getAnimationElapsedTime(){return this._action?this._action.time:0}setAnimationElapsedTime(t){this._action&&(this._action.time=t)}getAnimationDuration(t){const e=THREE.AnimationClip.findByName(this._originalModel.animations,t);return e?e.duration:0}}o.Model3DRuntimeObjectRenderer=j})(gdjs||(gdjs={})); |