三种JS-GLTF模型很暗

时间:2018-08-06 22:59:23

标签: three.js babylonjs

我已经成功使用GLTFLoader将模型加载到ThreeJS中,但是我的模型很暗。我尝试将其上传到glTF ViewerBabylonJS,并且在那里完美运行。这是我的JavaScript代码:

const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth/window.innerHeight, 0.1, 1000 )
const controls = new THREE.OrbitControls( camera )
const light = new THREE.AmbientLight( 0x404040 ); // soft white light


const renderer = new THREE.WebGLRenderer()
renderer.setSize( window.innerWidth, window.innerHeight )
renderer.setClearColor( 0xffffff )
document.body.appendChild( renderer.domElement )

// Instantiate a loader
const loader = new THREE.GLTFLoader();

// Load a glTF resource
loader.load(
    // resource URL
    'untitled2.gltf',
    // called when the resource is loaded
    function ( gltf ) {

        scene.add( gltf.scene )

        gltf.animations // Array<THREE.AnimationClip>
        gltf.scene // THREE.Scene
        gltf.scenes // Array<THREE.Scene>
        gltf.cameras // Array<THREE.Camera>
        gltf.asset // Object

    }
    // loading and error function
)

camera.position.y = 1
camera.position.z = 2

// Vertical
controls.minPolarAngle = 1; // radians
controls.maxPolarAngle = 1; // radians

//Horizontal
controls.minAzimuthAngle = - Infinity; // radians
controls.maxAzimuthAngle = Infinity; // radians

scene.add( light );

const animate = function () {
    requestAnimationFrame( animate )
    renderer.render( scene, camera )
}

animate()

我尝试添加环境照明,因为根据文档,它应该用作全局照明并更改背景颜色。

这是将模型上传到babylonJS的时间: enter image description here

这是当我将模型上传到glTF查看器时: enter image description here

这是当我将其加载到ThreeJS时(黑暗): enter image description here

1 个答案:

答案 0 :(得分:0)

终于解决了!解决的办法是我需要增加环境光的强度。