简体   繁体   English

Three.js MeshPhong材质线框照明

[英]Three.js MeshPhongMaterial Wireframe lighting

When I try to view meshphongmaterial with a wireframe onto an arrayBufferGeometry where the vetexColors are set to THREE.vertexColors; 当我尝试将具有线框的meshphongmaterial查看到arrayBufferGeometry上,其中vetexColors设置为THREE.vertexColors;。 The lighting is only working for 1 random face. 照明仅适用于1张随机面孔。 When I switch to MeshBasicmaterial I get the desired behavior. 当我切换到MeshBasicmaterial时,我得到了想要的行为。 With wireframe set to false the phong material looks good and is lit up: 线框设置为假时,丁字裤材质看起来很好并且被点亮:

 geometry.addAttribute('position', new THREE.BufferAttribute(vertices, 3));
    geometry.addAttribute('color', new THREE.BufferAttribute(colors, 3));
    geometry.computeFaceNormals();
    geometry.computeVertexNormals();

    console.log(geometry);
    var material = new THREE.MeshBasicMaterial({
        side: THREE.DoubleSide,
        wireframe: true,
        transparent: false,
        vertexColors: THREE.VertexColors, // CHANGED
        shininess: 100,
        //     color: 0xff0000,
        shading: THREE.SmoothShading
    });

    console.log(material);

    var terrainMesh = new THREE.Mesh(geometry, material);
    terrainMesh.name = 'GRD';
    terrainMesh.receiveShadow = true;
    terrainMesh.castShadow = true;
    console.log(terrainMesh);
    return terrainMesh;

Do I need to recompute the vertex normals after the material? 材质之后,我是否需要重新计算顶点法线? Is there a reason why the lighting would work for solid faces and not wireframe? 照明是否可以用于实体面而不是线框,是否有原因?

It was a lighting issue. 这是一个照明问题。

I have a variety of lights, AmbientLight, DirectionalLight to represent the sun, and a SpotLight that follows the camera target around to highlight what the user is looking at. 我有各种各样的灯光,AmbientLight,DirectionalLight代表太阳,还有一个SpotLight跟随相机目标周围以突出显示用户正在查看的内容。

Non of these were properly lighting the wire-frame. 这些都不是正确地照明线框。 I then followed the MeshPhongMaterial example and saw they used point lights. 然后,我遵循了MeshPhongMaterial示例,并看到它们使用了点光源。 I assumed the only difference between a point light and a spot light was a direction and target. 我认为点光源和点光源之间的唯一区别是方向和目标。 That is incorrect because the point light ended up working. 这是不正确的,因为点光源最终起作用了。

Another issue is that the lighting from a point light onto the wire-frame has to be on the front side of the material(regardless of the side property in MeshPhongMaterial) and can not be from the back. 另一个问题是,从点光源到线框的照明必须在材质的正面(不管MeshPhongMaterial是否具有侧面属性),而不能从背面。 My geometry faces down, because of the format of the file loaded is opposite to standards. 我的几何图形面朝下,因为加载的文件格式与标准相反。 The point light had to be positioned under the geometry to illuminate the material. 点光源必须放置在几何形状下方以照亮材质。 I ended up adding a reverse sun type light that illuminates the geometry from underneath using a PointLight. 最后,我添加了反向太阳光,使用PointLight从下面照亮了几何形状。

I still do not comprehend why wireframe is only illuminated by PointLight and why it doesnt illuminate a THREE.DoubleSide from the rear. 我仍然不理解为什么线框仅由PointLight照明,以及为什么它不从背面照明THREE.DoubleSide。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM