如何将灯光添加到BufferGeometry生成的Mesh并绘制为TriangleStrips?

时间:2017-04-23 15:34:24

标签: three.js

我试图将灯光添加到BufferGeometry创建的Mesh的场景中。 mesh.drawModeTHREE.TriangleStripDrawMode。我不知道为什么光没有应用于网格。

有一个例子:

https://jsbin.com/jofasabeji/edit?js,output

是否有要激活的标志(如面部剔除)?

谢谢!

1 个答案:

答案 0 :(得分:2)

您的几何体缺少顶点法线。

您可以自己指定法线,或者 - 如果您发现结果可以接受 - 您可以致电:

public myjFrame()
    {
        setCursor(Toolkit.getDefaultToolkit().createCustomCursor(new ImageIcon(UrlImg("cur_empty.png")).getImage(),new Point(0,0),"cursor_default"));
        this.setLayout(new BorderLayout());
        lblBg= new JLabel();
        lblBg.setIcon(new ImageIcon(UrlImg("main_menu_bg.png")));
        lblBg.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                cMouseDragged(evt);
            }
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                cMouseMoved(evt);
            }
        });
        this.add(lblBg);
    lblBg.setLayout(null);`

        lblBtn= new JLabel();
        lblBtn.setIcon(new ImageIcon(UrlImg("choi.png")));
        lblBtn.setBounds(120, 310, 345, 132);
        lblBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblChoiMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                lblChoiMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                lblChoiMouseExited(evt);
            }
        });  
        lblBg.add(lblBtn);
        lblCur= new JLabel();
        lblCur.setIcon(new ImageIcon(UrlImg("cur_def.png")));
        lblCur.setBounds(200, 200, 155, 155);
        lblCur.setText("");
        lblBg.add(lblCur);
    }
    private void cMouseMoved(java.awt.event.MouseEvent evt) {
        lblBg.add(lblBtn);
        lblCur.setLocation(evt.getX()-40,evt.getY()-40); 
    }
    private void cMouseDragged(java.awt.event.MouseEvent evt) {
        lblCur.setLocation(evt.getX()-40,evt.getY()-40);
    } 
     private void lblChoiMouseEntered(java.awt.event.MouseEvent evt) {                                     
      lblBtn.setIcon(new ImageIcon(UrlImg("choi_hover.png")));
    }                                    

    private void lblChoiMouseExited(java.awt.event.MouseEvent evt) {                                    
         lblBtn.setIcon(new ImageIcon(UrlImg("choi.png"))); 
    } 
     private void lblChoiMouseClicked(java.awt.event.MouseEvent evt) {                                     
        this.dispose();
    }   
    public static void main(String[] args) {
        myjFrame main= new myjFrame();
        main.setBounds(100, 100, 769,892);
        main.setVisible(true);
    }
}

或者,如果将材质属性设置为平面着色(并且材质支持),则可以避免设置顶点法线:

geometry.computeVertexNormals();

此外,您需要为灯光设置合理的强度:

material.shading = THREE.FlatShading;

three.js r.85