diff --git a/src/api/plmModel.ts b/src/api/plmModel.ts index 3116b21..27e0461 100644 --- a/src/api/plmModel.ts +++ b/src/api/plmModel.ts @@ -45,7 +45,7 @@ export const plmModelApi = { url: '/biz/plm/model/preview', method: 'get', params, - timeout: 120000, + timeout: 360000, }) }, } diff --git a/src/components/CadModelViewer.vue b/src/components/CadModelViewer.vue index 652c579..fd07a78 100644 --- a/src/components/CadModelViewer.vue +++ b/src/components/CadModelViewer.vue @@ -46,8 +46,10 @@ let animationId = null let currentModel = null let dracoLoader let gltfLoader -let defaultCameraPosition = new THREE.Vector3(0,0,9) -let defaultTarget = new THREE.Vector3(0,0,0) +let resetCameraPos = new THREE.Vector3() +let resetLookTarget = new THREE.Vector3() +let grid = new THREE.GridHelper(200,20,0x666666,0xdcdcdc) + function resolveUrl(modelUrl) { @@ -100,10 +102,7 @@ const initScene = () => { const fillLight = new THREE.DirectionalLight(0xffffff, 0.35) fillLight.position.set(-200, -100, -200) scene.add(fillLight) - - const grid = new THREE.GridHelper(10, 20, 0xcccccc, 0xe8e8e8) - scene.add(grid) - + // scene.add(grid) controls = new OrbitControls(camera, renderer.domElement) controls.enableDamping = true @@ -149,6 +148,16 @@ const fitModelToView = (model) => { camera.updateProjectionMatrix() controls.target.set(0, 0, 0) controls.update() + + // 网格尺寸取模型最大尺寸的 2.5 倍,保证四周留白 + const gridSize = Math.ceil(maxDim * 2.5) + // 分段数按尺寸自适应,保证每格宽度合理 + const gridDivisions = Math.max(10, Math.floor(gridSize / 10)) + grid = new THREE.GridHelper(gridSize, gridDivisions, 0x666666, 0xdcdcdc) + scene.add(grid) + + resetCameraPos.copy(camera.position) + resetLookTarget.copy(controls.target) } const loadModel = () => { @@ -225,8 +234,9 @@ const onWindowResize = () => { function resetView() { if (!camera || !controls) return - camera.position.copy(defaultCameraPosition) - controls.target.copy(defaultTarget) + camera.position.copy(resetCameraPos) + controls.target.copy(resetLookTarget) + camera.updateProjectionMatrix() controls.update() }