我正在努力猜测如何才能让任何物体加载几乎覆盖画布的整个宽度和高度。
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
var renderer = new THREE.WebGLRenderer();
var loader = new THREE.STLLoader();
var mesh;
renderer.setClearColor(0xFFFFFF, 1);
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
loader.addEventListener( 'load', function ( event ) {
var geometry = event.content;
var redPhongMaterial = new THREE.MeshPhongMaterial({ color: 0xFFEA32, side: THREE.DoubleSide, ambient:0x000000});
mesh = new THREE.Mesh( geometry, redPhongMaterial )
mesh.castShadow = true;
mesh.receiveShadow = true;
geometry.computeBoundingBox();
var boundingBox = mesh.geometry.boundingBox.clone();
drawBoundingBox(boundingBox, mesh.scale.x, mesh.scale.y, mesh.scale.z);
mesh.translateX (0);
mesh.translateY (0);
mesh.translateZ (0);
scene.add( mesh );
} );
loader.addEventListener( 'progress', function ( event ) {
document.getElementById('progress').innerHTML = 'Progress: '+event.loaded+'%';
});
loader.addEventListener( 'error', function ( event ) {
alert( event.message );
});
loader.load( 'pet.stl' );
camera.position.set( 15, -10, 120 );
render();
function render() {
requestAnimationFrame(render);
renderer.render(scene, camera);
}
</script>
我想我应该将相机位置设置为x,y和z,但不知道。
我该如何做到这一点?
答案 0 :(得分:2)
camera.position.set(0,0,Math.max(x*3,ys*3,z*3));