private void createBackgroundMesh() { // The composition and colors of the background mesh were plotted on paper and photoshop // first then translated to the csv file in raw. Points and colors are not random. ArrayList meshData = new ArrayList(); InputStream inputStream = mRes.openRawResource(R.raw.bgmesh); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); try { String line; while ((line = reader.readLine()) != null) { meshData.add(line); } } catch (IOException e) { Log.e(LOG_TAG, "Unable to load background mesh from csv file."); } finally { try { inputStream.close(); } catch (IOException e) { Log.e(LOG_TAG, "Unable to close background mesh csv file."); } } int meshDataSize = meshData.size(); mVertexColors = new ScriptField_VertexColor_s(mRS, meshDataSize); for (int i = 0; i < meshDataSize; i++) { String line = (String) meshData.get(i); String[] values = line.split(","); float xPos = new Float(values[0]); float yPos = new Float(values[1]); float red = new Float(values[2]); float green = new Float(values[3]); float blue = new Float(values[4]); mVertexColors.set_position(i, new Float3(xPos, yPos, 0.0f), false); mVertexColors.set_color(i, new Float4(red, green, blue, 1.0f), false); } mVertexColors.copyAll(); Mesh.AllocationBuilder backgroundBuilder = new Mesh.AllocationBuilder(mRS); backgroundBuilder.addIndexSetType(Primitive.TRIANGLE); backgroundBuilder.addVertexAllocation(mVertexColors.getAllocation()); mScript.set_gBackgroundMesh(backgroundBuilder.create()); mScript.bind_vertexColors(mVertexColors); }
private void createProgramVertex() { ProgramVertex.Builder backgroundBuilder = new ProgramVertex.Builder(mRS); backgroundBuilder.setShader(mRes, R.raw.bg_vs); backgroundBuilder.addInput(ScriptField_VertexColor_s.createElement(mRS)); ProgramVertex programVertexBackground = backgroundBuilder.create(); mScript.set_vertBg(programVertexBackground); updateProjectionMatrices(); ProgramVertex.Builder builder = new ProgramVertex.Builder(mRS); builder.setShader(mRes, R.raw.dot_vs); builder.addConstant(mPvConsts.getType()); builder.addInput(mDotMesh.getVertexAllocation(0).getType().getElement()); ProgramVertex pvs = builder.create(); pvs.bindConstants(mPvConsts.getAllocation(), 0); mRS.bindProgramVertex(pvs); mScript.set_vertDots(pvs); }