【问题标题】:Why .obj does not react to directional light? [three.js]为什么 .obj 对定向光没有反应? [三.js]
【发布时间】:2015-03-25 23:18:33
【问题描述】:

谁知道为什么 .obj 不像盒子那样反射定向光?

两者的材质相同。

这是 GitHub 中的代码:https://github.com/triple-verge/triple-verge-website/blob/master/src/js/modules/logo-3d.js#L52

下面是这段代码:

logo.addLogo = function () {
    loader.load('img/logo.obj', function (obj) {
        var material = new THREE.MeshLambertMaterial({
                color: 0xff0000
            }),
            cube; // Test

        _logo.obj = obj;

        obj.traverse(function (child) {
            if (child instanceof THREE.Mesh) {
                child.geometry.applyMatrix(
                    new THREE.Matrix4().makeTranslation(-0.5, 0, 0)
                );

                child.material = material;

                // Test
                cube = new THREE.Mesh(
                    new THREE.BoxGeometry(0.5, 0.5, 0.5),
                    material
                );

                $(_logo.container).on('frame', function () {
                    child.position.set(0, Math.sin(Date.now() / 750) * 0.1, 0);
                    child.rotation.set(
                        Math.PI * 0.5,
                        0,
                        Math.sin(Date.now() / 500) * 0.8
                    );
                    cube.rotation.set(
                        Math.PI * 0.5,
                        0,
                        Math.sin(Date.now() / 500) * 0.8
                    );
                });
            }
        });

        _logo.scene.add(obj);
        _logo.scene.add(cube); // Test
    });
};

谢谢!

three.js r.70

【问题讨论】:

  • 您的 obj 文件似乎没有指定法线。

标签: javascript 3d three.js


【解决方案1】:

您要么需要在 obj 文件中导出顶点法线,要么调用

child.geometry.computeVertexNormals();

在您的 traverse() 加载程序回调函数内的方法中。

three.js r.70

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-20
    • 1970-01-01
    • 2021-05-10
    • 2019-01-28
    • 2019-02-01
    • 1970-01-01
    • 2018-01-01
    • 1970-01-01
    相关资源
    最近更新 更多