首页 > 解决方案 > 三 JS - GLTF 模型暗

问题描述

我已成功使用 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 的时候: 在此处输入图像描述

这是我将模型上传到 glTF 查看器时: 在此处输入图像描述

这是当我将它加载到 ThreeJS 时(它是黑暗的): 在此处输入图像描述

标签: three.jsbabylonjs

解决方案


Solved it finally! The solution was that I needed to add intensity to the ambient light.


推荐阅读