Measure.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  1. import * as THREE from "../../libs/three.js/build/three.module.js";
  2. import {TextSprite} from "../TextSprite.js";
  3. import {Utils} from "../utils.js";
  4. import Label from "./Label.js";
  5. import {LineDraw} from "../utils/DrawUtil";
  6. import math from "./math.js";
  7. import {MOUSE} from "../defines.js";
  8. import DepthBasicMaterial from "../materials/DepthBasicMaterial.js";
  9. import Sprite from '../viewer/Sprite'
  10. import {config} from '../settings'
  11. import {ctrlPolygon} from './ctrlPolygon'
  12. let texLoader = new THREE.TextureLoader()
  13. let color = new THREE.Color(config.measure.lineColor)
  14. let textColor = new THREE.Color(config.measure.textColor)
  15. let highLightColor = new THREE.Color(config.measure.highLightColor)
  16. var markerMats;
  17. var lineMats;
  18. var planeMats
  19. const markerSizeInfo = {
  20. minSize : 25 , maxSize : 65, nearBound : 0.2, farBound : 8,
  21. }
  22. const labelSizeInfo = {width2d:200}
  23. const mainLabelProp = {
  24. backgroundColor: {r: color.r*255, g: color.g*255, b: color.b*255, a:config.measure.labelOpacity},
  25. textColor: {r: textColor.r*255, g: textColor.g*255, b: textColor.b*255, a: 1.0},
  26. fontsize:16,
  27. useDepth : true ,
  28. renderOrder : 5
  29. }
  30. const subLabelProp = {
  31. backgroundColor: {r: 255, g: 255, b: 255, a:1},
  32. textColor: {r: 0, g: 0, b:0, a: 1.0},
  33. fontsize:14,
  34. renderOrder : 4
  35. }
  36. export class Measure extends ctrlPolygon{
  37. constructor (prop) {
  38. prop.dimension = '2d'
  39. super('measure',prop);
  40. this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1;
  41. this.name = this.measureType + this.constructor.counter //'Measure_' + this.constructor.counter;
  42. this.color = new THREE.Color(config.measure.lineColor)//new THREE.Color(0xff0000);
  43. this.markerLabels = [];
  44. this.edgeLabels = [];
  45. this.angleLabels = [];
  46. this.coordinateLabels = [];
  47. this.area = {value:0,string:''}
  48. if(this.closed/* this.showArea */){
  49. this.areaLabel = this.createAreaLabel();
  50. this.add(this.areaLabel)
  51. }
  52. //add:
  53. if(this.maxMarkers > 2 || this.faceDirection){
  54. this.guideLine = this.createGuideLine();
  55. this.add(this.guideLine)
  56. }
  57. this.selectStates = {}
  58. this.setUnitSystem(prop.unit || viewer.unitConvert.UnitService.defaultSystem)
  59. viewer.setObjectLayers(this, 'measure' )
  60. //addMarkers:
  61. this.initData(prop)
  62. this.points_datasets || (this.points_datasets = []) //存每个点是哪个数据集
  63. this.addEventListener('marker_dropped',(e)=>{
  64. this.updateDatasetBelong()
  65. })
  66. }
  67. updateDatasetBelong(){//更新所属数据集
  68. let old = this.datasetId
  69. let maxCount = {id:null,count:0}
  70. let datasets = {}
  71. this.points_datasets.forEach(e=>{
  72. if(datasets[e]){
  73. datasets[e] ++
  74. }else{
  75. datasets[e] = 1
  76. }
  77. })
  78. for(let i in datasets) {
  79. if(datasets[i]>maxCount.count){
  80. maxCount = {id:i, count:datasets[i]}
  81. }
  82. }
  83. this.datasetId = maxCount.count > 0 ? maxCount.id : null
  84. if(this.datasetId != old){
  85. this.dispatchEvent({type:'changeDatasetId'})
  86. if(this.datasetId == void 0){
  87. this.dataset_points = null
  88. }else{
  89. this.dataset_points = this.points.map(e=>{
  90. return Potree.Utils.datasetPosTransform.toDataset({datasetId:this.datasetId, position:e.clone()})
  91. })
  92. }
  93. }
  94. }
  95. transformByPointcloud(){//每次移动点云 or 加载测量线时要获取一下当前position
  96. if(this.datasetId == void 0)return
  97. this.points = this.dataset_points.map(e=>{
  98. return Potree.Utils.datasetPosTransform.fromDataset({datasetId:this.datasetId, dataset_location:e.clone()})
  99. })
  100. this.getPoint2dInfo(this.points)
  101. this.update(true)
  102. this.setSelected(false)//隐藏edgelabel
  103. }
  104. update(ifUpdateMarkers) {
  105. super.update(ifUpdateMarkers)
  106. if(this.showCoordinates && this.points.length>0){
  107. let position = this.points[0];
  108. this.markers[0].position.copy(position);
  109. { // coordinate labels
  110. let coordinateLabel = this.coordinateLabels[0];
  111. let lonlat = viewer.transform.lonlatToLocal.inverse(position.toArray())
  112. let EPSG4550 = viewer.transform.lonlatTo4550.forward(lonlat)
  113. let pos = [
  114. position.toArray(),
  115. lonlat,
  116. EPSG4550
  117. ]
  118. //let msg = position.toArray().map(p => Utils.addCommas(p.toFixed(2))).join(" / ");
  119. let msg = pos.map(a=>
  120. a.map(p => Utils.addCommas(p.toFixed(10))).join(", ")
  121. ).join("<br>")
  122. coordinateLabel.setText(msg);
  123. coordinateLabel.setPos(position)
  124. coordinateLabel.setVisible(true)//this.showCoordinates;
  125. }
  126. return
  127. }
  128. let lastIndex = this.points.length - 1;
  129. for (let index = 0; index <= lastIndex; index++) {
  130. let nextIndex = (index + 1 > lastIndex) ? 0 : index + 1;
  131. let previousIndex = (index === 0) ? lastIndex : index - 1;
  132. let point = this.points[index];
  133. let nextPoint = this.points[nextIndex];
  134. let previousPoint = this.points[previousIndex];
  135. if(this.showDistances){ // edge labels
  136. let edgeLabel = this.edgeLabels[index];
  137. let center = new THREE.Vector3().add(point);
  138. center.add(nextPoint);
  139. center = center.multiplyScalar(0.5);
  140. edgeLabel.setPos(center)
  141. let distance = point.distanceTo(nextPoint);
  142. var text = viewer.unitConvert.convert(distance, 'distance', void 0, this.unitSystem, 0.1 , true)//distance要传0.1 这个factor
  143. edgeLabel.setText(text)
  144. edgeLabel.shouldVisi = (index < lastIndex || this.closed && this.points.length > 2) && distance>0
  145. /* this.closed || */ edgeLabel.setVisible(edgeLabel.shouldVisi)
  146. }
  147. }
  148. if(this.showArea && this.point2dInfo){ // update area
  149. /* if(this.points.length>2){
  150. this.area = {value:0};
  151. this.areaLabel.setVisible(false)
  152. }else{ */
  153. let area = Math.abs(math.getArea(this.point2dInfo.points2d))//this.getArea();
  154. let msg = viewer.unitConvert.convert(area, 'area', void 0, this.unitSystem/* , 0.1 */ )
  155. this.area = {value:area, string:msg}
  156. this.areaLabel.setPos(this.center);
  157. this.areaLabel.setText(msg);
  158. this.areaLabel.setVisible(true)
  159. //}
  160. }
  161. };
  162. addMarker (o={}) {
  163. let marker = new Sprite({mat:this.getMarkerMaterial('default'), sizeInfo: markerSizeInfo, name:"measure_point"} )
  164. viewer.setObjectLayers(marker, 'measure' )
  165. marker.renderOrder = 3
  166. marker.markerSelectStates = {}
  167. let edge
  168. { // edges
  169. edge = LineDraw.createFatLine( [
  170. 0, 0, 0,
  171. 0, 0, 0,
  172. ],{material:this.getLineMat('edgeDefault')} )
  173. viewer.setObjectLayers(edge, 'measure' )
  174. //----
  175. let mouseover = (e) => {this.setSelected(true, 'edge')};
  176. let mouseleave = (e) => {this.setSelected(false, 'edge')};
  177. edge.addEventListener('mouseover', mouseover);
  178. edge.addEventListener('mouseleave', mouseleave);
  179. }
  180. super.addMarker({point:o.point, marker:marker, edge})
  181. if(this.showEdges){ // edge labels
  182. var className = 'measure_length';
  183. if(this.closed){
  184. className += ' sub'
  185. }
  186. /* let edgeLabel = new Label({
  187. className ,
  188. })
  189. edgeLabel.setVisible(false)
  190. if(!this.closed){
  191. edgeLabel.elem.on('mouseover',()=>{
  192. this.setSelected(true, 'edgeLabel')
  193. })
  194. edgeLabel.elem.on('mouseout',()=>{
  195. this.setSelected(false, 'edgeLabel')
  196. })
  197. } */
  198. const edgeLabel = new TextSprite(
  199. $.extend(this.closed ? subLabelProp : mainLabelProp,{sizeInfo: labelSizeInfo, name:'edgeLabel'})
  200. )
  201. if(!this.closed){
  202. edgeLabel.addEventListener('mouseover',()=>{
  203. this.setSelected(true, 'edgeLabel')
  204. })
  205. edgeLabel.addEventListener('mouseleave',()=>{
  206. this.setSelected(false, 'edgeLabel')
  207. })
  208. edgeLabel.addEventListener('click',()=>{
  209. viewer.focusOnObject(this, 'measure')
  210. })
  211. }
  212. viewer.setObjectLayers(edgeLabel, 'measure' )
  213. this.edgeLabels.push(edgeLabel);
  214. this.add(edgeLabel);
  215. }
  216. if(this.showCoordinates){ // coordinate labels
  217. let coordinateLabel = new Label({
  218. className:'measure_pointPos',
  219. camera: viewer.scene.getActiveCamera()
  220. })
  221. coordinateLabel.setVisible(false)
  222. this.coordinateLabels.push(coordinateLabel);
  223. }
  224. let event = {
  225. type: 'marker_added',
  226. measurement: this,
  227. marker: marker
  228. };
  229. this.dispatchEvent(event);
  230. //this.setMarker(this.points.length - 1, point);
  231. return marker;//add
  232. };
  233. editStateChange(state){ //主要针对edgeLabels显示切换,编辑时显示
  234. super.editStateChange(state)
  235. if(!state){
  236. this.editStateTimer = setTimeout(()=>{
  237. if(!this.isEditing){
  238. this.dispatchEvent({type:'editStateChange',state:false})
  239. this.closed && this.edgeLabels.forEach(e=>e.setVisible(false) )
  240. }
  241. },100)
  242. }else{
  243. if(!this.isEditing){
  244. this.dispatchEvent({type:'editStateChange',state:true})
  245. this.closed && this.edgeLabels.forEach(e=>e.setVisible(e.shouldVisi) )
  246. clearTimeout(this.editStateTimer)
  247. }
  248. }
  249. this.isEditing = state
  250. }
  251. setMarkerSelected(marker, state, hoverObject){
  252. //console.warn(marker.id , state, hoverObject)
  253. marker.markerSelectStates[hoverObject] = state
  254. let absoluteState = false
  255. for(var i in marker.markerSelectStates){
  256. if(marker.markerSelectStates[i]){
  257. absoluteState = true; break;
  258. }
  259. }
  260. if(absoluteState){
  261. marker.material = this.getMarkerMaterial('select')
  262. }else{
  263. marker.material = this.getMarkerMaterial('default')
  264. }
  265. marker.selected = absoluteState
  266. viewer.mapViewer.emit('content_changed')
  267. }
  268. setSelected(state, hoverObject){//add
  269. hoverObject && (this.selectStates[hoverObject] = state)
  270. let absoluteState = false
  271. for(var i in this.selectStates){
  272. if(this.selectStates[i]){
  273. absoluteState = true; break;
  274. }
  275. }
  276. if(absoluteState){
  277. this.markers.forEach(e=>this.setMarkerSelected(e,true,'selectAll' ) )
  278. this.edges.forEach(e=>e.material = this.getLineMat('edgeSelect') )
  279. this.areaPlane && (this.areaPlane.material = planeMats.selected)
  280. this.closed && this.edgeLabels.forEach(e=>e.setVisible(e.shouldVisi) )
  281. //this.areaLabel && this.areaLabel.elem.addClass('highLight')
  282. //this.closed || this.edgeLabels.forEach(e=>e.elem.addClass('highLight') )
  283. this.areaLabel && setLabelHightState(this.areaLabel, true)
  284. this.closed || this.edgeLabels.forEach(e=>setLabelHightState(e, true) )
  285. }else{
  286. this.markers.forEach(e=>this.setMarkerSelected(e,false,'selectAll' ))
  287. this.edges.forEach(e=>e.material = this.getLineMat('edgeDefault') )
  288. this.areaPlane && (this.areaPlane.material = planeMats.default)
  289. this.closed && this.edgeLabels.forEach(e=>e.setVisible( false))
  290. //this.areaLabel && this.areaLabel.elem.removeClass('highLight')
  291. //this.closed || this.edgeLabels.forEach(e=>e.elem.removeClass('highLight') )
  292. this.areaLabel && setLabelHightState(this.areaLabel, false)
  293. this.closed || this.edgeLabels.forEach(e=>setLabelHightState(e, false) )
  294. }
  295. this.selected = absoluteState
  296. viewer.mapViewer.emit('content_changed')
  297. }
  298. removeMarker(index ){
  299. super.removeMarker(index)
  300. this.points_datasets.splice(index, 1);
  301. this.dataset_points.splice(index, 1)
  302. this.coordinateLabels.splice(index, 1);
  303. let edgeIndex = index//(index === 0) ? 0 : (index - 1);
  304. if(this.edgeLabels[edgeIndex]){
  305. this.edgeLabels[edgeIndex].dispose()
  306. this.edgeLabels.splice(edgeIndex, 1);
  307. }
  308. this.update();
  309. this.dispatchEvent({type: 'marker_removed', measurement: this});
  310. }
  311. setPosition(index, position) {
  312. super.setPosition(index, position)
  313. let event = {
  314. type: 'marker_moved',
  315. measure: this,
  316. index: index,
  317. position: position.clone()
  318. };
  319. this.dispatchEvent(event);
  320. }
  321. dispose(){//add
  322. var labels = this.edgeLabels.concat(this.coordinateLabels)
  323. this.areaLabel && labels.push(this.areaLabel)
  324. labels.forEach(e=>e.dispose())
  325. super.dispose()
  326. }
  327. getTotalDistance () {
  328. if (this.points.length === 0) {
  329. return 0;
  330. }
  331. let distance = 0;
  332. for (let i = 1; i < this.points.length; i++) {
  333. let prev = this.points[i - 1];
  334. let curr = this.points[i];
  335. let d = prev.distanceTo(curr);
  336. distance += d;
  337. }
  338. if (this.closed && this.points.length > 1) {
  339. let first = this.points[0];
  340. let last = this.points[this.points.length - 1];
  341. let d = last.distanceTo(first);
  342. distance += d;
  343. }
  344. return distance;
  345. }
  346. getAngleBetweenLines (cornerPoint, point1, point2) {
  347. let v1 = new THREE.Vector3().subVectors(point1, cornerPoint);
  348. let v2 = new THREE.Vector3().subVectors(point2, cornerPoint);
  349. // avoid the error printed by threejs if denominator is 0
  350. const denominator = Math.sqrt( v1.lengthSq() * v2.lengthSq() );
  351. if(denominator === 0){
  352. return 0;
  353. }else{
  354. return v1.angleTo(v2);
  355. }
  356. };
  357. getAngle (index) {
  358. if (this.points.length < 3 || index >= this.points.length) {
  359. return 0;
  360. }
  361. let previous = (index === 0) ? this.points[this.points.length - 1] : this.points[index - 1];
  362. let point = this.points[index];
  363. let next = this.points[(index + 1) % (this.points.length)];
  364. return this.getAngleBetweenLines(point, previous, next);
  365. }
  366. getCenter(/* update */){
  367. if(this.points.length>=3){
  368. return this.center.clone()
  369. }else if(this.points.length == 2){
  370. return this.points[0].clone().add((this.points[1])).multiplyScalar(0.5)
  371. }else return this.points[0].clone()
  372. }
  373. // updateAzimuth(){
  374. // // if(this.points.length !== 2){
  375. // // return;
  376. // // }
  377. // // const azimuth = this.azimuth;
  378. // // const [p0, p1] = this.points;
  379. // // const r = p0.distanceTo(p1);
  380. // }
  381. createGuideLine(){//add 辅助线
  382. var guideEdge = LineDraw.createFatLine([
  383. 0, 0, 0,
  384. 0, 0, 0,
  385. ],{material:this.getLineMat('guide')} )
  386. guideEdge.visible = false
  387. return guideEdge;
  388. }
  389. createAreaLabel(){
  390. /* const areaLabel = new Label({
  391. className:'measure_area',
  392. })
  393. areaLabel.elem.on('mouseover',()=>{
  394. this.setSelected(true, 'areaLabel')
  395. })
  396. areaLabel.elem.on('mouseout',()=>{
  397. this.setSelected(false, 'areaLabel')
  398. }) */
  399. const areaLabel = new TextSprite(
  400. $.extend(mainLabelProp,{sizeInfo: labelSizeInfo, name:'areaLabel_'} )
  401. )
  402. areaLabel.addEventListener('mouseover',()=>{
  403. this.setSelected(true, 'areaLabel')
  404. })
  405. areaLabel.addEventListener('mouseleave',()=>{
  406. this.setSelected(false, 'areaLabel')
  407. })
  408. areaLabel.addEventListener('click',()=>{
  409. viewer.focusOnObject(this, 'measure')
  410. })
  411. viewer.setObjectLayers(areaLabel, 'measure' )
  412. areaLabel.visible = false
  413. return areaLabel;
  414. }
  415. getMarkerMaterial(type) {
  416. if(!markerMats){
  417. markerMats = {
  418. default: new DepthBasicMaterial({
  419. transparent: !0,
  420. opacity: 1,
  421. map: texLoader.load(Potree.resourcePath+'/textures/pic_point32.png' ),
  422. useDepth:true
  423. }),
  424. select: new DepthBasicMaterial({
  425. transparent: !0,
  426. opacity: 1,
  427. map: texLoader.load(Potree.resourcePath+'/textures/pic_point_s32.png'/* , null, null, { antialias: false } */),
  428. }),
  429. }
  430. Measure.markerMats = markerMats
  431. }
  432. return markerMats[type]
  433. }
  434. getLineMat(type) {
  435. if(!Measure.lineMats){
  436. Measure.lineMats = {
  437. edgeDefault: LineDraw.createFatLineMat({
  438. color: color,
  439. dashSize: 0.5,
  440. gapSize: 0.2,
  441. linewidth: config.measure.lineWidth,
  442. useDepth :true
  443. }),
  444. edgeSelect: LineDraw.createFatLineMat({
  445. color: highLightColor,//'#f0ff00',
  446. dashSize: 0.5,
  447. gapSize: 0.2,
  448. linewidth: config.measure.lineWidth
  449. }),
  450. guide: LineDraw.createFatLineMat({
  451. color:config.measure.guideLineColor,
  452. dashSize: 0.1,
  453. gapSize: 0.02,
  454. dashed: true,
  455. linewidth: config.measure.lineWidth
  456. })
  457. }
  458. }
  459. return Measure.lineMats[type]
  460. }
  461. createAreaPlane(){
  462. planeMats || (planeMats = {
  463. default: new DepthBasicMaterial({
  464. color:color,
  465. side:THREE.DoubleSide,
  466. opacity:0.2,
  467. transparent:true,
  468. useDepth:true
  469. }),
  470. selected: new DepthBasicMaterial({
  471. color:color,
  472. side:THREE.DoubleSide,
  473. opacity:0.3,
  474. transparent:true
  475. })
  476. },Measure.planeMats = planeMats)
  477. return super.createAreaPlane(planeMats.default)
  478. }
  479. raycast (raycaster, intersects) {
  480. for (let i = 0; i < this.points.length; i++) {
  481. let marker = this.markers[i];
  482. marker.raycast(raycaster, intersects);
  483. }
  484. // recalculate distances because they are not necessarely correct
  485. // for scaled objects.
  486. // see https://github.com/mrdoob/three.js/issues/5827
  487. // TODO: remove this once the bug has been fixed
  488. for (let i = 0; i < intersects.length; i++) {
  489. let I = intersects[i];
  490. I.distance = raycaster.ray.origin.distanceTo(I.point);
  491. }
  492. intersects.sort(function (a, b) { return a.distance - b.distance; });
  493. };
  494. transformData(prop){
  495. if(prop.measureType == 'Point'){
  496. prop.showCoordinates = true,
  497. prop.closed = true,
  498. prop.maxMarkers = 1,
  499. prop.minMarkers = 1
  500. }else if(prop.measureType == 'Distance'){
  501. prop.showDistances = true,
  502. prop.closed = false,
  503. prop.showEdges = true,
  504. prop.maxMarkers = 2,
  505. prop.minMarkers = 2
  506. }else if(prop.measureType == 'Ver Distance'){
  507. prop.showDistances = true,
  508. prop.closed = false,
  509. prop.showEdges = true,
  510. prop.maxMarkers = 2,
  511. prop.minMarkers = 2,
  512. prop.faceDirection = "vertical"
  513. }else if(prop.measureType == 'Hor Distance'){
  514. prop.showDistances = true,
  515. prop.closed = false,
  516. prop.showEdges = true,
  517. prop.maxMarkers = 2,
  518. prop.minMarkers = 2,
  519. prop.faceDirection = "horizontal"
  520. }else if(prop.measureType == 'Area'){
  521. prop.showDistances = true,
  522. prop.showArea = true,
  523. prop.showEdges = true,
  524. prop.closed = true,
  525. prop.minMarkers = 3
  526. }else if(prop.measureType == 'Hor Area'){
  527. prop.showDistances = true,
  528. prop.showArea = true,
  529. prop.showEdges = true,
  530. prop.closed = true,
  531. prop.minMarkers = 3
  532. prop.faceDirection = "horizontal"
  533. }else if(prop.measureType == 'Ver Area'){
  534. prop.showDistances = true,
  535. prop.showArea = true,
  536. prop.showEdges = true,
  537. prop.closed = true,
  538. prop.minMarkers = 3
  539. prop.faceDirection = "vertical"
  540. }else if(prop.measureType == 'Rect Area'){
  541. prop.showDistances = true,
  542. prop.showArea = true,
  543. prop.showEdges = true,
  544. prop.closed = true,
  545. prop.minMarkers = 4
  546. prop.maxMarkers = 4
  547. }else if(prop.measureType == 'Hor Rect Area'){
  548. prop.showDistances = true,
  549. prop.showArea = true,
  550. prop.showEdges = true,
  551. prop.closed = true,
  552. prop.minMarkers = 4
  553. prop.maxMarkers = 4
  554. prop.isRect = true
  555. prop.faceDirection = "horizontal"
  556. }else if(prop.measureType == 'Ver Rect Area'){
  557. prop.showDistances = true,
  558. prop.showArea = true,
  559. prop.showEdges = true,
  560. prop.closed = true,
  561. prop.minMarkers = 4
  562. prop.maxMarkers = 4
  563. prop.isRect = true
  564. prop.faceDirection = "vertical"
  565. }
  566. }
  567. setUnitSystem(unitSystem){
  568. //console.log(this.name +':' +this.unitSystem)
  569. if(unitSystem != this.unitSystem){
  570. if(unitSystem == "metric"){
  571. }else if(unitSystem == 'imperial'){
  572. }
  573. this.unitSystem = unitSystem
  574. this.update()
  575. }
  576. }
  577. /* get showCoordinates () {
  578. return this._showCoordinates;
  579. }
  580. set showCoordinates (value) {
  581. this._showCoordinates = value;
  582. this.update();
  583. }
  584. get showAngles () {
  585. return this._showAngles;
  586. }
  587. set showAngles (value) {
  588. this._showAngles = value;
  589. this.update();
  590. }
  591. get showCircle () {
  592. return this._showCircle;
  593. }
  594. set showCircle (value) {
  595. this._showCircle = value;
  596. this.update();
  597. }
  598. get showAzimuth(){
  599. return this._showAzimuth;
  600. }
  601. set showAzimuth(value){
  602. this._showAzimuth = value;
  603. this.update();
  604. }
  605. get showEdges () {
  606. return this._showEdges;
  607. }
  608. set showEdges (value) {
  609. this._showEdges = value;
  610. this.update();
  611. }
  612. get showHeight () {
  613. return this._showHeight;
  614. }
  615. set showHeight (value) {
  616. this._showHeight = value;
  617. this.update();
  618. }
  619. get showArea () {
  620. return this._showArea;
  621. }
  622. set showArea (value) {
  623. this._showArea = value;
  624. this.update();
  625. }
  626. get closed () {
  627. return this._closed;
  628. }
  629. set closed (value) {
  630. this._closed = value;
  631. this.update();
  632. }
  633. get showDistances () {
  634. return this._showDistances;
  635. }
  636. set showDistances (value) {
  637. this._showDistances = value;
  638. this.update();
  639. } */
  640. }
  641. function setLabelHightState(label, state){
  642. if(state){
  643. //label.backgroundColor = {r: highLightColor.r*255, g: highLightColor.g*255, b: highLightColor.b*255, a:1},
  644. label.backgroundColor.a = 1
  645. label.sprite.material.useDepth = false;
  646. }else{
  647. //label.backgroundColor = mainLabelProp.backgroundColor
  648. label.backgroundColor.a = config.measure.labelOpacity
  649. label.sprite.material.useDepth = true
  650. }
  651. label.updateTexture()
  652. //label.sprite.material.needsUpdate = true
  653. }
  654. function createCircleRadiusLabel(){
  655. const circleRadiusLabel = new TextSprite("");
  656. circleRadiusLabel.setTextColor({r: 140, g: 250, b: 140, a: 1.0});
  657. circleRadiusLabel.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
  658. circleRadiusLabel.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
  659. circleRadiusLabel.fontsize = 16;
  660. circleRadiusLabel.material.depthTest = false;
  661. circleRadiusLabel.material.opacity = 1;
  662. circleRadiusLabel.visible = false;
  663. return circleRadiusLabel;
  664. }
  665. function createCircleRadiusLine(){
  666. /* const lineGeometry = new LineGeometry();
  667. lineGeometry.setPositions([
  668. 0, 0, 0,
  669. 0, 0, 0,
  670. ]);
  671. const lineMaterial = new LineMaterial({
  672. color: 0xff0000,
  673. linewidth: 2,
  674. resolution: new THREE.Vector2(1000, 1000),
  675. gapSize: 1,
  676. dashed: true,
  677. });
  678. lineMaterial.depthTest = false;
  679. const circleRadiusLine = new Line2(lineGeometry, lineMaterial);*/
  680. var circleRadiusLine = LineDraw.createFatLine([
  681. 0, 0, 0,
  682. 0, 0, 0,
  683. ],{
  684. color:0xff0000,
  685. dashSize: 0.5,
  686. gapSize: 0.2,
  687. linewidth: config.measure.lineWidth
  688. })
  689. circleRadiusLine.visible = false;
  690. return circleRadiusLine;
  691. }
  692. function createCircleLine(){
  693. const coordinates = [];
  694. let n = 128;
  695. for(let i = 0; i <= n; i++){
  696. let u0 = 2 * Math.PI * (i / n);
  697. let u1 = 2 * Math.PI * (i + 1) / n;
  698. let p0 = new THREE.Vector3(
  699. Math.cos(u0),
  700. Math.sin(u0),
  701. 0
  702. );
  703. let p1 = new THREE.Vector3(
  704. Math.cos(u1),
  705. Math.sin(u1),
  706. 0
  707. );
  708. coordinates.push(
  709. ...p0.toArray(),
  710. ...p1.toArray(),
  711. );
  712. }
  713. /* const geometry = new LineGeometry();
  714. geometry.setPositions(coordinates);
  715. const material = new LineMaterial({
  716. color: 0xff0000,
  717. dashSize: 5,
  718. gapSize: 2,
  719. linewidth: 2,
  720. resolution: new THREE.Vector2(1000, 1000),
  721. });
  722. material.depthTest = false;
  723. const circleLine = new Line2(geometry, material);
  724. circleLine.visible = false;
  725. circleLine.computeLineDistances();*/
  726. var circleLine = LineDraw.createFatLine(coordinates,{
  727. color: 0xff0000,
  728. dashSize: 0.5,
  729. gapSize: 0.2,
  730. linewidth: config.measure.lineWidth
  731. })
  732. return circleLine;
  733. }
  734. function createCircleCenter(){
  735. const sg = new THREE.markerGeometry(1, 32, 32);
  736. const sm = new THREE.MeshNormalMaterial();
  737. const circleCenter = new THREE.Mesh(sg, sm);
  738. circleCenter.visible = false;
  739. return circleCenter;
  740. }
  741. function createLine(){
  742. const line = LineDraw.createFatLine([
  743. 0, 0, 0,
  744. 0, 0, 0,
  745. ],{
  746. color: 0xff0000,
  747. dashSize: 0.5,
  748. gapSize: 0.2,
  749. linewidth: config.measure.lineWidth
  750. })
  751. return line;
  752. }
  753. function createCircle(){
  754. const coordinates = [];
  755. let n = 128;
  756. for(let i = 0; i <= n; i++){
  757. let u0 = 2 * Math.PI * (i / n);
  758. let u1 = 2 * Math.PI * (i + 1) / n;
  759. let p0 = new THREE.Vector3(
  760. Math.cos(u0),
  761. Math.sin(u0),
  762. 0
  763. );
  764. let p1 = new THREE.Vector3(
  765. Math.cos(u1),
  766. Math.sin(u1),
  767. 0
  768. );
  769. coordinates.push(
  770. ...p0.toArray(),
  771. ...p1.toArray(),
  772. );
  773. }
  774. var line = LineDraw.createFatLine(coordinates,{
  775. color: 0xff0000,
  776. dashSize: 0.5,
  777. gapSize: 0.2,
  778. linewidth: config.measure.lineWidth
  779. })
  780. return line;
  781. }
  782. function createAzimuth(){
  783. const azimuth = {
  784. label: null,
  785. center: null,
  786. target: null,
  787. north: null,
  788. centerToNorth: null,
  789. centerToTarget: null,
  790. centerToTargetground: null,
  791. targetgroundToTarget: null,
  792. circle: null,
  793. node: null,
  794. };
  795. const sg = new THREE.markerGeometry(1, 32, 32);
  796. const sm = new THREE.MeshNormalMaterial();
  797. {
  798. const label = new TextSprite("");
  799. label.setTextColor({r: 140, g: 250, b: 140, a: 1.0});
  800. label.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
  801. label.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
  802. label.fontsize = 16;
  803. label.material.depthTest = false;
  804. label.material.opacity = 1;
  805. azimuth.label = label;
  806. }
  807. azimuth.center = new THREE.Mesh(sg, sm);
  808. azimuth.target = new THREE.Mesh(sg, sm);
  809. azimuth.north = new THREE.Mesh(sg, sm);
  810. azimuth.centerToNorth = createLine();
  811. azimuth.centerToTarget = createLine();
  812. azimuth.centerToTargetground = createLine();
  813. azimuth.targetgroundToTarget = createLine();
  814. azimuth.circle = createCircle();
  815. azimuth.node = new THREE.Object3D();
  816. azimuth.node.add(
  817. azimuth.centerToNorth,
  818. azimuth.centerToTarget,
  819. azimuth.centerToTargetground,
  820. azimuth.targetgroundToTarget,
  821. azimuth.circle,
  822. azimuth.label,
  823. azimuth.center,
  824. azimuth.target,
  825. azimuth.north,
  826. );
  827. return azimuth;
  828. }
  829. /*
  830. */