|
@@ -6,11 +6,14 @@ import Label from "../Label.js";
|
|
|
import {LineDraw} from "../../utils/DrawUtil.js";
|
|
|
import math from "../../utils/math.js";
|
|
|
import DepthBasicMaterial from "../../materials/DepthBasicMaterial.js";
|
|
|
+import BasicMaterial from '../../materials/BasicMaterial.js'
|
|
|
import Sprite from '../Sprite.js'
|
|
|
import {config} from '../../settings.js'
|
|
|
import browser from "../../utils/browser.js";
|
|
|
import {ctrlPolygon} from './ctrlPolygon.js'
|
|
|
|
|
|
+
|
|
|
+
|
|
|
|
|
|
let texLoader = new THREE.TextureLoader()
|
|
|
let defaultColor = new THREE.Color(config.measure.default.color);
|
|
@@ -18,9 +21,7 @@ let highlightColor = new THREE.Color(config.measure.highlight.color);
|
|
|
|
|
|
let color = new THREE.Color(config.measure.color)
|
|
|
let textColor = new THREE.Color(config.measure.textColor)
|
|
|
-var markerMats;
|
|
|
-var lineMats;
|
|
|
-var planeMats
|
|
|
+let markerMaps
|
|
|
|
|
|
const textSizeRatio = math.linearClamp(window.outerWidth * window.outerHeight , [360*720, 1920*1080], [0.7, 1]) //pc字显示大一些 用
|
|
|
|
|
@@ -81,20 +82,18 @@ const guideShowMinAngle = {min: angle, max: Math.PI/2 - angle}
|
|
|
|
|
|
export class Measure extends ctrlPolygon{
|
|
|
constructor (prop) {
|
|
|
- prop.dimension = '2d'
|
|
|
-
|
|
|
+ prop.dimension = '2d'
|
|
|
super('measure',prop);
|
|
|
this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1;
|
|
|
|
|
|
|
|
|
this.name = this.name || this.measureType + this.constructor.counter
|
|
|
- this.selectStates = {}
|
|
|
-
|
|
|
+ this.selectStates = {}
|
|
|
|
|
|
this.edgeLabels = [];
|
|
|
this.coordinateLabels = [];
|
|
|
this.area = {value:0,string:''}
|
|
|
-
|
|
|
+ this.expands = []
|
|
|
|
|
|
if( this.showArea ){
|
|
|
this.areaLabel = this.createAreaLabel();
|
|
@@ -125,7 +124,7 @@ export class Measure extends ctrlPolygon{
|
|
|
|
|
|
|
|
|
//addMarkers:
|
|
|
-
|
|
|
+
|
|
|
this.initData(prop)
|
|
|
this.pointsPos2d = new Map //屏幕上的二维坐标
|
|
|
|
|
@@ -155,6 +154,11 @@ export class Measure extends ctrlPolygon{
|
|
|
}else{
|
|
|
this.failBuilded = true
|
|
|
}
|
|
|
+ if(prop.expands){ //基本不会从这加
|
|
|
+ for(let data of prop.expands){
|
|
|
+ this.addExpand(data)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -218,7 +222,19 @@ export class Measure extends ctrlPolygon{
|
|
|
this.setSelected(false)//隐藏edgelabel
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ changeColor(color){
|
|
|
+ this.color = color //'#ffffff'
|
|
|
+ this.edges.forEach(e=>e.material = this.getMat('edgeDefault')) //update
|
|
|
+ this.markers.forEach(e=>e.material = this.getMat('markerDefault'))
|
|
|
+ this.areaPlane && (this.areaPlane.material = this.getMat('planeDefault') )
|
|
|
+ this.expands.forEach(e=>e.edges.forEach(a=>a.material = this.getMat('edgeExpand')))
|
|
|
+ viewer.dispatchEvent('content_changed')
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
update(options={}) {
|
|
|
if(options.index == -1)return
|
|
|
|
|
@@ -277,17 +293,18 @@ export class Measure extends ctrlPolygon{
|
|
|
|
|
|
|
|
|
let setLabel = (index)=>{
|
|
|
+ if(index == null)return
|
|
|
let previousIndex = this.getIndex(index, -1)
|
|
|
let nextIndex = this.getIndex(index, +1)
|
|
|
let previousPoint = this.points[previousIndex];
|
|
|
let point = this.points[index];
|
|
|
let nextPoint = this.points[nextIndex];
|
|
|
|
|
|
- if(this.showDistances){ // edge labels
|
|
|
- let edgeLabel = this.edgeLabels[index];
|
|
|
- let distance = point.distanceTo(nextPoint)
|
|
|
+ if(this.showDistances ){ // edge labels
|
|
|
+ let edgeLabel = this.edgeLabels[index];
|
|
|
+ let distance = nextPoint && point.distanceTo(nextPoint)
|
|
|
this.edges[index].distance_ = distance
|
|
|
- edgeLabel.shouldVisi = (index < lastIndex || this.isRect || this.closed && !this.isNew ) && distance>0
|
|
|
+ edgeLabel.shouldVisi = nextPoint && (index < lastIndex || this.isRect || this.closed && !this.isNew ) && distance>0
|
|
|
//this.closed || edgeLabel.setVisible(edgeLabel.shouldVisi) //closed的在setEdgesDisplay中设置
|
|
|
Utils.updateVisible(edgeLabel, 'shouldVisi', edgeLabel.shouldVisi, 2)
|
|
|
if(edgeLabel.shouldVisi){
|
|
@@ -369,7 +386,7 @@ export class Measure extends ctrlPolygon{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ this.expands.forEach(e=>e.update(options))
|
|
|
};
|
|
|
|
|
|
|
|
@@ -582,7 +599,7 @@ export class Measure extends ctrlPolygon{
|
|
|
addMarker (o={}) {
|
|
|
var index = o.index == void 0 ? this.points.length : o.index //要当第几个
|
|
|
|
|
|
- let marker = o.marker || new Sprite({mat:this.getMarkerMaterial('default'), sizeInfo: markerSizeInfo, name:"measure_point"} )
|
|
|
+ let marker = o.marker || new Sprite({mat:this.getMat('markerDefault'), sizeInfo: markerSizeInfo, name:"measure_point"} )
|
|
|
//Potree.Utils.setObjectLayers(marker, 'measure' )
|
|
|
marker.pickOrder = marker.renderOrder = Potree.config.renderOrders.measureMarker
|
|
|
marker.markerSelectStates = {}
|
|
@@ -639,7 +656,7 @@ export class Measure extends ctrlPolygon{
|
|
|
//marker.measure = this
|
|
|
let edge
|
|
|
{ // edges
|
|
|
- edge = o.edge || LineDraw.createFatLine( [ ],{mat:this.getLineMat('edgeDefault')} )
|
|
|
+ edge = o.edge || LineDraw.createFatLine( [ ],{mat:this.getMat('edgeDefault')} )
|
|
|
edge.pickOrder = 0
|
|
|
//Potree.Utils.setObjectLayers(edge, 'measure' )
|
|
|
|
|
@@ -725,7 +742,8 @@ export class Measure extends ctrlPolygon{
|
|
|
marker: marker
|
|
|
};
|
|
|
this.dispatchEvent(event);
|
|
|
-
|
|
|
+
|
|
|
+ this.expands.forEach(e=>e.addMarker(o))
|
|
|
//this.setMarker(this.points.length - 1, point);
|
|
|
this.update({index})//更新一下倒数第二条线
|
|
|
return marker;//add
|
|
@@ -779,10 +797,10 @@ export class Measure extends ctrlPolygon{
|
|
|
}
|
|
|
}
|
|
|
if(absoluteState){
|
|
|
- marker.material = this.getMarkerMaterial('select')
|
|
|
+ marker.material = this.getMat('markerSelect')
|
|
|
marker.renderOrder = marker.pickOrder = Potree.config.renderOrders.measureMarker+1
|
|
|
}else{
|
|
|
- marker.material = this.getMarkerMaterial('default')
|
|
|
+ marker.material = this.getMat('markerDefault')
|
|
|
marker.renderOrder = marker.pickOrder = Potree.config.renderOrders.measureMarker
|
|
|
}
|
|
|
|
|
@@ -830,10 +848,10 @@ export class Measure extends ctrlPolygon{
|
|
|
|
|
|
this.edges.forEach(e=>{
|
|
|
e.renderOrder = Potree.config.renderOrders.line + 1
|
|
|
- e.material = this.getLineMat('edgeSelect')
|
|
|
+ e.material = this.getMat('edgeSelect')
|
|
|
})
|
|
|
|
|
|
- this.areaPlane && (this.areaPlane.material = planeMats.selected)
|
|
|
+ this.areaPlane && (this.areaPlane.material = this.getMat('planeSelected'))
|
|
|
|
|
|
|
|
|
//this.areaLabel && this.areaLabel.elem.addClass('highLight')
|
|
@@ -845,8 +863,8 @@ export class Measure extends ctrlPolygon{
|
|
|
|
|
|
}else{
|
|
|
this.markers.forEach(e=>this.setMarkerSelected(e, 'unhover', 'selectAll' ))
|
|
|
- this.edges.forEach(e=>e.material = this.getLineMat('edgeDefault') )
|
|
|
- this.areaPlane && (this.areaPlane.material = planeMats.default)
|
|
|
+ this.edges.forEach(e=>e.material = this.getMat('edgeDefault') )
|
|
|
+ this.areaPlane && (this.areaPlane.material = this.getMat('planeDefault'))
|
|
|
this.setEdgesDisplay(false, hoverObject=="screenshot")
|
|
|
//this.areaLabel && this.areaLabel.elem.removeClass('highLight')
|
|
|
//this.closed || this.edgeLabels.forEach(e=>e.elem.removeClass('highLight') )
|
|
@@ -878,7 +896,7 @@ export class Measure extends ctrlPolygon{
|
|
|
this.edgeLabels[edgeIndex].dispose()
|
|
|
this.edgeLabels.splice(edgeIndex, 1);
|
|
|
}
|
|
|
-
|
|
|
+ this.expands.forEach(e=>e.removeMarker(index))
|
|
|
this.update({index: this.getIndex(index, -1)});
|
|
|
this.dispatchEvent({type: 'marker_removed', measurement: this});
|
|
|
}
|
|
@@ -898,6 +916,7 @@ export class Measure extends ctrlPolygon{
|
|
|
var labels = this.edgeLabels.concat(this.coordinateLabels)
|
|
|
this.areaLabel && labels.push(this.areaLabel)
|
|
|
labels.forEach(e=>e.dispose())
|
|
|
+ this.expands.forEach(e=>e.dispose())
|
|
|
super.dispose()
|
|
|
this.dispatchEvent('disposed')
|
|
|
}
|
|
@@ -948,18 +967,18 @@ export class Measure extends ctrlPolygon{
|
|
|
|
|
|
|
|
|
createGuideLine(){//add 辅助线
|
|
|
- var guideLine = LineDraw.createFatLine([ ],{mat:this.getLineMat('guide')} )
|
|
|
+ var guideLine = LineDraw.createFatLine([ ],{mat:this.getMat('edgeGuide')} )
|
|
|
guideLine.visible = false
|
|
|
this.guideLine = guideLine
|
|
|
this.add(guideLine);
|
|
|
}
|
|
|
createHorVerGuideLine(){//创建水平与垂直辅助线,仅距离测量有。
|
|
|
- var verGuideEdge = LineDraw.createFatLine([ ],{mat:this.getLineMat('guide')} )
|
|
|
+ var verGuideEdge = LineDraw.createFatLine([ ],{mat:this.getMat('edgeGuide')} )
|
|
|
verGuideEdge.visible = false
|
|
|
this.verGuideEdge = verGuideEdge
|
|
|
verGuideEdge.name = 'verGuideEdge'
|
|
|
|
|
|
- var horGuideEdge = LineDraw.createFatLine([ ],{mat:this.getLineMat('guide')} )
|
|
|
+ var horGuideEdge = LineDraw.createFatLine([ ],{mat:this.getMat('edgeGuide')} )
|
|
|
horGuideEdge.visible = false
|
|
|
horGuideEdge.name = 'horGuideEdge'
|
|
|
this.horGuideEdge = horGuideEdge
|
|
@@ -1046,97 +1065,162 @@ export class Measure extends ctrlPolygon{
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
- getMarkerMaterial(type) {
|
|
|
- if(!markerMats){
|
|
|
- let maps = [texLoader.load(Potree.resourcePath+'/textures/pic_point_s32.png' ),
|
|
|
- texLoader.load(Potree.resourcePath+'/textures/pic_point32.png' )]
|
|
|
- maps.forEach(map=>{
|
|
|
- map.repeat.set(1/markerMapShrink,1/markerMapShrink)
|
|
|
- map.offset.set((markerMapShrink-1)/2/markerMapShrink, (markerMapShrink-1)/2/markerMapShrink)
|
|
|
- })
|
|
|
-
|
|
|
- markerMats = {
|
|
|
- default: new DepthBasicMaterial($.extend({},lineDepthInfo,{
|
|
|
- transparent: !0,
|
|
|
- opacity: 1,
|
|
|
- map: maps[0] ,
|
|
|
- useDepth:true ,
|
|
|
- //mapScale: markerMapShrink
|
|
|
- })),
|
|
|
- select: new THREE.MeshBasicMaterial({
|
|
|
- transparent: !0,
|
|
|
- opacity: 1,
|
|
|
- depthTest:false,
|
|
|
- map: maps[1],
|
|
|
- }),
|
|
|
- }
|
|
|
- Measure.markerMats = markerMats
|
|
|
-
|
|
|
- }
|
|
|
- return markerMats[type]
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
- getLineMat(type) {
|
|
|
- if(!Measure.lineMats){
|
|
|
- Measure.lineMats = {
|
|
|
- edgeDefault: LineDraw.createFatLineMat($.extend({},lineDepthInfo,{
|
|
|
- color: config.measure.default.color,
|
|
|
- lineWidth: config.measure.lineWidth,
|
|
|
- useDepth :true,
|
|
|
- dashWithDepth :true, // 只在被遮住的部分显示虚线,因为实线容易挡住label
|
|
|
- dashed :true,
|
|
|
- dashSize : 0.04,
|
|
|
- gapSize: 0.04,
|
|
|
- transparent: true,
|
|
|
- opacity: config.measure.default.opacity,
|
|
|
- depthTestWhenPick:true,
|
|
|
- })),
|
|
|
- edgeSelect: LineDraw.createFatLineMat($.extend({},lineDepthInfo,{
|
|
|
- color: config.measure.highlight.color,//'#f0ff00',
|
|
|
- dashSize: 0.5,
|
|
|
- gapSize: 0.2,
|
|
|
- lineWidth: config.measure.lineWidth ,
|
|
|
- transparent: true,
|
|
|
- opacity: config.measure.highlight.opacity
|
|
|
- })),
|
|
|
- guide: LineDraw.createFatLineMat($.extend({},lineDepthInfo,{
|
|
|
+ getMat(type) {
|
|
|
+ if(!Measure.Mats){ //不变色的部分
|
|
|
+ Measure.Mats = {
|
|
|
+ edgeGuide: LineDraw.createFatLineMat($.extend({},lineDepthInfo,{
|
|
|
color:config.measure.guide.color,
|
|
|
dashSize: 0.1,
|
|
|
gapSize: 0.02,
|
|
|
dashed: true,
|
|
|
lineWidth: config.measure.lineWidth/2
|
|
|
})),
|
|
|
+ multiColors:{}
|
|
|
+ }
|
|
|
+ {
|
|
|
+ markerMaps = [texLoader.load(Potree.resourcePath+'/textures/whiteCircle.png' ), //pic_point_s32
|
|
|
+ texLoader.load(Potree.resourcePath+'/textures/pic_point32.png' )]
|
|
|
+ markerMaps.forEach(map=>{
|
|
|
+ map.repeat.set(1/markerMapShrink,1/markerMapShrink)
|
|
|
+ map.offset.set((markerMapShrink-1)/2/markerMapShrink, (markerMapShrink-1)/2/markerMapShrink)
|
|
|
+ })
|
|
|
+ markerMaps[0].minFilter = 1006 //禁黑边
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
- return Measure.lineMats[type]
|
|
|
|
|
|
+
|
|
|
+ let mat = Measure.Mats[type]
|
|
|
+ let multiColors = Measure.Mats.multiColors
|
|
|
+ //console.log('getMat', this.name, this.color, type)
|
|
|
+ if(!mat){
|
|
|
+
|
|
|
+ let colorObject = multiColors[this.color]
|
|
|
+ if(!colorObject){
|
|
|
+
|
|
|
+
|
|
|
+ let c = new THREE.Color().set(this.color).getHSL({ h: 0, s: 0, l: 0 })
|
|
|
+ let expandColor = new THREE.Color().setHSL(c.h, c.s, c.l >= 0.4 ? c.l - 0.3: c.l + 0.3)
|
|
|
+ //new THREE.Color().setHSL(c.h, c.s > 0.5 ? c.s - 0.2 : c.s + 0.2, c.l >= 0.6 ? c.l - 0.1 : c.l + 0.1 )
|
|
|
+
|
|
|
+
|
|
|
+ colorObject = {
|
|
|
+ edgeDefault: LineDraw.createFatLineMat($.extend({},lineDepthInfo,{
|
|
|
+ color: this.color || config.measure.default.color,
|
|
|
+ lineWidth: config.measure.lineWidth,
|
|
|
+ useDepth :true,
|
|
|
+ dashWithDepth :true, // 只在被遮住的部分显示虚线,因为实线容易挡住label
|
|
|
+ dashed :true,
|
|
|
+ dashSize : 0.04,
|
|
|
+ gapSize: 0.04,
|
|
|
+ transparent: true,
|
|
|
+ opacity: config.measure.default.opacity,
|
|
|
+ depthTestWhenPick:true,
|
|
|
+ })),
|
|
|
+ edgeSelect: LineDraw.createFatLineMat($.extend({},lineDepthInfo,{
|
|
|
+ color: this.color || config.measure.highlight.color,//'#f0ff00',
|
|
|
+ dashSize: 0.5,
|
|
|
+ gapSize: 0.2,
|
|
|
+ lineWidth: config.measure.lineWidth ,
|
|
|
+ transparent: true,
|
|
|
+ opacity: config.measure.highlight.opacity
|
|
|
+ })),
|
|
|
+
|
|
|
+ edgeExpand : LineDraw.createFatLineMat($.extend({},lineDepthInfo,{
|
|
|
+ color: expandColor,
|
|
|
+ useDepth :true,
|
|
|
+ lineWidth: 2 ,
|
|
|
+ transparent: true,
|
|
|
+ opacity: config.measure.default.opacity,
|
|
|
+ })),
|
|
|
+ markerDefault: new DepthBasicMaterial($.extend({},lineDepthInfo,{
|
|
|
+ transparent: !0,
|
|
|
+ opacity: 1,
|
|
|
+ map: markerMaps[0] ,
|
|
|
+ useDepth:true ,
|
|
|
+ color: this.color,
|
|
|
+ //mapScale: markerMapShrink
|
|
|
+ })),
|
|
|
+ markerSelect: new BasicMaterial({
|
|
|
+ transparent: !0,
|
|
|
+ opacity: 1,
|
|
|
+ depthTest:false,
|
|
|
+ map: markerMaps[1],
|
|
|
+ }),
|
|
|
+ planeDefault : new DepthBasicMaterial( $.extend({},lineDepthInfo,{
|
|
|
+ color : this.color || color,
|
|
|
+ side:THREE.DoubleSide,
|
|
|
+ opacity:0.2,
|
|
|
+ transparent:true,
|
|
|
+ useDepth:true,
|
|
|
+ })),
|
|
|
+ planeSelected: new THREE.MeshBasicMaterial({
|
|
|
+ color: this.color || color,
|
|
|
+ side:THREE.DoubleSide,
|
|
|
+ opacity:0.3,
|
|
|
+ transparent:true,
|
|
|
+ //wireframe:true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ colorObject.markerSelect.defines.replaceColor = '' //将绿色部分替换成color
|
|
|
+ colorObject.markerSelect.uniforms.newMapColor = {type:'v3', value: new THREE.Color(this.color)}
|
|
|
+ colorObject.markerSelect.onBeforeCompile = function ( shader ) {
|
|
|
+ shader.fragmentShader = shader.fragmentShader
|
|
|
+ .replace( 'uniform sampler2D map;', `uniform sampler2D map; uniform vec3 newMapColor;` )//将图中绿色#00C8AF换成指定色
|
|
|
+ .replace( 'gl_FragColor = texColor * color_;', `
|
|
|
+ vec3 texWhite = vec3(1.0,1.0,1.0); //中心部分白色不变,外围原本绿色的r刚好为0,所以r值越高越往白色过渡
|
|
|
+ texColor.rgb = mix(newMapColor, texWhite, texColor.r);
|
|
|
+ gl_FragColor = texColor * color_;` )
|
|
|
+ }
|
|
|
+ multiColors[this.color] = colorObject
|
|
|
+
|
|
|
+ {//清理不用的colorObject
|
|
|
+ let measures = viewer.scene.measurements.slice()
|
|
|
+ measures.includes(this) || measures.push(this)
|
|
|
+ for(let co in multiColors){
|
|
|
+ multiColors[co].useCount = 0
|
|
|
+ }
|
|
|
+ measures.forEach(e=>{
|
|
|
+ multiColors[e.color].useCount ++
|
|
|
+ })
|
|
|
+ let deletes = []
|
|
|
+ for(let co in multiColors){
|
|
|
+ if(multiColors[co].useCount == 0){
|
|
|
+ deletes.push(co)
|
|
|
+ delete multiColors[co].useCount
|
|
|
+ for(let i in multiColors[co]){
|
|
|
+ multiColors[co][i].dispose()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ deletes.forEach(co=>delete multiColors[co])
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ mat = colorObject[type]
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return mat
|
|
|
}
|
|
|
|
|
|
|
|
|
- createAreaPlane(){
|
|
|
- planeMats || (planeMats = {
|
|
|
- default: new DepthBasicMaterial( $.extend({},lineDepthInfo,{
|
|
|
- color:color,
|
|
|
- side:THREE.DoubleSide,
|
|
|
- opacity:0.2,
|
|
|
- transparent:true,
|
|
|
- useDepth:true,
|
|
|
- })),
|
|
|
- selected: new THREE.MeshBasicMaterial({
|
|
|
- color: color ,
|
|
|
- side:THREE.DoubleSide,
|
|
|
- opacity:0.3,
|
|
|
- transparent:true,
|
|
|
- //wireframe:true
|
|
|
- })
|
|
|
- },Measure.planeMats = planeMats)
|
|
|
- return super.createAreaPlane(planeMats.default)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ createAreaPlane(){
|
|
|
+ return super.createAreaPlane(this.getMat('planeDefault'))
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1294,6 +1378,7 @@ export class Measure extends ctrlPolygon{
|
|
|
|
|
|
}
|
|
|
this.unitSystem = unitSystem
|
|
|
+ this.expands.forEach(e=>e.unitSystem = unitSystem)
|
|
|
this.update()
|
|
|
}
|
|
|
}
|
|
@@ -1317,10 +1402,28 @@ export class Measure extends ctrlPolygon{
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+ addExpand(data){//{offset,color}
|
|
|
+ data.measure = this
|
|
|
+ let expand = new ExpandLine(data)
|
|
|
+ this.expands.push(expand)
|
|
|
+ viewer.scene.overlayScene.add(expand) //this.add(expand) //因为其可见性不随父结点所以分开
|
|
|
+ }
|
|
|
+
|
|
|
+ removeExpand(expand){
|
|
|
+ let index = this.expands.indexOf(expand)
|
|
|
+ if(index > -1){
|
|
|
+ expand.dispose()
|
|
|
+ this.expands.splice(index,1)
|
|
|
+ //this.remove(expand)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
function setLabelHightState(label, state){
|
|
|
if(state){
|
|
|
let color = new THREE.Color(Potree.config.measure.highlight.color)
|
|
@@ -1341,26 +1444,8 @@ function setLabelHightState(label, state){
|
|
|
label.updateTexture()
|
|
|
}
|
|
|
|
|
|
-/* function setLabelHightState(label, state){
|
|
|
- if(state){
|
|
|
- label.setBackgroundColor({r: highlightColor.r*255, g: highlightColor.g*255, b: highlightColor.b*255, a:config.measure.highlight.labelOpacity})
|
|
|
- label.sprite.material.useDepth = false;
|
|
|
-
|
|
|
- }else{
|
|
|
- label.setBackgroundColor(mainLabelProp.backgroundColor)
|
|
|
- label.sprite.material.useDepth = true
|
|
|
-
|
|
|
- }
|
|
|
- label.updateTexture()
|
|
|
- //label.sprite.material.needsUpdate = true
|
|
|
-}
|
|
|
|
|
|
|
|
|
- */
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
function createCircleRadiusLabel(){
|
|
|
const circleRadiusLabel = new TextSprite("");
|
|
@@ -1377,24 +1462,7 @@ function createCircleRadiusLabel(){
|
|
|
}
|
|
|
|
|
|
function createCircleRadiusLine(){
|
|
|
- /* const lineGeometry = new LineGeometry();
|
|
|
-
|
|
|
- lineGeometry.setPositions([
|
|
|
- 0, 0, 0,
|
|
|
- 0, 0, 0,
|
|
|
- ]);
|
|
|
-
|
|
|
- const lineMaterial = new LineMaterial({
|
|
|
- color: 0xff0000,
|
|
|
- lineWidth: 2,
|
|
|
- resolution: new THREE.Vector2(1000, 1000),
|
|
|
- gapSize: 1,
|
|
|
- dashed: true,
|
|
|
- });
|
|
|
-
|
|
|
- lineMaterial.depthTest = false;
|
|
|
-
|
|
|
- const circleRadiusLine = new Line2(lineGeometry, lineMaterial);*/
|
|
|
+
|
|
|
|
|
|
var circleRadiusLine = LineDraw.createFatLine([ ],{
|
|
|
color:0xff0000,
|
|
@@ -1432,22 +1500,7 @@ function createCircleLine(){
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- /* const geometry = new LineGeometry();
|
|
|
- geometry.setPositions(coordinates);
|
|
|
-
|
|
|
- const material = new LineMaterial({
|
|
|
- color: 0xff0000,
|
|
|
- dashSize: 5,
|
|
|
- gapSize: 2,
|
|
|
- lineWidth: 2,
|
|
|
- resolution: new THREE.Vector2(1000, 1000),
|
|
|
- });
|
|
|
-
|
|
|
- material.depthTest = false;
|
|
|
-
|
|
|
- const circleLine = new Line2(geometry, material);
|
|
|
- circleLine.visible = false;
|
|
|
- circleLine.computeLineDistances();*/
|
|
|
+
|
|
|
|
|
|
var circleLine = LineDraw.createFatLine(coordinates,{
|
|
|
color: 0xff0000,
|
|
@@ -1459,16 +1512,7 @@ function createCircleLine(){
|
|
|
|
|
|
return circleLine;
|
|
|
}
|
|
|
-
|
|
|
-/* function createCircleCenter(){
|
|
|
- const sg = new THREE.markerGeometry(1, 32, 32);
|
|
|
- const sm = new THREE.MeshNormalMaterial();
|
|
|
-
|
|
|
- const circleCenter = new THREE.Mesh(sg, sm);
|
|
|
- circleCenter.visible = false;
|
|
|
-
|
|
|
- return circleCenter;
|
|
|
-} */
|
|
|
+
|
|
|
|
|
|
function createLine(){
|
|
|
|
|
@@ -1522,66 +1566,108 @@ function createCircle(){
|
|
|
|
|
|
}
|
|
|
|
|
|
-/* function createAzimuth(){
|
|
|
-
|
|
|
- const azimuth = {
|
|
|
- label: null,
|
|
|
- center: null,
|
|
|
- target: null,
|
|
|
- north: null,
|
|
|
- centerToNorth: null,
|
|
|
- centerToTarget: null,
|
|
|
- centerToTargetground: null,
|
|
|
- targetgroundToTarget: null,
|
|
|
- circle: null,
|
|
|
-
|
|
|
- node: null,
|
|
|
- };
|
|
|
-
|
|
|
- const sg = new THREE.markerGeometry(1, 32, 32);
|
|
|
- const sm = new THREE.MeshNormalMaterial();
|
|
|
-
|
|
|
- {
|
|
|
- const label = new TextSprite("");
|
|
|
-
|
|
|
- label.setTextColor({r: 140, g: 250, b: 140, a: 1.0});
|
|
|
- label.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
|
|
|
- label.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
|
|
|
- label.fontsize = 16;
|
|
|
- label.material.depthTest = false;
|
|
|
- label.material.opacity = 1;
|
|
|
-
|
|
|
- azimuth.label = label;
|
|
|
- }
|
|
|
-
|
|
|
- azimuth.center = new THREE.Mesh(sg, sm);
|
|
|
- azimuth.target = new THREE.Mesh(sg, sm);
|
|
|
- azimuth.north = new THREE.Mesh(sg, sm);
|
|
|
- azimuth.centerToNorth = createLine();
|
|
|
- azimuth.centerToTarget = createLine();
|
|
|
- azimuth.centerToTargetground = createLine();
|
|
|
- azimuth.targetgroundToTarget = createLine();
|
|
|
- azimuth.circle = createCircle();
|
|
|
-
|
|
|
- azimuth.node = new THREE.Object3D();
|
|
|
- azimuth.node.add(
|
|
|
- azimuth.centerToNorth,
|
|
|
- azimuth.centerToTarget,
|
|
|
- azimuth.centerToTargetground,
|
|
|
- azimuth.targetgroundToTarget,
|
|
|
- azimuth.circle,
|
|
|
- azimuth.label,
|
|
|
- azimuth.center,
|
|
|
- azimuth.target,
|
|
|
- azimuth.north,
|
|
|
- );
|
|
|
-
|
|
|
- return azimuth;
|
|
|
-} */
|
|
|
|
|
|
|
|
|
|
|
|
+//缓冲区扩展,随measure改变,不可拖拽
|
|
|
+class ExpandLine extends ctrlPolygon{
|
|
|
+
|
|
|
+ constructor (prop) {
|
|
|
+ prop.points = prop.measure.points.map(e=>e.clone()) //先复制 用来加marker
|
|
|
+ prop.unitSystem = prop.measure.unitSystem
|
|
|
+ prop.atPlane = prop.measure.atPlane
|
|
|
+ prop.closed = prop.measure.closed
|
|
|
+ super('expandLine',prop);
|
|
|
+
|
|
|
+ this.name = 'measureExpand_'+prop.measure.name
|
|
|
+
|
|
|
+
|
|
|
+ this.initData(prop)
|
|
|
+
|
|
|
+ //offset 正数为朝外
|
|
|
+ }
|
|
|
+
|
|
|
+ update(options={}){//暂时每次都全部更新,以后再改
|
|
|
+
|
|
|
+ let points = this.measure.points
|
|
|
+ let count = this.measure.points.length
|
|
|
+ let newPoints = []
|
|
|
+ let facePlane = this.getFacePlane(true) //更新normal. 不用measure的是因为measure没更新normal
|
|
|
+ let normal = facePlane?.normal //this.measure.facePlane.normal
|
|
|
+ if(!normal)return //暂时不知道怎么写
|
|
|
+ let offset = this.offset //Potree.math.getArea(this.measure.point2dInfo.points2d) > 0 ? -this.offset : this.offset // 时针受normal影响
|
|
|
+ //console.log('offset',offset, 'normal', normal.toArray(), 'clockwise', Potree.math.getArea(this.measure.point2dInfo.points2d) > 0)
|
|
|
+
|
|
|
+ for(let i=0; i<count; i++){
|
|
|
+
|
|
|
+ let O = points[i] //该点
|
|
|
+ let A = this.measure.getPoint(i,-1)//points[i-1] //上一个点
|
|
|
+ let B = this.measure.getPoint(i,1)//points[i+1] //下一个点
|
|
|
+
|
|
|
+
|
|
|
+ let p1, p2 //该点两边的折点
|
|
|
+ let sideVec //该点两边对应的向量
|
|
|
+ //如果是线段的话,
|
|
|
+
|
|
|
+ if(!A || !B){ //端点
|
|
|
+ let vec = new THREE.Vector3().subVectors(i==0 ? B : O, i==0 ? O : A)
|
|
|
+ sideVec = new THREE.Vector3().crossVectors(normal, vec).normalize().multiplyScalar(offset)
|
|
|
+ //sideVec = new THREE.Vector3().copy(math.getNormal2d({p1: i==0 ? B : O, p2: i==0 ? O : A})).setZ(0).multiplyScalar(this.halfPathWidth) //垂线
|
|
|
+
|
|
|
+ }else{
|
|
|
+ let OA = new THREE.Vector3().subVectors(A,O).normalize() //只保证俯视角度正确。(如果两点有高度差,该段四个点不会在同一平面,看起来有扭转,有的地方会肥大,但从俯视角度看是正确的。)
|
|
|
+ let OB = new THREE.Vector3().subVectors(B,O).normalize()
|
|
|
+ let angle = math.getAngle(OA, OB, normal)
|
|
|
+
|
|
|
+ if(math.closeTo(angle,0,1e-4) || math.closeTo(angle,Math.PI,1e-4) || math.closeTo(angle, -Math.PI,1e-4)){ //这时候直接加两个向量算出的平分线不准,故直接找垂线
|
|
|
+
|
|
|
+ let vec = new THREE.Vector3().subVectors(O, A)
|
|
|
+ sideVec = new THREE.Vector3().crossVectors(normal, vec).normalize().multiplyScalar(offset)
|
|
|
+
|
|
|
+ //sideVec = new THREE.Vector3().copy(math.getNormal2d({p1: O, p2: A})) //垂线
|
|
|
+ //console.log('接近0或180',angle, sideVec)
|
|
|
+ }else{
|
|
|
+ let midVecLength = offset / Math.sin(angle/2)
|
|
|
+ sideVec = new THREE.Vector3().addVectors(OA,OB).normalize().multiplyScalar(midVecLength) //角平分线 ( 和上一个方向保持在同一侧,故而顺时针和逆时针方向不同 )
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ let p = new THREE.Vector3().addVectors(O, sideVec)
|
|
|
+ newPoints.push(p)
|
|
|
+ }
|
|
|
+ this.points = newPoints
|
|
|
+ super.update()
|
|
|
+ }
|
|
|
+
|
|
|
+ changeOffset(offset){
|
|
|
+ this.offset = offset
|
|
|
+ this.update()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ addMarker({point,index }={}){
|
|
|
+ super.addMarker({index, point, edge: LineDraw.createFatLine( [ ],{ mat: this.measure.getMat('edgeExpand') })})
|
|
|
+ }
|
|
|
+
|
|
|
+ getArea(){
|
|
|
+
|
|
|
+ if(!this.closed)return
|
|
|
+ this.getPoint2dInfo(this.points)
|
|
|
+ this.measure.getArea.call(this)
|
|
|
+ this.measure.getArea()
|
|
|
+
|
|
|
+ let area = Math.abs(this.measure.area.value - this.area.value)
|
|
|
+ this.area = {value:area, string: this.getConvertString(area, 'area') }
|
|
|
+ return this.area
|
|
|
+ }
|
|
|
+}
|
|
|
+ExpandLine.prototype.getPoint2dInfo = Measure.prototype.getPoint2dInfo
|
|
|
+ExpandLine.prototype.getConvertString = Measure.prototype.getConvertString
|
|
|
+
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|