Merge pull request '更新旋转代码' (#1) from Training/ComputerGraphics:master into master

Reviewed-on: http://git.u-bim.net/Zhang/ComputerGraphics/pulls/1
This commit is contained in:
zhangXQ 2021-02-08 15:22:57 +08:00
commit 06a8c36d6b
4 changed files with 1234 additions and 3 deletions

View File

@ -10,6 +10,7 @@
</head>
<body>
<script src="lib/three.js"></script>
<script src="lib/OrbitControls.js"></script>
<script src="js/loader.js"></script>
<script src="js/main.js"></script>
</body>

View File

@ -14,6 +14,11 @@ renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0xffffff);
document.body.appendChild(renderer.domElement);
window.addEventListener('resize', onWindowResize);
// 相机控制
var controls = new THREE.OrbitControls(camera, renderer.domElement);
// 加载模型数据
const loader = new THREE.FileLoader();
loader.load(
@ -26,8 +31,7 @@ loader.load(
box.expandByScalar(10000);
var cameraPos = new THREE.Vector3(box.min.x, box.min.y, box.max.z);
camera.position.copy(cameraPos);
camera.lookAt(box.getCenter());
camera.updateMatrixWorld();
controls.target = box.getCenter();
scene.add(bimScene);
},
function(xhr)
@ -38,10 +42,19 @@ loader.load(
{
console.error('An error happened');
}
)
);
function onWindowResize()
{
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate() {
requestAnimationFrame( animate );
controls.update();
renderer.render( scene, camera );
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 KiB

After

Width:  |  Height:  |  Size: 159 KiB