【问题标题】:Three.js - Imported OBJ cannot receive shadows when material is appliedThree.js - 应用材质时导入的 OBJ 无法接收阴影
【发布时间】:2018-11-07 19:19:16
【问题描述】:

我已经用这个加载函数导入了一个 obj:

    // called when resource is loaded
    function ( object ) {

        // For any meshes in the model, add our material.
        object.traverse( function ( node ) {

            if ( node instanceof THREE.Mesh ){
                //node.material = material;
                //node.geometry.computeVertexNormals(); 
                node.castShadow = true; 
                node.receiveShadow = true;
            }
        } );


        object.scale.set(0.5,0.5,0.5);
        scene.add( object );
        parts[partName] = object;

    }

对象加载良好,并且场景中的聚光灯产生了阴影。问题是当我将材质应用于网格时(因此在上面的代码中注释掉了),模型不再接收阴影。

材质是逐个节点应用的,材质是这样映射jpg的。

if ( node.isMesh ) node.material = material;

new THREE.MeshBasicMaterial( { map: new THREE.TextureLoader().load( 'materials/orange.jpg' ), shininess: 50, shading: THREE.SmoothShading }),

感谢您的帮助,埃德。

【问题讨论】:

    标签: javascript three.js 3d


    【解决方案1】:

    我正在使用

    MeshBasicMaterial
    

    应该使用

    MeshLambertMaterial
    

    所以材质可以接收阴影。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-28
      • 2021-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-26
      相关资源
      最近更新 更多