|
@@ -20,7 +20,7 @@ var lineMats;
|
|
var planeMats
|
|
var planeMats
|
|
|
|
|
|
const sphereSizeInfo = {
|
|
const sphereSizeInfo = {
|
|
- minSize : 15 , maxSize : 55, nearBound : 0.2, farBound : 8,
|
|
|
|
|
|
+ minSize : 25 , maxSize : 65, nearBound : 0.2, farBound : 8,
|
|
}
|
|
}
|
|
const labelSizeInfo = {width2d:200}
|
|
const labelSizeInfo = {width2d:200}
|
|
const mainLabelProp = {
|
|
const mainLabelProp = {
|
|
@@ -114,11 +114,12 @@ export class Measure extends THREE.Object3D {
|
|
|
|
|
|
this.selectStates = {}
|
|
this.selectStates = {}
|
|
|
|
|
|
-
|
|
|
|
|
|
+ this.setUnitSystem(viewer.unitConvert.UnitService.defaultSystem)
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -129,7 +130,7 @@ export class Measure extends THREE.Object3D {
|
|
}else{
|
|
}else{
|
|
if(this.showCoordinates){
|
|
if(this.showCoordinates){
|
|
let point = this.points[0];
|
|
let point = this.points[0];
|
|
- let position = point.position;
|
|
|
|
|
|
+ let position = point
|
|
this.spheres[0].position.copy(position);
|
|
this.spheres[0].position.copy(position);
|
|
|
|
|
|
{ // coordinate labels
|
|
{ // coordinate labels
|
|
@@ -171,7 +172,7 @@ export class Measure extends THREE.Object3D {
|
|
if(this.showEdges){ // edges
|
|
if(this.showEdges){ // edges
|
|
let edge = this.edges[index];
|
|
let edge = this.edges[index];
|
|
|
|
|
|
- this.updateLine(edge,point.position, nextPoint.position)
|
|
|
|
|
|
+ this.updateLine(edge, point, nextPoint)
|
|
|
|
|
|
edge.visible = index < lastIndex || this.closed;
|
|
edge.visible = index < lastIndex || this.closed;
|
|
|
|
|
|
@@ -180,22 +181,23 @@ export class Measure extends THREE.Object3D {
|
|
if(this.showDistances){ // edge labels
|
|
if(this.showDistances){ // edge labels
|
|
let edgeLabel = this.edgeLabels[i];
|
|
let edgeLabel = this.edgeLabels[i];
|
|
|
|
|
|
- let center = new THREE.Vector3().add(point.position);
|
|
|
|
- center.add(nextPoint.position);
|
|
|
|
- center = center.multiplyScalar(0.5);
|
|
|
|
- let distance = point.position.distanceTo(nextPoint.position);
|
|
|
|
-
|
|
|
|
|
|
+ let center = new THREE.Vector3().add(point);
|
|
|
|
+ center.add(nextPoint);
|
|
|
|
+ center = center.multiplyScalar(0.5);
|
|
edgeLabel.setPos(center)
|
|
edgeLabel.setPos(center)
|
|
|
|
+ let distance = point.distanceTo(nextPoint);
|
|
|
|
+
|
|
|
|
+ var text = viewer.unitConvert.convert(distance, 'distance', void 0, this.unitSystem, 0.1 , true)//distance要传0.1 这个factor
|
|
|
|
|
|
- /* let suffix = "";
|
|
|
|
- if(this.lengthUnit != null && this.lengthUnitDisplay != null){
|
|
|
|
- distance = distance / this.lengthUnit.unitspermeter * this.lengthUnitDisplay.unitspermeter; //convert to meters then to the display unit
|
|
|
|
- suffix = this.lengthUnitDisplay.code;
|
|
|
|
- } */
|
|
|
|
- let suffix = "m";
|
|
|
|
|
|
+ /* let suffix = "m";
|
|
let txtLength = Utils.addCommas(distance.toFixed(2));
|
|
let txtLength = Utils.addCommas(distance.toFixed(2));
|
|
- edgeLabel.setText(`${txtLength} ${suffix}`);
|
|
|
|
|
|
+ edgeLabel.setText(`${txtLength} ${suffix}`); */
|
|
|
|
+ edgeLabel.setText(text)
|
|
|
|
+
|
|
|
|
+
|
|
edgeLabel.shouldVisi = (index < lastIndex || this.closed && this.points.length > 2) && distance>0
|
|
edgeLabel.shouldVisi = (index < lastIndex || this.closed && this.points.length > 2) && distance>0
|
|
|
|
+
|
|
|
|
+
|
|
/* this.closed || */ edgeLabel.setVisible(edgeLabel.shouldVisi)
|
|
/* this.closed || */ edgeLabel.setVisible(edgeLabel.shouldVisi)
|
|
|
|
|
|
}
|
|
}
|
|
@@ -229,25 +231,30 @@ export class Measure extends THREE.Object3D {
|
|
this.areaPlane.geometry = MeshDraw.getShapeGeo(this.point2dInfo.points2d)
|
|
this.areaPlane.geometry = MeshDraw.getShapeGeo(this.point2dInfo.points2d)
|
|
var center = math.getCenterOfGravityPoint(this.point2dInfo.points2d) //重心
|
|
var center = math.getCenterOfGravityPoint(this.point2dInfo.points2d) //重心
|
|
|
|
|
|
- var fistPos = this.point2dInfo.points2d[0].clone()
|
|
|
|
- fistPos.z = 0 //因为shape只读取了xy,所以位移下, 再算出最终位置,得到差距
|
|
|
|
- fistPos.applyQuaternion(this.point2dInfo.quaInverse)
|
|
|
|
- var vec = this.point2dInfo.originPoint0.clone().sub(fistPos)
|
|
|
|
|
|
+ var firstPos = this.point2dInfo.points2d[0].clone()
|
|
|
|
+ firstPos.z = 0 //因为shape只读取了xy,所以位移下, 再算出最终位置,得到差距
|
|
|
|
+ firstPos.applyQuaternion(this.point2dInfo.quaInverse)
|
|
|
|
+ var vec = this.point2dInfo.originPoint0.clone().sub(firstPos)
|
|
center = new THREE.Vector3(center.x, center.y, 0)
|
|
center = new THREE.Vector3(center.x, center.y, 0)
|
|
center.applyQuaternion(this.point2dInfo.quaInverse)
|
|
center.applyQuaternion(this.point2dInfo.quaInverse)
|
|
this.areaPlane.quaternion.copy(this.point2dInfo.quaInverse)
|
|
this.areaPlane.quaternion.copy(this.point2dInfo.quaInverse)
|
|
this.areaPlane.position.copy(vec)
|
|
this.areaPlane.position.copy(vec)
|
|
center.add(vec)
|
|
center.add(vec)
|
|
this.center = center
|
|
this.center = center
|
|
-
|
|
|
|
|
|
+ let area = Math.abs(math.getArea(this.point2dInfo.points2d))//this.getArea();
|
|
//label
|
|
//label
|
|
this.areaLabel.setPos(center);
|
|
this.areaLabel.setPos(center);
|
|
- let area = Math.abs(math.getArea(this.point2dInfo.points2d))//this.getArea();
|
|
|
|
|
|
+ /*
|
|
|
|
|
|
let suffix = "m";
|
|
let suffix = "m";
|
|
this.area = area
|
|
this.area = area
|
|
let txtArea = Utils.addCommas(area.toFixed(2));
|
|
let txtArea = Utils.addCommas(area.toFixed(2));
|
|
- let msg = `${this.measureType} ${txtArea} ${suffix}\u00B2`;
|
|
|
|
|
|
+ let msg = `${this.measureType} ${txtArea} ${suffix}\u00B2`; */
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ let msg = viewer.unitConvert.convert(area, 'area', void 0, this.unitSystem/* , 0.1 */ )
|
|
|
|
+ this.area = {value:area, string:msg}
|
|
|
|
+
|
|
this.areaLabel.setText(msg);
|
|
this.areaLabel.setText(msg);
|
|
this.areaLabel.setVisible(true)
|
|
this.areaLabel.setVisible(true)
|
|
}
|
|
}
|
|
@@ -267,9 +274,9 @@ export class Measure extends THREE.Object3D {
|
|
|
|
|
|
if(circleOkay){
|
|
if(circleOkay){
|
|
|
|
|
|
- const A = this.points[0].position;
|
|
|
|
- const B = this.points[1].position;
|
|
|
|
- const C = this.points[2].position;
|
|
|
|
|
|
+ const A = this.points[0];
|
|
|
|
+ const B = this.points[1];
|
|
|
|
+ const C = this.points[2];
|
|
const AB = B.clone().sub(A);
|
|
const AB = B.clone().sub(A);
|
|
const AC = C.clone().sub(A);
|
|
const AC = C.clone().sub(A);
|
|
const N = AC.clone().cross(AB).normalize();
|
|
const N = AC.clone().cross(AB).normalize();
|
|
@@ -313,17 +320,15 @@ export class Measure extends THREE.Object3D {
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addMarker (point) {
|
|
addMarker (point) {
|
|
- if (point.x != null) {
|
|
|
|
- point = {position: point};
|
|
|
|
- }else if(point instanceof Array){
|
|
|
|
- point = {position: new THREE.Vector3(...point)};
|
|
|
|
- }
|
|
|
|
|
|
+ if(point instanceof Array){
|
|
|
|
+ point = new THREE.Vector3(...point)
|
|
|
|
+ }
|
|
this.points.push(point);
|
|
this.points.push(point);
|
|
|
|
|
|
|
|
|
|
@@ -331,11 +336,12 @@ export class Measure extends THREE.Object3D {
|
|
//let sphere = new THREE.Sprite(this.getSphereMaterial('default') );
|
|
//let sphere = new THREE.Sprite(this.getSphereMaterial('default') );
|
|
|
|
|
|
let sphere = new Sprite({mat:this.getSphereMaterial('default'), sizeInfo: sphereSizeInfo, name:"measure_point"} )
|
|
let sphere = new Sprite({mat:this.getSphereMaterial('default'), sizeInfo: sphereSizeInfo, name:"measure_point"} )
|
|
|
|
+ viewer.setObjectLayers(sphere, 'measure' )
|
|
sphere.renderOrder = 3
|
|
sphere.renderOrder = 3
|
|
sphere.sphereSelectStates = {}
|
|
sphere.sphereSelectStates = {}
|
|
this.add(sphere);
|
|
this.add(sphere);
|
|
this.spheres.push(sphere);
|
|
this.spheres.push(sphere);
|
|
- this.updateSphere(sphere, point.position)
|
|
|
|
|
|
+ this.updateSphere(sphere, point)
|
|
|
|
|
|
|
|
|
|
{ // edges
|
|
{ // edges
|
|
@@ -345,7 +351,7 @@ export class Measure extends THREE.Object3D {
|
|
],{material:this.getLineMat('edgeDefault')} )
|
|
],{material:this.getLineMat('edgeDefault')} )
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
+ viewer.setObjectLayers(edge, 'measure' )
|
|
this.add(edge);
|
|
this.add(edge);
|
|
this.edges.push(edge);
|
|
this.edges.push(edge);
|
|
|
|
|
|
@@ -395,7 +401,7 @@ export class Measure extends THREE.Object3D {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+ viewer.setObjectLayers(edgeLabel, 'measure' )
|
|
this.edgeLabels.push(edgeLabel);
|
|
this.edgeLabels.push(edgeLabel);
|
|
this.add(edgeLabel);
|
|
this.add(edgeLabel);
|
|
}
|
|
}
|
|
@@ -431,23 +437,8 @@ export class Measure extends THREE.Object3D {
|
|
|
|
|
|
if (I) {
|
|
if (I) {
|
|
let i = this.spheres.indexOf(e.drag.object);
|
|
let i = this.spheres.indexOf(e.drag.object);
|
|
- if (i !== -1) {
|
|
|
|
- /* let point = this.points[i];
|
|
|
|
- let oldPos = point.position.clone();
|
|
|
|
-
|
|
|
|
- // loop through current keys and cleanup ones that will be orphaned
|
|
|
|
- for (let key of Object.keys(point)) {
|
|
|
|
- if (!I.point[key]) {
|
|
|
|
- delete point[key];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for (let key of Object.keys(I.point).filter(e => e !== 'position')) {
|
|
|
|
- point[key] = I.point[key];
|
|
|
|
- } */
|
|
|
|
-
|
|
|
|
- this.dragChange(I, i, atMap)
|
|
|
|
-
|
|
|
|
|
|
+ if (i !== -1) {
|
|
|
|
+ this.dragChange(I, i, atMap)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -457,7 +448,16 @@ export class Measure extends THREE.Object3D {
|
|
};
|
|
};
|
|
|
|
|
|
let drop = e => {
|
|
let drop = e => {
|
|
-
|
|
|
|
|
|
+ if(!e.isAtDomElement && this.isNew){//如果是刚添加时在其他dom点击, 不要响应
|
|
|
|
+ setTimeout(()=>{//等 drag=null之后 //右键拖拽结束后需要重新得到drag
|
|
|
|
+ if(viewer.scene.measurements.includes(this)){
|
|
|
|
+ viewer.inputHandler.startDragging(e.drag.object,
|
|
|
|
+ {endDragFun: e.drag.endDragFun}
|
|
|
|
+ )
|
|
|
|
+ }
|
|
|
|
+ },1)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
let i = this.spheres.indexOf(e.drag.object);
|
|
let i = this.spheres.indexOf(e.drag.object);
|
|
if (i !== -1) {
|
|
if (i !== -1) {
|
|
this.dispatchEvent({
|
|
this.dispatchEvent({
|
|
@@ -477,7 +477,8 @@ export class Measure extends THREE.Object3D {
|
|
|
|
|
|
this.editStateChange(false)
|
|
this.editStateChange(false)
|
|
e.drag.endDragFun && e.drag.endDragFun(e)// addmarker
|
|
e.drag.endDragFun && e.drag.endDragFun(e)// addmarker
|
|
- };
|
|
|
|
|
|
+ if(this.changeCallBack)this.changeCallBack()
|
|
|
|
+ };
|
|
|
|
|
|
|
|
|
|
let mouseover = (e) => {this.setSphereSelected(e.object, true, 'single');/* console.log('hover') */};
|
|
let mouseover = (e) => {this.setSphereSelected(e.object, true, 'single');/* console.log('hover') */};
|
|
@@ -525,32 +526,34 @@ export class Measure extends THREE.Object3D {
|
|
this.guideLine.visible = true
|
|
this.guideLine.visible = true
|
|
}else if( len > 1){
|
|
}else if( len > 1){
|
|
|
|
|
|
- var points = this.points.map(e=>e.position.clone())
|
|
|
|
|
|
+ var points = this.points//.map(e=>e.position.clone())
|
|
points[i].copy(location) //算normal需要提前确认point
|
|
points[i].copy(location) //算normal需要提前确认point
|
|
|
|
|
|
//若为定义了面朝向的矩形
|
|
//若为定义了面朝向的矩形
|
|
if(this.faceDirection == 'horizontal'){
|
|
if(this.faceDirection == 'horizontal'){
|
|
if(len == 2){
|
|
if(len == 2){
|
|
- location.setZ(this.points[0].position.z)
|
|
|
|
|
|
+ location.setZ(this.points[0].z)
|
|
}
|
|
}
|
|
if(!this.facePlane){//一个点就能确定面
|
|
if(!this.facePlane){//一个点就能确定面
|
|
- this.facePlane = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3(0,0,1), this.points[0].position )
|
|
|
|
|
|
+ this.facePlane = new THREE.Plane().setFromNormalAndCoplanarPoint( new THREE.Vector3(0,0,1), this.points[0] )
|
|
}
|
|
}
|
|
}else if(this.faceDirection == 'vertical'){//当有两个点时, 有两个方向的可能
|
|
}else if(this.faceDirection == 'vertical'){//当有两个点时, 有两个方向的可能
|
|
if(len == 2){
|
|
if(len == 2){
|
|
- let vec = points[0].clone().sub(location)
|
|
|
|
- if(Math.sqrt(vec.x*vec.x+vec.y*vec.y) > Math.abs(vec.z) ){//水平(高度差小于水平距离时)
|
|
|
|
- location.setZ(this.points[0].position.z)
|
|
|
|
- //this.cannotConfirmNormal = false;//能确定面为水平方向
|
|
|
|
- }else{//垂直 (当两点一样时也属于这种)
|
|
|
|
- location.setX(points[0].x);
|
|
|
|
- location.setY(points[0].y);
|
|
|
|
- //this.cannotConfirmNormal = true; //不能确定面,因第三点可绕着纵轴线自由移动
|
|
|
|
|
|
+ if(this.isRect){
|
|
|
|
+ let vec = points[0].clone().sub(location)
|
|
|
|
+ if(Math.sqrt(vec.x*vec.x+vec.y*vec.y) > Math.abs(vec.z) ){//水平(高度差小于水平距离时)
|
|
|
|
+ location.setZ(this.points[0].z)
|
|
|
|
+ //this.cannotConfirmNormal = false;//能确定面为水平方向
|
|
|
|
+ }else{//垂直 (当两点一样时也属于这种)
|
|
|
|
+ location.setX(points[0].x);
|
|
|
|
+ location.setY(points[0].y);
|
|
|
|
+ //this.cannotConfirmNormal = true; //不能确定面,因第三点可绕着纵轴线自由移动
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}else{
|
|
}else{
|
|
- {//判断cannotConfirmNormal
|
|
|
|
|
|
+ {//判断cannotConfirmNormal. 如果前几段都在竖直线上,就不能固定出面方向。
|
|
this.cannotConfirmNormal = true
|
|
this.cannotConfirmNormal = true
|
|
- let max = this.isRect ? 1 : len-2
|
|
|
|
|
|
+ let max = this.isRect ? 1 : len-2
|
|
for(let i=0;i<max;i++){
|
|
for(let i=0;i<max;i++){
|
|
let p1 = points[i].clone()
|
|
let p1 = points[i].clone()
|
|
let p2 = points[i+1].clone()
|
|
let p2 = points[i+1].clone()
|
|
@@ -569,7 +572,7 @@ export class Measure extends THREE.Object3D {
|
|
if(points2){
|
|
if(points2){
|
|
let normal = math.getNormal2d({p1:points2[0], p2:points2[1]})
|
|
let normal = math.getNormal2d({p1:points2[0], p2:points2[1]})
|
|
normal = new THREE.Vector3(normal.x, normal.y, 0)
|
|
normal = new THREE.Vector3(normal.x, normal.y, 0)
|
|
- this.facePlane = new THREE.Plane().setFromNormalAndCoplanarPoint( normal, this.points[0].position )
|
|
|
|
|
|
+ this.facePlane = new THREE.Plane().setFromNormalAndCoplanarPoint( normal, this.points[0] )
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -603,8 +606,8 @@ export class Measure extends THREE.Object3D {
|
|
|
|
|
|
if(this.isRect){ //是矩形 (即使没有faceDirection也能执行)
|
|
if(this.isRect){ //是矩形 (即使没有faceDirection也能执行)
|
|
//根据前两个点计算当前和下一个点
|
|
//根据前两个点计算当前和下一个点
|
|
- var p1 = this.points[(i-2+len)%len].position
|
|
|
|
- var p2 = this.points[(i-1+len)%len].position
|
|
|
|
|
|
+ var p1 = this.points[(i-2+len)%len]
|
|
|
|
+ var p2 = this.points[(i-1+len)%len]
|
|
if(p1.equals(p2)){//意外情况:重复点两次 ( bug点,改了好多遍)
|
|
if(p1.equals(p2)){//意外情况:重复点两次 ( bug点,改了好多遍)
|
|
if(this.faceDirection == 'vertical'){
|
|
if(this.faceDirection == 'vertical'){
|
|
p2.add(new THREE.Vector3(0,0,0.0001))
|
|
p2.add(new THREE.Vector3(0,0,0.0001))
|
|
@@ -625,15 +628,15 @@ export class Measure extends THREE.Object3D {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+ let points2d;
|
|
if(this.facePlane){
|
|
if(this.facePlane){
|
|
var originPoint0 = points[0].clone()
|
|
var originPoint0 = points[0].clone()
|
|
var qua = math.getQuaBetween2Vector(this.facePlane.normal, new THREE.Vector3(0,0,1), new THREE.Vector3(0,0,1));
|
|
var qua = math.getQuaBetween2Vector(this.facePlane.normal, new THREE.Vector3(0,0,1), new THREE.Vector3(0,0,1));
|
|
- points.forEach(e=>e.applyQuaternion(qua))
|
|
|
|
|
|
+ points2d = points.map(e=>e.clone().applyQuaternion(qua))
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- var isIntersectSelf = !this.isRect && len > 3 && this.intersectSelf(points)//检测相交
|
|
|
|
|
|
+ var isIntersectSelf = !this.isRect && len > 3 && this.intersectSelf(points2d)//检测相交
|
|
if(isIntersectSelf){
|
|
if(isIntersectSelf){
|
|
//not-allowed
|
|
//not-allowed
|
|
viewer.dispatchEvent({
|
|
viewer.dispatchEvent({
|
|
@@ -646,22 +649,22 @@ export class Measure extends THREE.Object3D {
|
|
})
|
|
})
|
|
this.facePlane && (this.point2dInfo = {
|
|
this.facePlane && (this.point2dInfo = {
|
|
originPoint0 ,
|
|
originPoint0 ,
|
|
- points2d : points,
|
|
|
|
|
|
+ points2d,
|
|
quaInverse : qua.clone().invert()
|
|
quaInverse : qua.clone().invert()
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
- var showGuideLine = this.isRect || len > 3
|
|
|
|
- if(showGuideLine){
|
|
|
|
- this.updateLine(this.guideLine, intersectPos, location)
|
|
|
|
- this.guideLine.visible = true
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+ var showGuideLine = len>1 && (this.faceDirection || len > 3)
|
|
|
|
+ if(showGuideLine){
|
|
|
|
+ this.updateLine(this.guideLine, intersectPos, location)
|
|
|
|
+ this.guideLine.visible = true
|
|
|
|
+ }
|
|
this.setPosition(i, location);
|
|
this.setPosition(i, location);
|
|
- //console.log(this.points.map(e=>e.position.toArray()))
|
|
|
|
|
|
+ //console.log(this.points.map(e=>e.toArray()))
|
|
|
|
|
|
}else{
|
|
}else{
|
|
this.setPosition(i, location);
|
|
this.setPosition(i, location);
|
|
@@ -826,7 +829,7 @@ export class Measure extends THREE.Object3D {
|
|
|
|
|
|
setPosition (index, position) {
|
|
setPosition (index, position) {
|
|
let point = this.points[index];
|
|
let point = this.points[index];
|
|
- point.position.copy(position);
|
|
|
|
|
|
+ point.copy(position);
|
|
|
|
|
|
let event = {
|
|
let event = {
|
|
type: 'marker_moved',
|
|
type: 'marker_moved',
|
|
@@ -837,7 +840,7 @@ export class Measure extends THREE.Object3D {
|
|
this.dispatchEvent(event);
|
|
this.dispatchEvent(event);
|
|
|
|
|
|
let sphere = this.spheres[index];
|
|
let sphere = this.spheres[index];
|
|
- this.updateSphere(sphere, point.position)
|
|
|
|
|
|
+ this.updateSphere(sphere, point)
|
|
|
|
|
|
};
|
|
};
|
|
intersectSelf(points2d){//add
|
|
intersectSelf(points2d){//add
|
|
@@ -864,19 +867,7 @@ export class Measure extends THREE.Object3D {
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
- /* getArea () {
|
|
|
|
- let area = 0;
|
|
|
|
- let j = this.points.length - 1;
|
|
|
|
-
|
|
|
|
- for (let i = 0; i < this.points.length; i++) {
|
|
|
|
- let p1 = this.points[i].position;
|
|
|
|
- let p2 = this.points[j].position;
|
|
|
|
- area += (p2.x + p1.x) * (p1.y - p2.y);
|
|
|
|
- j = i;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return Math.abs(area / 2);
|
|
|
|
- }; */
|
|
|
|
|
|
+
|
|
|
|
|
|
getTotalDistance () {
|
|
getTotalDistance () {
|
|
if (this.points.length === 0) {
|
|
if (this.points.length === 0) {
|
|
@@ -886,16 +877,16 @@ export class Measure extends THREE.Object3D {
|
|
let distance = 0;
|
|
let distance = 0;
|
|
|
|
|
|
for (let i = 1; i < this.points.length; i++) {
|
|
for (let i = 1; i < this.points.length; i++) {
|
|
- let prev = this.points[i - 1].position;
|
|
|
|
- let curr = this.points[i].position;
|
|
|
|
|
|
+ let prev = this.points[i - 1];
|
|
|
|
+ let curr = this.points[i];
|
|
let d = prev.distanceTo(curr);
|
|
let d = prev.distanceTo(curr);
|
|
|
|
|
|
distance += d;
|
|
distance += d;
|
|
}
|
|
}
|
|
|
|
|
|
if (this.closed && this.points.length > 1) {
|
|
if (this.closed && this.points.length > 1) {
|
|
- let first = this.points[0].position;
|
|
|
|
- let last = this.points[this.points.length - 1].position;
|
|
|
|
|
|
+ let first = this.points[0];
|
|
|
|
+ let last = this.points[this.points.length - 1];
|
|
let d = last.distanceTo(first);
|
|
let d = last.distanceTo(first);
|
|
|
|
|
|
distance += d;
|
|
distance += d;
|
|
@@ -905,8 +896,8 @@ export class Measure extends THREE.Object3D {
|
|
}
|
|
}
|
|
|
|
|
|
getAngleBetweenLines (cornerPoint, point1, point2) {
|
|
getAngleBetweenLines (cornerPoint, point1, point2) {
|
|
- let v1 = new THREE.Vector3().subVectors(point1.position, cornerPoint.position);
|
|
|
|
- let v2 = new THREE.Vector3().subVectors(point2.position, cornerPoint.position);
|
|
|
|
|
|
+ let v1 = new THREE.Vector3().subVectors(point1, cornerPoint);
|
|
|
|
+ let v2 = new THREE.Vector3().subVectors(point2, cornerPoint);
|
|
|
|
|
|
// avoid the error printed by threejs if denominator is 0
|
|
// avoid the error printed by threejs if denominator is 0
|
|
const denominator = Math.sqrt( v1.lengthSq() * v2.lengthSq() );
|
|
const denominator = Math.sqrt( v1.lengthSq() * v2.lengthSq() );
|
|
@@ -928,7 +919,16 @@ export class Measure extends THREE.Object3D {
|
|
|
|
|
|
return this.getAngleBetweenLines(point, previous, next);
|
|
return this.getAngleBetweenLines(point, previous, next);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ getCenter(/* update */){
|
|
|
|
+ if(this.points.length>=3){
|
|
|
|
+ return this.center.clone()
|
|
|
|
+ }else if(this.points.length == 2){
|
|
|
|
+ return this.points[0].clone().add((this.points[1])).multiplyScalar(0.5)
|
|
|
|
+ }else return this.points[0].clone()
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
// updateAzimuth(){
|
|
// updateAzimuth(){
|
|
// // if(this.points.length !== 2){
|
|
// // if(this.points.length !== 2){
|
|
// // return;
|
|
// // return;
|
|
@@ -938,7 +938,7 @@ export class Measure extends THREE.Object3D {
|
|
|
|
|
|
// // const [p0, p1] = this.points;
|
|
// // const [p0, p1] = this.points;
|
|
|
|
|
|
- // // const r = p0.position.distanceTo(p1.position);
|
|
|
|
|
|
+ // // const r = p0.distanceTo(p1);
|
|
|
|
|
|
// }
|
|
// }
|
|
|
|
|
|
@@ -977,7 +977,12 @@ export class Measure extends THREE.Object3D {
|
|
})
|
|
})
|
|
areaLabel.addEventListener('mouseleave',()=>{
|
|
areaLabel.addEventListener('mouseleave',()=>{
|
|
this.setSelected(false, 'areaLabel')
|
|
this.setSelected(false, 'areaLabel')
|
|
- })
|
|
|
|
|
|
+ })
|
|
|
|
+ areaLabel.addEventListener('click',()=>{
|
|
|
|
+ viewer.focusOnObject(this, 'measure')
|
|
|
|
+ })
|
|
|
|
+ viewer.setObjectLayers(areaLabel, 'measure' )
|
|
|
|
+
|
|
return areaLabel;
|
|
return areaLabel;
|
|
|
|
|
|
|
|
|
|
@@ -1145,7 +1150,17 @@ export class Measure extends THREE.Object3D {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
+ setUnitSystem(unitSystem){
|
|
|
|
+ if(unitSystem != this.unitSystem){
|
|
|
|
+ if(unitSystem == "metric"){
|
|
|
|
+
|
|
|
|
+ }else if(unitSystem == 'imperial'){
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ this.unitSystem = unitSystem
|
|
|
|
+ this.update()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1267,6 +1282,7 @@ function createAreaPlane(){
|
|
},Measure.planeMats = planeMats)
|
|
},Measure.planeMats = planeMats)
|
|
var geometry = new THREE.Geometry();
|
|
var geometry = new THREE.Geometry();
|
|
var mesh = new THREE.Mesh(geometry, planeMats.default)
|
|
var mesh = new THREE.Mesh(geometry, planeMats.default)
|
|
|
|
+ viewer.setObjectLayers(mesh, 'measure' )
|
|
return mesh
|
|
return mesh
|
|
}
|
|
}
|
|
|
|
|