修改模型前端代码
This commit is contained in:
parent
a9ce1a4f77
commit
284775bd9c
@ -45,7 +45,7 @@ export const plmModelApi = {
|
||||
url: '/biz/plm/model/preview',
|
||||
method: 'get',
|
||||
params,
|
||||
timeout: 120000,
|
||||
timeout: 360000,
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user