mxdraw 0.1.107 → 0.1.109
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -0
- package/dist/lib/MxModule/MxDbSVG/index.js +1 -1
- package/dist/lib/MxModule/MxDbSVGText/index.d.ts +4 -0
- package/dist/lib/MxModule/MxDbSVGText/index.js +1 -1
- package/dist/lib/MxModule/loadCoreCode/mxfun.es5.js +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/mxdraw.umd.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -3053,6 +3053,10 @@ declare class MxDbSVGText {
|
|
|
3053
3053
|
_txtObject: THREE.Sprite | null;
|
|
3054
3054
|
/** 比例 */
|
|
3055
3055
|
_txtAspectRatio: number;
|
|
3056
|
+
/** 文字是否能独立移动 */
|
|
3057
|
+
move: boolean;
|
|
3058
|
+
/** 文字移动到距图片远处,自动绘制一个连接线 */
|
|
3059
|
+
drawConnectingLine: boolean;
|
|
3056
3060
|
}
|
|
3057
3061
|
|
|
3058
3062
|
/** @module MxDbSVG*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(t,s,i
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(t,s,e,i){return new(e||(e=Promise))(function(o,r){function g(t){try{h(i.next(t))}catch(t){r(t)}}function n(t){try{h(i.throw(t))}catch(t){r(t)}}function h(t){var s;t.done?o(t.value):(s=t.value,s instanceof e?s:new e(function(t){t(s)})).then(g,n)}h((i=i.apply(t,s||[])).next())})};import MxDbEntity from"../MxDbEntity";import MxDbSVGText from"../MxDbSVGText";import MxFun from"../MxFun";import MxThreeJS from"../MxThreeJS";import MxType from"../MxType";export default class MxDbSVG extends MxDbEntity{constructor(){super(...arguments),this.svgPos=new THREE.Vector3,this.svg=null,this.svgPath="",this.svgSize=new THREE.Vector2(50,50),this.svgAlignmentRatio=new THREE.Vector2(0,0),this.svgRotate=0,this.svgReverse=!1,this.svgMirror=!1,this.svgChildColor=[],this.svgMargin=new THREE.Vector2(0,0),this.isSvgDirtyLocation=!1,this.isLoadFromPath=!0,this.aryText=[],this.svgBoxSize=null,this.fixedSize=!1,this.useSvgColor=!1}setSvgChildColor(t){if(this.svgChildColor=t,!this.useSvgColor&&this.svg){let t=new THREE.Color(this.getColor()),s=0,e=this;this.svg.traverse(function(i){i.material&&(s<e.svgChildColor.length?i.material.color=new THREE.Color(e.svgChildColor[s]):i.material.color=t,s++)}),this.setNeedUpdateDisplay(!0)}}getSvgChildColor(){return this.svgChildColor}calcVewSize(t){let s=this.svgSize.x,e=this.svgSize.y;return e<=0&&(e=this.svgBoxSize?this.svgBoxSize.y/this.svgBoxSize.x*s:s),this.fixedSize&&(s=t.screenCoordLong2Doc(s),e=t.screenCoordLong2Doc(e)),[s,e]}worldDraw(t){let s=t.getMxObject();this.calcSvgPosition(s);let[e,i]=this.calcVewSize(s),o=new THREE.Matrix4;o.makeScale(this.svgMirror?-1:1,this.svgReverse?-1:1,1);let r=new THREE.Matrix4;r.makeRotationZ(this.svgRotate);let g=new THREE.Matrix4,n=new THREE.Vector3(this.svgPos.x-e*this.svgAlignmentRatio.x,this.svgPos.y-i*this.svgAlignmentRatio.y,0);g.makeTranslation(n.x,n.y,n.z),r.multiply(o),r.premultiply(g);let h=new THREE.Vector3(0,0,0),l=new THREE.Vector3(e,0,0),a=new THREE.Vector3(e,i,0),x=new THREE.Vector3(0,i,0);h.applyMatrix4(r),l.applyMatrix4(r),a.applyMatrix4(r),x.applyMatrix4(r);let v=a.clone().add(h.clone().sub(a).multiplyScalar(.5));if(this.aryText.forEach(i=>{if(i.txt.length>0){let o=new THREE.Vector3(i.txtPos.x,i.txtPos.y,0);this.fixedSize&&(i.txtPos.x>0?o.x=this.svgPos.x+s.screenCoordLong2Doc(i.txtPos.x):o.x=this.svgPos.x-s.screenCoordLong2Doc(i.txtPos.x),i.txtPos.y>0?o.y=this.svgPos.y+s.screenCoordLong2Doc(i.txtPos.y):o.y=this.svgPos.y-s.screenCoordLong2Doc(i.txtPos.y));let r=void 0;i.color&&(r=t.getColor(),t.setColor(i.color));let g=i.txtHeight;if(this.fixedSize&&(g=s.screenCoordLong2Doc(i.txtHeight)),i._txtObject=t.drawText(i.txt,g,0,o),i._txtAspectRatio=-1,r&&t.setColor(r),i.drawConnectingLine){let s=v.clone().sub(o);if(s.length()>i.txtHeight+e){s.normalize();let r=v.clone().sub(s.clone().multiplyScalar(e)),g=o.clone().add(s.clone().multiplyScalar(i.txtHeight));t.drawLine(r,g)}}}}),1==t.getType()){if(this.svg)t.drawEntity(this.svg);else if(this.svgPath.length>0&&this.isLoadFromPath){let e=this,i=t.getMxObject();MxThreeJS.loadSVG(this.svgPath,void 0,o=>{if(o){let r=o;if(r.boxSize)e.svgBoxSize=r.boxSize.clone();else{let t=(new THREE.Box3).setFromObject(o);e.svgBoxSize||(e.svgBoxSize=new THREE.Vector3),e.svgBoxSize.x=t.max.x-t.min.x,e.svgBoxSize.y=t.max.y-t.min.y}let[g,n]=e.calcVewSize(s);e.svgBoxSize&&(o.scale.x=g/e.svgBoxSize.x,o.scale.y=n/e.svgBoxSize.y),o.scale.z=o.scale.x,e.svgReverse&&(o.scale.y*=-1),e.svgMirror&&(o.scale.x*=-1),o.rotateZ(e.svgRotate),e.isSvgDirtyLocation=!0;let h=new THREE.Color(t.getColor()),l=0;o.traverse(function(t){t.material&&(t.material=t.material.clone(),t.material.transparent=!0,t.material.depthTest=!1,e.useSvgColor||(l<e.svgChildColor.length?t.material.color=new THREE.Color(e.svgChildColor[l]):t.material.color=h),l++)}),e.svg=o,e.setNeedUpdateDisplay(),i.updateDisplay()}else console.log("mx LoadSVG:"+e.svgPath+" failed");e.isLoadFromPath=!1})}t.drawSelectLine(h,a),t.drawSelectLine(l,x),t.drawSelectLine(h,l),t.drawSelectLine(l,a),t.drawSelectLine(a,x),t.drawSelectLine(x,h)}else t.drawLine(h,l),t.drawLine(l,a),t.drawLine(a,x),t.drawLine(x,h)}setSvgPath(t,s=!1){return __awaiter(this,void 0,void 0,function*(){this.svgPath=t,this.svg=null,this.isLoadFromPath=!0,this.svgBoxSize=null,s&&(yield MxThreeJS.loadSVG(t))})}getSvgPath(){return this.svgPath}setSvgPostion(t){this.svgPos=t.clone(),this.isSvgDirtyLocation=!0}getSvgPostion(){return this.svgPos}setSvgSize(t){this.svgSize=t,this.isSvgDirtyLocation=!0}getSvgSize(){return this.svgSize}setSvgAlignmentRatio(t){this.svgAlignmentRatio=t,this.isSvgDirtyLocation=!0}getSvgAlignmentRatio(){return this.svgAlignmentRatio}getText(t){return t<this.aryText.length?this.aryText[t]:null}addText(t){this.aryText.push(t)}getGripPoints(){let t=[];t.push(this.svgPos);let s=0;for(;s<this.aryText.length;s++){let e=this.aryText[s];if(e.move){let s=new THREE.Vector3(e.txtPos.x,e.txtPos.y,0);if(this.fixedSize){let t=MxFun.getCurrentDraw();e.txtPos.x>0?s.x=this.svgPos.x+t.screenCoordLong2Doc(e.txtPos.x):s.x=this.svgPos.x-t.screenCoordLong2Doc(e.txtPos.x),e.txtPos.y>0?s.y=this.svgPos.y+t.screenCoordLong2Doc(e.txtPos.y):s.y=this.svgPos.y-t.screenCoordLong2Doc(e.txtPos.y)}t.push(s)}}return t}moveGripPointsAt(t,s){if(0==t)this.svgPos.add(s),this.fixedSize||this.aryText.forEach(t=>{t.txtPos.add(s)});else if(t-1>=0&&t-1<this.aryText.length){let e=this.aryText[t-1];if(e.move)if(this.fixedSize){let t=MxFun.getCurrentDraw();e.txtPos.x+=t.docCoordLong2Screen(s.x),e.txtPos.y+=t.docCoordLong2Screen(s.y)}else e.txtPos.add(s)}return this.isSvgDirtyLocation=!0,!0}calcSvgPosition(t){if(!this.svg||!this.isSvgDirtyLocation)return;this.isSvgDirtyLocation=!1;let[s,e]=this.calcVewSize(t);this.svg.position.x=this.svgPos.x-s*this.svgAlignmentRatio.x-this.svgMargin.x*s,this.svg.position.y=this.svgPos.y-e*this.svgAlignmentRatio.y-this.svgMargin.y*e}dwgIn(t){this.onDwgIn(t),this.fixedSize=t.fixedSize,this.fixedSize?this.svg=null:t.type==MxType.MxCloneType.kClone&&t.svg&&(this.svg=t.svg.clone()),this.svgPos.copy(t.svgPos),this.svgPath=t.svgPath.substr(0),this.svgSize.copy(t.svgSize),this.svgAlignmentRatio.copy(t.svgAlignmentRatio),this.isSvgDirtyLocation=!0,this.svg||(this.isLoadFromPath=!0),this.svgBoxSize=null;let s=t.txts;return this.aryText=[],s.forEach(t=>{let s=new MxDbSVGText;s.txt=t.txt,s.txtHeight=t.txtHeight,s.txtPos.copy(t.txtPos),s.move=t.move,s.drawConnectingLine=t.drawConnectingLine,this.aryText.push(s)}),this.svgRotate=t.svgRotate,this.useSvgColor=t.useSvgColor,this.svgReverse=t.svgReverse,this.svgMirror=t.svgMirror,this.svgMargin=t.svgMargin,t.svgChildColor?this.svgChildColor=t.svgChildColor:this.svgChildColor=[],!0}dwgOut(t){return this.onDwgOut(t),t.type==MxType.MxCloneType.kClone&&(t.svg=this.svg),t.svgPath=this.svgPath,t.svgPos=this.svgPos,t.svgSize=this.svgSize,t.svgAlignmentRatio=this.svgAlignmentRatio,t.txts=[],this.aryText.forEach(s=>{let e={txtPos:s.txtPos,txt:s.txt,txtHeight:s.txtHeight,color:s.color,_txtAspectRatio:s._txtAspectRatio,move:s.move,drawConnectingLine:s.drawConnectingLine};t.txts.push(e)}),t.fixedSize=this.fixedSize,t.svgRotate=this.svgRotate,t.useSvgColor=this.useSvgColor,t.svgReverse=this.svgReverse,t.svgMirror=this.svgMirror,t.svgMargin=this.svgMargin,t.svgChildColor=this.svgChildColor,t}create(){return new MxDbSVG}transformBy(t){this.svgPos.applyMatrix4(t),this.isSvgDirtyLocation=!0,this.fixedSize||this.aryText.forEach(s=>{s.txtPos.applyMatrix4(t)})}getTypeName(){return"MxDbSVG"}setColor(t){if(super.setColor(t),this.svg){let t=new THREE.Color(this.color);this.svg.traverse(function(s){s.material&&(s.material.color=t)})}}setSvg(t){this.svg=t,this.isLoadFromPath=!1,this.svgBoxSize=null}calcSvgBoxSize(t){if(!this.svgBoxSize)if(t.boxSize)this.svgBoxSize=t.boxSize.clone();else{let s=(new THREE.Box3).setFromObject(t);this.svgBoxSize||(this.svgBoxSize=new THREE.Vector3),this.svgBoxSize.x=s.max.x-s.min.x,this.svgBoxSize.y=s.max.y-s.min.y}}reComputeSVG(){if(!this.svg)return;let t=this.getMxObject();if(!t)return;this.calcSvgBoxSize(this.svg);let[s,e]=this.calcVewSize(t);this.svgBoxSize&&(this.svg.scale.x=s/this.svgBoxSize.x,this.svg.scale.y=e/this.svgBoxSize.y),this.svg.scale.z=this.svg.scale.x,this.svgReverse&&(this.svg.scale.y*=-1),this.svgMirror&&(this.svg.scale.x*=-1),this.isSvgDirtyLocation=!0,this.calcSvgPosition(t)}onViewChange(){if(!this.fixedSize)return!1;let t=this.getMxObject();if(null==t)return!1;if(this.svg){this.calcSvgBoxSize(this.svg);let[s,e]=this.calcVewSize(t);this.svgBoxSize&&(this.svg.scale.x=s/this.svgBoxSize.x,this.svg.scale.y=e/this.svgBoxSize.y),this.svg.scale.z=this.svg.scale.x,this.svgReverse&&(this.svg.scale.y*=-1),this.svgMirror&&(this.svg.scale.x*=-1),this.isSvgDirtyLocation=!0,this.calcSvgPosition(t)}let s=this;return this.aryText.forEach(e=>{if(e._txtObject&&t){let i=t.screenCoordLong2Doc(e.txtHeight);i>1e-5&&(e._txtAspectRatio<=0&&(e._txtAspectRatio=e._txtObject.scale.x/e._txtObject.scale.y),e._txtObject.scale.set(e._txtAspectRatio*i,i,1),e.txtPos.x>0?e._txtObject.position.x=s.svgPos.x+t.screenCoordLong2Doc(e.txtPos.x):e._txtObject.position.x=s.svgPos.x-t.screenCoordLong2Doc(e.txtPos.x),e.txtPos.y>0?e._txtObject.position.y=s.svgPos.y+t.screenCoordLong2Doc(e.txtPos.y):e._txtObject.position.y=s.svgPos.y-t.screenCoordLong2Doc(e.txtPos.y),e._txtObject.updateMatrix())}}),!0}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default class MxDbSVGText{constructor(){this.txtPos=new THREE.Vector3,this.txt="",this.txtHeight=1,this.color=void 0,this._txtObject=null,this._txtAspectRatio=-1}};
|
|
1
|
+
export default class MxDbSVGText{constructor(){this.txtPos=new THREE.Vector3,this.txt="",this.txtHeight=1,this.color=void 0,this._txtObject=null,this._txtAspectRatio=-1,this.move=!1,this.drawConnectingLine=!1}};
|