|
|
|
@ -91,93 +91,31 @@ export default class WayRenderer extends BaseRenderer { |
|
|
|
const lineMesh = new THREE.Mesh(tubeGeometry, this.lineMaterial) |
|
|
|
group.add(lineMesh) |
|
|
|
|
|
|
|
return [group] |
|
|
|
} |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
const position = new THREE.Vector3().addVectors(p0, p1).multiplyScalar(0.5) |
|
|
|
let labelObj: Text | CSS2DObject | undefined = objects[0].userData.labelObj |
|
|
|
if (!labelObj || !labelObj.parent) { |
|
|
|
labelObj = this.createLabel(label) |
|
|
|
this.tempViewport.scene.add(labelObj) |
|
|
|
objects[0].userData.labelObj = labelObj |
|
|
|
} |
|
|
|
|
|
|
|
labelObj.position.set(position.x, position.y, position.z) |
|
|
|
|
|
|
|
if (this.useHtmlLabel) { |
|
|
|
labelObj.element.innerHTML = label |
|
|
|
|
|
|
|
} else { |
|
|
|
// 让文本朝向摄像机
|
|
|
|
labelObj.quaternion.copy(this.tempViewport.camera.quaternion) |
|
|
|
labelObj.text = label |
|
|
|
labelObj.sync() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
afterDeleteLine(start: ItemJson, end: ItemJson, type: LinkType, option: RendererCudOption, objects: THREE.Object3D[]) { |
|
|
|
super.afterDeleteLine(start, end, type, option, objects) |
|
|
|
const midPoint = new THREE.Vector3() |
|
|
|
.addVectors(startPosition, endPosition) |
|
|
|
.multiplyScalar(0.5) |
|
|
|
|
|
|
|
const distance = startPosition.distanceTo(endPosition) * 1000 |
|
|
|
|
|
|
|
const label = new Text() |
|
|
|
label.text = distance |
|
|
|
label.font = SimSunTTF |
|
|
|
label.fontSize = 0.2 |
|
|
|
label.color = '#5f5f5f' |
|
|
|
label.opacity = 0.8 |
|
|
|
label.anchorX = 'center' |
|
|
|
label.anchorY = 'middle' |
|
|
|
label.depthOffset = 1 |
|
|
|
label.material.depthTest = false |
|
|
|
label.name = WayRenderer.LABEL_NAME |
|
|
|
label.quaternion.copy(this.tempViewport.camera.quaternion) |
|
|
|
label.sync() |
|
|
|
label.position.set(midPoint.x, midPoint.y, midPoint.z) |
|
|
|
|
|
|
|
group.add(label) |
|
|
|
|
|
|
|
// 删除标签
|
|
|
|
const labelObj = objects[0]?.userData?.labelObj |
|
|
|
if (labelObj && labelObj.parent) { |
|
|
|
labelObj.parent.remove(labelObj) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 创建标签 |
|
|
|
*/ |
|
|
|
createLabel(text: string): Text | CSS2DObject { |
|
|
|
if (this.useHtmlLabel) { |
|
|
|
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 = WayRenderer.LABEL_NAME |
|
|
|
return obj |
|
|
|
|
|
|
|
} else { |
|
|
|
const label = new Text() |
|
|
|
label.text = text |
|
|
|
label.font = SimSunTTF |
|
|
|
label.fontSize = 0.4 |
|
|
|
label.color = '#333333' |
|
|
|
label.opacity = 0.8 |
|
|
|
label.padding = 0.2 |
|
|
|
label.anchorX = 'center' |
|
|
|
label.anchorY = 'middle' |
|
|
|
label.depthOffset = 1 |
|
|
|
label.backgroundColor = '#000000' // 黑色背景
|
|
|
|
label.backgroundOpacity = 0.6 // 背景半透明
|
|
|
|
label.padding = 0.2 // 内边距
|
|
|
|
label.material.depthTest = false |
|
|
|
label.name = WayRenderer.LABEL_NAME |
|
|
|
|
|
|
|
label.sync() |
|
|
|
return label |
|
|
|
} |
|
|
|
return [group] |
|
|
|
} |
|
|
|
|
|
|
|
updateLine(start: ItemJson, end: ItemJson, type: LinkType, option?: RendererCudOption) { |
|
|
|
@ -192,12 +130,24 @@ export default class WayRenderer extends BaseRenderer { |
|
|
|
const group: THREE.Group = lines[0] as THREE.Group |
|
|
|
|
|
|
|
// 清空group里的元素
|
|
|
|
const label: Text = group.children[1] |
|
|
|
group.clear() |
|
|
|
|
|
|
|
const curve = new THREE.LineCurve3(startPosition, endPosition) |
|
|
|
const tubeGeometry = new THREE.TubeGeometry(curve, 1, width / 2, 8, false) |
|
|
|
const lineMesh = new THREE.Mesh(tubeGeometry, this.lineMaterial) |
|
|
|
group.add(lineMesh) |
|
|
|
|
|
|
|
const midPoint = new THREE.Vector3() |
|
|
|
.addVectors(startPosition, endPosition) |
|
|
|
.multiplyScalar(0.5) |
|
|
|
|
|
|
|
const distance = startPosition.distanceTo(endPosition) * 1000 |
|
|
|
label.text = distance |
|
|
|
label.quaternion.copy(this.tempViewport.camera.quaternion) |
|
|
|
label.sync() |
|
|
|
label.position.set(midPoint.x, midPoint.y, midPoint.z) |
|
|
|
group.add(label) |
|
|
|
} |
|
|
|
|
|
|
|
createPointBasic(item: ItemJson, option?: RendererCudOption): THREE.Object3D[] { |
|
|
|
|