Android Open Source - jmini3d Canvas3d






From Project

Back to project page jmini3d.

License

The source code is released under:

Copyright 2012 Mobialia http://www.mobialia.com/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to ...

If you think the Android project jmini3d 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 jmini3d.gwt;
/*  w  ww  . j a  va2s.  c o  m*/
import com.google.gwt.animation.client.AnimationScheduler;
import com.google.gwt.canvas.dom.client.Context;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Window;
import com.googlecode.gwtgl.binding.WebGLRenderingContext;

import jmini3d.Scene;
import jmini3d.SceneController;

public class Canvas3d implements AnimationScheduler.AnimationCallback, TextureLoadedListener {

  Element webGLCanvas;
  WebGLRenderingContext gl;

  boolean stopped = false;
  int width, height;
  float scale = 1;

  public Renderer3d renderer3d;
  SceneController sceneController;
  boolean forceRedraw = false;

  public Canvas3d(String resourceLoaderDir) {

    webGLCanvas = DOM.createElement("canvas");
    webGLCanvas.setAttribute("tabindex", "0"); // Workaround to receive key events

    gl = (WebGLRenderingContext) getContext(webGLCanvas, "webgl");
    if (gl == null) {
      gl = (WebGLRenderingContext) getContext(webGLCanvas, "experimental-webgl");
    }
    if (gl == null) {
      Window.alert("Sorry, Your browser doesn't support WebGL. Please install the last version of Firefox, Chrome, Safari, or Internet Explorer and check that WebGL is enabled.");
      return;
    }

    renderer3d = new Renderer3d(gl, new ResourceLoader(resourceLoaderDir), this);
  }

  public final native Context getContext(Element el, String contextId) /*-{
    return el.getContext(contextId);
   }-*/;

  public final native float getDevicePixelRatio() /*-{
     return window.devicePixelRatio || 1;
   }-*/;

  public void setSize(int width, int height) {
    this.width = (int) (width * scale);
    this.height = (int) (height * scale);
    webGLCanvas.setAttribute("width", String.valueOf(this.width));
    webGLCanvas.setAttribute("height", String.valueOf(this.height));
    webGLCanvas.setAttribute("style", "width: " + width + "px; height: " + height + "px;");
    requestRender();
  }

  public void onResume() {
    stopped = false;
    AnimationScheduler.get().requestAnimationFrame(this);
  }

  public void onPause() {
    stopped = true;
  }

  @Override
  public void execute(double timestamp) {
    if (!stopped) {
      if (sceneController != null) {
        if (sceneController.updateScene(width, height) || forceRedraw) {
          Scene scene = sceneController.getScene();
          if (scene != null) {
            forceRedraw = false;
            renderer3d.render(scene);
          }
        }
      }
      AnimationScheduler.get().requestAnimationFrame(this);
    }
  }

  public void requestRender() {
    forceRedraw = true;
  }

  public void setSceneController(SceneController sceneController) {
    this.sceneController = sceneController;
  }

  public Renderer3d getRenderer3d() {
    return renderer3d;
  }

  public Element getElement() {
    return webGLCanvas;
  }

  public void setScale(float scale) {
    this.scale = scale;
  }

  public float getScale() {
    return scale;
  }

  @Override
  public void onTextureLoaded() {
    requestRender();
  }
}




Java Source Code List

cocoonjs.CocoonJsLinker.java
jmini3d.Blending.java
jmini3d.Camera.java
jmini3d.Color4.java
jmini3d.CubeMapTexture.java
jmini3d.Font.java
jmini3d.GpuObjectStatus.java
jmini3d.MatrixUtils.java
jmini3d.Object3d.java
jmini3d.Rect.java
jmini3d.SceneController.java
jmini3d.Scene.java
jmini3d.Texture.java
jmini3d.Utils.java
jmini3d.Vector3.java
jmini3d.android.Activity3d.java
jmini3d.android.GeometryBuffers.java
jmini3d.android.GlSurfaceView3d.java
jmini3d.android.GpuUploader.java
jmini3d.android.Program.java
jmini3d.android.Renderer3d.java
jmini3d.android.ResourceLoader.java
jmini3d.android.compat.CompatibilityWrapper5.java
jmini3d.android.demo.DemoActivity.java
jmini3d.android.input.InputController.java
jmini3d.demo.ArialFont.java
jmini3d.demo.CubeScene.java
jmini3d.demo.CubesScene.java
jmini3d.demo.DemoSceneController.java
jmini3d.demo.EnvMapCubeScene.java
jmini3d.demo.NormalMapScene.java
jmini3d.demo.ParentScene.java
jmini3d.demo.TeapotGeometry.java
jmini3d.demo.TeapotScene.java
jmini3d.geometry.BoxGeometry.java
jmini3d.geometry.Geometry.java
jmini3d.geometry.PlaneGeometry.java
jmini3d.geometry.SkyboxGeometry.java
jmini3d.geometry.SpriteGeometry.java
jmini3d.geometry.VariableGeometry.java
jmini3d.gwt.Canvas3d.java
jmini3d.gwt.EngineResources.java
jmini3d.gwt.EntryPoint3d.java
jmini3d.gwt.GeometryBuffers.java
jmini3d.gwt.GpuUploader.java
jmini3d.gwt.MyInt16Array.java
jmini3d.gwt.Program.java
jmini3d.gwt.Renderer3d.java
jmini3d.gwt.ResourceLoader.java
jmini3d.gwt.TextureLoadedListener.java
jmini3d.gwt.demo.DemoEntryPoint.java
jmini3d.gwt.input.InputController.java
jmini3d.input.KeyListener.java
jmini3d.input.TouchListener.java
jmini3d.input.TouchPointer.java
jmini3d.light.AmbientLight.java
jmini3d.light.DirectionalLight.java
jmini3d.light.Light.java
jmini3d.light.PointLight.java
jmini3d.material.Material.java
jmini3d.material.PhongMaterial.java
jmini3d.material.SpriteMaterial.java
jmini3d.utils.Fnt2Class.java
jmini3d.utils.Obj2Class.java