0

我在加载 three.js 中的对象时遇到问题。正如我所说,颜色不会出现,物体是黑白的!

这是我的代码:

入门(我不确定这部分是否正常,所以我把它放在这里。)

const
    width = window.innerWidth - 300,
    height = window.innerHeight,
    scene = new THREE.Scene(),
    camera = new THREE.PerspectiveCamera(90, width / height, 1, 1000),
    renderer = new THREE.WebGLRenderer(),
    controls = new THREE.OrbitControls(camera, renderer.domElement),
    light = new THREE.AmbientLight(0xffffff, .5),
    loader = new THREE.OBJLoader();

camera.position.z = 50;
scene.add(camera);

controls.update();

scene.add(light);

renderer.setSize(width, height);
document.body.appendChild(renderer.domElement);

function animate() {
    requestAnimationFrame(animate);
    controls.update();
    renderer.render(scene, camera);
}

animate();

$(window).resize(function () {
    camera.aspect = width / height;
    camera.updateProjectionMatrix();
    renderer.setSize(width, height);
});

加载对象

function onProgress(xhr) {
    if (xhr.lengthComputable) {
        const percentComplete = xhr.loaded / xhr.total * 100;
        console.log(Math.round(percentComplete, 2) + '% downloaded');
    }
}

function onError() {
}

const manager = new THREE.LoadingManager();
manager.addHandler(/\.dds$/i, new THREE.DDSLoader());

new THREE.MTLLoader(manager)

    .setPath('http://localhost/X/assets/models/house/')
    .load('CH_building1.mtl', function (materials) {

        materials.preload();
        new THREE.OBJLoader(manager)
            .setMaterials(materials)

            .setPath('http://localhost/X/assets/models/house/')
            .load('CH_building1.obj', function (object) {

                object.position.y = -10;

                scene.add(object);
            }, onProgress, onError);
    });

对不起,如果它太长了。

也许目标文件已损坏。如果是这样,那我该如何解决?

编辑:那是因为灯光反射吗?

4

0 回答 0