|
|
@ -7,6 +7,7 @@ import { getLineId } from '@/core/ModelUtils.ts' |
|
|
import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer' |
|
|
import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer' |
|
|
import { numberToString } from '@/utils/webutils.ts' |
|
|
import { numberToString } from '@/utils/webutils.ts' |
|
|
import Constract from '@/core/Constract.ts' |
|
|
import Constract from '@/core/Constract.ts' |
|
|
|
|
|
import type { ExtrudeGeometryOptions } from 'three/src/geometries/ExtrudeGeometry' |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 辅助测量工具渲染器 |
|
|
* 辅助测量工具渲染器 |
|
|
@ -78,16 +79,38 @@ export default class WayRenderer extends BaseRenderer { |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private _createOrUpdateLine(startPosition: THREE.Vector3, endPosition: THREE.Vector3, type: LinkType) { |
|
|
|
|
|
const width = 1 |
|
|
|
|
|
const halfWidth = width / 2 |
|
|
|
|
|
|
|
|
|
|
|
const path = new THREE.LineCurve3( |
|
|
|
|
|
new THREE.Vector3(startPosition.x, startPosition.z, halfWidth - Constract.HEIGHT_WAY_LINE), |
|
|
|
|
|
new THREE.Vector3(endPosition.x, endPosition.z, halfWidth - Constract.HEIGHT_WAY_LINE) |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const shape = new THREE.Shape() |
|
|
|
|
|
shape.moveTo(halfWidth, -halfWidth) |
|
|
|
|
|
shape.lineTo(halfWidth, halfWidth) |
|
|
|
|
|
|
|
|
|
|
|
const extrudeSettings: ExtrudeGeometryOptions = { |
|
|
|
|
|
steps: 2, // 沿路径的分段数
|
|
|
|
|
|
depth: 1, // 实际由路径长度决定
|
|
|
|
|
|
bevelEnabled: false, // 禁用倒角
|
|
|
|
|
|
extrudePath: path // 挤出路径
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const extrudedGeometry = new THREE.ExtrudeGeometry(shape, extrudeSettings) |
|
|
|
|
|
extrudedGeometry.rotateX(Math.PI / 2) |
|
|
|
|
|
|
|
|
|
|
|
return new THREE.Mesh(extrudedGeometry, this.lineMaterial) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
createLineBasic(start: ItemJson, end: ItemJson, type: LinkType): THREE.Object3D[] { |
|
|
createLineBasic(start: ItemJson, end: ItemJson, type: LinkType): THREE.Object3D[] { |
|
|
const group = new THREE.Group() |
|
|
const startPosition = new THREE.Vector3(start.tf[0][0], 0, start.tf[0][2]) |
|
|
const startPosition = new THREE.Vector3(start.tf[0][0], 0.01, start.tf[0][2]) |
|
|
const endPosition = new THREE.Vector3(end.tf[0][0], 0, end.tf[0][2]) |
|
|
const endPosition = new THREE.Vector3(end.tf[0][0], 0.01, end.tf[0][2]) |
|
|
|
|
|
const width = 1 |
|
|
|
|
|
|
|
|
|
|
|
const curve = new THREE.LineCurve3(startPosition, endPosition) |
|
|
const group = new THREE.Group() |
|
|
const tubeGeometry = new THREE.TubeGeometry(curve, 1, width / 2, 2, false) |
|
|
const lineMesh = this._createOrUpdateLine(startPosition, endPosition, type) |
|
|
const lineMesh = new THREE.Mesh(tubeGeometry, this.lineMaterial) |
|
|
|
|
|
group.add(lineMesh) |
|
|
group.add(lineMesh) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -110,7 +133,7 @@ export default class WayRenderer extends BaseRenderer { |
|
|
label.name = WayRenderer.LABEL_NAME |
|
|
label.name = WayRenderer.LABEL_NAME |
|
|
label.quaternion.copy(this.tempViewport.camera.quaternion) |
|
|
label.quaternion.copy(this.tempViewport.camera.quaternion) |
|
|
label.sync() |
|
|
label.sync() |
|
|
label.position.set(midPoint.x, midPoint.y, midPoint.z) |
|
|
label.position.set(midPoint.x, Constract.HEIGHT_WAY_LABEL, midPoint.z) |
|
|
|
|
|
|
|
|
group.add(label) |
|
|
group.add(label) |
|
|
|
|
|
|
|
|
@ -122,7 +145,6 @@ export default class WayRenderer extends BaseRenderer { |
|
|
|
|
|
|
|
|
const startPosition = new THREE.Vector3(start.tf[0][0], 0.01, start.tf[0][2]) |
|
|
const startPosition = new THREE.Vector3(start.tf[0][0], 0.01, start.tf[0][2]) |
|
|
const endPosition = new THREE.Vector3(end.tf[0][0], 0.01, end.tf[0][2]) |
|
|
const endPosition = new THREE.Vector3(end.tf[0][0], 0.01, end.tf[0][2]) |
|
|
const width = 1 |
|
|
|
|
|
|
|
|
|
|
|
const lineId = getLineId(start.id, end.id, type) |
|
|
const lineId = getLineId(start.id, end.id, type) |
|
|
const lines = this.tempViewport.entityManager.findLineObjectsById(lineId) |
|
|
const lines = this.tempViewport.entityManager.findLineObjectsById(lineId) |
|
|
@ -132,9 +154,7 @@ export default class WayRenderer extends BaseRenderer { |
|
|
const label: Text = group.children[1] |
|
|
const label: Text = group.children[1] |
|
|
group.clear() |
|
|
group.clear() |
|
|
|
|
|
|
|
|
const curve = new THREE.LineCurve3(startPosition, endPosition) |
|
|
const lineMesh = this._createOrUpdateLine(startPosition, endPosition, type) |
|
|
const tubeGeometry = new THREE.TubeGeometry(curve, 1, width / 2, 8, false) |
|
|
|
|
|
const lineMesh = new THREE.Mesh(tubeGeometry, this.lineMaterial) |
|
|
|
|
|
group.add(lineMesh) |
|
|
group.add(lineMesh) |
|
|
|
|
|
|
|
|
const midPoint = new THREE.Vector3() |
|
|
const midPoint = new THREE.Vector3() |
|
|
|