Prechádzať zdrojové kódy

feat(cockpit): 窨井 3D 模型尺寸单源并与管线同倍率

ChenJZ 6 hodín pred
rodič
commit
2648c53db4

+ 44 - 0
src/modules/cockpit/domain/manholeModel.js

@@ -0,0 +1,44 @@
+/**
+ * 窨井 3D 模型尺寸(票 04)。
+ *
+ * 为什么单独一份:窨井在「地下管线详情视图」里由 `threePipeEnhancement` 画成井筒 + 底座 + 井盖,
+ * 而管线按 `PIPE_DISPLAY.diameterScale`(当前 8×)放大显示直径。窨井若按真实米数画,
+ * 同一屏里就会小得看不见。这里把**基础尺寸**与**显示倍率**分开:
+ *   · 基础尺寸是业务可读的真实比例(米);
+ *   · 显示倍率复用管线那一份(`PIPE_DISPLAY.diameterScale`),改倍率时管线与窨井一起变。
+ *
+ * 所有线性尺寸与 Y 偏移都由同一份基础尺寸乘同一个倍率得出,调用方不再手写第二组数字。
+ */
+import { PIPE_DISPLAY } from './pipeVisual.js'
+
+/** 真实比例下的模型基础尺寸(米)。Y 是相对设施地面点的偏移,负值向下。 */
+export const MANHOLE_MODEL_BASE = Object.freeze({
+    shaft: Object.freeze({ radius: 0.85, height: 2.4, centerY: -0.9 }),
+    base: Object.freeze({ radius: 0.86, height: 0.12, centerY: -2.15 }),
+    cover: Object.freeze({ radius: 0.9, height: 0.12, centerY: 0.55, tilt: -0.2 }),
+})
+
+function scaled(part, factor) {
+    return {
+        radius: part.radius * factor,
+        height: part.height * factor,
+        centerY: part.centerY * factor,
+    }
+}
+
+/**
+ * 窨井模型在给定显示倍率下的尺寸。
+ *
+ * @param {number} [scale] 显示倍率;缺省/非法时用管线同一个倍率,保证两处同步。
+ * @returns {{scale:number, shaft:object, base:object, cover:object}}
+ */
+export function manholeModelMetrics(scale = PIPE_DISPLAY.diameterScale) {
+    const factor = Number.isFinite(scale) && scale > 0 ? scale : PIPE_DISPLAY.diameterScale
+    return {
+        scale: factor,
+        shaft: scaled(MANHOLE_MODEL_BASE.shaft, factor),
+        base: scaled(MANHOLE_MODEL_BASE.base, factor),
+        // 井盖的倾角是角度,不随线性倍率缩放。
+        cover: { ...scaled(MANHOLE_MODEL_BASE.cover, factor), tilt: MANHOLE_MODEL_BASE.cover.tilt },
+    }
+}

+ 11 - 7
src/modules/cockpit/services/threePipeEnhancement.js

@@ -2,6 +2,7 @@
 import * as THREE from 'three'
 import { enhancementLabel } from '../domain/pipeEnhancement.js'
 import { displayPipeDiameter, PIPE_PALETTE } from '../domain/pipeVisual.js'
+import { manholeModelMetrics } from '../domain/manholeModel.js'
 import { attachSceneFocus } from './sceneInputFocus.js'
 import { addDetailedPipeSegment } from './pipeDetailGeometry.js'
 import { attachPointPick } from './pointPick.js'
@@ -155,19 +156,22 @@ function buildObject(plan, frame = null) {
             })
         }
     } else if (object.renderKind === 'manhole') {
-        const shell = new THREE.Mesh(new THREE.CylinderGeometry(0.85, 0.85, 2.4, 32, 1, true, Math.PI * 0.25, Math.PI * 1.5),
+        // 票 04:尺寸与 Y 偏移全部来自 domain/manholeModel.js 的单源,
+        // 并与管线共用同一个显示倍率(PIPE_DISPLAY.diameterScale),不再手写第二组米数。
+        const model = manholeModelMetrics()
+        const shell = new THREE.Mesh(new THREE.CylinderGeometry(model.shaft.radius, model.shaft.radius, model.shaft.height, 32, 1, true, Math.PI * 0.25, Math.PI * 1.5),
             new THREE.MeshStandardMaterial({ color: '#718093', roughness: 0.9, side: THREE.DoubleSide }))
         shell.name = 'manhole-shaft'
         shell.position.copy(points[0])
-        shell.position.y = -0.9
+        shell.position.y = model.shaft.centerY
         root.add(shell)
-        const base = new THREE.Mesh(new THREE.CylinderGeometry(0.86, 0.86, 0.12, 32), material('#53616f'))
-        base.position.copy(points[0]); base.position.y = -2.15
+        const base = new THREE.Mesh(new THREE.CylinderGeometry(model.base.radius, model.base.radius, model.base.height, 32), material('#53616f'))
+        base.position.copy(points[0]); base.position.y = model.base.centerY
         root.add(base)
-        const cover = new THREE.Mesh(new THREE.CylinderGeometry(0.9, 0.9, 0.12, 32), material(color))
+        const cover = new THREE.Mesh(new THREE.CylinderGeometry(model.cover.radius, model.cover.radius, model.cover.height, 32), material(color))
         cover.name = 'manhole-cover'
-        cover.position.copy(points[0]); cover.position.y = 0.55
-        cover.rotation.x = -0.2
+        cover.position.copy(points[0]); cover.position.y = model.cover.centerY
+        cover.rotation.x = model.cover.tilt
         root.add(cover)
     } else {
         const shape = object.renderKind === 'valve'