three.js-当我尝试加载对象时,颜色不会出现

时间:2019-12-11 08:51:54

标签: javascript three.js objloader

我在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);
    });

抱歉,时间太长

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

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

0 个答案:

没有答案