import{addRegisterMxDbEntity}from"../../tools/registerMxDbEntity";import MxDbEntity from"../MxDbEntity";import MxFun from"../MxFun";import MxType from"../MxType";import drawMxDbImage from"./draw";class MxDbImage extends MxDbEntity{constructor(){super(...arguments),this.pt1=new THREE.Vector3,this.pt2=new THREE.Vector3,this.imagePath="",this.isLoadMaterialFromPath=!0,this.material=null,this.angle=0}getTypeName(){return"MxDbImage"}getAngle(){return this.angle}setAngle(t){this.angle=t}worldDraw(t){let e=new THREE.Vector3(this.pt1.x,this.pt2.y),i=new THREE.Vector3(this.pt2.x,this.pt1.y);if(Math.abs(this.angle)>1e-5){let e=new THREE.Vector3(.5*(this.pt1.x-this.pt2.x)+this.pt2.x,.5*(this.pt1.y-this.pt2.y)+this.pt2.y),i=new THREE.Matrix4;i.makeRotationZ(this.angle);let a=(new THREE.Matrix4).makeTranslation(e.x,e.y,e.z).multiply(i).multiply((new THREE.Matrix4).makeTranslation(-e.x,-e.y,-e.z));t.setMatrix(a)}if(1==t.getType()){if(t.drawSelectLine(this.pt1,e),t.drawSelectLine(e,this.pt2),t.drawSelectLine(this.pt2,i),t.drawSelectLine(i,this.pt1),this.material){let e=Math.abs(this.pt1.x-this.pt2.x),i=Math.abs(this.pt1.y-this.pt2.y),a=new THREE.PlaneGeometry(e,i),s=Math.min(this.pt1.x,this.pt2.x),h=Math.min(this.pt1.y,this.pt2.y);for(let t=0;t0&&this.isLoadMaterialFromPath){let e=this,i=t.getMxObject();MxFun.loadImageMaterial(this.imagePath,t=>{this.isLoadMaterialFromPath=!1,t&&(e.setMaterial(t),e.setNeedUpdateDisplay(),i.updateDisplay())})}}else if(this.material){let e=Math.abs(this.pt1.x-this.pt2.x),i=Math.abs(this.pt1.y-this.pt2.y),a=new THREE.PlaneGeometry(e,i),s=Math.min(this.pt1.x,this.pt2.x),h=Math.min(this.pt1.y,this.pt2.y);for(let t=0;t{this.isLoadMaterialFromPath=!1,e.setMaterial(t)})}setPoint1(t){this.pt1=t}getPoint1(){return this.pt1}setPoint2(t){this.pt2=t}getPoint2(){return this.pt2}getGripPoints(){let t=[];t.push(this.pt1),t.push(this.pt2);let e=new THREE.Vector3(this.pt1.x+.5*(this.pt2.x-this.pt1.x),this.pt1.y+.5*(this.pt2.y-this.pt1.y));return t.push(e),t}moveGripPointsAt(t,e){return 0==t?this.pt1.add(e):1==t?this.pt2.add(e):2==t&&(this.pt1.add(e),this.pt2.add(e)),!0}dwgIn(t){return this.onDwgIn(t),this.pt1.copy(t.pt1),this.pt2.copy(t.pt2),this.imagePath=t.imagePath.substr(0),this.isLoadMaterialFromPath=!0,t.angle&&(this.angle=t.angle),t.material&&(this.material=t.material),!0}dwgOut(t){return this.onDwgOut(t),t.pt1=this.pt1,t.pt2=this.pt2,t.imagePath=this.imagePath,t.angle=this.angle,t.type==MxType.MxCloneType.kDragClone&&(t.material=this.material),t}create(){return new MxDbImage}}MxDbImage.cmd="Mx_DrawImage",MxDbImage.draw=drawMxDbImage,addRegisterMxDbEntity(MxDbImage);export default MxDbImage;