gpt4 book ai didi

javascript - Three.js - 设置相机位置

转载 作者:行者123 更新时间:2023-12-02 17:44:22 29 4
gpt4 key购买 nike

我正在努力猜测如何加载几乎覆盖 Canvas 整个宽度和高度的任何对象。

 <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,但我不知道。

我怎样才能做到这一点?

最佳答案

camera.position.set(0,0,Math.max(x*3,ys*3,z*3));

关于javascript - Three.js - 设置相机位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21894607/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com