|
|
|
@ -1,9 +1,11 @@ |
|
|
|
import * as THREE from 'three' |
|
|
|
import BaseRenderer from '@/core/base/BaseRenderer.ts' |
|
|
|
import { LineGeometry } from 'three/examples/jsm/lines/LineGeometry' |
|
|
|
import { Line2 } from 'three/examples/jsm/lines/Line2' |
|
|
|
import { LineMaterial } from 'three/examples/jsm/lines/LineMaterial' |
|
|
|
import { getLineId } from '@/core/ModelUtils.ts' |
|
|
|
import { LineMaterial } from 'three/examples/jsm/lines/LineMaterial.js' |
|
|
|
import { LineGeometry } from 'three/examples/jsm/lines/LineGeometry.js' |
|
|
|
import { Line2 } from 'three/examples/jsm/lines/Line2.js' |
|
|
|
import { numberToString } from '@/utils/webutils.ts' |
|
|
|
import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer' |
|
|
|
|
|
|
|
/** |
|
|
|
* 辅助测量工具渲染器 |
|
|
|
@ -62,4 +64,59 @@ export default class MeasureRenderer extends BaseRenderer { |
|
|
|
|
|
|
|
this.group.add(...objects) |
|
|
|
} |
|
|
|
|
|
|
|
afterCreateOrUpdateLine(start: ItemJson, end: ItemJson, type: LinkType, option: RendererCudOption, objects: THREE.Object3D[]) { |
|
|
|
super.afterCreateOrUpdateLine(start, end, type, option, objects) |
|
|
|
|
|
|
|
const startPoint = this.tempViewport?.entityManager.findObjectsById(start.id)?.[0] |
|
|
|
const endPoint = this.tempViewport?.entityManager.findObjectsById(end.id)?.[0] |
|
|
|
|
|
|
|
const p0 = startPoint.position |
|
|
|
const p1 = endPoint.position |
|
|
|
|
|
|
|
const dist = p0.distanceTo(p1) |
|
|
|
const label = `${numberToString(dist)} m` |
|
|
|
|
|
|
|
const position = new THREE.Vector3().addVectors(p0, p1).multiplyScalar(0.5) |
|
|
|
let labelObj: CSS2DObject | undefined = objects[0].userData.labelObj |
|
|
|
if (!labelObj || !labelObj.parent) { |
|
|
|
labelObj = this.createLabel(label) |
|
|
|
this.group.add(labelObj) |
|
|
|
objects[0].userData.labelObj = labelObj |
|
|
|
} |
|
|
|
|
|
|
|
labelObj.position.set(position.x, position.y, position.z) |
|
|
|
labelObj.element.innerHTML = label |
|
|
|
} |
|
|
|
|
|
|
|
afterDeleteLine(start: ItemJson, end: ItemJson, type: LinkType, option: RendererCudOption, objects: THREE.Object3D[]) { |
|
|
|
super.afterDeleteLine(start, end, type, option, objects) |
|
|
|
|
|
|
|
// 删除标签
|
|
|
|
const labelObj = objects[0]?.userData?.labelObj |
|
|
|
if (labelObj && labelObj.parent) { |
|
|
|
labelObj.parent.remove(labelObj) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 创建标签 |
|
|
|
*/ |
|
|
|
createLabel(text: string): CSS2DObject { |
|
|
|
const div = document.createElement('div') |
|
|
|
div.className = 'css2dObjectLabel' |
|
|
|
div.innerHTML = text |
|
|
|
div.style.padding = '5px 8px' |
|
|
|
div.style.color = '#fff' |
|
|
|
div.style.fontSize = '14px' |
|
|
|
div.style.position = 'absolute' |
|
|
|
div.style.backgroundColor = 'rgba(25, 25, 25, 0.3)' |
|
|
|
div.style.borderRadius = '12px' |
|
|
|
div.style.top = '0px' |
|
|
|
div.style.left = '0px' |
|
|
|
// div.style.pointerEvents = 'none' //避免HTML元素影响场景的鼠标事件
|
|
|
|
const obj = new CSS2DObject(div) |
|
|
|
obj.name = MeasureRenderer.LABEL_NAME |
|
|
|
return obj |
|
|
|
} |
|
|
|
} |