1 line
4.0 KiB
JavaScript
1 line
4.0 KiB
JavaScript
import{getToGenerateRoundedCorners,repairGeometryFaceVertexUvs}from"../../tools/three";import McGeTool from"../McGeTool";import MxDbEntity from"../MxDbEntity";import MxFilters from"../MxFilters";import MxFun from"../MxFun";import MxType from"../MxType";export default class MxDbShape extends MxDbEntity{constructor(){super(...arguments),this.isLoadMaterialFromPath=!0,this.strokeLineWidth=2,this.isStrokeDashLine=!1,this.isFill=!1,this.curveSegments=50,this.closed=!0,this.cornerRadius=[],this._propertyDbKeys=["isFill","stroke","strokeLineWidth","isStrokeDashLine","closed","cornerRadius","fillImageSrc","fillImageParam"]}setStroke(t){return this.stroke=t,this}setStrokeLineWidth(t){return this.strokeLineWidth=t,this}setIsStrokeDashLine(t){return this.isStrokeDashLine=t,this}setIsFill(t){return this.isFill=t,this}get fillImageSrc(){return this._fillImageSrc}set fillImageSrc(t){this._fillImageSrc=t,this.isLoadMaterialFromPath=!0,this.material=null}setFillImageSrc(t){return this.fillImageSrc=t,this}setCurveSegments(t){return this.curveSegments=t,this}setClosed(t){return this.closed=t,this}setCornerRadius(t,e=!0){t instanceof Array?this.cornerRadius=t.map(t=>e?MxFun.screenCoordLong2Doc(t):t):this.cornerRadius=e?MxFun.screenCoordLong2Doc(t):t}getTypeName(){return"MxDbShape"}getShapePoints(t){const{curveSegments:e}=this;return this.points=t.getPoints(e).map(t=>t instanceof THREE.Vector2?new THREE.Vector3(t.x,t.y,0):t),this.points}createPaths(t){return this._paths=new THREE.CurvePath,Array.isArray(t)?t.forEach(t=>this._paths.add(t)):this._paths.add(t),this._paths}_draw(t,e){let{isFill:i,closed:s}=this;const r=t.getColor();t.setColor(this.filter?this.filter._getFilterColor(this.color,this.opacity):this.color);const o=this.getCornerRadiusPoints(s||i?this.getClosedPoints(e):e);i?!this.fillImageSrc&&t.drawSolid(o):t.drawLines(o),this._fillImg(t,o),t.setColor(r)}getCornerRadiusPoints(t){const{cornerRadius:e}=this;if(!e)return t;const i="number"==typeof e?t.map(()=>e):e;return i.length>0?getToGenerateRoundedCorners(t,i):t}_drawStoreLine(t,e,i){const{isFill:s,stroke:r,strokeLineWidth:o}=this,a=t.getLineWidth(),n=t.getColor(),l=t.isDashLineDisplay();r&&s&&(t.setDashLineDisplay(this.isStrokeDashLine),t.setColor(r),t.setLineWidth(o),i?i(t):t.drawLines(this.getCornerRadiusPoints(this.getClosedPoints(e))),t.setColor(n),t.setLineWidth(a),t.setDashLineDisplay(l))}getClosedPoints(t){return[...t,t[0]]}getTotalLength(){return this._paths?this._paths.getLength()+(this.closedLine?this.closedLine.getLength():0):0}getArea(){return this.points?McGeTool.calcArea(this.closed?this.getClosedPoints(this.points):this.points):0}worldDraw(t){const e=this.createPaths(new THREE.Curve),i=this.getShapePoints(e);this._draw(t,i),this._drawStoreLine(t,i)}_fillImg(t,e){const i={transparent:!0,depthTest:!1,opacity:this.opacity,visible:this.visible};if(!this.isFill||!this.fillImageSrc)return;if(!this.material){let t=this;return void MxFun.loadImageMaterial(this.fillImageSrc,e=>{t.isLoadMaterialFromPath=!1,e&&(t.material=e,t.setNeedUpdateDisplay(),MxFun.updateDisplay())})}const s=e.map(({x:t,y:e})=>new THREE.Vector2(t,e));let r=this.material,o=new THREE.ShapeGeometry(new THREE.Shape(s));if(o=repairGeometryFaceVertexUvs(o),this.filter){const t=r.map,e=this.filter._getFilterShaderData(t);r=new THREE.ShaderMaterial(Object.assign(Object.assign({},e),i))}if(r.depthTest=!1,r.transparent=!0,r.opacity=this.opacity,r.visible=this.visible,this.fillImageParam){const t=this.fillImageParam;for(let e in this.fillImageParam){this.material.map[e]=t[e]}}let a=new THREE.Mesh(o,r);t.drawEntity(a)}getGripPoints(){return[]}moveGripPointsAt(t,e){return!0}dwgIn(t){return this.onDwgIn(t),this.dwgInHelp(t,this._propertyDbKeys),this.isLoadMaterialFromPath=!0,this.material=null,t.type===MxType.MxCloneType.kMxFileClone?t.filter&&(this.filter=MxFilters.fromJSON(t.filter)):t.filter&&(this.filter=t.filter),!0}dwgOut(t){var e;return this.onDwgOut(t),this.dwgOutHelp(t,this._propertyDbKeys),t.type===MxType.MxCloneType.kMxFileClone?this.filter&&(t.filter=null===(e=this.filter)||void 0===e?void 0:e.toJSON()):t.filter=this.filter,t}}; |