|
|
|
@ -31,7 +31,7 @@ export default class MeasureRenderer extends BaseRenderer { |
|
|
|
|
|
|
|
readonly defulePositionY = Constract.HEIGHT_MEASURE |
|
|
|
readonly defaultScale: THREE.Vector3 = new THREE.Vector3(0.1, 0.1, 0.1) |
|
|
|
readonly defaultRotation: THREE.Vector3 = new THREE.Vector3(90, 0, 0) |
|
|
|
readonly defaultRotation: THREE.Vector3 = new THREE.Vector3(0, 0, 0) |
|
|
|
|
|
|
|
constructor(itemTypeName: string) { |
|
|
|
super(itemTypeName) |
|
|
|
@ -97,109 +97,109 @@ export default class MeasureRenderer extends BaseRenderer { |
|
|
|
return obj |
|
|
|
} |
|
|
|
|
|
|
|
appendToScene(...objects: THREE.Object3D[]) { |
|
|
|
if (!this.group || this.group.parent !== this.tempViewport.scene.scene) { |
|
|
|
if (this.group && this.group.parent !== this.tempViewport.scene.scene) { |
|
|
|
// 幻影加载问题
|
|
|
|
this.group.parent.removeFromParent() |
|
|
|
} |
|
|
|
|
|
|
|
this.group = new THREE.Group() |
|
|
|
this.group.name = MeasureRenderer.GROUP_NAME |
|
|
|
this.tempViewport?.scene.add(this.group) |
|
|
|
} |
|
|
|
|
|
|
|
const dragObjects = objects.filter(obj => !!obj.userData.draggable) |
|
|
|
//this.tempViewport.dragControl.setDragObjects(dragObjects, 'push')
|
|
|
|
|
|
|
|
this.group.add(...objects) |
|
|
|
} |
|
|
|
|
|
|
|
afterCreateOrUpdateLine(start: ItemJson, end: ItemJson, type: LinkType, option: RendererCudOption, object: THREE.Object3D) { |
|
|
|
super.afterCreateOrUpdateLine(start, end, type, option, object) |
|
|
|
|
|
|
|
const startPoint = this.tempViewport?.entityManager.findObjectById(start.id) |
|
|
|
const endPoint = this.tempViewport?.entityManager.findObjectById(end.id) |
|
|
|
|
|
|
|
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: Text | CSS2DObject | undefined = object.userData.labelObj |
|
|
|
if (!labelObj || !labelObj.parent) { |
|
|
|
labelObj = this.createLabel(label) |
|
|
|
this.group.add(labelObj) |
|
|
|
object.userData.labelObj = labelObj |
|
|
|
} |
|
|
|
|
|
|
|
labelObj.position.set(position.x, position.y + 0.3, position.z - 0.2) |
|
|
|
|
|
|
|
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, object: THREE.Object3D) { |
|
|
|
super.afterDeleteLine(start, end, type, option, object) |
|
|
|
|
|
|
|
// 删除标签
|
|
|
|
const labelObj = object.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 = MeasureRenderer.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 = MeasureRenderer.LABEL_NAME |
|
|
|
|
|
|
|
label.sync() |
|
|
|
return label |
|
|
|
} |
|
|
|
} |
|
|
|
// appendToScene(...objects: THREE.Object3D[]) {
|
|
|
|
// if (!this.group || this.group.parent !== this.tempViewport.scene.scene) {
|
|
|
|
// if (this.group && this.group.parent !== this.tempViewport.scene.scene) {
|
|
|
|
// // 幻影加载问题
|
|
|
|
// this.group.parent.removeFromParent()
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// this.group = new THREE.Group()
|
|
|
|
// this.group.name = MeasureRenderer.GROUP_NAME
|
|
|
|
// this.tempViewport?.scene.add(this.group)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// const dragObjects = objects.filter(obj => !!obj.userData.draggable)
|
|
|
|
// //this.tempViewport.dragControl.setDragObjects(dragObjects, 'push')
|
|
|
|
//
|
|
|
|
// this.group.add(...objects)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// afterCreateOrUpdateLine(start: ItemJson, end: ItemJson, type: LinkType, option: RendererCudOption, object: THREE.Object3D) {
|
|
|
|
// super.afterCreateOrUpdateLine(start, end, type, option, object)
|
|
|
|
//
|
|
|
|
// const startPoint = this.tempViewport?.entityManager.findObjectById(start.id)
|
|
|
|
// const endPoint = this.tempViewport?.entityManager.findObjectById(end.id)
|
|
|
|
//
|
|
|
|
// 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: Text | CSS2DObject | undefined = object.userData.labelObj
|
|
|
|
// if (!labelObj || !labelObj.parent) {
|
|
|
|
// labelObj = this.createLabel(label)
|
|
|
|
// this.group.add(labelObj)
|
|
|
|
// object.userData.labelObj = labelObj
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// labelObj.position.set(position.x, position.y + 0.3, position.z - 0.2)
|
|
|
|
//
|
|
|
|
// 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, object: THREE.Object3D) {
|
|
|
|
// super.afterDeleteLine(start, end, type, option, object)
|
|
|
|
//
|
|
|
|
// // 删除标签
|
|
|
|
// const labelObj = object.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 = MeasureRenderer.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 = MeasureRenderer.LABEL_NAME
|
|
|
|
//
|
|
|
|
// label.sync()
|
|
|
|
// return label
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
dispose() { |
|
|
|
super.dispose() |
|
|
|
|