| | |
| | | return box.getSize(new THREE.Vector3()); |
| | | }; |
| | | |
| | | const orientUnderdriveMesh = (mesh) => { |
| | | const quarterTurns = [0, Math.PI / 2, Math.PI, Math.PI * 1.5]; |
| | | let bestRotation = new THREE.Euler(0, 0, 0); |
| | | let bestScore = null; |
| | | |
| | | quarterTurns.forEach((x) => { |
| | | quarterTurns.forEach((y) => { |
| | | quarterTurns.forEach((z) => { |
| | | mesh.rotation.set(x, y, z); |
| | | mesh.updateMatrixWorld(true); |
| | | |
| | | const size = new THREE.Box3() |
| | | .setFromObject(mesh) |
| | | .getSize(new THREE.Vector3()); |
| | | |
| | | const score = { |
| | | height: size.y, |
| | | footprint: size.x * size.z, |
| | | widthBias: Math.max(size.x, size.z), |
| | | }; |
| | | |
| | | if ( |
| | | !bestScore |
| | | || score.height < bestScore.height - 0.001 |
| | | || ( |
| | | Math.abs(score.height - bestScore.height) <= 0.001 |
| | | && score.footprint > bestScore.footprint + 0.001 |
| | | ) |
| | | || ( |
| | | Math.abs(score.height - bestScore.height) <= 0.001 |
| | | && Math.abs(score.footprint - bestScore.footprint) <= 0.001 |
| | | && score.widthBias > bestScore.widthBias + 0.001 |
| | | ) |
| | | ) { |
| | | bestScore = score; |
| | | bestRotation = new THREE.Euler(x, y, z); |
| | | } |
| | | }); |
| | | }); |
| | | }); |
| | | |
| | | mesh.rotation.copy(bestRotation); |
| | | mesh.updateMatrixWorld(true); |
| | | }; |
| | | |
| | | if (agvModel === 'UNDERDRIVE_AGV') { |
| | | loadModel('model/latent/body.fbx').then((bodyMesh) => { |
| | | const scaleVal = 1; |
| | | const scaleVal = 0.55; |
| | | bodyMesh.scale.set(scaleVal, scaleVal, scaleVal); |
| | | |
| | | orientUnderdriveMesh(bodyMesh); |
| | | bodyMesh.rotateX(Math.PI); |
| | | |
| | | const size = centerMeshToGround(bodyMesh); |
| | | const horizontalSize = Math.max(size.x, size.z); |
| | | |
| | | const agvGroup = new THREE.Group(); |
| | | agvGroup.add(bodyMesh); |
| | |
| | | addObject(agvGroup); |
| | | |
| | | threeRef.current?.rePerspective( |
| | | Math.max(size.y, 250), |
| | | Math.max(size.y * 1.2, 320), |
| | | Math.max(size.y, 150), |
| | | Math.max(horizontalSize, 560), |
| | | ); |
| | | }).catch((error) => { |
| | | console.error('Failed to load latent/body.fbx.', error); |