Exemplo n.º 1
0
  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);
  }
Exemplo n.º 2
0
  public void init(int dpi, RenderScriptGL rs, Resources res, int width, int height) {
    if (!mInited) {
      mDensityDPI = dpi;

      mRS = rs;
      mRes = res;

      mWidth = width;
      mHeight = height;

      mDotParticles = new ScriptField_Particle(mRS, DOT_COUNT);
      Mesh.AllocationBuilder smb2 = new Mesh.AllocationBuilder(mRS);
      smb2.addVertexAllocation(mDotParticles.getAllocation());
      smb2.addIndexSetType(Mesh.Primitive.POINT);
      mDotMesh = smb2.create();

      mBeamParticles = new ScriptField_Particle(mRS, DOT_COUNT);
      Mesh.AllocationBuilder smb3 = new Mesh.AllocationBuilder(mRS);
      smb3.addVertexAllocation(mBeamParticles.getAllocation());
      smb3.addIndexSetType(Mesh.Primitive.POINT);
      mBeamMesh = smb3.create();

      mScript = new ScriptC_phasebeam(mRS, mRes, R.raw.phasebeam);
      mScript.set_dotMesh(mDotMesh);
      mScript.set_beamMesh(mBeamMesh);
      mScript.bind_dotParticles(mDotParticles);
      mScript.bind_beamParticles(mBeamParticles);

      mPvConsts = new ScriptField_VpConsts(mRS, 1);

      createProgramVertex();
      createProgramRaster();
      createProgramFragmentStore();
      createProgramFragment();
      createBackgroundMesh();
      loadTextures();

      mScript.set_densityDPI(mDensityDPI);

      mRS.bindRootScript(mScript);

      mScript.invoke_positionParticles();
      mInited = true;
    }
  }