Android Open Source - android-per-pixel-lighting-demo Model






From Project

Back to project page android-per-pixel-lighting-demo.

License

The source code is released under:

Apache License

If you think the Android project android-per-pixel-lighting-demo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.pedroedrasousa.object3d;
/*from w ww.  j a  va 2 s. co m*/
import java.io.IOException;
import java.io.InputStream;

import com.pedroedrasousa.engine.Texture;

import android.content.Context;
import android.opengl.GLES20;
import android.opengl.Matrix;

public class Model {
  
  private Mesh  mMesh;
  private Texture  mBaseMap    = new Texture();
  private Texture  mNormalMap    = new Texture();
  private float[]  mModelMatrix  = new float[16];
  
  public Model() {
    Matrix.setIdentityM(mModelMatrix, 0);
  }
  
  public void LoadFromObj(Context context, String assetName) {
    
    ObjLoader objLoader = new ObjLoader();
    
      InputStream inputStream;
    try {
      inputStream = context.getAssets().open(assetName);
      mMesh = objLoader.load(context, inputStream);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  
  public void setBaseMap(Texture texture) {
    mBaseMap = texture;
  }
  
  public void setNormalMap(Texture texture) {
    mNormalMap = texture;
  }
  
  public void bindVertexBuffers() {
    mMesh.bindVertexBuffers();
  }
  
  public void unbindVertexBuffers() {
    mMesh.unbindVertexBuffers();
  }
  
  public void render() {
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mBaseMap.getHandle());
        GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mNormalMap.getHandle());
    mMesh.render();
  }
  
  public final float[] getModelMatrix() {
    return mModelMatrix;
  }
}




Java Source Code List

com.pedroedrasousa.engine.EngineGLSurfaceView.java
com.pedroedrasousa.engine.Renderer.java
com.pedroedrasousa.engine.ShaderProgram.java
com.pedroedrasousa.engine.Texture.java
com.pedroedrasousa.engine.Vec2.java
com.pedroedrasousa.engine.Vec3.java
com.pedroedrasousa.object3d.Mesh.java
com.pedroedrasousa.object3d.Model.java
com.pedroedrasousa.object3d.ObjLoader.java
com.pedroedrasousa.object3d.Triangle.java
com.pedroedrasousa.object3d.Vertex.java
com.pedroedrasousa.perpixellightingdemo.MainActivity.java
com.pedroedrasousa.perpixellightingdemo.PerPixelLighting.java