mxdraw 0.1.115 → 0.1.117
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 +5 -1
- package/dist/lib/MxModule/McGiWorldDraw/index.d.ts +1 -1
- 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/mxdraw.es.js +1 -1
- package/dist/mxdraw.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -292,7 +292,7 @@ interface McGiWorldDraw {
|
|
|
292
292
|
* ```
|
|
293
293
|
*
|
|
294
294
|
*/
|
|
295
|
-
drawText(sText: string, iSize: number, dAngle: number, pt: THREE.Vector3, width?: number): THREE.Sprite | null;
|
|
295
|
+
drawText(sText: string, iSize: number, dAngle: number, pt: THREE.Vector3, width?: number, callGetFontStyle?: (iFontSize: number) => string): THREE.Sprite | null;
|
|
296
296
|
/**
|
|
297
297
|
* 设置DrawOrder,默认值为100.
|
|
298
298
|
* @returns
|
|
@@ -3161,6 +3161,10 @@ declare class MxDbSVGText {
|
|
|
3161
3161
|
move: boolean;
|
|
3162
3162
|
/** 文字移动到距图片远处,自动绘制一个连接线 */
|
|
3163
3163
|
drawConnectingLine: boolean;
|
|
3164
|
+
/** 字体样式 */
|
|
3165
|
+
fontStyle: string;
|
|
3166
|
+
/** 下划线 */
|
|
3167
|
+
underline: boolean;
|
|
3164
3168
|
}
|
|
3165
3169
|
|
|
3166
3170
|
/** @module MxDbSVG*/
|
|
@@ -142,7 +142,7 @@ export default interface McGiWorldDraw {
|
|
|
142
142
|
* ```
|
|
143
143
|
*
|
|
144
144
|
*/
|
|
145
|
-
drawText(sText: string, iSize: number, dAngle: number, pt: THREE.Vector3, width?: number): THREE.Sprite | null;
|
|
145
|
+
drawText(sText: string, iSize: number, dAngle: number, pt: THREE.Vector3, width?: number, callGetFontStyle?: (iFontSize: number) => string): THREE.Sprite | null;
|
|
146
146
|
/**
|
|
147
147
|
* 设置DrawOrder,默认值为100.
|
|
148
148
|
* @returns
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(t,s,
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(t,e,s,i){return new(s||(s=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 e;t.done?o(t.value):(e=t.value,e instanceof s?e:new s(function(t){t(e)})).then(g,n)}h((i=i.apply(t,e||[])).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()),e=0,s=this;this.svg.traverse(function(i){i.material&&(e<s.svgChildColor.length?i.material.color=new THREE.Color(s.svgChildColor[e]):i.material.color=t,e++)}),this.setNeedUpdateDisplay(!0)}}getSvgChildColor(){return this.svgChildColor}calcVewSize(t){let e=this.svgSize.x,s=this.svgSize.y;return s<=0&&(s=this.svgBoxSize?this.svgBoxSize.y/this.svgBoxSize.x*e:e),this.fixedSize&&(e=t.screenCoordLong2Doc(e),s=t.screenCoordLong2Doc(s)),[e,s]}calcSvgDrawRect(t){if(!t)return;this.calcSvgPosition(t);let[e,s]=this.calcVewSize(t),i=new THREE.Matrix4;i.makeScale(this.svgMirror?-1:1,this.svgReverse?-1:1,1);let o=new THREE.Matrix4;o.makeRotationZ(this.svgRotate);let r=new THREE.Matrix4,g=new THREE.Vector3(this.svgPos.x-e*this.svgAlignmentRatio.x,this.svgPos.y-s*this.svgAlignmentRatio.y,0);r.makeTranslation(g.x,g.y,g.z),o.multiply(i),o.premultiply(r);let n=new THREE.Vector3(0,0,0),h=new THREE.Vector3(e,0,0),a=new THREE.Vector3(e,s,0),l=new THREE.Vector3(0,s,0);return n.applyMatrix4(o),h.applyMatrix4(o),a.applyMatrix4(o),l.applyMatrix4(o),{pt1:n,pt2:a,pt3:h,pt4:l,cenpt:a.clone().add(n.clone().sub(a).multiplyScalar(.5)),sizew:e,sizeh:s}}worldDraw(t){let e=t.getMxObject(),s=this.calcSvgDrawRect(e),i=s.pt1,o=s.pt2,r=s.pt3,g=s.pt4,n=s.cenpt,h=s.sizew;if(this.aryText.forEach((s,i)=>{if(s.txt.length>0){let o=new THREE.Vector3(s.txtPos.x,s.txtPos.y,0);this.fixedSize&&(s.txtPos.x>0?o.x=this.svgPos.x+e.screenCoordLong2Doc(s.txtPos.x):o.x=this.svgPos.x-e.screenCoordLong2Doc(s.txtPos.x),s.txtPos.y>0?o.y=this.svgPos.y+e.screenCoordLong2Doc(s.txtPos.y):o.y=this.svgPos.y-e.screenCoordLong2Doc(s.txtPos.y));let r=void 0;s.color&&(r=t.getColor(),t.setColor(s.color));let g=s.txtHeight;if(this.fixedSize&&(g=e.screenCoordLong2Doc(s.txtHeight)),t.setXData({type:"text",txt:s.txt,index:i}),s._txtObject=t.drawText(s.txt,g,0,o,void 0,t=>{let e="";return e=s.fontStyle.length>0?`${s.fontStyle} ${t}px Arial`:`normal ${t}px Arial`}),s.underline&&s._txtObject){const e=new THREE.Box3;e.expandByObject(s._txtObject);let i=new THREE.Vector3(e.min.x,e.min.y,0),o=new THREE.Vector3(e.max.x,e.min.y,0);t.drawLine(i,o)}if(s._txtAspectRatio=-1,r&&t.setColor(r),s.drawConnectingLine){let e=n.clone().sub(o);if(e.length()>s.txtHeight+h){e.normalize();let i=n.clone().sub(e.clone().multiplyScalar(h)),r=o.clone().add(e.clone().multiplyScalar(s.txtHeight));t.setXData({type:"line"}),t.drawLine(i,r)}}}}),1==t.getType()){if(this.svg)t.setXData({type:"svg"}),t.drawEntity(this.svg);else if(this.svgPath.length>0&&this.isLoadFromPath){let s=this,i=t.getMxObject();MxThreeJS.loadSVG(this.svgPath,void 0,o=>{if(o){let r=o;if(r.boxSize)s.svgBoxSize=r.boxSize.clone();else{let t=(new THREE.Box3).setFromObject(o);s.svgBoxSize||(s.svgBoxSize=new THREE.Vector3),s.svgBoxSize.x=t.max.x-t.min.x,s.svgBoxSize.y=t.max.y-t.min.y}let[g,n]=s.calcVewSize(e);s.svgBoxSize&&(o.scale.x=g/s.svgBoxSize.x,o.scale.y=n/s.svgBoxSize.y),o.scale.z=o.scale.x,s.svgReverse&&(o.scale.y*=-1),s.svgMirror&&(o.scale.x*=-1),o.rotateZ(s.svgRotate),s.isSvgDirtyLocation=!0;let h=new THREE.Color(t.getColor()),a=0;o.traverse(function(t){t.material&&(t.material=t.material.clone(),t.material.transparent=!0,t.material.depthTest=!1,s.useSvgColor||(a<s.svgChildColor.length?t.material.color=new THREE.Color(s.svgChildColor[a]):t.material.color=h),a++)}),s.svg=o,s.setNeedUpdateDisplay(),i.updateDisplay()}else console.log("mx LoadSVG:"+s.svgPath+" failed");s.isLoadFromPath=!1})}this.fixedSize||(t.drawSelectLine(i,o),t.drawSelectLine(r,g),t.drawSelectLine(i,r),t.drawSelectLine(r,o),t.drawSelectLine(o,g),t.drawSelectLine(g,i))}else t.drawLine(i,r),t.drawLine(r,o),t.drawLine(o,g),t.drawLine(g,i)}setSvgPath(t,e=!1){return __awaiter(this,void 0,void 0,function*(){this.svgPath=t,this.svg=null,this.isLoadFromPath=!0,this.svgBoxSize=null,e&&(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 e=0;for(;e<this.aryText.length;e++){let s=this.aryText[e];if(s.move){let e=new THREE.Vector3(s.txtPos.x,s.txtPos.y,0);if(this.fixedSize){let t=MxFun.getCurrentDraw();s.txtPos.x>0?e.x=this.svgPos.x+t.screenCoordLong2Doc(s.txtPos.x):e.x=this.svgPos.x-t.screenCoordLong2Doc(s.txtPos.x),s.txtPos.y>0?e.y=this.svgPos.y+t.screenCoordLong2Doc(s.txtPos.y):e.y=this.svgPos.y-t.screenCoordLong2Doc(s.txtPos.y)}t.push(e)}}return t}moveGripPointsAt(t,e){if(0==t)this.svgPos.add(e),this.fixedSize||this.aryText.forEach(t=>{t.txtPos.add(e)});else if(t-1>=0&&t-1<this.aryText.length){let s=this.aryText[t-1];if(s.move)if(this.fixedSize){let t=MxFun.getCurrentDraw();s.txtPos.x+=t.docCoordLong2Screen(e.x),s.txtPos.y+=t.docCoordLong2Screen(e.y)}else s.txtPos.add(e)}return this.isSvgDirtyLocation=!0,!0}calcSvgPosition(t){if(!this.svg||!this.isSvgDirtyLocation)return;this.isSvgDirtyLocation=!1;let[e,s]=this.calcVewSize(t);this.svg.position.x=this.svgPos.x-e*this.svgAlignmentRatio.x-this.svgMargin.x*e,this.svg.position.y=this.svgPos.y-s*this.svgAlignmentRatio.y-this.svgMargin.y*s}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 e=t.txts;return this.aryText=[],e.forEach(t=>{let e=new MxDbSVGText;e.txt=t.txt,e.txtHeight=t.txtHeight,e.txtPos.copy(t.txtPos),e.move=t.move,e.drawConnectingLine=t.drawConnectingLine,this.aryText.push(e)}),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(e=>{let s={txtPos:e.txtPos,txt:e.txt,txtHeight:e.txtHeight,color:e.color,_txtAspectRatio:e._txtAspectRatio,move:e.move,drawConnectingLine:e.drawConnectingLine};t.txts.push(s)}),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(e=>{e.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(e){e.material&&(e.material.color=t)})}return this}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 e=(new THREE.Box3).setFromObject(t);this.svgBoxSize||(this.svgBoxSize=new THREE.Vector3),this.svgBoxSize.x=e.max.x-e.min.x,this.svgBoxSize.y=e.max.y-e.min.y}}reComputeSVG(){if(!this.svg)return;let t=this.getMxObject();if(!t)return;this.calcSvgBoxSize(this.svg);let[e,s]=this.calcVewSize(t);this.svgBoxSize&&(this.svg.scale.x=e/this.svgBoxSize.x,this.svg.scale.y=s/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[e,s]=this.calcVewSize(t);this.svgBoxSize&&(this.svg.scale.x=e/this.svgBoxSize.x,this.svg.scale.y=s/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 e=this;return this.aryText.forEach(s=>{if(s._txtObject&&t){let i=t.screenCoordLong2Doc(s.txtHeight);i>1e-5&&(s._txtAspectRatio<=0&&(s._txtAspectRatio=s._txtObject.scale.x/s._txtObject.scale.y),s._txtObject.scale.set(s._txtAspectRatio*i,i,1),s.txtPos.x>0?s._txtObject.position.x=e.svgPos.x+t.screenCoordLong2Doc(s.txtPos.x):s._txtObject.position.x=e.svgPos.x-t.screenCoordLong2Doc(s.txtPos.x),s.txtPos.y>0?s._txtObject.position.y=e.svgPos.y+t.screenCoordLong2Doc(s.txtPos.y):s._txtObject.position.y=e.svgPos.y-t.screenCoordLong2Doc(s.txtPos.y),s._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,this.move=!1,this.drawConnectingLine=!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,this.fontStyle="",this.underline=!1}};
|