2013-05-17 2 views
0

카메라로 빛을 이동하고 싶습니다. 내가 쓴 :three.js TrackballControls로 빛을 이동시킬 때 카메라 위치가 잘못되었습니다.

scene = new THREE.Scene(); 

    camera = new THREE.PerspectiveCamera(40, windowWidth/windowHeight, 1, 10000); 
    camera.position.z = 50; 
    scene.add(camera); 


    var dirLight = new THREE.DirectionalLight(0xffffff); 
    **dirLight.position = camera.position;** 
    dirLight.position.normalize(); 
    scene.add(dirLight); 

    renderer = new THREE.WebGLRenderer(); 
    renderer.setSize(windowWidth, windowHeight); 
    i_container.appendChild(renderer.domElement); 

    controls = new THREE.TrackballControls(camera); 

    controls.rotateSpeed = 1.0; 
    controls.zoomSpeed = 1.2; 
    controls.panSpeed = 0.8; 

    controls.noZoom = false; 
    controls.noPan = false; 

    controls.staticMoving = true; 
    controls.dynamicDampingFactor = 0.3; 

    controls.keys = [65, 83, 68]; 

    controls.addEventListener('change', render); 

모든 작품 : 빛이 카메라로 이동합니다. 그러나 한 가지 문제가 있습니다. 장면을 초기화 할 때 카메라가 내 물건 안에 있습니다. 그래서 전체 개체를 보려면 축소해야합니다.

이 줄이없는 경우 - "dirLight.position = camera.position;" 장면이 초기화됩니다. ok : 전체 객체를 봅니다.

무엇이 잘못 되었습니까? 나는 카메라의 위치를 ​​바꾸지 않는다. 왜 내가 물건 안에 있니?

감사합니다, Zhenya

답변

0

TrackballControls 함께 할 수 없다. 그것은

dirLight.position = camera.position; 
dirLight.position.normalize(); 

이 카메라 위치를 표준화하기 때문입니다.

dirLight.position.normalize()을 삭제하십시오. 더 이상 필요하지 않습니다.

사실, 대신 pointLight를 사용 하겠지만 현재 수행중인 작업은 현재 버전의 three.js에서 작동합니다.

three.js r.58

관련 문제