Measure.js 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487
  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.js";
  6. import math from "../../utils/math.js";
  7. import DepthBasicMaterial from "../../materials/DepthBasicMaterial.js";
  8. import Sprite from '../Sprite.js'
  9. import {config} from '../../settings.js'
  10. import {ctrlPolygon} from './ctrlPolygon.js'
  11. let texLoader = new THREE.TextureLoader()
  12. let defaultColor = new THREE.Color(config.measure.default.color);
  13. let highlightColor = new THREE.Color(config.measure.highlight.color);
  14. let color = new THREE.Color(config.measure.color)
  15. let textColor = new THREE.Color(config.measure.textColor)
  16. var markerMats = {}
  17. var lineMats ;
  18. var planeMats
  19. const lineDepthInfo = {
  20. clipDistance : 4,//消失距离
  21. occlusionDistance: 1,//变为backColor距离
  22. }
  23. const planeDepthInfo = {
  24. clipDistance : 30,//消失距离
  25. occlusionDistance: 4,//变为backColor距离
  26. maxOcclusionFactor:0.3,
  27. maxClipFactor:0.1
  28. }
  29. const textSizeRatio = math.linearClamp(window.innerWidth * window.innerHeight , 360*720, 1920*1080, 0.75, 1) //pc字显示大一些
  30. const markerSizeInfo = {
  31. minSize : 30*2 , maxSize : 65*2, nearBound : 0.2, farBound : 4,
  32. }
  33. const labelSizeInfo = {width2d:190}
  34. const mainLabelProp = {
  35. //backgroundColor: {r: defaultColor.r*255, g: defaultColor.g*255, b: defaultColor.b*255, a:config.measure.default.opacity},
  36. backgroundColor: {r: 0, g: 0, b: 0, a:0},
  37. textColor: {r: textColor.r*255, g: textColor.g*255, b: textColor.b*255, a: 1.0},
  38. textBorderColor: {r:255, g: 255, b:255, a: 1.0},
  39. textBorderThick:3,
  40. fontsize: 15 * textSizeRatio,
  41. borderRadius : 12, margin:{x:20,y:4},
  42. renderOrder : 5, pickOrder:5,
  43. disToLine:-0.15,
  44. useDepth : true ,
  45. // 2023.10 尽量不让数字被挡住
  46. clipDistance : 50,//消失距离
  47. occlusionDistance: 10,//变为backColor距离
  48. maxOcclusionFactor:0.2,
  49. maxClipFactor:0.1
  50. }
  51. const subLabelProp = {
  52. backgroundColor: {r: 255, g: 255, b: 255, a:config.measure.default.opacity},
  53. textColor: {r: 0.3, g: 0.3, b:0.3, a: 1.0},
  54. fontsize:15 * textSizeRatio, borderRadius : 12, margin:{x:20,y:4},
  55. renderOrder : 4, pickOrder:4,
  56. }
  57. const angle = THREE.Math.degToRad(5);//显示水平垂直辅助线的最小角度
  58. const guideShowMinAngle = {min: angle, max: Math.PI/2 - angle}
  59. export class Measure extends ctrlPolygon{
  60. constructor (prop) {
  61. prop.dimension = '2d'
  62. super('measure',prop);
  63. this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1;
  64. this.name = this.measureType + this.constructor.counter //'Measure_' + this.constructor.counter;
  65. //this.color = '#FF4399'
  66. this.color = new THREE.Color(this.color)
  67. this.markerLabels = [];
  68. this.edgeLabels = [];
  69. this.angleLabels = [];
  70. this.coordinateLabels = [];
  71. this.area = {value:0,string:''}
  72. if( this.showArea ){
  73. this.areaLabel = this.createAreaLabel();
  74. this.add(this.areaLabel)
  75. }
  76. //add:
  77. if(this.atPlane || this.faceDirection){ //是一个平面上的话
  78. if(this.guideLinePoints){
  79. this.createGuideLines()
  80. }else{
  81. this.createGuideLine();
  82. }
  83. }
  84. if(this.measureType == 'Distance' /* || this.measureType.includes('MulDistance') */){
  85. this.createHorVerGuideLine()
  86. }
  87. this.selectStates = {}
  88. this.setUnitSystem(prop.unit || viewer.unitConvert.UnitService.defaultSystem)
  89. Potree.Utils.setObjectLayers(this, 'measure' )
  90. //addMarkers:
  91. this.initData(prop)
  92. this.points_datasets || (this.points_datasets = []) //存每个点是哪个数据集
  93. //这版应该没多数据集,不需要更新这个:
  94. /* this.addEventListener('marker_dropped',(e)=>{
  95. this.updateDatasetBelong(e.index)
  96. }) */
  97. this.addEventListener('isVisible', ()=>{
  98. viewer.mapViewer && viewer.mapViewer.dispatchEvent({type:'content_changed'})
  99. })
  100. }
  101. initData(prop){
  102. let makeIt = super.initData(prop)
  103. if(makeIt){
  104. this.edges.forEach(edge=>{edge.dispatchEvent('addHoverEvent') })
  105. }else{
  106. this.failBuilded = true
  107. }
  108. }
  109. updateDatasetBelong(changeIndex){//更新所属数据集
  110. if(Potree.settings.editType == "merge"){//无地图
  111. /* this.dataset_points = this.points.map((e,i)=>{
  112. return Potree.Utils.datasetPosTransform({toDataset:true, datasetId:this.points_datasets[i], position:e.clone()})
  113. }) */
  114. this.dataset_points[changeIndex] = Potree.Utils.datasetPosTransform({toDataset:true, datasetId:this.points_datasets[changeIndex], position:this.points[changeIndex].clone()})
  115. return
  116. }
  117. let old = this.datasetId
  118. let maxCount = {id:null,count:0}
  119. let datasets = {}
  120. this.points_datasets.forEach(e=>{
  121. if(e == void 0)return
  122. if(datasets[e]){
  123. datasets[e] ++
  124. }else{
  125. datasets[e] = 1
  126. }
  127. })
  128. for(let i in datasets) {
  129. if(datasets[i]>maxCount.count){
  130. maxCount = {id:i, count:datasets[i]}
  131. }
  132. }
  133. this.datasetId = maxCount.count > 0 ? maxCount.id : null
  134. //if(this.datasetId != old){
  135. //this.dispatchEvent({type:'changeDatasetId'})
  136. if(this.datasetId == void 0){
  137. this.dataset_points = null //可能为空或[null,null...]
  138. }else{
  139. this.dataset_points = this.points.map(e=>{
  140. return Potree.Utils.datasetPosTransform({toDataset:true,datasetId:this.datasetId, position:e.clone()})
  141. })
  142. }
  143. //}
  144. }
  145. transformByPointcloud(){//每次移动点云 or 加载测量线时要获取一下当前position //有地图时
  146. if(this.datasetId == void 0)return
  147. this.points = this.dataset_points.map(e=>{
  148. return Potree.Utils.datasetPosTransform({fromDataset:true, datasetId:this.datasetId, position:e.clone()})
  149. })
  150. this.getPoint2dInfo(this.points)
  151. this.update({ifUpdateMarkers:true})
  152. this.setSelected(false)//隐藏edgelabel
  153. }
  154. update(options={}) {
  155. super.update(options)
  156. if(this.showCoordinates && this.points.length>0){
  157. let position = this.points[0];
  158. this.markers[0].position.copy(position);
  159. { // coordinate labels
  160. let coordinateLabel = this.coordinateLabels[0];
  161. let lonlat = viewer.transform.lonlatToLocal.inverse(position.toArray())
  162. let EPSG4550 = viewer.transform.lonlatTo4550.forward(lonlat)
  163. let pos = [
  164. position.toArray(),
  165. lonlat,
  166. EPSG4550
  167. ]
  168. //let msg = position.toArray().map(p => Utils.addCommas(p.toFixed(2))).join(" / ");
  169. let msg = pos.map(a=>
  170. a.map(p => Utils.addCommas(p.toFixed(10))).join(", ")
  171. ).join("<br>")
  172. coordinateLabel.setText(msg);
  173. coordinateLabel.setPos(position)
  174. coordinateLabel.setVisible(true)//this.showCoordinates;
  175. }
  176. return
  177. }
  178. /* viewer.addEventListener('camera_changed',(e)=>{
  179. if(e.changeInfo.positionChanged){
  180. setLabelPos()
  181. }
  182. }) */
  183. let setEdgeLabel = (label,p1,p2,distance)=>{//设置label位置和字
  184. this.setEdgeLabelPos(label,p1,p2)
  185. distance = distance == void 0 ? p1.distanceTo(p2) : distance;
  186. var text = this.labelText || viewer.unitConvert.convert(distance, 'distance', Potree.settings.precision , this.unitSystem, 0.001 , true, true)//distance要传0.1 这个factor
  187. label.setText(text)
  188. }
  189. let lastIndex = this.points.length - 1;
  190. for (let index = 0; index <= lastIndex; index++) {
  191. let nextIndex = (index + 1 > lastIndex) ? 0 : index + 1;
  192. let previousIndex = (index === 0) ? lastIndex : index - 1;
  193. //if(!this.closed && nextIndex == 0 )break; //add
  194. let point = this.points[index];
  195. let nextPoint = this.points[nextIndex];
  196. let previousPoint = this.points[previousIndex];
  197. if(this.showDistances || this.labelText){ // edge labels
  198. let edgeLabel = this.edgeLabels[index];
  199. let distance = this.labelText || point.distanceTo(nextPoint)
  200. edgeLabel.shouldVisi = (this.labelText || distance>0) && (index < lastIndex || this.isRect || this.closed && !this.isNew )
  201. /* this.closed || */edgeLabel.setVisible(edgeLabel.shouldVisi)
  202. if(edgeLabel.shouldVisi){
  203. this.lineDir = new THREE.Vector3().subVectors(point,nextPoint).normalize() //[point,nextPoint]
  204. setEdgeLabel(edgeLabel,point,nextPoint,distance)
  205. }
  206. }
  207. }
  208. if(this.measureType == 'Distance' && this.points.length>1){//设置水平垂直辅助线
  209. var pTop, pBtm
  210. if(this.points[0].z > this.points[1].z ){
  211. pTop = this.points[0];
  212. pBtm = this.points[1];
  213. }else{
  214. pTop = this.points[1];
  215. pBtm = this.points[0];
  216. }
  217. let projectPos = new THREE.Vector3(pTop.x, pTop.y, pBtm.z);//两条guideline的交点
  218. {//倾斜角度太小的时候不显示
  219. let tan = pTop.distanceTo(projectPos) / pBtm.distanceTo(projectPos)
  220. let angle = Math.atan(tan);
  221. this.shouldShowHorVerGuide = angle > guideShowMinAngle.min && angle < guideShowMinAngle.max
  222. }
  223. LineDraw.updateLine(this.verGuideEdge, [pTop, projectPos])
  224. LineDraw.updateLine(this.horGuideEdge, [pBtm, projectPos])
  225. setEdgeLabel(this.verEdgeLabel,pTop,projectPos)
  226. setEdgeLabel(this.horEdgeLabel,pBtm,projectPos)
  227. this.verGuideEdge.visible = this.horGuideEdge.visible = this.shouldShowHorVerGuide
  228. this.verEdgeLabel.visible = this.horEdgeLabel.visible = this.shouldShowHorVerGuide
  229. }
  230. if(this.showArea && this.point2dInfo){ // update area
  231. /* if(this.points.length>2){
  232. this.area = {value:0};
  233. this.areaLabel.setVisible(false)
  234. }else{ */
  235. let area = Math.abs(math.getArea(this.point2dInfo.points2d))//this.getArea();
  236. let msg = viewer.unitConvert.convert(area, 'area', Potree.settings.precision, this.unitSystem/* , 0.1 */ )
  237. this.area = {value:area, string:msg}
  238. this.areaLabel.setPos(this.center);
  239. this.areaLabel.setText(msg);
  240. this.areaLabel.setVisible(true)
  241. //}
  242. }
  243. };
  244. setEdgeLabelPos(label,p1,p2){ //调整label的位置,使倾斜后看起来在线的中心,而不要挡住端点
  245. let center = new THREE.Vector3().addVectors(p1,p2).multiplyScalar(0.5);
  246. if(this.lineDir && this.lineDir.length() > 0){
  247. if(viewer.mainViewport.camera.type == 'OrthographicCamera'){
  248. label.setPos(center)
  249. }else{
  250. //根据视线和线的夹角(后又加入相机和两个端点距离差)来决定标签偏移位置。+
  251. let eyePos = viewer.mainViewport.camera.position;
  252. let dir = viewer.mainViewport.view.direction //new THREE.Vector3().subVectors(center,eyePos).normalize()
  253. /*let centerDir = new THREE.Vector3().subVectors(center,eyePos).normalize()
  254. if(centerDir.dot(dir)<0){//中点在相机后方,就不设置
  255. label.setPos(center)
  256. return
  257. } */
  258. let cos = dir.dot(this.lineDir)
  259. let nearPoint = cos > 0 ? p2 : p1 //近端点。
  260. let far = cos > 0 ? p1 : p2 //远端点。
  261. let nearPointDir = new THREE.Vector3().subVectors(nearPoint,eyePos)//.normalize()
  262. //使label在中点和近端点中变化, 近端点可能到了相机后方,需要投影到相机所在平面上
  263. if(nearPointDir.dot(dir)<0){//近端点到了相机后方,前移。
  264. //let hfov = cameraLight.getHFOVForCamera(viewer.mainViewport.camera , true ); //暂且只看水平fov
  265. //if(nearPointDir.dot(dir)<Math.cos(hfov/2)){//近端点在镜头外,前移。 --但是这个就得把点转化成在镜头边缘而非左右两边(camDirPlane上)
  266. let ray = new THREE.Raycaster()
  267. ray.set(nearPoint, cos>0?this.lineDir:this.lineDir.clone().negate())
  268. let camDirPlane = new THREE.Plane().setFromNormalAndCoplanarPoint(dir, eyePos)
  269. nearPoint = ray.ray.intersectPlane(camDirPlane, new THREE.Vector3())
  270. if(!nearPoint){//线是垂直的,视线是水平的时候
  271. return label.setPos(center)
  272. }
  273. }
  274. //防止离远了之后也偏移很多,但远了之后相机到端点vec和到中点的vec的夹角接近,不需要怎么偏移的。
  275. let dis1 = nearPoint.distanceToSquared(eyePos)
  276. let dis2 = far.distanceToSquared(eyePos)
  277. let diff = Math.abs(dis1/dis2)
  278. diff<1 && (diff = 1/diff)
  279. diff = math.linearClamp(diff,0, 30, 0,1 )
  280. let efficiency = 0.7; // 0-1 数值越高,r越容易接近1或-1,label越容易在倾斜后靠近近端点。
  281. //let r = 0.5*efficiency*cos + 0.5
  282. let r = 0.5*efficiency*diff*cos + 0.5
  283. r = THREE.Math.clamp(r,0.1,0.9)
  284. //视线越接近线的方向,标签应该越往近端点偏移,防止看起来几乎在远端。
  285. if(cos > 0){
  286. center = p1.clone().multiplyScalar(1-r).add(nearPoint.clone().multiplyScalar(r)); //label在线上滑动,使尽量保持在视觉中心
  287. }else{
  288. center = nearPoint.clone().multiplyScalar(1-r).add(p2.clone().multiplyScalar(r)); //label在线上滑动,使尽量保持在视觉中心
  289. }
  290. label.setPos(center)
  291. }
  292. //归零
  293. this.orient2dInfo = null
  294. this.markers.forEach(e=>e.needsUpdate=true)
  295. }else{
  296. label.setPos(center)
  297. }
  298. }
  299. addMarker (o={}) {
  300. let marker = new Sprite({mat:this.getMarkerMaterial('default'), sizeInfo: markerSizeInfo, name:"measure_point"} )
  301. Potree.Utils.setObjectLayers(marker, 'measure' )
  302. marker.pickOrder = marker.renderOrder = 3
  303. marker.markerSelectStates = {}
  304. marker.addEventListener('startDragging',(e)=>{
  305. if(e.drag.dragViewport.name == 'MainView')viewer.inputHandler.dispatchEvent( {type: 'isMeasuring',v:true, cause:'startDragging'})
  306. })
  307. marker.addEventListener('drop',(e)=>{
  308. viewer.inputHandler.dispatchEvent({type: 'isMeasuring', v:false, cause:'stopDragging'} )
  309. })
  310. marker.measure = this
  311. let edge
  312. { // edges
  313. edge = LineDraw.createFatLine( [ ],{material:this.getLineMat('edgeDefault')} )
  314. edge.pickOrder = 0
  315. Potree.Utils.setObjectLayers(edge, 'measure' )
  316. let addHoverEvent = ()=>{ //当非isNew时才添加事件
  317. let mouseover = (e) => {this.setSelected(true, 'edge')};
  318. let mouseleave = (e) => {this.setSelected(false, 'edge')};
  319. edge.addEventListener('mouseover', mouseover);
  320. edge.addEventListener('mouseleave', mouseleave);
  321. edge.removeEventListener('addHoverEvent', addHoverEvent);
  322. //2023.10.25add:
  323. edge.addEventListener('click',()=>{
  324. if(!this.isNew) this.focus()
  325. })
  326. }
  327. edge.addEventListener('addHoverEvent', addHoverEvent);
  328. }
  329. super.addMarker({point:o.point, marker:marker, edge})
  330. if(this.showEdges){ // edge labels
  331. const edgeLabel = this.createEdgeLabel('edgeLabel', !this.closed)
  332. edgeLabel.measure = this
  333. this.edgeLabels.push(edgeLabel);
  334. }
  335. if(this.showCoordinates){ // coordinate labels
  336. let coordinateLabel = new Label({
  337. className:'measure_pointPos',
  338. camera: viewer.scene.getActiveCamera()
  339. })
  340. coordinateLabel.setVisible(false)
  341. this.coordinateLabels.push(coordinateLabel);
  342. }
  343. let event = {
  344. type: 'marker_added',
  345. measurement: this,
  346. marker: marker
  347. };
  348. this.dispatchEvent(event);
  349. //this.setMarker(this.points.length - 1, point);
  350. this.update()//更新一下倒数第二条线
  351. return marker;//add
  352. };
  353. editStateChange(state){ //主要针对edgeLabels显示切换,编辑时显示
  354. super.editStateChange(state)
  355. if(!state){
  356. this.editStateTimer = setTimeout(()=>{
  357. if(!this.isEditing){
  358. this.dispatchEvent({type:'editStateChange',state:false})
  359. this.setEdgesDisplay(false)
  360. this.areaPlane && Potree.Utils.updateVisible(this.areaPlane, 'intersectLastLine', true)
  361. this.areaLabel && Potree.Utils.updateVisible(this.areaLabel, 'intersectLastLine', true)
  362. }
  363. },100)
  364. }else{
  365. if(!this.isEditing){
  366. this.dispatchEvent({type:'editStateChange',state:true})
  367. this.setEdgesDisplay(true)
  368. clearTimeout(this.editStateTimer)
  369. }
  370. }
  371. this.isEditing = state
  372. viewer.dispatchEvent({type:'MeasureDragChange',state})
  373. }
  374. setMarkerSelected(marker, state, hoverObject){
  375. //console.warn(marker.id , state, hoverObject)
  376. marker.markerSelectStates[hoverObject] = state
  377. let absoluteState = false
  378. for(var i in marker.markerSelectStates){
  379. if(marker.markerSelectStates[i] == 'hover'){
  380. absoluteState = true; break;
  381. }
  382. }
  383. if(absoluteState){
  384. marker.material = this.getMarkerMaterial('select')
  385. }else{
  386. marker.material = this.getMarkerMaterial('default')
  387. }
  388. marker.selected = absoluteState
  389. viewer.mapViewer && viewer.mapViewer.dispatchEvent('content_changed')
  390. viewer.dispatchEvent('content_changed')
  391. }
  392. setEdgesDisplay(state, ignoreGuideLine){
  393. this.closed && this.edgeLabels.forEach(e=>e.setVisible(!!(state && e.shouldVisi)) )
  394. if(!ignoreGuideLine && this.measureType == 'Distance'){
  395. this.horEdgeLabel.visible = this.verEdgeLabel.visible = this.horGuideEdge.visible = this.verGuideEdge.visible = !!(state && this.shouldShowHorVerGuide)
  396. }
  397. }
  398. setSelected(state, hoverObject){//add
  399. //console.log('setSelected', state, hoverObject)
  400. hoverObject && (this.selectStates[hoverObject] = state)
  401. let absoluteState = false
  402. for(var i in this.selectStates){
  403. if(this.selectStates[i]){
  404. absoluteState = true; break;
  405. }
  406. }
  407. if(absoluteState){
  408. this.markers.forEach(e=>this.setMarkerSelected(e, 'hover', 'selectAll' ) )
  409. this.edges.forEach(e=>e.material = this.getLineMat('edgeSelect') )
  410. this.areaPlane && (this.areaPlane.material = planeMats.selected)
  411. //this.areaLabel && this.areaLabel.elem.addClass('highLight')
  412. //this.closed || this.edgeLabels.forEach(e=>e.elem.addClass('highLight') )
  413. this.setEdgesDisplay(true, hoverObject=="screenshot")
  414. this.areaLabel && this.setLabelHightState(this.areaLabel, true)
  415. this.closed || this.edgeLabels.forEach(e=>this.setLabelHightState(e, true) )
  416. }else{
  417. this.markers.forEach(e=>this.setMarkerSelected(e, 'unhover', 'selectAll' ))
  418. this.edges.forEach(e=>e.material = this.getLineMat('edgeDefault') )
  419. this.areaPlane && (this.areaPlane.material = planeMats.default)
  420. this.setEdgesDisplay(false, hoverObject=="screenshot")
  421. //this.areaLabel && this.areaLabel.elem.removeClass('highLight')
  422. //this.closed || this.edgeLabels.forEach(e=>e.elem.removeClass('highLight') )
  423. this.areaLabel && this.setLabelHightState(this.areaLabel, false)
  424. this.closed || this.edgeLabels.forEach(e=>this.setLabelHightState(e, false) )
  425. }
  426. this.selected = absoluteState
  427. if(hoverObject != 'byList'){
  428. //this.bus && this.bus.emit('highlight', this.selected)
  429. this.dispatchEvent({type:'highlight',state:this.selected})//列表高亮
  430. }
  431. viewer.dispatchEvent('content_changed')
  432. viewer.mapViewer && viewer.mapViewer.dispatchEvent('content_changed')
  433. }
  434. setLabelHightState(label, state){
  435. if(state){
  436. let color = new THREE.Color(Potree.config.measure.highlight.color)
  437. //label.sprite.material.opacity = config.measure.highlight.opacity
  438. //label.setBackgroundColor({r:255*color.r, g:255*color.g, b:255*color.b, a:config.measure.highlight.opacity})
  439. label.sprite.material.useDepth = false;
  440. //label.textColor = {r: this.color.r*255, g: this.color.g*255, b: this.color.b*255, a: 1}
  441. }else{
  442. //label.setBackgroundColor({r: this.color.r*255, g: this.color.g*255, b: this.color.b*255, a:config.measure.default.opacity})
  443. label.sprite.material.useDepth = true
  444. //label.sprite.material.opacity = 0.98
  445. //label.textColor = {r: 255, g: 255, b: 255, a: 1}
  446. }
  447. label.updateTexture()
  448. }
  449. removeMarker(index ){
  450. super.removeMarker(index)
  451. this.points_datasets.splice(index, 1);
  452. this.dataset_points && this.dataset_points.splice(index, 1)
  453. this.coordinateLabels.splice(index, 1);
  454. let edgeIndex = index//(index === 0) ? 0 : (index - 1);
  455. if(this.edgeLabels[edgeIndex]){
  456. this.edgeLabels[edgeIndex].dispose()
  457. this.edgeLabels.splice(edgeIndex, 1);
  458. }
  459. this.update();
  460. this.dispatchEvent({type: 'marker_removed', measurement: this});
  461. }
  462. setPosition(index, position) {
  463. super.setPosition(index, position)
  464. //相连的点的箭头也要更新方向
  465. this.markers[(index + this.points.length - 1) % this.points.length].waitUpdate()
  466. this.markers[(index + this.points.length + 1) % this.points.length].waitUpdate()
  467. let event = {
  468. type: 'marker_moved',
  469. measure: this,
  470. index: index,
  471. position: position.clone()
  472. };
  473. this.dispatchEvent(event);
  474. }
  475. dispose(){//add
  476. var labels = this.edgeLabels.concat(this.coordinateLabels)
  477. this.areaLabel && labels.push(this.areaLabel)
  478. labels.forEach(e=>e.dispatchEvent({type:'dispose'}))
  479. super.dispose()
  480. }
  481. getTotalDistance () {
  482. if (this.points.length === 0) {
  483. return 0;
  484. }
  485. let distance = 0;
  486. for (let i = 1; i < this.points.length; i++) {
  487. let prev = this.points[i - 1];
  488. let curr = this.points[i];
  489. let d = prev.distanceTo(curr);
  490. distance += d;
  491. }
  492. if (this.closed && this.points.length > 1) {
  493. let first = this.points[0];
  494. let last = this.points[this.points.length - 1];
  495. let d = last.distanceTo(first);
  496. distance += d;
  497. }
  498. return distance;
  499. }
  500. getAngleBetweenLines (cornerPoint, point1, point2) {
  501. let v1 = new THREE.Vector3().subVectors(point1, cornerPoint);
  502. let v2 = new THREE.Vector3().subVectors(point2, cornerPoint);
  503. // avoid the error printed by threejs if denominator is 0
  504. const denominator = Math.sqrt( v1.lengthSq() * v2.lengthSq() );
  505. if(denominator === 0){
  506. return 0;
  507. }else{
  508. return v1.angleTo(v2);
  509. }
  510. };
  511. getAngle (index) {
  512. if (this.points.length < 3 || index >= this.points.length) {
  513. return 0;
  514. }
  515. let previous = (index === 0) ? this.points[this.points.length - 1] : this.points[index - 1];
  516. let point = this.points[index];
  517. let next = this.points[(index + 1) % (this.points.length)];
  518. return this.getAngleBetweenLines(point, previous, next);
  519. }
  520. getCenter(/* update */){
  521. if(this.closed){
  522. return this.center.clone()
  523. }else{
  524. let center = this.points.reduce(function(total, currentValue ){
  525. return total.add(currentValue)
  526. }, new THREE.Vector3 )
  527. center.multiplyScalar(1/this.points.length)
  528. return center //求不出重心呜呜
  529. }
  530. }
  531. // updateAzimuth(){
  532. // // if(this.points.length !== 2){
  533. // // return;
  534. // // }
  535. // // const azimuth = this.azimuth;
  536. // // const [p0, p1] = this.points;
  537. // // const r = p0.distanceTo(p1);
  538. // }
  539. createGuideLine(){//add 辅助线
  540. var guideLine = LineDraw.createFatLine([ ],{material:this.getLineMat('guide')} )
  541. guideLine.visible = false
  542. this.guideLine = guideLine
  543. this.add(guideLine);
  544. }
  545. createHorVerGuideLine(){//创建水平与垂直辅助线,仅距离测量有。
  546. var verGuideEdge = LineDraw.createFatLine([ ],{material:this.getLineMat('guide')} )
  547. verGuideEdge.visible = false
  548. this.verGuideEdge = verGuideEdge
  549. verGuideEdge.name = 'verGuideEdge'
  550. var horGuideEdge = LineDraw.createFatLine([ ],{material:this.getLineMat('guide')} )
  551. horGuideEdge.visible = false
  552. horGuideEdge.name = 'horGuideEdge'
  553. this.horGuideEdge = horGuideEdge
  554. this.add(this.verGuideEdge);
  555. this.add(this.horGuideEdge);
  556. //label:
  557. this.verEdgeLabel = this.createEdgeLabel('verGuideEdge')
  558. this.horEdgeLabel = this.createEdgeLabel('horGuideEdge')
  559. }
  560. createGuideLines(){//add 固定点垂线的辅助线 可以多段
  561. var guideLine = LineDraw.createFatLine(this.guideLinePoints ,{material:this.getLineMat('guide')} )
  562. this.guideLine = guideLine //暂时也叫这个名字
  563. this.add(guideLine);
  564. }
  565. updateGuideLines(){
  566. this.guideLine.updateLine(this.guideLine, this.guideLinePoints)
  567. }
  568. focus({dontMoveCamera=false}={}){
  569. if(this.clickSelected)return
  570. if(Potree.settings.displayMode == 'showPanos')dontMoveCamera = true //2023.10.24 新需求:点击后不移动,否则经常跳到别的点。且在app上会反应一秒才选中。
  571. if(!dontMoveCamera){
  572. let dontChangeCamDir = viewer.mainViewport.camera.type == 'OrthographicCamera' /* && math.closeTo( viewer.mainViewport.view.pitch , -1.57079632) */ // 不改角度
  573. viewer.focusOnObject(this, 'measure', null, {dontChangeCamDir})
  574. }
  575. this.setSelected(true, 'focus')
  576. this.dispatchEvent({type:'selected', state:true})
  577. this.clickSelected = true
  578. //viewer.dispatchEvent({type:'selectMeasure', measure:this})
  579. let cancelSelect = ()=>{
  580. this.clickSelected = false
  581. this.removeEventListener('cancelSelect', cancelSelect)
  582. viewer.removeEventListener('global_click', cancelSelect)
  583. this.setSelected(false, 'focus')
  584. this.dispatchEvent({type:'selected', state:false})
  585. return {stopContinue:true}//不要flytopano
  586. }
  587. setTimeout(()=>{
  588. this.addEventListener('cancelSelect', cancelSelect)
  589. viewer.addEventListener('global_click', cancelSelect,{importance:10})
  590. },10)
  591. }
  592. createEdgeLabel(name, hasHoverEvent){
  593. //mainLabelProp.backgroundColor = {r: this.color.r*255, g: this.color.g*255, b: this.color.b*255, a:config.measure.default.opacity}
  594. const edgeLabel = new TextSprite(
  595. $.extend(hasHoverEvent ? mainLabelProp : subLabelProp,{
  596. sizeInfo: labelSizeInfo, name:name||'edgeLabel',
  597. })
  598. )
  599. if(hasHoverEvent){
  600. edgeLabel.addEventListener('mouseover',()=>{
  601. this.setSelected(true, 'edgeLabel')
  602. })
  603. edgeLabel.addEventListener('mouseleave',()=>{
  604. this.setSelected(false, 'edgeLabel')
  605. })
  606. edgeLabel.addEventListener('click',()=>{
  607. if(!this.isNew) this.focus()
  608. })
  609. //edgeLabel.sprite.material.opacity = config.measure.default.opacity
  610. }
  611. edgeLabel.visible = false
  612. edgeLabel.sprite.material.depthTestWhenPick = true
  613. Potree.Utils.setObjectLayers(edgeLabel, 'measure' )
  614. this.add(edgeLabel)
  615. return edgeLabel
  616. }
  617. createAreaLabel(){
  618. /* const areaLabel = new Label({
  619. className:'measure_area',
  620. })
  621. areaLabel.elem.on('mouseover',()=>{
  622. this.setSelected(true, 'areaLabel')
  623. })
  624. areaLabel.elem.on('mouseout',()=>{
  625. this.setSelected(false, 'areaLabel')
  626. }) */
  627. const areaLabel = new TextSprite(
  628. $.extend({}, mainLabelProp,{sizeInfo: labelSizeInfo, name:'areaLabel', fontsize:16*textSizeRatio} )
  629. )
  630. areaLabel.addEventListener('mouseover',()=>{
  631. this.setSelected(true, 'areaLabel')
  632. })
  633. areaLabel.addEventListener('mouseleave',()=>{
  634. this.setSelected(false, 'areaLabel')
  635. })
  636. areaLabel.addEventListener('click',()=>{
  637. if(!this.isNew) this.focus()
  638. })
  639. Potree.Utils.setObjectLayers(areaLabel, 'measure' )
  640. areaLabel.setVisible(false)
  641. return areaLabel;
  642. }
  643. getMarkerMaterial(type){
  644. let color = this.color.getHexString()
  645. if(!markerMats[type + color]){
  646. markerMats['default' + color] = new DepthBasicMaterial($.extend({},lineDepthInfo,{
  647. transparent: !0,
  648. opacity: 1,
  649. //map: texLoader.load(Potree.resourcePath+'/textures/pic_point_s32.png' ),
  650. map: texLoader.load(Potree.resourcePath+'/textures/arrows_l_32.png' ),
  651. useDepth:true,
  652. replaceColor:this.color,
  653. beReplacedRed: 0.184, //0.18431372
  654. mapColorReplace:true,
  655. })),
  656. markerMats['select' + color] = new DepthBasicMaterial($.extend({},lineDepthInfo,{
  657. transparent: !0,
  658. opacity: 1,
  659. map: texLoader.load(Potree.resourcePath+'/textures/arrows_l_32.png' ),
  660. //useDepth:true ,
  661. replaceColor: new THREE.Color(Potree.config.measure.highlight.color) ,
  662. beReplacedRed: 0.184, //0.18431372
  663. mapColorReplace:true
  664. }))
  665. }
  666. return markerMats[type + color]
  667. }
  668. getLineMat(type) {
  669. if(!lineMats) Measure.lineMats = lineMats = {
  670. guide: LineDraw.createFatLineMat({
  671. color:config.measure.guide.color,
  672. dashSize: 0.1,
  673. gapSize: 0.02,
  674. dashed: true,
  675. lineWidth: 2
  676. })
  677. }
  678. let color = this.color.getHexString()
  679. if(!lineMats['edgeDefault'+color]){
  680. lineMats['edgeDefault'+color] = LineDraw.createFatLineMat(Object.assign({}, lineDepthInfo, {
  681. color: this.color,
  682. lineWidth: config.measure.lineWidth,
  683. useDepth :true,
  684. dashWithDepth :true, // 只在被遮住的部分显示虚线,因为实线容易挡住label
  685. dashed :true,
  686. dashSize : 0.04,
  687. gapSize: 0.04,
  688. transparent: true,
  689. opacity: config.measure.default.opacity,
  690. depthTestWhenPick:true,
  691. }))
  692. lineMats['edgeSelect'+color] = LineDraw.createFatLineMat(Object.assign({}, lineDepthInfo,{
  693. color: Potree.config.measure.highlight.color ,
  694. dashSize: 0.5,
  695. gapSize: 0.2,
  696. lineWidth: config.measure.lineWidth ,
  697. transparent: true,
  698. opacity: config.measure.highlight.opacity
  699. }))
  700. }
  701. if(type != 'guide'){
  702. return Measure.lineMats[type+color]
  703. }else return Measure.lineMats[type]
  704. }
  705. createAreaPlane(){
  706. planeMats || (planeMats = {
  707. default: new DepthBasicMaterial( $.extend({},planeDepthInfo,{
  708. color:color,
  709. side:THREE.DoubleSide,
  710. opacity:0.2,
  711. transparent:true,
  712. useDepth:true
  713. })),
  714. selected: new THREE.MeshBasicMaterial({
  715. color: color ,
  716. side:THREE.DoubleSide,
  717. opacity:0.3,
  718. transparent:true,
  719. })
  720. },Measure.planeMats = planeMats)
  721. return super.createAreaPlane(planeMats.default)
  722. }
  723. raycast (raycaster, intersects) {
  724. for (let i = 0; i < this.points.length; i++) {
  725. let marker = this.markers[i];
  726. marker.raycast(raycaster, intersects);
  727. }
  728. // recalculate distances because they are not necessarely correct
  729. // for scaled objects.
  730. // see https://github.com/mrdoob/three.js/issues/5827
  731. // TODO: remove this once the bug has been fixed
  732. for (let i = 0; i < intersects.length; i++) {
  733. let I = intersects[i];
  734. I.distance = raycaster.ray.origin.distanceTo(I.point);
  735. }
  736. intersects.sort(function (a, b) { return a.distance - b.distance; });
  737. };
  738. transformData(prop){
  739. if(prop.measureType == 'Point'){
  740. prop.showCoordinates = true,
  741. prop.closed = true,
  742. prop.maxMarkers = 1,
  743. prop.minMarkers = 1
  744. }else if(prop.measureType == 'Distance'){
  745. prop.showDistances = true,
  746. prop.showEdges = true,
  747. prop.maxMarkers = 2,
  748. prop.minMarkers = 2
  749. }else if(prop.measureType == 'MulDistance'){//new
  750. prop.showDistances = true,
  751. prop.showEdges = true,
  752. prop.minMarkers = 2
  753. }else if(prop.measureType == 'Ver MulDistance'){
  754. prop.showDistances = true,
  755. prop.atPlane = true,
  756. prop.showEdges = true,
  757. prop.minMarkers = 2
  758. prop.faceDirection = "vertical"
  759. prop.unableDragAtMap = true
  760. }else if(prop.measureType == 'Hor MulDistance'){
  761. prop.showDistances = true,
  762. prop.atPlane = true,
  763. prop.showEdges = true,
  764. prop.minMarkers = 2
  765. prop.faceDirection = "horizontal"
  766. }else if(prop.measureType == 'Ver Distance'){
  767. prop.showDistances = true,
  768. prop.showEdges = true,
  769. prop.maxMarkers = 2,
  770. prop.minMarkers = 2,
  771. prop.faceDirection = "vertical"
  772. prop.unableDragAtMap = true
  773. }else if(prop.measureType == 'Hor Distance'){
  774. prop.showDistances = true,
  775. prop.showEdges = true,
  776. prop.maxMarkers = 2,
  777. prop.minMarkers = 2,
  778. prop.faceDirection = "horizontal"
  779. }else if(prop.measureType == "Hor LINE with Text"){ //add
  780. prop.showEdges = true,
  781. prop.maxMarkers = 2,
  782. prop.minMarkers = 2,
  783. prop.faceDirection = "horizontal"
  784. }else if(prop.measureType == 'Area'){
  785. prop.showDistances = true,
  786. prop.atPlane = true,
  787. prop.showEdges = true,
  788. prop.closed = true,
  789. prop.minMarkers = 3
  790. }else if(prop.measureType == 'Hor Area'){
  791. prop.showDistances = true,
  792. prop.atPlane = true,
  793. prop.showEdges = true,
  794. prop.closed = true,
  795. prop.minMarkers = 3
  796. prop.faceDirection = "horizontal"
  797. }else if(prop.measureType == 'Ver Area'){
  798. prop.showDistances = true,
  799. prop.atPlane = true,
  800. prop.showEdges = true,
  801. prop.closed = true,
  802. prop.minMarkers = 3
  803. prop.faceDirection = "vertical"
  804. prop.unableDragAtMap = true
  805. }else if(prop.measureType == 'Rect Area'){
  806. prop.showDistances = true,
  807. prop.atPlane = true,
  808. prop.showEdges = true,
  809. prop.closed = true,
  810. prop.minMarkers = 4
  811. prop.maxMarkers = 4
  812. }else if(prop.measureType == 'Hor Rect Area'){
  813. prop.showDistances = true,
  814. prop.atPlane = true,
  815. prop.showEdges = true,
  816. prop.closed = true,
  817. prop.minMarkers = 4
  818. prop.maxMarkers = 4
  819. prop.isRect = true
  820. prop.faceDirection = "horizontal"
  821. }else if(prop.measureType == 'Ver Rect Area'){
  822. prop.showDistances = true,
  823. prop.atPlane = true,
  824. prop.showEdges = true,
  825. prop.closed = true,
  826. prop.minMarkers = 4
  827. prop.maxMarkers = 4
  828. prop.isRect = true
  829. prop.faceDirection = "vertical"
  830. prop.unableDragAtMap = true
  831. }
  832. if(prop.atPlane && prop.closed){ //atPlane在同一平面上
  833. prop.showArea = true
  834. }
  835. super.transformData(prop)
  836. }
  837. setUnitSystem(unitSystem){
  838. //console.log(this.name +':' +this.unitSystem)
  839. if(unitSystem != this.unitSystem){
  840. if(unitSystem == "metric"){
  841. }else if(unitSystem == 'imperial'){
  842. }
  843. this.unitSystem = unitSystem
  844. this.update()
  845. }
  846. }
  847. reDraw(restMarkerCount=0){//重新开始画
  848. super.reDraw(restMarkerCount)
  849. if(this.measureType == 'Distance'){
  850. this.shouldShowHorVerGuide = false
  851. this.setEdgesDisplay(false)
  852. }
  853. if(this.showArea){
  854. this.area = {value:0};
  855. this.areaLabel && this.areaLabel.setVisible(false)
  856. }
  857. viewer.inputHandler.dispatchEvent( {type:'isMeasuring', v:true, cause:'reDraw'} )
  858. }
  859. /* get showCoordinates () {
  860. return this._showCoordinates;
  861. }
  862. set showCoordinates (value) {
  863. this._showCoordinates = value;
  864. this.update();
  865. }
  866. get showAngles () {
  867. return this._showAngles;
  868. }
  869. set showAngles (value) {
  870. this._showAngles = value;
  871. this.update();
  872. }
  873. get showCircle () {
  874. return this._showCircle;
  875. }
  876. set showCircle (value) {
  877. this._showCircle = value;
  878. this.update();
  879. }
  880. get showAzimuth(){
  881. return this._showAzimuth;
  882. }
  883. set showAzimuth(value){
  884. this._showAzimuth = value;
  885. this.update();
  886. }
  887. get showEdges () {
  888. return this._showEdges;
  889. }
  890. set showEdges (value) {
  891. this._showEdges = value;
  892. this.update();
  893. }
  894. get showHeight () {
  895. return this._showHeight;
  896. }
  897. set showHeight (value) {
  898. this._showHeight = value;
  899. this.update();
  900. }
  901. get showArea () {
  902. return this._showArea;
  903. }
  904. set showArea (value) {
  905. this._showArea = value;
  906. this.update();
  907. }
  908. get closed () {
  909. return this._closed;
  910. }
  911. set closed (value) {
  912. this._closed = value;
  913. this.update();
  914. }
  915. get showDistances () {
  916. return this._showDistances;
  917. }
  918. set showDistances (value) {
  919. this._showDistances = value;
  920. this.update();
  921. } */
  922. }
  923. function createCircleRadiusLabel(){
  924. const circleRadiusLabel = new TextSprite("");
  925. circleRadiusLabel.setTextColor({r: 140, g: 250, b: 140, a: 1.0});
  926. circleRadiusLabel.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
  927. circleRadiusLabel.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
  928. circleRadiusLabel.fontsize = 16;
  929. circleRadiusLabel.material.depthTest = false;
  930. circleRadiusLabel.material.opacity = 1;
  931. circleRadiusLabel.visible = false;
  932. return circleRadiusLabel;
  933. }
  934. function createCircleRadiusLine(){
  935. /* const lineGeometry = new LineGeometry();
  936. lineGeometry.setPositions([
  937. 0, 0, 0,
  938. 0, 0, 0,
  939. ]);
  940. const lineMaterial = new LineMaterial({
  941. color: 0xff0000,
  942. lineWidth: 2,
  943. resolution: new THREE.Vector2(1000, 1000),
  944. gapSize: 1,
  945. dashed: true,
  946. });
  947. lineMaterial.depthTest = false;
  948. const circleRadiusLine = new Line2(lineGeometry, lineMaterial);*/
  949. var circleRadiusLine = LineDraw.createFatLine([ ],{
  950. color:0xff0000,
  951. dashSize: 0.5,
  952. gapSize: 0.2,
  953. lineWidth: config.measure.lineWidth
  954. })
  955. circleRadiusLine.visible = false;
  956. return circleRadiusLine;
  957. }
  958. function createCircleLine(){
  959. const coordinates = [];
  960. let n = 128;
  961. for(let i = 0; i <= n; i++){
  962. let u0 = 2 * Math.PI * (i / n);
  963. let u1 = 2 * Math.PI * (i + 1) / n;
  964. let p0 = new THREE.Vector3(
  965. Math.cos(u0),
  966. Math.sin(u0),
  967. 0
  968. );
  969. let p1 = new THREE.Vector3(
  970. Math.cos(u1),
  971. Math.sin(u1),
  972. 0
  973. );
  974. coordinates.push(
  975. p0,
  976. p1
  977. );
  978. }
  979. /* const geometry = new LineGeometry();
  980. geometry.setPositions(coordinates);
  981. const material = new LineMaterial({
  982. color: 0xff0000,
  983. dashSize: 5,
  984. gapSize: 2,
  985. lineWidth: 2,
  986. resolution: new THREE.Vector2(1000, 1000),
  987. });
  988. material.depthTest = false;
  989. const circleLine = new Line2(geometry, material);
  990. circleLine.visible = false;
  991. circleLine.computeLineDistances();*/
  992. var circleLine = LineDraw.createFatLine(coordinates,{
  993. color: 0xff0000,
  994. dashSize: 0.5,
  995. gapSize: 0.2,
  996. lineWidth: config.measure.lineWidth
  997. })
  998. return circleLine;
  999. }
  1000. /* function createCircleCenter(){
  1001. const sg = new THREE.markerGeometry(1, 32, 32);
  1002. const sm = new THREE.MeshNormalMaterial();
  1003. const circleCenter = new THREE.Mesh(sg, sm);
  1004. circleCenter.visible = false;
  1005. return circleCenter;
  1006. } */
  1007. function createLine(){
  1008. const line = LineDraw.createFatLine([ ],{
  1009. color: 0xff0000,
  1010. dashSize: 0.5,
  1011. gapSize: 0.2,
  1012. lineWidth: config.measure.lineWidth
  1013. })
  1014. return line;
  1015. }
  1016. function createCircle(){
  1017. const coordinates = [];
  1018. let n = 128;
  1019. for(let i = 0; i <= n; i++){
  1020. let u0 = 2 * Math.PI * (i / n);
  1021. let u1 = 2 * Math.PI * (i + 1) / n;
  1022. let p0 = new THREE.Vector3(
  1023. Math.cos(u0),
  1024. Math.sin(u0),
  1025. 0
  1026. );
  1027. let p1 = new THREE.Vector3(
  1028. Math.cos(u1),
  1029. Math.sin(u1),
  1030. 0
  1031. );
  1032. coordinates.push(
  1033. p0,
  1034. p1
  1035. );
  1036. }
  1037. var line = LineDraw.createFatLine(coordinates,{
  1038. color: 0xff0000,
  1039. dashSize: 0.5,
  1040. gapSize: 0.2,
  1041. lineWidth: config.measure.lineWidth
  1042. })
  1043. return line;
  1044. }
  1045. Measure.markerMats = markerMats;
  1046. /* function createAzimuth(){
  1047. const azimuth = {
  1048. label: null,
  1049. center: null,
  1050. target: null,
  1051. north: null,
  1052. centerToNorth: null,
  1053. centerToTarget: null,
  1054. centerToTargetground: null,
  1055. targetgroundToTarget: null,
  1056. circle: null,
  1057. node: null,
  1058. };
  1059. const sg = new THREE.markerGeometry(1, 32, 32);
  1060. const sm = new THREE.MeshNormalMaterial();
  1061. {
  1062. const label = new TextSprite("");
  1063. label.setTextColor({r: 140, g: 250, b: 140, a: 1.0});
  1064. label.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
  1065. label.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
  1066. label.fontsize = 16;
  1067. label.material.depthTest = false;
  1068. label.material.opacity = 1;
  1069. azimuth.label = label;
  1070. }
  1071. azimuth.center = new THREE.Mesh(sg, sm);
  1072. azimuth.target = new THREE.Mesh(sg, sm);
  1073. azimuth.north = new THREE.Mesh(sg, sm);
  1074. azimuth.centerToNorth = createLine();
  1075. azimuth.centerToTarget = createLine();
  1076. azimuth.centerToTargetground = createLine();
  1077. azimuth.targetgroundToTarget = createLine();
  1078. azimuth.circle = createCircle();
  1079. azimuth.node = new THREE.Object3D();
  1080. azimuth.node.add(
  1081. azimuth.centerToNorth,
  1082. azimuth.centerToTarget,
  1083. azimuth.centerToTargetground,
  1084. azimuth.targetgroundToTarget,
  1085. azimuth.circle,
  1086. azimuth.label,
  1087. azimuth.center,
  1088. azimuth.target,
  1089. azimuth.north,
  1090. );
  1091. return azimuth;
  1092. } */
  1093. /*
  1094. */