Android Open Source - min3d Scene






From Project

Back to project page min3d.

License

The source code is released under:

MIT License

If you think the Android project min3d 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.min3d.lib.core;
/*from  w w w .ja v  a2  s .  c om*/
import android.util.Log;

import com.min3d.lib.Min3d;
import com.min3d.lib.interfaces.IDirtyParent;
import com.min3d.lib.interfaces.IObject3dContainer;
import com.min3d.lib.interfaces.ISceneController;
import com.min3d.lib.vos.CameraVo;
import com.min3d.lib.vos.Color4;
import com.min3d.lib.vos.Color4Managed;
import com.min3d.lib.vos.FogType;

import java.util.ArrayList;


public class Scene implements IObject3dContainer, IDirtyParent
{
  private ArrayList<Object3d> _children = new ArrayList<Object3d>();

  private ManagedLightList _lights;
  private CameraVo _camera;
  
  private Color4Managed _backgroundColor;
  private boolean _lightingEnabled;
  
  private Color4 _fogColor;
  private float _fogFar;
  private float _fogNear;
  private FogType _fogType;
  private boolean _fogEnabled;

  private ISceneController _sceneController;
  

  public Scene(ISceneController $sceneController) 
  {
    _sceneController = $sceneController;
    _lights = new ManagedLightList();
    _fogColor = new Color4(255, 255, 255, 255);
    _fogNear = 0;
    _fogFar = 10;
    _fogType = FogType.LINEAR;
    _fogEnabled = false;
  }

  /**
   * Allows you to use any Class implementing ISceneController
   * to drive the Scene...
   * @return
   */
  public ISceneController sceneController()
  {
    return _sceneController;
  }
  public void sceneController(ISceneController $sceneController)
  {
    _sceneController = $sceneController;
  }
  
  //
  
  /**
   * Resets Scene to default settings.
   * Removes and clears any attached Object3ds.
   * Resets light list.
   */
  public void reset()
  {
    clearChildren(this);

    _children = new ArrayList<Object3d>();

    _camera = new CameraVo();
    
    _backgroundColor = new Color4Managed(0, 0, 0, 255, this);
    
    _lights = new ManagedLightList();
    
    lightingEnabled(true);
  }
  
  /**
   * Adds Object3d to Scene. Object3d's must be added to Scene in order to be rendered
   * Returns always true. 
   */
  public void addChild(Object3d $o)
  {
    if (_children.contains($o)) return;
    
    _children.add($o);
    
    $o.parent(this);
    $o.scene(this);
  }
  
  public void addChildAt(Object3d $o, int $index)
  {
    if (_children.contains($o)) return;

    _children.add($index, $o);
  }
  
  /**
   * Removes Object3d from Scene.
   * Returns false if unsuccessful
   */
  public boolean removeChild(Object3d $o)
  {
    $o.parent(null);
    $o.scene(null);
    return _children.remove($o);
  }
  
  public Object3d removeChildAt(int $index)
  {
    Object3d o = _children.remove($index);
    
    if (o != null) {
      o.parent(null);
      o.scene(null);
    }
    return o;
  }
  
  public Object3d getChildAt(int $index)
  {
    return _children.get($index);
  }
  
  /**
   * TODO: Use better lookup 
   */
  public Object3d getChildByName(String $name)
  {
    for (int i = 0; i < _children.size(); i++)
    {
      if (_children.get(0).name() == $name) return _children.get(0); 
    }
    return null;
  }
  
  public int getChildIndexOf(Object3d $o)
  {
    return _children.indexOf($o);
  }
  
  public int numChildren()
  {
    return _children.size();
  }

  /**
   * Scene's camera
   */
  public CameraVo camera()
  {
    return _camera;
  }
  public void camera(CameraVo $camera)
  {
    _camera = $camera;
  }
  
  /**
   * Scene instance's background color
   */
  public Color4Managed backgroundColor()
  {
    return _backgroundColor;
  }

  /**
   * Lights used by the Scene 
   */
  public ManagedLightList lights()
  {
    return _lights;
  }

  /**
   * Determines if lighting is enabled for Scene. 
   */
  public boolean lightingEnabled()
  {
    return _lightingEnabled;
  }
  
  public void lightingEnabled(boolean $b)
  {
    _lightingEnabled = $b;
  }
  
  //

  /*
  public boolean backgroundTransparent() {
    return _backgroundTransparent;
  }

  public void backgroundTransparent(boolean backgroundTransparent) {
    this._backgroundTransparent = backgroundTransparent;
  }
  */

  public Color4 fogColor() {
    return _fogColor;
  }

  public void fogColor(Color4 _fogColor) {
    this._fogColor = _fogColor;
  }

  public float fogFar() {
    return _fogFar;
  }

  public void fogFar(float _fogFar) {
    this._fogFar = _fogFar;
  }

  public float fogNear() {
    return _fogNear;
  }

  public void fogNear(float _fogNear) {
    this._fogNear = _fogNear;
  }

  public FogType fogType() {
    return _fogType;
  }

  public void fogType(FogType _fogType) {
    this._fogType = _fogType;
  }

  public boolean fogEnabled() {
    return _fogEnabled;
  }

  public void fogEnabled(boolean _fogEnabled) {
    this._fogEnabled = _fogEnabled;
  }

  /**
   * Used by Renderer 
   */
  void init() /*package-private*/ 
  {
    Log.i(Min3d.TAG, "Scene.init()");
    
    this.reset();
    
    _sceneController.initScene();
    _sceneController.getInitSceneHandler().post(_sceneController.getInitSceneRunnable());
  }
  
  void update()
  {
    _sceneController.updateScene();
    _sceneController.getUpdateSceneHandler().post(_sceneController.getUpdateSceneRunnable());
  }
  
  /**
   * Used by Renderer 
   */
  ArrayList<Object3d> children() /*package-private*/ 
  {
    return _children;
  }
  
  private void clearChildren(IObject3dContainer $c)
  {
    for (int i = $c.numChildren() - 1; i >= 0; i--)
    {
      Object3d o = $c.getChildAt(i);
      o.clear();
      
      if (o instanceof Object3dContainer)
      {
        clearChildren((Object3dContainer)o);
      }
    }
  }  
  
  public void onDirty()
  {
    //
  }
}




Java Source Code List

com.min3d.ApplicationTest.java
com.min3d.ExampleAccelerometer.java
com.min3d.ExampleAnimatedTexture.java
com.min3d.ExampleAnimatingVertices.java
com.min3d.ExampleAssigningTexturesDynamically.java
com.min3d.ExampleCamera.java
com.min3d.ExampleFog.java
com.min3d.ExampleFromScratch.java
com.min3d.ExampleInsideLayout.java
com.min3d.ExampleKeyframeAnimation.java
com.min3d.ExampleLightProperties.java
com.min3d.ExampleLoad3DSFile.java
com.min3d.ExampleLoadMD2File.java
com.min3d.ExampleLoadObjFileMultiple.java
com.min3d.ExampleLoadObjFile.java
com.min3d.ExampleMipMap.java
com.min3d.ExampleMostMinimal.java
com.min3d.ExampleMultiTexture.java
com.min3d.ExampleMultipleLights.java
com.min3d.ExampleRenderType.java
com.min3d.ExampleRotatingPlanets.java
com.min3d.ExampleSubsetOfFaces.java
com.min3d.ExampleTextureOffset.java
com.min3d.ExampleTextureWrap.java
com.min3d.ExampleTextures.java
com.min3d.ExampleTransparentGlSurface.java
com.min3d.ExampleVertexColors.java
com.min3d.ExampleVerticesVariations.java
com.min3d.ScratchActivity.java
com.min3d.SplashActivity.java
com.min3d.lib.AParser.java
com.min3d.lib.ApplicationTest.java
com.min3d.lib.IParser.java
com.min3d.lib.LittleEndianDataInputStream.java
com.min3d.lib.MD2Parser.java
com.min3d.lib.Max3DSParser.java
com.min3d.lib.Min3d.java
com.min3d.lib.ObjParser.java
com.min3d.lib.ParseObjectData.java
com.min3d.lib.ParseObjectFace.java
com.min3d.lib.Parser.java
com.min3d.lib.Shared.java
com.min3d.lib.Utils.java
com.min3d.lib.animation.AnimationObject3d.java
com.min3d.lib.animation.KeyFrame.java
com.min3d.lib.core.Color4BufferList.java
com.min3d.lib.core.FacesBufferedList.java
com.min3d.lib.core.ManagedLightList.java
com.min3d.lib.core.Number3dBufferList.java
com.min3d.lib.core.Object3dContainer.java
com.min3d.lib.core.Object3d.java
com.min3d.lib.core.RenderCaps.java
com.min3d.lib.core.RendererActivity.java
com.min3d.lib.core.Renderer.java
com.min3d.lib.core.Scene.java
com.min3d.lib.core.TextureList.java
com.min3d.lib.core.TextureManager.java
com.min3d.lib.core.UvBufferList.java
com.min3d.lib.core.Vertices.java
com.min3d.lib.interfaces.IDirtyManaged.java
com.min3d.lib.interfaces.IDirtyParent.java
com.min3d.lib.interfaces.IObject3dContainer.java
com.min3d.lib.interfaces.ISceneController.java
com.min3d.lib.objectPrimitives.Box.java
com.min3d.lib.objectPrimitives.HollowCylinder.java
com.min3d.lib.objectPrimitives.Rectangle.java
com.min3d.lib.objectPrimitives.SkyBox.java
com.min3d.lib.objectPrimitives.Sphere.java
com.min3d.lib.objectPrimitives.Torus.java
com.min3d.lib.vos.AbstractDirtyManaged.java
com.min3d.lib.vos.BooleanManaged.java
com.min3d.lib.vos.CameraVo.java
com.min3d.lib.vos.Color4Managed.java
com.min3d.lib.vos.Color4.java
com.min3d.lib.vos.Face.java
com.min3d.lib.vos.FloatManaged.java
com.min3d.lib.vos.FogType.java
com.min3d.lib.vos.FrustumManaged.java
com.min3d.lib.vos.LightType.java
com.min3d.lib.vos.Light.java
com.min3d.lib.vos.Number3dManaged.java
com.min3d.lib.vos.Number3d.java
com.min3d.lib.vos.RenderType.java
com.min3d.lib.vos.ShadeModelManaged.java
com.min3d.lib.vos.ShadeModel.java
com.min3d.lib.vos.TexEnvxVo.java
com.min3d.lib.vos.TextureVo.java
com.min3d.lib.vos.Uv.java
com.min3d.lib.vos.Vertex3d.java