Android Open Source - ScalAR Material






From Project

Back to project page ScalAR.

License

The source code is released under:

GNU General Public License

If you think the Android project ScalAR 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

/**
  Copyright (C) 2010  Tobias Domhan//from ww w .  j  a  v a 2 s. com

    This file is part of AndObjViewer.

    AndObjViewer is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    AndObjViewer is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with AndObjViewer.  If not, see <http://www.gnu.org/licenses/>.
 
 */
package edu.dhbw.andobjviewer.models;

import java.io.Serializable;
import java.nio.FloatBuffer;

import android.graphics.Bitmap;

import edu.dhbw.andobjviewer.util.ArrayIterator;
import edu.dhbw.andobjviewer.util.BaseFileUtil;
import edu.dhbw.andobjviewer.util.MemUtil;

public class Material implements Serializable {
  //default values:
  //http://wiki.delphigl.com/index.php/glMaterial
  private float[] ambientlightArr = {0.2f, 0.2f, 0.2f, 1.0f};
  private float[] diffuselightArr = {0.8f, 0.8f, 0.8f, 1.0f};
  private float[] specularlightArr = {0.0f, 0.0f, 0.0f, 1.0f};
  //public access for performance reasons
  public transient FloatBuffer ambientlight = MemUtil.makeFloatBuffer(4);
  public transient FloatBuffer diffuselight = MemUtil.makeFloatBuffer(4);
  public transient FloatBuffer specularlight = MemUtil.makeFloatBuffer(4);
  public float shininess = 0;
  public int STATE = STATE_DYNAMIC;
    public static final int STATE_DYNAMIC = 0;
    public static final int STATE_FINALIZED = 1;
  
  private transient Bitmap texture = null;
  private String bitmapFileName = null;
  private transient BaseFileUtil fileUtil = null;
  
  private String name = "defaultMaterial";
  
  public Material() {
    
  }
  
  public Material(String name) {
    this.name = name;
    //fill with default values
    ambientlight.put(new float[]{0.2f, 0.2f, 0.2f, 1.0f});
    ambientlight.position(0);
    diffuselight.put(new float[]{0.8f, 0.8f, 0.8f, 1.0f});
    diffuselight.position(0);
    specularlight.put(new float[]{0.0f, 0.0f, 0.0f, 1.0f});
    specularlight.position(0);
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }
  
  
  public void setFileUtil(BaseFileUtil fileUtil) {
    this.fileUtil = fileUtil;
  }

  public String getBitmapFileName() {
    return bitmapFileName;
  }

  public void setBitmapFileName(String bitmapFileName) {
    this.bitmapFileName = bitmapFileName;
  }

  public void setAmbient(float[] arr) {
    ambientlightArr = arr;
  }
  
  public void setDiffuse(float[] arr) {
    diffuselightArr = arr;
  }
  
  public void setSpecular(float[] arr) {
    specularlightArr = arr;
  }
  
  public void setShininess(float ns) {
    shininess = ns;
  }
  
  /**
   * Sets the alpha value of the light sources.
   * @param alpha
   */
  public void setAlpha(float alpha) {
    ambientlight.put(3, alpha);
    diffuselight.put(3, alpha);
    specularlight.put(3, alpha);
  }
  
  public Bitmap getTexture() {
    return texture;
  }

  public void setTexture(Bitmap texture) {
    this.texture = texture;
  }
  
  public boolean hasTexture() {
    if(STATE == STATE_DYNAMIC) 
      return this.bitmapFileName != null;
    else if(STATE == STATE_FINALIZED)
        return this.texture != null;
    else 
      return false;
  }
  
  /**
   * stores the arrays in memory regions accessible by opengl
   * must be done before it is being used in opengl code
   */
  public void finalize() {
    ambientlight = MemUtil.makeFloatBuffer(ambientlightArr);
    diffuselight = MemUtil.makeFloatBuffer(diffuselightArr);
    specularlight = MemUtil.makeFloatBuffer(specularlightArr);
    ambientlightArr = null;
    diffuselightArr = null;
    specularlightArr = null;
    if(fileUtil != null && bitmapFileName != null) {
      texture = fileUtil.getBitmapFromName(bitmapFileName);
    }
  }
  
  /*
   * get  a google protocol buffers builder, that may be serialized
   */
  /*public BufferMaterial getProtocolBuffer() {
    ModelProtocolBuffer.BufferMaterial.Builder builder = ModelProtocolBuffer.BufferMaterial.newBuilder();
    builder.setName(name);
    return builder.build();
  }*/
  
}




Java Source Code List

com.skylion.speech.GoogleTranslate.java
com.skylion.speech.Narrator.java
com.skylion.speech.Synthesiser.java
edu.dhbw.andar.ARObject.java
edu.dhbw.andar.ARToolkit.java
edu.dhbw.andar.AndARActivity.java
edu.dhbw.andar.AndARRenderer.java
edu.dhbw.andar.CameraHolder.java
edu.dhbw.andar.CameraParameters.java
edu.dhbw.andar.CameraPreviewHandler.java
edu.dhbw.andar.CameraStatus.java
edu.dhbw.andar.Config.java
edu.dhbw.andar.GenericFunctions.java
edu.dhbw.andar.exceptions.AndARException.java
edu.dhbw.andar.exceptions.AndARRuntimeException.java
edu.dhbw.andar.interfaces.MarkerVisibilityListener.java
edu.dhbw.andar.interfaces.OpenGLRenderer.java
edu.dhbw.andar.interfaces.PreviewFrameSink.java
edu.dhbw.andar.pub.CustomActivity.java
edu.dhbw.andar.pub.CustomObject.java
edu.dhbw.andar.pub.CustomRenderer.java
edu.dhbw.andar.pub.SimpleBox.java
edu.dhbw.andar.util.GraphicsUtil.java
edu.dhbw.andar.util.IO.java
edu.dhbw.andobjviewer.AugmentedModelViewerActivity.java
edu.dhbw.andobjviewer.CheckFileManagerActivity.java
edu.dhbw.andobjviewer.Config.java
edu.dhbw.andobjviewer.InstructionsActivity.java
edu.dhbw.andobjviewer.ModelChooser.java
edu.dhbw.andobjviewer.graphics.LightingRenderer.java
edu.dhbw.andobjviewer.graphics.Model3D.java
edu.dhbw.andobjviewer.graphics.Renderer.java
edu.dhbw.andobjviewer.models.Group.java
edu.dhbw.andobjviewer.models.Material.java
edu.dhbw.andobjviewer.models.Model.java
edu.dhbw.andobjviewer.models.Vector3D.java
edu.dhbw.andobjviewer.parser.MtlParser.java
edu.dhbw.andobjviewer.parser.ObjParser.java
edu.dhbw.andobjviewer.parser.ParseException.java
edu.dhbw.andobjviewer.parser.SimpleTokenizer.java
edu.dhbw.andobjviewer.parser.Util.java
edu.dhbw.andobjviewer.util.ArrayIterator.java
edu.dhbw.andobjviewer.util.AssetsFileUtil.java
edu.dhbw.andobjviewer.util.BaseFileUtil.java
edu.dhbw.andobjviewer.util.FixedPointUtils.java
edu.dhbw.andobjviewer.util.MatrixUtils.java
edu.dhbw.andobjviewer.util.MemUtil.java
edu.dhbw.andobjviewer.util.SDCardFileUtil.java