1

由于在https://github.com/googlesamples/tango-examples-java/tree/master/PointCloudJava中发布yamabe 并使用 rajawali 渲染器,点云不再根据与 3D 相机的距离进行着色。我尝试将 Points.java 的代码修改如下,以再次获得相同的功能:

public class Points extends Object3D {


    private static final String sVertexShaderCode = "uniform mat4 uMVPMatrix;"
            + "attribute vec4 vPosition;" + "varying vec4 vColor;"
            + "void main() {" + "gl_PointSize = 5.0;"
            + "  gl_Position = uMVPMatrix * vPosition;"
            + "  vColor = vPosition;" + "}";
    private static final String sFragmentShaderCode = "precision mediump float;"
            + "varying vec4 vColor;"
            + "void main() {"
            + "  gl_FragColor = vec4(vColor);" + "}";





private int mMaxNumberofVertices;


public Points(int numberOfPoints) {
    super();
    mMaxNumberofVertices = numberOfPoints;
    init(true);
    Material m = new Material(new VertexShader(sVertexShaderCode), new FragmentShader(sFragmentShaderCode));
    //m.setColor(Color.GREEN);
    setMaterial(m);
}

// Initialize the buffers for Points primitive.
// Since only vertex and Index buffers are used, we only initialize them using setdata call.
protected void init(boolean createVBOs) {
    float[] vertices = new float[mMaxNumberofVertices*3];
    int[] indices = new int[mMaxNumberofVertices];
    for(int i = 0; i < indices.length; ++i){
        indices[i] = i;
    }
    setData(vertices, GLES20.GL_STATIC_DRAW,
            null, GLES20.GL_STATIC_DRAW,
            null, GLES20.GL_STATIC_DRAW,
            null, GLES20.GL_STATIC_DRAW,
            indices, GLES20.GL_STATIC_DRAW,
            true);

}

// Update the geometry of the points once new Point Cloud Data is available.
public void updatePoints(FloatBuffer pointCloudBuffer, int pointCount) {
    pointCloudBuffer.position(0);
    mGeometry.setNumIndices(pointCount);
    mGeometry.getVertices().position(0);
    mGeometry.changeBufferData(mGeometry.getVertexBufferInfo(), pointCloudBuffer, 0, pointCount * 3);
}

public void preRender() {
    super.preRender();
    setDrawingMode(GLES20.GL_POINTS);
    GLES10.glPointSize(5.0f);
}

}

但是这些点只是红色而不是不同的颜色。我对 Rajawali 和 OGL 很陌生,所以有人可以告诉我我缺少什么部分来让着色器在点类上工作。

非常感谢彼得。

4

0 回答 0